From 7fce20c98eac14789124496b19b7e292c78fada1 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 24 Oct 2017 20:25:51 +0300 Subject: [PATCH] Removed redundant calls UpdateGObject(). Undocommand for piece label. --HG-- branch : feature --- .../operation/vabstractoperation.cpp | 3 +- .../drawTools/operation/vabstractoperation.h | 2 +- .../tooldoublepoint/vtooldoublepoint.cpp | 4 +- .../tooldoublepoint/vtooldoublepoint.h | 2 +- .../toolsinglepoint/vtoolsinglepoint.cpp | 3 +- .../toolsinglepoint/vtoolsinglepoint.h | 2 +- src/libs/vtools/tools/drawTools/vdrawtool.cpp | 7 ---- src/libs/vtools/tools/drawTools/vdrawtool.h | 1 - .../vtools/tools/nodeDetails/vnodepoint.cpp | 41 ++++++++----------- .../vtools/tools/nodeDetails/vnodepoint.h | 3 +- src/libs/vtools/tools/vabstracttool.cpp | 7 ++++ src/libs/vtools/tools/vabstracttool.h | 1 + .../undocommands/label/movedoublelabel.cpp | 2 +- .../vtools/undocommands/label/movelabel.cpp | 7 ++-- .../undocommands/label/operationmovelabel.cpp | 2 +- 15 files changed, 39 insertions(+), 48 deletions(-) diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp index 7db3e3a49..16eb41479 100644 --- a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp @@ -86,7 +86,7 @@ void VAbstractOperation::paint(QPainter *painter, const QStyleOptionGraphicsItem } //--------------------------------------------------------------------------------------------------------------------- -void VAbstractOperation::DoChangePosition(quint32 id, const QPointF &pos) +void VAbstractOperation::ChangeLabelPosition(quint32 id, const QPointF &pos) { if (operatedObjects.contains(id)) { @@ -98,7 +98,6 @@ void VAbstractOperation::DoChangePosition(quint32 id, const QPointF &pos) QSharedPointer point = VAbstractTool::data.GeometricObject(id); point->setMx(pos.x()); point->setMy(pos.y()); - VAbstractTool::data.UpdateGObject(id, point); item->RefreshPointGeometry(*(point.data())); } } diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h index 1137bc6e0..ea1c1fd29 100644 --- a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h @@ -87,7 +87,7 @@ public: virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE; - virtual void DoChangePosition(quint32 id, const QPointF &pos) Q_DECL_OVERRIDE; + virtual void ChangeLabelPosition(quint32 id, const QPointF &pos) Q_DECL_OVERRIDE; virtual bool IsLabelVisible(quint32 id) const Q_DECL_OVERRIDE; virtual void SetLabelVisible(quint32 id, bool visible) Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp index e384bf580..a8025c93b 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp @@ -220,14 +220,13 @@ void VToolDoublePoint::FullUpdateFromFile() } //--------------------------------------------------------------------------------------------------------------------- -void VToolDoublePoint::DoChangePosition(quint32 id, const QPointF &pos) +void VToolDoublePoint::ChangeLabelPosition(quint32 id, const QPointF &pos) { if (id == p1id) { QSharedPointer point = VAbstractTool::data.GeometricObject(p1id); point->setMx(pos.x()); point->setMy(pos.y()); - VAbstractTool::data.UpdateGObject(p1id, point); firstPoint->RefreshPointGeometry(*(point.data())); } else if (id == p2id) @@ -235,7 +234,6 @@ void VToolDoublePoint::DoChangePosition(quint32 id, const QPointF &pos) QSharedPointer point = VAbstractTool::data.GeometricObject(p2id); point->setMx(pos.x()); point->setMy(pos.y()); - VAbstractTool::data.UpdateGObject(p2id, point); secondPoint->RefreshPointGeometry(*(point.data())); } } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h index 4e5cdd720..f384d47fa 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h @@ -63,7 +63,7 @@ public: void setNameP2(const QString &name); virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; - virtual void DoChangePosition(quint32 id, const QPointF &pos) Q_DECL_OVERRIDE; + virtual void ChangeLabelPosition(quint32 id, const QPointF &pos) Q_DECL_OVERRIDE; virtual bool IsLabelVisible(quint32 id) const Q_DECL_OVERRIDE; virtual void SetLabelVisible(quint32 id, bool visible) Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp index dae587b22..b0b212de5 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp @@ -324,14 +324,13 @@ void VToolSinglePoint::ChangeLabelVisibility(quint32 id, bool visible) } //--------------------------------------------------------------------------------------------------------------------- -void VToolSinglePoint::DoChangePosition(quint32 id, const QPointF &pos) +void VToolSinglePoint::ChangeLabelPosition(quint32 id, const QPointF &pos) { if (id == m_id) { QSharedPointer point = VAbstractTool::data.GeometricObject(id); point->setMx(pos.x()); point->setMy(pos.y()); - VAbstractTool::data.UpdateGObject(id, point); m_namePoint->blockSignals(true); m_namePoint->setPos(pos); m_namePoint->blockSignals(false); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h index 02a863768..51c195fe5 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h @@ -79,7 +79,7 @@ public: void SetEnabled(bool enabled); virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; - virtual void DoChangePosition(quint32 id, const QPointF &pos) Q_DECL_OVERRIDE; + virtual void ChangeLabelPosition(quint32 id, const QPointF &pos) Q_DECL_OVERRIDE; virtual bool IsLabelVisible(quint32 id) const Q_DECL_OVERRIDE; virtual void SetLabelVisible(quint32 id, bool visible) Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.cpp b/src/libs/vtools/tools/drawTools/vdrawtool.cpp index 96ba1f547..87f0f34a4 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.cpp +++ b/src/libs/vtools/tools/drawTools/vdrawtool.cpp @@ -269,10 +269,3 @@ void VDrawTool::SetLabelVisible(quint32 id, bool visible) Q_UNUSED(id) Q_UNUSED(visible) } - -//--------------------------------------------------------------------------------------------------------------------- -void VDrawTool::DoChangePosition(quint32 id, const QPointF &pos) -{ - Q_UNUSED(id) - Q_UNUSED(pos) -} diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.h b/src/libs/vtools/tools/drawTools/vdrawtool.h index 6f21f6f46..b39f5d33b 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -69,7 +69,6 @@ public: virtual bool IsLabelVisible(quint32 id) const; virtual void SetLabelVisible(quint32 id, bool visible); - virtual void DoChangePosition(quint32 id, const QPointF &pos); signals: void ChangedToolSelection(bool selected, quint32 object, quint32 tool); diff --git a/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp b/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp index d7681b648..721907088 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp +++ b/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp @@ -54,6 +54,7 @@ #include "../vabstracttool.h" #include "../vdatatool.h" #include "vabstractnode.h" +#include "../../undocommands/label/movelabel.h" const QString VNodePoint::ToolType = QStringLiteral("modeling"); @@ -126,6 +127,21 @@ QString VNodePoint::getTagName() const return VAbstractPattern::TagPoint; } +//--------------------------------------------------------------------------------------------------------------------- +void VNodePoint::ChangeLabelPosition(quint32 id, const QPointF &pos) +{ + if (id == m_id) + { + QSharedPointer point = VAbstractTool::data.GeometricObject(id); + point->setMx(pos.x()); + point->setMy(pos.y()); + m_namePoint->blockSignals(true); + m_namePoint->setPos(pos); + m_namePoint->blockSignals(false); + RefreshLine(); + } +} + //--------------------------------------------------------------------------------------------------------------------- void VNodePoint::PointChoosed() { @@ -199,30 +215,7 @@ void VNodePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) */ void VNodePoint::NameChangePosition(const QPointF &pos) { - VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject(m_id)); - QPointF p = pos - this->pos(); - point->setMx(p.x()); - point->setMy(p.y()); - RefreshLine(); - UpdateNamePosition(point->mx(), point->my()); - VAbstractTool::data.UpdateGObject(m_id, point); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief UpdateNamePosition update label position in file. - * @param mx label bias x axis. - * @param my label bias y axis. - */ -void VNodePoint::UpdateNamePosition(qreal mx, qreal my) -{ - QDomElement domElement = doc->elementById(m_id, getTagName()); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, AttrMx, QString().setNum(qApp->fromPixel(mx))); - doc->SetAttribute(domElement, AttrMy, QString().setNum(qApp->fromPixel(my))); - emit toolhaveChange(); - } + qApp->getUndoStack()->push(new MoveLabel(doc, pos - this->pos(), m_id)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/nodeDetails/vnodepoint.h b/src/libs/vtools/tools/nodeDetails/vnodepoint.h index 81c47c267..30ee4380d 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodepoint.h +++ b/src/libs/vtools/tools/nodeDetails/vnodepoint.h @@ -57,6 +57,8 @@ public: enum { Type = UserType + static_cast(Tool::NodePoint)}; virtual QString getTagName() const Q_DECL_OVERRIDE; + virtual void ChangeLabelPosition(quint32 id, const QPointF &pos) Q_DECL_OVERRIDE; + signals: /** * @brief ShowContextMenu emit when need show tool context menu. @@ -77,7 +79,6 @@ protected: virtual void AddToFile() Q_DECL_OVERRIDE; virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE; virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; - virtual void UpdateNamePosition(qreal mx, qreal my); virtual void ShowNode() Q_DECL_OVERRIDE; virtual void HideNode() Q_DECL_OVERRIDE; virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/vabstracttool.cpp b/src/libs/vtools/tools/vabstracttool.cpp index 7228a96c9..07d94fffe 100644 --- a/src/libs/vtools/tools/vabstracttool.cpp +++ b/src/libs/vtools/tools/vabstracttool.cpp @@ -397,6 +397,13 @@ QMap VAbstractTool::PointsList() const return list; } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractTool::ChangeLabelPosition(quint32 id, const QPointF &pos) +{ + Q_UNUSED(id) + Q_UNUSED(pos) +} + //--------------------------------------------------------------------------------------------------------------------- void VAbstractTool::ToolSelectionType(const SelectionType &type) { diff --git a/src/libs/vtools/tools/vabstracttool.h b/src/libs/vtools/tools/vabstracttool.h index 7af08426e..585de3903 100644 --- a/src/libs/vtools/tools/vabstracttool.h +++ b/src/libs/vtools/tools/vabstracttool.h @@ -108,6 +108,7 @@ public: QMap PointsList() const; virtual QString getTagName() const =0; virtual void ShowVisualization(bool show) =0; + virtual void ChangeLabelPosition(quint32 id, const QPointF &pos); template static quint32 CreateNode(VContainer *data, quint32 id); diff --git a/src/libs/vtools/undocommands/label/movedoublelabel.cpp b/src/libs/vtools/undocommands/label/movedoublelabel.cpp index 13e8878c7..8cc724ecc 100644 --- a/src/libs/vtools/undocommands/label/movedoublelabel.cpp +++ b/src/libs/vtools/undocommands/label/movedoublelabel.cpp @@ -146,7 +146,7 @@ void MoveDoubleLabel::Do(const QPointF &pos) if (VDrawTool *tool = qobject_cast(VAbstractPattern::getTool(m_idTool))) { - tool->DoChangePosition(nodeId, pos); + tool->ChangeLabelPosition(nodeId, pos); } VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView()); } diff --git a/src/libs/vtools/undocommands/label/movelabel.cpp b/src/libs/vtools/undocommands/label/movelabel.cpp index a0792856a..46ae8e487 100644 --- a/src/libs/vtools/undocommands/label/movelabel.cpp +++ b/src/libs/vtools/undocommands/label/movelabel.cpp @@ -37,7 +37,8 @@ #include "../vmisc/vabstractapplication.h" #include "../vundocommand.h" #include "moveabstractlabel.h" -#include "../vtools/tools/drawTools/vdrawtool.h" +#include "../vtools/tools/vabstracttool.h" +#include "../vwidgets/vmaingraphicsview.h" //--------------------------------------------------------------------------------------------------------------------- MoveLabel::MoveLabel(VAbstractPattern *doc, const QPointF &pos, const quint32 &id, QUndoCommand *parent) @@ -97,9 +98,9 @@ void MoveLabel::Do(const QPointF &pos) doc->SetAttribute(domElement, AttrMx, QString().setNum(qApp->fromPixel(pos.x()))); doc->SetAttribute(domElement, AttrMy, QString().setNum(qApp->fromPixel(pos.y()))); - if (VDrawTool *tool = qobject_cast(VAbstractPattern::getTool(nodeId))) + if (VAbstractTool *tool = qobject_cast(VAbstractPattern::getTool(nodeId))) { - tool->DoChangePosition(nodeId, pos); + tool->ChangeLabelPosition(nodeId, pos); } VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView()); } diff --git a/src/libs/vtools/undocommands/label/operationmovelabel.cpp b/src/libs/vtools/undocommands/label/operationmovelabel.cpp index d2cc93752..cd3cea064 100644 --- a/src/libs/vtools/undocommands/label/operationmovelabel.cpp +++ b/src/libs/vtools/undocommands/label/operationmovelabel.cpp @@ -104,7 +104,7 @@ void OperationMoveLabel::Do(const QPointF &pos) if (VDrawTool *tool = qobject_cast(VAbstractPattern::getTool(m_idTool))) { - tool->DoChangePosition(nodeId, pos); + tool->ChangeLabelPosition(nodeId, pos); } VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView()); }