Bug in undocommands. We should return to pattern piece only if in Calculation

mode. If do it in Details mode Valentina may not switch pattern piece back when
a user returns to Calculation mode. This breaks a work and no new object can be
added to pattern.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-07-25 11:26:09 +03:00
parent d35684a44a
commit fe9dc90dc7
16 changed files with 87 additions and 40 deletions

View File

@ -130,7 +130,7 @@ MainWindow::MainWindow(QWidget *parent)
dialogTool(), dialogTool(),
dialogHistory(nullptr), dialogHistory(nullptr),
dialogFMeasurements(nullptr), dialogFMeasurements(nullptr),
comboBoxDraws(nullptr), patternPieceLabel(nullptr), mode(Draw::Calculation), comboBoxDraws(nullptr), patternPieceLabel(nullptr),
currentDrawIndex(0), currentToolBoxIndex(0), currentDrawIndex(0), currentToolBoxIndex(0),
isDockToolOptionsVisible(true), isDockToolOptionsVisible(true),
isDockGroupsVisible(true), isDockGroupsVisible(true),
@ -159,7 +159,7 @@ MainWindow::MainWindow(QWidget *parent)
CreateActions(); CreateActions();
InitScenes(); InitScenes();
doc = new VPattern(pattern, &mode, sceneDraw, sceneDetails); doc = new VPattern(pattern, sceneDraw, sceneDetails);
connect(doc, &VPattern::ClearMainWindow, this, &MainWindow::Clear); connect(doc, &VPattern::ClearMainWindow, this, &MainWindow::Clear);
connect(doc, &VPattern::patternChanged, this, &MainWindow::PatternChangesWereSaved); connect(doc, &VPattern::patternChanged, this, &MainWindow::PatternChangesWereSaved);
connect(doc, &VPattern::UndoCommand, this, &MainWindow::FullParseFile); connect(doc, &VPattern::UndoCommand, this, &MainWindow::FullParseFile);
@ -2463,7 +2463,7 @@ void MainWindow::keyPressEvent ( QKeyEvent * event )
*/ */
void MainWindow::SaveCurrentScene() void MainWindow::SaveCurrentScene()
{ {
if (mode == Draw::Calculation || mode == Draw::Modeling) if (qApp->GetDrawMode() == Draw::Calculation || qApp->GetDrawMode() == Draw::Modeling)
{ {
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(currentScene); VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(currentScene);
SCASSERT(scene != nullptr) SCASSERT(scene != nullptr)
@ -2520,7 +2520,7 @@ void MainWindow::ActionDraw(bool checked)
ui->view->setScene(currentScene); ui->view->setScene(currentScene);
RestoreCurrentScene(); RestoreCurrentScene();
mode = Draw::Calculation; qApp->SetDrawMode(Draw::Calculation);
comboBoxDraws->setCurrentIndex(currentDrawIndex);//restore current pattern peace comboBoxDraws->setCurrentIndex(currentDrawIndex);//restore current pattern peace
drawMode = true; drawMode = true;
@ -2594,11 +2594,11 @@ void MainWindow::ActionDetails(bool checked)
ui->view->setScene(currentScene); ui->view->setScene(currentScene);
RestoreCurrentScene(); RestoreCurrentScene();
if (mode == Draw::Calculation) if (qApp->GetDrawMode() == Draw::Calculation)
{ {
currentToolBoxIndex = ui->toolBox->currentIndex(); currentToolBoxIndex = ui->toolBox->currentIndex();
} }
mode = Draw::Modeling; qApp->SetDrawMode(Draw::Modeling);
SetEnableTool(true); SetEnableTool(true);
SetEnableWidgets(true); SetEnableWidgets(true);
ui->toolBox->setCurrentIndex(ui->toolBox->indexOf(ui->detailPage)); ui->toolBox->setCurrentIndex(ui->toolBox->indexOf(ui->detailPage));
@ -2678,7 +2678,7 @@ void MainWindow::ActionLayout(bool checked)
QMessageBox::information(this, tr("Layout mode"), tr("You can't use Layout mode yet. Please, " QMessageBox::information(this, tr("Layout mode"), tr("You can't use Layout mode yet. Please, "
"include at least one detail in layout."), "include at least one detail in layout."),
QMessageBox::Ok, QMessageBox::Ok); QMessageBox::Ok, QMessageBox::Ok);
mode == Draw::Calculation ? ActionDraw(true) : ActionDetails(true); qApp->GetDrawMode() == Draw::Calculation ? ActionDraw(true) : ActionDetails(true);
return; return;
} }
} }
@ -2700,7 +2700,7 @@ void MainWindow::ActionLayout(bool checked)
QMessageBox::warning(this, tr("Layout mode"), QMessageBox::warning(this, tr("Layout mode"),
tr("You can't use Layout mode yet.") + QLatin1String(" \n") + e.ErrorMessage(), tr("You can't use Layout mode yet.") + QLatin1String(" \n") + e.ErrorMessage(),
QMessageBox::Ok, QMessageBox::Ok); QMessageBox::Ok, QMessageBox::Ok);
mode == Draw::Calculation ? ActionDraw(true) : ActionDetails(true); qApp->GetDrawMode() == Draw::Calculation ? ActionDraw(true) : ActionDetails(true);
return; return;
} }
@ -2708,11 +2708,11 @@ void MainWindow::ActionLayout(bool checked)
emit ui->view->itemClicked(nullptr); emit ui->view->itemClicked(nullptr);
ui->view->setScene(currentScene); ui->view->setScene(currentScene);
if (mode == Draw::Calculation) if (qApp->GetDrawMode() == Draw::Calculation)
{ {
currentToolBoxIndex = ui->toolBox->currentIndex(); currentToolBoxIndex = ui->toolBox->currentIndex();
} }
mode = Draw::Layout; qApp->SetDrawMode(Draw::Layout);
SetEnableTool(true); SetEnableTool(true);
SetEnableWidgets(true); SetEnableWidgets(true);
ui->toolBox->setCurrentIndex(ui->toolBox->indexOf(ui->layoutPage)); ui->toolBox->setCurrentIndex(ui->toolBox->indexOf(ui->layoutPage));
@ -3307,8 +3307,8 @@ void MainWindow::SetEnabledGUI(bool enabled)
*/ */
void MainWindow::SetEnableWidgets(bool enable) void MainWindow::SetEnableWidgets(bool enable)
{ {
const bool drawStage = (mode == Draw::Calculation); const bool drawStage = (qApp->GetDrawMode() == Draw::Calculation);
const bool designStage = (drawStage || mode == Draw::Modeling); const bool designStage = (drawStage || qApp->GetDrawMode() == Draw::Modeling);
comboBoxDraws->setEnabled(enable && drawStage); comboBoxDraws->setEnabled(enable && drawStage);
ui->actionOptionDraw->setEnabled(enable && drawStage); ui->actionOptionDraw->setEnabled(enable && drawStage);
@ -3586,7 +3586,7 @@ void MainWindow::SetEnableTool(bool enable)
QT_WARNING_PUSH QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wswitch-default") QT_WARNING_DISABLE_GCC("-Wswitch-default")
switch (mode) switch (qApp->GetDrawMode())
{ {
case Draw::Calculation: case Draw::Calculation:
drawTools = enable; drawTools = enable;

View File

@ -246,9 +246,6 @@ private:
QComboBox *comboBoxDraws; QComboBox *comboBoxDraws;
QLabel *patternPieceLabel; QLabel *patternPieceLabel;
/** @brief mode keep current draw mode. */
Draw mode;
/** @brief currentDrawIndex save current selected pattern peace. */ /** @brief currentDrawIndex save current selected pattern peace. */
qint32 currentDrawIndex; qint32 currentDrawIndex;

View File

@ -90,9 +90,8 @@ void GatherCount(int &count, const int nodes)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPattern::VPattern(VContainer *data, Draw *mode, VMainGraphicsScene *sceneDraw, VPattern::VPattern(VContainer *data, VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, QObject *parent)
VMainGraphicsScene *sceneDetail, QObject *parent) : VAbstractPattern(parent), data(data), sceneDraw(sceneDraw), sceneDetail(sceneDetail)
: VAbstractPattern(parent), data(data), mode(mode), sceneDraw(sceneDraw), sceneDetail(sceneDetail)
{ {
SCASSERT(sceneDraw != nullptr) SCASSERT(sceneDraw != nullptr)
SCASSERT(sceneDetail != nullptr) SCASSERT(sceneDetail != nullptr)
@ -269,7 +268,7 @@ void VPattern::Parse(const Document &parse)
*/ */
void VPattern::setCurrentData() void VPattern::setCurrentData()
{ {
if (*mode == Draw::Calculation) if (qApp->GetDrawMode() == Draw::Calculation)
{ {
const int countPP = CountPP(); const int countPP = CountPP();
if (countPP > 1)//don't need upadate data if we have only one pattern piece if (countPP > 1)//don't need upadate data if we have only one pattern piece

View File

@ -46,7 +46,7 @@ class VPattern : public VAbstractPattern
{ {
Q_OBJECT Q_OBJECT
public: public:
VPattern(VContainer *data, Draw *mode, VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, VPattern(VContainer *data, VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail,
QObject *parent = nullptr); QObject *parent = nullptr);
virtual void CreateEmptyFile() override; virtual void CreateEmptyFile() override;
@ -125,9 +125,6 @@ private:
/** @brief data container with data. */ /** @brief data container with data. */
VContainer *data; VContainer *data;
/** @brief mode current draw mode. */
Draw *mode;
VMainGraphicsScene *sceneDraw; VMainGraphicsScene *sceneDraw;
VMainGraphicsScene *sceneDetail; VMainGraphicsScene *sceneDetail;

View File

@ -32,7 +32,6 @@
#include <QVector> #include <QVector>
#include <QPolygonF> #include <QPolygonF>
enum class Draw : char { Calculation, Modeling, Layout };
enum class GOType : char enum class GOType : char
{ {
Point, Point,

View File

@ -36,6 +36,7 @@
#include <QtGlobal> #include <QtGlobal>
#include "vgeometrydef.h" #include "vgeometrydef.h"
#include "../vmisc/def.h"
class QLineF; class QLineF;
class QPoint; class QPoint;

View File

@ -68,6 +68,7 @@ enum class Source : char { FromGui, FromFile, FromTool };
enum class NodeUsage : bool {NotInUse = false, InUse = true}; enum class NodeUsage : bool {NotInUse = false, InUse = true};
enum class SelectionType : bool {ByMousePress, ByMouseRelease}; enum class SelectionType : bool {ByMousePress, ByMouseRelease};
enum class PageOrientation : bool {Portrait = true, Landscape = false}; enum class PageOrientation : bool {Portrait = true, Landscape = false};
enum class Draw : char { Calculation, Modeling, Layout };
enum class PieceNodeAngle : unsigned char enum class PieceNodeAngle : unsigned char
{ {

View File

@ -61,7 +61,8 @@ VAbstractApplication::VAbstractApplication(int &argc, char **argv)
doc(nullptr), doc(nullptr),
m_customerName(), m_customerName(),
m_userMaterials(), m_userMaterials(),
openingPattern(false) openingPattern(false),
mode(Draw::Calculation)
{ {
QString rules; QString rules;
@ -259,6 +260,18 @@ QString VAbstractApplication::ClearMessage(QString msg)
return msg; return msg;
} }
//---------------------------------------------------------------------------------------------------------------------
const Draw &VAbstractApplication::GetDrawMode() const
{
return mode;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractApplication::SetDrawMode(const Draw &value)
{
mode = value;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
void VAbstractApplication::WinAttachConsole() void VAbstractApplication::WinAttachConsole()

View File

@ -121,6 +121,9 @@ public:
QMap<int, QString> GetUserMaterials() const; QMap<int, QString> GetUserMaterials() const;
void SetUserMaterials(const QMap<int, QString> &userMaterials); void SetUserMaterials(const QMap<int, QString> &userMaterials);
const Draw &GetDrawMode() const;
void SetDrawMode(const Draw &value);
protected: protected:
QUndoStack *undoStack; QUndoStack *undoStack;
@ -163,6 +166,9 @@ private:
*/ */
bool openingPattern; bool openingPattern;
/** @brief mode keep current draw mode. */
Draw mode;
void ClearTranslation(); void ClearTranslation();
}; };

View File

@ -92,8 +92,11 @@ void AddGroup::undo()
} }
VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView());
if (qApp->GetDrawMode() == Draw::Calculation)
{
emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo
} }
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void AddGroup::redo() void AddGroup::redo()

View File

@ -116,5 +116,8 @@ void AddItemToGroup::performUndoRedo(bool isUndo)
} }
VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView());
if (qApp->GetDrawMode() == Draw::Calculation)
{
emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo
} }
}

View File

@ -78,8 +78,11 @@ void AddToCalc::undo()
} }
emit NeedFullParsing(); emit NeedFullParsing();
VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView());
if (qApp->GetDrawMode() == Draw::Calculation)
{
emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo
} }
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void AddToCalc::redo() void AddToCalc::redo()
@ -125,8 +128,11 @@ void AddToCalc::RedoFullParsing()
if (redoFlag) if (redoFlag)
{ {
emit NeedFullParsing(); emit NeedFullParsing();
if (qApp->GetDrawMode() == Draw::Calculation)
{
emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo
} }
}
else else
{ {
QApplication::postEvent(doc, new LiteParseEvent()); QApplication::postEvent(doc, new LiteParseEvent());

View File

@ -32,6 +32,7 @@
#include <QDomNodeList> #include <QDomNodeList>
#include "../vmisc/logging.h" #include "../vmisc/logging.h"
#include "../vmisc/vabstractapplication.h"
#include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vabstractpattern.h"
#include "vundocommand.h" #include "vundocommand.h"
@ -82,15 +83,21 @@ void DeletePatternPiece::undo()
} }
emit NeedFullParsing(); emit NeedFullParsing();
if (qApp->GetDrawMode() == Draw::Calculation)
{
emit doc->SetCurrentPP(namePP);//Without this user will not see this change emit doc->SetCurrentPP(namePP);//Without this user will not see this change
} }
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DeletePatternPiece::redo() void DeletePatternPiece::redo()
{ {
qCDebug(vUndo, "Redo."); qCDebug(vUndo, "Redo.");
if (qApp->GetDrawMode() == Draw::Calculation)
{
emit doc->SetCurrentPP(namePP);//Without this user will not see this change emit doc->SetCurrentPP(namePP);//Without this user will not see this change
}
QDomElement rootElement = doc->documentElement(); QDomElement rootElement = doc->documentElement();
const QDomElement patternPiece = doc->GetPPElement(namePP); const QDomElement patternPiece = doc->GetPPElement(namePP);
rootElement.removeChild(patternPiece); rootElement.removeChild(patternPiece);

View File

@ -58,7 +58,10 @@ void DelGroup::undo()
{ {
qCDebug(vUndo, "Undo."); qCDebug(vUndo, "Undo.");
if (qApp->GetDrawMode() == Draw::Calculation)
{
emit doc->SetCurrentPP(nameActivDraw);//Without this user will not see this change emit doc->SetCurrentPP(nameActivDraw);//Without this user will not see this change
}
QDomElement groups = doc->CreateGroups(); QDomElement groups = doc->CreateGroups();
if (not groups.isNull()) if (not groups.isNull())
@ -81,8 +84,10 @@ void DelGroup::redo()
{ {
qCDebug(vUndo, "Redo."); qCDebug(vUndo, "Redo.");
//Keep first! if (qApp->GetDrawMode() == Draw::Calculation)
{//Keep first!
emit doc->SetCurrentPP(nameActivDraw);//Without this user will not see this change emit doc->SetCurrentPP(nameActivDraw);//Without this user will not see this change
}
QDomElement groups = doc->CreateGroups(); QDomElement groups = doc->CreateGroups();
if (not groups.isNull()) if (not groups.isNull())
{ {

View File

@ -33,6 +33,7 @@
#include "../ifc/ifcdef.h" #include "../ifc/ifcdef.h"
#include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vabstractpattern.h"
#include "../vmisc/logging.h" #include "../vmisc/logging.h"
#include "../vmisc/vabstractapplication.h"
#include "vundocommand.h" #include "vundocommand.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -58,17 +59,22 @@ void DelTool::undo()
UndoDeleteAfterSibling(parentNode, siblingId); UndoDeleteAfterSibling(parentNode, siblingId);
emit NeedFullParsing(); emit NeedFullParsing();
//Keep last!
if (qApp->GetDrawMode() == Draw::Calculation)
{//Keep last!
emit doc->SetCurrentPP(nameActivDraw);//Without this user will not see this change emit doc->SetCurrentPP(nameActivDraw);//Without this user will not see this change
} }
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DelTool::redo() void DelTool::redo()
{ {
qCDebug(vUndo, "Redo."); qCDebug(vUndo, "Redo.");
//Keep first! if (qApp->GetDrawMode() == Draw::Calculation)
{//Keep first!
emit doc->SetCurrentPP(nameActivDraw);//Without this user will not see this change emit doc->SetCurrentPP(nameActivDraw);//Without this user will not see this change
}
QDomElement domElement = doc->NodeById(nodeId); QDomElement domElement = doc->NodeById(nodeId);
parentNode.removeChild(domElement); parentNode.removeChild(domElement);
emit NeedFullParsing(); emit NeedFullParsing();

View File

@ -116,5 +116,9 @@ void RemoveItemFromGroup::performUndoRedo(bool isUndo)
} }
VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView());
if (qApp->GetDrawMode() == Draw::Calculation)
{
emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo
} }
}