Removed redundant calls UpdateGObject(). Undocommand for piece label.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-10-24 20:25:51 +03:00
parent 89a2323944
commit 7fce20c98e
15 changed files with 39 additions and 48 deletions

View File

@ -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)) if (operatedObjects.contains(id))
{ {
@ -98,7 +98,6 @@ void VAbstractOperation::DoChangePosition(quint32 id, const QPointF &pos)
QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id); QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id);
point->setMx(pos.x()); point->setMx(pos.x());
point->setMy(pos.y()); point->setMy(pos.y());
VAbstractTool::data.UpdateGObject(id, point);
item->RefreshPointGeometry(*(point.data())); item->RefreshPointGeometry(*(point.data()));
} }
} }

View File

@ -87,7 +87,7 @@ public:
virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; 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 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 bool IsLabelVisible(quint32 id) const Q_DECL_OVERRIDE;
virtual void SetLabelVisible(quint32 id, bool visible) Q_DECL_OVERRIDE; virtual void SetLabelVisible(quint32 id, bool visible) Q_DECL_OVERRIDE;

View File

@ -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) if (id == p1id)
{ {
QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(p1id); QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(p1id);
point->setMx(pos.x()); point->setMx(pos.x());
point->setMy(pos.y()); point->setMy(pos.y());
VAbstractTool::data.UpdateGObject(p1id, point);
firstPoint->RefreshPointGeometry(*(point.data())); firstPoint->RefreshPointGeometry(*(point.data()));
} }
else if (id == p2id) else if (id == p2id)
@ -235,7 +234,6 @@ void VToolDoublePoint::DoChangePosition(quint32 id, const QPointF &pos)
QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(p2id); QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(p2id);
point->setMx(pos.x()); point->setMx(pos.x());
point->setMy(pos.y()); point->setMy(pos.y());
VAbstractTool::data.UpdateGObject(p2id, point);
secondPoint->RefreshPointGeometry(*(point.data())); secondPoint->RefreshPointGeometry(*(point.data()));
} }
} }

View File

@ -63,7 +63,7 @@ public:
void setNameP2(const QString &name); void setNameP2(const QString &name);
virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; 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 bool IsLabelVisible(quint32 id) const Q_DECL_OVERRIDE;
virtual void SetLabelVisible(quint32 id, bool visible) Q_DECL_OVERRIDE; virtual void SetLabelVisible(quint32 id, bool visible) Q_DECL_OVERRIDE;

View File

@ -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) if (id == m_id)
{ {
QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id); QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id);
point->setMx(pos.x()); point->setMx(pos.x());
point->setMy(pos.y()); point->setMy(pos.y());
VAbstractTool::data.UpdateGObject(id, point);
m_namePoint->blockSignals(true); m_namePoint->blockSignals(true);
m_namePoint->setPos(pos); m_namePoint->setPos(pos);
m_namePoint->blockSignals(false); m_namePoint->blockSignals(false);

View File

@ -79,7 +79,7 @@ public:
void SetEnabled(bool enabled); void SetEnabled(bool enabled);
virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; 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 bool IsLabelVisible(quint32 id) const Q_DECL_OVERRIDE;
virtual void SetLabelVisible(quint32 id, bool visible) Q_DECL_OVERRIDE; virtual void SetLabelVisible(quint32 id, bool visible) Q_DECL_OVERRIDE;

View File

@ -269,10 +269,3 @@ void VDrawTool::SetLabelVisible(quint32 id, bool visible)
Q_UNUSED(id) Q_UNUSED(id)
Q_UNUSED(visible) Q_UNUSED(visible)
} }
//---------------------------------------------------------------------------------------------------------------------
void VDrawTool::DoChangePosition(quint32 id, const QPointF &pos)
{
Q_UNUSED(id)
Q_UNUSED(pos)
}

View File

@ -69,7 +69,6 @@ public:
virtual bool IsLabelVisible(quint32 id) const; virtual bool IsLabelVisible(quint32 id) const;
virtual void SetLabelVisible(quint32 id, bool visible); virtual void SetLabelVisible(quint32 id, bool visible);
virtual void DoChangePosition(quint32 id, const QPointF &pos);
signals: signals:
void ChangedToolSelection(bool selected, quint32 object, quint32 tool); void ChangedToolSelection(bool selected, quint32 object, quint32 tool);

View File

