issue 826 - workind on undo redo command

--HG--
branch : feature
This commit is contained in:
Ronan Le Tiec 2018-04-01 17:19:10 +02:00
parent 2ee19af497
commit 1526d77612
8 changed files with 48 additions and 19 deletions

View File

@ -3485,6 +3485,12 @@ void MainWindow::ShowProgress()
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::UpdateGroups()
{
groupsWidget->UpdateGroups();
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MainWindow::SetDefaultHeight() void MainWindow::SetDefaultHeight()
{ {
@ -4123,7 +4129,7 @@ void MainWindow::InitDocksContain()
qCDebug(vMainWindow, "Initialization groups dock."); qCDebug(vMainWindow, "Initialization groups dock.");
groupsWidget = new VWidgetGroups(doc, this); groupsWidget = new VWidgetGroups(doc, this);
ui->dockWidgetGroups->setWidget(groupsWidget); ui->dockWidgetGroups->setWidget(groupsWidget);
connect(doc,&VAbstractPattern::UpdateGroups , groupsWidget, &VWidgetGroups::UpdateGroups); connect(doc,&VAbstractPattern::UpdateGroups , this, &MainWindow::UpdateGroups);
detailsWidget = new VWidgetDetails(pattern, doc, this); detailsWidget = new VWidgetDetails(pattern, doc, this);
connect(doc, &VPattern::FullUpdateFromFile, detailsWidget, &VWidgetDetails::UpdateList); connect(doc, &VPattern::FullUpdateFromFile, detailsWidget, &VWidgetDetails::UpdateList);

View File

@ -68,7 +68,7 @@ public:
public slots: public slots:
void ProcessCMD(); void ProcessCMD();
void UpdateGroups();
virtual void ShowToolTip(const QString &toolTip) Q_DECL_OVERRIDE; virtual void ShowToolTip(const QString &toolTip) Q_DECL_OVERRIDE;
signals: signals:

View File

@ -2506,6 +2506,8 @@ QDomElement VAbstractPattern::AddItemToGroup(quint32 toolId, quint32 objectId, q
{ {
qDebug() << "The group of id " << groupId << " doesn't exist"; qDebug() << "The group of id " << groupId << " doesn't exist";
} }
return QDomElement();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -2555,7 +2557,7 @@ QDomElement VAbstractPattern::RemoveItemFromGroup(quint32 toolId, quint32 object
ParseGroups(groups); ParseGroups(groups);
} }
return itemNode; return item;
} }
} }
} }
@ -2566,6 +2568,8 @@ QDomElement VAbstractPattern::RemoveItemFromGroup(quint32 toolId, quint32 object
{ {
qDebug() << "The group of id " << groupId << " doesn't exist"; qDebug() << "The group of id " << groupId << " doesn't exist";
} }
return QDomElement();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -51,6 +51,8 @@
#include "../vdatatool.h" #include "../vdatatool.h"
#include "../vgeometry/vpointf.h" #include "../vgeometry/vpointf.h"
#include "../vtools/undocommands/addgroup.h" #include "../vtools/undocommands/addgroup.h"
#include "../vtools/undocommands/additemtogroup.h"
#include "../../../../app/valentina/mainwindow.h"
template <class T> class QSharedPointer; template <class T> class QSharedPointer;
@ -282,11 +284,14 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI
quint32 groupId = selectedAction->data().toUInt(); quint32 groupId = selectedAction->data().toUInt();
QDomElement item = doc->AddItemToGroup(this->getId(), itemId, groupId); QDomElement item = doc->AddItemToGroup(this->getId(), itemId, groupId);
AddItemToGroup *addItemToGroup = new AddItemToGroup(item, doc); MainWindow *window = qobject_cast<MainWindow *>(qApp->getMainWindow());
// where should the signal be connected to? should we have a central "UpdateGroup" slot, like in the mainWindow? SCASSERT(window != nullptr)
// connect(addItemToGroup, &AddItemToGroup::UpdateGroups, , &VWidgetGroups::UpdateGroups); {
qApp->getUndoStack()->push(addGroup); AddItemToGroup *addItemToGroup = new AddItemToGroup(item, doc);
connect(addItemToGroup, &AddItemToGroup::UpdateGroups, window, &MainWindow::UpdateGroups);
qApp->getUndoStack()->push(addItemToGroup);
}
} }
else if (selectedAction->actionGroup() == actionsRemoveFromGroup) else if (selectedAction->actionGroup() == actionsRemoveFromGroup)

View File

@ -40,13 +40,18 @@
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
AddItemToGroup::AddItemToGroup(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent) AddItemToGroup::AddItemToGroup(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent)
: VUndoCommand(xml, doc, parent), nameActivDraw(doc->GetNameActivPP()) : VUndoCommand(xml, doc, parent), nameActivDraw(doc->GetNameActivPP()), toolId(0), objectId(0)
{ {
setText(tr("add item to group")); setText(tr("add item to group"));
objectId = doc->GetParametrUInt(xml,QString("object"),NULL_ID_STR); objectId = doc->GetParametrUInt(xml,QString("object"),NULL_ID_STR);
toolId = doc->GetParametrUInt(xml,QString("tool"),NULL_ID_STR); toolId = doc->GetParametrUInt(xml,QString("tool"),NULL_ID_STR);
nodeId = doc->GetParametrId(xml.parentNode()); // nodeId is the groupId QDomNode parentNode = xml.parentNode();
if (parentNode.isElement())
{
nodeId = doc->GetParametrId(parentNode.toElement()); // nodeId is the groupId
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -73,7 +78,11 @@ void AddItemToGroup::undo()
return; return;
} }
doc->SetModified(true);
emit qApp->getCurrentDocument()->patternChanged(false);
doc->ParseGroups(groups); doc->ParseGroups(groups);
emit UpdateGroups(); emit UpdateGroups();
} }
else else
@ -91,3 +100,8 @@ void AddItemToGroup::undo()
VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView());
emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo
} }
void AddItemToGroup::redo()
{
}

View File

@ -43,7 +43,7 @@ class AddItemToGroup : public VUndoCommand
Q_OBJECT Q_OBJECT
public: public:
AddItemToGroup(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent = nullptr); AddItemToGroup(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent = nullptr);
virtual ~AddGroup(); virtual ~AddItemToGroup();
virtual void undo() Q_DECL_OVERRIDE; virtual void undo() Q_DECL_OVERRIDE;
virtual void redo() Q_DECL_OVERRIDE; virtual void redo() Q_DECL_OVERRIDE;
protected: protected:

View File

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

View File

@ -2,10 +2,10 @@
#define REMOVEITEMFROMGROUP_H #define REMOVEITEMFROMGROUP_H
class RemoveItemFromGroup : public VUndoCommand //class RemoveItemFromGroup : public VUndoCommand
{ //{
public: //public:
RemoveItemFromGroup(); // RemoveItemFromGroup();
}; //};
#endif // REMOVEITEMFROMGROUP_H #endif // REMOVEITEMFROMGROUP_H