issue 826 start working on undo redo command

--HG--
branch : feature
This commit is contained in:
Ronan Le Tiec 2018-03-31 11:50:08 +02:00
parent d2f7a742b7
commit 2ee19af497
8 changed files with 191 additions and 8 deletions

View File

@ -2470,7 +2470,7 @@ bool VAbstractPattern::GroupHasItem(const QDomElement &groupDomElement, quint32
* @param objectId * @param objectId
* @param groupId * @param groupId
*/ */
void VAbstractPattern::AddItemToGroup(quint32 toolId, quint32 objectId, quint32 groupId) QDomElement VAbstractPattern::AddItemToGroup(quint32 toolId, quint32 objectId, quint32 groupId)
{ {
QDomElement group = elementById(groupId, TagGroup); QDomElement group = elementById(groupId, TagGroup);
@ -2499,6 +2499,8 @@ void VAbstractPattern::AddItemToGroup(quint32 toolId, quint32 objectId, quint32
{ {
ParseGroups(groups); ParseGroups(groups);
} }
return item;
} }
else else
{ {
@ -2513,7 +2515,7 @@ void VAbstractPattern::AddItemToGroup(quint32 toolId, quint32 objectId, quint32
* @param objectId * @param objectId
* @param groupId * @param groupId
*/ */
void VAbstractPattern::RemoveItemFromGroup(quint32 toolId, quint32 objectId, quint32 groupId) QDomElement VAbstractPattern::RemoveItemFromGroup(quint32 toolId, quint32 objectId, quint32 groupId)
{ {
QDomElement group = elementById(groupId, TagGroup); QDomElement group = elementById(groupId, TagGroup);
@ -2553,7 +2555,7 @@ void VAbstractPattern::RemoveItemFromGroup(quint32 toolId, quint32 objectId, qui
ParseGroups(groups); ParseGroups(groups);
} }
break; return itemNode;
} }
} }
} }

View File

@ -196,8 +196,8 @@ public:
void SetGroupName(quint32 id, const QString &name); void SetGroupName(quint32 id, const QString &name);
QMap<quint32, QPair<QString, bool> > GetGroups(); QMap<quint32, QPair<QString, bool> > GetGroups();
QMap<quint32, QString> GetGroupsContainingItem(quint32 toolId, quint32 objectId, bool containItem); QMap<quint32, QString> GetGroupsContainingItem(quint32 toolId, quint32 objectId, bool containItem);
void AddItemToGroup(quint32 toolId, quint32 objectId, quint32 groupId); QDomElement AddItemToGroup(quint32 toolId, quint32 objectId, quint32 groupId);
void RemoveItemFromGroup(quint32 toolId, quint32 objectId, quint32 groupId); QDomElement RemoveItemFromGroup(quint32 toolId, quint32 objectId, quint32 groupId);
bool GroupIsEmpty(quint32 id); bool GroupIsEmpty(quint32 id);
bool GetGroupVisivility(quint32 id); bool GetGroupVisivility(quint32 id);
void SetGroupVisivility(quint32 id, bool visible); void SetGroupVisivility(quint32 id, bool visible);

View File

