diff --git a/src/libs/vgeometry/vpointf.cpp b/src/libs/vgeometry/vpointf.cpp index 12de7bc1c..3812244af 100644 --- a/src/libs/vgeometry/vpointf.cpp +++ b/src/libs/vgeometry/vpointf.cpp @@ -214,6 +214,18 @@ void VPointF::setY(const qreal &value) d->_y = value; } +//--------------------------------------------------------------------------------------------------------------------- +bool VPointF::IsShowLabel() const +{ + return d->m_showLabel; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPointF::SetHideLabel(bool hide) +{ + d->m_showLabel = hide; +} + //--------------------------------------------------------------------------------------------------------------------- QPointF VPointF::RotatePF(const QPointF &originPoint, const QPointF &point, qreal degrees) { diff --git a/src/libs/vgeometry/vpointf.h b/src/libs/vgeometry/vpointf.h index b84d8c48e..ce0ebb13c 100644 --- a/src/libs/vgeometry/vpointf.h +++ b/src/libs/vgeometry/vpointf.h @@ -82,6 +82,9 @@ public: qreal y() const; void setY(const qreal &value); + bool IsShowLabel() const; + void SetHideLabel(bool hide); + static QPointF RotatePF(const QPointF &originPoint, const QPointF &point, qreal degrees); static QPointF FlipPF(const QLineF &axis, const QPointF &point); static QPointF MovePF(const QPointF &originPoint, qreal length, qreal angle); diff --git a/src/libs/vgeometry/vpointf_p.h b/src/libs/vgeometry/vpointf_p.h index 5885768a3..cc18db341 100644 --- a/src/libs/vgeometry/vpointf_p.h +++ b/src/libs/vgeometry/vpointf_p.h @@ -43,23 +43,23 @@ class VPointFData : public QSharedData public: VPointFData() - : _mx(0), _my(0), _x(0), _y(0) + : _mx(0), _my(0), _x(0), _y(0), m_showLabel(true) {} VPointFData(const VPointFData &point) - :QSharedData(point), _mx(point._mx), _my(point._my), _x(point._x), _y(point._y) + :QSharedData(point), _mx(point._mx), _my(point._my), _x(point._x), _y(point._y), m_showLabel(point.m_showLabel) {} explicit VPointFData(const QPointF &point) - :_mx(0), _my(0), _x(point.x()), _y(point.y()) + :_mx(0), _my(0), _x(point.x()), _y(point.y()), m_showLabel(true) {} VPointFData(qreal x, qreal y, qreal mx, qreal my) - :_mx(mx), _my(my), _x(x), _y(y) + :_mx(mx), _my(my), _x(x), _y(y), m_showLabel(true) {} VPointFData(const QPointF &point, qreal mx, qreal my) - :_mx(mx), _my(my), _x(point.x()), _y(point.y()) + :_mx(mx), _my(my), _x(point.x()), _y(point.y()), m_showLabel(true) {} virtual ~VPointFData(); @@ -76,6 +76,9 @@ public: /** @brief _y y coordinate */ qreal _y; + /** @brief m_hideLabel show or not label for this point */ + bool m_showLabel; + private: VPointFData &operator=(const VPointFData &) Q_DECL_EQ_DELETE; }; diff --git a/src/libs/vpatterndb/vcontainer.h b/src/libs/vpatterndb/vcontainer.h index 6f5e882a6..5abca636f 100644 --- a/src/libs/vpatterndb/vcontainer.h +++ b/src/libs/vpatterndb/vcontainer.h @@ -239,6 +239,11 @@ Q_DECLARE_TYPEINFO(VContainer, Q_MOVABLE_TYPE); template const QSharedPointer VContainer::GeometricObject(const quint32 &id) const { + if (id == NULL_ID) + { + throw VExceptionBadId(tr("Can't find object"), id); + } + QSharedPointer gObj = QSharedPointer(); if (d->gObjects.contains(id)) { diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp index 91035aea5..12759fe93 100644 --- a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp @@ -474,9 +474,9 @@ void VAbstractOperation::InitCurve(quint32 id, VContainer *data, GOType curveTyp curve->setParentItem(this); curve->SetType(curveType); connect(curve, &VSimpleCurve::Selected, this, &VAbstractOperation::ObjectSelected); - connect(curve, &VSimpleCurve::ShowContextMenu, this, [this](QGraphicsSceneContextMenuEvent * event) + connect(curve, &VSimpleCurve::ShowContextMenu, this, [this](QGraphicsSceneContextMenuEvent * event, quint32 id) { - contextMenuEvent(event); + ShowContextMenu(event, id); }); connect(curve, &VSimpleCurve::Choosed, this, [this, sceneType](quint32 id) { @@ -576,9 +576,9 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") }); connect(point, &VSimplePoint::Selected, this, &VAbstractOperation::ObjectSelected); connect(point, &VSimplePoint::ShowContextMenu, - this, [this](QGraphicsSceneContextMenuEvent * event) + this, [this](QGraphicsSceneContextMenuEvent * event, quint32 id) { - contextMenuEvent(event); + ShowContextMenu(event, id); }); connect(point, &VSimplePoint::Delete, this, &VAbstractOperation::DeleteFromLabel); connect(point, &VSimplePoint::NameChangedPosition, this, &VAbstractOperation::LabelChangePosition); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp index fd28c852d..ac326d90c 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp @@ -67,7 +67,7 @@ VToolDoublePoint::VToolDoublePoint(VAbstractPattern *doc, VContainer *data, quin firstPoint->setParentItem(this); connect(firstPoint, &VSimplePoint::Choosed, this, &VToolDoublePoint::Point1Choosed); connect(firstPoint, &VSimplePoint::Selected, this, &VToolDoublePoint::Point1Selected); - connect(firstPoint, &VSimplePoint::ShowContextMenu, this, &VToolDoublePoint::contextMenuEvent); + connect(firstPoint, &VSimplePoint::ShowContextMenu, this, &VToolDoublePoint::ShowContextMenu); connect(firstPoint, &VSimplePoint::Delete, this, &VToolDoublePoint::DeleteFromLabel); connect(firstPoint, &VSimplePoint::NameChangedPosition, this, &VToolDoublePoint::Label1ChangePosition); firstPoint->RefreshPointGeometry(*VAbstractTool::data.GeometricObject(p1id)); @@ -76,7 +76,7 @@ VToolDoublePoint::VToolDoublePoint(VAbstractPattern *doc, VContainer *data, quin secondPoint->setParentItem(this); connect(secondPoint, &VSimplePoint::Choosed, this, &VToolDoublePoint::Point2Choosed); connect(secondPoint, &VSimplePoint::Selected, this, &VToolDoublePoint::Point2Selected); - connect(secondPoint, &VSimplePoint::ShowContextMenu, this, &VToolDoublePoint::contextMenuEvent); + connect(secondPoint, &VSimplePoint::ShowContextMenu, this, &VToolDoublePoint::ShowContextMenu); connect(secondPoint, &VSimplePoint::Delete, this, &VToolDoublePoint::DeleteFromLabel); connect(secondPoint, &VSimplePoint::NameChangedPosition, this, &VToolDoublePoint::Label2ChangePosition); secondPoint->RefreshPointGeometry(*VAbstractTool::data.GeometricObject(p2id)); diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.h b/src/libs/vtools/tools/drawTools/vdrawtool.h index 12e4ebf77..f769864fd 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -49,6 +49,7 @@ #include "../vwidgets/vmaingraphicsscene.h" #include "../vwidgets/vmaingraphicsview.h" #include "../vdatatool.h" +#include "../vgeometry/vpointf.h" template class QSharedPointer; @@ -133,7 +134,6 @@ template void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemId, const RemoveOption &showRemove, const Referens &ref) { - Q_UNUSED(itemId) SCASSERT(event != nullptr) if (m_suppressContextMenu) @@ -144,6 +144,20 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI qCDebug(vTool, "Creating tool context menu."); QMenu menu; QAction *actionOption = menu.addAction(QIcon::fromTheme("preferences-other"), tr("Options")); + + QAction *actionShowLabel = menu.addAction(tr("Show label")); + actionShowLabel->setCheckable(true); + + try + { + const QSharedPointer point = VAbstractTool::data.GeometricObject(itemId); + actionShowLabel->setChecked(point->IsShowLabel()); + } + catch(const VExceptionBadId &) + { + actionShowLabel->setVisible(false); + } + QAction *actionRemove = menu.addAction(QIcon::fromTheme("edit-delete"), tr("Delete")); if (showRemove == RemoveOption::Enable) { @@ -187,12 +201,16 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI m_dialog->show(); } - if (selectedAction == actionRemove) + else if (selectedAction == actionRemove) { qCDebug(vTool, "Deleting tool."); DeleteTool(); // do not catch exception here return; //Leave this method immediately after call!!! } + else if (selectedAction == actionShowLabel) + { + // do something here to show/hide a label + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vwidgets/vabstractsimple.cpp b/src/libs/vwidgets/vabstractsimple.cpp index 7ac7409f6..220ed8bd2 100644 --- a/src/libs/vwidgets/vabstractsimple.cpp +++ b/src/libs/vwidgets/vabstractsimple.cpp @@ -43,12 +43,6 @@ void VAbstractSimple::ToolSelectionType(const SelectionType &type) selectionType = type; } -//--------------------------------------------------------------------------------------------------------------------- -void VAbstractSimple::ContextMenu(QGraphicsSceneContextMenuEvent *event) -{ - emit ShowContextMenu(event); -} - //--------------------------------------------------------------------------------------------------------------------- GOType VAbstractSimple::GetType() const { diff --git a/src/libs/vwidgets/vabstractsimple.h b/src/libs/vwidgets/vabstractsimple.h index 23b624777..ecffd9c47 100644 --- a/src/libs/vwidgets/vabstractsimple.h +++ b/src/libs/vwidgets/vabstractsimple.h @@ -56,12 +56,9 @@ public: void SetType(const GOType &value); signals: - void ShowContextMenu(QGraphicsSceneContextMenuEvent * event); + void ShowContextMenu(QGraphicsSceneContextMenuEvent * event, quint32 id = NULL_ID); void Delete(); -public slots: - void ContextMenu(QGraphicsSceneContextMenuEvent * event); - protected: /** @brief id spline id. */ quint32 id; diff --git a/src/libs/vwidgets/vsimplepoint.cpp b/src/libs/vwidgets/vsimplepoint.cpp index 12ab1ab42..3bc87accd 100644 --- a/src/libs/vwidgets/vsimplepoint.cpp +++ b/src/libs/vwidgets/vsimplepoint.cpp @@ -55,7 +55,7 @@ VSimplePoint::VSimplePoint(quint32 id, const QColor ¤tColor, QObject *pare m_alwaysHovered(false) { m_baseColor = currentColor; - connect(m_namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VSimplePoint::ContextMenu); + connect(m_namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VSimplePoint::contextMenuEvent); connect(m_namePoint, &VGraphicsSimpleTextItem::DeleteTool, this, &VSimplePoint::DeleteFromLabel); connect(m_namePoint, &VGraphicsSimpleTextItem::PointChoosed, this, &VSimplePoint::PointChoosed); connect(m_namePoint, &VGraphicsSimpleTextItem::PointSelected, this, &VSimplePoint::PointSelected); @@ -234,5 +234,5 @@ QVariant VSimplePoint::itemChange(QGraphicsItem::GraphicsItemChange change, cons //--------------------------------------------------------------------------------------------------------------------- void VSimplePoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - emit ShowContextMenu(event); + emit ShowContextMenu(event, id); }