New undo command AddToCalculation.

--HG--
branch : feature
This commit is contained in:
dismine 2014-06-05 12:52:00 +03:00
parent 36949b8f45
commit 55a7ba99a4
9 changed files with 177 additions and 22 deletions

View File

@ -133,7 +133,7 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par
connect(ui->toolButtonAdd, &QPushButton::clicked, this, &DialogIncrements::clickedToolButtonAdd); connect(ui->toolButtonAdd, &QPushButton::clicked, this, &DialogIncrements::clickedToolButtonAdd);
connect(ui->toolButtonRemove, &QPushButton::clicked, this, &DialogIncrements::clickedToolButtonRemove); 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, &DialogIncrements::haveLiteChange, this->doc, &VPattern::haveLiteChange);
connect(this->doc, &VPattern::FullUpdateFromFile, this, &DialogIncrements::FullUpdateFromFile); connect(this->doc, &VPattern::FullUpdateFromFile, this, &DialogIncrements::FullUpdateFromFile);

View File

@ -567,7 +567,7 @@ void MainWindow::ClosedDialogDetail(int result)
VToolDetail::Create(dialogTool, sceneDetails, doc, pattern); VToolDetail::Create(dialogTool, sceneDetails, doc, pattern);
} }
ArrowTool(); ArrowTool();
doc->FullUpdateTree(); doc->LiteParseTree();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -655,7 +655,7 @@ void MainWindow::ToolUnionDetails(bool checked)
void MainWindow::ClosedDialogUnionDetails(int result) void MainWindow::ClosedDialogUnionDetails(int result)
{ {
ClosedDialog<VToolUnionDetails>(result); ClosedDialog<VToolUnionDetails>(result);
doc->FullUpdateTree(); doc->LiteParseTree();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1366,7 +1366,7 @@ void MainWindow::ChangedSize(const QString & text)
{ {
qint32 size = text.toInt(); qint32 size = text.toInt();
pattern->SetSize(size); pattern->SetSize(size);
doc->FullUpdateTree(); doc->LiteParseTree();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1378,7 +1378,7 @@ void MainWindow::ChangedHeight(const QString &text)
{ {
qint32 growth = text.toInt(); qint32 growth = text.toInt();
pattern->SetHeight(growth); pattern->SetHeight(growth);
doc->FullUpdateTree(); doc->LiteParseTree();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -126,7 +126,7 @@ QVariant VToolSinglePoint::itemChange(QGraphicsItem::GraphicsItemChange change,
VAbstractTool::NewSceneRect(this->scene(), list[0]); VAbstractTool::NewSceneRect(this->scene(), list[0]);
//I don't now why but signal does not work. //I don't now why but signal does not work.
doc->FullUpdateTree(); doc->LiteParseTree();
emit toolhaveChange(); emit toolhaveChange();
} }
} }

View File

@ -77,7 +77,7 @@ VAbstractTool::VAbstractTool(VPattern *doc, VContainer *data, quint32 id, QObjec
Q_CHECK_PTR(doc); Q_CHECK_PTR(doc);
connect(this, &VAbstractTool::toolhaveChange, this->doc, &VPattern::haveLiteChange); connect(this, &VAbstractTool::toolhaveChange, this->doc, &VPattern::haveLiteChange);
connect(this->doc, &VPattern::FullUpdateFromFile, this, &VAbstractTool::FullUpdateFromFile); 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 scene->removeItem(tool);//remove form scene
} }
doc->FullUpdateTree(); doc->LiteParseTree();
emit toolhaveChange();//set enabled save button emit toolhaveChange();//set enabled save button
} }
else else

View File

@ -110,18 +110,21 @@ void VPattern::CreateEmptyFile(const QString &tablePath)
void VPattern::ChangeActivDraw(const QString &name, const Document::Documents &parse) void VPattern::ChangeActivDraw(const QString &name, const Document::Documents &parse)
{ {
Q_ASSERT_X(name.isEmpty() == false, "ChangeActivDraw", "name draw is empty"); Q_ASSERT_X(name.isEmpty() == false, "ChangeActivDraw", "name draw is empty");
if (CheckNameDraw(name)) if (this->nameActivDraw != name)
{ {
this->nameActivDraw = name; if (CheckNameDraw(name))
if (parse == Document::FullParse)
{ {
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) if (nameActivDraw.isEmpty() == false)
{ {
@ -279,8 +282,11 @@ VDataTool *VPattern::getTool(const quint32 &id)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPattern::setCursor(const quint32 &value) void VPattern::setCursor(const quint32 &value)
{ {
cursor = value; if (cursor != value)
emit ChangedCursor(cursor); {
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"); Q_ASSERT_X(name.isEmpty() == false, "GetActivNodeElement", "name draw is empty");
QDomElement drawElement; QDomElement drawElement;
@ -555,7 +561,7 @@ bool VPattern::SaveDocument(const QString &fileName)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPattern::FullUpdateTree() void VPattern::LiteParseTree()
{ {
VMainGraphicsScene *scene = nullptr; VMainGraphicsScene *scene = nullptr;
try try

View File

@ -84,7 +84,7 @@ public:
* @param element draw tag. * @param element draw tag.
* @return true if found. * @return true if found.
*/ */
bool GetActivDrawElement(QDomElement &element); bool GetActivDrawElement(QDomElement &element) const;
/** /**
* @brief appendDraw add new pattern peace structure to the file. * @brief appendDraw add new pattern peace structure to the file.
* @param name pattern peace name. * @param name pattern peace name.
@ -174,7 +174,7 @@ public:
* @param element element. * @param element element.
* @return true if found. * @return true if found.
*/ */
bool GetActivNodeElement(const QString& name, QDomElement& element); bool GetActivNodeElement(const QString& name, QDomElement& element) const;
QString MPath() const; QString MPath() const;
void SetPath(const QString &path); void SetPath(const QString &path);
Valentina::Units MUnit() const; Valentina::Units MUnit() const;
@ -241,7 +241,7 @@ public slots:
/** /**
* @brief FullUpdateTree lite parse file. * @brief FullUpdateTree lite parse file.
*/ */
void FullUpdateTree(); void LiteParseTree();
/** /**
* @brief haveLiteChange we have unsaved change. * @brief haveLiteChange we have unsaved change.
*/ */

View File

@ -0,0 +1,96 @@
/************************************************************************
**
** @file vundocommands.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "vundocommands.h"
#include <QDebug>
//---------------------------------------------------------------------------------------------------------------------
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()<<QObject::tr("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;
}
//emit toolhaveChange();
}

View File

@ -0,0 +1,51 @@
/************************************************************************
**
** @file vundocommands.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef VUNDOCOMMANDS_H
#define VUNDOCOMMANDS_H
#include "vpattern.h"
#include <QDomElement>
#include <QUndoCommand>
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

View File

@ -3,11 +3,13 @@ HEADERS += \
xml/vdomdocument.h \ xml/vdomdocument.h \
xml/vpattern.h \ xml/vpattern.h \
xml/vstandardmeasurements.h \ xml/vstandardmeasurements.h \
xml/vindividualmeasurements.h xml/vindividualmeasurements.h \
xml/vundocommands.h
SOURCES += \ SOURCES += \
xml/vtoolrecord.cpp \ xml/vtoolrecord.cpp \
xml/vdomdocument.cpp \ xml/vdomdocument.cpp \
xml/vpattern.cpp \ xml/vpattern.cpp \
xml/vstandardmeasurements.cpp \ xml/vstandardmeasurements.cpp \
xml/vindividualmeasurements.cpp xml/vindividualmeasurements.cpp \
xml/vundocommands.cpp