diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 94f65cb3e..0dc58046a 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -115,6 +115,7 @@ MainWindow::MainWindow(QWidget *parent) connect(doc, &VPattern::UndoCommand, this, &MainWindow::FullParseFile); connect(doc, &VPattern::SetEnabledGUI, this, &MainWindow::SetEnabledGUI); connect(doc, &VPattern::CheckLayout, this, &MainWindow::Layout); + connect(doc, &VPattern::SetCurrentPP, this, &MainWindow::GlobalChangePP); qApp->setCurrentDocument(doc); connect(qApp->getUndoStack(), &QUndoStack::cleanChanged, this, &MainWindow::PatternWasModified); @@ -1484,7 +1485,23 @@ void MainWindow::FullParseFile() comboBoxDraws->blockSignals(false); ui->actionPattern_properties->setEnabled(true); - qint32 index = comboBoxDraws->findText(patternPiece); + GlobalChangePP(patternPiece); + + if (comboBoxDraws->count() > 0) + { + SetEnableTool(true); + } + else + { + SetEnableTool(false); + } + SetEnableWidgets(true); +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::GlobalChangePP(const QString &patternPiece) +{ + const qint32 index = comboBoxDraws->findText(patternPiece); try { if ( index != -1 ) @@ -1508,19 +1525,8 @@ void MainWindow::FullParseFile() SetEnabledGUI(false); return; } - - if (comboBoxDraws->count() > 0) - { - SetEnableTool(true); - } - else - { - SetEnableTool(false); - } - SetEnableWidgets(true); } - //--------------------------------------------------------------------------------------------------------------------- void MainWindow::SetEnabledGUI(bool enabled) { diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index 498ab2f52..0169846c4 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -127,6 +127,7 @@ public slots: void ClickEndVisualization(); void Layout(); void UpdateGradation(); + void GlobalChangePP(const QString &patternPiece); signals: /** * @brief ModelChosen emit after calculation all details. diff --git a/src/app/undocommands/addtocalc.cpp b/src/app/undocommands/addtocalc.cpp index 9074bd8c9..db5487e81 100644 --- a/src/app/undocommands/addtocalc.cpp +++ b/src/app/undocommands/addtocalc.cpp @@ -48,7 +48,7 @@ AddToCalc::~AddToCalc() //--------------------------------------------------------------------------------------------------------------------- void AddToCalc::undo() { - doc->ChangeActivPP(nameActivDraw); + doc->ChangeActivPP(nameActivDraw);//User will not see this change doc->setCursor(cursor); QDomElement calcElement; @@ -80,12 +80,13 @@ void AddToCalc::undo() } emit NeedFullParsing(); VAbstractTool::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); + doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo } //--------------------------------------------------------------------------------------------------------------------- void AddToCalc::redo() { - doc->ChangeActivPP(nameActivDraw); + doc->ChangeActivPP(nameActivDraw);//User will not see this change doc->setCursor(cursor); QDomElement calcElement; @@ -118,3 +119,14 @@ void AddToCalc::redo() RedoFullParsing(); VAbstractTool::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); } + +//--------------------------------------------------------------------------------------------------------------------- +void AddToCalc::RedoFullParsing() +{ + if (redoFlag) + { + emit NeedFullParsing(); + doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo + } + redoFlag = true; +} diff --git a/src/app/undocommands/addtocalc.h b/src/app/undocommands/addtocalc.h index e09e18cb5..81d589d82 100644 --- a/src/app/undocommands/addtocalc.h +++ b/src/app/undocommands/addtocalc.h @@ -39,6 +39,8 @@ public: virtual ~AddToCalc(); virtual void undo(); virtual void redo(); +protected: + virtual void RedoFullParsing(); private: Q_DISABLE_COPY(AddToCalc) const QString nameActivDraw; diff --git a/src/app/undocommands/deltool.cpp b/src/app/undocommands/deltool.cpp index 386b91f74..5097f5a10 100644 --- a/src/app/undocommands/deltool.cpp +++ b/src/app/undocommands/deltool.cpp @@ -33,40 +33,14 @@ //--------------------------------------------------------------------------------------------------------------------- DelTool::DelTool(VPattern *doc, quint32 id, QUndoCommand *parent) - : VUndoCommand(QDomElement(), doc, parent), parentNode(QDomNode()), siblingId(NULL_ID) + : VUndoCommand(QDomElement(), doc, parent), parentNode(QDomNode()), siblingId(NULL_ID), + nameActivDraw(doc->GetNameActivPP()) { setText(tr("Delete tool")); nodeId = id; - - QVector history = doc->getLocalHistory(); - for (qint32 i = 0; i< history.size(); ++i) - { - const VToolRecord tool = history.at(i); - if (nodeId == tool.getId()) - { - if (i == 0) - { - siblingId = NULL_ID; - } - else - { - const VToolRecord tool = history.at(i-1); - siblingId = tool.getId(); - } - } - } - - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - xml = domElement.cloneNode().toElement(); - parentNode = domElement.parentNode(); - } - else - { - qDebug()<<"Can't get tool by id = "<SiblingNodeId(nodeId); + parentNode = doc->ParentNodeById(nodeId); + xml = doc->CloneNodeById(nodeId); } //--------------------------------------------------------------------------------------------------------------------- @@ -78,20 +52,14 @@ void DelTool::undo() { UndoDeleteAfterSibling(parentNode, siblingId); emit NeedFullParsing(); + doc->SetCurrentPP(nameActivDraw); } //--------------------------------------------------------------------------------------------------------------------- void DelTool::redo() { - QDomElement domElement = doc->elementById(QString().setNum(nodeId)); - if (domElement.isElement()) - { - parentNode.removeChild(domElement); - emit NeedFullParsing(); - } - else - { - qDebug()<<"Can't get tool by id = "<NodeById(nodeId); + parentNode.removeChild(domElement); + emit NeedFullParsing(); + doc->SetCurrentPP(nameActivDraw); } diff --git a/src/app/undocommands/deltool.h b/src/app/undocommands/deltool.h index dfa19dabe..df8c12377 100644 --- a/src/app/undocommands/deltool.h +++ b/src/app/undocommands/deltool.h @@ -42,8 +42,9 @@ public: virtual void redo(); private: Q_DISABLE_COPY(DelTool) - QDomNode parentNode; - quint32 siblingId; + QDomNode parentNode; + quint32 siblingId; + const QString nameActivDraw; }; #endif // DELTOOL_H diff --git a/src/app/undocommands/vundocommand.cpp b/src/app/undocommands/vundocommand.cpp index 9391f8dd0..dc09e65ae 100644 --- a/src/app/undocommands/vundocommand.cpp +++ b/src/app/undocommands/vundocommand.cpp @@ -59,14 +59,7 @@ void VUndoCommand::UndoDeleteAfterSibling(QDomNode &parentNode, const quint32 &s } else { - const QDomElement refElement = doc->elementById(QString().setNum(siblingId)); - if (refElement.isElement()) - { - parentNode.insertAfter(xml, refElement); - } - else - { - qDebug()<<"Can't find sibling node."; - } + const QDomElement refElement = doc->NodeById(siblingId); + parentNode.insertAfter(xml, refElement); } } diff --git a/src/app/undocommands/vundocommand.h b/src/app/undocommands/vundocommand.h index 57120e6fb..d14e85ca0 100644 --- a/src/app/undocommands/vundocommand.h +++ b/src/app/undocommands/vundocommand.h @@ -60,12 +60,12 @@ signals: void NeedFullParsing(); void NeedLiteParsing(const Document &parse); protected: - QDomElement xml; - VPattern *doc; - quint32 nodeId; - bool redoFlag; - void RedoFullParsing(); - void UndoDeleteAfterSibling(QDomNode &parentNode, const quint32 &siblingId) const; + QDomElement xml; + VPattern *doc; + quint32 nodeId; + bool redoFlag; + virtual void RedoFullParsing(); + void UndoDeleteAfterSibling(QDomNode &parentNode, const quint32 &siblingId) const; private: Q_DISABLE_COPY(VUndoCommand) }; diff --git a/src/app/version.h b/src/app/version.h index 49a67f980..f9653698d 100644 --- a/src/app/version.h +++ b/src/app/version.h @@ -37,7 +37,6 @@ extern const int DEBUG_VERSION; extern const QString APP_VERSION; -// Don't forget change version number in manifest file /src/app/share/resources/valentina.exe.manifest. // Change version number in version.cpp also. #define VER_FILEVERSION 0,2,8,0 diff --git a/src/app/xml/vdomdocument.cpp b/src/app/xml/vdomdocument.cpp index 54e855dcc..e389c006d 100644 --- a/src/app/xml/vdomdocument.cpp +++ b/src/app/xml/vdomdocument.cpp @@ -600,3 +600,28 @@ void VDomDocument::RemoveAllChild(QDomElement &domElement) } } } + +//--------------------------------------------------------------------------------------------------------------------- +QDomNode VDomDocument::ParentNodeById(const quint32 &nodeId) +{ + QDomElement domElement = NodeById(nodeId); + return domElement.parentNode(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QDomElement VDomDocument::CloneNodeById(const quint32 &nodeId) +{ + QDomElement domElement = NodeById(nodeId); + return domElement.cloneNode().toElement(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QDomElement VDomDocument::NodeById(const quint32 &nodeId) +{ + QDomElement domElement = elementById(QString().setNum(nodeId)); + if (domElement.isNull() || domElement.isElement() == false) + { + throw VExceptionBadId(tr("Couldn't get node"), nodeId); + } + return domElement; +} diff --git a/src/app/xml/vdomdocument.h b/src/app/xml/vdomdocument.h index 088aaee7a..4cb915190 100644 --- a/src/app/xml/vdomdocument.h +++ b/src/app/xml/vdomdocument.h @@ -109,6 +109,10 @@ public: QString Minor() const; QString Patch() const; static void RemoveAllChild(QDomElement &domElement); + + QDomNode ParentNodeById(const quint32 &nodeId); + QDomElement CloneNodeById(const quint32 &nodeId); + QDomElement NodeById(const quint32 &nodeId); protected: /** @brief data container with data. */ VContainer *data; diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index d842e1ba6..2dc7220f4 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -2741,7 +2741,7 @@ QRectF VPattern::ToolBoundingRect(const QRectF &rec, const quint32 &id) const //--------------------------------------------------------------------------------------------------------------------- -QVector VPattern::getLocalHistory() +QVector VPattern::getLocalHistory() const { QVector historyPP; for (qint32 i = 0; i< history.size(); ++i) @@ -2755,3 +2755,45 @@ QVector VPattern::getLocalHistory() } return historyPP; } + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VPattern::SiblingNodeId(const quint32 &nodeId) const +{ + quint32 siblingId = NULL_ID; + + const QVector history = getLocalHistory(); + for (qint32 i = 0; i < history.size(); ++i) + { + const VToolRecord tool = history.at(i); + if (nodeId == tool.getId()) + { + if (i == 0) + { + siblingId = NULL_ID; + } + else + { + for (qint32 j = i; j > 0; --j) + { + const VToolRecord tool = history.at(j-1); + switch ( tool.getTypeTool() ) + { + case Tool::Detail: + case Tool::UnionDetails: + case Tool::NodeArc: + case Tool::NodePoint: + case Tool::NodeSpline: + case Tool::NodeSplinePath: + continue; + break; + default: + siblingId = tool.getId(); + j = 0;// break loop + break; + } + } + } + } + } + return siblingId; +} diff --git a/src/app/xml/vpattern.h b/src/app/xml/vpattern.h index 24b7bdb81..50eb05f00 100644 --- a/src/app/xml/vpattern.h +++ b/src/app/xml/vpattern.h @@ -72,7 +72,7 @@ public: QHash* getTools(); VDataTool* getTool(const quint32 &id); QVector *getHistory(); - QVector getLocalHistory(); + QVector getLocalHistory() const; quint32 getCursor() const; void setCursor(const quint32 &value); void setCurrentData(); @@ -183,6 +183,8 @@ public: void SetVersion(); QString GenerateLabel(const LabelType &type)const; + + quint32 SiblingNodeId(const quint32 &nodeId) const; signals: /** * @brief ChangedActivDraw change active pattern peace. @@ -219,6 +221,7 @@ signals: void UndoCommand(); void SetEnabledGUI(bool enabled); void CheckLayout(); + void SetCurrentPP(const QString &patterPiece); public slots: void LiteParseTree(const Document &parse); void haveLiteChange();