From f7c75111cea31bd5417df991b7aa93f9ebc8f92f Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 20 Sep 2017 12:10:57 +0300 Subject: [PATCH] Added support for operation tools. --HG-- branch : feature --- src/libs/ifc/schema/pattern/v0.6.3.xsd | 1 + src/libs/vgeometry/vpointf.cpp | 12 ++- .../operation/flipping/vabstractflipping.cpp | 15 +-- .../operation/flipping/vabstractflipping.h | 2 +- .../operation/vabstractoperation.cpp | 48 +++++++++ .../drawTools/operation/vabstractoperation.h | 5 + .../tools/drawTools/operation/vtoolmove.cpp | 17 ++- .../tools/drawTools/operation/vtoolmove.h | 2 +- .../drawTools/operation/vtoolrotation.cpp | 13 +-- .../tools/drawTools/operation/vtoolrotation.h | 2 +- .../undocommands/label/operationmovelabel.cpp | 40 ------- .../undocommands/label/operationmovelabel.h | 2 - .../undocommands/label/operationshowlabel.cpp | 101 ++++++++++++++++++ .../undocommands/label/operationshowlabel.h | 57 ++++++++++ .../undocommands/label/showdoublelabel.cpp | 4 +- src/libs/vtools/undocommands/undocommands.pri | 6 +- src/libs/vtools/undocommands/vundocommand.cpp | 40 +++++++ src/libs/vtools/undocommands/vundocommand.h | 2 + 18 files changed, 295 insertions(+), 74 deletions(-) create mode 100644 src/libs/vtools/undocommands/label/operationshowlabel.cpp create mode 100644 src/libs/vtools/undocommands/label/operationshowlabel.h diff --git a/src/libs/ifc/schema/pattern/v0.6.3.xsd b/src/libs/ifc/schema/pattern/v0.6.3.xsd index ff5e59890..96f6f07fe 100644 --- a/src/libs/ifc/schema/pattern/v0.6.3.xsd +++ b/src/libs/ifc/schema/pattern/v0.6.3.xsd @@ -252,6 +252,7 @@ + diff --git a/src/libs/vgeometry/vpointf.cpp b/src/libs/vgeometry/vpointf.cpp index 369d2cb12..df1316064 100644 --- a/src/libs/vgeometry/vpointf.cpp +++ b/src/libs/vgeometry/vpointf.cpp @@ -111,21 +111,27 @@ VPointF::operator QPointF() const VPointF VPointF::Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix) const { const QPointF p = RotatePF(originPoint, toQPointF(), degrees); - return VPointF(p, name() + prefix, mx(), my()); + VPointF rotated(p, name() + prefix, mx(), my()); + rotated.SetShowLabel(IsShowLabel()); + return rotated; } //--------------------------------------------------------------------------------------------------------------------- VPointF VPointF::Flip(const QLineF &axis, const QString &prefix) const { const QPointF p = FlipPF(axis, toQPointF()); - return VPointF(p, name() + prefix, mx(), my()); + VPointF flipped(p, name() + prefix, mx(), my()); + flipped.SetShowLabel(IsShowLabel()); + return flipped; } //--------------------------------------------------------------------------------------------------------------------- VPointF VPointF::Move(qreal length, qreal angle, const QString &prefix) const { const QPointF p = MovePF(toQPointF(), length, angle); - return VPointF(p, name() + prefix, mx(), my()); + VPointF moved(p, name() + prefix, mx(), my()); + moved.SetShowLabel(IsShowLabel()); + return moved; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp index 1e1f37e2a..db3342521 100644 --- a/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp @@ -120,8 +120,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") case GOType::Point: { const DestinationItem &item = initData.destination.at(i); - UpdatePoint(initData.id, idObject, fPoint, sPoint, initData.suffix, initData.data, item.id, item.mx, - item.my); + UpdatePoint(initData.id, idObject, fPoint, sPoint, initData.suffix, initData.data, item); break; } case GOType::Arc: @@ -171,6 +170,7 @@ DestinationItem VAbstractFlipping::CreatePoint(quint32 idTool, quint32 idItem, c DestinationItem item; item.mx = rotated.mx(); item.my = rotated.my(); + item.showLabel = rotated.IsShowLabel(); item.id = data->AddGObject(new VPointF(rotated)); return item; } @@ -187,15 +187,16 @@ DestinationItem VAbstractFlipping::CreateArc(quint32 idTool, quint32 idItem, con //--------------------------------------------------------------------------------------------------------------------- void VAbstractFlipping::UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, - const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id, - qreal mx, qreal my) + const QPointF &secondPoint, const QString &suffix, VContainer *data, + const DestinationItem &item) { const QSharedPointer point = data->GeometricObject(idItem); VPointF rotated = point->Flip(QLineF(firstPoint, secondPoint), suffix); rotated.setIdObject(idTool); - rotated.setMx(mx); - rotated.setMy(my); - data->UpdateGObject(id, new VPointF(rotated)); + rotated.setMx(item.mx); + rotated.setMy(item.my); + rotated.SetShowLabel(item.showLabel); + data->UpdateGObject(item.id, new VPointF(rotated)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.h b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.h index f678ba646..fe112f06d 100644 --- a/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.h +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.h @@ -62,7 +62,7 @@ protected: const QPointF &secondPoint, const QString &suffix, VContainer *data); static void UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, - const QString &suffix, VContainer *data, quint32 id, qreal mx, qreal my); + const QString &suffix, VContainer *data, const DestinationItem &item); template static void UpdateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id); diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp index 52b2fa0d3..8f64535c4 100644 --- a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp @@ -28,6 +28,7 @@ #include "vabstractoperation.h" #include "../../../undocommands/label/operationmovelabel.h" +#include "../../../undocommands/label/operationshowlabel.h" #include "../vgeometry/vpointf.h" const QString VAbstractOperation::TagItem = QStringLiteral("item"); @@ -84,6 +85,38 @@ void VAbstractOperation::paint(QPainter *painter, const QStyleOptionGraphicsItem Q_UNUSED(widget) } +//--------------------------------------------------------------------------------------------------------------------- +bool VAbstractOperation::IsLabelVisible(quint32 id) const +{ + if (operatedObjects.contains(id)) + { + VAbstractSimple *obj = operatedObjects.value(id); + if (obj && obj->GetType() == GOType::Point) + { + return VAbstractTool::data.GeometricObject(id)->IsShowLabel(); + } + } + + return false; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::SetLabelVisible(quint32 id, bool visible) +{ + if (operatedObjects.contains(id)) + { + VAbstractSimple *obj = operatedObjects.value(id); + if (obj && obj->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(obj); + SCASSERT(item != nullptr) + const QSharedPointer point = VAbstractTool::data.GeometricObject(id); + point->SetShowLabel(visible); + item->RefreshPointGeometry(*point); + } + } +} + //--------------------------------------------------------------------------------------------------------------------- void VAbstractOperation::ExtractData(const QDomElement &domElement, VAbstractOperationInitData &initData) { @@ -118,6 +151,7 @@ void VAbstractOperation::ExtractData(const QDomElement &domElement, VAbstractOpe d.id = VDomDocument::GetParametrUInt(element, AttrIdObject, NULL_ID_STR); d.mx = qApp->toPixel(VDomDocument::GetParametrDouble(element, AttrMx, QString::number(INT_MAX))); d.my = qApp->toPixel(VDomDocument::GetParametrDouble(element, AttrMy, QString::number(INT_MAX))); + d.showLabel = VDomDocument::GetParametrBool(element, AttrShowLabel, trueStr); initData.destination.append(d); } } @@ -426,6 +460,19 @@ void VAbstractOperation::AddToFile() AddToCalculation(domElement); } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::ChangeLabelVisibility(quint32 id, bool visible) +{ + if (operatedObjects.contains(id)) + { + VAbstractSimple *obj = operatedObjects.value(id); + if (obj && obj->GetType() == GOType::Point) + { + qApp->getUndoStack()->push(new OperationShowLabel(doc, m_id, id, visible)); + } + } +} + //--------------------------------------------------------------------------------------------------------------------- void VAbstractOperation::UpdateNamePosition(quint32 id) { @@ -460,6 +507,7 @@ void VAbstractOperation::SaveSourceDestination(QDomElement &tag) { doc->SetAttribute(item, AttrMx, qApp->fromPixel(destination.at(i).mx)); doc->SetAttribute(item, AttrMy, qApp->fromPixel(destination.at(i).my)); + doc->SetAttribute(item, AttrShowLabel, destination.at(i).showLabel); } tagObjects.appendChild(item); diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h index 195c6819b..4e82a5aac 100644 --- a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h @@ -47,6 +47,7 @@ struct DestinationItem quint32 id; qreal mx; qreal my; + bool showLabel; }; struct VAbstractOperationInitData : public VAbstractToolInitData @@ -87,6 +88,9 @@ 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 bool IsLabelVisible(quint32 id) const Q_DECL_OVERRIDE; + virtual void SetLabelVisible(quint32 id, bool visible) Q_DECL_OVERRIDE; + static void ExtractData(const QDomElement &domElement, VAbstractOperationInitData &initData); public slots: virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; @@ -131,6 +135,7 @@ protected: QGraphicsItem *parent = nullptr); virtual void AddToFile() Q_DECL_OVERRIDE; + virtual void ChangeLabelVisibility(quint32 id, bool visible) Q_DECL_OVERRIDE; void UpdateNamePosition(quint32 id); void SaveSourceDestination(QDomElement &tag); diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp index 6b9bad08c..b2c73d7ea 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp @@ -191,12 +191,9 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") switch(static_cast(obj->getType())) { case GOType::Point: - { - const DestinationItem &item = initData.destination.at(i); - UpdatePoint(initData.id, idObject, calcAngle, calcLength, initData.suffix, initData.data, item.id, - item.mx, item.my); + UpdatePoint(initData.id, idObject, calcAngle, calcLength, initData.suffix, initData.data, + initData.destination.at(i)); break; - } case GOType::Arc: UpdateArc(initData.id, idObject, calcAngle, calcLength, initData.suffix, initData.data, initData.destination.at(i).id); @@ -397,6 +394,7 @@ DestinationItem VToolMove::CreatePoint(quint32 idTool, quint32 idItem, qreal ang DestinationItem item; item.mx = moved.mx(); item.my = moved.my(); + item.showLabel = moved.IsShowLabel(); item.id = data->AddGObject(new VPointF(moved)); return item; } @@ -413,14 +411,15 @@ DestinationItem VToolMove::CreateArc(quint32 idTool, quint32 idItem, qreal angle //--------------------------------------------------------------------------------------------------------------------- void VToolMove::UpdatePoint(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix, - VContainer *data, quint32 id, qreal mx, qreal my) + VContainer *data, const DestinationItem &item) { const QSharedPointer point = data->GeometricObject(idItem); VPointF moved = point->Move(length, angle, suffix); moved.setIdObject(idTool); - moved.setMx(mx); - moved.setMy(my); - data->UpdateGObject(id, new VPointF(moved)); + moved.setMx(item.mx); + moved.setMy(item.my); + moved.SetShowLabel(item.showLabel); + data->UpdateGObject(item.id, new VPointF(moved)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolmove.h b/src/libs/vtools/tools/drawTools/operation/vtoolmove.h index b054f54e9..6043ddd6c 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolmove.h +++ b/src/libs/vtools/tools/drawTools/operation/vtoolmove.h @@ -111,7 +111,7 @@ private: const QString &suffix, VContainer *data); static void UpdatePoint(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix, - VContainer *data, quint32 id, qreal mx, qreal my); + VContainer *data, const DestinationItem &item); template static void UpdateItem(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix, VContainer *data, quint32 id); diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp index ae8779bfd..715c6d2b9 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp @@ -208,9 +208,8 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") { case GOType::Point: { - const DestinationItem &item = initData.destination.at(i); UpdatePoint(initData.id, idObject, oPoint, calcAngle, initData.suffix, initData.data, - item.id, item.mx, item.my); + initData.destination.at(i)); break; } case GOType::Arc: @@ -384,6 +383,7 @@ DestinationItem VToolRotation::CreatePoint(quint32 idTool, quint32 idItem, const DestinationItem item; item.mx = rotated.mx(); item.my = rotated.my(); + item.showLabel = rotated.IsShowLabel(); item.id = data->AddGObject(new VPointF(rotated)); return item; } @@ -436,14 +436,15 @@ DestinationItem VToolRotation::CreateCurveWithSegments(quint32 idTool, quint32 i //--------------------------------------------------------------------------------------------------------------------- void VToolRotation::UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, - const QString &suffix, VContainer *data, quint32 id, qreal mx, qreal my) + const QString &suffix, VContainer *data, const DestinationItem &item) { const QSharedPointer point = data->GeometricObject(idItem); VPointF rotated = point->Rotate(origin, angle, suffix); rotated.setIdObject(idTool); - rotated.setMx(mx); - rotated.setMy(my); - data->UpdateGObject(id, new VPointF(rotated)); + rotated.setMx(item.mx); + rotated.setMy(item.my); + rotated.SetShowLabel(item.showLabel); + data->UpdateGObject(item.id, new VPointF(rotated)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h index a660aae95..7d8729d77 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h +++ b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h @@ -111,7 +111,7 @@ private: qreal angle, const QString &suffix, VContainer *data); static void UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, - const QString &suffix, VContainer *data, quint32 id, qreal mx, qreal my); + const QString &suffix, VContainer *data, const DestinationItem &item); template static void UpdateItem(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, const QString &suffix, VContainer *data, quint32 id); diff --git a/src/libs/vtools/undocommands/label/operationmovelabel.cpp b/src/libs/vtools/undocommands/label/operationmovelabel.cpp index 8bdd50f27..5f675054f 100644 --- a/src/libs/vtools/undocommands/label/operationmovelabel.cpp +++ b/src/libs/vtools/undocommands/label/operationmovelabel.cpp @@ -31,7 +31,6 @@ #include #include -#include "../../tools/drawTools/operation/vtoolrotation.h" #include "../ifc/xml/vabstractpattern.h" #include "../ifc/ifcdef.h" #include "../vmisc/logging.h" @@ -112,42 +111,3 @@ void OperationMoveLabel::Do(double mx, double my) qCDebug(vUndo, "Can't find point with id = %u.", nodeId); } } - -//--------------------------------------------------------------------------------------------------------------------- -QDomElement OperationMoveLabel::GetDestinationObject(quint32 idTool, quint32 idPoint) const -{ - const QDomElement tool = doc->elementById(idTool, VAbstractPattern::TagOperation); - if (tool.isElement()) - { - QDomElement correctDest; - const QDomNodeList nodeList = tool.childNodes(); - for (qint32 i = 0; i < nodeList.size(); ++i) - { - const QDomElement dest = nodeList.at(i).toElement(); - if (not dest.isNull() && dest.isElement() && dest.tagName() == VAbstractOperation::TagDestination) - { - correctDest = dest; - break; - } - } - - if (not correctDest.isNull()) - { - const QDomNodeList destObjects = correctDest.childNodes(); - for (qint32 i = 0; i < destObjects.size(); ++i) - { - const QDomElement obj = destObjects.at(i).toElement(); - if (not obj.isNull() && obj.isElement()) - { - const quint32 id = doc->GetParametrUInt(obj, AttrIdObject, NULL_ID_STR); - if (idPoint == id) - { - return obj; - } - } - } - } - } - - return QDomElement(); -} diff --git a/src/libs/vtools/undocommands/label/operationmovelabel.h b/src/libs/vtools/undocommands/label/operationmovelabel.h index cc516025a..c0918c88d 100644 --- a/src/libs/vtools/undocommands/label/operationmovelabel.h +++ b/src/libs/vtools/undocommands/label/operationmovelabel.h @@ -55,8 +55,6 @@ protected: private: Q_DISABLE_COPY(OperationMoveLabel) quint32 m_idTool; - - QDomElement GetDestinationObject(quint32 idTool, quint32 idPoint) const; }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/undocommands/label/operationshowlabel.cpp b/src/libs/vtools/undocommands/label/operationshowlabel.cpp new file mode 100644 index 000000000..12bb6e0b6 --- /dev/null +++ b/src/libs/vtools/undocommands/label/operationshowlabel.cpp @@ -0,0 +1,101 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 20 9, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2017 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "operationshowlabel.h" + +#include + +#include "../ifc/xml/vabstractpattern.h" +#include "../vmisc/logging.h" +#include "../vwidgets/vmaingraphicsview.h" +#include "../vmisc/vabstractapplication.h" +#include "../vtools/tools/drawTools/vdrawtool.h" + +//--------------------------------------------------------------------------------------------------------------------- +OperationShowLabel::OperationShowLabel(VAbstractPattern *doc, quint32 idTool, quint32 idPoint, bool visible, + QUndoCommand *parent) + : VUndoCommand(QDomElement(), doc, parent), + m_visible(visible), + m_oldVisible(not visible), + m_scene(qApp->getCurrentScene()), + m_idTool(idTool) +{ + nodeId = idPoint; + qCDebug(vUndo, "Point id %u", nodeId); + + setText(tr("toggle label")); + + qCDebug(vUndo, "Tool id %u", m_idTool); + + const QDomElement element = GetDestinationObject(m_idTool, nodeId); + if (element.isElement()) + { + m_oldVisible = doc->GetParametrBool(element, AttrShowLabel, trueStr); + } + else + { + qCDebug(vUndo, "Can't find point with id = %u.", nodeId); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void OperationShowLabel::undo() +{ + qCDebug(vUndo, "Undo."); + + Do(m_oldVisible); +} + +//--------------------------------------------------------------------------------------------------------------------- +void OperationShowLabel::redo() +{ + qCDebug(vUndo, "Redo."); + + Do(m_visible); +} + +//--------------------------------------------------------------------------------------------------------------------- +void OperationShowLabel::Do(bool visible) +{ + QDomElement domElement = GetDestinationObject(m_idTool, nodeId); + if (not domElement.isNull() && domElement.isElement()) + { + doc->SetAttribute(domElement, AttrShowLabel, visible); + + if (VDrawTool *tool = qobject_cast(VAbstractPattern::getTool(m_idTool))) + { + tool->SetLabelVisible(nodeId, visible); + } + VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView()); + } + else + { + qCDebug(vUndo, "Can't find point with id = %u.", nodeId); + } +} + diff --git a/src/libs/vtools/undocommands/label/operationshowlabel.h b/src/libs/vtools/undocommands/label/operationshowlabel.h new file mode 100644 index 000000000..a7ae07e69 --- /dev/null +++ b/src/libs/vtools/undocommands/label/operationshowlabel.h @@ -0,0 +1,57 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 20 9, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2017 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef OPERATIONSHOWLABEL_H +#define OPERATIONSHOWLABEL_H + +#include "../vundocommand.h" + +class QGraphicsScene; + +class OperationShowLabel : public VUndoCommand +{ +public: + OperationShowLabel(VAbstractPattern *doc, quint32 idTool, quint32 idPoint, bool visible, + QUndoCommand *parent = nullptr); + virtual ~OperationShowLabel()=default; + + virtual void undo() Q_DECL_OVERRIDE; + virtual void redo() Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(OperationShowLabel) + bool m_visible; + bool m_oldVisible; + //Need for resizing scene rect + QGraphicsScene *m_scene; + quint32 m_idTool; + + void Do(bool visible); +}; + +#endif // OPERATIONSHOWLABEL_H diff --git a/src/libs/vtools/undocommands/label/showdoublelabel.cpp b/src/libs/vtools/undocommands/label/showdoublelabel.cpp index 710a9e130..356c33a89 100644 --- a/src/libs/vtools/undocommands/label/showdoublelabel.cpp +++ b/src/libs/vtools/undocommands/label/showdoublelabel.cpp @@ -51,11 +51,11 @@ ShowDoubleLabel::ShowDoubleLabel(VAbstractPattern *doc, quint32 toolId, quint32 if (type == ShowDoublePoint::FirstPoint) { - setText(tr("show the first dart label")); + setText(tr("toggle the first dart label")); } else { - setText(tr("show the second dart label")); + setText(tr("togggle the second dart label")); } const QDomElement domElement = doc->elementById(m_idTool, VAbstractPattern::TagPoint); diff --git a/src/libs/vtools/undocommands/undocommands.pri b/src/libs/vtools/undocommands/undocommands.pri index d689b7c92..42252b14d 100644 --- a/src/libs/vtools/undocommands/undocommands.pri +++ b/src/libs/vtools/undocommands/undocommands.pri @@ -26,7 +26,8 @@ HEADERS += \ $$PWD/togglepieceinlayout.h \ $$PWD/savepiecepathoptions.h \ $$PWD/label/showlabel.h \ - $$PWD/label/showdoublelabel.h + $$PWD/label/showdoublelabel.h \ + $$PWD/label/operationshowlabel.h SOURCES += \ $$PWD/addtocalc.cpp \ @@ -53,4 +54,5 @@ SOURCES += \ $$PWD/togglepieceinlayout.cpp \ $$PWD/savepiecepathoptions.cpp \ $$PWD/label/showlabel.cpp \ - $$PWD/label/showdoublelabel.cpp + $$PWD/label/showdoublelabel.cpp \ + $$PWD/label/operationshowlabel.cpp diff --git a/src/libs/vtools/undocommands/vundocommand.cpp b/src/libs/vtools/undocommands/vundocommand.cpp index a1858d3be..c5b4101dd 100644 --- a/src/libs/vtools/undocommands/vundocommand.cpp +++ b/src/libs/vtools/undocommands/vundocommand.cpp @@ -36,6 +36,7 @@ #include "../vmisc/customevents.h" #include "../vpatterndb/vnodedetail.h" #include "../vpatterndb/vpiecenode.h" +#include "../tools/drawTools/operation/vabstractoperation.h" Q_LOGGING_CATEGORY(vUndo, "v.undo") @@ -143,3 +144,42 @@ void VUndoCommand::DecrementReferences(const QVector &nodes) const DecrementReferences(n); } + +//--------------------------------------------------------------------------------------------------------------------- +QDomElement VUndoCommand::GetDestinationObject(quint32 idTool, quint32 idPoint) const +{ + const QDomElement tool = doc->elementById(idTool, VAbstractPattern::TagOperation); + if (tool.isElement()) + { + QDomElement correctDest; + const QDomNodeList nodeList = tool.childNodes(); + for (qint32 i = 0; i < nodeList.size(); ++i) + { + const QDomElement dest = nodeList.at(i).toElement(); + if (not dest.isNull() && dest.isElement() && dest.tagName() == VAbstractOperation::TagDestination) + { + correctDest = dest; + break; + } + } + + if (not correctDest.isNull()) + { + const QDomNodeList destObjects = correctDest.childNodes(); + for (qint32 i = 0; i < destObjects.size(); ++i) + { + const QDomElement obj = destObjects.at(i).toElement(); + if (not obj.isNull() && obj.isElement()) + { + const quint32 id = doc->GetParametrUInt(obj, AttrIdObject, NULL_ID_STR); + if (idPoint == id) + { + return obj; + } + } + } + } + } + + return QDomElement(); +} diff --git a/src/libs/vtools/undocommands/vundocommand.h b/src/libs/vtools/undocommands/vundocommand.h index 1a5d055be..0749c6828 100644 --- a/src/libs/vtools/undocommands/vundocommand.h +++ b/src/libs/vtools/undocommands/vundocommand.h @@ -90,6 +90,8 @@ protected: void IncrementReferences(const QVector &nodes) const; void DecrementReferences(const QVector &nodes) const; + + QDomElement GetDestinationObject(quint32 idTool, quint32 idPoint) const; private: Q_DISABLE_COPY(VUndoCommand) };