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

View File

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

View File

@ -29,10 +29,9 @@
#include "vdrawtool.h"
#include <qmuparsererror.h>
#include <dialogs/tools/dialogeditwrongformula.h>
#include <container/calculator.h>
#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()<<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();
AddToCal *addToCal = new AddToCal(domElement, doc);
connect(addToCal, &AddToCal::UnsavedChange, doc, &VPattern::haveLiteChange);
connect(addToCal, &AddToCal::NeedFullParsing, doc, &VPattern::NeedFullParsing);
qApp->getUndoStack()->push(addToCal);
}

View File

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

View File

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

View File

@ -30,18 +30,18 @@
#include <QDebug>
//---------------------------------------------------------------------------------------------------------------------
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()<<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
{
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 <QUndoCommand>
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