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 groupId
*/
void VAbstractPattern::AddItemToGroup(quint32 toolId, quint32 objectId, quint32 groupId)
QDomElement VAbstractPattern::AddItemToGroup(quint32 toolId, quint32 objectId, quint32 groupId)
{
QDomElement group = elementById(groupId, TagGroup);
@ -2499,6 +2499,8 @@ void VAbstractPattern::AddItemToGroup(quint32 toolId, quint32 objectId, quint32
{
ParseGroups(groups);
}
return item;
}
else
{
@ -2513,7 +2515,7 @@ void VAbstractPattern::AddItemToGroup(quint32 toolId, quint32 objectId, quint32
* @param objectId
* @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);
@ -2553,7 +2555,7 @@ void VAbstractPattern::RemoveItemFromGroup(quint32 toolId, quint32 objectId, qui
ParseGroups(groups);
}
break;
return itemNode;
}
}
}

View file

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

View file

@ -50,6 +50,7 @@
#include "../vwidgets/vmaingraphicsview.h"
#include "../vdatatool.h"
#include "../vgeometry/vpointf.h"
#include "../vtools/undocommands/addgroup.h"
template <class T> class QSharedPointer;
@ -279,7 +280,14 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI
else if (selectedAction->actionGroup() == actionsAddToGroup)
{
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)
{

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/operationshowlabel.h \
$$PWD/saveplacelabeloptions.h \
$$PWD/togglepiecestate.h
$$PWD/togglepiecestate.h \
$$PWD/additemtogroup.h \
$$PWD/removeitemfromgroup.h
SOURCES += \
$$PWD/addtocalc.cpp \
@ -55,4 +57,6 @@ SOURCES += \
$$PWD/label/showdoublelabel.cpp \
$$PWD/label/operationshowlabel.cpp \
$$PWD/saveplacelabeloptions.cpp \
$$PWD/togglepiecestate.cpp
$$PWD/togglepiecestate.cpp \
$$PWD/additemtogroup.cpp \
$$PWD/removeitemfromgroup.cpp