From 40662bb94861a9219f6243078c6c4984528e63dc Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 20 Sep 2017 15:39:42 +0300 Subject: [PATCH] Fixed bug. After full parse undocommand Move labe losts connection to tool. --HG-- branch : develop --- ChangeLog.txt | 1 + .../operation/vabstractoperation.cpp | 60 +++++++++--------- .../drawTools/operation/vabstractoperation.h | 7 +-- .../tooldoublepoint/vtooldoublepoint.cpp | 38 +++++------ .../tooldoublepoint/vtooldoublepoint.h | 4 +- .../toolsinglepoint/vtoolsinglepoint.cpp | 33 +++++----- .../toolsinglepoint/vtoolsinglepoint.h | 4 +- .../drawTools/toolpoint/vabstractpoint.h | 16 +---- src/libs/vtools/tools/drawTools/vdrawtool.cpp | 7 +++ src/libs/vtools/tools/drawTools/vdrawtool.h | 1 + .../undocommands/label/moveabstractlabel.cpp | 31 ++------- .../undocommands/label/moveabstractlabel.h | 32 +++------- .../undocommands/label/movedoublelabel.cpp | 63 ++++++++++--------- .../undocommands/label/movedoublelabel.h | 9 +-- .../vtools/undocommands/label/movelabel.cpp | 41 ++++++------ .../vtools/undocommands/label/movelabel.h | 10 +-- .../undocommands/label/operationmovelabel.cpp | 44 ++++++------- .../undocommands/label/operationmovelabel.h | 9 +-- 18 files changed, 185 insertions(+), 225 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 7becbb857..0ef6aa188 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -18,6 +18,7 @@ - Removed crash sending system for Windows. - Added new language Polish (Poland). - [#755] New feature. Toggle point label. +- Fixed bug. After full parse undocommand Move labe losts connection to tool. # Version 0.5.1 - [#683] Tool Seam allowance's dialog is off screen on small resolutions. diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp index 8f64535c4..0cc0438fb 100644 --- a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp @@ -85,6 +85,25 @@ void VAbstractOperation::paint(QPainter *painter, const QStyleOptionGraphicsItem Q_UNUSED(widget) } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::DoChangePosition(quint32 id, const QPointF &pos) +{ + if (operatedObjects.contains(id)) + { + VAbstractSimple *obj = operatedObjects.value(id); + if (obj && obj->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(obj); + SCASSERT(item != nullptr) + QSharedPointer point = VAbstractTool::data.GeometricObject(id); + point->setMx(pos.x()); + point->setMy(pos.y()); + VAbstractTool::data.UpdateGObject(id, point); + item->RefreshPointGeometry(*(point.data())); + } + } +} + //--------------------------------------------------------------------------------------------------------------------- bool VAbstractOperation::IsLabelVisible(quint32 id) const { @@ -433,7 +452,7 @@ void VAbstractOperation::LabelChangePosition(const QPointF &pos, quint32 labelId { VSimplePoint *item = qobject_cast(obj); SCASSERT(item != nullptr) - ChangePosition(item, labelId, pos); + UpdateNamePosition(labelId, pos - item->pos()); } } } @@ -474,12 +493,16 @@ void VAbstractOperation::ChangeLabelVisibility(quint32 id, bool visible) } //--------------------------------------------------------------------------------------------------------------------- -void VAbstractOperation::UpdateNamePosition(quint32 id) +void VAbstractOperation::UpdateNamePosition(quint32 id, const QPointF &pos) { - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - auto moveLabel = new OperationMoveLabel(m_id, doc, point->mx(), point->my(), id); - connect(moveLabel, &OperationMoveLabel::ChangePosition, this, &VAbstractOperation::DoChangePosition); - qApp->getUndoStack()->push(moveLabel); + if (operatedObjects.contains(id)) + { + VAbstractSimple *obj = operatedObjects.value(id); + if (obj && obj->GetType() == GOType::Point) + { + qApp->getUndoStack()->push(new OperationMoveLabel(m_id, doc, pos, id)); + } + } } //--------------------------------------------------------------------------------------------------------------------- @@ -537,23 +560,6 @@ void VAbstractOperation::InitCurve(quint32 id, VContainer *data, GOType curveTyp operatedObjects.insert(id, curve); } -//--------------------------------------------------------------------------------------------------------------------- -void VAbstractOperation::DoChangePosition(quint32 id, qreal mx, qreal my) -{ - if (operatedObjects.contains(id)) - { - VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject(id)); - point->setMx(mx); - point->setMy(my); - VAbstractTool::data.UpdateGObject(id, point); - - VSimplePoint *item = qobject_cast(operatedObjects.value(id)); - SCASSERT(item != nullptr) - - item->RefreshPointGeometry(*point); - } -} - //--------------------------------------------------------------------------------------------------------------------- void VAbstractOperation::AllowCurveHover(bool enabled, GOType type) { @@ -592,14 +598,6 @@ void VAbstractOperation::AllowCurveSelecting(bool enabled, GOType type) } } -//--------------------------------------------------------------------------------------------------------------------- -void VAbstractOperation::ChangePosition(QGraphicsItem *item, quint32 id, const QPointF &pos) -{ - const QPointF p = pos - item->pos(); - DoChangePosition(id, p.x(), p.y()); - UpdateNamePosition(id); -} - //--------------------------------------------------------------------------------------------------------------------- void VAbstractOperation::InitOperatedObjects() { diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h index 4e82a5aac..8426a9d91 100644 --- a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h @@ -87,6 +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 bool IsLabelVisible(quint32 id) const Q_DECL_OVERRIDE; virtual void SetLabelVisible(quint32 id, bool visible) Q_DECL_OVERRIDE; @@ -137,7 +138,7 @@ protected: virtual void AddToFile() Q_DECL_OVERRIDE; virtual void ChangeLabelVisibility(quint32 id, bool visible) Q_DECL_OVERRIDE; - void UpdateNamePosition(quint32 id); + void UpdateNamePosition(quint32 id, const QPointF &pos); void SaveSourceDestination(QDomElement &tag); template @@ -152,15 +153,11 @@ protected: QString ComplexPointToolTip(quint32 itemId) const; QString ComplexCurveToolTip(quint32 itemId) const; -protected slots: - void DoChangePosition(quint32 id, qreal mx, qreal my); private: Q_DISABLE_COPY(VAbstractOperation) void AllowCurveHover(bool enabled, GOType type); void AllowCurveSelecting(bool enabled, GOType type); - - void ChangePosition(QGraphicsItem *item, quint32 id, const QPointF &pos); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp index 230ae02f4..33a3f91f3 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp @@ -159,13 +159,13 @@ void VToolDoublePoint::SetLabelVisible(quint32 id, bool visible) //--------------------------------------------------------------------------------------------------------------------- void VToolDoublePoint::Label1ChangePosition(const QPointF &pos) { - ChangePosition(firstPoint, p1id, pos); + UpdateNamePosition(p1id, pos - firstPoint->pos()); } //--------------------------------------------------------------------------------------------------------------------- void VToolDoublePoint::Label2ChangePosition(const QPointF &pos) { - ChangePosition(secondPoint, p2id, pos); + UpdateNamePosition(p2id, pos - secondPoint->pos()); } //--------------------------------------------------------------------------------------------------------------------- @@ -220,23 +220,23 @@ void VToolDoublePoint::FullUpdateFromFile() } //--------------------------------------------------------------------------------------------------------------------- -void VToolDoublePoint::DoChangePosition(quint32 id, qreal mx, qreal my) +void VToolDoublePoint::DoChangePosition(quint32 id, const QPointF &pos) { if (id == p1id) { - VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject(p1id)); - point->setMx(mx); - point->setMy(my); + QSharedPointer point = VAbstractTool::data.GeometricObject(p1id); + point->setMx(pos.x()); + point->setMy(pos.y()); VAbstractTool::data.UpdateGObject(p1id, point); - firstPoint->RefreshPointGeometry(*point); + firstPoint->RefreshPointGeometry(*(point.data())); } else if (id == p2id) { - VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject(p2id)); - point->setMx(mx); - point->setMy(my); + QSharedPointer point = VAbstractTool::data.GeometricObject(p2id); + point->setMx(pos.x()); + point->setMy(pos.y()); VAbstractTool::data.UpdateGObject(p2id, point); - secondPoint->RefreshPointGeometry(*point); + secondPoint->RefreshPointGeometry(*(point.data())); } } @@ -277,23 +277,15 @@ void VToolDoublePoint::ToolSelectionType(const SelectionType &type) } //--------------------------------------------------------------------------------------------------------------------- -void VToolDoublePoint::UpdateNamePosition(quint32 id) -{ +void VToolDoublePoint::UpdateNamePosition(quint32 id, const QPointF &pos) +{ if (id == p1id) { - const VPointF *p1 = VAbstractTool::data.GeometricObject(p1id).data(); - - auto moveLabel = new MoveDoubleLabel(doc, p1->mx(), p1->my(), MoveDoublePoint::FirstPoint, m_id, p1id); - connect(moveLabel, &MoveDoubleLabel::ChangePosition, this, &VToolDoublePoint::DoChangePosition); - qApp->getUndoStack()->push(moveLabel); + qApp->getUndoStack()->push(new MoveDoubleLabel(doc, pos, MoveDoublePoint::FirstPoint, m_id, p1id)); } else if (id == p2id) { - const VPointF *p2 = VAbstractTool::data.GeometricObject(p2id).data(); - - auto moveLabel = new MoveDoubleLabel(doc, p2->mx(), p2->my(), MoveDoublePoint::SecondPoint, m_id, p2id); - connect(moveLabel, &MoveDoubleLabel::ChangePosition, this, &VToolDoublePoint::DoChangePosition); - qApp->getUndoStack()->push(moveLabel); + qApp->getUndoStack()->push(new MoveDoubleLabel(doc, pos, MoveDoublePoint::SecondPoint, m_id, p2id)); } } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h index e66baa9eb..e0d680e82 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h @@ -63,6 +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 bool IsLabelVisible(quint32 id) const Q_DECL_OVERRIDE; virtual void SetLabelVisible(quint32 id, bool visible) Q_DECL_OVERRIDE; @@ -76,7 +77,6 @@ public slots: void Point1Selected(bool selected); void Point2Selected(bool selected); virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; - virtual void DoChangePosition(quint32 id, qreal mx, qreal my) Q_DECL_OVERRIDE; virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE; void AllowLabelHover(bool enabled); @@ -90,7 +90,7 @@ protected: quint32 p1id; quint32 p2id; - virtual void UpdateNamePosition(quint32 id) Q_DECL_OVERRIDE; + virtual void UpdateNamePosition(quint32 id, const QPointF &pos) Q_DECL_OVERRIDE; virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ) Q_DECL_OVERRIDE; virtual void keyReleaseEvent(QKeyEvent * event) Q_DECL_OVERRIDE; virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) 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 ee4425a77..b0bd7137d 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp @@ -147,19 +147,19 @@ void VToolSinglePoint::SetLabelVisible(quint32 id, bool visible) */ void VToolSinglePoint::NameChangePosition(const QPointF &pos) { - ChangePosition(this, m_id, pos); + UpdateNamePosition(m_id, pos - this->pos()); } //--------------------------------------------------------------------------------------------------------------------- /** * @brief UpdateNamePosition save new position label to the pattern file. */ -void VToolSinglePoint::UpdateNamePosition(quint32 id) +void VToolSinglePoint::UpdateNamePosition(quint32 id, const QPointF &pos) { - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - auto moveLabel = new MoveLabel(doc, point->mx(), point->my(), id); - connect(moveLabel, &MoveLabel::ChangePosition, this, &VToolSinglePoint::DoChangePosition); - qApp->getUndoStack()->push(moveLabel); + if (id == m_id) + { + qApp->getUndoStack()->push(new MoveLabel(doc, pos, id)); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -324,16 +324,19 @@ void VToolSinglePoint::ChangeLabelVisibility(quint32 id, bool visible) } //--------------------------------------------------------------------------------------------------------------------- -void VToolSinglePoint::DoChangePosition(quint32 id, qreal mx, qreal my) +void VToolSinglePoint::DoChangePosition(quint32 id, const QPointF &pos) { - VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject(id)); - point->setMx(mx); - point->setMy(my); - VAbstractTool::data.UpdateGObject(id, point); - m_namePoint->blockSignals(true); - m_namePoint->setPos(QPointF(mx, my)); - m_namePoint->blockSignals(false); - RefreshLine(); + 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); + RefreshLine(); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h index 4167323a9..0a2797a82 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h @@ -79,6 +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 bool IsLabelVisible(quint32 id) const Q_DECL_OVERRIDE; virtual void SetLabelVisible(quint32 id, bool visible) Q_DECL_OVERRIDE; @@ -89,14 +90,13 @@ public slots: void PointChoosed(); void PointSelected(bool selected); virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; - virtual void DoChangePosition(quint32 id, qreal mx, qreal my) Q_DECL_OVERRIDE; virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE; void AllowLabelHover(bool enabled); void AllowLabelSelecting(bool enabled); virtual void ToolSelectionType(const SelectionType &type) Q_DECL_OVERRIDE; protected: - virtual void UpdateNamePosition(quint32 id) Q_DECL_OVERRIDE; + virtual void UpdateNamePosition(quint32 id, const QPointF &pos) Q_DECL_OVERRIDE; virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE; virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.h b/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.h index c5b45f9d9..c6cfe9d31 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.h @@ -64,16 +64,11 @@ public: public slots: virtual void ShowTool(quint32 id, bool enable) Q_DECL_OVERRIDE; void DeleteFromLabel(); - virtual void DoChangePosition(quint32 id, qreal mx, qreal my) =0; protected: void SetPointName(quint32 id, const QString &name); - template - void ChangePosition(T *item, quint32 id, const QPointF &pos); - - - virtual void UpdateNamePosition(quint32 id)=0; + virtual void UpdateNamePosition(quint32 id, const QPointF &pos)=0; template static void InitToolConnections(VMainGraphicsScene *scene, T *tool); @@ -107,15 +102,6 @@ void VAbstractPoint::ShowToolVisualization(bool show) } } -//--------------------------------------------------------------------------------------------------------------------- -template -void VAbstractPoint::ChangePosition(T *item, quint32 id, const QPointF &pos) -{ - const QPointF p = pos - item->pos(); - DoChangePosition(id, p.x(), p.y()); - UpdateNamePosition(id); -} - //--------------------------------------------------------------------------------------------------------------------- template void VAbstractPoint::InitToolConnections(VMainGraphicsScene *scene, T *tool) diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.cpp b/src/libs/vtools/tools/drawTools/vdrawtool.cpp index 2040d147c..33422561b 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.cpp +++ b/src/libs/vtools/tools/drawTools/vdrawtool.cpp @@ -257,3 +257,10 @@ 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 548c6de59..bc8ff9da7 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -69,6 +69,7 @@ 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/undocommands/label/moveabstractlabel.cpp b/src/libs/vtools/undocommands/label/moveabstractlabel.cpp index 7f30b11b6..5d5c2d2da 100644 --- a/src/libs/vtools/undocommands/label/moveabstractlabel.cpp +++ b/src/libs/vtools/undocommands/label/moveabstractlabel.cpp @@ -36,26 +36,15 @@ #include "../vundocommand.h" //--------------------------------------------------------------------------------------------------------------------- -MoveAbstractLabel::MoveAbstractLabel(VAbstractPattern *doc, quint32 pointId, double x, double y, - QUndoCommand *parent) +MoveAbstractLabel::MoveAbstractLabel(VAbstractPattern *doc, quint32 pointId, const QPointF &pos, QUndoCommand *parent) : VUndoCommand(QDomElement(), doc, parent), - m_oldMx(0.0), - m_oldMy(0.0), - m_newMx(x), - m_newMy(y), - m_isRedo(false), - m_scene(qApp->getCurrentScene()) + m_oldPos(), + m_newPos(pos) { nodeId = pointId; qCDebug(vUndo, "Point id %u", nodeId); - qCDebug(vUndo, "Label new Mx %f", m_newMx); - qCDebug(vUndo, "Label new My %f", m_newMy); -} - -//--------------------------------------------------------------------------------------------------------------------- -MoveAbstractLabel::~MoveAbstractLabel() -{ + qCDebug(vUndo, "Label new position (%f;%f)", m_newPos.x(), m_newPos.y()); } //--------------------------------------------------------------------------------------------------------------------- @@ -63,10 +52,7 @@ void MoveAbstractLabel::undo() { qCDebug(vUndo, "Undo."); - Do(m_oldMx, m_oldMy); - VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView()); - m_isRedo = true; - emit ChangePosition(nodeId, m_oldMx, m_oldMy); + Do(m_oldPos); } //--------------------------------------------------------------------------------------------------------------------- @@ -74,10 +60,5 @@ void MoveAbstractLabel::redo() { qCDebug(vUndo, "Redo."); - Do(m_newMx, m_newMy); - VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView()); - if (m_isRedo) - { - emit ChangePosition(nodeId, m_newMx, m_newMy); - } + Do(m_newPos); } diff --git a/src/libs/vtools/undocommands/label/moveabstractlabel.h b/src/libs/vtools/undocommands/label/moveabstractlabel.h index ae255e68b..435257455 100644 --- a/src/libs/vtools/undocommands/label/moveabstractlabel.h +++ b/src/libs/vtools/undocommands/label/moveabstractlabel.h @@ -41,30 +41,20 @@ class QGraphicsScene; class MoveAbstractLabel : public VUndoCommand { - Q_OBJECT public: - MoveAbstractLabel(VAbstractPattern *doc, quint32 pointId, double x, double y, QUndoCommand *parent = nullptr); - virtual ~MoveAbstractLabel(); + MoveAbstractLabel(VAbstractPattern *doc, quint32 pointId, const QPointF &pos, QUndoCommand *parent = nullptr); + virtual ~MoveAbstractLabel()=default; virtual void undo() Q_DECL_OVERRIDE; virtual void redo() Q_DECL_OVERRIDE; quint32 GetPointId() const; - double GetNewMx() const; - double GetNewMy() const; - -signals: - void ChangePosition(quint32 id, qreal mx, qreal my); + QPointF GetNewPos() const; protected: - double m_oldMx; - double m_oldMy; - double m_newMx; - double m_newMy; - bool m_isRedo; - //Need for resizing scene rect - QGraphicsScene *m_scene; + QPointF m_oldPos; + QPointF m_newPos; - virtual void Do(double mx, double my)=0; + virtual void Do(const QPointF &pos)=0; private: Q_DISABLE_COPY(MoveAbstractLabel) }; @@ -76,15 +66,9 @@ inline quint32 MoveAbstractLabel::GetPointId() const } //--------------------------------------------------------------------------------------------------------------------- -inline double MoveAbstractLabel::GetNewMx() const +inline QPointF MoveAbstractLabel::GetNewPos() const { - return m_newMx; -} - -//--------------------------------------------------------------------------------------------------------------------- -inline double MoveAbstractLabel::GetNewMy() const -{ - return m_newMy; + return m_newPos; } #endif // MOVEABSTRACTLABEL_H diff --git a/src/libs/vtools/undocommands/label/movedoublelabel.cpp b/src/libs/vtools/undocommands/label/movedoublelabel.cpp index b4970eb54..50b1e082b 100644 --- a/src/libs/vtools/undocommands/label/movedoublelabel.cpp +++ b/src/libs/vtools/undocommands/label/movedoublelabel.cpp @@ -37,13 +37,15 @@ #include "../vmisc/def.h" #include "../vundocommand.h" #include "moveabstractlabel.h" +#include "../vtools/tools/drawTools/vdrawtool.h" //--------------------------------------------------------------------------------------------------------------------- -MoveDoubleLabel::MoveDoubleLabel(VAbstractPattern *doc, const double &x, const double &y, MoveDoublePoint type, +MoveDoubleLabel::MoveDoubleLabel(VAbstractPattern *doc, const QPointF &pos, MoveDoublePoint type, quint32 toolId, quint32 pointId, QUndoCommand *parent) - : MoveAbstractLabel(doc, pointId, x, y, parent), + : MoveAbstractLabel(doc, pointId, pos, parent), m_type(type), - m_idTool(toolId) + m_idTool(toolId), + m_scene(qApp->getCurrentScene()) { if (type == MoveDoublePoint::FirstPoint) { @@ -59,19 +61,19 @@ MoveDoubleLabel::MoveDoubleLabel(VAbstractPattern *doc, const double &x, const d { if (type == MoveDoublePoint::FirstPoint) { - m_oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx1, "0.0")); - m_oldMy = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy1, "0.0")); + m_oldPos.rx() = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx1, "0.0")); + m_oldPos.ry() = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy1, "0.0")); - qCDebug(vUndo, "Label old Mx1 %f", m_oldMx); - qCDebug(vUndo, "Label old My1 %f", m_oldMy); + qCDebug(vUndo, "Label old Mx1 %f", m_oldPos.x()); + qCDebug(vUndo, "Label old My1 %f", m_oldPos.y()); } else { - m_oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx2, "0.0")); - m_oldMy = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy2, "0.0")); + m_oldPos.rx() = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx2, "0.0")); + m_oldPos.ry() = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy2, "0.0")); - qCDebug(vUndo, "Label old Mx2 %f", m_oldMx); - qCDebug(vUndo, "Label old My2 %f", m_oldMy); + qCDebug(vUndo, "Label old Mx2 %f", m_oldPos.x()); + qCDebug(vUndo, "Label old My2 %f", m_oldPos.y()); } } else @@ -80,10 +82,6 @@ MoveDoubleLabel::MoveDoubleLabel(VAbstractPattern *doc, const double &x, const d } } -//--------------------------------------------------------------------------------------------------------------------- -MoveDoubleLabel::~MoveDoubleLabel() -{} - //--------------------------------------------------------------------------------------------------------------------- bool MoveDoubleLabel::mergeWith(const QUndoCommand *command) { @@ -97,18 +95,17 @@ bool MoveDoubleLabel::mergeWith(const QUndoCommand *command) return false; } - m_newMx = moveCommand->GetNewMx(); - m_newMy = moveCommand->GetNewMy(); + m_newPos = moveCommand->GetNewPos(); if (m_type == MoveDoublePoint::FirstPoint) { - qCDebug(vUndo, "Label new Mx1 %f", m_newMx); - qCDebug(vUndo, "Label new My1 %f", m_newMy); + qCDebug(vUndo, "Label new Mx1 %f", m_newPos.x()); + qCDebug(vUndo, "Label new My1 %f", m_newPos.y()); } else { - qCDebug(vUndo, "Label new Mx2 %f", m_newMx); - qCDebug(vUndo, "Label new My2 %f", m_newMy); + qCDebug(vUndo, "Label new Mx2 %f", m_newPos.x()); + qCDebug(vUndo, "Label new My2 %f", m_newPos.y()); } return true; } @@ -120,17 +117,17 @@ int MoveDoubleLabel::id() const } //--------------------------------------------------------------------------------------------------------------------- -void MoveDoubleLabel::Do(double mx, double my) +void MoveDoubleLabel::Do(const QPointF &pos) { if (m_type == MoveDoublePoint::FirstPoint) { - qCDebug(vUndo, "New mx1 %f", mx); - qCDebug(vUndo, "New my1 %f", my); + qCDebug(vUndo, "New mx1 %f", pos.x()); + qCDebug(vUndo, "New my1 %f", pos.y()); } else { - qCDebug(vUndo, "New mx2 %f", mx); - qCDebug(vUndo, "New my2 %f", my); + qCDebug(vUndo, "New mx2 %f", pos.x()); + qCDebug(vUndo, "New my2 %f", pos.y()); } QDomElement domElement = doc->elementById(m_idTool, VAbstractPattern::TagPoint); @@ -138,14 +135,20 @@ void MoveDoubleLabel::Do(double mx, double my) { if (m_type == MoveDoublePoint::FirstPoint) { - doc->SetAttribute(domElement, AttrMx1, QString().setNum(qApp->fromPixel(mx))); - doc->SetAttribute(domElement, AttrMy1, QString().setNum(qApp->fromPixel(my))); + doc->SetAttribute(domElement, AttrMx1, QString().setNum(qApp->fromPixel(pos.x()))); + doc->SetAttribute(domElement, AttrMy1, QString().setNum(qApp->fromPixel(pos.y()))); } else { - doc->SetAttribute(domElement, AttrMx2, QString().setNum(qApp->fromPixel(mx))); - doc->SetAttribute(domElement, AttrMy2, QString().setNum(qApp->fromPixel(my))); + doc->SetAttribute(domElement, AttrMx2, QString().setNum(qApp->fromPixel(pos.x()))); + doc->SetAttribute(domElement, AttrMy2, QString().setNum(qApp->fromPixel(pos.y()))); } + + if (VDrawTool *tool = qobject_cast(VAbstractPattern::getTool(m_idTool))) + { + tool->DoChangePosition(nodeId, pos); + } + VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView()); } else { diff --git a/src/libs/vtools/undocommands/label/movedoublelabel.h b/src/libs/vtools/undocommands/label/movedoublelabel.h index 201256943..ae7a8cb8b 100644 --- a/src/libs/vtools/undocommands/label/movedoublelabel.h +++ b/src/libs/vtools/undocommands/label/movedoublelabel.h @@ -41,11 +41,10 @@ enum class MoveDoublePoint: char { FirstPoint, SecondPoint }; class MoveDoubleLabel : public MoveAbstractLabel { - Q_OBJECT public: - MoveDoubleLabel(VAbstractPattern *doc, const double &x, const double &y, MoveDoublePoint type, + MoveDoubleLabel(VAbstractPattern *doc, const QPointF &pos, MoveDoublePoint type, quint32 toolId, quint32 pointId, QUndoCommand *parent = nullptr); - virtual ~MoveDoubleLabel() Q_DECL_OVERRIDE; + virtual ~MoveDoubleLabel()=default; virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE; virtual int id() const Q_DECL_OVERRIDE; @@ -53,11 +52,13 @@ public: quint32 GetToolId() const; MoveDoublePoint GetPointType() const; protected: - virtual void Do(double mx, double my) Q_DECL_OVERRIDE; + virtual void Do(const QPointF &pos) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(MoveDoubleLabel) MoveDoublePoint m_type; quint32 m_idTool; + //Need for resizing scene rect + QGraphicsScene *m_scene; }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/undocommands/label/movelabel.cpp b/src/libs/vtools/undocommands/label/movelabel.cpp index 006ce5a87..3b9c73aba 100644 --- a/src/libs/vtools/undocommands/label/movelabel.cpp +++ b/src/libs/vtools/undocommands/label/movelabel.cpp @@ -37,21 +37,23 @@ #include "../vmisc/vabstractapplication.h" #include "../vundocommand.h" #include "moveabstractlabel.h" +#include "../vtools/tools/drawTools/vdrawtool.h" //--------------------------------------------------------------------------------------------------------------------- -MoveLabel::MoveLabel(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, QUndoCommand *parent) - : MoveAbstractLabel(doc, id, x, y, parent) +MoveLabel::MoveLabel(VAbstractPattern *doc, const QPointF &pos, const quint32 &id, QUndoCommand *parent) + : MoveAbstractLabel(doc, id, pos, parent), + m_scene(qApp->getCurrentScene()) { setText(tr("move point label")); QDomElement domElement = doc->elementById(nodeId, VAbstractPattern::TagPoint); if (domElement.isElement()) { - m_oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx, "0.0")); - m_oldMy = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy, "0.0")); + m_oldPos.rx() = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx, "0.0")); + m_oldPos.ry() = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy, "0.0")); - qCDebug(vUndo, "Label old Mx %f", m_oldMx); - qCDebug(vUndo, "Label old My %f", m_oldMy); + qCDebug(vUndo, "Label old Mx %f", m_oldPos.x()); + qCDebug(vUndo, "Label old My %f", m_oldPos.y()); } else { @@ -59,10 +61,6 @@ MoveLabel::MoveLabel(VAbstractPattern *doc, const double &x, const double &y, co } } -//--------------------------------------------------------------------------------------------------------------------- -MoveLabel::~MoveLabel() -{} - //--------------------------------------------------------------------------------------------------------------------- bool MoveLabel::mergeWith(const QUndoCommand *command) { @@ -75,10 +73,9 @@ bool MoveLabel::mergeWith(const QUndoCommand *command) } qCDebug(vUndo, "Mergin undo."); - m_newMx = moveCommand->GetNewMx(); - m_newMy = moveCommand->GetNewMy(); - qCDebug(vUndo, "Label new Mx %f", m_newMx); - qCDebug(vUndo, "Label new My %f", m_newMy); + m_newPos = moveCommand->GetNewPos(); + qCDebug(vUndo, "Label new Mx %f", m_newPos.x()); + qCDebug(vUndo, "Label new My %f", m_newPos.y()); return true; } @@ -89,16 +86,22 @@ int MoveLabel::id() const } //--------------------------------------------------------------------------------------------------------------------- -void MoveLabel::Do(double mx, double my) +void MoveLabel::Do(const QPointF &pos) { - qCDebug(vUndo, "New mx %f", mx); - qCDebug(vUndo, "New my %f", my); + qCDebug(vUndo, "New mx %f", pos.x()); + qCDebug(vUndo, "New my %f", pos.y()); QDomElement domElement = doc->elementById(nodeId, VAbstractPattern::TagPoint); if (domElement.isElement()) { - doc->SetAttribute(domElement, AttrMx, QString().setNum(qApp->fromPixel(mx))); - doc->SetAttribute(domElement, AttrMy, QString().setNum(qApp->fromPixel(my))); + 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))) + { + tool->DoChangePosition(nodeId, pos); + } + VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView()); } else { diff --git a/src/libs/vtools/undocommands/label/movelabel.h b/src/libs/vtools/undocommands/label/movelabel.h index e9e18447c..d3b3cdac0 100644 --- a/src/libs/vtools/undocommands/label/movelabel.h +++ b/src/libs/vtools/undocommands/label/movelabel.h @@ -39,18 +39,18 @@ class MoveLabel : public MoveAbstractLabel { - Q_OBJECT public: - MoveLabel(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, - QUndoCommand *parent = nullptr); - virtual ~MoveLabel(); + MoveLabel(VAbstractPattern *doc, const QPointF &pos, const quint32 &id, QUndoCommand *parent = nullptr); + virtual ~MoveLabel()=default; virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE; virtual int id() const Q_DECL_OVERRIDE; protected: - virtual void Do(double mx, double my) Q_DECL_OVERRIDE; + virtual void Do(const QPointF &pos) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(MoveLabel) + //Need for resizing scene rect + QGraphicsScene *m_scene; }; #endif // MOVELABEL_H diff --git a/src/libs/vtools/undocommands/label/operationmovelabel.cpp b/src/libs/vtools/undocommands/label/operationmovelabel.cpp index 5f675054f..577466760 100644 --- a/src/libs/vtools/undocommands/label/operationmovelabel.cpp +++ b/src/libs/vtools/undocommands/label/operationmovelabel.cpp @@ -38,12 +38,14 @@ #include "../vmisc/def.h" #include "../vundocommand.h" #include "moveabstractlabel.h" +#include "../vtools/tools/drawTools/vdrawtool.h" //--------------------------------------------------------------------------------------------------------------------- -OperationMoveLabel::OperationMoveLabel(quint32 idTool, VAbstractPattern *doc, double x, double y, quint32 idPoint, +OperationMoveLabel::OperationMoveLabel(quint32 idTool, VAbstractPattern *doc, const QPointF &pos, quint32 idPoint, QUndoCommand *parent) - : MoveAbstractLabel(doc, idPoint, x, y, parent), - m_idTool(idTool) + : MoveAbstractLabel(doc, idPoint, pos, parent), + m_idTool(idTool), + m_scene(qApp->getCurrentScene()) { setText(tr("move point label")); @@ -52,11 +54,11 @@ OperationMoveLabel::OperationMoveLabel(quint32 idTool, VAbstractPattern *doc, do const QDomElement element = GetDestinationObject(m_idTool, nodeId); if (element.isElement()) { - m_oldMx = qApp->toPixel(doc->GetParametrDouble(element, AttrMx, "0.0")); - m_oldMy = qApp->toPixel(doc->GetParametrDouble(element, AttrMy, "0.0")); + m_oldPos.rx() = qApp->toPixel(doc->GetParametrDouble(element, AttrMx, "0.0")); + m_oldPos.ry() = qApp->toPixel(doc->GetParametrDouble(element, AttrMy, "0.0")); - qCDebug(vUndo, "Label old Mx %f", m_oldMx); - qCDebug(vUndo, "Label old My %f", m_oldMy); + qCDebug(vUndo, "Label old Mx %f", m_oldPos.x()); + qCDebug(vUndo, "Label old My %f", m_oldPos.y()); } else { @@ -64,11 +66,6 @@ OperationMoveLabel::OperationMoveLabel(quint32 idTool, VAbstractPattern *doc, do } } -//--------------------------------------------------------------------------------------------------------------------- -OperationMoveLabel::~OperationMoveLabel() -{ -} - //--------------------------------------------------------------------------------------------------------------------- bool OperationMoveLabel::mergeWith(const QUndoCommand *command) { @@ -81,10 +78,9 @@ bool OperationMoveLabel::mergeWith(const QUndoCommand *command) } qCDebug(vUndo, "Mergin undo."); - m_newMx = moveCommand->GetNewMx(); - m_newMy = moveCommand->GetNewMy(); - qCDebug(vUndo, "Label new Mx %f", m_newMx); - qCDebug(vUndo, "Label new My %f", m_newMy); + m_newPos = moveCommand->GetNewPos(); + qCDebug(vUndo, "Label new Mx %f", m_newPos.x()); + qCDebug(vUndo, "Label new My %f", m_newPos.y()); return true; } @@ -95,16 +91,22 @@ int OperationMoveLabel::id() const } //--------------------------------------------------------------------------------------------------------------------- -void OperationMoveLabel::Do(double mx, double my) +void OperationMoveLabel::Do(const QPointF &pos) { - qCDebug(vUndo, "New mx %f", mx); - qCDebug(vUndo, "New my %f", my); + qCDebug(vUndo, "New mx %f", pos.x()); + qCDebug(vUndo, "New my %f", pos.y()); QDomElement domElement = GetDestinationObject(m_idTool, nodeId); if (not domElement.isNull() && domElement.isElement()) { - doc->SetAttribute(domElement, AttrMx, QString().setNum(qApp->fromPixel(mx))); - doc->SetAttribute(domElement, AttrMy, QString().setNum(qApp->fromPixel(my))); + 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(m_idTool))) + { + tool->DoChangePosition(nodeId, pos); + } + VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView()); } else { diff --git a/src/libs/vtools/undocommands/label/operationmovelabel.h b/src/libs/vtools/undocommands/label/operationmovelabel.h index c0918c88d..bea9cd336 100644 --- a/src/libs/vtools/undocommands/label/operationmovelabel.h +++ b/src/libs/vtools/undocommands/label/operationmovelabel.h @@ -40,21 +40,22 @@ class OperationMoveLabel : public MoveAbstractLabel { - Q_OBJECT public: - OperationMoveLabel(quint32 idTool, VAbstractPattern *doc, double x, double y, quint32 idPoint, + OperationMoveLabel(quint32 idTool, VAbstractPattern *doc, const QPointF &pos, quint32 idPoint, QUndoCommand *parent = nullptr); - virtual ~OperationMoveLabel(); + virtual ~OperationMoveLabel()=default; virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE; virtual int id() const Q_DECL_OVERRIDE; quint32 GetToolId() const; protected: - virtual void Do(double mx, double my) Q_DECL_OVERRIDE; + virtual void Do(const QPointF &pos) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(OperationMoveLabel) quint32 m_idTool; + //Need for resizing scene rect + QGraphicsScene *m_scene; }; //---------------------------------------------------------------------------------------------------------------------