From d914f359c171a27082998f2ab2df3a56846d148c Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 6 Jun 2014 13:36:34 +0300 Subject: [PATCH] New undo command AddPatternPiece. --HG-- branch : feature --- src/app/mainwindow.cpp | 12 +++++--- src/app/mainwindow.h | 2 +- src/app/tools/drawTools/vdrawtool.cpp | 35 ++++------------------ src/app/xml/vpattern.cpp | 15 ++++++---- src/app/xml/vpattern.h | 2 ++ src/app/xml/vundocommands.cpp | 42 +++++++++++++++++++++------ src/app/xml/vundocommands.h | 29 ++++++++++++++++-- 7 files changed, 85 insertions(+), 52 deletions(-) diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index d63759da1..179b17030 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -93,6 +93,7 @@ MainWindow::MainWindow(QWidget *parent) doc = new VPattern(pattern, &mode, sceneDraw, sceneDetails); connect(doc, &VPattern::patternChanged, this, &MainWindow::PatternWasModified); connect(doc, &VPattern::ClearMainWindow, this, &MainWindow::Clear); + connect(doc, &VPattern::UndoCommand, this, &MainWindow::FullParseFile); InitAutoSave(); @@ -105,16 +106,19 @@ MainWindow::MainWindow(QWidget *parent) //--------------------------------------------------------------------------------------------------------------------- /** - * @brief ActionNewDraw add to scene new pattern peace. + * @brief ActionNewPP add to scene new pattern piece. */ -void MainWindow::ActionNewDraw() +void MainWindow::ActionNewPP() { QString patternPieceName = QString(tr("Pattern piece %1")).arg(comboBoxDraws->count()+1); if (comboBoxDraws->count() == 0) { QString path; DialogMeasurements measurements(this); - measurements.exec(); + if (measurements.exec() == QDialog::Rejected) + { + return; + } if (measurements.type() == Measurements::Standard) { qApp->setPatternType(Pattern::Standard); @@ -1819,7 +1823,7 @@ void MainWindow::CreateActions() connect(ui->actionArrowTool, &QAction::triggered, this, &MainWindow::ActionAroowTool); connect(ui->actionDraw, &QAction::triggered, this, &MainWindow::ActionDraw); connect(ui->actionDetails, &QAction::triggered, this, &MainWindow::ActionDetails); - connect(ui->actionNewDraw, &QAction::triggered, this, &MainWindow::ActionNewDraw); + connect(ui->actionNewDraw, &QAction::triggered, this, &MainWindow::ActionNewPP); connect(ui->actionOptionDraw, &QAction::triggered, this, &MainWindow::OptionDraw); connect(ui->actionSaveAs, &QAction::triggered, this, &MainWindow::SaveAs); connect(ui->actionSave, &QAction::triggered, this, &MainWindow::Save); diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index c041bae18..2b80248b4 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -60,7 +60,7 @@ public slots: void ActionAroowTool(); void ActionDraw(bool checked); void ActionDetails(bool checked); - void ActionNewDraw(); + void ActionNewPP(); void ActionLayout(bool checked); void ActionTable(bool checked); void ActionHistory(bool checked); diff --git a/src/app/tools/drawTools/vdrawtool.cpp b/src/app/tools/drawTools/vdrawtool.cpp index 2b45827f5..7a6b628e7 100644 --- a/src/app/tools/drawTools/vdrawtool.cpp +++ b/src/app/tools/drawTools/vdrawtool.cpp @@ -29,10 +29,9 @@ #include "vdrawtool.h" #include - #include - #include +#include "../../xml/vundocommands.h" qreal VDrawTool::factor = 1; @@ -191,32 +190,8 @@ qreal VDrawTool::CheckFormula(QString &formula, VContainer *data) */ void VDrawTool::AddToCalculation(const QDomElement &domElement) { - QDomElement calcElement; - bool ok = doc->GetActivNodeElement(VPattern::TagCalculation, calcElement); - if (ok) - { - quint32 id = doc->getCursor(); - if (id <= 0) - { - calcElement.appendChild(domElement); - } - else - { - QDomElement refElement = doc->elementById(QString().setNum(doc->getCursor())); - if (refElement.isElement()) - { - calcElement.insertAfter(domElement, refElement); - doc->setCursor(0); - } - else - { - qCritical()<getUndoStack()->push(addToCal); } diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 0670d12ad..7ebeb3878 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -399,7 +399,7 @@ void VPattern::setCurrentData() void VPattern::AddTool(const quint32 &id, VDataTool *tool) { Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); - Q_CHECK_PTR(tool); + SCASSERT(tool != nullptr); tools.insert(id, tool); } @@ -412,9 +412,9 @@ void VPattern::AddTool(const quint32 &id, VDataTool *tool) void VPattern::UpdateToolData(const quint32 &id, VContainer *data) { Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); - Q_CHECK_PTR(data); + SCASSERT(data != nullptr); VDataTool *tool = tools.value(id); - Q_CHECK_PTR(tool); + SCASSERT(tool != nullptr); tool->VDataTool::setData(data); } @@ -427,7 +427,7 @@ void VPattern::IncrementReferens(quint32 id) const { Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); VDataTool *tool = tools.value(id); - Q_CHECK_PTR(tool); + SCASSERT(tool != nullptr); tool->incrementReferens(); } @@ -440,7 +440,7 @@ void VPattern::DecrementReferens(quint32 id) const { Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); VDataTool *tool = tools.value(id); - Q_CHECK_PTR(tool); + SCASSERT(tool != nullptr); tool->decrementReferens(); } @@ -747,6 +747,11 @@ void VPattern::ShowHistoryTool(quint32 id, Qt::GlobalColor color, bool enable) emit ShowTool(id, color, enable); } +void VPattern::NeedFullParsing() +{ + emit UndoCommand(); +} + //--------------------------------------------------------------------------------------------------------------------- /** diff --git a/src/app/xml/vpattern.h b/src/app/xml/vpattern.h index d662a1974..6936adb9e 100644 --- a/src/app/xml/vpattern.h +++ b/src/app/xml/vpattern.h @@ -149,10 +149,12 @@ signals: */ void ChangedCursor(quint32 id); void ClearMainWindow(); + void UndoCommand(); public slots: void LiteParseTree(); void haveLiteChange(); void ShowHistoryTool(quint32 id, Qt::GlobalColor color, bool enable); + void NeedFullParsing(); private: Q_DISABLE_COPY(VPattern) diff --git a/src/app/xml/vundocommands.cpp b/src/app/xml/vundocommands.cpp index cc1b9ccb4..588b2f57b 100644 --- a/src/app/xml/vundocommands.cpp +++ b/src/app/xml/vundocommands.cpp @@ -30,18 +30,18 @@ #include //--------------------------------------------------------------------------------------------------------------------- -AddToCalculation::AddToCalculation(const QDomElement &xml, VPattern *doc, QUndoCommand *parent) - : QUndoCommand(parent), xml(xml), doc(doc), nameActivDraw(doc->GetNameActivDraw()), cursor(doc->getCursor()) +AddToCal::AddToCal(const QDomElement &xml, VPattern *doc, QUndoCommand *parent) + : QObject(), QUndoCommand(parent), xml(xml), doc(doc), nameActivDraw(doc->GetNameActivDraw()), cursor(doc->getCursor()) { - setText(QObject::tr("Add to section %1").arg(VPattern::TagCalculation)); + setText(tr("Add to section %1").arg(VPattern::TagCalculation)); } //--------------------------------------------------------------------------------------------------------------------- -AddToCalculation::~AddToCalculation() +AddToCal::~AddToCal() {} //--------------------------------------------------------------------------------------------------------------------- -void AddToCalculation::undo() +void AddToCal::undo() { doc->ChangeActivDraw(nameActivDraw); doc->setCursor(cursor); @@ -59,10 +59,11 @@ void AddToCalculation::undo() { qDebug()<<"Can't find tag Calculation"<< Q_FUNC_INFO; } + emit NeedFullParsing(); } //--------------------------------------------------------------------------------------------------------------------- -void AddToCalculation::redo() +void AddToCal::redo() { doc->ChangeActivDraw(nameActivDraw); doc->setCursor(cursor); @@ -84,13 +85,36 @@ void AddToCalculation::redo() } else { - qDebug()< #include -class AddToCalculation : public QUndoCommand +class AddToCal : public QObject, public QUndoCommand { + Q_OBJECT public: - AddToCalculation(const QDomElement &xml, VPattern *doc, QUndoCommand *parent = 0); - virtual ~AddToCalculation(); + AddToCal(const QDomElement &xml, VPattern *doc, QUndoCommand *parent = 0); + virtual ~AddToCal(); virtual void undo(); virtual void redo(); +signals: + void UnsavedChange(); + void NeedFullParsing(); private: + Q_DISABLE_COPY(AddToCal) const QDomElement xml; VPattern *doc; const QString nameActivDraw; quint32 cursor; }; +class AddPatternPiece : public QObject, public QUndoCommand +{ + Q_OBJECT +public: + AddPatternPiece(const QDomElement &xml, VPattern *doc, QUndoCommand *parent = 0); + virtual ~AddPatternPiece(); + virtual void undo(); + virtual void redo(); +signals: + void UnsavedChange(); + void NeedFullParsing(); +private: + Q_DISABLE_COPY(AddPatternPiece) + const QDomElement xml; + VPattern *doc; + static int countPP; +}; + #endif // VUNDOCOMMANDS_H