New undo command AddPatternPiece.

--HG--
branch : feature
This commit is contained in:
dismine 2014-06-06 13:36:34 +03:00
parent 99314a358f
commit d914f359c1
7 changed files with 85 additions and 52 deletions

View File

@ -93,6 +93,7 @@ MainWindow::MainWindow(QWidget *parent)
doc = new VPattern(pattern, &mode, sceneDraw, sceneDetails); doc = new VPattern(pattern, &mode, sceneDraw, sceneDetails);
connect(doc, &VPattern::patternChanged, this, &MainWindow::PatternWasModified); connect(doc, &VPattern::patternChanged, this, &MainWindow::PatternWasModified);
connect(doc, &VPattern::ClearMainWindow, this, &MainWindow::Clear); connect(doc, &VPattern::ClearMainWindow, this, &MainWindow::Clear);
connect(doc, &VPattern::UndoCommand, this, &MainWindow::FullParseFile);
InitAutoSave(); 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); QString patternPieceName = QString(tr("Pattern piece %1")).arg(comboBoxDraws->count()+1);
if (comboBoxDraws->count() == 0) if (comboBoxDraws->count() == 0)
{ {
QString path; QString path;
DialogMeasurements measurements(this); DialogMeasurements measurements(this);
measurements.exec(); if (measurements.exec() == QDialog::Rejected)
{
return;
}
if (measurements.type() == Measurements::Standard) if (measurements.type() == Measurements::Standard)
{ {
qApp->setPatternType(Pattern::Standard); qApp->setPatternType(Pattern::Standard);
@ -1819,7 +1823,7 @@ void MainWindow::CreateActions()
connect(ui->actionArrowTool, &QAction::triggered, this, &MainWindow::ActionAroowTool); connect(ui->actionArrowTool, &QAction::triggered, this, &MainWindow::ActionAroowTool);
connect(ui->actionDraw, &QAction::triggered, this, &MainWindow::ActionDraw); connect(ui->actionDraw, &QAction::triggered, this, &MainWindow::ActionDraw);
connect(ui->actionDetails, &QAction::triggered, this, &MainWindow::ActionDetails); 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->actionOptionDraw, &QAction::triggered, this, &MainWindow::OptionDraw);
connect(ui->actionSaveAs, &QAction::triggered, this, &MainWindow::SaveAs); connect(ui->actionSaveAs, &QAction::triggered, this, &MainWindow::SaveAs);
connect(ui->actionSave, &QAction::triggered, this, &MainWindow::Save); connect(ui->actionSave, &QAction::triggered, this, &MainWindow::Save);

View File

@ -60,7 +60,7 @@ public slots:
void ActionAroowTool(); void ActionAroowTool();
void ActionDraw(bool checked); void ActionDraw(bool checked);
void ActionDetails(bool checked); void ActionDetails(bool checked);
void ActionNewDraw(); void ActionNewPP();
void ActionLayout(bool checked); void ActionLayout(bool checked);
void ActionTable(bool checked); void ActionTable(bool checked);
void ActionHistory(bool checked); void ActionHistory(bool checked);

View File

@ -29,10 +29,9 @@
#include "vdrawtool.h" #include "vdrawtool.h"
#include <qmuparsererror.h> #include <qmuparsererror.h>
#include <dialogs/tools/dialogeditwrongformula.h> #include <dialogs/tools/dialogeditwrongformula.h>
#include <container/calculator.h> #include <container/calculator.h>
#include "../../xml/vundocommands.h"
qreal VDrawTool::factor = 1; qreal VDrawTool::factor = 1;
@ -191,32 +190,8 @@ qreal VDrawTool::CheckFormula(QString &formula, VContainer *data)
*/ */
void VDrawTool::AddToCalculation(const QDomElement &domElement) void VDrawTool::AddToCalculation(const QDomElement &domElement)
{ {
QDomElement calcElement; AddToCal *addToCal = new AddToCal(domElement, doc);
bool ok = doc->GetActivNodeElement(VPattern::TagCalculation, calcElement); connect(addToCal, &AddToCal::UnsavedChange, doc, &VPattern::haveLiteChange);
if (ok) connect(addToCal, &AddToCal::NeedFullParsing, doc, &VPattern::NeedFullParsing);
{ qApp->getUndoStack()->push(addToCal);
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()<<tr("Can not find the element after which you want to insert.")<< Q_FUNC_INFO;
}
}
}
else
{
qCritical()<<tr("Can't find tag Calculation")<< Q_FUNC_INFO;
}
emit toolhaveChange();
} }

View File

@ -399,7 +399,7 @@ void VPattern::setCurrentData()
void VPattern::AddTool(const quint32 &id, VDataTool *tool) void VPattern::AddTool(const quint32 &id, VDataTool *tool)
{ {
Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0");
Q_CHECK_PTR(tool); SCASSERT(tool != nullptr);
tools.insert(id, tool); tools.insert(id, tool);
} }
@ -412,9 +412,9 @@ void VPattern::AddTool(const quint32 &id, VDataTool *tool)
void VPattern::UpdateToolData(const quint32 &id, VContainer *data) void VPattern::UpdateToolData(const quint32 &id, VContainer *data)
{ {
Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0");
Q_CHECK_PTR(data); SCASSERT(data != nullptr);
VDataTool *tool = tools.value(id); VDataTool *tool = tools.value(id);
Q_CHECK_PTR(tool); SCASSERT(tool != nullptr);
tool->VDataTool::setData(data); tool->VDataTool::setData(data);
} }
@ -427,7 +427,7 @@ void VPattern::IncrementReferens(quint32 id) const
{ {
Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0");
VDataTool *tool = tools.value(id); VDataTool *tool = tools.value(id);
Q_CHECK_PTR(tool); SCASSERT(tool != nullptr);
tool->incrementReferens(); tool->incrementReferens();
} }
@ -440,7 +440,7 @@ void VPattern::DecrementReferens(quint32 id) const
{ {
Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0");
VDataTool *tool = tools.value(id); VDataTool *tool = tools.value(id);
Q_CHECK_PTR(tool); SCASSERT(tool != nullptr);
tool->decrementReferens(); tool->decrementReferens();
} }
@ -747,6 +747,11 @@ void VPattern::ShowHistoryTool(quint32 id, Qt::GlobalColor color, bool enable)
emit ShowTool(id, color, enable); emit ShowTool(id, color, enable);
} }
void VPattern::NeedFullParsing()
{
emit UndoCommand();
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**

View File

@ -149,10 +149,12 @@ signals:
*/ */
void ChangedCursor(quint32 id); void ChangedCursor(quint32 id);
void ClearMainWindow(); void ClearMainWindow();
void UndoCommand();
public slots: public slots:
void LiteParseTree(); void LiteParseTree();
void haveLiteChange(); void haveLiteChange();
void ShowHistoryTool(quint32 id, Qt::GlobalColor color, bool enable); void ShowHistoryTool(quint32 id, Qt::GlobalColor color, bool enable);
void NeedFullParsing();
private: private:
Q_DISABLE_COPY(VPattern) Q_DISABLE_COPY(VPattern)

View File

@ -30,18 +30,18 @@
#include <QDebug> #include <QDebug>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
AddToCalculation::AddToCalculation(const QDomElement &xml, VPattern *doc, QUndoCommand *parent) AddToCal::AddToCal(const QDomElement &xml, VPattern *doc, QUndoCommand *parent)
: QUndoCommand(parent), xml(xml), doc(doc), nameActivDraw(doc->GetNameActivDraw()), cursor(doc->getCursor()) : 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->ChangeActivDraw(nameActivDraw);
doc->setCursor(cursor); doc->setCursor(cursor);
@ -59,10 +59,11 @@ void AddToCalculation::undo()
{ {
qDebug()<<"Can't find tag Calculation"<< Q_FUNC_INFO; qDebug()<<"Can't find tag Calculation"<< Q_FUNC_INFO;
} }
emit NeedFullParsing();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void AddToCalculation::redo() void AddToCal::redo()
{ {
doc->ChangeActivDraw(nameActivDraw); doc->ChangeActivDraw(nameActivDraw);
doc->setCursor(cursor); doc->setCursor(cursor);
@ -84,13 +85,36 @@ void AddToCalculation::redo()
} }
else else
{ {
qDebug()<<QObject::tr("Can not find the element after which you want to insert.")<< Q_FUNC_INFO; qDebug()<<"Can not find the element after which you want to insert."<< Q_FUNC_INFO;
} }
} }
} }
else else
{ {
qDebug()<<QObject::tr("Can't find tag Calculation")<< Q_FUNC_INFO; qDebug()<<"Can't find tag Calculation"<< Q_FUNC_INFO;
} }
//emit toolhaveChange(); emit UnsavedChange();
}
//--------------------------------------------AddPatternPiece----------------------------------------------------------
int AddPatternPiece::countPP = 0;
AddPatternPiece::AddPatternPiece(const QDomElement &xml, VPattern *doc, QUndoCommand *parent)
: QObject(), QUndoCommand(parent), xml(xml), doc(doc)
{
setText(tr("Add to new pattern piece"));
}
AddPatternPiece::~AddPatternPiece()
{}
void AddPatternPiece::undo()
{
--countPP;
}
void AddPatternPiece::redo()
{
++countPP;
} }

View File

@ -34,18 +34,41 @@
#include <QDomElement> #include <QDomElement>
#include <QUndoCommand> #include <QUndoCommand>
class AddToCalculation : public QUndoCommand class AddToCal : public QObject, public QUndoCommand
{ {
Q_OBJECT
public: public:
AddToCalculation(const QDomElement &xml, VPattern *doc, QUndoCommand *parent = 0); AddToCal(const QDomElement &xml, VPattern *doc, QUndoCommand *parent = 0);
virtual ~AddToCalculation(); virtual ~AddToCal();
virtual void undo(); virtual void undo();
virtual void redo(); virtual void redo();
signals:
void UnsavedChange();
void NeedFullParsing();
private: private:
Q_DISABLE_COPY(AddToCal)
const QDomElement xml; const QDomElement xml;
VPattern *doc; VPattern *doc;
const QString nameActivDraw; const QString nameActivDraw;
quint32 cursor; 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 #endif // VUNDOCOMMANDS_H