From 6bd1a460e66b4f6cccd895d6e54c4675b654cd43 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 25 Sep 2017 18:15:28 +0300 Subject: [PATCH] Refactor method VPattern::setCurrentData(). It should use method VAbstractPattern::getLocalHistory(). --HG-- branch : develop --- src/app/valentina/xml/vpattern.cpp | 34 +++++++-------------------- src/libs/ifc/xml/vabstractpattern.cpp | 10 -------- src/libs/ifc/xml/vabstractpattern.h | 10 ++++++++ 3 files changed, 18 insertions(+), 36 deletions(-) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index b43467821..57a7c6509 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -254,41 +254,23 @@ void VPattern::setCurrentData() { if (*mode == Draw::Calculation) { - if (CountPP() > 1)//don't need upadate data if we have only one pattern piece + const int countPP = CountPP(); + if (countPP > 1)//don't need upadate data if we have only one pattern piece { qCDebug(vXML, "Setting current data"); qCDebug(vXML, "Current PP name %s", qUtf8Printable(nameActivPP)); - qCDebug(vXML, "PP count %d", CountPP()); + qCDebug(vXML, "PP count %d", countPP); - quint32 id = 0; - if (history.size() == 0) + const QVector localHistory = getLocalHistory(); + if (localHistory.size() == 0) { qCDebug(vXML, "History is empty!"); return; } - for (qint32 i = 0; i < history.size(); ++i) - { - const VToolRecord tool = history.at(i); - if (tool.getNameDraw() == nameActivPP) - { - id = tool.getId(); - } - } - qCDebug(vXML, "Resoring data from tool with id %u", id); - if (id == NULL_ID) - { - qCDebug(vXML, "Could not find record for this current pattern piece %s", - qUtf8Printable(nameActivPP)); - const VToolRecord tool = history.at(history.size()-1); - id = tool.getId(); - qCDebug(vXML, "Taking record with id %u from PP %s", id, qUtf8Printable(tool.getNameDraw())); - if (id == NULL_ID) - { - qCDebug(vXML, "Bad id for last record in history."); - return; - } - } + const quint32 id = localHistory.last().getId(); + qCDebug(vXML, "Resoring data from tool with id %u", id); + if (tools.size() > 0) { try diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 6c87c238a..1e442e673 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -307,16 +307,6 @@ void VAbstractPattern::ChangeActivPP(const QString &name, const Document &parse) } } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetNameActivPP return current pattern piece name. - * @return pattern piece name. - */ -QString VAbstractPattern::GetNameActivPP() const -{ - return nameActivPP; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief GetActivDrawElement return draw tag for current pattern peace. diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 874d2b0ed..6b5ae7b76 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -446,4 +446,14 @@ private: void SetMaterials(QDomElement &element, const QMap &materials); }; +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetNameActivPP return current pattern piece name. + * @return pattern piece name. + */ +inline QString VAbstractPattern::GetNameActivPP() const +{ + return nameActivPP; +} + #endif // VABSTRACTPATTERN_H