Fixed issue #82. Fixed issue #83. Fixed issue #85.

--HG--
branch : develop
This commit is contained in:
dismine 2014-06-24 11:23:39 +03:00
parent ed25d04e5e
commit 82836c15a1
46 changed files with 615 additions and 43 deletions

View file

@ -0,0 +1,79 @@
/************************************************************************
**
** @file dialogundo.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "dialogundo.h"
#include "ui_dialogundo.h"
#include "../../widgets/vapplication.h"
#include "../../exception/vexceptionundo.h"
#include <QCloseEvent>
#include <QUndoStack>
//---------------------------------------------------------------------------------------------------------------------
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();
}

View file

@ -0,0 +1,65 @@
/************************************************************************
**
** @file dialogundo.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef DIALOGUNDO_H
#define DIALOGUNDO_H
#include <QDialog>
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

View file

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialogUndo</class>
<widget class="QDialog" name="DialogUndo">
<property name="windowModality">
<enum>Qt::WindowModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>387</width>
<height>145</height>
</rect>
</property>
<property name="windowTitle">
<string>Broken formula</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Error while calculation formula. You can try undo last operation or fix broken formula.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="pushButtonUndo">
<property name="text">
<string>&amp;Undo</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonFix">
<property name="text">
<string>&amp;Fix formula</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonCancel">
<property name="text">
<string>&amp;Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -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

View file

@ -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

View file

@ -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;

View file

@ -0,0 +1,39 @@
/************************************************************************
**
** @file vexceptionundo.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "vexceptionundo.h"
//---------------------------------------------------------------------------------------------------------------------
VExceptionUndo::VExceptionUndo(const QString &what)
:VException(what)
{}
//---------------------------------------------------------------------------------------------------------------------
VExceptionUndo::VExceptionUndo(const VExceptionUndo &e)
:VException(e)
{}

View file

@ -0,0 +1,42 @@
/************************************************************************
**
** @file vexceptionundo.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#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

View file

@ -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 <QInputDialog>
#include <QtCore>
@ -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);
}
}
//---------------------------------------------------------------------------------------------------------------------

View file

@ -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();

View file

@ -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.

View file

@ -41,6 +41,7 @@ public:
static const QString TagName;
public slots:
virtual void FullUpdateFromFile ();
void Disable(bool disable);
signals:
/**
* @brief RefreshLine refresh control line.

View file

@ -30,9 +30,11 @@
#include <qmuparsererror.h>
#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;
}
}

View file

@ -165,6 +165,20 @@ protected:
item->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor));
}
}
template <typename Item>
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)
};

View file

@ -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);

View file

@ -157,6 +157,7 @@ VToolArc* VToolArc::Create(const quint32 _id, const quint32 &center, 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.

View file

@ -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();

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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;

View file

@ -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);

View file

@ -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.

View file

@ -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();

View file

@ -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);

View file

@ -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);

View file

@ -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.

View file

@ -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;

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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<DialogSinglePoint>(this, event);
@ -247,6 +249,7 @@ void VToolSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event
{
ContextMenu<DialogSinglePoint>(this, event, false);
}
_referens = ref; // restore referens. If not restore garbage collector delete point!!!
}
//---------------------------------------------------------------------------------------------------------------------

View file

@ -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.

View file

@ -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 ();

View file

@ -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.

View file

@ -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();

View file

@ -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);

View file

@ -50,7 +50,6 @@ DeletePatternPiece::~DeletePatternPiece()
//---------------------------------------------------------------------------------------------------------------------
void DeletePatternPiece::undo()
{
QDomElement rootElement = doc->documentElement();
rootElement.insertAfter(patternPiece, previousNode);

View file

@ -0,0 +1,34 @@
/************************************************************************
**
** @file undoevent.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "undoevent.h"
//---------------------------------------------------------------------------------------------------------------------
UndoEvent::UndoEvent()
:QEvent(UNDO_EVENT)
{}

View file

@ -0,0 +1,43 @@
/************************************************************************
**
** @file undoevent.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef UNDOEVENT_H
#define UNDOEVENT_H
#include <QEvent>
// Define undo event identifier
const QEvent::Type UNDO_EVENT = static_cast<QEvent::Type>(QEvent::User + 1);
class UndoEvent : public QEvent
{
public:
UndoEvent();
};
#endif // UNDOEVENT_H

View file

@ -28,6 +28,8 @@
#include "vmaingraphicsscene.h"
#include <QGraphicsSceneMouseEvent>
#include <QList>
#include <QGraphicsItem>
//---------------------------------------------------------------------------------------------------------------------
/**
@ -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.

View file

@ -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;

View file

@ -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

View file

@ -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;
}
}

View file

@ -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)