New undo command DeletePatternPiece.
--HG-- branch : feature
This commit is contained in:
parent
a31157f88c
commit
d66a4b98fe
|
@ -154,7 +154,7 @@ void VAbstractSpline::keyReleaseEvent(QKeyEvent *event)
|
|||
switch (event->key())
|
||||
{
|
||||
case Qt::Key_Delete:
|
||||
DeleteTool(this);
|
||||
DeleteTool();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -134,7 +134,7 @@ protected:
|
|||
{
|
||||
if (selectedAction == actionRemove)
|
||||
{
|
||||
DeleteTool(tool);
|
||||
DeleteTool();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -349,7 +349,7 @@ void VToolArc::keyReleaseEvent(QKeyEvent *event)
|
|||
switch (event->key())
|
||||
{
|
||||
case Qt::Key_Delete:
|
||||
DeleteTool(this);
|
||||
DeleteTool();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -315,7 +315,7 @@ void VToolLine::keyReleaseEvent(QKeyEvent *event)
|
|||
switch (event->key())
|
||||
{
|
||||
case Qt::Key_Delete:
|
||||
DeleteTool(this);
|
||||
DeleteTool();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -279,7 +279,7 @@ void VToolPoint::keyReleaseEvent(QKeyEvent *event)
|
|||
switch (event->key())
|
||||
{
|
||||
case Qt::Key_Delete:
|
||||
DeleteTool(this);
|
||||
DeleteTool();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "../../widgets/vgraphicssimpletextitem.h"
|
||||
#include "../../undocommands/movespoint.h"
|
||||
#include "../../undocommands/addpatternpiece.h"
|
||||
#include "../../undocommands/deletepatternpiece.h"
|
||||
#include "../../geometry/vpointf.h"
|
||||
|
||||
const QString VToolSinglePoint::ToolType = QStringLiteral("single");
|
||||
|
@ -181,6 +182,15 @@ void VToolSinglePoint::decrementReferens()
|
|||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VToolSinglePoint::DeleteTool()
|
||||
{
|
||||
DeletePatternPiece *deletePP = new DeletePatternPiece(doc, namePP);
|
||||
connect(deletePP, &DeletePatternPiece::ClearScene, doc, &VPattern::ClearScene);
|
||||
connect(deletePP, &DeletePatternPiece::NeedFullParsing, doc, &VPattern::NeedFullParsing);
|
||||
qApp->getUndoStack()->push(deletePP);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief SaveDialog save options into file after change in dialog.
|
||||
|
@ -215,7 +225,7 @@ void VToolSinglePoint::setColorLabel(const Qt::GlobalColor &color)
|
|||
*/
|
||||
void VToolSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event )
|
||||
{
|
||||
ContextMenu<DialogSinglePoint>(this, event, false);
|
||||
ContextMenu<DialogSinglePoint>(this, event);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -64,7 +64,7 @@ protected:
|
|||
* @brief DeleteTool delete tool from file and scene. This tool can't be deleted by now.
|
||||
* @param tool tool what me delete.
|
||||
*/
|
||||
virtual void DeleteTool(QGraphicsItem *tool){Q_UNUSED(tool)}
|
||||
virtual void DeleteTool();
|
||||
virtual void SaveDialog(QDomElement &domElement);
|
||||
private:
|
||||
QString namePP;
|
||||
|
|
|
@ -242,7 +242,7 @@ QPointF VAbstractTool::addVector(const QPointF &p, const QPointF &p1, const QPoi
|
|||
* @brief DeleteTool full delete object form scene and file.
|
||||
* @param tool tool
|
||||
*/
|
||||
void VAbstractTool::DeleteTool(QGraphicsItem *tool)
|
||||
void VAbstractTool::DeleteTool()
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(tr("Confirm the deletion."));
|
||||
|
|
|
@ -145,7 +145,7 @@ protected:
|
|||
* @brief RemoveReferens decrement value of reference.
|
||||
*/
|
||||
virtual void RemoveReferens(){}
|
||||
virtual void DeleteTool(QGraphicsItem *tool);
|
||||
virtual void DeleteTool();
|
||||
Qt::PenStyle LineStyle();
|
||||
private:
|
||||
Q_DISABLE_COPY(VAbstractTool)
|
||||
|
|
|
@ -266,7 +266,7 @@ void VToolDetail::Create(const quint32 &_id, const VDetail &newDetail, VMainGrap
|
|||
*/
|
||||
void VToolDetail::Remove()
|
||||
{
|
||||
DeleteTool(this);
|
||||
DeleteTool();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -399,7 +399,7 @@ void VToolDetail::keyReleaseEvent(QKeyEvent *event)
|
|||
switch (event->key())
|
||||
{
|
||||
case Qt::Key_Delete:
|
||||
DeleteTool(this);
|
||||
DeleteTool();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -453,7 +453,7 @@ void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
|||
}
|
||||
if (selectedAction == actionRemove)
|
||||
{
|
||||
DeleteTool(this);
|
||||
DeleteTool();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,8 +29,6 @@
|
|||
#include "addpatternpiece.h"
|
||||
#include "../xml/vpattern.h"
|
||||
|
||||
int AddPatternPiece::countPP = 0;
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
AddPatternPiece::AddPatternPiece(const QDomElement &xml, VPattern *doc, const QString &namePP, const QString &mPath,
|
||||
QUndoCommand *parent)
|
||||
|
@ -46,7 +44,7 @@ AddPatternPiece::~AddPatternPiece()
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void AddPatternPiece::undo()
|
||||
{
|
||||
if (countPP <= 1)
|
||||
if (CountPP() <= 1)
|
||||
{
|
||||
emit ClearScene();
|
||||
}
|
||||
|
@ -57,14 +55,12 @@ void AddPatternPiece::undo()
|
|||
rootElement.removeChild(patternPiece);
|
||||
emit NeedFullParsing();
|
||||
}
|
||||
--countPP;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void AddPatternPiece::redo()
|
||||
{
|
||||
++countPP;
|
||||
if (countPP == 1 && mPath.isEmpty() == false)
|
||||
if (CountPP() == 0 && mPath.isEmpty() == false)
|
||||
{
|
||||
doc->CreateEmptyFile(mPath);
|
||||
}
|
||||
|
@ -72,7 +68,6 @@ void AddPatternPiece::redo()
|
|||
QDomElement rootElement = doc->documentElement();
|
||||
|
||||
rootElement.appendChild(xml);
|
||||
doc->haveLiteChange();
|
||||
|
||||
if (redoFlag)
|
||||
{
|
||||
|
@ -80,3 +75,16 @@ void AddPatternPiece::redo()
|
|||
}
|
||||
redoFlag = true;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
int AddPatternPiece::CountPP()
|
||||
{
|
||||
QDomElement rootElement = doc->documentElement();
|
||||
if (rootElement.isNull())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const QDomNodeList elements = rootElement.elementsByTagName( VPattern::TagDraw );
|
||||
return elements.count();
|
||||
}
|
||||
|
|
|
@ -50,10 +50,10 @@ private:
|
|||
Q_DISABLE_COPY(AddPatternPiece)
|
||||
const QDomElement xml;
|
||||
VPattern *doc;
|
||||
static int countPP;
|
||||
QString namePP;
|
||||
bool redoFlag;
|
||||
QString mPath;
|
||||
int CountPP();
|
||||
};
|
||||
|
||||
#endif // ADDPATTERNPIECE_H
|
||||
|
|
91
src/app/undocommands/deletepatternpiece.cpp
Normal file
91
src/app/undocommands/deletepatternpiece.cpp
Normal file
|
@ -0,0 +1,91 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file deletepatternpiece.cpp
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 14 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 "deletepatternpiece.h"
|
||||
#include "../xml/vpattern.h"
|
||||
#include "addpatternpiece.h"
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
DeletePatternPiece::DeletePatternPiece(VPattern *doc, const QString &namePP, QUndoCommand *parent)
|
||||
: QObject(), QUndoCommand(parent), doc(doc), namePP(namePP), patternPiece(QDomElement()), mPath(QString()),
|
||||
previousNode(QDomNode())
|
||||
{
|
||||
setText(tr("Delete pattern piece %1").arg(namePP));
|
||||
|
||||
QDomElement patternP= doc->GetPPElement(namePP);
|
||||
patternPiece = patternP.cloneNode().toElement();
|
||||
mPath = doc->MPath();
|
||||
previousNode = patternP.previousSibling();//find previous pattern piece
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
DeletePatternPiece::~DeletePatternPiece()
|
||||
{}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DeletePatternPiece::undo()
|
||||
{
|
||||
if (CountPP() == 0)
|
||||
{
|
||||
doc->CreateEmptyFile(mPath);
|
||||
}
|
||||
|
||||
QDomElement rootElement = doc->documentElement();
|
||||
rootElement.insertAfter(patternPiece, previousNode);
|
||||
|
||||
emit NeedFullParsing();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DeletePatternPiece::redo()
|
||||
{
|
||||
if (CountPP() <= 1)
|
||||
{
|
||||
emit ClearScene();
|
||||
}
|
||||
else
|
||||
{
|
||||
QDomElement rootElement = doc->documentElement();
|
||||
QDomElement patternPiece = doc->GetPPElement(namePP);
|
||||
rootElement.removeChild(patternPiece);
|
||||
emit NeedFullParsing();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
int DeletePatternPiece::CountPP()
|
||||
{
|
||||
QDomElement rootElement = doc->documentElement();
|
||||
if (rootElement.isNull())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const QDomNodeList elements = rootElement.elementsByTagName( VPattern::TagDraw );
|
||||
return elements.count();
|
||||
}
|
58
src/app/undocommands/deletepatternpiece.h
Normal file
58
src/app/undocommands/deletepatternpiece.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file deletepatternpiece.h
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 14 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 DELETEPATTERNPIECE_H
|
||||
#define DELETEPATTERNPIECE_H
|
||||
|
||||
#include <QDomElement>
|
||||
#include <QUndoCommand>
|
||||
|
||||
class VPattern;
|
||||
|
||||
class DeletePatternPiece : public QObject, public QUndoCommand
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DeletePatternPiece(VPattern *doc, const QString &namePP, QUndoCommand *parent = 0);
|
||||
virtual ~DeletePatternPiece();
|
||||
virtual void undo();
|
||||
virtual void redo();
|
||||
signals:
|
||||
void ClearScene();
|
||||
void NeedFullParsing();
|
||||
private:
|
||||
Q_DISABLE_COPY(DeletePatternPiece)
|
||||
VPattern *doc;
|
||||
QString namePP;
|
||||
QDomElement patternPiece;
|
||||
QString mPath;
|
||||
QDomNode previousNode;
|
||||
int CountPP();
|
||||
};
|
||||
|
||||
#endif // DELETEPATTERNPIECE_H
|
|
@ -37,7 +37,8 @@ enum class UndoCommand: char { AddPatternPiece,
|
|||
SaveToolOptions,
|
||||
SaveDetailOptions,
|
||||
MoveDetail,
|
||||
DeleteTool
|
||||
DeleteTool,
|
||||
DeletePatternPiece
|
||||
};
|
||||
|
||||
#endif // UNDOCOMMANDS_H
|
||||
|
|
|
@ -8,7 +8,8 @@ HEADERS += \
|
|||
undocommands/undocommands.h \
|
||||
undocommands/savedetailoptions.h \
|
||||
undocommands/movedetail.h \
|
||||
undocommands/deltool.h
|
||||
undocommands/deltool.h \
|
||||
undocommands/deletepatternpiece.h
|
||||
|
||||
|
||||
SOURCES += \
|
||||
|
@ -20,5 +21,6 @@ SOURCES += \
|
|||
undocommands/savetooloptions.cpp \
|
||||
undocommands/savedetailoptions.cpp \
|
||||
undocommands/movedetail.cpp \
|
||||
undocommands/deltool.cpp
|
||||
undocommands/deltool.cpp \
|
||||
undocommands/deletepatternpiece.cpp
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user