@ -50,6 +50,7 @@
#include "../vwidgets/vmaingraphicsview.h" #include "../vwidgets/vmaingraphicsview.h"
#include "../vdatatool.h" #include "../vdatatool.h"
#include "../vgeometry/vpointf.h" #include "../vgeometry/vpointf.h"
#include "../vtools/undocommands/addgroup.h"
template <class T> class QSharedPointer; template <class T> class QSharedPointer;
@ -279,7 +280,14 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI
else if (selectedAction->actionGroup() == actionsAddToGroup) else if (selectedAction->actionGroup() == actionsAddToGroup)
{ {
quint32 groupId = selectedAction->data().toUInt(); quint32 groupId = selectedAction->data().toUInt();
doc->AddItemToGroup(this->getId(), itemId, groupId); QDomElement item = doc->AddItemToGroup(this->getId(), itemId, groupId);
AddItemToGroup *addItemToGroup = new AddItemToGroup(item, doc);
// where should the signal be connected to? should we have a central "UpdateGroup" slot, like in the mainWindow?
// connect(addItemToGroup, &AddItemToGroup::UpdateGroups, , &VWidgetGroups::UpdateGroups);
qApp->getUndoStack()->push(addGroup);
} }
else if (selectedAction->actionGroup() == actionsRemoveFromGroup) else if (selectedAction->actionGroup() == actionsRemoveFromGroup)
{ {

View File

@ -0,0 +1,93 @@
/************************************************************************
**
** @file addgroup.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 31 3, 2018
**
** @brief
** @copyright
** This source code is part of the Valentina 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 "additemtogroup.h"
#include <QDomNode>
#include <QDomNodeList>
#include "../vmisc/logging.h"
#include "../vmisc/vabstractapplication.h"
#include "../vmisc/def.h"
#include "../vwidgets/vmaingraphicsview.h"
#include "../ifc/xml/vabstractpattern.h"
#include "vundocommand.h"
//---------------------------------------------------------------------------------------------------------------------
AddItemToGroup::AddItemToGroup(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent)
: VUndoCommand(xml, doc, parent), nameActivDraw(doc->GetNameActivPP())
{
setText(tr("add item to group"));
objectId = doc->GetParametrUInt(xml,QString("object"),NULL_ID_STR);
toolId = doc->GetParametrUInt(xml,QString("tool"),NULL_ID_STR);
nodeId = doc->GetParametrId(xml.parentNode()); // nodeId is the groupId
}
//---------------------------------------------------------------------------------------------------------------------
AddItemToGroup::~AddItemToGroup()
{
}
//---------------------------------------------------------------------------------------------------------------------
void AddItemToGroup::undo()
{
qCDebug(vUndo, "Undo.");
doc->ChangeActivPP(nameActivDraw);//Without this user will not see this change
QDomElement groups = doc->CreateGroups();
if (not groups.isNull())
{
QDomElement group = doc->elementById(nodeId, VAbstractPattern::TagGroup);
if (group.isElement())
{
if (group.removeChild(xml).isNull())
{
qCDebug(vUndo, "Can't delete item.");
return;
}
doc->ParseGroups(groups);
emit UpdateGroups();
}
else
{
qCDebug(vUndo, "Can't get group by id = %u.", nodeId);
return;
}
}
else
{
qCDebug(vUndo, "Can't get tag Groups.");
return;
}
VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView());
emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo
}

View File

@ -0,0 +1,59 @@
/************************************************************************
**
** @file addgroup.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 31 3, 2018
**
** @brief
** @copyright
** This source code is part of the Valentina 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 ADDITEMTOGROUP_H
#define ADDITEMTOGROUP_H
#include <qcompilerdetection.h>
#include <QDomElement>
#include <QMetaObject>
#include <QObject>
#include <QString>
#include <QtGlobal>
#include "vundocommand.h"
class AddItemToGroup : public VUndoCommand
{
Q_OBJECT
public:
AddItemToGroup(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent = nullptr);
virtual ~AddGroup();
virtual void undo() Q_DECL_OVERRIDE;
virtual void redo() Q_DECL_OVERRIDE;
protected:
quint32 toolId;
quint32 objectId;
signals:
void UpdateGroups();
private:
Q_DISABLE_COPY(AddItemToGroup)
const QString nameActivDraw;
};
#endif // ADDITEMTOGROUP_H

View File

@ -0,0 +1,6 @@
#include "removeitemfromgroup.h"
RemoveItemFromGroup::RemoveItemFromGroup()
{
}

View File

@ -0,0 +1,11 @@
#ifndef REMOVEITEMFROMGROUP_H
#define REMOVEITEMFROMGROUP_H
class RemoveItemFromGroup : public VUndoCommand
{
public:
RemoveItemFromGroup();
};
#endif // REMOVEITEMFROMGROUP_H

View File

@ -27,7 +27,9 @@ HEADERS += \
$$PWD/label/showdoublelabel.h \ $$PWD/label/showdoublelabel.h \
$$PWD/label/operationshowlabel.h \ $$PWD/label/operationshowlabel.h \
$$PWD/saveplacelabeloptions.h \ $$PWD/saveplacelabeloptions.h \
$$PWD/togglepiecestate.h $$PWD/togglepiecestate.h \
$$PWD/additemtogroup.h \
$$PWD/removeitemfromgroup.h
SOURCES += \ SOURCES += \
$$PWD/addtocalc.cpp \ $$PWD/addtocalc.cpp \
@ -55,4 +57,6 @@ SOURCES += \
$$PWD/label/showdoublelabel.cpp \ $$PWD/label/showdoublelabel.cpp \
$$PWD/label/operationshowlabel.cpp \ $$PWD/label/operationshowlabel.cpp \
$$PWD/saveplacelabeloptions.cpp \ $$PWD/saveplacelabeloptions.cpp \
$$PWD/togglepiecestate.cpp $$PWD/togglepiecestate.cpp \
$$PWD/additemtogroup.cpp \
$$PWD/removeitemfromgroup.cpp