New undo command SaveToolOptions.

--HG--
branch : feature
This commit is contained in:
dismine 2014-06-11 19:32:32 +03:00
parent 745004bb5f
commit c5250cde7f
5 changed files with 198 additions and 13 deletions

View file

@ -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;
}
}

View file

@ -31,7 +31,6 @@
#include <QUndoCommand>
#include "../geometry/vsplinepath.h"
#include <QtCore>
class VPattern;
class QGraphicsScene;

View 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;
}

View 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

View file

@ -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