2014-06-14 15:10:16 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file deletepatternpiece.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 14 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.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2014-06-14 15:10:16 +02:00
|
|
|
** <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 "deletepatternpiece.h"
|
|
|
|
#include "addpatternpiece.h"
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-06-16 10:30:25 +02:00
|
|
|
DeletePatternPiece::DeletePatternPiece(VAbstractPattern *doc, const QString &namePP, QUndoCommand *parent)
|
2015-09-16 10:03:33 +02:00
|
|
|
: VUndoCommand(QDomElement(), doc, parent), namePP(namePP), patternPiece(QDomElement()),
|
2014-07-16 14:37:38 +02:00
|
|
|
previousPPName(QString())
|
2014-06-14 15:10:16 +02:00
|
|
|
{
|
2015-06-24 16:48:57 +02:00
|
|
|
setText(tr("delete pattern piece %1").arg(namePP));
|
2014-06-14 15:10:16 +02:00
|
|
|
|
2016-02-19 15:34:32 +01:00
|
|
|
const QDomElement patternP = doc->GetPPElement(namePP);
|
2014-06-14 15:10:16 +02:00
|
|
|
patternPiece = patternP.cloneNode().toElement();
|
2016-02-19 15:34:32 +01:00
|
|
|
const QDomElement previousPP = patternP.previousSibling().toElement();//find previous pattern piece
|
|
|
|
if (not previousPP.isNull() && previousPP.tagName() == VAbstractPattern::TagDraw)
|
|
|
|
{
|
|
|
|
previousPPName = doc->GetParametrString(previousPP, VAbstractPattern::AttrName, "");
|
|
|
|
}
|
2014-06-14 15:10:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
DeletePatternPiece::~DeletePatternPiece()
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DeletePatternPiece::undo()
|
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vUndo, "Undo.");
|
2014-11-20 18:52:51 +01:00
|
|
|
|
2014-06-14 15:10:16 +02:00
|
|
|
QDomElement rootElement = doc->documentElement();
|
2016-02-19 15:34:32 +01:00
|
|
|
|
|
|
|
if (not previousPPName.isEmpty())
|
|
|
|
{ // not first in the list, add after tag draw
|
|
|
|
const QDomNode previousPP = doc->GetPPElement(previousPPName);
|
|
|
|
rootElement.insertAfter(patternPiece, previousPP);
|
|
|
|
}
|
|
|
|
else
|
2016-02-20 09:05:18 +01:00
|
|
|
{ // first in the list, add before tag draw
|
|
|
|
const QDomNodeList list = rootElement.elementsByTagName(VAbstractPattern::TagDraw);
|
|
|
|
QDomElement draw;
|
2016-02-19 15:34:32 +01:00
|
|
|
|
|
|
|
if (not list.isEmpty())
|
|
|
|
{
|
2016-02-20 09:05:18 +01:00
|
|
|
draw = list.at(0).toElement();
|
2016-02-19 15:34:32 +01:00
|
|
|
}
|
|
|
|
|
2016-02-20 09:05:18 +01:00
|
|
|
Q_ASSERT_X(not draw.isNull(), Q_FUNC_INFO, "Couldn't' find tag draw");
|
|
|
|
rootElement.insertBefore(patternPiece, draw);
|
2016-02-19 15:34:32 +01:00
|
|
|
}
|
2014-06-14 15:10:16 +02:00
|
|
|
|
|
|
|
emit NeedFullParsing();
|
2016-02-19 15:34:32 +01:00
|
|
|
doc->ChangeActivPP(namePP);
|
2014-06-14 15:10:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DeletePatternPiece::redo()
|
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vUndo, "Redo.");
|
2014-11-20 18:52:51 +01:00
|
|
|
|
2014-06-14 15:10:16 +02:00
|
|
|
QDomElement rootElement = doc->documentElement();
|
2016-02-19 15:34:32 +01:00
|
|
|
const QDomElement patternPiece = doc->GetPPElement(namePP);
|
2014-06-15 10:04:49 +02:00
|
|
|
rootElement.removeChild(patternPiece);
|
|
|
|
emit NeedFullParsing();
|
2014-06-14 15:10:16 +02:00
|
|
|
}
|