Fixed issue #4.

--HG--
branch : feature
This commit is contained in:
dismine 2014-06-16 15:14:46 +03:00
parent 814e414b4b
commit 2b000cd59f
15 changed files with 196 additions and 30 deletions

View File

@ -137,7 +137,7 @@ protected:
} }
if (selectedAction == actionRemove) if (selectedAction == actionRemove)
{ {
DeleteTool(tool); DeleteTool();
} }
} }
} }

View File

@ -184,9 +184,8 @@ void VToolSinglePoint::decrementReferens()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSinglePoint::DeleteTool(QGraphicsItem *tool, bool ask) void VToolSinglePoint::DeleteTool(bool ask)
{ {
Q_UNUSED(tool)
if (ask) if (ask)
{ {
QMessageBox msgBox; QMessageBox msgBox;

View File

@ -59,7 +59,7 @@ protected:
virtual void RefreshDataInFile(); virtual void RefreshDataInFile();
QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); QVariant itemChange ( GraphicsItemChange change, const QVariant &value );
virtual void decrementReferens(); virtual void decrementReferens();
virtual void DeleteTool(QGraphicsItem *tool, bool ask = true); virtual void DeleteTool(bool ask = true);
virtual void SaveDialog(QDomElement &domElement); virtual void SaveDialog(QDomElement &domElement);
private: private:
QString namePP; QString namePP;

View File

@ -242,9 +242,8 @@ QPointF VAbstractTool::addVector(const QPointF &p, const QPointF &p1, const QPoi
* @brief DeleteTool full delete object form scene and file. * @brief DeleteTool full delete object form scene and file.
* @param tool tool * @param tool tool
*/ */
void VAbstractTool::DeleteTool(QGraphicsItem *tool, bool ask) void VAbstractTool::DeleteTool(bool ask)
{ {
DelTool *delTool = new DelTool(doc, id, tool);
if (ask) if (ask)
{ {
QMessageBox msgBox; QMessageBox msgBox;
@ -257,9 +256,9 @@ void VAbstractTool::DeleteTool(QGraphicsItem *tool, bool ask)
{ {
return; return;
} }
/*Ugly hack. If UnionDetails delete detail no need emit FullParsing */
connect(delTool, &DelTool::NeedFullParsing, doc, &VPattern::NeedFullParsing);
} }
DelTool *delTool = new DelTool(doc, id);
connect(delTool, &DelTool::NeedFullParsing, doc, &VPattern::NeedFullParsing);
qApp->getUndoStack()->push(delTool); qApp->getUndoStack()->push(delTool);
} }

View File

@ -146,7 +146,7 @@ protected:
* @brief RemoveReferens decrement value of reference. * @brief RemoveReferens decrement value of reference.
*/ */
virtual void RemoveReferens(){} virtual void RemoveReferens(){}
virtual void DeleteTool(QGraphicsItem *tool, bool ask = true); virtual void DeleteTool(bool ask = true);
Qt::PenStyle LineStyle(); Qt::PenStyle LineStyle();
private: private:
Q_DISABLE_COPY(VAbstractTool) Q_DISABLE_COPY(VAbstractTool)

View File

@ -38,9 +38,11 @@
#include <QGraphicsSceneMouseEvent> #include <QGraphicsSceneMouseEvent>
#include <QMenu> #include <QMenu>
#include <QGraphicsView> #include <QGraphicsView>
#include <QMessageBox>
#include "../undocommands/savedetailoptions.h" #include "../undocommands/savedetailoptions.h"
#include "../undocommands/movedetail.h" #include "../undocommands/movedetail.h"
#include "../undocommands/adddet.h" #include "../undocommands/adddet.h"
#include "../undocommands/deletedetail.h"
const QString VToolDetail::TagName = QStringLiteral("detail"); const QString VToolDetail::TagName = QStringLiteral("detail");
const QString VToolDetail::TagNode = QStringLiteral("node"); const QString VToolDetail::TagNode = QStringLiteral("node");
@ -273,7 +275,7 @@ void VToolDetail::Create(const quint32 &_id, const VDetail &newDetail, VMainGrap
*/ */
void VToolDetail::Remove(bool ask) void VToolDetail::Remove(bool ask)
{ {
DeleteTool(this, ask); DeleteTool(ask);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -552,6 +554,27 @@ void VToolDetail::RefreshGeometry()
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
} }
void VToolDetail::DeleteTool(bool ask)
{
DeleteDetail *delDet = new DeleteDetail(doc, id);
if (ask)
{
QMessageBox msgBox;
msgBox.setText(tr("Confirm the deletion."));
msgBox.setInformativeText(tr("Do you really want delete?"));
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setIcon(QMessageBox::Question);
if (msgBox.exec() == QMessageBox::Cancel)
{
return;
}
/*Ugly hack. If UnionDetails delete detail no need emit FullParsing */
connect(delDet, &DeleteDetail::NeedFullParsing, doc, &VPattern::NeedFullParsing);
}
qApp->getUndoStack()->push(delDet);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
template <typename Tool> template <typename Tool>
//cppcheck-suppress unusedFunction //cppcheck-suppress unusedFunction

View File

@ -109,6 +109,7 @@ private:
* @param node node of detail. * @param node node of detail.
*/ */
void InitTool(VMainGraphicsScene *scene, const VNodeDetail &node); void InitTool(VMainGraphicsScene *scene, const VNodeDetail &node);
virtual void DeleteTool(bool ask = true);
}; };
#endif // VTOOLDETAIL_H #endif // VTOOLDETAIL_H

View File

@ -467,7 +467,7 @@ void VToolUnionDetails::UpdatePoints(const quint32 &idDetail, VContainer *data,
* @param angle angle rotation. * @param angle angle rotation.
*/ */
void VToolUnionDetails::BiasRotatePoint(VPointF *point, const qreal &dx, const qreal &dy, const QPointF &pRotate, void VToolUnionDetails::BiasRotatePoint(VPointF *point, const qreal &dx, const qreal &dy, const QPointF &pRotate,
const qreal angle) const qreal &angle)
{ {
point->setX(point->x()+dx); point->setX(point->x()+dx);
point->setY(point->y()+dy); point->setY(point->y()+dy);
@ -496,6 +496,7 @@ void VToolUnionDetails::Create(DialogTool *dialog, VMainGraphicsScene *scene, VP
qApp->getUndoStack()->beginMacro("union details"); qApp->getUndoStack()->beginMacro("union details");
Create(0, d1, d2, dialogTool->getD1(), dialogTool->getD2(), indexD1, indexD2, scene, doc, data, Document::FullParse, Create(0, d1, d2, dialogTool->getD1(), dialogTool->getD2(), indexD1, indexD2, scene, doc, data, Document::FullParse,
Source::FromGui); Source::FromGui);
qApp->getUndoStack()->endMacro();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -650,11 +651,6 @@ void VToolUnionDetails::Create(const quint32 _id, const VDetail &d1, const VDeta
} }
} while (i<d1.RemoveEdge(indexD1).CountNode()); } while (i<d1.RemoveEdge(indexD1).CountNode());
} }
if (typeCreation == Source::FromGui)
{
qApp->getUndoStack()->endMacro();
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -75,7 +75,7 @@ public:
quint32 &idCount, const qreal &dx = 0, const qreal &dy = 0, const quint32 &pRotate = 0, quint32 &idCount, const qreal &dx = 0, const qreal &dy = 0, const quint32 &pRotate = 0,
const qreal &angle = 0); const qreal &angle = 0);
static void BiasRotatePoint(VPointF *point, const qreal &dx, const qreal &dy, const QPointF &pRotate, static void BiasRotatePoint(VPointF *point, const qreal &dx, const qreal &dy, const QPointF &pRotate,
const qreal angle); const qreal &angle);
public slots: public slots:
/** /**
* @brief FullUpdateFromFile update tool data form file. * @brief FullUpdateFromFile update tool data form file.

View File

@ -0,0 +1,83 @@
/************************************************************************
**
** @file deletedetail.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 16 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 "deletedetail.h"
#include "../xml/vpattern.h"
#include "../tools/vtooldetail.h"
//---------------------------------------------------------------------------------------------------------------------
DeleteDetail::DeleteDetail(VPattern *doc, quint32 id, QUndoCommand *parent)
: QObject(), QUndoCommand(parent), xml(QDomElement()), doc(doc), detId(id), parentNode(QDomNode())
{
setText(tr("Delete tool"));
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
xml = domElement.cloneNode().toElement();
parentNode = domElement.parentNode();
}
else
{
qDebug()<<"Can't get detail by id = "<<detId<<Q_FUNC_INFO;
return;
}
}
//---------------------------------------------------------------------------------------------------------------------
DeleteDetail::~DeleteDetail()
{}
//---------------------------------------------------------------------------------------------------------------------
void DeleteDetail::undo()
{
parentNode.appendChild(xml);
emit NeedFullParsing();
}
//---------------------------------------------------------------------------------------------------------------------
void DeleteDetail::redo()
{
QDomElement domElement = doc->elementById(QString().setNum(detId));
if (domElement.isElement())
{
parentNode.removeChild(domElement);
QHash<quint32, VDataTool*>* tools = doc->getTools();
SCASSERT(tools != nullptr);
VToolDetail *toolDet = qobject_cast<VToolDetail*>(tools->value(detId));
SCASSERT(toolDet != nullptr);
toolDet->hide();
emit NeedFullParsing();
}
else
{
qDebug()<<"Can't get detail by id = "<<detId<<Q_FUNC_INFO;
return;
}
}

View File

@ -0,0 +1,56 @@
/************************************************************************
**
** @file deletedetail.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 16 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 DELETEDETAIL_H
#define DELETEDETAIL_H
#include <QDomElement>
#include <QUndoCommand>
class VPattern;
class QGraphicsItem;
class DeleteDetail : public QObject, public QUndoCommand
{
Q_OBJECT
public:
DeleteDetail(VPattern *doc, quint32 id, QUndoCommand *parent = 0);
virtual ~DeleteDetail();
virtual void undo();
virtual void redo();
signals:
void NeedFullParsing();
private:
Q_DISABLE_COPY(DeleteDetail)
QDomElement xml;
VPattern *doc;
quint32 detId;
QDomNode parentNode;
};
#endif // DELETEDETAIL_H

View File

@ -29,11 +29,12 @@
#include "deltool.h" #include "deltool.h"
#include "../xml/vpattern.h" #include "../xml/vpattern.h"
#include <QGraphicsItem> #include <QGraphicsItem>
#include "../tools/vtooldetail.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DelTool::DelTool(VPattern *doc, quint32 id, QGraphicsItem *tool, QUndoCommand *parent) DelTool::DelTool(VPattern *doc, quint32 id, QUndoCommand *parent)
: QObject(), QUndoCommand(parent), xml(QDomElement()), parentNode(QDomNode()), previousNode(QDomNode()), : QObject(), QUndoCommand(parent), xml(QDomElement()), parentNode(QDomNode()), doc(doc), toolId(id),
doc(doc), toolId(id), tool(tool) cursor(doc->getCursor())
{ {
setText(tr("Delete tool")); setText(tr("Delete tool"));
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(QString().setNum(id));
@ -41,7 +42,6 @@ DelTool::DelTool(VPattern *doc, quint32 id, QGraphicsItem *tool, QUndoCommand *p
{ {
xml = domElement.cloneNode().toElement(); xml = domElement.cloneNode().toElement();
parentNode = domElement.parentNode(); parentNode = domElement.parentNode();
previousNode = domElement.previousSibling();
} }
else else
{ {
@ -57,7 +57,18 @@ DelTool::~DelTool()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DelTool::undo() void DelTool::undo()
{ {
parentNode.insertAfter(xml, previousNode); if (cursor <= 0)
{
parentNode.appendChild(xml);
}
else
{
QDomElement refElement = doc->elementById(QString().setNum(cursor));
if (refElement.isElement())
{
parentNode.insertAfter(xml, refElement);
}
}
emit NeedFullParsing(); emit NeedFullParsing();
} }
@ -68,7 +79,6 @@ void DelTool::redo()
if (domElement.isElement()) if (domElement.isElement())
{ {
parentNode.removeChild(domElement); parentNode.removeChild(domElement);
tool->hide();
emit NeedFullParsing(); emit NeedFullParsing();
} }
else else

View File

@ -39,7 +39,7 @@ class DelTool : public QObject, public QUndoCommand
{ {
Q_OBJECT Q_OBJECT
public: public:
DelTool(VPattern *doc, quint32 id, QGraphicsItem *tool, QUndoCommand *parent = 0); DelTool(VPattern *doc, quint32 id, QUndoCommand *parent = 0);
virtual ~DelTool(); virtual ~DelTool();
virtual void undo(); virtual void undo();
virtual void redo(); virtual void redo();
@ -49,10 +49,9 @@ private:
Q_DISABLE_COPY(DelTool) Q_DISABLE_COPY(DelTool)
QDomElement xml; QDomElement xml;
QDomNode parentNode; QDomNode parentNode;
QDomNode previousNode;
VPattern *doc; VPattern *doc;
quint32 toolId; quint32 toolId;
QGraphicsItem *tool; quint32 cursor;
}; };
#endif // DELTOOL_H #endif // DELTOOL_H

View File

@ -68,7 +68,6 @@ void MoveDetail::undo()
{ {
doc->SetAttribute(domElement, VAbstractTool::AttrMx, QString().setNum(qApp->fromPixel(oldX))); doc->SetAttribute(domElement, VAbstractTool::AttrMx, QString().setNum(qApp->fromPixel(oldX)));
doc->SetAttribute(domElement, VAbstractTool::AttrMy, QString().setNum(qApp->fromPixel(oldY))); doc->SetAttribute(domElement, VAbstractTool::AttrMy, QString().setNum(qApp->fromPixel(oldY)));
qDebug()<<"undo move detail"<<oldX<<oldY;
emit NeedLiteParsing(); emit NeedLiteParsing();
@ -90,7 +89,6 @@ void MoveDetail::redo()
{ {
doc->SetAttribute(domElement, VAbstractTool::AttrMx, QString().setNum(qApp->fromPixel(newX))); doc->SetAttribute(domElement, VAbstractTool::AttrMx, QString().setNum(qApp->fromPixel(newX)));
doc->SetAttribute(domElement, VAbstractTool::AttrMy, QString().setNum(qApp->fromPixel(newY))); doc->SetAttribute(domElement, VAbstractTool::AttrMy, QString().setNum(qApp->fromPixel(newY)));
qDebug()<<"redo move detail"<<newX<<newY;
if (redoFlag) if (redoFlag)
{ {

View File

@ -12,7 +12,8 @@ HEADERS += \
undocommands/deletepatternpiece.h \ undocommands/deletepatternpiece.h \
undocommands/adddetnode.h \ undocommands/adddetnode.h \
undocommands/adddet.h \ undocommands/adddet.h \
undocommands/adduniondetails.h undocommands/adduniondetails.h \
undocommands/deletedetail.h
SOURCES += \ SOURCES += \
@ -28,5 +29,6 @@ SOURCES += \
undocommands/deletepatternpiece.cpp \ undocommands/deletepatternpiece.cpp \
undocommands/adddetnode.cpp \ undocommands/adddetnode.cpp \
undocommands/adddet.cpp \ undocommands/adddet.cpp \
undocommands/adduniondetails.cpp undocommands/adduniondetails.cpp \
undocommands/deletedetail.cpp