New undo command SaveToolOptions.
--HG-- branch : feature
This commit is contained in:
parent
745004bb5f
commit
c5250cde7f
|
@ -32,6 +32,7 @@
|
||||||
#include "dialogs/tools/dialogeditwrongformula.h"
|
#include "dialogs/tools/dialogeditwrongformula.h"
|
||||||
#include "container/calculator.h"
|
#include "container/calculator.h"
|
||||||
#include "../../undocommands/addtocalc.h"
|
#include "../../undocommands/addtocalc.h"
|
||||||
|
#include "../../undocommands/savetooloptions.h"
|
||||||
|
|
||||||
qreal VDrawTool::factor = 1;
|
qreal VDrawTool::factor = 1;
|
||||||
|
|
||||||
|
@ -111,13 +112,19 @@ void VDrawTool::FullUpdateFromGui(int result)
|
||||||
{
|
{
|
||||||
if (result == QDialog::Accepted)
|
if (result == QDialog::Accepted)
|
||||||
{
|
{
|
||||||
QDomElement domElement = doc->elementById(QString().setNum(id));
|
QDomElement oldDomElement = doc->elementById(QString().setNum(id));
|
||||||
if (domElement.isElement())
|
if (oldDomElement.isElement())
|
||||||
{
|
{
|
||||||
SaveDialog(domElement);
|
QDomElement newDomElement = oldDomElement.cloneNode().toElement();
|
||||||
|
SaveDialog(newDomElement);
|
||||||
|
|
||||||
emit LiteUpdateTree();
|
SaveToolOptions *saveOptions = new SaveToolOptions(oldDomElement, newDomElement, doc, id);
|
||||||
emit toolhaveChange();
|
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;
|
delete dialog;
|
||||||
|
@ -127,13 +134,19 @@ void VDrawTool::FullUpdateFromGui(int result)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VDrawTool::FullUpdateFromGuiApply()
|
void VDrawTool::FullUpdateFromGuiApply()
|
||||||
{
|
{
|
||||||
QDomElement domElement = doc->elementById(QString().setNum(id));
|
QDomElement oldDomElement = doc->elementById(QString().setNum(id));
|
||||||
if (domElement.isElement())
|
if (oldDomElement.isElement())
|
||||||
{
|
{
|
||||||
SaveDialog(domElement);
|
QDomElement newDomElement = oldDomElement.cloneNode().toElement();
|
||||||
|
SaveDialog(newDomElement);
|
||||||
|
|
||||||
emit LiteUpdateTree();
|
SaveToolOptions *saveOptions = new SaveToolOptions(oldDomElement, newDomElement, doc, id);
|
||||||
emit toolhaveChange();
|
connect(saveOptions, &SaveToolOptions::NeedLiteParsing, doc, &VPattern::LiteParseTree);
|
||||||
|
qApp->getUndoStack()->push(saveOptions);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qDebug()<<"Can't find tool with id ="<< id << Q_FUNC_INFO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
|
|
||||||
#include <QUndoCommand>
|
#include <QUndoCommand>
|
||||||
#include "../geometry/vsplinepath.h"
|
#include "../geometry/vsplinepath.h"
|
||||||
#include <QtCore>
|
|
||||||
|
|
||||||
class VPattern;
|
class VPattern;
|
||||||
class QGraphicsScene;
|
class QGraphicsScene;
|
||||||
|
|
93
src/app/undocommands/savetooloptions.cpp
Normal file
93
src/app/undocommands/savetooloptions.cpp
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file savetooloptions.cpp
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @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
|
||||||
|
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
|
||||||
|
**
|
||||||
|
*************************************************************************/
|
||||||
|
|
||||||
|
#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<const SaveToolOptions *>(command);
|
||||||
|
SCASSERT(moveCommand != nullptr);
|
||||||
|
const quint32 id = moveCommand->getToolId();
|
||||||
|
|
||||||
|
if (id != toolId)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
newXml = moveCommand->getNewXml();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
78
src/app/undocommands/savetooloptions.h
Normal file
78
src/app/undocommands/savetooloptions.h
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file savetooloptions.h
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @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
|
||||||
|
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
|
||||||
|
**
|
||||||
|
*************************************************************************/
|
||||||
|
|
||||||
|
#ifndef SAVETOOLOPTIONS_H
|
||||||
|
#define SAVETOOLOPTIONS_H
|
||||||
|
|
||||||
|
#include <QUndoCommand>
|
||||||
|
#include <QDomElement>
|
||||||
|
|
||||||
|
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
|
|
@ -3,7 +3,8 @@ HEADERS += \
|
||||||
undocommands/addpatternpiece.h \
|
undocommands/addpatternpiece.h \
|
||||||
undocommands/movespoint.h \
|
undocommands/movespoint.h \
|
||||||
undocommands/movespline.h \
|
undocommands/movespline.h \
|
||||||
undocommands/movesplinepath.h
|
undocommands/movesplinepath.h \
|
||||||
|
undocommands/savetooloptions.h
|
||||||
|
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
@ -11,5 +12,6 @@ SOURCES += \
|
||||||
undocommands/addpatternpiece.cpp \
|
undocommands/addpatternpiece.cpp \
|
||||||
undocommands/movespoint.cpp \
|
undocommands/movespoint.cpp \
|
||||||
undocommands/movespline.cpp \
|
undocommands/movespline.cpp \
|
||||||
undocommands/movesplinepath.cpp
|
undocommands/movesplinepath.cpp \
|
||||||
|
undocommands/savetooloptions.cpp
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user