Improve Add piece undocommand.

Performance improvement.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-10-18 18:02:02 +03:00
parent 614fd3a0f9
commit 6bbd54f6ef
8 changed files with 63 additions and 189 deletions

View File

@ -35,7 +35,6 @@
#include <QUndoStack>
#include <Qt>
#include "../../undocommands/adddetnode.h"
#include "../ifc/ifcdef.h"
#include "../ifc/xml/vabstractpattern.h"
#include "../vgeometry/vgobject.h"
@ -176,6 +175,14 @@ void VAbstractNode::ToolCreation(const Source &typeCreation)
*/
void VAbstractNode::AddToModeling(const QDomElement &domElement)
{
AddDetNode *addNode = new AddDetNode(domElement, doc, m_drawName);
qApp->getUndoStack()->push(addNode);
QDomElement modeling;
if (m_drawName.isEmpty())
{
doc->GetActivNodeElement(VAbstractPattern::TagModeling, modeling);
}
else
{
modeling = doc->GetDraw(m_drawName).firstChildElement(VAbstractPattern::TagModeling);
}
modeling.appendChild(domElement);
}

View File

@ -50,7 +50,6 @@ VToolPiecePath *VToolPiecePath::Create(QSharedPointer<DialogTool> dialog, VMainG
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
qApp->getUndoStack()->beginMacro("add path");
initData.path.SetNodes(PrepareNodes(initData.path, scene, doc, data));
VToolPiecePath *pathTool = Create(initData);
@ -276,10 +275,6 @@ void VToolPiecePath::ToolCreation(const Source &typeCreation)
if (typeCreation == Source::FromGui || typeCreation == Source::FromTool)
{
AddToFile();
if (typeCreation != Source::FromTool)
{
qApp->getUndoStack()->endMacro();
}
}
else
{

View File

@ -101,7 +101,6 @@ VToolSeamAllowance *VToolSeamAllowance::Create(QSharedPointer<DialogTool> dialog
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
qApp->getUndoStack()->beginMacro("add detail");
initData.detail.GetPath().SetNodes(PrepareNodes(initData.detail.GetPath(), scene, doc, data));
VToolSeamAllowance *piece = Create(initData);
@ -921,9 +920,7 @@ void VToolSeamAllowance::AddToFile()
AddInternalPaths(doc, domElement, piece.GetInternalPaths());
AddPins(doc, domElement, piece.GetPins());
AddPiece *addDet = new AddPiece(domElement, doc, piece, m_drawName);
connect(addDet, &AddPiece::NeedFullParsing, doc, &VAbstractPattern::NeedFullParsing);
qApp->getUndoStack()->push(addDet);
qApp->getUndoStack()->push(new AddPiece(domElement, doc, VAbstractTool::data, m_sceneDetails, m_drawName));
}
//---------------------------------------------------------------------------------------------------------------------
@ -1594,10 +1591,6 @@ void VToolSeamAllowance::ToolCreation(const Source &typeCreation)
if (typeCreation == Source::FromGui || typeCreation == Source::FromTool)
{
AddToFile();
if (typeCreation != Source::FromTool)
{
qApp->getUndoStack()->endMacro();
}
}
else
{

View File

@ -1,106 +0,0 @@
/************************************************************************
**
** @file adddetnode.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 15 6, 2014
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2013-2015 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 "adddetnode.h"
#include <QByteArray>
#include <QDomNode>
#include "../vmisc/logging.h"
#include "../ifc/xml/vabstractpattern.h"
#include "vundocommand.h"
//---------------------------------------------------------------------------------------------------------------------
AddDetNode::AddDetNode(const QDomElement &xml, VAbstractPattern *doc, const QString &drawName, QUndoCommand *parent)
: VUndoCommand(xml, doc, parent), m_drawName(drawName)
{
setText(QObject::tr("add node"));
nodeId = doc->GetParametrId(xml);
}
//---------------------------------------------------------------------------------------------------------------------
AddDetNode::~AddDetNode()
{}
//---------------------------------------------------------------------------------------------------------------------
void AddDetNode::undo()
{
qCDebug(vUndo, "Undo.");
QDomElement modeling = GetModelingSection();
if (not modeling.isNull())
{
QDomElement domElement = doc->elementById(nodeId);
if (domElement.isElement())
{
if (modeling.removeChild(domElement).isNull())
{
qCDebug(vUndo, "Can't delete node.");
}
}
else
{
qCDebug(vUndo, "Can't get node by id = %u.", nodeId);
}
}
else
{
qCDebug(vUndo, "Can't find tag %s.", qUtf8Printable(VAbstractPattern::TagModeling));
}
}
//---------------------------------------------------------------------------------------------------------------------
void AddDetNode::redo()
{
qCDebug(vUndo, "Redo.");
QDomElement modeling = GetModelingSection();
if (not modeling.isNull())
{
modeling.appendChild(xml);
}
else
{
qCDebug(vUndo, "Can't find tag %s.", qUtf8Printable(VAbstractPattern::TagModeling));
}
}
//---------------------------------------------------------------------------------------------------------------------
QDomElement AddDetNode::GetModelingSection() const
{
QDomElement modeling;
if (m_drawName.isEmpty())
{
doc->GetActivNodeElement(VAbstractPattern::TagModeling, modeling);
}
else
{
modeling = doc->GetDraw(m_drawName).firstChildElement(VAbstractPattern::TagModeling);
}
return modeling;
}

View File

@ -1,57 +0,0 @@
/************************************************************************
**
** @file adddetnode.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 15 6, 2014
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2013-2015 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 ADDDETNODE_H
#define ADDDETNODE_H
#include <qcompilerdetection.h>
#include <QDomElement>
#include <QMetaObject>
#include <QObject>
#include <QString>
#include <QtGlobal>
#include "vundocommand.h"
class AddDetNode : public VUndoCommand
{
Q_OBJECT
public:
AddDetNode(const QDomElement &xml, VAbstractPattern *doc, const QString &drawName, QUndoCommand *parent = nullptr);
virtual ~AddDetNode() Q_DECL_OVERRIDE;
virtual void undo() Q_DECL_OVERRIDE;
virtual void redo() Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(AddDetNode)
QString m_drawName;
QDomElement GetModelingSection() const;
};
#endif // ADDDETNODE_H

View File

@ -29,21 +29,33 @@
#include "addpiece.h"
#include "../vpatterndb/vpiecenode.h"
#include "../vpatterndb/vpiecepath.h"
#include "../vwidgets/vmaingraphicsview.h"
//---------------------------------------------------------------------------------------------------------------------
AddPiece::AddPiece(const QDomElement &xml, VAbstractPattern *doc, const VPiece &detail, const QString &drawName,
QUndoCommand *parent)
AddPiece::AddPiece(const QDomElement &xml, VAbstractPattern *doc, VContainer data, VMainGraphicsScene *scene,
const QString &drawName, QUndoCommand *parent)
: VUndoCommand(xml, doc, parent),
m_detail(detail),
m_drawName(drawName)
m_detail(),
m_drawName(drawName),
m_tool(),
m_record(),
m_scene(scene),
m_data(data)
{
setText(tr("add detail"));
nodeId = doc->GetParametrId(xml);
m_detail = data.GetPiece(nodeId);
m_record = VAbstractTool::GetRecord(nodeId, Tool::Piece, doc);
}
//---------------------------------------------------------------------------------------------------------------------
AddPiece::~AddPiece()
{}
{
if (not m_tool.isNull())
{
delete m_tool;
}
}
//---------------------------------------------------------------------------------------------------------------------
void AddPiece::undo()
@ -62,10 +74,23 @@ void AddPiece::undo()
return;
}
m_tool = qobject_cast<VToolSeamAllowance*>(VAbstractPattern::getTool(nodeId));
SCASSERT(not m_tool.isNull());
m_tool->DisconnectOutsideSignals();
m_tool->hide();
m_scene->removeItem(m_tool);
VAbstractPattern::RemoveTool(nodeId);
m_data.RemovePiece(nodeId);
VAbstractTool::RemoveRecord(m_record, doc);
DecrementReferences(m_detail.GetPath().GetNodes());
DecrementReferences(m_detail.GetCustomSARecords());
DecrementReferences(m_detail.GetInternalPaths());
DecrementReferences(m_detail.GetPins());
VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView());
}
else
{
@ -90,13 +115,28 @@ void AddPiece::redo()
if (not details.isNull())
{
details.appendChild(xml);
if (not m_tool.isNull())
{
VAbstractPattern::AddTool(nodeId, m_tool);
m_data.UpdatePiece(nodeId, m_detail);
m_tool->ReinitInternals(m_detail, m_scene);
VAbstractTool::AddRecord(m_record, doc);
m_scene->addItem(m_tool);
m_tool->ConnectOutsideSignals();
m_tool->show();
m_tool.clear();
}
VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView());
}
else
{
qCDebug(vUndo, "Can't find tag %s.", qUtf8Printable(VAbstractPattern::TagDetails));
return;
}
RedoFullParsing();
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -44,8 +44,8 @@ class AddPiece : public VUndoCommand
{
Q_OBJECT
public:
AddPiece(const QDomElement &xml, VAbstractPattern *doc, const VPiece &detail, const QString &drawName = QString(),
QUndoCommand *parent = nullptr);
AddPiece(const QDomElement &xml, VAbstractPattern *doc, VContainer data, VMainGraphicsScene *scene,
const QString &drawName = QString(), QUndoCommand *parent = nullptr);
virtual ~AddPiece();
// cppcheck-suppress unusedFunction
@ -57,6 +57,10 @@ private:
VPiece m_detail;
QString m_drawName;
QPointer<VToolSeamAllowance> m_tool;
VToolRecord m_record;
VMainGraphicsScene *m_scene;
VContainer m_data;
QDomElement GetDetailsSection() const;
};

View File

@ -10,7 +10,6 @@ HEADERS += \
$$PWD/savetooloptions.h \
$$PWD/deltool.h \
$$PWD/deletepatternpiece.h \
$$PWD/adddetnode.h \
$$PWD/vundocommand.h \
$$PWD/renamepp.h \
$$PWD/label/movelabel.h \
@ -38,7 +37,6 @@ SOURCES += \
$$PWD/savetooloptions.cpp \
$$PWD/deltool.cpp \
$$PWD/deletepatternpiece.cpp \
$$PWD/adddetnode.cpp \
$$PWD/vundocommand.cpp \
$$PWD/renamepp.cpp \
$$PWD/label/movelabel.cpp \