Commit 42ce42ea authored by Samuel Jackson's avatar Samuel Jackson
Browse files

Refs #18043 Fix line appearing outside of integration range.

parent c2f96f11
......@@ -352,6 +352,8 @@ private:
void drawMaskShapes(QPainter &painter) const;
/// Draw the selection rectangle to the surface
void drawSelectionRect(QPainter &painter) const;
/// Check if a peak is visible at a given point
bool peakVisibleAtPoint(const QPointF &point) const;
/// Get the current input controller
MantidQt::MantidWidgets::InputController *getController() const;
......
......@@ -53,6 +53,7 @@ public:
void keyPressEvent(QKeyEvent *);
bool selectAtXY(int x, int y, bool edit = true);
bool selectAtXY(const QPointF &point, bool edit = true);
void deselectAtXY(int x, int y);
bool selectIn(const QRect &rect);
void removeCurrentShape();
......
......@@ -515,20 +515,54 @@ void ProjectionSurface::setPeakVisibility() const {
}
}
/** Check a peak is visible at the given point
*
* Will return true if any peak in any overlay was found to be positioned at
* the given point.
*
* @param point :: the point to check for peaks
* @return true if any peaks was found at the given point
*/
bool ProjectionSurface::peakVisibleAtPoint(const QPointF &point) const {
bool visible = false;
for (const auto po : m_peakShapes) {
po->selectAtXY(point);
auto markers = po->getSelectedPeakMarkers();
visible =
std::any_of(markers.begin(), markers.end(),
[](PeakMarker2D *marker) { return marker->isVisible(); });
if (visible)
return true;
}
return false;
}
/**
* Draw a line between peak markers being compared
* @param painter :: The QPainter object to draw the line with
*/
void ProjectionSurface::drawPeakComparisonLine(QPainter &painter) const {
if (!m_selectedMarkers.first.isNull() && !m_selectedMarkers.second.isNull()) {
QTransform transform;
auto windowRect = getSurfaceBounds();
windowRect.findTransform(transform, painter.viewport());
auto p1 = transform.map(m_selectedMarkers.first);
auto p2 = transform.map(m_selectedMarkers.second);
painter.setPen(Qt::red);
painter.drawLine(p1, p2);
}
const auto &firstOrigin = m_selectedMarkers.first;
const auto &secondOrigin = m_selectedMarkers.second;
// Check is user has selected enough peaks
if (firstOrigin.isNull() || secondOrigin.isNull())
return;
// Check if the integration range is such that some peaks are visible
if (!peakVisibleAtPoint(firstOrigin) || !peakVisibleAtPoint(secondOrigin))
return;
// Draw line between peaks
QTransform transform;
auto windowRect = getSurfaceBounds();
windowRect.findTransform(transform, painter.viewport());
auto p1 = transform.map(firstOrigin);
auto p2 = transform.map(secondOrigin);
painter.setPen(Qt::red);
painter.drawLine(p1, p2);
}
/**
......
......@@ -300,13 +300,20 @@ void Shape2DCollection::touchShapeOrControlPointAt(int x, int y) {
* Select a shape which contains a point (x,y) of the screen.
*/
bool Shape2DCollection::selectAtXY(int x, int y, bool edit) {
const auto point = m_transform.inverted().map(QPointF(x, y));
return selectAtXY(point, edit);
}
/**
* Select a shape which contains a point (x, y) of the world.
*/
bool Shape2DCollection::selectAtXY(const QPointF &point, bool edit) {
if (edit) {
// if shape has to be edited (resized) it must be the only selection
deselectAll();
}
QPointF p = m_transform.inverted().map(QPointF(x, y));
foreach (Shape2D *shape, m_shapes) {
bool picked = shape->selectAt(p);
bool picked = shape->selectAt(point);
if (picked) {
addToSelection(shape);
return true;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment