New undo command DelTool.
--HG-- branch : feature
This commit is contained in:
parent
a755089a99
commit
12cbc8b566
|
@ -29,6 +29,9 @@
|
|||
#include "vabstracttool.h"
|
||||
#include "../xml/vpattern.h"
|
||||
#include <QGraphicsView>
|
||||
#include <QMessageBox>
|
||||
#include "../undocommands/deltool.h"
|
||||
#include "../widgets/vapplication.h"
|
||||
|
||||
const QString VAbstractTool::AttrType = QStringLiteral("type");
|
||||
const QString VAbstractTool::AttrMx = QStringLiteral("mx");
|
||||
|
@ -240,8 +243,6 @@ QPointF VAbstractTool::addVector(const QPointF &p, const QPointF &p1, const QPoi
|
|||
* @param tool tool
|
||||
*/
|
||||
void VAbstractTool::DeleteTool(QGraphicsItem *tool)
|
||||
{
|
||||
if (_referens <= 1)
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(tr("Confirm the deletion."));
|
||||
|
@ -253,40 +254,10 @@ void VAbstractTool::DeleteTool(QGraphicsItem *tool)
|
|||
{
|
||||
return;
|
||||
}
|
||||
//remove from xml file
|
||||
QDomElement domElement = doc->elementById(QString().setNum(id));
|
||||
if (domElement.isElement())
|
||||
{
|
||||
QDomNode element = domElement.parentNode();
|
||||
if (element.isNull() == false)
|
||||
{
|
||||
if (element.isElement())
|
||||
{
|
||||
RemoveReferens();//deincrement referens
|
||||
element.removeChild(domElement);//remove form file
|
||||
QGraphicsScene *scene = tool->scene();
|
||||
if (scene != 0)//some tools haven't scene
|
||||
{
|
||||
scene->removeItem(tool);//remove form scene
|
||||
}
|
||||
doc->LiteParseTree();
|
||||
emit toolhaveChange();//set enabled save button
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug()<<"parent isn't element"<<Q_FUNC_INFO;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug()<<"parent isNull"<<Q_FUNC_INFO;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug()<<"Can't get element by id form file = "<<id<<Q_FUNC_INFO;
|
||||
}
|
||||
}
|
||||
|
||||
DelTool *delTool = new DelTool(doc, id);
|
||||
connect(delTool, &DelTool::NeedFullParsing, doc, &VPattern::NeedFullParsing);
|
||||
qApp->getUndoStack()->push(delTool);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
75
src/app/undocommands/deltool.cpp
Normal file
75
src/app/undocommands/deltool.cpp
Normal file
|
@ -0,0 +1,75 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file deltool.cpp
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 13 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 "deltool.h"
|
||||
#include "../xml/vpattern.h"
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
DelTool::DelTool(VPattern *doc, quint32 id, QUndoCommand *parent)
|
||||
: QObject(), QUndoCommand(parent), xml(QDomElement()), parentNode(QDomNode()), previousNode(QDomNode()),
|
||||
doc(doc), toolId(id)
|
||||
{
|
||||
setText(tr("Delete tool"));
|
||||
QDomElement domElement = doc->elementById(QString().setNum(id));
|
||||
if (domElement.isElement())
|
||||
{
|
||||
xml = domElement.cloneNode().toElement();
|
||||
parentNode = domElement.parentNode();
|
||||
previousNode = domElement.previousSibling();
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug()<<"Can't get tool by id = "<<toolId<<Q_FUNC_INFO;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
DelTool::~DelTool()
|
||||
{}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DelTool::undo()
|
||||
{
|
||||
parentNode.insertAfter(xml, previousNode);
|
||||
emit NeedFullParsing();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DelTool::redo()
|
||||
{
|
||||
QDomElement domElement = doc->elementById(QString().setNum(toolId));
|
||||
if (domElement.isElement())
|
||||
{
|
||||
parentNode.removeChild(domElement);
|
||||
emit NeedFullParsing();
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug()<<"Can't get tool by id = "<<toolId<<Q_FUNC_INFO;
|
||||
}
|
||||
}
|
56
src/app/undocommands/deltool.h
Normal file
56
src/app/undocommands/deltool.h
Normal file
|
@ -0,0 +1,56 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file deltool.h
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 13 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 DELTOOL_H
|
||||
#define DELTOOL_H
|
||||
|
||||
#include <QDomElement>
|
||||
#include <QUndoCommand>
|
||||
|
||||
class VPattern;
|
||||
|
||||
class DelTool : public QObject, public QUndoCommand
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DelTool(VPattern *doc, quint32 id, QUndoCommand *parent = 0);
|
||||
virtual ~DelTool();
|
||||
virtual void undo();
|
||||
virtual void redo();
|
||||
signals:
|
||||
void NeedFullParsing();
|
||||
private:
|
||||
Q_DISABLE_COPY(DelTool)
|
||||
QDomElement xml;
|
||||
QDomNode parentNode;
|
||||
QDomNode previousNode;
|
||||
VPattern *doc;
|
||||
quint32 toolId;
|
||||
};
|
||||
|
||||
#endif // DELTOOL_H
|
|
@ -36,7 +36,8 @@ enum class UndoCommand: char { AddPatternPiece,
|
|||
MoveSPoint,
|
||||
SaveToolOptions,
|
||||
SaveDetailOptions,
|
||||
MoveDetail
|
||||
MoveDetail,
|
||||
DeleteTool
|
||||
};
|
||||
|
||||
#endif // UNDOCOMMANDS_H
|
||||
|
|
|
@ -7,7 +7,8 @@ HEADERS += \
|
|||
undocommands/savetooloptions.h \
|
||||
undocommands/undocommands.h \
|
||||
undocommands/savedetailoptions.h \
|
||||
undocommands/movedetail.h
|
||||
undocommands/movedetail.h \
|
||||
undocommands/deltool.h
|
||||
|
||||
|
||||
SOURCES += \
|
||||
|
@ -18,5 +19,6 @@ SOURCES += \
|
|||
undocommands/movesplinepath.cpp \
|
||||
undocommands/savetooloptions.cpp \
|
||||
undocommands/savedetailoptions.cpp \
|
||||
undocommands/movedetail.cpp
|
||||
undocommands/movedetail.cpp \
|
||||
undocommands/deltool.cpp
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user