diff options
author | Samuel Fadel <samuelfadel@gmail.com> | 2016-01-27 18:47:31 +0100 |
---|---|---|
committer | Samuel Fadel <samuelfadel@gmail.com> | 2016-01-27 18:47:31 +0100 |
commit | 29911b37d6fa377e648ca60161ba6381555b0ef4 (patch) | |
tree | ef740afecf49042170e4be733ba2ed0a00a2002b | |
parent | 6d075f34ef264f257288748b2d57c9950ae0888d (diff) |
Scatterplot: now possible to use brush to select points.
-rw-r--r-- | scatterplot.cpp | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/scatterplot.cpp b/scatterplot.cpp index f10f1b4..8a2bd13 100644 --- a/scatterplot.cpp +++ b/scatterplot.cpp @@ -539,7 +539,9 @@ void Scatterplot::updateGlyphs(QSGNode *glyphsNode) void Scatterplot::updateBrush(QSGNode *node) { QMatrix4x4 transform; - if (m_brushedItem < 0) { + if (m_brushedItem < 0 + || (m_currentInteractionState != INTERACTION_NONE + && m_currentInteractionState != INTERACTION_SELECTED)) { transform.translate(-width(), -height()); } else { const arma::rowvec &row = m_xy.row(m_brushedItem); @@ -557,8 +559,6 @@ void Scatterplot::mousePressEvent(QMouseEvent *event) case INTERACTION_SELECTED: if (event->modifiers() == Qt::ShiftModifier) { m_currentInteractionState = INTERACTION_BEGIN_MOVING; - } else { - m_currentInteractionState = INTERACTION_SELECTING; } m_dragOriginPos = event->localPos(); m_dragCurrentPos = m_dragOriginPos; @@ -566,6 +566,7 @@ void Scatterplot::mousePressEvent(QMouseEvent *event) case INTERACTION_SELECTING: case INTERACTION_BEGIN_MOVING: case INTERACTION_MOVING: + // Probably shouldn't reach these event->ignore(); break; } @@ -587,20 +588,48 @@ void Scatterplot::mouseMoveEvent(QMouseEvent *event) break; case INTERACTION_NONE: case INTERACTION_SELECTED: - event->ignore(); - return; + m_currentInteractionState = INTERACTION_SELECTING; + break; } } void Scatterplot::mouseReleaseEvent(QMouseEvent *event) { switch (m_currentInteractionState) { + case INTERACTION_NONE: + case INTERACTION_SELECTED: + if (m_brushedItem < 0) { + // Mouse clicked with no brush target; clear selection, if any + m_selection.assign(m_selection.size(), false); + m_shouldUpdateMaterials = true; + update(); + } else { + // Mouse clicked with brush target; set new selection or append to + // current + bool mergeSelection = (event->modifiers() == Qt::ControlModifier); + if (!mergeSelection) { + m_selection.assign(m_selection.size(), false); + } + m_selection[m_brushedItem] = true; + emit selectionInteractivelyChanged(m_selection); + + m_shouldUpdateMaterials = true; + update(); + } + break; case INTERACTION_SELECTING: { + // Selecting points and mouse is now released; update selection and + // brush bool mergeSelection = (event->modifiers() == Qt::ControlModifier); bool anySelected = interactiveSelection(mergeSelection); m_currentInteractionState = anySelected ? INTERACTION_SELECTED : INTERACTION_NONE; + + QPoint pos = event->pos(); + m_brushedItem = m_quadtree->nearestTo(pos.x(), pos.y()); + emit itemInteractivelyBrushed(m_brushedItem); + m_shouldUpdateMaterials = true; update(); } @@ -609,15 +638,13 @@ void Scatterplot::mouseReleaseEvent(QMouseEvent *event) m_currentInteractionState = INTERACTION_SELECTED; break; case INTERACTION_MOVING: + // Moving points and now stopped; apply manipulation m_currentInteractionState = INTERACTION_SELECTED; applyManipulation(); m_shouldUpdateGeometry = true; update(); m_dragOriginPos = m_dragCurrentPos; break; - case INTERACTION_NONE: - case INTERACTION_SELECTED: - break; // should not be reached } } |