diff --git a/src/app/dialogs/app/dialogincrements.cpp b/src/app/dialogs/app/dialogincrements.cpp index ceb1a37e6..07a6c1c1d 100644 --- a/src/app/dialogs/app/dialogincrements.cpp +++ b/src/app/dialogs/app/dialogincrements.cpp @@ -133,7 +133,7 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par connect(ui->toolButtonAdd, &QPushButton::clicked, this, &DialogIncrements::clickedToolButtonAdd); connect(ui->toolButtonRemove, &QPushButton::clicked, this, &DialogIncrements::clickedToolButtonRemove); - connect(this, &DialogIncrements::FullUpdateTree, this->doc, &VPattern::FullUpdateTree); + connect(this, &DialogIncrements::FullUpdateTree, this->doc, &VPattern::LiteParseTree); connect(this, &DialogIncrements::haveLiteChange, this->doc, &VPattern::haveLiteChange); connect(this->doc, &VPattern::FullUpdateFromFile, this, &DialogIncrements::FullUpdateFromFile); diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 66ba94573..df2e10802 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -567,7 +567,7 @@ void MainWindow::ClosedDialogDetail(int result) VToolDetail::Create(dialogTool, sceneDetails, doc, pattern); } ArrowTool(); - doc->FullUpdateTree(); + doc->LiteParseTree(); } //--------------------------------------------------------------------------------------------------------------------- @@ -655,7 +655,7 @@ void MainWindow::ToolUnionDetails(bool checked) void MainWindow::ClosedDialogUnionDetails(int result) { ClosedDialog(result); - doc->FullUpdateTree(); + doc->LiteParseTree(); } //--------------------------------------------------------------------------------------------------------------------- @@ -1366,7 +1366,7 @@ void MainWindow::ChangedSize(const QString & text) { qint32 size = text.toInt(); pattern->SetSize(size); - doc->FullUpdateTree(); + doc->LiteParseTree(); } //--------------------------------------------------------------------------------------------------------------------- @@ -1378,7 +1378,7 @@ void MainWindow::ChangedHeight(const QString &text) { qint32 growth = text.toInt(); pattern->SetHeight(growth); - doc->FullUpdateTree(); + doc->LiteParseTree(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolsinglepoint.cpp b/src/app/tools/drawTools/vtoolsinglepoint.cpp index 2c542cc5d..288f09050 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/app/tools/drawTools/vtoolsinglepoint.cpp @@ -126,7 +126,7 @@ QVariant VToolSinglePoint::itemChange(QGraphicsItem::GraphicsItemChange change, VAbstractTool::NewSceneRect(this->scene(), list[0]); //I don't now why but signal does not work. - doc->FullUpdateTree(); + doc->LiteParseTree(); emit toolhaveChange(); } } diff --git a/src/app/tools/vabstracttool.cpp b/src/app/tools/vabstracttool.cpp index 90a7ebb84..d22654351 100644 --- a/src/app/tools/vabstracttool.cpp +++ b/src/app/tools/vabstracttool.cpp @@ -77,7 +77,7 @@ VAbstractTool::VAbstractTool(VPattern *doc, VContainer *data, quint32 id, QObjec Q_CHECK_PTR(doc); connect(this, &VAbstractTool::toolhaveChange, this->doc, &VPattern::haveLiteChange); connect(this->doc, &VPattern::FullUpdateFromFile, this, &VAbstractTool::FullUpdateFromFile); - connect(this, &VAbstractTool::FullUpdateTree, this->doc, &VPattern::FullUpdateTree); + connect(this, &VAbstractTool::FullUpdateTree, this->doc, &VPattern::LiteParseTree); } //--------------------------------------------------------------------------------------------------------------------- @@ -244,7 +244,7 @@ void VAbstractTool::DeleteTool(QGraphicsItem *tool) { scene->removeItem(tool);//remove form scene } - doc->FullUpdateTree(); + doc->LiteParseTree(); emit toolhaveChange();//set enabled save button } else diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 67bd9edc1..c5f4dec67 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -110,18 +110,21 @@ void VPattern::CreateEmptyFile(const QString &tablePath) void VPattern::ChangeActivDraw(const QString &name, const Document::Documents &parse) { Q_ASSERT_X(name.isEmpty() == false, "ChangeActivDraw", "name draw is empty"); - if (CheckNameDraw(name)) + if (this->nameActivDraw != name) { - this->nameActivDraw = name; - if (parse == Document::FullParse) + if (CheckNameDraw(name)) { - emit ChangedActivDraw(name); + this->nameActivDraw = name; + if (parse == Document::FullParse) + { + emit ChangedActivDraw(name); + } } } } //--------------------------------------------------------------------------------------------------------------------- -bool VPattern::GetActivDrawElement(QDomElement &element) +bool VPattern::GetActivDrawElement(QDomElement &element) const { if (nameActivDraw.isEmpty() == false) { @@ -279,8 +282,11 @@ VDataTool *VPattern::getTool(const quint32 &id) //--------------------------------------------------------------------------------------------------------------------- void VPattern::setCursor(const quint32 &value) { - cursor = value; - emit ChangedCursor(cursor); + if (cursor != value) + { + cursor = value; + emit ChangedCursor(cursor); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -420,7 +426,7 @@ void VPattern::SetActivDraw(const QString &name) } //--------------------------------------------------------------------------------------------------------------------- -bool VPattern::GetActivNodeElement(const QString &name, QDomElement &element) +bool VPattern::GetActivNodeElement(const QString &name, QDomElement &element) const { Q_ASSERT_X(name.isEmpty() == false, "GetActivNodeElement", "name draw is empty"); QDomElement drawElement; @@ -555,7 +561,7 @@ bool VPattern::SaveDocument(const QString &fileName) } //--------------------------------------------------------------------------------------------------------------------- -void VPattern::FullUpdateTree() +void VPattern::LiteParseTree() { VMainGraphicsScene *scene = nullptr; try diff --git a/src/app/xml/vpattern.h b/src/app/xml/vpattern.h index 98699120e..d7e2b3f96 100644 --- a/src/app/xml/vpattern.h +++ b/src/app/xml/vpattern.h @@ -84,7 +84,7 @@ public: * @param element draw tag. * @return true if found. */ - bool GetActivDrawElement(QDomElement &element); + bool GetActivDrawElement(QDomElement &element) const; /** * @brief appendDraw add new pattern peace structure to the file. * @param name pattern peace name. @@ -174,7 +174,7 @@ public: * @param element element. * @return true if found. */ - bool GetActivNodeElement(const QString& name, QDomElement& element); + bool GetActivNodeElement(const QString& name, QDomElement& element) const; QString MPath() const; void SetPath(const QString &path); Valentina::Units MUnit() const; @@ -241,7 +241,7 @@ public slots: /** * @brief FullUpdateTree lite parse file. */ - void FullUpdateTree(); + void LiteParseTree(); /** * @brief haveLiteChange we have unsaved change. */ diff --git a/src/app/xml/vundocommands.cpp b/src/app/xml/vundocommands.cpp new file mode 100644 index 000000000..cc1b9ccb4 --- /dev/null +++ b/src/app/xml/vundocommands.cpp @@ -0,0 +1,96 @@ +/************************************************************************ + ** + ** @file vundocommands.cpp + ** @author Roman Telezhynskyi + ** @date 4 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 + ** 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 . + ** + *************************************************************************/ + +#include "vundocommands.h" +#include + +//--------------------------------------------------------------------------------------------------------------------- +AddToCalculation::AddToCalculation(const QDomElement &xml, VPattern *doc, QUndoCommand *parent) + : QUndoCommand(parent), xml(xml), doc(doc), nameActivDraw(doc->GetNameActivDraw()), cursor(doc->getCursor()) +{ + setText(QObject::tr("Add to section %1").arg(VPattern::TagCalculation)); +} + +//--------------------------------------------------------------------------------------------------------------------- +AddToCalculation::~AddToCalculation() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void AddToCalculation::undo() +{ + doc->ChangeActivDraw(nameActivDraw); + doc->setCursor(cursor); + + QDomElement calcElement; + if (doc->GetActivNodeElement(VPattern::TagCalculation, calcElement)) + { + calcElement.removeChild(xml); + if (cursor > 0) + { + doc->setCursor(0); + } + } + else + { + qDebug()<<"Can't find tag Calculation"<< Q_FUNC_INFO; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void AddToCalculation::redo() +{ + doc->ChangeActivDraw(nameActivDraw); + doc->setCursor(cursor); + + QDomElement calcElement; + if (doc->GetActivNodeElement(VPattern::TagCalculation, calcElement)) + { + if (cursor <= 0) + { + calcElement.appendChild(xml); + } + else + { + QDomElement refElement = doc->elementById(QString().setNum(cursor)); + if (refElement.isElement()) + { + calcElement.insertAfter(xml, refElement); + doc->setCursor(0); + } + else + { + qDebug()< + ** @date 4 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 + ** 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 . + ** + *************************************************************************/ + +#ifndef VUNDOCOMMANDS_H +#define VUNDOCOMMANDS_H + +#include "vpattern.h" + +#include +#include + +class AddToCalculation : public QUndoCommand +{ +public: + AddToCalculation(const QDomElement &xml, VPattern *doc, QUndoCommand *parent = 0); + virtual ~AddToCalculation(); + virtual void undo(); + virtual void redo(); +private: + const QDomElement xml; + VPattern *doc; + const QString nameActivDraw; + quint32 cursor; +}; + +#endif // VUNDOCOMMANDS_H diff --git a/src/app/xml/xml.pri b/src/app/xml/xml.pri index d9b56eea9..274582dca 100644 --- a/src/app/xml/xml.pri +++ b/src/app/xml/xml.pri @@ -3,11 +3,13 @@ HEADERS += \ xml/vdomdocument.h \ xml/vpattern.h \ xml/vstandardmeasurements.h \ - xml/vindividualmeasurements.h + xml/vindividualmeasurements.h \ + xml/vundocommands.h SOURCES += \ xml/vtoolrecord.cpp \ xml/vdomdocument.cpp \ xml/vpattern.cpp \ xml/vstandardmeasurements.cpp \ - xml/vindividualmeasurements.cpp + xml/vindividualmeasurements.cpp \ + xml/vundocommands.cpp