Returned undocommand "Save piece options".
--HG-- branch : feature
This commit is contained in:
parent
8601b2ae2a
commit
988ce8f7f2
|
@ -244,6 +244,57 @@ void VPiece::SetMy(qreal value)
|
|||
d->m_my = value;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief Missing find missing nodes in detail. When we deleted object in detail and return this detail need
|
||||
* understand, what nodes need make invisible.
|
||||
* @param det changed detail.
|
||||
* @return list with missing nodes.
|
||||
*/
|
||||
QVector<VPieceNode> VPiece::Missing(const VPiece &det) const
|
||||
{
|
||||
if (d->m_nodes.size() == det.CountNodes()) //-V807
|
||||
{
|
||||
return QVector<VPieceNode>();
|
||||
}
|
||||
|
||||
QSet<quint32> set1;
|
||||
for (qint32 i = 0; i < d->m_nodes.size(); ++i)
|
||||
{
|
||||
set1.insert(d->m_nodes.at(i).GetId());
|
||||
}
|
||||
|
||||
QSet<quint32> set2;
|
||||
for (qint32 j = 0; j < det.CountNodes(); ++j)
|
||||
{
|
||||
set2.insert(det.at(j).GetId());
|
||||
}
|
||||
|
||||
const QList<quint32> set3 = set1.subtract(set2).toList();
|
||||
QVector<VPieceNode> nodes;
|
||||
for (qint32 i = 0; i < set3.size(); ++i)
|
||||
{
|
||||
const int index = indexOfNode(d->m_nodes, set3.at(i));
|
||||
if (index != -1)
|
||||
{
|
||||
nodes.append(d->m_nodes.at(index));
|
||||
}
|
||||
}
|
||||
|
||||
return nodes;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief indexOfNode return index in list node using id object.
|
||||
* @param id object (arc, point, spline, splinePath) id.
|
||||
* @return index in list or -1 id can't find.
|
||||
*/
|
||||
int VPiece::indexOfNode(const quint32 &id) const
|
||||
{
|
||||
return indexOfNode(d->m_nodes, id);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QPointF VPiece::StartSegment(const VContainer *data, const int &i, bool reverse) const
|
||||
{
|
||||
|
@ -317,3 +368,23 @@ QPointF VPiece::EndSegment(const VContainer *data, const int &i, bool reverse) c
|
|||
}
|
||||
return end;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief indexOfNode return index in list node using id object.
|
||||
* @param list list nodes detail.
|
||||
* @param id object (arc, point, spline, splinePath) id.
|
||||
* @return index in list or -1 id can't find.
|
||||
*/
|
||||
int VPiece::indexOfNode(const QVector<VPieceNode> &list, quint32 id)
|
||||
{
|
||||
for (int i = 0; i < list.size(); ++i)
|
||||
{
|
||||
if (list.at(i).GetId() == id)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
qDebug()<<"Can't find node.";
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -71,11 +71,17 @@ public:
|
|||
qreal GetMy() const;
|
||||
void SetMy(qreal value);
|
||||
|
||||
QVector<VPieceNode> Missing(const VPiece &det) const;
|
||||
|
||||
int indexOfNode(const quint32 &id) const;
|
||||
|
||||
private:
|
||||
QSharedDataPointer<VPieceData> d;
|
||||
|
||||
QPointF StartSegment(const VContainer *data, const int &i, bool reverse) const;
|
||||
QPointF EndSegment(const VContainer *data, const int &i, bool reverse) const;
|
||||
|
||||
static int indexOfNode(const QVector<VPieceNode> &list, quint32 id);
|
||||
};
|
||||
|
||||
Q_DECLARE_TYPEINFO(VPiece, Q_MOVABLE_TYPE);
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
#include "../undocommands/addpiece.h"
|
||||
#include "../undocommands/deletepiece.h"
|
||||
#include "../undocommands/movepiece.h"
|
||||
//#include "../undocommands/savepieceoptions.h"
|
||||
#include "../undocommands/savepieceoptions.h"
|
||||
//#include "../undocommands/togglepieceinlayout.h"
|
||||
#include "../vwidgets/vmaingraphicsview.h"
|
||||
|
||||
|
@ -241,6 +241,35 @@ void VToolSeamAllowance::AddNodes(VAbstractPattern *doc, QDomElement &domElement
|
|||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VToolSeamAllowance::AddAttributes(VAbstractPattern *doc, QDomElement &domElement, quint32 id, const VPiece &piece)
|
||||
{
|
||||
SCASSERT(doc != nullptr);
|
||||
|
||||
doc->SetAttribute(domElement, VDomDocument::AttrId, id);
|
||||
doc->SetAttribute(domElement, AttrVersion, QString().setNum(pieceVersion));
|
||||
doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(piece.GetMx()));
|
||||
doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(piece.GetMy()));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VToolSeamAllowance::AddPatternPieceData(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VToolSeamAllowance::AddPatternInfo(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VToolSeamAllowance::AddGrainline(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString VToolSeamAllowance::getTagName() const
|
||||
{
|
||||
|
@ -268,7 +297,21 @@ void VToolSeamAllowance::FullUpdateFromFile()
|
|||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VToolSeamAllowance::FullUpdateFromGuiOk(int result)
|
||||
{}
|
||||
{
|
||||
if (result == QDialog::Accepted)
|
||||
{
|
||||
SCASSERT(not m_dialog.isNull());
|
||||
DialogSeamAllowance *dialogTool = qobject_cast<DialogSeamAllowance*>(m_dialog.data());
|
||||
SCASSERT(dialogTool != nullptr);
|
||||
const VPiece newDet = dialogTool->GetPiece();
|
||||
const VPiece oldDet = VAbstractTool::data.GetPiece(id);
|
||||
|
||||
SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, id, this->scene());
|
||||
connect(saveCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
||||
qApp->getUndoStack()->push(saveCommand);
|
||||
}
|
||||
delete m_dialog;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VToolSeamAllowance::EnableToolMove(bool move)
|
||||
|
@ -301,10 +344,10 @@ void VToolSeamAllowance::AddToFile()
|
|||
|
||||
QDomElement domElement = doc->createElement(getTagName());
|
||||
|
||||
doc->SetAttribute(domElement, VDomDocument::AttrId, id);
|
||||
doc->SetAttribute(domElement, AttrVersion, QString().setNum(pieceVersion));
|
||||
doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(piece.GetMx()));
|
||||
doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(piece.GetMy()));
|
||||
AddAttributes(doc, domElement, id, piece);
|
||||
AddPatternPieceData(doc, domElement, piece);
|
||||
AddPatternInfo(doc, domElement, piece);
|
||||
AddGrainline(doc, domElement, piece);
|
||||
|
||||
// nodes
|
||||
AddNodes(doc, domElement, piece);
|
||||
|
@ -490,7 +533,7 @@ void VToolSeamAllowance::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
|||
dialog->EnableApply(true);
|
||||
m_dialog = dialog;
|
||||
m_dialog->setModal(true);
|
||||
connect(m_dialog, &DialogTool::DialogClosed, this, &VToolSeamAllowance::FullUpdateFromGuiOk);
|
||||
connect(m_dialog.data(), &DialogTool::DialogClosed, this, &VToolSeamAllowance::FullUpdateFromGuiOk);
|
||||
SetDialog();
|
||||
m_dialog->show();
|
||||
}
|
||||
|
@ -542,7 +585,7 @@ void VToolSeamAllowance::keyReleaseEvent(QKeyEvent *event)
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VToolSeamAllowance::SetDialog()
|
||||
{
|
||||
SCASSERT(m_dialog != nullptr);
|
||||
SCASSERT(not m_dialog.isNull());
|
||||
DialogSeamAllowance *dialogTool = qobject_cast<DialogSeamAllowance*>(m_dialog);
|
||||
SCASSERT(dialogTool != nullptr);
|
||||
dialogTool->SetPiece(VAbstractTool::data.GetPiece(id));
|
||||
|
@ -555,7 +598,7 @@ VToolSeamAllowance::VToolSeamAllowance(VAbstractPattern *doc, VContainer *data,
|
|||
const QString &drawName, QGraphicsItem *parent)
|
||||
: VAbstractTool(doc, data, id),
|
||||
VNoBrushScalePathItem(parent),
|
||||
m_dialog(nullptr),
|
||||
m_dialog(),
|
||||
m_sceneDetails(scene),
|
||||
m_drawName(drawName)
|
||||
{
|
||||
|
|
|
@ -69,6 +69,10 @@ public:
|
|||
|
||||
static void AddNode(VAbstractPattern *doc, QDomElement &domElement, const VPieceNode &node);
|
||||
static void AddNodes(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece);
|
||||
static void AddAttributes(VAbstractPattern *doc, QDomElement &domElement, quint32 id, const VPiece &piece);
|
||||
static void AddPatternPieceData(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece);
|
||||
static void AddPatternInfo(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece);
|
||||
static void AddGrainline(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece);
|
||||
|
||||
virtual int type() const Q_DECL_OVERRIDE {return Type;}
|
||||
enum { Type = UserType + static_cast<int>(Tool::Piece)};
|
||||
|
@ -101,7 +105,7 @@ private:
|
|||
Q_DISABLE_COPY(VToolSeamAllowance)
|
||||
|
||||
/** @brief dialog dialog options. */
|
||||
DialogTool *m_dialog;
|
||||
QPointer<DialogTool> m_dialog;
|
||||
|
||||
/** @brief sceneDetails pointer to the scene. */
|
||||
VMainGraphicsScene *m_sceneDetails;
|
||||
|
|
136
src/libs/vtools/undocommands/savepieceoptions.cpp
Normal file
136
src/libs/vtools/undocommands/savepieceoptions.cpp
Normal file
|
@ -0,0 +1,136 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 9 11, 2016
|
||||
**
|
||||
** @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) 2016 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 "savepieceoptions.h"
|
||||
|
||||
#include <QDomElement>
|
||||
#include <QPointF>
|
||||
#include <QUndoCommand>
|
||||
#include <QDebug>
|
||||
|
||||
#include "../ifc/xml/vabstractpattern.h"
|
||||
#include "../ifc/ifcdef.h"
|
||||
#include "../vmisc/logging.h"
|
||||
#include "../vmisc/def.h"
|
||||
#include "../vpatterndb/vpiecenode.h"
|
||||
#include "../vpatterndb/vpatterninfogeometry.h"
|
||||
#include "../vpatterndb/vpatternpiecedata.h"
|
||||
#include "../vpatterndb/vgrainlinegeometry.h"
|
||||
#include "../tools/vtoolseamallowance.h"
|
||||
#include "vundocommand.h"
|
||||
|
||||
class QDomElement;
|
||||
class QUndoCommand;
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
SavePieceOptions::SavePieceOptions(const VPiece &oldDet, const VPiece &newDet, VAbstractPattern *doc, quint32 id,
|
||||
QGraphicsScene *scene, QUndoCommand *parent)
|
||||
: VUndoCommand(QDomElement(), doc, parent),
|
||||
m_oldDet(oldDet),
|
||||
m_newDet(newDet),
|
||||
m_scene(scene)
|
||||
{
|
||||
setText(tr("save detail option"));
|
||||
nodeId = id;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
SavePieceOptions::~SavePieceOptions()
|
||||
{}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void SavePieceOptions::undo()
|
||||
{
|
||||
qCDebug(vUndo, "Undo.");
|
||||
|
||||
QDomElement domElement = doc->elementById(nodeId);
|
||||
if (domElement.isElement())
|
||||
{
|
||||
VToolSeamAllowance::AddAttributes(doc, domElement, nodeId, m_oldDet);
|
||||
doc->RemoveAllChildren(domElement);//Very important to clear before rewrite
|
||||
VToolSeamAllowance::AddPatternPieceData(doc, domElement, m_oldDet);
|
||||
VToolSeamAllowance::AddPatternInfo(doc, domElement, m_oldDet);
|
||||
VToolSeamAllowance::AddGrainline(doc, domElement, m_oldDet);
|
||||
VToolSeamAllowance::AddNodes(doc, domElement, m_oldDet);
|
||||
|
||||
IncrementReferences(m_oldDet.Missing(m_newDet));
|
||||
emit NeedLiteParsing(Document::LiteParse);
|
||||
}
|
||||
else
|
||||
{
|
||||
qCDebug(vUndo, "Can't find detail with id = %u.", nodeId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void SavePieceOptions::redo()
|
||||
{
|
||||
qCDebug(vUndo, "Redo.");
|
||||
|
||||
QDomElement domElement = doc->elementById(nodeId);
|
||||
if (domElement.isElement())
|
||||
{
|
||||
VToolSeamAllowance::AddAttributes(doc, domElement, nodeId, m_newDet);
|
||||
doc->RemoveAllChildren(domElement);//Very important to clear before rewrite
|
||||
VToolSeamAllowance::AddPatternPieceData(doc, domElement, m_newDet);
|
||||
VToolSeamAllowance::AddPatternInfo(doc, domElement, m_newDet);
|
||||
VToolSeamAllowance::AddGrainline(doc, domElement, m_newDet);
|
||||
VToolSeamAllowance::AddNodes(doc, domElement, m_newDet);
|
||||
|
||||
DecrementReferences(m_oldDet.Missing(m_newDet));
|
||||
emit NeedLiteParsing(Document::LiteParse);
|
||||
}
|
||||
else
|
||||
{
|
||||
qCDebug(vUndo, "Can't find detail with id = %u.", nodeId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool SavePieceOptions::mergeWith(const QUndoCommand *command)
|
||||
{
|
||||
const SavePieceOptions *saveCommand = static_cast<const SavePieceOptions *>(command);
|
||||
SCASSERT(saveCommand != nullptr);
|
||||
const quint32 id = saveCommand->DetId();
|
||||
|
||||
if (id != nodeId)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_newDet = saveCommand->NewDet();
|
||||
return true;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
int SavePieceOptions::id() const
|
||||
{
|
||||
return static_cast<int>(UndoCommand::SavePieceOptions);
|
||||
}
|
75
src/libs/vtools/undocommands/savepieceoptions.h
Normal file
75
src/libs/vtools/undocommands/savepieceoptions.h
Normal file
|
@ -0,0 +1,75 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 9 11, 2016
|
||||
**
|
||||
** @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) 2016 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 SAVEPIECEOPTIONS_H
|
||||
#define SAVEPIECEOPTIONS_H
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#include "vpiece.h"
|
||||
#include "vundocommand.h"
|
||||
|
||||
class QDomElement;
|
||||
class QGraphicsScene;
|
||||
class QUndoCommand;
|
||||
class VAbstractPattern;
|
||||
|
||||
class SavePieceOptions : public VUndoCommand
|
||||
{
|
||||
public:
|
||||
SavePieceOptions(const VPiece &m_oldDet, const VPiece &m_newDet, VAbstractPattern *doc, quint32 id,
|
||||
QGraphicsScene *m_scene, QUndoCommand *parent = nullptr);
|
||||
virtual ~SavePieceOptions();
|
||||
|
||||
virtual void undo() Q_DECL_OVERRIDE;
|
||||
virtual void redo() Q_DECL_OVERRIDE;
|
||||
virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE;
|
||||
virtual int id() const Q_DECL_OVERRIDE;
|
||||
quint32 DetId() const;
|
||||
VPiece NewDet() const;
|
||||
private:
|
||||
Q_DISABLE_COPY(SavePieceOptions)
|
||||
|
||||
const VPiece m_oldDet;
|
||||
VPiece m_newDet;
|
||||
QGraphicsScene *m_scene;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
inline quint32 SavePieceOptions::DetId() const
|
||||
{
|
||||
return nodeId;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
inline VPiece SavePieceOptions::NewDet() const
|
||||
{
|
||||
return m_newDet;
|
||||
}
|
||||
|
||||
#endif // SAVEPIECEOPTIONS_H
|
|
@ -25,7 +25,8 @@ HEADERS += \
|
|||
$$PWD/label/operationmovelabel.h \
|
||||
$$PWD/addpiece.h \
|
||||
$$PWD/deletepiece.h \
|
||||
$$PWD/movepiece.h
|
||||
$$PWD/movepiece.h \
|
||||
$$PWD/savepieceoptions.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/addtocalc.cpp \
|
||||
|
@ -51,4 +52,5 @@ SOURCES += \
|
|||
$$PWD/label/operationmovelabel.cpp \
|
||||
$$PWD/addpiece.cpp \
|
||||
$$PWD/deletepiece.cpp \
|
||||
$$PWD/movepiece.cpp
|
||||
$$PWD/movepiece.cpp \
|
||||
$$PWD/savepieceoptions.cpp
|
||||
|
|
|
@ -94,6 +94,15 @@ void VUndoCommand::DecrementReferences(const QVector<VNodeDetail> &nodes) const
|
|||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VUndoCommand::IncrementReferences(const QVector<VPieceNode> &nodes) const
|
||||
{
|
||||
for (qint32 i = 0; i < nodes.size(); ++i)
|
||||
{
|
||||
doc->IncrementReferens(nodes.at(i).GetId());
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VUndoCommand::DecrementReferences(const QVector<VPieceNode> &nodes) const
|
||||
{
|
||||
|
|
|
@ -54,6 +54,7 @@ enum class UndoCommand: char { AddPatternPiece,
|
|||
MoveSPoint,
|
||||
SaveToolOptions,
|
||||
SaveDetailOptions,
|
||||
SavePieceOptions,
|
||||
MovePiece,
|
||||
DeleteTool,
|
||||
DeletePatternPiece,
|
||||
|
@ -88,6 +89,7 @@ protected:
|
|||
|
||||
void IncrementReferences(const QVector<VNodeDetail> &nodes) const;
|
||||
void DecrementReferences(const QVector<VNodeDetail> &nodes) const;
|
||||
void IncrementReferences(const QVector<VPieceNode> &nodes) const;
|
||||
void DecrementReferences(const QVector<VPieceNode> &nodes) const;
|
||||
private:
|
||||
Q_DISABLE_COPY(VUndoCommand)
|
||||
|
|
Loading…
Reference in New Issue
Block a user