From c5250cde7f61cc5181c9b381da03a045fd627eec Mon Sep 17 00:00:00 2001 From: dismine Date: Wed, 11 Jun 2014 19:32:32 +0300 Subject: [PATCH] New undo command SaveToolOptions. --HG-- branch : feature --- src/app/tools/drawTools/vdrawtool.cpp | 33 ++++++--- src/app/undocommands/movesplinepath.h | 1 - src/app/undocommands/savetooloptions.cpp | 93 ++++++++++++++++++++++++ src/app/undocommands/savetooloptions.h | 78 ++++++++++++++++++++ src/app/undocommands/undocommands.pri | 6 +- 5 files changed, 198 insertions(+), 13 deletions(-) create mode 100644 src/app/undocommands/savetooloptions.cpp create mode 100644 src/app/undocommands/savetooloptions.h diff --git a/src/app/tools/drawTools/vdrawtool.cpp b/src/app/tools/drawTools/vdrawtool.cpp index fa5bad980..b8175d8e8 100644 --- a/src/app/tools/drawTools/vdrawtool.cpp +++ b/src/app/tools/drawTools/vdrawtool.cpp @@ -32,6 +32,7 @@ #include "dialogs/tools/dialogeditwrongformula.h" #include "container/calculator.h" #include "../../undocommands/addtocalc.h" +#include "../../undocommands/savetooloptions.h" qreal VDrawTool::factor = 1; @@ -111,13 +112,19 @@ void VDrawTool::FullUpdateFromGui(int result) { if (result == QDialog::Accepted) { - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) + QDomElement oldDomElement = doc->elementById(QString().setNum(id)); + if (oldDomElement.isElement()) { - SaveDialog(domElement); + QDomElement newDomElement = oldDomElement.cloneNode().toElement(); + SaveDialog(newDomElement); - emit LiteUpdateTree(); - emit toolhaveChange(); + SaveToolOptions *saveOptions = new SaveToolOptions(oldDomElement, newDomElement, doc, id); + connect(saveOptions, &SaveToolOptions::NeedLiteParsing, doc, &VPattern::LiteParseTree); + qApp->getUndoStack()->push(saveOptions); + } + else + { + qDebug()<<"Can't find tool with id ="<< id << Q_FUNC_INFO; } } delete dialog; @@ -127,13 +134,19 @@ void VDrawTool::FullUpdateFromGui(int result) //--------------------------------------------------------------------------------------------------------------------- void VDrawTool::FullUpdateFromGuiApply() { - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) + QDomElement oldDomElement = doc->elementById(QString().setNum(id)); + if (oldDomElement.isElement()) { - SaveDialog(domElement); + QDomElement newDomElement = oldDomElement.cloneNode().toElement(); + SaveDialog(newDomElement); - emit LiteUpdateTree(); - emit toolhaveChange(); + SaveToolOptions *saveOptions = new SaveToolOptions(oldDomElement, newDomElement, doc, id); + connect(saveOptions, &SaveToolOptions::NeedLiteParsing, doc, &VPattern::LiteParseTree); + qApp->getUndoStack()->push(saveOptions); + } + else + { + qDebug()<<"Can't find tool with id ="<< id << Q_FUNC_INFO; } } diff --git a/src/app/undocommands/movesplinepath.h b/src/app/undocommands/movesplinepath.h index 923217b07..0eb0a061c 100644 --- a/src/app/undocommands/movesplinepath.h +++ b/src/app/undocommands/movesplinepath.h @@ -31,7 +31,6 @@ #include #include "../geometry/vsplinepath.h" -#include class VPattern; class QGraphicsScene; diff --git a/src/app/undocommands/savetooloptions.cpp b/src/app/undocommands/savetooloptions.cpp new file mode 100644 index 000000000..52f45f1bf --- /dev/null +++ b/src/app/undocommands/savetooloptions.cpp @@ -0,0 +1,93 @@ +/************************************************************************ + ** + ** @file savetooloptions.cpp + ** @author Roman Telezhynskyi + ** @date 11 6, 2014 + ** + ** @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) 2014 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 "savetooloptions.h" +#include "../options.h" +#include "../xml/vpattern.h" + +//--------------------------------------------------------------------------------------------------------------------- +SaveToolOptions::SaveToolOptions(const QDomElement &oldXml, const QDomElement &newXml, VPattern *doc, const quint32 &id, + QUndoCommand *parent) + : QObject(), QUndoCommand(parent), oldXml(oldXml), newXml(newXml), doc(doc), toolId(id) +{ + setText(tr("Save tool option")); +} + +//--------------------------------------------------------------------------------------------------------------------- +SaveToolOptions::~SaveToolOptions() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void SaveToolOptions::undo() +{ + QDomElement domElement = doc->elementById(QString().setNum(toolId)); + if (domElement.isElement()) + { + domElement.parentNode().replaceChild(oldXml, domElement); + + emit NeedLiteParsing(); + } + else + { + qDebug()<<"Can't find tool with id ="<< toolId << Q_FUNC_INFO; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void SaveToolOptions::redo() +{ + QDomElement domElement = doc->elementById(QString().setNum(toolId)); + if (domElement.isElement()) + { + domElement.parentNode().replaceChild(newXml, domElement); + + emit NeedLiteParsing(); + } + else + { + qDebug()<<"Can't find tool with id ="<< toolId << Q_FUNC_INFO; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +bool SaveToolOptions::mergeWith(const QUndoCommand *command) +{ + const SaveToolOptions *moveCommand = static_cast(command); + SCASSERT(moveCommand != nullptr); + const quint32 id = moveCommand->getToolId(); + + if (id != toolId) + { + return false; + } + + newXml = moveCommand->getNewXml(); + return true; +} + + diff --git a/src/app/undocommands/savetooloptions.h b/src/app/undocommands/savetooloptions.h new file mode 100644 index 000000000..78512977e --- /dev/null +++ b/src/app/undocommands/savetooloptions.h @@ -0,0 +1,78 @@ +/************************************************************************ + ** + ** @file savetooloptions.h + ** @author Roman Telezhynskyi + ** @date 11 6, 2014 + ** + ** @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) 2014 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 SAVETOOLOPTIONS_H +#define SAVETOOLOPTIONS_H + +#include +#include + +class VPattern; + +class SaveToolOptions : public QObject, public QUndoCommand +{ + Q_OBJECT +public: + SaveToolOptions(const QDomElement &oldXml, const QDomElement &newXml, VPattern *doc, const quint32 &id, QUndoCommand *parent = 0); + virtual ~SaveToolOptions(); + virtual void undo(); + virtual void redo(); + virtual bool mergeWith(const QUndoCommand *command); + virtual int id() const; + QDomElement getNewXml() const; + quint32 getToolId() const; +signals: + void NeedLiteParsing(); +private: + Q_DISABLE_COPY(SaveToolOptions) + enum { Id = 3 }; + const QDomElement oldXml; + QDomElement newXml; + VPattern *doc; + const quint32 toolId; +}; + +//--------------------------------------------------------------------------------------------------------------------- +inline QDomElement SaveToolOptions::getNewXml() const +{ + return newXml; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline int SaveToolOptions::id() const +{ + return Id; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline quint32 SaveToolOptions::getToolId() const +{ + return toolId; +} + +#endif // SAVETOOLOPTIONS_H diff --git a/src/app/undocommands/undocommands.pri b/src/app/undocommands/undocommands.pri index 04c5128b9..4e24e5814 100644 --- a/src/app/undocommands/undocommands.pri +++ b/src/app/undocommands/undocommands.pri @@ -3,7 +3,8 @@ HEADERS += \ undocommands/addpatternpiece.h \ undocommands/movespoint.h \ undocommands/movespline.h \ - undocommands/movesplinepath.h + undocommands/movesplinepath.h \ + undocommands/savetooloptions.h SOURCES += \ @@ -11,5 +12,6 @@ SOURCES += \ undocommands/addpatternpiece.cpp \ undocommands/movespoint.cpp \ undocommands/movespline.cpp \ - undocommands/movesplinepath.cpp + undocommands/movesplinepath.cpp \ + undocommands/savetooloptions.cpp