New undo command DelTool.

--HG--
branch : feature
This commit is contained in:
dismine 2014-06-14 09:37:25 +03:00
parent a755089a99
commit 12cbc8b566
5 changed files with 152 additions and 47 deletions

View File

@ -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");
@ -241,52 +244,20 @@ QPointF VAbstractTool::addVector(const QPointF &p, const QPointF &p1, const QPoi
*/
void VAbstractTool::DeleteTool(QGraphicsItem *tool)
{
if (_referens <= 1)
QMessageBox msgBox;
msgBox.setText(tr("Confirm the deletion."));
msgBox.setInformativeText(tr("Do you really want delete?"));
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setIcon(QMessageBox::Question);
if (msgBox.exec() == QMessageBox::Cancel)
{
QMessageBox msgBox;
msgBox.setText(tr("Confirm the deletion."));
msgBox.setInformativeText(tr("Do you really want delete?"));
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setIcon(QMessageBox::Question);
if (msgBox.exec() == QMessageBox::Cancel)
{
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;
}
return;
}
DelTool *delTool = new DelTool(doc, id);
connect(delTool, &DelTool::NeedFullParsing, doc, &VPattern::NeedFullParsing);
qApp->getUndoStack()->push(delTool);
}
//---------------------------------------------------------------------------------------------------------------------

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

View 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

View File

@ -36,7 +36,8 @@ enum class UndoCommand: char { AddPatternPiece,
MoveSPoint,
SaveToolOptions,
SaveDetailOptions,
MoveDetail
MoveDetail,
DeleteTool
};
#endif // UNDOCOMMANDS_H

View File

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