From 59c9a0b4006bcd136463760fc88609c5771971ae Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 13 Jan 2017 16:57:49 +0200 Subject: [PATCH] Allow a user to select a point covered by visualization. --HG-- branch : feature --- .../visualization/path/vistoolpiecepath.cpp | 1 + src/libs/vwidgets/vsimplepoint.cpp | 60 +++++++++++++------ src/libs/vwidgets/vsimplepoint.h | 4 ++ 3 files changed, 47 insertions(+), 18 deletions(-) diff --git a/src/libs/vtools/visualization/path/vistoolpiecepath.cpp b/src/libs/vtools/visualization/path/vistoolpiecepath.cpp index 470a4ffff..e0c4a5750 100644 --- a/src/libs/vtools/visualization/path/vistoolpiecepath.cpp +++ b/src/libs/vtools/visualization/path/vistoolpiecepath.cpp @@ -92,6 +92,7 @@ VSimplePoint *VisToolPiecePath::GetPoint(quint32 i, const QColor &color) VSimplePoint *point = new VSimplePoint(NULL_ID, color, *Visualization::data->GetPatternUnit(), &factor); point->SetPointHighlight(true); point->setParentItem(this); + point->SetVisualizationMode(true); m_points.append(point); return point; diff --git a/src/libs/vwidgets/vsimplepoint.cpp b/src/libs/vwidgets/vsimplepoint.cpp index f8bfa1d37..8d1980e3a 100644 --- a/src/libs/vwidgets/vsimplepoint.cpp +++ b/src/libs/vwidgets/vsimplepoint.cpp @@ -59,7 +59,8 @@ VSimplePoint::VSimplePoint(quint32 id, const QColor ¤tColor, Unit patternU namePoint(nullptr), lineName(nullptr), m_onlyPoint(false), - m_isHighlight(false) + m_isHighlight(false), + m_visualizationMode(false) { namePoint = new VGraphicsSimpleTextItem(this); connect(namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VSimplePoint::ContextMenu); @@ -92,6 +93,19 @@ bool VSimplePoint::IsOnlyPoint() const return m_onlyPoint; } +//--------------------------------------------------------------------------------------------------------------------- +void VSimplePoint::SetVisualizationMode(bool value) +{ + m_visualizationMode = value; + this->setFlag(QGraphicsItem::ItemIsFocusable, not m_visualizationMode); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VSimplePoint::IsVisualizationMode() const +{ + return m_visualizationMode; +} + //--------------------------------------------------------------------------------------------------------------------- void VSimplePoint::SetPointHighlight(bool value) { @@ -209,24 +223,31 @@ void VSimplePoint::ChangedPosition(const QPointF &pos) //--------------------------------------------------------------------------------------------------------------------- void VSimplePoint::mousePressEvent(QGraphicsSceneMouseEvent *event) { - // Special for not selectable item first need to call standard mousePressEvent then accept event - QGraphicsEllipseItem::mousePressEvent(event); - - // Somehow clicking on notselectable object do not clean previous selections. - if (not (flags() & ItemIsSelectable) && scene()) + if (m_visualizationMode) { - scene()->clearSelection(); - } - - if (selectionType == SelectionType::ByMouseRelease) - { - event->accept();// Special for not selectable item first need to call standard mousePressEvent then accept event + event->ignore(); } else { - if (event->button() == Qt::LeftButton) + // Special for not selectable item first need to call standard mousePressEvent then accept event + QGraphicsEllipseItem::mousePressEvent(event); + + // Somehow clicking on notselectable object do not clean previous selections. + if (not (flags() & ItemIsSelectable) && scene()) { - emit Choosed(id); + scene()->clearSelection(); + } + + if (selectionType == SelectionType::ByMouseRelease) + {// Special for not selectable item first need to call standard mousePressEvent then accept event + event->accept(); + } + else + { + if (event->button() == Qt::LeftButton) + { + emit Choosed(id); + } } } } @@ -234,14 +255,17 @@ void VSimplePoint::mousePressEvent(QGraphicsSceneMouseEvent *event) //--------------------------------------------------------------------------------------------------------------------- void VSimplePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if (selectionType == SelectionType::ByMouseRelease) + if (not m_visualizationMode) { - if (event->button() == Qt::LeftButton) + if (selectionType == SelectionType::ByMouseRelease) { - emit Choosed(id); + if (event->button() == Qt::LeftButton) + { + emit Choosed(id); + } } + QGraphicsEllipseItem::mouseReleaseEvent(event); } - QGraphicsEllipseItem::mouseReleaseEvent(event); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vwidgets/vsimplepoint.h b/src/libs/vwidgets/vsimplepoint.h index 68785a802..7378f5362 100644 --- a/src/libs/vwidgets/vsimplepoint.h +++ b/src/libs/vwidgets/vsimplepoint.h @@ -65,6 +65,9 @@ public: void SetOnlyPoint(bool value); bool IsOnlyPoint() const; + void SetVisualizationMode(bool value); + bool IsVisualizationMode() const; + void SetPointHighlight(bool value); void RefreshLine(); @@ -112,6 +115,7 @@ private: bool m_onlyPoint; bool m_isHighlight; + bool m_visualizationMode; }; #endif // VSIMPLEPOINT_H