From 82836c15a147c3a0fabcee3442f066701f5180c3 Mon Sep 17 00:00:00 2001 From: dismine Date: Tue, 24 Jun 2014 11:23:39 +0300 Subject: [PATCH] Fixed issue #82. Fixed issue #83. Fixed issue #85. --HG-- branch : develop --- src/app/dialogs/app/dialogundo.cpp | 79 ++++++++++++++++++ src/app/dialogs/app/dialogundo.h | 65 +++++++++++++++ src/app/dialogs/app/dialogundo.ui | 66 +++++++++++++++ src/app/dialogs/dialogs.pri | 9 +- src/app/exception/exception.pri | 6 +- src/app/exception/vexception.h | 4 +- src/app/exception/vexceptionundo.cpp | 39 +++++++++ src/app/exception/vexceptionundo.h | 42 ++++++++++ src/app/mainwindow.cpp | 83 ++++++++++++++++--- src/app/mainwindow.h | 3 + src/app/tools/drawTools/vabstractspline.cpp | 6 ++ src/app/tools/drawTools/vabstractspline.h | 1 + src/app/tools/drawTools/vdrawtool.cpp | 46 +++++++--- src/app/tools/drawTools/vdrawtool.h | 14 ++++ src/app/tools/drawTools/vtoolalongline.cpp | 1 + src/app/tools/drawTools/vtoolarc.cpp | 7 ++ src/app/tools/drawTools/vtoolarc.h | 1 + src/app/tools/drawTools/vtoolbisector.cpp | 3 +- src/app/tools/drawTools/vtoolcutarc.cpp | 3 +- src/app/tools/drawTools/vtoolcutspline.cpp | 3 +- .../tools/drawTools/vtoolcutsplinepath.cpp | 1 + src/app/tools/drawTools/vtoolendline.cpp | 1 + src/app/tools/drawTools/vtoolheight.cpp | 1 + src/app/tools/drawTools/vtoolline.cpp | 7 ++ src/app/tools/drawTools/vtoolline.h | 1 + .../tools/drawTools/vtoollineintersect.cpp | 1 + src/app/tools/drawTools/vtoolnormal.cpp | 1 + src/app/tools/drawTools/vtoolpoint.cpp | 6 ++ src/app/tools/drawTools/vtoolpoint.h | 1 + .../tools/drawTools/vtoolpointofcontact.cpp | 1 + .../drawTools/vtoolpointofintersection.cpp | 1 + .../tools/drawTools/vtoolshoulderpoint.cpp | 1 + src/app/tools/drawTools/vtoolsinglepoint.cpp | 3 + src/app/tools/drawTools/vtoolspline.cpp | 7 ++ src/app/tools/drawTools/vtoolspline.h | 1 + src/app/tools/drawTools/vtoolsplinepath.cpp | 7 ++ src/app/tools/drawTools/vtoolsplinepath.h | 1 + src/app/tools/drawTools/vtooltriangle.cpp | 1 + src/app/undocommands/deletepatternpiece.cpp | 1 - src/app/widgets/undoevent.cpp | 34 ++++++++ src/app/widgets/undoevent.h | 43 ++++++++++ src/app/widgets/vmaingraphicsscene.cpp | 8 ++ src/app/widgets/vmaingraphicsscene.h | 2 + src/app/widgets/widgets.pri | 6 +- src/app/xml/vpattern.cpp | 37 +++++++-- src/app/xml/vpattern.h | 3 + 46 files changed, 615 insertions(+), 43 deletions(-) create mode 100644 src/app/dialogs/app/dialogundo.cpp create mode 100644 src/app/dialogs/app/dialogundo.h create mode 100644 src/app/dialogs/app/dialogundo.ui create mode 100644 src/app/exception/vexceptionundo.cpp create mode 100644 src/app/exception/vexceptionundo.h create mode 100644 src/app/widgets/undoevent.cpp create mode 100644 src/app/widgets/undoevent.h diff --git a/src/app/dialogs/app/dialogundo.cpp b/src/app/dialogs/app/dialogundo.cpp new file mode 100644 index 000000000..f9e931f0f --- /dev/null +++ b/src/app/dialogs/app/dialogundo.cpp @@ -0,0 +1,79 @@ +/************************************************************************ + ** + ** @file dialogundo.cpp + ** @author Roman Telezhynskyi + ** @date 23 6, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** 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 . + ** + *************************************************************************/ + +#include "dialogundo.h" +#include "ui_dialogundo.h" +#include "../../widgets/vapplication.h" +#include "../../exception/vexceptionundo.h" +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- +DialogUndo::DialogUndo(QWidget *parent) + :QDialog(parent), ui(new Ui::DialogUndo), result(UndoButton::Cancel) +{ + ui->setupUi(this); + + connect(ui->pushButtonUndo, &QPushButton::clicked, this, &DialogUndo::Undo); + connect(ui->pushButtonFix, &QPushButton::clicked, this, &DialogUndo::Fix); + connect(ui->pushButtonCancel, &QPushButton::clicked, this, &DialogUndo::Cancel); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogUndo::~DialogUndo() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogUndo::Undo() +{ + result = UndoButton::Undo; + accept(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogUndo::Fix() +{ + result = UndoButton::Fix; + accept(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogUndo::Cancel() +{ + result = UndoButton::Cancel; + reject(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogUndo::closeEvent(QCloseEvent *event) +{ + Cancel(); + event->accept(); +} diff --git a/src/app/dialogs/app/dialogundo.h b/src/app/dialogs/app/dialogundo.h new file mode 100644 index 000000000..d391e7696 --- /dev/null +++ b/src/app/dialogs/app/dialogundo.h @@ -0,0 +1,65 @@ +/************************************************************************ + ** + ** @file dialogundo.h + ** @author Roman Telezhynskyi + ** @date 23 6, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** 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 . + ** + *************************************************************************/ + +#ifndef DIALOGUNDO_H +#define DIALOGUNDO_H + +#include + +namespace Ui +{ + class DialogUndo; +} + +enum class UndoButton {Undo, Fix, Cancel}; + +class DialogUndo : public QDialog +{ + Q_OBJECT +public: + explicit DialogUndo(QWidget *parent = 0); + UndoButton Result() const; + ~DialogUndo(); +public slots: + void Undo(); + void Fix(); + void Cancel(); +protected: + virtual void closeEvent ( QCloseEvent * event ); +private: + Q_DISABLE_COPY(DialogUndo) + Ui::DialogUndo *ui; + UndoButton result; +}; + +inline UndoButton DialogUndo::Result() const +{ + return result; +} + +#endif // DIALOGUNDO_H diff --git a/src/app/dialogs/app/dialogundo.ui b/src/app/dialogs/app/dialogundo.ui new file mode 100644 index 000000000..158fb10f0 --- /dev/null +++ b/src/app/dialogs/app/dialogundo.ui @@ -0,0 +1,66 @@ + + + DialogUndo + + + Qt::WindowModal + + + + 0 + 0 + 387 + 145 + + + + Broken formula + + + true + + + + + + + + Error while calculation formula. You can try undo last operation or fix broken formula. + + + true + + + + + + + + + &Undo + + + + + + + &Fix formula + + + + + + + &Cancel + + + + + + + + + + + + diff --git a/src/app/dialogs/dialogs.pri b/src/app/dialogs/dialogs.pri index 2a2deb89a..8f98a8997 100644 --- a/src/app/dialogs/dialogs.pri +++ b/src/app/dialogs/dialogs.pri @@ -35,7 +35,8 @@ HEADERS += \ dialogs/app/configpages/configurationpage.h \ dialogs/app/configpages/patternpage.h \ dialogs/app/configpages/communitypage.h \ - dialogs/app/configpages/pathpage.h + dialogs/app/configpages/pathpage.h \ + dialogs/app/dialogundo.h SOURCES += \ dialogs/tools/dialogtriangle.cpp \ @@ -72,7 +73,8 @@ SOURCES += \ dialogs/app/configpages/configurationpage.cpp \ dialogs/app/configpages/patternpage.cpp \ dialogs/app/configpages/communitypage.cpp \ - dialogs/app/configpages/pathpage.cpp + dialogs/app/configpages/pathpage.cpp \ + dialogs/app/dialogundo.cpp FORMS += \ dialogs/tools/dialogtriangle.ui \ @@ -103,4 +105,5 @@ FORMS += \ dialogs/app/dialogindividualmeasurements.ui \ dialogs/app/dialogaboutapp.ui \ dialogs/app/dialogpatternxmledit.ui \ - dialogs/tools/dialogeditwrongformula.ui + dialogs/tools/dialogeditwrongformula.ui \ + dialogs/app/dialogundo.ui diff --git a/src/app/exception/exception.pri b/src/app/exception/exception.pri index d78a7f862..6a1eb7828 100644 --- a/src/app/exception/exception.pri +++ b/src/app/exception/exception.pri @@ -4,7 +4,8 @@ HEADERS += \ exception/vexceptionconversionerror.h \ exception/vexceptionbadid.h \ exception/vexception.h \ - exception/vexceptionwrongid.h + exception/vexceptionwrongid.h \ + exception/vexceptionundo.h SOURCES += \ exception/vexceptionobjecterror.cpp \ @@ -12,4 +13,5 @@ SOURCES += \ exception/vexceptionconversionerror.cpp \ exception/vexceptionbadid.cpp \ exception/vexception.cpp \ - exception/vexceptionwrongid.cpp + exception/vexceptionwrongid.cpp \ + exception/vexceptionundo.cpp diff --git a/src/app/exception/vexception.h b/src/app/exception/vexception.h index 4f30c3423..c9c677321 100644 --- a/src/app/exception/vexception.h +++ b/src/app/exception/vexception.h @@ -53,8 +53,8 @@ public: virtual QString DetailedInformation() const; QString What() const; virtual void CriticalMessageBox(const QString &situation, QWidget *parent = nullptr) const; - void AddMoreInformation(const QString &info); - QString MoreInformation() const; + void AddMoreInformation(const QString &info); + QString MoreInformation() const; protected: /** @brief what string with error */ QString what; diff --git a/src/app/exception/vexceptionundo.cpp b/src/app/exception/vexceptionundo.cpp new file mode 100644 index 000000000..dc1a31b1b --- /dev/null +++ b/src/app/exception/vexceptionundo.cpp @@ -0,0 +1,39 @@ +/************************************************************************ + ** + ** @file vexceptionundo.cpp + ** @author Roman Telezhynskyi + ** @date 23 6, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** 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 . + ** + *************************************************************************/ + +#include "vexceptionundo.h" + +//--------------------------------------------------------------------------------------------------------------------- +VExceptionUndo::VExceptionUndo(const QString &what) + :VException(what) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VExceptionUndo::VExceptionUndo(const VExceptionUndo &e) + :VException(e) +{} diff --git a/src/app/exception/vexceptionundo.h b/src/app/exception/vexceptionundo.h new file mode 100644 index 000000000..9dbfc535a --- /dev/null +++ b/src/app/exception/vexceptionundo.h @@ -0,0 +1,42 @@ +/************************************************************************ + ** + ** @file vexceptionundo.h + ** @author Roman Telezhynskyi + ** @date 23 6, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** 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 . + ** + *************************************************************************/ + +#ifndef VEXCEPTIONUNDO_H +#define VEXCEPTIONUNDO_H + +#include "vexception.h" + +class VExceptionUndo : public VException +{ +public: + VExceptionUndo(const QString &what); + VExceptionUndo(const VExceptionUndo &e); + virtual ~VExceptionUndo() noexcept (true){} +}; + +#endif // VEXCEPTIONUNDO_H diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 0d6e92e5a..32af0ba02 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -34,10 +34,12 @@ #include "exception/vexceptionconversionerror.h" #include "exception/vexceptionemptyparameter.h" #include "exception/vexceptionwrongid.h" +#include "exception/vexceptionundo.h" #include "version.h" #include "xml/vstandardmeasurements.h" #include "xml/vindividualmeasurements.h" #include "widgets/vapplication.h" +#include "widgets/undoevent.h" #include #include @@ -61,7 +63,7 @@ MainWindow::MainWindow(QWidget *parent) view(nullptr), isInitialized(false), dialogTable(0), dialogTool(nullptr), dialogHistory(nullptr), comboBoxDraws(nullptr), curFile(QString()), mode(Draw::Calculation), currentDrawIndex(0), currentToolBoxIndex(0), drawMode(true), recentFileActs{0, 0, 0, 0, 0}, separatorAct(nullptr), - autoSaveTimer(nullptr) + autoSaveTimer(nullptr), guiEnabled(true) { CreateActions(); CreateMenus(); @@ -98,6 +100,7 @@ MainWindow::MainWindow(QWidget *parent) connect(doc, &VPattern::ClearMainWindow, this, &MainWindow::Clear); connect(doc, &VPattern::patternChanged, this, &MainWindow::PatternWasModified); connect(doc, &VPattern::UndoCommand, this, &MainWindow::FullParseFile); + connect(doc, &VPattern::SetEnabledGUI, this, &MainWindow::SetEnabledGUI); connect(qApp->getUndoStack(), &QUndoStack::cleanChanged, this, &MainWindow::PatternWasModified); @@ -968,6 +971,15 @@ void MainWindow::closeEvent(QCloseEvent *event) } } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::customEvent(QEvent *event) +{ + if(event->type() == UNDO_EVENT) + { + qApp->getUndoStack()->undo(); + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ToolBarOption enable option toolbar. @@ -1532,36 +1544,45 @@ void MainWindow::FullParseFile() { try { + SetEnabledGUI(true); doc->Parse(Document::FullParse); } + catch (const VExceptionUndo &e) + { + Q_UNUSED(e); + /* If user want undo last operation before undo we need finish broken redo operation. For those we post event + * myself. Later in method customEvent call undo.*/ + QApplication::postEvent(this, new UndoEvent()); + return; + } catch (const VExceptionObjectError &e) { e.CriticalMessageBox(tr("Error parsing file."), this); - Clear(); + SetEnabledGUI(false); return; } catch (const VExceptionConversionError &e) { e.CriticalMessageBox(tr("Error can't convert value."), this); - Clear(); + SetEnabledGUI(false); return; } catch (const VExceptionEmptyParameter &e) { e.CriticalMessageBox(tr("Error empty parameter."), this); - Clear(); + SetEnabledGUI(false); return; } catch (const VExceptionWrongId &e) { e.CriticalMessageBox(tr("Error wrong id."), this); - Clear(); + SetEnabledGUI(false); return; } catch (VException &e) { e.CriticalMessageBox(tr("Error parsing file."), this); - Clear(); + SetEnabledGUI(false); return; } catch (const std::bad_alloc &) @@ -1574,7 +1595,7 @@ void MainWindow::FullParseFile() #ifndef QT_NO_CURSOR QApplication::setOverrideCursor(Qt::WaitCursor); #endif - Clear(); + SetEnabledGUI(false); return; } @@ -1606,13 +1627,13 @@ void MainWindow::FullParseFile() catch (VExceptionBadId &e) { e.CriticalMessageBox(tr("Bad id."), this); - Clear(); + SetEnabledGUI(false); return; } catch (const VExceptionEmptyParameter &e) { e.CriticalMessageBox(tr("Error empty parameter."), this); - Clear(); + SetEnabledGUI(false); return; } @@ -1627,6 +1648,43 @@ void MainWindow::FullParseFile() SetEnableWidgets(true); } + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::SetEnabledGUI(bool enabled) +{ + if (guiEnabled != enabled) + { + if (enabled == false) + { + CancelTool(); + } + comboBoxDraws->setEnabled(enabled); + ui->actionOptionDraw->setEnabled(enabled); + ui->actionSave->setEnabled(enabled); + ui->actionSaveAs->setEnabled(enabled); + ui->actionPattern_properties->setEnabled(enabled); + ui->actionEdit_pattern_code->setEnabled(enabled); + ui->actionZoomIn->setEnabled(enabled); + ui->actionZoomOut->setEnabled(enabled); + ui->actionArrowTool->setEnabled(enabled); + ui->actionHistory->setEnabled(enabled); + ui->actionNewDraw->setEnabled(enabled); + ui->actionDraw->setEnabled(enabled); + ui->actionDetails->setEnabled(enabled); + ui->actionTable->setEnabled(enabled); + guiEnabled = enabled; + + sceneDraw->SetDisable(!enabled); + view->setEnabled(enabled); + + SetEnableTool(enabled); + ui->toolBarOption->setEnabled(enabled); + #ifndef QT_NO_CURSOR + QApplication::setOverrideCursor(Qt::ArrowCursor); + #endif + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief NewPattern create new empty pattern. @@ -1647,8 +1705,11 @@ void MainWindow::NewPattern() */ void MainWindow::PatternWasModified(bool saved) { - setWindowModified(!saved); - ui->actionSave->setEnabled(!saved); + if (guiEnabled) + { + setWindowModified(!saved); + ui->actionSave->setEnabled(!saved); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index 7f16894c8..a0f288aa7 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -142,6 +142,7 @@ public slots: */ void EditPatternCode(); void FullParseFile(); + void SetEnabledGUI(bool enabled); signals: /** * @brief ModelChosen emit after calculation all details. @@ -153,6 +154,7 @@ protected: virtual void keyPressEvent ( QKeyEvent * event ); virtual void showEvent( QShowEvent *event ); virtual void closeEvent( QCloseEvent * event ); + virtual void customEvent(QEvent * event); private: Q_DISABLE_COPY(MainWindow) /** @brief ui keeps information about user interface */ @@ -214,6 +216,7 @@ private: QAction *recentFileActs[MaxRecentFiles]; QAction *separatorAct; QTimer *autoSaveTimer; + bool guiEnabled; void ToolBarOption(); void ToolBarDraws(); void ToolBarZoom(); diff --git a/src/app/tools/drawTools/vabstractspline.cpp b/src/app/tools/drawTools/vabstractspline.cpp index b1705a21a..337ef0f1c 100644 --- a/src/app/tools/drawTools/vabstractspline.cpp +++ b/src/app/tools/drawTools/vabstractspline.cpp @@ -47,6 +47,12 @@ void VAbstractSpline::FullUpdateFromFile() RefreshGeometry(); } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractSpline::Disable(bool disable) +{ + DisableItem(this, disable); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ChangedActivDraw disable or enable context menu after change active pattern peace. diff --git a/src/app/tools/drawTools/vabstractspline.h b/src/app/tools/drawTools/vabstractspline.h index a9dc13a99..89c203d68 100644 --- a/src/app/tools/drawTools/vabstractspline.h +++ b/src/app/tools/drawTools/vabstractspline.h @@ -41,6 +41,7 @@ public: static const QString TagName; public slots: virtual void FullUpdateFromFile (); + void Disable(bool disable); signals: /** * @brief RefreshLine refresh control line. diff --git a/src/app/tools/drawTools/vdrawtool.cpp b/src/app/tools/drawTools/vdrawtool.cpp index 06339c463..bcfaf86c2 100644 --- a/src/app/tools/drawTools/vdrawtool.cpp +++ b/src/app/tools/drawTools/vdrawtool.cpp @@ -30,9 +30,11 @@ #include #include "dialogs/tools/dialogeditwrongformula.h" +#include "dialogs/app/dialogundo.h" #include "container/calculator.h" #include "../../undocommands/addtocalc.h" #include "../../undocommands/savetooloptions.h" +#include "../../exception/vexceptionundo.h" qreal VDrawTool::factor = 1; @@ -193,21 +195,43 @@ qreal VDrawTool::CheckFormula(QString &formula, VContainer *data) { Q_UNUSED(e) delete cal; - DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data); - dialog->setFormula(formula); - if (dialog->exec() == QDialog::Accepted) + + DialogUndo *dialogUndo = new DialogUndo(); + if (dialogUndo->exec() == QDialog::Accepted) { - formula = dialog->getFormula(); - //Need delete dialog here because parser in dialog don't allow use correct separator for parsing here. - //Don't know why. - delete dialog; - Calculator *cal1 = new Calculator(data); - result = cal1->EvalFormula(formula); - delete cal1;//Here can be memory leak, but dialog already check this formula and probability very low. + UndoButton resultUndo = dialogUndo->Result(); + delete dialogUndo; + if (resultUndo == UndoButton::Fix) + { + DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data); + dialog->setFormula(formula); + if (dialog->exec() == QDialog::Accepted) + { + formula = dialog->getFormula(); + /* Need delete dialog here because parser in dialog don't allow use correct separator for parsing + * here. + * Don't know why. */ + delete dialog; + Calculator *cal1 = new Calculator(data); + result = cal1->EvalFormula(formula); + delete cal1; /* Here can be memory leak, but dialog already check this formula and probability + * very low. */ + } + else + { + delete dialog; + throw; + } + } + else + { + QString what = QString("Undo wrong formula %1").arg(formula); + throw VExceptionUndo(what); + } } else { - delete dialog; + delete dialogUndo; throw; } } diff --git a/src/app/tools/drawTools/vdrawtool.h b/src/app/tools/drawTools/vdrawtool.h index ec15a3987..07ef881cb 100644 --- a/src/app/tools/drawTools/vdrawtool.h +++ b/src/app/tools/drawTools/vdrawtool.h @@ -165,6 +165,20 @@ protected: item->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); } } + template + void DisableItem(Item *item, bool disable) + { + SCASSERT(item != nullptr); + if (disable) + { + currentColor = Qt::gray; + } + else + { + currentColor = baseColor; + } + item->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); + } private: Q_DISABLE_COPY(VDrawTool) }; diff --git a/src/app/tools/drawTools/vtoolalongline.cpp b/src/app/tools/drawTools/vtoolalongline.cpp index 0009ac2ce..871d1a433 100644 --- a/src/app/tools/drawTools/vtoolalongline.cpp +++ b/src/app/tools/drawTools/vtoolalongline.cpp @@ -280,6 +280,7 @@ VToolAlongLine* VToolAlongLine::Create(const quint32 _id, const QString &pointNa scene->addItem(point); connect(point, &VToolAlongLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolAlongLine::SetFactor); + connect(scene, &VMainGraphicsScene::DisableItem, point, &VToolAlongLine::Disable); doc->AddTool(id, point); doc->IncrementReferens(firstPointId); doc->IncrementReferens(secondPointId); diff --git a/src/app/tools/drawTools/vtoolarc.cpp b/src/app/tools/drawTools/vtoolarc.cpp index 6612affdd..a3f7a8709 100644 --- a/src/app/tools/drawTools/vtoolarc.cpp +++ b/src/app/tools/drawTools/vtoolarc.cpp @@ -157,6 +157,7 @@ VToolArc* VToolArc::Create(const quint32 _id, const quint32 ¢er, QString &ra VToolArc *toolArc = new VToolArc(doc, data, id, typeCreation); scene->addItem(toolArc); connect(toolArc, &VToolArc::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(scene, &VMainGraphicsScene::DisableItem, toolArc, &VToolArc::Disable); doc->AddTool(id, toolArc); doc->IncrementReferens(center); return toolArc; @@ -220,6 +221,12 @@ void VToolArc::SetFactor(qreal factor) RefreshGeometry(); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolArc::Disable(bool disable) +{ + DisableItem(this, disable); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief contextMenuEvent handle context menu events. diff --git a/src/app/tools/drawTools/vtoolarc.h b/src/app/tools/drawTools/vtoolarc.h index 764688a0e..b1eee21f2 100644 --- a/src/app/tools/drawTools/vtoolarc.h +++ b/src/app/tools/drawTools/vtoolarc.h @@ -53,6 +53,7 @@ public slots: virtual void ChangedActivDraw(const QString &newName); virtual void ShowTool(quint32 id, Qt::GlobalColor color, bool enable); virtual void SetFactor(qreal factor); + void Disable(bool disable); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void AddToFile(); diff --git a/src/app/tools/drawTools/vtoolbisector.cpp b/src/app/tools/drawTools/vtoolbisector.cpp index 95834c66d..3bc3cd623 100644 --- a/src/app/tools/drawTools/vtoolbisector.cpp +++ b/src/app/tools/drawTools/vtoolbisector.cpp @@ -194,8 +194,9 @@ VToolBisector* VToolBisector::Create(const quint32 _id, QString &formula, const VToolBisector *point = new VToolBisector(doc, data, id, typeLine, formula, firstPointId, secondPointId, thirdPointId, typeCreation); scene->addItem(point); - connect(point, &VToolBisector::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolBisector::SetFactor); + connect(scene, &VMainGraphicsScene::DisableItem, point, &VToolPoint::Disable); doc->AddTool(id, point); doc->IncrementReferens(firstPointId); doc->IncrementReferens(secondPointId); diff --git a/src/app/tools/drawTools/vtoolcutarc.cpp b/src/app/tools/drawTools/vtoolcutarc.cpp index b9fbdbbfc..fec7ac05c 100644 --- a/src/app/tools/drawTools/vtoolcutarc.cpp +++ b/src/app/tools/drawTools/vtoolcutarc.cpp @@ -187,7 +187,8 @@ VToolCutArc* VToolCutArc::Create(const quint32 _id, const QString &pointName, QS VToolCutArc *point = new VToolCutArc(doc, data, id, formula, arcId, arc1id, arc2id, typeCreation); scene->addItem(point); connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPoint::SetFactor); + connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolCutArc::SetFactor); + connect(scene, &VMainGraphicsScene::DisableItem, point, &VToolPoint::Disable); doc->AddTool(id, point); doc->AddTool(arc1id, point); doc->AddTool(arc2id, point); diff --git a/src/app/tools/drawTools/vtoolcutspline.cpp b/src/app/tools/drawTools/vtoolcutspline.cpp index 909870e16..c62d88bcc 100644 --- a/src/app/tools/drawTools/vtoolcutspline.cpp +++ b/src/app/tools/drawTools/vtoolcutspline.cpp @@ -181,7 +181,8 @@ void VToolCutSpline::Create(const quint32 _id, const QString &pointName, QString VToolCutSpline *point = new VToolCutSpline(doc, data, id, formula, splineId, spl1id, spl2id, typeCreation); scene->addItem(point); connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPoint::SetFactor); + connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolCutSpline::SetFactor); + connect(scene, &VMainGraphicsScene::DisableItem, point, &VToolPoint::Disable); doc->AddTool(id, point); doc->AddTool(spl1id, point); doc->AddTool(spl2id, point); diff --git a/src/app/tools/drawTools/vtoolcutsplinepath.cpp b/src/app/tools/drawTools/vtoolcutsplinepath.cpp index 6f5906669..601c72d11 100644 --- a/src/app/tools/drawTools/vtoolcutsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolcutsplinepath.cpp @@ -237,6 +237,7 @@ void VToolCutSplinePath::Create(const quint32 _id, const QString &pointName, QSt scene->addItem(point); connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPoint::SetFactor); + connect(scene, &VMainGraphicsScene::DisableItem, point, &VToolPoint::Disable); doc->AddTool(id, point); doc->AddTool(splPath1id, point); doc->AddTool(splPath2id, point); diff --git a/src/app/tools/drawTools/vtoolendline.cpp b/src/app/tools/drawTools/vtoolendline.cpp index c6aa1f66f..41867cce0 100644 --- a/src/app/tools/drawTools/vtoolendline.cpp +++ b/src/app/tools/drawTools/vtoolendline.cpp @@ -162,6 +162,7 @@ VToolEndLine* VToolEndLine::Create(const quint32 _id, const QString &pointName, scene->addItem(point); connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPoint::SetFactor); + connect(scene, &VMainGraphicsScene::DisableItem, point, &VToolPoint::Disable); doc->AddTool(id, point); doc->IncrementReferens(basePointId); return point; diff --git a/src/app/tools/drawTools/vtoolheight.cpp b/src/app/tools/drawTools/vtoolheight.cpp index f43811317..1a26c392e 100644 --- a/src/app/tools/drawTools/vtoolheight.cpp +++ b/src/app/tools/drawTools/vtoolheight.cpp @@ -156,6 +156,7 @@ void VToolHeight::Create(const quint32 _id, const QString &pointName, const QStr scene->addItem(point); connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPoint::SetFactor); + connect(scene, &VMainGraphicsScene::DisableItem, point, &VToolPoint::Disable); doc->AddTool(id, point); doc->IncrementReferens(basePointId); doc->IncrementReferens(p1LineId); diff --git a/src/app/tools/drawTools/vtoolline.cpp b/src/app/tools/drawTools/vtoolline.cpp index b210a8458..87dd99d31 100644 --- a/src/app/tools/drawTools/vtoolline.cpp +++ b/src/app/tools/drawTools/vtoolline.cpp @@ -147,6 +147,7 @@ void VToolLine::Create(const quint32 &_id, const quint32 &firstPoint, const quin scene->addItem(line); connect(line, &VToolLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(scene, &VMainGraphicsScene::NewFactor, line, &VToolLine::SetFactor); + connect(scene, &VMainGraphicsScene::DisableItem, line, &VToolLine::Disable); doc->AddTool(id, line); doc->IncrementReferens(firstPoint); doc->IncrementReferens(secondPoint); @@ -185,6 +186,12 @@ void VToolLine::SetFactor(qreal factor) RefreshGeometry(); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolLine::Disable(bool disable) +{ + DisableItem(this, disable); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ChangedActivDraw disable or enable context menu after change active pattern peace. diff --git a/src/app/tools/drawTools/vtoolline.h b/src/app/tools/drawTools/vtoolline.h index 29f313208..97ab224a4 100644 --- a/src/app/tools/drawTools/vtoolline.h +++ b/src/app/tools/drawTools/vtoolline.h @@ -52,6 +52,7 @@ public slots: virtual void ChangedActivDraw(const QString &newName); virtual void ShowTool(quint32 id, Qt::GlobalColor color, bool enable); virtual void SetFactor(qreal factor); + void Disable(bool disable); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void AddToFile(); diff --git a/src/app/tools/drawTools/vtoollineintersect.cpp b/src/app/tools/drawTools/vtoollineintersect.cpp index 9cd93fd2e..36a98e11f 100644 --- a/src/app/tools/drawTools/vtoollineintersect.cpp +++ b/src/app/tools/drawTools/vtoollineintersect.cpp @@ -165,6 +165,7 @@ void VToolLineIntersect::Create(const quint32 _id, const quint32 &p1Line1Id, con scene->addItem(point); connect(point, &VToolLineIntersect::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolLineIntersect::SetFactor); + connect(scene, &VMainGraphicsScene::DisableItem, point, &VToolPoint::Disable); doc->AddTool(id, point); doc->IncrementReferens(p1Line1Id); doc->IncrementReferens(p2Line1Id); diff --git a/src/app/tools/drawTools/vtoolnormal.cpp b/src/app/tools/drawTools/vtoolnormal.cpp index 49978e3bb..1f9c14584 100644 --- a/src/app/tools/drawTools/vtoolnormal.cpp +++ b/src/app/tools/drawTools/vtoolnormal.cpp @@ -165,6 +165,7 @@ VToolNormal* VToolNormal::Create(const quint32 _id, QString &formula, const quin scene->addItem(point); connect(point, &VToolNormal::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolNormal::SetFactor); + connect(scene, &VMainGraphicsScene::DisableItem, point, &VToolPoint::Disable); doc->AddTool(id, point); doc->IncrementReferens(firstPointId); doc->IncrementReferens(secondPointId); diff --git a/src/app/tools/drawTools/vtoolpoint.cpp b/src/app/tools/drawTools/vtoolpoint.cpp index 52815ea12..55f9ba22e 100644 --- a/src/app/tools/drawTools/vtoolpoint.cpp +++ b/src/app/tools/drawTools/vtoolpoint.cpp @@ -156,6 +156,12 @@ void VToolPoint::ShowContextMenu(QGraphicsSceneContextMenuEvent *event) Q_UNUSED(event); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolPoint::Disable(bool disable) +{ + DisableItem(this, disable); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief mouseReleaseEvent handle mouse release events. diff --git a/src/app/tools/drawTools/vtoolpoint.h b/src/app/tools/drawTools/vtoolpoint.h index fd4fc12e8..eeeda8dc6 100644 --- a/src/app/tools/drawTools/vtoolpoint.h +++ b/src/app/tools/drawTools/vtoolpoint.h @@ -51,6 +51,7 @@ public slots: virtual void ShowTool(quint32 id, Qt::GlobalColor color, bool enable); virtual void SetFactor(qreal factor); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); + void Disable(bool disable); protected: /** @brief radius radius circle. */ qreal radius; diff --git a/src/app/tools/drawTools/vtoolpointofcontact.cpp b/src/app/tools/drawTools/vtoolpointofcontact.cpp index a61d5ab9d..2cb9d1e31 100644 --- a/src/app/tools/drawTools/vtoolpointofcontact.cpp +++ b/src/app/tools/drawTools/vtoolpointofcontact.cpp @@ -202,6 +202,7 @@ VToolPointOfContact* VToolPointOfContact::Create(const quint32 _id, QString &rad scene->addItem(point); connect(point, &VToolPointOfContact::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPointOfContact::SetFactor); + connect(scene, &VMainGraphicsScene::DisableItem, point, &VToolPoint::Disable); doc->AddTool(id, point); doc->IncrementReferens(center); doc->IncrementReferens(firstPointId); diff --git a/src/app/tools/drawTools/vtoolpointofintersection.cpp b/src/app/tools/drawTools/vtoolpointofintersection.cpp index 7d724dfd0..2df07fe28 100644 --- a/src/app/tools/drawTools/vtoolpointofintersection.cpp +++ b/src/app/tools/drawTools/vtoolpointofintersection.cpp @@ -139,6 +139,7 @@ void VToolPointOfIntersection::Create(const quint32 _id, const QString &pointNam scene->addItem(point); connect(point, &VToolPointOfIntersection::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPointOfIntersection::SetFactor); + connect(scene, &VMainGraphicsScene::DisableItem, point, &VToolPoint::Disable); doc->AddTool(id, point); doc->IncrementReferens(firstPointId); doc->IncrementReferens(secondPointId); diff --git a/src/app/tools/drawTools/vtoolshoulderpoint.cpp b/src/app/tools/drawTools/vtoolshoulderpoint.cpp index 6448d9bda..de415aede 100644 --- a/src/app/tools/drawTools/vtoolshoulderpoint.cpp +++ b/src/app/tools/drawTools/vtoolshoulderpoint.cpp @@ -206,6 +206,7 @@ VToolShoulderPoint* VToolShoulderPoint::Create(const quint32 _id, QString &formu scene->addItem(point); connect(point, &VToolShoulderPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolShoulderPoint::SetFactor); + connect(scene, &VMainGraphicsScene::DisableItem, point, &VToolPoint::Disable); doc->AddTool(id, point); doc->IncrementReferens(p1Line); doc->IncrementReferens(p2Line); diff --git a/src/app/tools/drawTools/vtoolsinglepoint.cpp b/src/app/tools/drawTools/vtoolsinglepoint.cpp index 2327502c8..4d4fdf42a 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/app/tools/drawTools/vtoolsinglepoint.cpp @@ -239,6 +239,8 @@ void VToolSinglePoint::setColorLabel(const Qt::GlobalColor &color) */ void VToolSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) { + quint32 ref = _referens; // store referens + _referens = 1; // make available delete pattern piece if (doc->CountPP() > 1) { ContextMenu(this, event); @@ -247,6 +249,7 @@ void VToolSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event { ContextMenu(this, event, false); } + _referens = ref; // restore referens. If not restore garbage collector delete point!!! } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolspline.cpp b/src/app/tools/drawTools/vtoolspline.cpp index 8029c69e4..3daceaa58 100644 --- a/src/app/tools/drawTools/vtoolspline.cpp +++ b/src/app/tools/drawTools/vtoolspline.cpp @@ -171,6 +171,7 @@ void VToolSpline::Create(const quint32 _id, const quint32 &p1, const quint32 &p4 scene->addItem(spl); connect(spl, &VToolSpline::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(scene, &VMainGraphicsScene::NewFactor, spl, &VToolSpline::SetFactor); + connect(scene, &VMainGraphicsScene::DisableItem, spl, &VToolSpline::Disable); doc->AddTool(id, spl); doc->IncrementReferens(p1); doc->IncrementReferens(p4); @@ -204,6 +205,12 @@ void VToolSpline::ControlPointChangePosition(const qint32 &indexSpline, const Sp qApp->getUndoStack()->push(moveSpl); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolSpline::Disable(bool disable) +{ + DisableItem(this, disable); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief contextMenuEvent handle context menu events. diff --git a/src/app/tools/drawTools/vtoolspline.h b/src/app/tools/drawTools/vtoolspline.h index a75726a94..873e9e97a 100644 --- a/src/app/tools/drawTools/vtoolspline.h +++ b/src/app/tools/drawTools/vtoolspline.h @@ -51,6 +51,7 @@ public: public slots: void ControlPointChangePosition (const qint32 &indexSpline, const SplinePointPosition &position, const QPointF &pos); + void Disable(bool disable); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void AddToFile (); diff --git a/src/app/tools/drawTools/vtoolsplinepath.cpp b/src/app/tools/drawTools/vtoolsplinepath.cpp index d96942684..d96a7350b 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolsplinepath.cpp @@ -153,6 +153,7 @@ void VToolSplinePath::Create(const quint32 _id, VSplinePath *path, VMainGraphics scene->addItem(spl); connect(spl, &VToolSplinePath::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(scene, &VMainGraphicsScene::NewFactor, spl, &VToolSplinePath::SetFactor); + connect(scene, &VMainGraphicsScene::DisableItem, spl, &VToolSplinePath::Disable); doc->AddTool(id, spl); } } @@ -186,6 +187,12 @@ void VToolSplinePath::ControlPointChangePosition(const qint32 &indexSpline, cons qApp->getUndoStack()->push(moveSplPath); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolSplinePath::Disable(bool disable) +{ + DisableItem(this, disable); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief UpdateControlPoints update position points control points in file. diff --git a/src/app/tools/drawTools/vtoolsplinepath.h b/src/app/tools/drawTools/vtoolsplinepath.h index 793bc70fe..ae739b3ae 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.h +++ b/src/app/tools/drawTools/vtoolsplinepath.h @@ -65,6 +65,7 @@ public slots: void ControlPointChangePosition(const qint32 &indexSpline, const SplinePointPosition &position, const QPointF &pos); + void Disable(bool disable); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void AddToFile(); diff --git a/src/app/tools/drawTools/vtooltriangle.cpp b/src/app/tools/drawTools/vtooltriangle.cpp index f9d46f2de..42974d5b7 100644 --- a/src/app/tools/drawTools/vtooltriangle.cpp +++ b/src/app/tools/drawTools/vtooltriangle.cpp @@ -151,6 +151,7 @@ void VToolTriangle::Create(const quint32 _id, const QString &pointName, const qu scene->addItem(point); connect(point, &VToolTriangle::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolTriangle::SetFactor); + connect(scene, &VMainGraphicsScene::DisableItem, point, &VToolPoint::Disable); doc->AddTool(id, point); doc->IncrementReferens(axisP1Id); doc->IncrementReferens(axisP2Id); diff --git a/src/app/undocommands/deletepatternpiece.cpp b/src/app/undocommands/deletepatternpiece.cpp index 15d55da60..34fccc286 100644 --- a/src/app/undocommands/deletepatternpiece.cpp +++ b/src/app/undocommands/deletepatternpiece.cpp @@ -50,7 +50,6 @@ DeletePatternPiece::~DeletePatternPiece() //--------------------------------------------------------------------------------------------------------------------- void DeletePatternPiece::undo() { - QDomElement rootElement = doc->documentElement(); rootElement.insertAfter(patternPiece, previousNode); diff --git a/src/app/widgets/undoevent.cpp b/src/app/widgets/undoevent.cpp new file mode 100644 index 000000000..566d27364 --- /dev/null +++ b/src/app/widgets/undoevent.cpp @@ -0,0 +1,34 @@ +/************************************************************************ + ** + ** @file undoevent.cpp + ** @author Roman Telezhynskyi + ** @date 23 6, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** 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 . + ** + *************************************************************************/ + +#include "undoevent.h" + +//--------------------------------------------------------------------------------------------------------------------- +UndoEvent::UndoEvent() + :QEvent(UNDO_EVENT) +{} diff --git a/src/app/widgets/undoevent.h b/src/app/widgets/undoevent.h new file mode 100644 index 000000000..86b0b5d49 --- /dev/null +++ b/src/app/widgets/undoevent.h @@ -0,0 +1,43 @@ +/************************************************************************ + ** + ** @file undoevent.h + ** @author Roman Telezhynskyi + ** @date 23 6, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** 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 . + ** + *************************************************************************/ + +#ifndef UNDOEVENT_H +#define UNDOEVENT_H + +#include + +// Define undo event identifier +const QEvent::Type UNDO_EVENT = static_cast(QEvent::User + 1); + +class UndoEvent : public QEvent +{ +public: + UndoEvent(); +}; + +#endif // UNDOEVENT_H diff --git a/src/app/widgets/vmaingraphicsscene.cpp b/src/app/widgets/vmaingraphicsscene.cpp index e4bbf423d..d5fff7306 100644 --- a/src/app/widgets/vmaingraphicsscene.cpp +++ b/src/app/widgets/vmaingraphicsscene.cpp @@ -28,6 +28,8 @@ #include "vmaingraphicsscene.h" #include +#include +#include //--------------------------------------------------------------------------------------------------------------------- /** @@ -89,6 +91,12 @@ void VMainGraphicsScene::setTransform(const QTransform &transform) _transform = transform; } +//--------------------------------------------------------------------------------------------------------------------- +void VMainGraphicsScene::SetDisable(bool disable) +{ + emit DisableItem(disable); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ChoosedItem emit ChoosedObject signal. diff --git a/src/app/widgets/vmaingraphicsscene.h b/src/app/widgets/vmaingraphicsscene.h index da0489ea9..dae971fa0 100644 --- a/src/app/widgets/vmaingraphicsscene.h +++ b/src/app/widgets/vmaingraphicsscene.h @@ -47,6 +47,7 @@ public: void setVerScrollBar(const qint32 &value); QTransform transform() const; void setTransform(const QTransform &transform); + void SetDisable(bool enabled); public slots: void ChoosedItem(quint32 id, const SceneObject &type); void SetFactor(qreal factor); @@ -75,6 +76,7 @@ signals: * @param factor scene scale factor. */ void NewFactor(qreal factor); + void DisableItem(bool disable); private: /** @brief horScrollBar value horizontal scroll bar. */ qint32 horScrollBar; diff --git a/src/app/widgets/widgets.pri b/src/app/widgets/widgets.pri index 52b5d6e1e..9f65f5621 100644 --- a/src/app/widgets/widgets.pri +++ b/src/app/widgets/widgets.pri @@ -11,7 +11,8 @@ HEADERS += \ widgets/vsimplesplinepath.h \ widgets/vsimplearc.h \ widgets/textdelegate.h \ - widgets/vtranslation.h + widgets/vtranslation.h \ + widgets/undoevent.h SOURCES += \ widgets/vtablegraphicsview.cpp \ @@ -26,4 +27,5 @@ SOURCES += \ widgets/vsimplesplinepath.cpp \ widgets/vsimplearc.cpp \ widgets/textdelegate.cpp \ - widgets/vtranslation.cpp + widgets/vtranslation.cpp \ + widgets/undoevent.cpp diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index fb697fbd2..5787834cc 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -36,6 +36,8 @@ #include "../exception/vexceptionwrongid.h" #include "../exception/vexceptionconversionerror.h" #include "../exception/vexceptionemptyparameter.h" +#include "../exception/vexceptionundo.h" +#include "../widgets/undoevent.h" #include "vstandardmeasurements.h" #include "vindividualmeasurements.h" #include "../../libs/qmuparser/qmuparsererror.h" @@ -650,36 +652,45 @@ void VPattern::LiteParseTree() { try { + emit SetEnabledGUI(true); Parse(Document::LiteParse); } + catch (const VExceptionUndo &e) + { + Q_UNUSED(e); + /* If user want undo last operation before undo we need finish broken redo operation. For those we post event + * myself. Later in method customEvent call undo.*/ + QApplication::postEvent(this, new UndoEvent()); + return; + } catch (const VExceptionObjectError &e) { e.CriticalMessageBox(tr("Error parsing file.")); - emit ClearMainWindow(); + emit SetEnabledGUI(false); return; } catch (const VExceptionConversionError &e) { e.CriticalMessageBox(tr("Error can't convert value.")); - emit ClearMainWindow(); + emit SetEnabledGUI(false); return; } catch (const VExceptionEmptyParameter &e) { e.CriticalMessageBox(tr("Error empty parameter.")); - emit ClearMainWindow(); + emit SetEnabledGUI(false); return; } catch (const VExceptionWrongId &e) { e.CriticalMessageBox(tr("Error wrong id.")); - emit ClearMainWindow(); + emit SetEnabledGUI(false); return; } catch (VException &e) { e.CriticalMessageBox(tr("Error parsing file.")); - emit ClearMainWindow(); + emit SetEnabledGUI(false); return; } catch (const std::bad_alloc &) @@ -687,12 +698,12 @@ void VPattern::LiteParseTree() #ifndef QT_NO_CURSOR QApplication::restoreOverrideCursor(); #endif - QMessageBox::critical(nullptr, tr("Critical error!"), tr("Error parsing file (std::bad_alloc)."), QMessageBox::Ok, - QMessageBox::Ok); + QMessageBox::critical(nullptr, tr("Critical error!"), tr("Error parsing file (std::bad_alloc)."), + QMessageBox::Ok, QMessageBox::Ok); #ifndef QT_NO_CURSOR QApplication::setOverrideCursor(Qt::WaitCursor); #endif - emit ClearMainWindow(); + emit SetEnabledGUI(false); return; } @@ -733,6 +744,15 @@ void VPattern::ClearScene() emit ClearMainWindow(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::customEvent(QEvent *event) +{ + if(event->type() == UNDO_EVENT) + { + qApp->getUndoStack()->undo(); + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ParseDrawElement parse draw tag. @@ -1008,6 +1028,7 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElem scene->addItem(spoint); connect(spoint, &VToolSinglePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(scene, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor); + connect(scene, &VMainGraphicsScene::DisableItem, spoint, &VToolPoint::Disable); tools[id] = spoint; } } diff --git a/src/app/xml/vpattern.h b/src/app/xml/vpattern.h index 753c9cdb5..4b94141b1 100644 --- a/src/app/xml/vpattern.h +++ b/src/app/xml/vpattern.h @@ -145,12 +145,15 @@ signals: void ChangedCursor(quint32 id); void ClearMainWindow(); void UndoCommand(); + void SetEnabledGUI(bool enabled); public slots: void LiteParseTree(); void haveLiteChange(); void ShowHistoryTool(quint32 id, Qt::GlobalColor color, bool enable); void NeedFullParsing(); void ClearScene(); +protected: + virtual void customEvent(QEvent * event); private: Q_DISABLE_COPY(VPattern)