From b14a3c9551f3edf001557f1274b5d536565853a3 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Tue, 21 Jun 2016 19:53:15 +0200 Subject: [PATCH] Fixed the SaveDetailOption::undo method and few code style issues --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 2 +- src/libs/vpatterndb/vpatternpiecedata.cpp | 6 +-- .../vtools/dialogs/tools/dialogdetail.cpp | 3 +- src/libs/vtools/dialogs/tools/dialogdetail.h | 2 +- src/libs/vtools/tools/vtooldetail.cpp | 2 +- .../vtools/undocommands/savedetailoptions.cpp | 38 +++++++++++-------- .../vtools/undocommands/savedetailoptions.h | 1 + 7 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 4332f78bb..d0fe27435 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -47,7 +47,7 @@ #include "../vgeometry/vcubicbezierpath.h" #include "../core/vapplication.h" #include "../vpatterndb/calculator.h" -#include "vpatternpiecedata.h" +#include "../vpatterndb/vpatternpiecedata.h" #include #include diff --git a/src/libs/vpatterndb/vpatternpiecedata.cpp b/src/libs/vpatterndb/vpatternpiecedata.cpp index bb26f1644..72826edd1 100644 --- a/src/libs/vpatterndb/vpatternpiecedata.cpp +++ b/src/libs/vpatterndb/vpatternpiecedata.cpp @@ -69,7 +69,7 @@ const MaterialCutPlacement& VPatternPieceData::GetMCP(int i) const { Q_ASSERT(i >= 0); Q_ASSERT(i < GetMCPCount()); - return m_conMCP[i]; + return m_conMCP.at(i); } //--------------------------------------------------------------------------------------------------------------------- @@ -83,8 +83,8 @@ void VPatternPieceData::RemoveMCP(int i) //--------------------------------------------------------------------------------------------------------------------- void VPatternPieceData::Clear() { - m_qsLetter = ""; - m_qsName = ""; + m_qsLetter.clear(); + m_qsName.clear(); m_conMCP.clear(); } diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.cpp b/src/libs/vtools/dialogs/tools/dialogdetail.cpp index cfe14c8fe..8c4cbba48 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.cpp +++ b/src/libs/vtools/dialogs/tools/dialogdetail.cpp @@ -36,7 +36,6 @@ #include "../../../vgeometry/vsplinepath.h" #include "../../../vpatterndb/vcontainer.h" #include "../../../ifc/xml/vdomdocument.h" -#include "vpatternpiecedata.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -173,7 +172,7 @@ void DialogDetail::UpdateList() ui.listWidgetMCP->clear(); for (int i = 0; i < m_conMCP.count(); ++i) { - MaterialCutPlacement mcp = m_conMCP[i]; + MaterialCutPlacement mcp = m_conMCP.at(i); QString qsText = tr("Cut %1 of %2%3").arg(mcp.m_iCutNumber); if (mcp.m_eMaterial < MaterialType::mtUserDefined) { diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.h b/src/libs/vtools/dialogs/tools/dialogdetail.h index 85dda1627..c03e33635 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.h +++ b/src/libs/vtools/dialogs/tools/dialogdetail.h @@ -32,7 +32,7 @@ #include "ui_dialogdetail.h" #include "dialogtool.h" #include "../vpatterndb/vdetail.h" -#include "vpatternpiecedata.h" +#include "../vpatterndb/vpatternpiecedata.h" /** * @brief The DialogDetail class dialog for ToolDetai. Help create detail and edit option. diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 222126575..75c5c5864 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -40,7 +40,7 @@ #include "../undocommands/movedetail.h" #include "../undocommands/adddet.h" #include "../undocommands/deletedetail.h" -#include "vpatternpiecedata.h" +#include "../vpatterndb/vpatternpiecedata.h" #include #include diff --git a/src/libs/vtools/undocommands/savedetailoptions.cpp b/src/libs/vtools/undocommands/savedetailoptions.cpp index 005b87504..0576c9700 100644 --- a/src/libs/vtools/undocommands/savedetailoptions.cpp +++ b/src/libs/vtools/undocommands/savedetailoptions.cpp @@ -27,10 +27,10 @@ *************************************************************************/ #include "savedetailoptions.h" -#include "vpatternpiecedata.h" #include "../tools/nodeDetails/vabstractnode.h" #include "../../vwidgets/vmaingraphicsview.h" #include "../ifc/xml/vabstractpattern.h" +#include "../vpatterndb/vpatternpiecedata.h" #include @@ -57,6 +57,7 @@ void SaveDetailOptions::undo() { SaveDet(domElement, oldDet); doc->RemoveAllChildren(domElement); + SavePatternPieceData(domElement, oldDet); for (int i = 0; i < oldDet.CountNode(); ++i) { VToolDetail::AddNode(doc, domElement, oldDet.at(i)); @@ -81,21 +82,7 @@ void SaveDetailOptions::redo() { SaveDet(domElement, newDet); doc->RemoveAllChildren(domElement); - - QDomElement domData = doc->createElement(VAbstractPattern::TagData); - doc->SetAttribute(domData, VAbstractPattern::AttrLetter, newDet.GetPatternPieceData().GetLetter()); - doc->SetAttribute(domData, VAbstractPattern::AttrName, newDet.GetPatternPieceData().GetName()); - for (int i = 0; i < newDet.GetPatternPieceData().GetMCPCount(); ++i) - { - MaterialCutPlacement mcp = newDet.GetPatternPieceData().GetMCP(i); - QDomElement domMCP = doc->createElement(VAbstractPattern::TagMCP); - doc->SetAttribute(domMCP, VAbstractPattern::AttrMaterial, int(mcp.m_eMaterial)); - doc->SetAttribute(domMCP, VAbstractPattern::AttrUserDefined, mcp.m_qsMaterialUserDef); - doc->SetAttribute(domMCP, VAbstractPattern::AttrCutNumber, mcp.m_iCutNumber); - doc->SetAttribute(domMCP, VAbstractPattern::AttrPlacement, int(mcp.m_ePlacement)); - domData.appendChild(domMCP); - } - domElement.appendChild(domData); + SavePatternPieceData(domElement, newDet); for (int i = 0; i < newDet.CountNode(); ++i) { @@ -142,3 +129,22 @@ void SaveDetailOptions::SaveDet(QDomElement &domElement, const VDetail &det) doc->SetAttribute(domElement, VToolDetail::AttrClosed, QString().setNum(det.getClosed())); doc->SetAttribute(domElement, VToolDetail::AttrWidth, QString().setNum(det.getWidth())); } + +//--------------------------------------------------------------------------------------------------------------------- +void SaveDetailOptions::SavePatternPieceData(QDomElement &domElement, const VDetail &det) +{ + QDomElement domData = doc->createElement(VAbstractPattern::TagData); + doc->SetAttribute(domData, VAbstractPattern::AttrLetter, det.GetPatternPieceData().GetLetter()); + doc->SetAttribute(domData, VAbstractPattern::AttrName, det.GetPatternPieceData().GetName()); + for (int i = 0; i < det.GetPatternPieceData().GetMCPCount(); ++i) + { + MaterialCutPlacement mcp = det.GetPatternPieceData().GetMCP(i); + QDomElement domMCP = doc->createElement(VAbstractPattern::TagMCP); + doc->SetAttribute(domMCP, VAbstractPattern::AttrMaterial, int(mcp.m_eMaterial)); + doc->SetAttribute(domMCP, VAbstractPattern::AttrUserDefined, mcp.m_qsMaterialUserDef); + doc->SetAttribute(domMCP, VAbstractPattern::AttrCutNumber, mcp.m_iCutNumber); + doc->SetAttribute(domMCP, VAbstractPattern::AttrPlacement, int(mcp.m_ePlacement)); + domData.appendChild(domMCP); + } + domElement.appendChild(domData); +} diff --git a/src/libs/vtools/undocommands/savedetailoptions.h b/src/libs/vtools/undocommands/savedetailoptions.h index 922a7a976..99d796ecb 100644 --- a/src/libs/vtools/undocommands/savedetailoptions.h +++ b/src/libs/vtools/undocommands/savedetailoptions.h @@ -53,6 +53,7 @@ private: VDetail newDet; QGraphicsScene *scene; void SaveDet(QDomElement &domElement, const VDetail &det); + void SavePatternPieceData(QDomElement &domElement, const VDetail &det); }; //---------------------------------------------------------------------------------------------------------------------