From fe9dc90dc7335e43eef8b30507c3d155cfc8397e Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 25 Jul 2018 11:26:09 +0300 Subject: [PATCH] Bug in undocommands. We should return to pattern piece only if in Calculation mode. If do it in Details mode Valentina may not switch pattern piece back when a user returns to Calculation mode. This breaks a work and no new object can be added to pattern. --HG-- branch : develop --- src/app/valentina/mainwindow.cpp | 26 +++++++++---------- src/app/valentina/mainwindow.h | 3 --- src/app/valentina/xml/vpattern.cpp | 7 +++-- src/app/valentina/xml/vpattern.h | 5 +--- src/libs/vgeometry/vgeometrydef.h | 1 - src/libs/vgeometry/vgobject.h | 1 + src/libs/vmisc/def.h | 1 + src/libs/vmisc/vabstractapplication.cpp | 15 ++++++++++- src/libs/vmisc/vabstractapplication.h | 6 +++++ src/libs/vtools/undocommands/addgroup.cpp | 5 +++- .../vtools/undocommands/additemtogroup.cpp | 5 +++- src/libs/vtools/undocommands/addtocalc.cpp | 10 +++++-- .../undocommands/deletepatternpiece.cpp | 11 ++++++-- src/libs/vtools/undocommands/delgroup.cpp | 11 +++++--- src/libs/vtools/undocommands/deltool.cpp | 14 +++++++--- .../undocommands/removeitemfromgroup.cpp | 6 ++++- 16 files changed, 87 insertions(+), 40 deletions(-) diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 8c3361f59..019f7679b 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -130,7 +130,7 @@ MainWindow::MainWindow(QWidget *parent) dialogTool(), dialogHistory(nullptr), dialogFMeasurements(nullptr), - comboBoxDraws(nullptr), patternPieceLabel(nullptr), mode(Draw::Calculation), + comboBoxDraws(nullptr), patternPieceLabel(nullptr), currentDrawIndex(0), currentToolBoxIndex(0), isDockToolOptionsVisible(true), isDockGroupsVisible(true), @@ -159,7 +159,7 @@ MainWindow::MainWindow(QWidget *parent) CreateActions(); InitScenes(); - doc = new VPattern(pattern, &mode, sceneDraw, sceneDetails); + doc = new VPattern(pattern, sceneDraw, sceneDetails); connect(doc, &VPattern::ClearMainWindow, this, &MainWindow::Clear); connect(doc, &VPattern::patternChanged, this, &MainWindow::PatternChangesWereSaved); connect(doc, &VPattern::UndoCommand, this, &MainWindow::FullParseFile); @@ -2463,7 +2463,7 @@ void MainWindow::keyPressEvent ( QKeyEvent * event ) */ void MainWindow::SaveCurrentScene() { - if (mode == Draw::Calculation || mode == Draw::Modeling) + if (qApp->GetDrawMode() == Draw::Calculation || qApp->GetDrawMode() == Draw::Modeling) { VMainGraphicsScene *scene = qobject_cast(currentScene); SCASSERT(scene != nullptr) @@ -2520,7 +2520,7 @@ void MainWindow::ActionDraw(bool checked) ui->view->setScene(currentScene); RestoreCurrentScene(); - mode = Draw::Calculation; + qApp->SetDrawMode(Draw::Calculation); comboBoxDraws->setCurrentIndex(currentDrawIndex);//restore current pattern peace drawMode = true; @@ -2594,11 +2594,11 @@ void MainWindow::ActionDetails(bool checked) ui->view->setScene(currentScene); RestoreCurrentScene(); - if (mode == Draw::Calculation) + if (qApp->GetDrawMode() == Draw::Calculation) { currentToolBoxIndex = ui->toolBox->currentIndex(); } - mode = Draw::Modeling; + qApp->SetDrawMode(Draw::Modeling); SetEnableTool(true); SetEnableWidgets(true); ui->toolBox->setCurrentIndex(ui->toolBox->indexOf(ui->detailPage)); @@ -2678,7 +2678,7 @@ void MainWindow::ActionLayout(bool checked) QMessageBox::information(this, tr("Layout mode"), tr("You can't use Layout mode yet. Please, " "include at least one detail in layout."), QMessageBox::Ok, QMessageBox::Ok); - mode == Draw::Calculation ? ActionDraw(true) : ActionDetails(true); + qApp->GetDrawMode() == Draw::Calculation ? ActionDraw(true) : ActionDetails(true); return; } } @@ -2700,7 +2700,7 @@ void MainWindow::ActionLayout(bool checked) QMessageBox::warning(this, tr("Layout mode"), tr("You can't use Layout mode yet.") + QLatin1String(" \n") + e.ErrorMessage(), QMessageBox::Ok, QMessageBox::Ok); - mode == Draw::Calculation ? ActionDraw(true) : ActionDetails(true); + qApp->GetDrawMode() == Draw::Calculation ? ActionDraw(true) : ActionDetails(true); return; } @@ -2708,11 +2708,11 @@ void MainWindow::ActionLayout(bool checked) emit ui->view->itemClicked(nullptr); ui->view->setScene(currentScene); - if (mode == Draw::Calculation) + if (qApp->GetDrawMode() == Draw::Calculation) { currentToolBoxIndex = ui->toolBox->currentIndex(); } - mode = Draw::Layout; + qApp->SetDrawMode(Draw::Layout); SetEnableTool(true); SetEnableWidgets(true); ui->toolBox->setCurrentIndex(ui->toolBox->indexOf(ui->layoutPage)); @@ -3307,8 +3307,8 @@ void MainWindow::SetEnabledGUI(bool enabled) */ void MainWindow::SetEnableWidgets(bool enable) { - const bool drawStage = (mode == Draw::Calculation); - const bool designStage = (drawStage || mode == Draw::Modeling); + const bool drawStage = (qApp->GetDrawMode() == Draw::Calculation); + const bool designStage = (drawStage || qApp->GetDrawMode() == Draw::Modeling); comboBoxDraws->setEnabled(enable && drawStage); ui->actionOptionDraw->setEnabled(enable && drawStage); @@ -3586,7 +3586,7 @@ void MainWindow::SetEnableTool(bool enable) QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wswitch-default") - switch (mode) + switch (qApp->GetDrawMode()) { case Draw::Calculation: drawTools = enable; diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index d336fe7fe..2fbac38de 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -246,9 +246,6 @@ private: QComboBox *comboBoxDraws; QLabel *patternPieceLabel; - /** @brief mode keep current draw mode. */ - Draw mode; - /** @brief currentDrawIndex save current selected pattern peace. */ qint32 currentDrawIndex; diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 6fd22fa4b..de073314e 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -90,9 +90,8 @@ void GatherCount(int &count, const int nodes) } //--------------------------------------------------------------------------------------------------------------------- -VPattern::VPattern(VContainer *data, Draw *mode, VMainGraphicsScene *sceneDraw, - VMainGraphicsScene *sceneDetail, QObject *parent) - : VAbstractPattern(parent), data(data), mode(mode), sceneDraw(sceneDraw), sceneDetail(sceneDetail) +VPattern::VPattern(VContainer *data, VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, QObject *parent) + : VAbstractPattern(parent), data(data), sceneDraw(sceneDraw), sceneDetail(sceneDetail) { SCASSERT(sceneDraw != nullptr) SCASSERT(sceneDetail != nullptr) @@ -269,7 +268,7 @@ void VPattern::Parse(const Document &parse) */ void VPattern::setCurrentData() { - if (*mode == Draw::Calculation) + if (qApp->GetDrawMode() == Draw::Calculation) { const int countPP = CountPP(); if (countPP > 1)//don't need upadate data if we have only one pattern piece diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index 3fddcf593..df18e833b 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -46,7 +46,7 @@ class VPattern : public VAbstractPattern { Q_OBJECT public: - VPattern(VContainer *data, Draw *mode, VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, + VPattern(VContainer *data, VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, QObject *parent = nullptr); virtual void CreateEmptyFile() override; @@ -125,9 +125,6 @@ private: /** @brief data container with data. */ VContainer *data; - /** @brief mode current draw mode. */ - Draw *mode; - VMainGraphicsScene *sceneDraw; VMainGraphicsScene *sceneDetail; diff --git a/src/libs/vgeometry/vgeometrydef.h b/src/libs/vgeometry/vgeometrydef.h index f3a4c1a7f..5faea0bdd 100644 --- a/src/libs/vgeometry/vgeometrydef.h +++ b/src/libs/vgeometry/vgeometrydef.h @@ -32,7 +32,6 @@ #include #include -enum class Draw : char { Calculation, Modeling, Layout }; enum class GOType : char { Point, diff --git a/src/libs/vgeometry/vgobject.h b/src/libs/vgeometry/vgobject.h index 5242169d6..4a5b1c441 100644 --- a/src/libs/vgeometry/vgobject.h +++ b/src/libs/vgeometry/vgobject.h @@ -36,6 +36,7 @@ #include #include "vgeometrydef.h" +#include "../vmisc/def.h" class QLineF; class QPoint; diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 1af1a667f..e038e1b4f 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -68,6 +68,7 @@ enum class Source : char { FromGui, FromFile, FromTool }; enum class NodeUsage : bool {NotInUse = false, InUse = true}; enum class SelectionType : bool {ByMousePress, ByMouseRelease}; enum class PageOrientation : bool {Portrait = true, Landscape = false}; +enum class Draw : char { Calculation, Modeling, Layout }; enum class PieceNodeAngle : unsigned char { diff --git a/src/libs/vmisc/vabstractapplication.cpp b/src/libs/vmisc/vabstractapplication.cpp index 5e0eafb81..2c54365e6 100644 --- a/src/libs/vmisc/vabstractapplication.cpp +++ b/src/libs/vmisc/vabstractapplication.cpp @@ -61,7 +61,8 @@ VAbstractApplication::VAbstractApplication(int &argc, char **argv) doc(nullptr), m_customerName(), m_userMaterials(), - openingPattern(false) + openingPattern(false), + mode(Draw::Calculation) { QString rules; @@ -259,6 +260,18 @@ QString VAbstractApplication::ClearMessage(QString msg) return msg; } +//--------------------------------------------------------------------------------------------------------------------- +const Draw &VAbstractApplication::GetDrawMode() const +{ + return mode; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractApplication::SetDrawMode(const Draw &value) +{ + mode = value; +} + //--------------------------------------------------------------------------------------------------------------------- #if defined(Q_OS_WIN) void VAbstractApplication::WinAttachConsole() diff --git a/src/libs/vmisc/vabstractapplication.h b/src/libs/vmisc/vabstractapplication.h index 78224747b..eb39ed56b 100644 --- a/src/libs/vmisc/vabstractapplication.h +++ b/src/libs/vmisc/vabstractapplication.h @@ -121,6 +121,9 @@ public: QMap GetUserMaterials() const; void SetUserMaterials(const QMap &userMaterials); + const Draw &GetDrawMode() const; + void SetDrawMode(const Draw &value); + protected: QUndoStack *undoStack; @@ -163,6 +166,9 @@ private: */ bool openingPattern; + /** @brief mode keep current draw mode. */ + Draw mode; + void ClearTranslation(); }; diff --git a/src/libs/vtools/undocommands/addgroup.cpp b/src/libs/vtools/undocommands/addgroup.cpp index bfc8390e7..5ace45524 100644 --- a/src/libs/vtools/undocommands/addgroup.cpp +++ b/src/libs/vtools/undocommands/addgroup.cpp @@ -92,7 +92,10 @@ void AddGroup::undo() } VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); - emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo + if (qApp->GetDrawMode() == Draw::Calculation) + { + emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/undocommands/additemtogroup.cpp b/src/libs/vtools/undocommands/additemtogroup.cpp index 120227ee2..1dea7c284 100644 --- a/src/libs/vtools/undocommands/additemtogroup.cpp +++ b/src/libs/vtools/undocommands/additemtogroup.cpp @@ -116,5 +116,8 @@ void AddItemToGroup::performUndoRedo(bool isUndo) } VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); - emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo + if (qApp->GetDrawMode() == Draw::Calculation) + { + emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo + } } diff --git a/src/libs/vtools/undocommands/addtocalc.cpp b/src/libs/vtools/undocommands/addtocalc.cpp index 49e0baae1..32898ba59 100644 --- a/src/libs/vtools/undocommands/addtocalc.cpp +++ b/src/libs/vtools/undocommands/addtocalc.cpp @@ -78,7 +78,10 @@ void AddToCalc::undo() } emit NeedFullParsing(); VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); - emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo + if (qApp->GetDrawMode() == Draw::Calculation) + { + emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo + } } //--------------------------------------------------------------------------------------------------------------------- @@ -125,7 +128,10 @@ void AddToCalc::RedoFullParsing() if (redoFlag) { emit NeedFullParsing(); - emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo + if (qApp->GetDrawMode() == Draw::Calculation) + { + emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo + } } else { diff --git a/src/libs/vtools/undocommands/deletepatternpiece.cpp b/src/libs/vtools/undocommands/deletepatternpiece.cpp index e575fce7d..5932e47a2 100644 --- a/src/libs/vtools/undocommands/deletepatternpiece.cpp +++ b/src/libs/vtools/undocommands/deletepatternpiece.cpp @@ -32,6 +32,7 @@ #include #include "../vmisc/logging.h" +#include "../vmisc/vabstractapplication.h" #include "../ifc/xml/vabstractpattern.h" #include "vundocommand.h" @@ -82,7 +83,10 @@ void DeletePatternPiece::undo() } emit NeedFullParsing(); - emit doc->SetCurrentPP(namePP);//Without this user will not see this change + if (qApp->GetDrawMode() == Draw::Calculation) + { + emit doc->SetCurrentPP(namePP);//Without this user will not see this change + } } //--------------------------------------------------------------------------------------------------------------------- @@ -90,7 +94,10 @@ void DeletePatternPiece::redo() { qCDebug(vUndo, "Redo."); - emit doc->SetCurrentPP(namePP);//Without this user will not see this change + if (qApp->GetDrawMode() == Draw::Calculation) + { + emit doc->SetCurrentPP(namePP);//Without this user will not see this change + } QDomElement rootElement = doc->documentElement(); const QDomElement patternPiece = doc->GetPPElement(namePP); rootElement.removeChild(patternPiece); diff --git a/src/libs/vtools/undocommands/delgroup.cpp b/src/libs/vtools/undocommands/delgroup.cpp index ad3d2b630..ef0594b11 100644 --- a/src/libs/vtools/undocommands/delgroup.cpp +++ b/src/libs/vtools/undocommands/delgroup.cpp @@ -58,7 +58,10 @@ void DelGroup::undo() { qCDebug(vUndo, "Undo."); - emit doc->SetCurrentPP(nameActivDraw);//Without this user will not see this change + if (qApp->GetDrawMode() == Draw::Calculation) + { + emit doc->SetCurrentPP(nameActivDraw);//Without this user will not see this change + } QDomElement groups = doc->CreateGroups(); if (not groups.isNull()) @@ -81,8 +84,10 @@ void DelGroup::redo() { qCDebug(vUndo, "Redo."); - //Keep first! - emit doc->SetCurrentPP(nameActivDraw);//Without this user will not see this change + if (qApp->GetDrawMode() == Draw::Calculation) + {//Keep first! + emit doc->SetCurrentPP(nameActivDraw);//Without this user will not see this change + } QDomElement groups = doc->CreateGroups(); if (not groups.isNull()) { diff --git a/src/libs/vtools/undocommands/deltool.cpp b/src/libs/vtools/undocommands/deltool.cpp index 0559bd4ef..80ec270e5 100644 --- a/src/libs/vtools/undocommands/deltool.cpp +++ b/src/libs/vtools/undocommands/deltool.cpp @@ -33,6 +33,7 @@ #include "../ifc/ifcdef.h" #include "../ifc/xml/vabstractpattern.h" #include "../vmisc/logging.h" +#include "../vmisc/vabstractapplication.h" #include "vundocommand.h" //--------------------------------------------------------------------------------------------------------------------- @@ -58,8 +59,11 @@ void DelTool::undo() UndoDeleteAfterSibling(parentNode, siblingId); emit NeedFullParsing(); - //Keep last! - emit doc->SetCurrentPP(nameActivDraw);//Without this user will not see this change + + if (qApp->GetDrawMode() == Draw::Calculation) + {//Keep last! + emit doc->SetCurrentPP(nameActivDraw);//Without this user will not see this change + } } //--------------------------------------------------------------------------------------------------------------------- @@ -67,8 +71,10 @@ void DelTool::redo() { qCDebug(vUndo, "Redo."); - //Keep first! - emit doc->SetCurrentPP(nameActivDraw);//Without this user will not see this change + if (qApp->GetDrawMode() == Draw::Calculation) + {//Keep first! + emit doc->SetCurrentPP(nameActivDraw);//Without this user will not see this change + } QDomElement domElement = doc->NodeById(nodeId); parentNode.removeChild(domElement); emit NeedFullParsing(); diff --git a/src/libs/vtools/undocommands/removeitemfromgroup.cpp b/src/libs/vtools/undocommands/removeitemfromgroup.cpp index 70e89d9dc..a4236f169 100644 --- a/src/libs/vtools/undocommands/removeitemfromgroup.cpp +++ b/src/libs/vtools/undocommands/removeitemfromgroup.cpp @@ -116,5 +116,9 @@ void RemoveItemFromGroup::performUndoRedo(bool isUndo) } VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); - emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo + + if (qApp->GetDrawMode() == Draw::Calculation) + { + emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo + } }