2014-06-11 19:12:46 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
2014-07-16 14:37:38 +02:00
|
|
|
** @file vundocommand.cpp
|
2014-06-11 19:12:46 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2014-07-16 14:37:38 +02:00
|
|
|
** @date 16 7, 2014
|
2014-06-11 19:12:46 +02:00
|
|
|
**
|
|
|
|
** @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-11 19:12:46 +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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
2014-07-16 14:37:38 +02:00
|
|
|
#include "vundocommand.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include <QDomNode>
|
|
|
|
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../ifc/ifcdef.h"
|
|
|
|
#include "../vmisc/def.h"
|
|
|
|
#include "../vpatterndb/vnodedetail.h"
|
2016-11-08 11:54:33 +01:00
|
|
|
#include "../vpatterndb/vpiecenode.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
class QDomElement;
|
|
|
|
class QDomNode;
|
|
|
|
class QUndoCommand;
|
2014-06-11 19:12:46 +02:00
|
|
|
|
2014-11-24 14:03:34 +01:00
|
|
|
Q_LOGGING_CATEGORY(vUndo, "v.undo")
|
|
|
|
|
2014-07-16 14:37:38 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-06-16 10:30:25 +02:00
|
|
|
VUndoCommand::VUndoCommand(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent)
|
2014-08-17 17:20:55 +02:00
|
|
|
:QObject(), QUndoCommand(parent), xml(xml), doc(doc), nodeId(NULL_ID), redoFlag(false)
|
2014-07-16 14:37:38 +02:00
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(doc != nullptr)
|
2014-07-16 14:37:38 +02:00
|
|
|
}
|
2014-06-11 19:12:46 +02:00
|
|
|
|
2014-07-16 14:37:38 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VUndoCommand::~VUndoCommand()
|
2014-07-16 19:08:24 +02:00
|
|
|
{}
|
2014-07-16 14:37:38 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VUndoCommand::RedoFullParsing()
|
|
|
|
{
|
|
|
|
if (redoFlag)
|
|
|
|
{
|
|
|
|
emit NeedFullParsing();
|
|
|
|
}
|
|
|
|
redoFlag = true;
|
|
|
|
}
|
2014-10-29 11:57:58 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VUndoCommand::UndoDeleteAfterSibling(QDomNode &parentNode, const quint32 &siblingId) const
|
|
|
|
{
|
|
|
|
if (siblingId == NULL_ID)
|
|
|
|
{
|
|
|
|
parentNode.appendChild(xml);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-10 15:49:39 +01:00
|
|
|
const QDomElement refElement = doc->NodeById(siblingId);
|
|
|
|
parentNode.insertAfter(xml, refElement);
|
2014-10-29 11:57:58 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-08 18:49:16 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VUndoCommand::IncrementReferences(const QVector<VNodeDetail> &nodes) const
|
|
|
|
{
|
|
|
|
for (qint32 i = 0; i < nodes.size(); ++i)
|
|
|
|
{
|
2016-03-15 16:32:12 +01:00
|
|
|
doc->IncrementReferens(nodes.at(i).getId());
|
2016-03-08 18:49:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VUndoCommand::DecrementReferences(const QVector<VNodeDetail> &nodes) const
|
|
|
|
{
|
|
|
|
for (qint32 i = 0; i < nodes.size(); ++i)
|
|
|
|
{
|
2016-03-15 16:32:12 +01:00
|
|
|
doc->DecrementReferens(nodes.at(i).getId());
|
2016-03-08 18:49:16 +01:00
|
|
|
}
|
|
|
|
}
|
2016-11-08 11:54:33 +01:00
|
|
|
|
2016-11-25 15:12:33 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VUndoCommand::IncrementReferences(const QVector<quint32> &nodes) const
|
|
|
|
{
|
|
|
|
for (qint32 i = 0; i < nodes.size(); ++i)
|
|
|
|
{
|
|
|
|
doc->IncrementReferens(nodes.at(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VUndoCommand::DecrementReferences(const QVector<quint32> &nodes) const
|
|
|
|
{
|
|
|
|
for (qint32 i = 0; i < nodes.size(); ++i)
|
|
|
|
{
|
|
|
|
doc->DecrementReferens(nodes.at(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VUndoCommand::IncrementReferences(const QVector<CustomSARecord> &nodes) const
|
|
|
|
{
|
|
|
|
QVector<quint32> n;
|
|
|
|
|
|
|
|
for (qint32 i = 0; i < nodes.size(); ++i)
|
|
|
|
{
|
|
|
|
n.append(nodes.at(i).path);
|
|
|
|
}
|
|
|
|
|
|
|
|
IncrementReferences(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VUndoCommand::DecrementReferences(const QVector<CustomSARecord> &nodes) const
|
|
|
|
{
|
|
|
|
QVector<quint32> n;
|
|
|
|
|
|
|
|
for (qint32 i = 0; i < nodes.size(); ++i)
|
|
|
|
{
|
|
|
|
n.append(nodes.at(i).path);
|
|
|
|
}
|
|
|
|
|
|
|
|
DecrementReferences(n);
|
|
|
|
}
|
|
|
|
|
2016-11-09 13:11:58 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VUndoCommand::IncrementReferences(const QVector<VPieceNode> &nodes) const
|
|
|
|
{
|
2016-11-25 15:12:33 +01:00
|
|
|
QVector<quint32> n;
|
|
|
|
|
2016-11-09 13:11:58 +01:00
|
|
|
for (qint32 i = 0; i < nodes.size(); ++i)
|
|
|
|
{
|
2016-11-25 15:12:33 +01:00
|
|
|
n.append(nodes.at(i).GetId());
|
2016-11-09 13:11:58 +01:00
|
|
|
}
|
2016-11-25 15:12:33 +01:00
|
|
|
|
|
|
|
IncrementReferences(n);
|
2016-11-09 13:11:58 +01:00
|
|
|
}
|
|
|
|
|
2016-11-08 11:54:33 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VUndoCommand::DecrementReferences(const QVector<VPieceNode> &nodes) const
|
|
|
|
{
|
2016-11-25 15:12:33 +01:00
|
|
|
QVector<quint32> n;
|
|
|
|
|
2016-11-08 11:54:33 +01:00
|
|
|
for (qint32 i = 0; i < nodes.size(); ++i)
|
|
|
|
{
|
2016-11-25 15:12:33 +01:00
|
|
|
n.append(nodes.at(i).GetId());
|
2016-11-08 11:54:33 +01:00
|
|
|
}
|
2016-11-25 15:12:33 +01:00
|
|
|
|
|
|
|
DecrementReferences(n);
|
2016-11-08 11:54:33 +01:00
|
|
|
}
|