From f09adc22ab88c9bfa6556de2f8b8b14307a2244e Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Fri, 6 Apr 2018 23:08:09 +0200 Subject: [PATCH] resolves #826 code refactoring and corrections --HG-- branch : develop --- src/app/tape/tmainwindow.cpp | 7 -- src/app/tape/tmainwindow.h | 1 - src/app/valentina/dialogs/vwidgetgroups.cpp | 2 +- src/libs/ifc/xml/vabstractpattern.h | 2 +- .../vtools/undocommands/additemtogroup.cpp | 81 +++++++------------ src/libs/vtools/undocommands/additemtogroup.h | 6 +- .../undocommands/removeitemfromgroup.cpp | 79 +++++++----------- .../vtools/undocommands/removeitemfromgroup.h | 32 +++++++- src/libs/vwidgets/vabstractmainwindow.cpp | 5 ++ src/libs/vwidgets/vabstractmainwindow.h | 2 +- 10 files changed, 102 insertions(+), 115 deletions(-) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 4925b42e7..ab49b7ef7 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -348,13 +348,6 @@ void TMainWindow::ShowToolTip(const QString &toolTip) // do nothing } -//--------------------------------------------------------------------------------------------------------------------- -void TMainWindow::UpdateGroups() -{ - // do nothing -} - - //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::FileNew() { diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index 865127658..a6139a259 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -65,7 +65,6 @@ public: public slots: virtual void ShowToolTip(const QString &toolTip) Q_DECL_OVERRIDE; - virtual void UpdateGroups() Q_DECL_OVERRIDE; protected: virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE; diff --git a/src/app/valentina/dialogs/vwidgetgroups.cpp b/src/app/valentina/dialogs/vwidgetgroups.cpp index 805f86908..70f156457 100644 --- a/src/app/valentina/dialogs/vwidgetgroups.cpp +++ b/src/app/valentina/dialogs/vwidgetgroups.cpp @@ -177,7 +177,7 @@ void VWidgetGroups::FillTable(const QMap > &groups if(doc->GroupIsEmpty(i.key())) { - QFont font; + QFont font = item->font(); font.setStrikeOut(true); item->setFont(font); } diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 2a3d2c067..24ad9e50d 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -444,7 +444,7 @@ protected: QVector getLocalHistory(const QString &draw) const; - bool GroupHasItem(const QDomElement &domElement, quint32 toolId, quint32 objectId); + bool GroupHasItem(const QDomElement &groupDomElement, quint32 toolId, quint32 objectId); private: Q_DISABLE_COPY(VAbstractPattern) diff --git a/src/libs/vtools/undocommands/additemtogroup.cpp b/src/libs/vtools/undocommands/additemtogroup.cpp index b4d3f93be..26180b5a7 100644 --- a/src/libs/vtools/undocommands/additemtogroup.cpp +++ b/src/libs/vtools/undocommands/additemtogroup.cpp @@ -1,7 +1,7 @@ /************************************************************************ ** ** @file addgroup.h - ** @author Roman Telezhynskyi + ** @author Ronan Le Tiec ** @date 31 3, 2018 ** ** @brief @@ -47,72 +47,51 @@ AddItemToGroup::AddItemToGroup(const QDomElement &xml, VAbstractPattern *doc, qu nodeId = groupId; } -//--------------------------------------------------------------------------------------------------------------------- -AddItemToGroup::~AddItemToGroup() -{ -} - //--------------------------------------------------------------------------------------------------------------------- void AddItemToGroup::undo() { qCDebug(vUndo, "Undo the add item to group"); - - doc->ChangeActivPP(nameActivDraw);//Without this user will not see this change - - QDomElement group = doc->elementById(nodeId, VAbstractPattern::TagGroup); - if (group.isElement()) - { - if (group.removeChild(xml).isNull()) - { - qCDebug(vUndo, "Can't delete item."); - return; - } - - doc->SetModified(true); - emit qApp->getCurrentDocument()->patternChanged(false); - - // set the item visible. Because if the undo is done when unvisibile and it's not in any group after the - // undo, it stays unvisible until the entire drawing is completly rerendered. - quint32 objectId = doc->GetParametrUInt(xml,QString("object"),NULL_ID_STR); - quint32 toolId = doc->GetParametrUInt(xml,QString("tool"),NULL_ID_STR); - VDataTool* tool = doc->getTool(toolId); - tool->GroupVisibility(objectId,true); - - QDomElement groups = doc->CreateGroups(); - if (not groups.isNull()) - { - doc->ParseGroups(groups); - } else - { - qCDebug(vUndo, "Can't get tag Groups."); - return; - } - - emit UpdateGroups(); - } - else - { - qCDebug(vUndo, "Can't get group by id = %u.", nodeId); - return; - } - - VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); - emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo + performUndoRedo(true); } //--------------------------------------------------------------------------------------------------------------------- void AddItemToGroup::redo() { qCDebug(vUndo, "Redo the add item to group"); + performUndoRedo(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +void AddItemToGroup::performUndoRedo(bool isUndo) +{ doc->ChangeActivPP(nameActivDraw);//Without this user will not see this change QDomElement group = doc->elementById(nodeId, VAbstractPattern::TagGroup); if (group.isElement()) { - if (group.appendChild(xml).isNull()) + if(isUndo) { - qCDebug(vUndo, "Can't add item."); - return; + if (group.removeChild(xml).isNull()) + { + qCDebug(vUndo, "Can't delete item."); + return; + } + + // set the item visible. Because if the undo is done when unvisible and it's not in any group after the + // undo, it stays unvisible until the entire drawing is completly rerendered. + quint32 objectId = doc->GetParametrUInt(xml,QString("object"),NULL_ID_STR); + quint32 toolId = doc->GetParametrUInt(xml,QString("tool"),NULL_ID_STR); + VDataTool* tool = doc->getTool(toolId); + tool->GroupVisibility(objectId,true); + } + else // is redo + { + + if (group.appendChild(xml).isNull()) + { + qCDebug(vUndo, "Can't add item."); + return; + } } doc->SetModified(true); diff --git a/src/libs/vtools/undocommands/additemtogroup.h b/src/libs/vtools/undocommands/additemtogroup.h index 63bb4436f..e82ca6226 100644 --- a/src/libs/vtools/undocommands/additemtogroup.h +++ b/src/libs/vtools/undocommands/additemtogroup.h @@ -1,7 +1,7 @@ /************************************************************************ ** ** @file addgroup.h - ** @author Roman Telezhynskyi + ** @author Ronan Le Tiec ** @date 31 3, 2018 ** ** @brief @@ -43,11 +43,13 @@ class AddItemToGroup : public VUndoCommand Q_OBJECT public: AddItemToGroup(const QDomElement &xml, VAbstractPattern *doc, quint32 nodeId, QUndoCommand *parent = nullptr); - virtual ~AddItemToGroup(); + virtual ~AddItemToGroup()=default; virtual void undo() Q_DECL_OVERRIDE; virtual void redo() Q_DECL_OVERRIDE; signals: void UpdateGroups(); +protected: + void performUndoRedo(bool isUndo); private: Q_DISABLE_COPY(AddItemToGroup) const QString nameActivDraw; diff --git a/src/libs/vtools/undocommands/removeitemfromgroup.cpp b/src/libs/vtools/undocommands/removeitemfromgroup.cpp index ffe2b93ad..2dc1459f4 100644 --- a/src/libs/vtools/undocommands/removeitemfromgroup.cpp +++ b/src/libs/vtools/undocommands/removeitemfromgroup.cpp @@ -1,7 +1,7 @@ /************************************************************************ ** ** @file removeitemfromgroup.cpp - ** @author Roman Telezhynskyi + ** @author Ronan Le Tiec ** @date 1 4, 2018 ** ** @brief @@ -48,76 +48,55 @@ RemoveItemFromGroup::RemoveItemFromGroup(const QDomElement &xml, VAbstractPatter nodeId = groupId; } -//--------------------------------------------------------------------------------------------------------------------- -RemoveItemFromGroup::~RemoveItemFromGroup() -{ -} - //--------------------------------------------------------------------------------------------------------------------- void RemoveItemFromGroup::undo() { qCDebug(vUndo, "Undo the remove item from group"); - doc->ChangeActivPP(nameActivDraw);//Without this user will not see this change - - QDomElement group = doc->elementById(nodeId, VAbstractPattern::TagGroup); - if (group.isElement()) - { - if (group.appendChild(xml).isNull()) - { - qCDebug(vUndo, "Can't add the item."); - return; - } - - doc->SetModified(true); - emit qApp->getCurrentDocument()->patternChanged(false); - - QDomElement groups = doc->CreateGroups(); - if (not groups.isNull()) - { - doc->ParseGroups(groups); - } else - { - qCDebug(vUndo, "Can't get tag Groups."); - return; - } - - emit UpdateGroups(); - } - else - { - qCDebug(vUndo, "Can't get group by id = %u.", nodeId); - return; - } - - VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); - emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo + performUndoRedo(true); } //--------------------------------------------------------------------------------------------------------------------- void RemoveItemFromGroup::redo() { qCDebug(vUndo, "Redo the add item to group"); + performUndoRedo(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +void RemoveItemFromGroup::performUndoRedo(bool isUndo) +{ doc->ChangeActivPP(nameActivDraw);//Without this user will not see this change QDomElement group = doc->elementById(nodeId, VAbstractPattern::TagGroup); if (group.isElement()) { - if (group.removeChild(xml).isNull()) + if(isUndo) { - qCDebug(vUndo, "Can't delete item."); - return; + if (group.appendChild(xml).isNull()) + { + qCDebug(vUndo, "Can't add the item."); + return; + } + } + else // is redo + { + if (group.removeChild(xml).isNull()) + { + qCDebug(vUndo, "Can't delete item."); + return; + } + + // set the item visible. Because if the undo is done when unvisibile and it's not in any group after the + // undo, it stays unvisible until the entire drawing is completly rerendered. + quint32 objectId = doc->GetParametrUInt(xml,QString("object"),NULL_ID_STR); + quint32 toolId = doc->GetParametrUInt(xml,QString("tool"),NULL_ID_STR); + VDataTool* tool = doc->getTool(toolId); + tool->GroupVisibility(objectId,true); } doc->SetModified(true); emit qApp->getCurrentDocument()->patternChanged(false); - // set the item visible. Because if the undo is done when unvisibile and it's not in any group after the - // undo, it stays unvisible until the entire drawing is completly rerendered. - quint32 objectId = doc->GetParametrUInt(xml,QString("object"),NULL_ID_STR); - quint32 toolId = doc->GetParametrUInt(xml,QString("tool"),NULL_ID_STR); - VDataTool* tool = doc->getTool(toolId); - tool->GroupVisibility(objectId,true); - QDomElement groups = doc->CreateGroups(); if (not groups.isNull()) { diff --git a/src/libs/vtools/undocommands/removeitemfromgroup.h b/src/libs/vtools/undocommands/removeitemfromgroup.h index 63bd0e464..042fd1971 100644 --- a/src/libs/vtools/undocommands/removeitemfromgroup.h +++ b/src/libs/vtools/undocommands/removeitemfromgroup.h @@ -1,3 +1,31 @@ +/************************************************************************ + ** + ** @file removeitemfromgroup.h + ** @author Ronan Le Tiec + ** @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 + ** 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 . + ** + *************************************************************************/ + #ifndef REMOVEITEMFROMGROUP_H #define REMOVEITEMFROMGROUP_H @@ -15,11 +43,13 @@ class RemoveItemFromGroup : public VUndoCommand Q_OBJECT public: RemoveItemFromGroup(const QDomElement &xml, VAbstractPattern *doc, quint32 groupId, QUndoCommand *parent = nullptr); - virtual ~RemoveItemFromGroup(); + virtual ~RemoveItemFromGroup()=default; virtual void undo() Q_DECL_OVERRIDE; virtual void redo() Q_DECL_OVERRIDE; signals: void UpdateGroups(); +protected: + void performUndoRedo(bool isUndo); private: Q_DISABLE_COPY(RemoveItemFromGroup) const QString nameActivDraw; diff --git a/src/libs/vwidgets/vabstractmainwindow.cpp b/src/libs/vwidgets/vabstractmainwindow.cpp index 967e0b516..7b03bc347 100644 --- a/src/libs/vwidgets/vabstractmainwindow.cpp +++ b/src/libs/vwidgets/vabstractmainwindow.cpp @@ -153,3 +153,8 @@ void VAbstractMainWindow::ExportDataToCSV() qApp->Settings()->SetCSVWithHeader(dialog.IsWithHeader()); } } + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractMainWindow::UpdateGroups() +{ +} diff --git a/src/libs/vwidgets/vabstractmainwindow.h b/src/libs/vwidgets/vabstractmainwindow.h index 6a4d0fa67..a3db738ff 100644 --- a/src/libs/vwidgets/vabstractmainwindow.h +++ b/src/libs/vwidgets/vabstractmainwindow.h @@ -46,7 +46,7 @@ public: public slots: virtual void ShowToolTip(const QString &toolTip)=0; - virtual void UpdateGroups()=0; + virtual void UpdateGroups(); protected slots: void WindowsLocale();