Fixed broken redo/undo command moving of a label.
--HG-- branch : develop
This commit is contained in:
parent
0c9b8453bf
commit
2339a95585
|
@ -160,6 +160,33 @@ void VToolDoublePoint::FullUpdateFromFile()
|
|||
SetVisualization();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VToolDoublePoint::DoChangePosition(quint32 id, qreal mx, qreal my)
|
||||
{
|
||||
if (id == p1id)
|
||||
{
|
||||
VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject<VPointF>(p1id));
|
||||
point->setMx(mx);
|
||||
point->setMy(my);
|
||||
VAbstractTool::data.UpdateGObject(p1id, point);
|
||||
firstPoint->blockSignals(true);
|
||||
firstPoint->setPos(QPointF(mx, my));
|
||||
firstPoint->blockSignals(false);
|
||||
RefreshLine(p1id);
|
||||
}
|
||||
else if (id == p2id)
|
||||
{
|
||||
VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject<VPointF>(p2id));
|
||||
point->setMx(mx);
|
||||
point->setMy(my);
|
||||
VAbstractTool::data.UpdateGObject(p2id, point);
|
||||
secondPoint->blockSignals(true);
|
||||
secondPoint->setPos(QPointF(mx, my));
|
||||
secondPoint->blockSignals(false);
|
||||
RefreshLine(p2id);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VToolDoublePoint::UpdateNamePosition(quint32 id)
|
||||
{
|
||||
|
@ -167,14 +194,17 @@ void VToolDoublePoint::UpdateNamePosition(quint32 id)
|
|||
{
|
||||
const VPointF *p1 = VAbstractTool::data.GeometricObject<VPointF>(p1id).data();
|
||||
|
||||
auto moveLabel = new MoveDoubleLabel(doc, p1->mx(), p1->my(), DoublePoint::FirstPoint, this->id, scene());
|
||||
auto moveLabel = new MoveDoubleLabel(doc, p1->mx(), p1->my(), DoublePoint::FirstPoint, this->id, p1id, scene());
|
||||
connect(moveLabel, &MoveDoubleLabel::ChangePosition, this, &VToolDoublePoint::DoChangePosition);
|
||||
qApp->getUndoStack()->push(moveLabel);
|
||||
}
|
||||
else if (id == p2id)
|
||||
{
|
||||
const VPointF *p2 = VAbstractTool::data.GeometricObject<VPointF>(p2id).data();
|
||||
|
||||
auto moveLabel = new MoveDoubleLabel(doc, p2->mx(), p2->my(), DoublePoint::SecondPoint, this->id, scene());
|
||||
auto moveLabel = new MoveDoubleLabel(doc, p2->mx(), p2->my(), DoublePoint::SecondPoint, this->id, p2id,
|
||||
scene());
|
||||
connect(moveLabel, &MoveDoubleLabel::ChangePosition, this, &VToolDoublePoint::DoChangePosition);
|
||||
qApp->getUndoStack()->push(moveLabel);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,6 +68,7 @@ public slots:
|
|||
void Point1Choosed();
|
||||
void Point2Choosed();
|
||||
virtual void FullUpdateFromFile() Q_DECL_OVERRIDE;
|
||||
virtual void DoChangePosition(quint32 id, qreal mx, qreal my) Q_DECL_OVERRIDE;
|
||||
|
||||
protected:
|
||||
VSimplePoint *firstPoint;
|
||||
|
|
|
@ -129,6 +129,7 @@ void VToolSinglePoint::UpdateNamePosition(quint32 id)
|
|||
{
|
||||
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id);
|
||||
auto moveLabel = new MoveLabel(doc, point->mx(), point->my(), id, scene());
|
||||
connect(moveLabel, &MoveLabel::ChangePosition, this, &VToolSinglePoint::DoChangePosition);
|
||||
qApp->getUndoStack()->push(moveLabel);
|
||||
}
|
||||
|
||||
|
@ -321,3 +322,16 @@ void VToolSinglePoint::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &o
|
|||
doc->SetAttribute(tag, AttrMx, qApp->fromPixel(point->mx()));
|
||||
doc->SetAttribute(tag, AttrMy, qApp->fromPixel(point->my()));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VToolSinglePoint::DoChangePosition(quint32 id, qreal mx, qreal my)
|
||||
{
|
||||
VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject<VPointF>(id));
|
||||
point->setMx(mx);
|
||||
point->setMy(my);
|
||||
VAbstractTool::data.UpdateGObject(id, point);
|
||||
namePoint->blockSignals(true);
|
||||
namePoint->setPos(QPointF(mx, my));
|
||||
namePoint->blockSignals(false);
|
||||
RefreshLine(id);
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ public slots:
|
|||
virtual void EnableToolMove(bool move) Q_DECL_OVERRIDE;
|
||||
void PointChoosed();
|
||||
virtual void FullUpdateFromFile() Q_DECL_OVERRIDE;
|
||||
virtual void DoChangePosition(quint32 id, qreal mx, qreal my) Q_DECL_OVERRIDE;
|
||||
protected:
|
||||
/** @brief radius radius circle. */
|
||||
qreal radius;
|
||||
|
|
|
@ -48,12 +48,14 @@ 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);
|
||||
void SetPointName(quint32 id, const QString &name);
|
||||
|
||||
template <typename T>
|
||||
void ChangePosition(T *item, quint32 id, const QPointF &pos);
|
||||
void ChangePosition(T *item, quint32 id, const QPointF &pos);
|
||||
|
||||
|
||||
virtual void UpdateNamePosition(quint32 id)=0;
|
||||
virtual void RefreshLine(quint32 id)=0;
|
||||
|
@ -111,12 +113,8 @@ void VAbstractPoint::SetToolEnabled(T *item, bool enabled)
|
|||
template <typename T>
|
||||
void VAbstractPoint::ChangePosition(T *item, quint32 id, const QPointF &pos)
|
||||
{
|
||||
VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject<VPointF>(id));
|
||||
const QPointF p = pos - item->pos();
|
||||
point->setMx(p.x());
|
||||
point->setMy(p.y());
|
||||
VAbstractTool::data.UpdateGObject(id, point);
|
||||
RefreshLine(id);
|
||||
DoChangePosition(id, p.x(), p.y());
|
||||
UpdateNamePosition(id);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,11 +35,13 @@
|
|||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
MoveDoubleLabel::MoveDoubleLabel(VAbstractPattern *doc, const double &x, const double &y, DoublePoint type,
|
||||
const quint32 &id, QGraphicsScene *scene, QUndoCommand *parent)
|
||||
quint32 tooId, quint32 pointId, QGraphicsScene *scene, QUndoCommand *parent)
|
||||
: VUndoCommand(QDomElement(), doc, parent),
|
||||
oldMx(0.0), oldMy(0.0),
|
||||
newMx(x), newMy(y),
|
||||
scene(scene), type(type)
|
||||
scene(scene), type(type),
|
||||
pointId(pointId),
|
||||
isRedo(false)
|
||||
{
|
||||
if (type == DoublePoint::FirstPoint)
|
||||
{
|
||||
|
@ -49,7 +51,7 @@ MoveDoubleLabel::MoveDoubleLabel(VAbstractPattern *doc, const double &x, const d
|
|||
{
|
||||
setText(tr("move the second dart label"));
|
||||
}
|
||||
nodeId = id;
|
||||
nodeId = tooId;
|
||||
qCDebug(vUndo, "Point id %u", nodeId);
|
||||
|
||||
if (type == DoublePoint::FirstPoint)
|
||||
|
@ -64,7 +66,7 @@ MoveDoubleLabel::MoveDoubleLabel(VAbstractPattern *doc, const double &x, const d
|
|||
}
|
||||
|
||||
SCASSERT(scene != nullptr);
|
||||
QDomElement domElement = doc->elementById(id);
|
||||
QDomElement domElement = doc->elementById(tooId);
|
||||
if (domElement.isElement())
|
||||
{
|
||||
if (type == DoublePoint::FirstPoint)
|
||||
|
@ -106,6 +108,8 @@ void MoveDoubleLabel::undo()
|
|||
qCDebug(vUndo, "Undo.");
|
||||
|
||||
Do(oldMx, oldMy);
|
||||
isRedo = true;
|
||||
emit ChangePosition(pointId, oldMx, oldMy);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -114,6 +118,10 @@ void MoveDoubleLabel::redo()
|
|||
qCDebug(vUndo, "Redo.");
|
||||
|
||||
Do(newMx, newMy);
|
||||
if (isRedo)
|
||||
{
|
||||
emit ChangePosition(pointId, newMx, newMy);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -122,7 +130,8 @@ bool MoveDoubleLabel::mergeWith(const QUndoCommand *command)
|
|||
const MoveDoubleLabel *moveCommand = static_cast<const MoveDoubleLabel *>(command);
|
||||
SCASSERT(moveCommand != nullptr);
|
||||
|
||||
if (moveCommand->getPointId() != nodeId || moveCommand->getPointType() != type)
|
||||
if (moveCommand->getPointId() != nodeId || moveCommand->getPointType() != type ||
|
||||
moveCommand->getLabelId() != pointId)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -149,6 +158,12 @@ int MoveDoubleLabel::id() const
|
|||
return static_cast<int>(UndoCommand::MoveDoubleLabel);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
quint32 MoveDoubleLabel::getLabelId() const
|
||||
{
|
||||
return pointId;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void MoveDoubleLabel::Do(double mx, double my)
|
||||
{
|
||||
|
|
|
@ -40,17 +40,20 @@ class MoveDoubleLabel : public VUndoCommand
|
|||
Q_OBJECT
|
||||
public:
|
||||
MoveDoubleLabel(VAbstractPattern *doc, const double &x, const double &y, DoublePoint type,
|
||||
const quint32 &id, QGraphicsScene *scene, QUndoCommand *parent = 0);
|
||||
quint32 tooId, quint32 pointId, QGraphicsScene *scene, QUndoCommand *parent = 0);
|
||||
virtual ~MoveDoubleLabel() Q_DECL_OVERRIDE;
|
||||
virtual void undo() Q_DECL_OVERRIDE;
|
||||
virtual void redo() Q_DECL_OVERRIDE;
|
||||
virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE;
|
||||
virtual int id() const Q_DECL_OVERRIDE;
|
||||
quint32 getPointId() const;
|
||||
quint32 getLabelId() const;
|
||||
double getNewMx() const;
|
||||
double getNewMy() const;
|
||||
DoublePoint getPointType() const;
|
||||
void Do(double mx, double my);
|
||||
signals:
|
||||
void ChangePosition(quint32 id, qreal mx, qreal my);
|
||||
private:
|
||||
Q_DISABLE_COPY(MoveDoubleLabel)
|
||||
double oldMx;
|
||||
|
@ -59,6 +62,8 @@ private:
|
|||
double newMy;
|
||||
QGraphicsScene *scene;
|
||||
DoublePoint type;
|
||||
quint32 pointId;
|
||||
bool isRedo;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
MoveLabel::MoveLabel(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, QGraphicsScene *scene,
|
||||
QUndoCommand *parent)
|
||||
: VUndoCommand(QDomElement(), doc, parent), oldMx(0.0), oldMy(0.0), newMx(x), newMy(y), scene(scene)
|
||||
: VUndoCommand(QDomElement(), doc, parent), oldMx(0.0), oldMy(0.0), newMx(x), newMy(y), isRedo(false), scene(scene)
|
||||
{
|
||||
setText(tr("move point label"));
|
||||
nodeId = id;
|
||||
|
@ -72,6 +72,8 @@ void MoveLabel::undo()
|
|||
qCDebug(vUndo, "Undo.");
|
||||
|
||||
Do(oldMx, oldMy);
|
||||
isRedo = true;
|
||||
emit ChangePosition(nodeId, oldMx, oldMy);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -80,6 +82,10 @@ void MoveLabel::redo()
|
|||
qCDebug(vUndo, "Redo.");
|
||||
|
||||
Do(newMx, newMy);
|
||||
if (isRedo)
|
||||
{
|
||||
emit ChangePosition(nodeId, newMx, newMy);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -48,12 +48,15 @@ public:
|
|||
double getNewMx() const;
|
||||
double getNewMy() const;
|
||||
void Do(double mx, double my);
|
||||
signals:
|
||||
void ChangePosition(quint32 id, qreal mx, qreal my);
|
||||
private:
|
||||
Q_DISABLE_COPY(MoveLabel)
|
||||
double oldMx;
|
||||
double oldMy;
|
||||
double newMx;
|
||||
double newMy;
|
||||
bool isRedo;
|
||||
QGraphicsScene *scene;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user