@ -54,6 +54,7 @@
#include "../vabstracttool.h" #include "../vabstracttool.h"
#include "../vdatatool.h" #include "../vdatatool.h"
#include "vabstractnode.h" #include "vabstractnode.h"
#include "../../undocommands/label/movelabel.h"
const QString VNodePoint::ToolType = QStringLiteral("modeling"); const QString VNodePoint::ToolType = QStringLiteral("modeling");
@ -126,6 +127,21 @@ QString VNodePoint::getTagName() const
return VAbstractPattern::TagPoint; return VAbstractPattern::TagPoint;
} }
//---------------------------------------------------------------------------------------------------------------------
void VNodePoint::ChangeLabelPosition(quint32 id, const QPointF &pos)
{
if (id == m_id)
{
QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(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() void VNodePoint::PointChoosed()
{ {
@ -199,30 +215,7 @@ void VNodePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
*/ */
void VNodePoint::NameChangePosition(const QPointF &pos) void VNodePoint::NameChangePosition(const QPointF &pos)
{ {
VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject<VPointF>(m_id)); qApp->getUndoStack()->push(new MoveLabel(doc, pos - this->pos(), 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();
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -57,6 +57,8 @@ public:
enum { Type = UserType + static_cast<int>(Tool::NodePoint)}; enum { Type = UserType + static_cast<int>(Tool::NodePoint)};
virtual QString getTagName() const Q_DECL_OVERRIDE; virtual QString getTagName() const Q_DECL_OVERRIDE;
virtual void ChangeLabelPosition(quint32 id, const QPointF &pos) Q_DECL_OVERRIDE;
signals: signals:
/** /**
* @brief ShowContextMenu emit when need show tool context menu. * @brief ShowContextMenu emit when need show tool context menu.
@ -77,7 +79,6 @@ protected:
virtual void AddToFile() Q_DECL_OVERRIDE; virtual void AddToFile() Q_DECL_OVERRIDE;
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE; virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
virtual void mouseReleaseEvent ( 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 ShowNode() Q_DECL_OVERRIDE;
virtual void HideNode() Q_DECL_OVERRIDE; virtual void HideNode() Q_DECL_OVERRIDE;
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) Q_DECL_OVERRIDE; virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) Q_DECL_OVERRIDE;

View File

@ -397,6 +397,13 @@ QMap<QString, quint32> VAbstractTool::PointsList() const
return list; return list;
} }
//---------------------------------------------------------------------------------------------------------------------
void VAbstractTool::ChangeLabelPosition(quint32 id, const QPointF &pos)
{
Q_UNUSED(id)
Q_UNUSED(pos)
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VAbstractTool::ToolSelectionType(const SelectionType &type) void VAbstractTool::ToolSelectionType(const SelectionType &type)
{ {

View File

@ -108,6 +108,7 @@ public:
QMap<QString, quint32> PointsList() const; QMap<QString, quint32> PointsList() const;
virtual QString getTagName() const =0; virtual QString getTagName() const =0;
virtual void ShowVisualization(bool show) =0; virtual void ShowVisualization(bool show) =0;
virtual void ChangeLabelPosition(quint32 id, const QPointF &pos);
template<typename T> template<typename T>
static quint32 CreateNode(VContainer *data, quint32 id); static quint32 CreateNode(VContainer *data, quint32 id);

View File

@ -146,7 +146,7 @@ void MoveDoubleLabel::Do(const QPointF &pos)
if (VDrawTool *tool = qobject_cast<VDrawTool *>(VAbstractPattern::getTool(m_idTool))) if (VDrawTool *tool = qobject_cast<VDrawTool *>(VAbstractPattern::getTool(m_idTool)))
{ {
tool->DoChangePosition(nodeId, pos); tool->ChangeLabelPosition(nodeId, pos);
} }
VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView()); VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView());
} }

View File

@ -37,7 +37,8 @@
#include "../vmisc/vabstractapplication.h" #include "../vmisc/vabstractapplication.h"
#include "../vundocommand.h" #include "../vundocommand.h"
#include "moveabstractlabel.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) 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, AttrMx, QString().setNum(qApp->fromPixel(pos.x())));
doc->SetAttribute(domElement, AttrMy, QString().setNum(qApp->fromPixel(pos.y()))); doc->SetAttribute(domElement, AttrMy, QString().setNum(qApp->fromPixel(pos.y())));
if (VDrawTool *tool = qobject_cast<VDrawTool *>(VAbstractPattern::getTool(nodeId))) if (VAbstractTool *tool = qobject_cast<VAbstractTool *>(VAbstractPattern::getTool(nodeId)))
{ {
tool->DoChangePosition(nodeId, pos); tool->ChangeLabelPosition(nodeId, pos);
} }
VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView()); VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView());
} }

View File

@ -104,7 +104,7 @@ void OperationMoveLabel::Do(const QPointF &pos)
if (VDrawTool *tool = qobject_cast<VDrawTool *>(VAbstractPattern::getTool(m_idTool))) if (VDrawTool *tool = qobject_cast<VDrawTool *>(VAbstractPattern::getTool(m_idTool)))
{ {
tool->DoChangePosition(nodeId, pos); tool->ChangeLabelPosition(nodeId, pos);
} }
VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView()); VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView());
} }