diff --git a/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp b/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp index c23e4804d..9b4db29e8 100644 --- a/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp +++ b/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp @@ -35,7 +35,6 @@ #include #include -#include "../../undocommands/adddetnode.h" #include "../ifc/ifcdef.h" #include "../ifc/xml/vabstractpattern.h" #include "../vgeometry/vgobject.h" @@ -176,6 +175,14 @@ void VAbstractNode::ToolCreation(const Source &typeCreation) */ void VAbstractNode::AddToModeling(const QDomElement &domElement) { - AddDetNode *addNode = new AddDetNode(domElement, doc, m_drawName); - qApp->getUndoStack()->push(addNode); + QDomElement modeling; + if (m_drawName.isEmpty()) + { + doc->GetActivNodeElement(VAbstractPattern::TagModeling, modeling); + } + else + { + modeling = doc->GetDraw(m_drawName).firstChildElement(VAbstractPattern::TagModeling); + } + modeling.appendChild(domElement); } diff --git a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp index e25ad7bbf..75ad2c42a 100644 --- a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp +++ b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp @@ -50,7 +50,6 @@ VToolPiecePath *VToolPiecePath::Create(QSharedPointer dialog, VMainG initData.parse = Document::FullParse; initData.typeCreation = Source::FromGui; - qApp->getUndoStack()->beginMacro("add path"); initData.path.SetNodes(PrepareNodes(initData.path, scene, doc, data)); VToolPiecePath *pathTool = Create(initData); @@ -276,10 +275,6 @@ void VToolPiecePath::ToolCreation(const Source &typeCreation) if (typeCreation == Source::FromGui || typeCreation == Source::FromTool) { AddToFile(); - if (typeCreation != Source::FromTool) - { - qApp->getUndoStack()->endMacro(); - } } else { diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 188b2454e..1fb7e5916 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -101,7 +101,6 @@ VToolSeamAllowance *VToolSeamAllowance::Create(QSharedPointer dialog initData.parse = Document::FullParse; initData.typeCreation = Source::FromGui; - qApp->getUndoStack()->beginMacro("add detail"); initData.detail.GetPath().SetNodes(PrepareNodes(initData.detail.GetPath(), scene, doc, data)); VToolSeamAllowance *piece = Create(initData); @@ -921,9 +920,7 @@ void VToolSeamAllowance::AddToFile() AddInternalPaths(doc, domElement, piece.GetInternalPaths()); AddPins(doc, domElement, piece.GetPins()); - AddPiece *addDet = new AddPiece(domElement, doc, piece, m_drawName); - connect(addDet, &AddPiece::NeedFullParsing, doc, &VAbstractPattern::NeedFullParsing); - qApp->getUndoStack()->push(addDet); + qApp->getUndoStack()->push(new AddPiece(domElement, doc, VAbstractTool::data, m_sceneDetails, m_drawName)); } //--------------------------------------------------------------------------------------------------------------------- @@ -1594,10 +1591,6 @@ void VToolSeamAllowance::ToolCreation(const Source &typeCreation) if (typeCreation == Source::FromGui || typeCreation == Source::FromTool) { AddToFile(); - if (typeCreation != Source::FromTool) - { - qApp->getUndoStack()->endMacro(); - } } else { diff --git a/src/libs/vtools/undocommands/adddetnode.cpp b/src/libs/vtools/undocommands/adddetnode.cpp deleted file mode 100644 index 23f9c4a3f..000000000 --- a/src/libs/vtools/undocommands/adddetnode.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/************************************************************************ - ** - ** @file adddetnode.cpp - ** @author Roman Telezhynskyi - ** @date 15 6, 2014 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2013-2015 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 "adddetnode.h" - -#include -#include - -#include "../vmisc/logging.h" -#include "../ifc/xml/vabstractpattern.h" -#include "vundocommand.h" - -//--------------------------------------------------------------------------------------------------------------------- -AddDetNode::AddDetNode(const QDomElement &xml, VAbstractPattern *doc, const QString &drawName, QUndoCommand *parent) - : VUndoCommand(xml, doc, parent), m_drawName(drawName) -{ - setText(QObject::tr("add node")); - nodeId = doc->GetParametrId(xml); -} - -//--------------------------------------------------------------------------------------------------------------------- -AddDetNode::~AddDetNode() -{} - -//--------------------------------------------------------------------------------------------------------------------- -void AddDetNode::undo() -{ - qCDebug(vUndo, "Undo."); - - QDomElement modeling = GetModelingSection(); - if (not modeling.isNull()) - { - QDomElement domElement = doc->elementById(nodeId); - if (domElement.isElement()) - { - if (modeling.removeChild(domElement).isNull()) - { - qCDebug(vUndo, "Can't delete node."); - } - } - else - { - qCDebug(vUndo, "Can't get node by id = %u.", nodeId); - } - } - else - { - qCDebug(vUndo, "Can't find tag %s.", qUtf8Printable(VAbstractPattern::TagModeling)); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void AddDetNode::redo() -{ - qCDebug(vUndo, "Redo."); - - QDomElement modeling = GetModelingSection(); - if (not modeling.isNull()) - { - modeling.appendChild(xml); - } - else - { - qCDebug(vUndo, "Can't find tag %s.", qUtf8Printable(VAbstractPattern::TagModeling)); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -QDomElement AddDetNode::GetModelingSection() const -{ - QDomElement modeling; - if (m_drawName.isEmpty()) - { - doc->GetActivNodeElement(VAbstractPattern::TagModeling, modeling); - } - else - { - modeling = doc->GetDraw(m_drawName).firstChildElement(VAbstractPattern::TagModeling); - } - return modeling; -} diff --git a/src/libs/vtools/undocommands/adddetnode.h b/src/libs/vtools/undocommands/adddetnode.h deleted file mode 100644 index c0dc7c9c6..000000000 --- a/src/libs/vtools/undocommands/adddetnode.h +++ /dev/null @@ -1,57 +0,0 @@ -/************************************************************************ - ** - ** @file adddetnode.h - ** @author Roman Telezhynskyi - ** @date 15 6, 2014 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2013-2015 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 ADDDETNODE_H -#define ADDDETNODE_H - -#include -#include -#include -#include -#include -#include - -#include "vundocommand.h" - -class AddDetNode : public VUndoCommand -{ - Q_OBJECT -public: - AddDetNode(const QDomElement &xml, VAbstractPattern *doc, const QString &drawName, QUndoCommand *parent = nullptr); - virtual ~AddDetNode() Q_DECL_OVERRIDE; - virtual void undo() Q_DECL_OVERRIDE; - virtual void redo() Q_DECL_OVERRIDE; -private: - Q_DISABLE_COPY(AddDetNode) - - QString m_drawName; - - QDomElement GetModelingSection() const; -}; - -#endif // ADDDETNODE_H diff --git a/src/libs/vtools/undocommands/addpiece.cpp b/src/libs/vtools/undocommands/addpiece.cpp index 588ca1528..3098033ee 100644 --- a/src/libs/vtools/undocommands/addpiece.cpp +++ b/src/libs/vtools/undocommands/addpiece.cpp @@ -29,21 +29,33 @@ #include "addpiece.h" #include "../vpatterndb/vpiecenode.h" #include "../vpatterndb/vpiecepath.h" +#include "../vwidgets/vmaingraphicsview.h" //--------------------------------------------------------------------------------------------------------------------- -AddPiece::AddPiece(const QDomElement &xml, VAbstractPattern *doc, const VPiece &detail, const QString &drawName, - QUndoCommand *parent) +AddPiece::AddPiece(const QDomElement &xml, VAbstractPattern *doc, VContainer data, VMainGraphicsScene *scene, + const QString &drawName, QUndoCommand *parent) : VUndoCommand(xml, doc, parent), - m_detail(detail), - m_drawName(drawName) + m_detail(), + m_drawName(drawName), + m_tool(), + m_record(), + m_scene(scene), + m_data(data) { setText(tr("add detail")); nodeId = doc->GetParametrId(xml); + m_detail = data.GetPiece(nodeId); + m_record = VAbstractTool::GetRecord(nodeId, Tool::Piece, doc); } //--------------------------------------------------------------------------------------------------------------------- AddPiece::~AddPiece() -{} +{ + if (not m_tool.isNull()) + { + delete m_tool; + } +} //--------------------------------------------------------------------------------------------------------------------- void AddPiece::undo() @@ -62,10 +74,23 @@ void AddPiece::undo() return; } + m_tool = qobject_cast(VAbstractPattern::getTool(nodeId)); + SCASSERT(not m_tool.isNull()); + m_tool->DisconnectOutsideSignals(); + m_tool->hide(); + + m_scene->removeItem(m_tool); + + VAbstractPattern::RemoveTool(nodeId); + m_data.RemovePiece(nodeId); + VAbstractTool::RemoveRecord(m_record, doc); + DecrementReferences(m_detail.GetPath().GetNodes()); DecrementReferences(m_detail.GetCustomSARecords()); DecrementReferences(m_detail.GetInternalPaths()); DecrementReferences(m_detail.GetPins()); + + VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView()); } else { @@ -90,13 +115,28 @@ void AddPiece::redo() if (not details.isNull()) { details.appendChild(xml); + + if (not m_tool.isNull()) + { + VAbstractPattern::AddTool(nodeId, m_tool); + m_data.UpdatePiece(nodeId, m_detail); + + m_tool->ReinitInternals(m_detail, m_scene); + + VAbstractTool::AddRecord(m_record, doc); + m_scene->addItem(m_tool); + m_tool->ConnectOutsideSignals(); + m_tool->show(); + m_tool.clear(); + } + + VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView()); } else { qCDebug(vUndo, "Can't find tag %s.", qUtf8Printable(VAbstractPattern::TagDetails)); return; } - RedoFullParsing(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/undocommands/addpiece.h b/src/libs/vtools/undocommands/addpiece.h index a6713570a..9a1bf68b5 100644 --- a/src/libs/vtools/undocommands/addpiece.h +++ b/src/libs/vtools/undocommands/addpiece.h @@ -44,8 +44,8 @@ class AddPiece : public VUndoCommand { Q_OBJECT public: - AddPiece(const QDomElement &xml, VAbstractPattern *doc, const VPiece &detail, const QString &drawName = QString(), - QUndoCommand *parent = nullptr); + AddPiece(const QDomElement &xml, VAbstractPattern *doc, VContainer data, VMainGraphicsScene *scene, + const QString &drawName = QString(), QUndoCommand *parent = nullptr); virtual ~AddPiece(); // cppcheck-suppress unusedFunction @@ -57,6 +57,10 @@ private: VPiece m_detail; QString m_drawName; + QPointer m_tool; + VToolRecord m_record; + VMainGraphicsScene *m_scene; + VContainer m_data; QDomElement GetDetailsSection() const; }; diff --git a/src/libs/vtools/undocommands/undocommands.pri b/src/libs/vtools/undocommands/undocommands.pri index 42252b14d..54fd83560 100644 --- a/src/libs/vtools/undocommands/undocommands.pri +++ b/src/libs/vtools/undocommands/undocommands.pri @@ -10,7 +10,6 @@ HEADERS += \ $$PWD/savetooloptions.h \ $$PWD/deltool.h \ $$PWD/deletepatternpiece.h \ - $$PWD/adddetnode.h \ $$PWD/vundocommand.h \ $$PWD/renamepp.h \ $$PWD/label/movelabel.h \ @@ -38,7 +37,6 @@ SOURCES += \ $$PWD/savetooloptions.cpp \ $$PWD/deltool.cpp \ $$PWD/deletepatternpiece.cpp \ - $$PWD/adddetnode.cpp \ $$PWD/vundocommand.cpp \ $$PWD/renamepp.cpp \ $$PWD/label/movelabel.cpp \