From 30fbe09b107693aa0580c9405db845945f459e4a Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Thu, 22 Mar 2018 18:21:13 +0000 Subject: [PATCH 01/12] Created new branch issue826 --HG-- branch : issue826 From be44126c94f172114a71eee512aa9cb1fa035a1e Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sat, 24 Mar 2018 23:42:17 +0100 Subject: [PATCH 02/12] add remove item from group and add item to group in tool context menu --HG-- branch : issue826 --- src/libs/ifc/xml/vabstractpattern.cpp | 151 ++++++++++++++++++++ src/libs/ifc/xml/vabstractpattern.h | 5 + src/libs/vtools/tools/drawTools/vdrawtool.h | 50 ++++++- 3 files changed, 205 insertions(+), 1 deletion(-) diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index e712fe573..5a92886ae 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -2376,6 +2376,157 @@ QMap > VAbstractPattern::GetGroups() return data; } +//--------------------------------------------------------------------------------------------------------------------- + +/** + * @brief Returns the groups that contain or do not contain the item identified by the toolid and the objectid + * @param id + * @param containItem | true if the groups have to contain the given item, false if they musn't contain the item + * @return + */ +QMap VAbstractPattern::GetGroupsContainingItem(quint32 toolId, quint32 objectId, bool containItem) +{ + QMap data; + + if(objectId == 0) + { + objectId = toolId; + } + + // TODO : order in alphabetical order + + QDomElement groups = CreateGroups(); + if (not groups.isNull()) + { + QDomNode domNode = groups.firstChild(); + while (domNode.isNull() == false) // iterate through the groups + { + if (domNode.isElement()) + { + const QDomElement group = domNode.toElement(); + if (group.isNull() == false) + { + if (group.tagName() == TagGroup && group.hasChildNodes()) + { + bool groupHasItem = GroupHasItem(group, toolId, objectId); + if((containItem && groupHasItem) || (not containItem && not groupHasItem)) + { + const quint32 groupId = GetParametrUInt(group, AttrId, "0"); + const QString name = GetParametrString(group, AttrName, tr("New group")); + data.insert(groupId, name); + } + } + } + } + domNode = domNode.nextSibling(); + } + } + else + { + qDebug("Can't get tag Groups."); + } + + return data; +} +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Checks if the given group has the item with the given toolId and objectId + * @param domElement + * @param toolId + * @param objectId + * @return + */ +bool VAbstractPattern::GroupHasItem(const QDomElement &groupDomElement, quint32 toolId, quint32 objectId) +{ + bool result = false; + + QDomNode itemNode = groupDomElement.firstChild(); + while (itemNode.isNull() == false) // iterate through the items of the group + { + if (itemNode.isElement()) + { + const QDomElement item = itemNode.toElement(); + if (item.isNull() == false) + { + quint32 toolIdIterate= GetParametrUInt(item, AttrTool, "0"); + quint32 objectIdIterate= GetParametrUInt(item, AttrObject, "0"); + + if(toolIdIterate == toolId && objectIdIterate == objectId) + { + result = true; + break; + } + } + } + itemNode = itemNode.nextSibling(); + } + return result; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Adds an item to the given group with the given toolId and objectId + * @param toolId + * @param objectId + * @param groupId + */ +void VAbstractPattern::AddItemToGroup(quint32 toolId, quint32 objectId, quint32 groupId) +{ + QDomElement group = elementById(groupId, TagGroup); + + if(objectId == 0) + { + objectId = toolId; + } + + QDomElement item = createElement(TagGroupItem); + item.setAttribute(AttrTool, toolId); + item.setAttribute(AttrObject, objectId); + group.appendChild(item); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Removes the item of given toolId and objectId from the group of given groupId + * @param toolId + * @param objectId + * @param groupId + */ +void VAbstractPattern::RemoveItemFromGroup(quint32 toolId, quint32 objectId, quint32 groupId) +{ + QDomElement group = elementById(groupId, TagGroup); + + if(objectId == 0) + { + objectId = toolId; + } + + QDomNode itemNode = group.firstChild(); + while (itemNode.isNull() == false) // iterate through the items of the group + { + if (itemNode.isElement()) + { + const QDomElement item = itemNode.toElement(); + if (item.isNull() == false) + { + quint32 toolIdIterate= GetParametrUInt(item, AttrTool, "0"); + quint32 objectIdIterate= GetParametrUInt(item, AttrObject, "0"); + + if(toolIdIterate == toolId && objectIdIterate == objectId) + { + group.removeChild(itemNode); + break; + } + } + } + itemNode = itemNode.nextSibling(); + } + + // Handling when removing the last child: + // - automatically removes the group? + // - or allow a group to be empty? +} + //--------------------------------------------------------------------------------------------------------------------- bool VAbstractPattern::GetGroupVisivility(quint32 id) { diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 248b9da29..2658e6ed2 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -195,6 +195,9 @@ public: QString GetGroupName(quint32 id); void SetGroupName(quint32 id, const QString &name); QMap > GetGroups(); + QMap GetGroupsContainingItem(quint32 toolId, quint32 objectId, bool containItem); + void AddItemToGroup(quint32 toolId, quint32 objectId, quint32 groupId); + void RemoveItemFromGroup(quint32 toolId, quint32 objectId, quint32 groupId); bool GetGroupVisivility(quint32 id); void SetGroupVisivility(quint32 id, bool visible); @@ -435,6 +438,8 @@ protected: bool GetActivDrawElement(QDomElement &element) const; QVector getLocalHistory(const QString &draw) const; + + bool GroupHasItem(const QDomElement &domElement, quint32 toolId, quint32 objectId); private: Q_DISABLE_COPY(VAbstractPattern) diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.h b/src/libs/vtools/tools/drawTools/vdrawtool.h index 6bc8877e8..2a3cb65ab 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -150,6 +150,39 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI QMenu menu; QAction *actionOption = menu.addAction(QIcon::fromTheme("preferences-other"), tr("Options")); + // add the menu "add to group" to the context menu + QMap groupsNotContainingItem = doc->GetGroupsContainingItem(this->getId(), itemId, false); + QActionGroup* actionsAddToGroup = new QActionGroup(this); + if(not groupsNotContainingItem.empty()) + { + QMenu *menuAddToGroup = menu.addMenu(QIcon::fromTheme("list-add"), tr("Add to group")); + + QMap::iterator i; + for(i = groupsNotContainingItem.begin();i != groupsNotContainingItem.end(); ++i) + { + QAction *actionAddToGroup = menuAddToGroup->addAction(i.value()); + actionsAddToGroup->addAction(actionAddToGroup); + actionAddToGroup->setData(i.key()); + } + } + + // add the menu "remove from group" to the context menu + QMap groupsContainingItem = doc->GetGroupsContainingItem(this->getId(), itemId, true); + QActionGroup* actionsRemoveFromGroup = new QActionGroup(this); + if(not groupsContainingItem.empty()) + { + QMenu *menuRemoveFromGroup = menu.addMenu(QIcon::fromTheme("list-remove"), tr("Remove from group")); + + QMap::iterator i; + for(i = groupsContainingItem.begin();i != groupsContainingItem.end(); ++i) + { + QAction *actionRemoveFromGroup = menuRemoveFromGroup->addAction(i.value()); + actionsRemoveFromGroup->addAction(actionRemoveFromGroup); + actionRemoveFromGroup->setData(i.key()); + } + } + + QAction *actionShowLabel = menu.addAction(tr("Show label")); actionShowLabel->setCheckable(true); if (itemId != NULL_ID) @@ -190,7 +223,12 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI } QAction *selectedAction = menu.exec(event->screenPos()); - if (selectedAction == actionOption) + + if(selectedAction == nullptr) + { + return; + } + else if (selectedAction == actionOption) { qCDebug(vTool, "Show options."); emit qApp->getSceneView()->itemClicked(nullptr); @@ -214,6 +252,16 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI { ChangeLabelVisibility(itemId, selectedAction->isChecked()); } + else if (selectedAction->actionGroup() == actionsAddToGroup) + { + quint32 groupId = selectedAction->data().toUInt(); + doc->AddItemToGroup(this->getId(), itemId, groupId); + } + else if (selectedAction->actionGroup() == actionsRemoveFromGroup) + { + quint32 groupId = selectedAction->data().toUInt(); + doc->RemoveItemFromGroup(this->getId(), itemId, groupId); + } } //--------------------------------------------------------------------------------------------------------------------- From 032783581ae1b989092f8fbbbe0d54ef41f389e3 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sun, 25 Mar 2018 16:43:28 +0200 Subject: [PATCH 03/12] issue826 allow empty groups, schema version 0.7.8, update group list when adding or removing item --HG-- branch : issue826 --- src/app/valentina/dialogs/vwidgetgroups.cpp | 8 + src/app/valentina/mainwindow.cpp | 2 + src/libs/ifc/schema.qrc | 3 +- src/libs/ifc/schema/pattern/v0.7.8.xsd | 1061 +++++++++++++++++++ src/libs/ifc/xml/vabstractpattern.cpp | 98 +- src/libs/ifc/xml/vabstractpattern.h | 5 + src/libs/ifc/xml/vpatternconverter.cpp | 24 +- src/libs/ifc/xml/vpatternconverter.h | 3 +- 8 files changed, 1166 insertions(+), 38 deletions(-) create mode 100644 src/libs/ifc/schema/pattern/v0.7.8.xsd diff --git a/src/app/valentina/dialogs/vwidgetgroups.cpp b/src/app/valentina/dialogs/vwidgetgroups.cpp index d4ce0079d..805f86908 100644 --- a/src/app/valentina/dialogs/vwidgetgroups.cpp +++ b/src/app/valentina/dialogs/vwidgetgroups.cpp @@ -174,6 +174,14 @@ void VWidgetGroups::FillTable(const QMap > &groups item = new QTableWidgetItem(data.first); item->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter); + + if(doc->GroupIsEmpty(i.key())) + { + QFont font; + font.setStrikeOut(true); + item->setFont(font); + } + ui->tableWidget->setItem(currentRow, 1, item); ++i; } diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 6fdf87025..fc80894f9 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -4123,6 +4123,8 @@ void MainWindow::InitDocksContain() qCDebug(vMainWindow, "Initialization groups dock."); groupsWidget = new VWidgetGroups(doc, this); ui->dockWidgetGroups->setWidget(groupsWidget); + connect(doc,&VAbstractPattern::UpdateGroups , groupsWidget, &VWidgetGroups::UpdateGroups); + connect(doc,&VAbstractPattern::UpdateGroups , groupsWidget, &VWidgetGroups::UpdateGroups); detailsWidget = new VWidgetDetails(pattern, doc, this); connect(doc, &VPattern::FullUpdateFromFile, detailsWidget, &VWidgetDetails::UpdateList); diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index 77a854a8c..a386caf32 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -49,6 +49,7 @@ schema/pattern/v0.7.5.xsd schema/pattern/v0.7.6.xsd schema/pattern/v0.7.7.xsd + schema/pattern/v0.7.8.xsd schema/standard_measurements/v0.3.0.xsd schema/standard_measurements/v0.4.0.xsd schema/standard_measurements/v0.4.1.xsd @@ -62,5 +63,5 @@ schema/individual_measurements/v0.3.3.xsd schema/individual_measurements/v0.4.0.xsd schema/label_template/v1.0.0.xsd - + diff --git a/src/libs/ifc/schema/pattern/v0.7.8.xsd b/src/libs/ifc/schema/pattern/v0.7.8.xsd new file mode 100644 index 000000000..5c9c40c4a --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.7.8.xsd @@ -0,0 +1,1061 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 5a92886ae..93528ac86 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -2377,11 +2377,11 @@ QMap > VAbstractPattern::GetGroups() } //--------------------------------------------------------------------------------------------------------------------- - /** * @brief Returns the groups that contain or do not contain the item identified by the toolid and the objectid - * @param id - * @param containItem | true if the groups have to contain the given item, false if they musn't contain the item + * @param toolId + * @param objectId + * @param containItem |true if the groups have to contain the given item, false if they musn't contain the item * @return */ QMap VAbstractPattern::GetGroupsContainingItem(quint32 toolId, quint32 objectId, bool containItem) @@ -2406,7 +2406,7 @@ QMap VAbstractPattern::GetGroupsContainingItem(quint32 toolId, const QDomElement group = domNode.toElement(); if (group.isNull() == false) { - if (group.tagName() == TagGroup && group.hasChildNodes()) + if (group.tagName() == TagGroup) { bool groupHasItem = GroupHasItem(group, toolId, objectId); if((containItem && groupHasItem) || (not containItem && not groupHasItem)) @@ -2431,7 +2431,7 @@ QMap VAbstractPattern::GetGroupsContainingItem(quint32 toolId, //--------------------------------------------------------------------------------------------------------------------- /** * @brief Checks if the given group has the item with the given toolId and objectId - * @param domElement + * @param groupDomElement * @param toolId * @param objectId * @return @@ -2474,15 +2474,24 @@ void VAbstractPattern::AddItemToGroup(quint32 toolId, quint32 objectId, quint32 { QDomElement group = elementById(groupId, TagGroup); - if(objectId == 0) + if (group.isNull() == false) { - objectId = toolId; - } + if(objectId == 0) + { + objectId = toolId; + } - QDomElement item = createElement(TagGroupItem); - item.setAttribute(AttrTool, toolId); - item.setAttribute(AttrObject, objectId); - group.appendChild(item); + QDomElement item = createElement(TagGroupItem); + item.setAttribute(AttrTool, toolId); + item.setAttribute(AttrObject, objectId); + group.appendChild(item); + + emit UpdateGroups(); + } + else + { + qDebug() << "The group of id " << groupId << " doesn't exist"; + } } //--------------------------------------------------------------------------------------------------------------------- @@ -2496,35 +2505,60 @@ void VAbstractPattern::RemoveItemFromGroup(quint32 toolId, quint32 objectId, qui { QDomElement group = elementById(groupId, TagGroup); - if(objectId == 0) + if (group.isNull() == false) { - objectId = toolId; - } - - QDomNode itemNode = group.firstChild(); - while (itemNode.isNull() == false) // iterate through the items of the group - { - if (itemNode.isElement()) + if(objectId == 0) { - const QDomElement item = itemNode.toElement(); - if (item.isNull() == false) - { - quint32 toolIdIterate= GetParametrUInt(item, AttrTool, "0"); - quint32 objectIdIterate= GetParametrUInt(item, AttrObject, "0"); + objectId = toolId; + } - if(toolIdIterate == toolId && objectIdIterate == objectId) + QDomNode itemNode = group.firstChild(); + while (itemNode.isNull() == false) // iterate through the items of the group + { + if (itemNode.isElement()) + { + const QDomElement item = itemNode.toElement(); + if (item.isNull() == false) { - group.removeChild(itemNode); - break; + quint32 toolIdIterate= GetParametrUInt(item, AttrTool, "0"); + quint32 objectIdIterate= GetParametrUInt(item, AttrObject, "0"); + + if(toolIdIterate == toolId && objectIdIterate == objectId) + { + group.removeChild(itemNode); + emit UpdateGroups(); + break; + } } } + itemNode = itemNode.nextSibling(); } - itemNode = itemNode.nextSibling(); } + else + { + qDebug() << "The group of id " << groupId << " doesn't exist"; + } +} - // Handling when removing the last child: - // - automatically removes the group? - // - or allow a group to be empty? +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Returns true if the given group is empty + * @param id + * @return + */ +bool VAbstractPattern::GroupIsEmpty(quint32 id) +{ + QDomElement group = elementById(id, TagGroup); + + if (group.isNull() == false) + { + return not group.hasChildNodes(); + } + else + { + qDebug() << "The group of id " << id << " doesn't exist"; + return true; + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 2658e6ed2..a86ec4f79 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -198,6 +198,7 @@ public: QMap GetGroupsContainingItem(quint32 toolId, quint32 objectId, bool containItem); void AddItemToGroup(quint32 toolId, quint32 objectId, quint32 groupId); void RemoveItemFromGroup(quint32 toolId, quint32 objectId, quint32 groupId); + bool GroupIsEmpty(quint32 id); bool GetGroupVisivility(quint32 id); void SetGroupVisivility(quint32 id, bool visible); @@ -388,6 +389,10 @@ signals: void ShowDetail(quint32 id); void SetCurrentPP(const QString &patterPiece); void MadeProgress(); + /** + * @brief UpdateGroups emit if the groups have been updated + */ + void UpdateGroups(); public slots: virtual void LiteParseTree(const Document &parse)=0; diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index 010f5d28c..84d627407 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -59,8 +59,8 @@ class QDomElement; */ const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.0"); -const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.7.7"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.7.7.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.7.8"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.7.8.xsd"); //VPatternConverter::PatternMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VPatternConverter::PatternMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! @@ -227,7 +227,8 @@ QString VPatternConverter::XSDSchema(int ver) const std::make_pair(0x000704, QStringLiteral("://schema/pattern/v0.7.4.xsd")), std::make_pair(0x000705, QStringLiteral("://schema/pattern/v0.7.5.xsd")), std::make_pair(0x000706, QStringLiteral("://schema/pattern/v0.7.6.xsd")), - std::make_pair(0x000707, CurrentSchema) + std::make_pair(0x000707, QStringLiteral("://schema/pattern/v0.7.7.xsd")), + std::make_pair(0x000708, CurrentSchema) }; if (schemas.contains(ver)) @@ -438,6 +439,10 @@ void VPatternConverter::ApplyPatches() ValidateXML(XSDSchema(0x000707), m_convertedFileName); V_FALLTHROUGH case (0x000707): + ToV0_7_8(); + ValidateXML(XSDSchema(0x000708), m_convertedFileName); + V_FALLTHROUGH + case (0x000708): break; default: InvalidVersion(m_ver); @@ -455,7 +460,7 @@ void VPatternConverter::DowngradeToCurrentMaxVersion() bool VPatternConverter::IsReadOnly() const { // Check if attribute readOnly was not changed in file format - Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == CONVERTER_VERSION_CHECK(0, 7, 7), + Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == CONVERTER_VERSION_CHECK(0, 7, 8), "Check attribute readOnly."); // Possibly in future attribute readOnly will change position etc. @@ -999,6 +1004,17 @@ void VPatternConverter::ToV0_7_7() Save(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_7_8() +{ + // TODO. Delete if minimal supported version is 0.7.8 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 7, 8), + "Time to refactor the code."); + SetVersion(QStringLiteral("0.7.8")); + Save(); +} + + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index 1ba761f8d..989e53cec 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -53,7 +53,7 @@ public: static const QString PatternMaxVerStr; static const QString CurrentSchema; static Q_DECL_CONSTEXPR const int PatternMinVer = CONVERTER_VERSION_CHECK(0, 1, 0); - static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 7, 7); + static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 7, 8); protected: virtual int MinVer() const Q_DECL_OVERRIDE; @@ -120,6 +120,7 @@ private: void ToV0_7_5(); void ToV0_7_6(); void ToV0_7_7(); + void ToV0_7_8(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0(); From 6ce7ac12483c067aa4c906ddea5be77657a1e2e0 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sun, 25 Mar 2018 18:21:55 +0200 Subject: [PATCH 04/12] issue 826 sort group names in alphabetical case insensitive order --HG-- branch : feature --- src/app/valentina/mainwindow.cpp | 1 - src/libs/vtools/tools/drawTools/vdrawtool.h | 20 ++++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index fc80894f9..562a834af 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -4124,7 +4124,6 @@ void MainWindow::InitDocksContain() groupsWidget = new VWidgetGroups(doc, this); ui->dockWidgetGroups->setWidget(groupsWidget); connect(doc,&VAbstractPattern::UpdateGroups , groupsWidget, &VWidgetGroups::UpdateGroups); - connect(doc,&VAbstractPattern::UpdateGroups , groupsWidget, &VWidgetGroups::UpdateGroups); detailsWidget = new VWidgetDetails(pattern, doc, this); connect(doc, &VPattern::FullUpdateFromFile, detailsWidget, &VWidgetDetails::UpdateList); diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.h b/src/libs/vtools/tools/drawTools/vdrawtool.h index 2a3cb65ab..be218194d 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -157,12 +157,14 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI { QMenu *menuAddToGroup = menu.addMenu(QIcon::fromTheme("list-add"), tr("Add to group")); - QMap::iterator i; - for(i = groupsNotContainingItem.begin();i != groupsNotContainingItem.end(); ++i) + QStringList list = QStringList(groupsNotContainingItem.values()); + list.sort(Qt::CaseInsensitive); + + for(int i=0; iaddAction(i.value()); + QAction *actionAddToGroup = menuAddToGroup->addAction(list[i]); actionsAddToGroup->addAction(actionAddToGroup); - actionAddToGroup->setData(i.key()); + actionAddToGroup->setData(groupsNotContainingItem.key(list[i])); } } @@ -173,12 +175,14 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI { QMenu *menuRemoveFromGroup = menu.addMenu(QIcon::fromTheme("list-remove"), tr("Remove from group")); - QMap::iterator i; - for(i = groupsContainingItem.begin();i != groupsContainingItem.end(); ++i) + QStringList list = QStringList(groupsContainingItem.values()); + list.sort(Qt::CaseInsensitive); + + for(int i=0; iaddAction(i.value()); + QAction *actionRemoveFromGroup = menuRemoveFromGroup->addAction(list[i]); actionsRemoveFromGroup->addAction(actionRemoveFromGroup); - actionRemoveFromGroup->setData(i.key()); + actionRemoveFromGroup->setData(groupsContainingItem.key(list[i])); } } From 67c0e7ed4516360a33d28d7beeefa4e4232d45d4 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sun, 25 Mar 2018 20:01:36 +0200 Subject: [PATCH 05/12] issue826 improvement for the handling of groups with the same name --HG-- branch : feature --- src/libs/vtools/tools/drawTools/vdrawtool.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.h b/src/libs/vtools/tools/drawTools/vdrawtool.h index be218194d..affc64300 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -164,7 +164,12 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI { QAction *actionAddToGroup = menuAddToGroup->addAction(list[i]); actionsAddToGroup->addAction(actionAddToGroup); - actionAddToGroup->setData(groupsNotContainingItem.key(list[i])); + const quint32 groupId = groupsNotContainingItem.key(list[i]); + actionAddToGroup->setData(groupId); + + // removes the group we just treated, because we can have several group + // with the same name. Otherwise the groupId would always be the same + groupsNotContainingItem.remove(groupId); } } @@ -182,7 +187,9 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI { QAction *actionRemoveFromGroup = menuRemoveFromGroup->addAction(list[i]); actionsRemoveFromGroup->addAction(actionRemoveFromGroup); - actionRemoveFromGroup->setData(groupsContainingItem.key(list[i])); + const quint32 groupId = groupsContainingItem.key(list[i]); + actionRemoveFromGroup->setData(groupId); + groupsContainingItem.remove(groupId); } } From 597f021139c3cdfcd143116fdc11d0f17d7999fe Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Thu, 29 Mar 2018 23:13:33 +0200 Subject: [PATCH 06/12] issue 826 improvement to be able to add --HG-- branch : feature --- src/libs/vtools/tools/drawTools/vdrawtool.h | 11 +++++++++-- src/libs/vwidgets/vsimplecurve.cpp | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.h b/src/libs/vtools/tools/drawTools/vdrawtool.h index affc64300..ef611c385 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -146,6 +146,13 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI return; } + GOType itemType = GOType::Unknown; + if(itemId != NULL_ID) + { + const auto obj = data.GetGObject(itemId); + itemType = obj->getType(); + } + qCDebug(vTool, "Creating tool context menu."); QMenu menu; QAction *actionOption = menu.addAction(QIcon::fromTheme("preferences-other"), tr("Options")); @@ -193,10 +200,10 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI } } - QAction *actionShowLabel = menu.addAction(tr("Show label")); actionShowLabel->setCheckable(true); - if (itemId != NULL_ID) + + if (itemType == GOType::Point) { actionShowLabel->setChecked(IsLabelVisible(itemId)); } diff --git a/src/libs/vwidgets/vsimplecurve.cpp b/src/libs/vwidgets/vsimplecurve.cpp index 6f6f80bb7..570de348d 100644 --- a/src/libs/vwidgets/vsimplecurve.cpp +++ b/src/libs/vwidgets/vsimplecurve.cpp @@ -155,7 +155,7 @@ QVariant VSimpleCurve::itemChange(QGraphicsItem::GraphicsItemChange change, cons //--------------------------------------------------------------------------------------------------------------------- void VSimpleCurve::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - emit ShowContextMenu(event); + emit ShowContextMenu(event, id); } //--------------------------------------------------------------------------------------------------------------------- From 5fba6b797b03f2d092605d584ed5cdd71137a614 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Fri, 30 Mar 2018 11:02:10 +0200 Subject: [PATCH 07/12] issue 826 pattern modified when group modified --HG-- branch : feature --- src/libs/ifc/xml/vabstractpattern.cpp | 5 +++++ src/libs/vtools/tools/drawTools/vdrawtool.h | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 93528ac86..98c0de503 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -2486,6 +2486,8 @@ void VAbstractPattern::AddItemToGroup(quint32 toolId, quint32 objectId, quint32 item.setAttribute(AttrObject, objectId); group.appendChild(item); + modified = true; + emit patternChanged(false); emit UpdateGroups(); } else @@ -2526,6 +2528,9 @@ void VAbstractPattern::RemoveItemFromGroup(quint32 toolId, quint32 objectId, qui if(toolIdIterate == toolId && objectIdIterate == objectId) { group.removeChild(itemNode); + + modified = true; + emit patternChanged(false); emit UpdateGroups(); break; } diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.h b/src/libs/vtools/tools/drawTools/vdrawtool.h index ef611c385..59c94d768 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -149,8 +149,14 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI GOType itemType = GOType::Unknown; if(itemId != NULL_ID) { - const auto obj = data.GetGObject(itemId); - itemType = obj->getType(); + try + { + itemType = data.GetGObject(itemId)->getType(); + } + catch (const VExceptionBadId &e) + { // Possible case. Parent was deleted, but the node object is still here. + qWarning() << qUtf8Printable(e.ErrorMessage()); + } } qCDebug(vTool, "Creating tool context menu."); From d2f7a742b7f1e7358172f8c06fa9dd51538ec23c Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Fri, 30 Mar 2018 12:56:37 +0200 Subject: [PATCH 08/12] issue 826 update the drawing after adding/removing item to group --HG-- branch : feature --- src/libs/ifc/xml/vabstractpattern.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 98c0de503..ff0b8bca0 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -2486,9 +2486,19 @@ void VAbstractPattern::AddItemToGroup(quint32 toolId, quint32 objectId, quint32 item.setAttribute(AttrObject, objectId); group.appendChild(item); + // to signalised that the pattern was changed and need to be saved modified = true; emit patternChanged(false); + + // to update the group table of the gui emit UpdateGroups(); + + // parse the groups to update the drawing, in case the item was added to an invisible group + QDomElement groups = CreateGroups(); + if (not groups.isNull()) + { + ParseGroups(groups); + } } else { @@ -2529,9 +2539,20 @@ void VAbstractPattern::RemoveItemFromGroup(quint32 toolId, quint32 objectId, qui { group.removeChild(itemNode); + // to signalised that the pattern was changed and need to be saved modified = true; emit patternChanged(false); + + // to update the group table of the gui emit UpdateGroups(); + + // parse the groups to update the drawing, in case the item was removed from an invisible group + QDomElement groups = CreateGroups(); + if (not groups.isNull()) + { + ParseGroups(groups); + } + break; } } From 2ee19af497bde77195e54e4f8838e5fd0502c6e4 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sat, 31 Mar 2018 11:50:08 +0200 Subject: [PATCH 09/12] issue 826 start working on undo redo command --HG-- branch : feature --- src/libs/ifc/xml/vabstractpattern.cpp | 8 +- src/libs/ifc/xml/vabstractpattern.h | 4 +- src/libs/vtools/tools/drawTools/vdrawtool.h | 10 +- .../vtools/undocommands/additemtogroup.cpp | 93 +++++++++++++++++++ src/libs/vtools/undocommands/additemtogroup.h | 59 ++++++++++++ .../undocommands/removeitemfromgroup.cpp | 6 ++ .../vtools/undocommands/removeitemfromgroup.h | 11 +++ src/libs/vtools/undocommands/undocommands.pri | 8 +- 8 files changed, 191 insertions(+), 8 deletions(-) create mode 100644 src/libs/vtools/undocommands/additemtogroup.cpp create mode 100644 src/libs/vtools/undocommands/additemtogroup.h create mode 100644 src/libs/vtools/undocommands/removeitemfromgroup.cpp create mode 100644 src/libs/vtools/undocommands/removeitemfromgroup.h diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index ff0b8bca0..a02657907 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -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; } } } diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index a86ec4f79..2a3d2c067 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -196,8 +196,8 @@ public: void SetGroupName(quint32 id, const QString &name); QMap > GetGroups(); QMap 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); diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.h b/src/libs/vtools/tools/drawTools/vdrawtool.h index 59c94d768..5e5c1c7bc 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -50,6 +50,7 @@ #include "../vwidgets/vmaingraphicsview.h" #include "../vdatatool.h" #include "../vgeometry/vpointf.h" +#include "../vtools/undocommands/addgroup.h" template 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) { diff --git a/src/libs/vtools/undocommands/additemtogroup.cpp b/src/libs/vtools/undocommands/additemtogroup.cpp new file mode 100644 index 000000000..3ed6ccbd1 --- /dev/null +++ b/src/libs/vtools/undocommands/additemtogroup.cpp @@ -0,0 +1,93 @@ +/************************************************************************ + ** + ** @file addgroup.h + ** @author Roman Telezhynskyi + ** @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 . + ** + *************************************************************************/ + +#include "additemtogroup.h" + +#include +#include + +#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 +} diff --git a/src/libs/vtools/undocommands/additemtogroup.h b/src/libs/vtools/undocommands/additemtogroup.h new file mode 100644 index 000000000..5b9fe9143 --- /dev/null +++ b/src/libs/vtools/undocommands/additemtogroup.h @@ -0,0 +1,59 @@ +/************************************************************************ + ** + ** @file addgroup.h + ** @author Roman Telezhynskyi + ** @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 ADDITEMTOGROUP_H +#define ADDITEMTOGROUP_H + +#include +#include +#include +#include +#include +#include + +#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 diff --git a/src/libs/vtools/undocommands/removeitemfromgroup.cpp b/src/libs/vtools/undocommands/removeitemfromgroup.cpp new file mode 100644 index 000000000..370767fd7 --- /dev/null +++ b/src/libs/vtools/undocommands/removeitemfromgroup.cpp @@ -0,0 +1,6 @@ +#include "removeitemfromgroup.h" + +RemoveItemFromGroup::RemoveItemFromGroup() +{ + +} diff --git a/src/libs/vtools/undocommands/removeitemfromgroup.h b/src/libs/vtools/undocommands/removeitemfromgroup.h new file mode 100644 index 000000000..5d6fb42fb --- /dev/null +++ b/src/libs/vtools/undocommands/removeitemfromgroup.h @@ -0,0 +1,11 @@ +#ifndef REMOVEITEMFROMGROUP_H +#define REMOVEITEMFROMGROUP_H + + +class RemoveItemFromGroup : public VUndoCommand +{ +public: + RemoveItemFromGroup(); +}; + +#endif // REMOVEITEMFROMGROUP_H \ No newline at end of file diff --git a/src/libs/vtools/undocommands/undocommands.pri b/src/libs/vtools/undocommands/undocommands.pri index a290553d7..f69bd070f 100644 --- a/src/libs/vtools/undocommands/undocommands.pri +++ b/src/libs/vtools/undocommands/undocommands.pri @@ -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 From 1526d7761273e6ac3290b5b47f7d0d0b6594ccd1 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sun, 1 Apr 2018 17:19:10 +0200 Subject: [PATCH 10/12] issue 826 - workind on undo redo command --HG-- branch : feature --- src/app/valentina/mainwindow.cpp | 8 +++++++- src/app/valentina/mainwindow.h | 2 +- src/libs/ifc/xml/vabstractpattern.cpp | 6 +++++- src/libs/vtools/tools/drawTools/vdrawtool.h | 13 +++++++++---- .../vtools/undocommands/additemtogroup.cpp | 18 ++++++++++++++++-- src/libs/vtools/undocommands/additemtogroup.h | 2 +- .../undocommands/removeitemfromgroup.cpp | 6 +++--- .../vtools/undocommands/removeitemfromgroup.h | 12 ++++++------ 8 files changed, 48 insertions(+), 19 deletions(-) diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 562a834af..5c06fb535 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -3485,6 +3485,12 @@ void MainWindow::ShowProgress() } } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::UpdateGroups() +{ + groupsWidget->UpdateGroups(); +} + //--------------------------------------------------------------------------------------------------------------------- void MainWindow::SetDefaultHeight() { @@ -4123,7 +4129,7 @@ void MainWindow::InitDocksContain() qCDebug(vMainWindow, "Initialization groups dock."); groupsWidget = new VWidgetGroups(doc, this); ui->dockWidgetGroups->setWidget(groupsWidget); - connect(doc,&VAbstractPattern::UpdateGroups , groupsWidget, &VWidgetGroups::UpdateGroups); + connect(doc,&VAbstractPattern::UpdateGroups , this, &MainWindow::UpdateGroups); detailsWidget = new VWidgetDetails(pattern, doc, this); connect(doc, &VPattern::FullUpdateFromFile, detailsWidget, &VWidgetDetails::UpdateList); diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index bb34cf391..def642090 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -68,7 +68,7 @@ public: public slots: void ProcessCMD(); - + void UpdateGroups(); virtual void ShowToolTip(const QString &toolTip) Q_DECL_OVERRIDE; signals: diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index a02657907..9968a652f 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -2506,6 +2506,8 @@ QDomElement VAbstractPattern::AddItemToGroup(quint32 toolId, quint32 objectId, q { qDebug() << "The group of id " << groupId << " doesn't exist"; } + + return QDomElement(); } //--------------------------------------------------------------------------------------------------------------------- @@ -2555,7 +2557,7 @@ QDomElement VAbstractPattern::RemoveItemFromGroup(quint32 toolId, quint32 object 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"; } + + return QDomElement(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.h b/src/libs/vtools/tools/drawTools/vdrawtool.h index 5e5c1c7bc..3a120eede 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -51,6 +51,8 @@ #include "../vdatatool.h" #include "../vgeometry/vpointf.h" #include "../vtools/undocommands/addgroup.h" +#include "../vtools/undocommands/additemtogroup.h" +#include "../../../../app/valentina/mainwindow.h" template class QSharedPointer; @@ -282,11 +284,14 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI quint32 groupId = selectedAction->data().toUInt(); QDomElement item = doc->AddItemToGroup(this->getId(), itemId, groupId); - AddItemToGroup *addItemToGroup = new AddItemToGroup(item, doc); + MainWindow *window = qobject_cast(qApp->getMainWindow()); - // 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); + SCASSERT(window != nullptr) + { + AddItemToGroup *addItemToGroup = new AddItemToGroup(item, doc); + connect(addItemToGroup, &AddItemToGroup::UpdateGroups, window, &MainWindow::UpdateGroups); + qApp->getUndoStack()->push(addItemToGroup); + } } else if (selectedAction->actionGroup() == actionsRemoveFromGroup) diff --git a/src/libs/vtools/undocommands/additemtogroup.cpp b/src/libs/vtools/undocommands/additemtogroup.cpp index 3ed6ccbd1..054412184 100644 --- a/src/libs/vtools/undocommands/additemtogroup.cpp +++ b/src/libs/vtools/undocommands/additemtogroup.cpp @@ -40,13 +40,18 @@ //--------------------------------------------------------------------------------------------------------------------- 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")); 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 + QDomNode parentNode = xml.parentNode(); + + if (parentNode.isElement()) + { + nodeId = doc->GetParametrId(parentNode.toElement()); // nodeId is the groupId + } } //--------------------------------------------------------------------------------------------------------------------- @@ -73,7 +78,11 @@ void AddItemToGroup::undo() return; } + doc->SetModified(true); + emit qApp->getCurrentDocument()->patternChanged(false); + doc->ParseGroups(groups); + emit UpdateGroups(); } else @@ -91,3 +100,8 @@ void AddItemToGroup::undo() VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo } + +void AddItemToGroup::redo() +{ + +} diff --git a/src/libs/vtools/undocommands/additemtogroup.h b/src/libs/vtools/undocommands/additemtogroup.h index 5b9fe9143..2d005ada6 100644 --- a/src/libs/vtools/undocommands/additemtogroup.h +++ b/src/libs/vtools/undocommands/additemtogroup.h @@ -43,7 +43,7 @@ class AddItemToGroup : public VUndoCommand Q_OBJECT public: AddItemToGroup(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent = nullptr); - virtual ~AddGroup(); + virtual ~AddItemToGroup(); virtual void undo() Q_DECL_OVERRIDE; virtual void redo() Q_DECL_OVERRIDE; protected: diff --git a/src/libs/vtools/undocommands/removeitemfromgroup.cpp b/src/libs/vtools/undocommands/removeitemfromgroup.cpp index 370767fd7..97875f6c1 100644 --- a/src/libs/vtools/undocommands/removeitemfromgroup.cpp +++ b/src/libs/vtools/undocommands/removeitemfromgroup.cpp @@ -1,6 +1,6 @@ #include "removeitemfromgroup.h" -RemoveItemFromGroup::RemoveItemFromGroup() -{ +//RemoveItemFromGroup::RemoveItemFromGroup() +//{ -} +//} diff --git a/src/libs/vtools/undocommands/removeitemfromgroup.h b/src/libs/vtools/undocommands/removeitemfromgroup.h index 5d6fb42fb..fc76a92e5 100644 --- a/src/libs/vtools/undocommands/removeitemfromgroup.h +++ b/src/libs/vtools/undocommands/removeitemfromgroup.h @@ -2,10 +2,10 @@ #define REMOVEITEMFROMGROUP_H -class RemoveItemFromGroup : public VUndoCommand -{ -public: - RemoveItemFromGroup(); -}; +//class RemoveItemFromGroup : public VUndoCommand +//{ +//public: +// RemoveItemFromGroup(); +//}; -#endif // REMOVEITEMFROMGROUP_H \ No newline at end of file +#endif // REMOVEITEMFROMGROUP_H From d3da522ac4e6a0d6e0cb906cf6a3bc66e364da2b Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sun, 1 Apr 2018 23:36:54 +0200 Subject: [PATCH 11/12] issue 826 undo and redo adding or removing item from group finished --HG-- branch : feature --- src/app/tape/tmainwindow.cpp | 7 + src/app/tape/tmainwindow.h | 1 + src/app/valentina/mainwindow.cpp | 16 +- src/app/valentina/mainwindow.h | 2 +- src/libs/vtools/tools/drawTools/vdrawtool.h | 21 ++- .../vtools/undocommands/additemtogroup.cpp | 102 ++++++++----- src/libs/vtools/undocommands/additemtogroup.h | 5 +- .../undocommands/removeitemfromgroup.cpp | 141 +++++++++++++++++- .../vtools/undocommands/removeitemfromgroup.h | 27 +++- src/libs/vwidgets/vabstractmainwindow.h | 1 + 10 files changed, 264 insertions(+), 59 deletions(-) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index ab49b7ef7..4925b42e7 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -348,6 +348,13 @@ 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 a6139a259..865127658 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -65,6 +65,7 @@ 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/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 5c06fb535..0bfcb1b78 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -1455,6 +1455,16 @@ void MainWindow::ShowToolTip(const QString &toolTip) m_statusLabel->setText(toolTip); } + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief triggers the update of the groups + */ +void MainWindow::UpdateGroups() +{ + groupsWidget->UpdateGroups(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief showEvent handle after show window. @@ -3485,12 +3495,6 @@ void MainWindow::ShowProgress() } } -//--------------------------------------------------------------------------------------------------------------------- -void MainWindow::UpdateGroups() -{ - groupsWidget->UpdateGroups(); -} - //--------------------------------------------------------------------------------------------------------------------- void MainWindow::SetDefaultHeight() { diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index def642090..841653c2a 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -68,8 +68,8 @@ public: public slots: void ProcessCMD(); - void UpdateGroups(); virtual void ShowToolTip(const QString &toolTip) Q_DECL_OVERRIDE; + virtual void UpdateGroups() Q_DECL_OVERRIDE; signals: void RefreshHistory(); diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.h b/src/libs/vtools/tools/drawTools/vdrawtool.h index 3a120eede..e705023f4 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -48,11 +48,12 @@ #include "../vmisc/def.h" #include "../vwidgets/vmaingraphicsscene.h" #include "../vwidgets/vmaingraphicsview.h" +#include "../vwidgets/vabstractmainwindow.h" #include "../vdatatool.h" #include "../vgeometry/vpointf.h" #include "../vtools/undocommands/addgroup.h" #include "../vtools/undocommands/additemtogroup.h" -#include "../../../../app/valentina/mainwindow.h" +#include "../vtools/undocommands/removeitemfromgroup.h" template class QSharedPointer; @@ -284,20 +285,28 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI quint32 groupId = selectedAction->data().toUInt(); QDomElement item = doc->AddItemToGroup(this->getId(), itemId, groupId); - MainWindow *window = qobject_cast(qApp->getMainWindow()); + VAbstractMainWindow *window = qobject_cast(qApp->getMainWindow()); SCASSERT(window != nullptr) { - AddItemToGroup *addItemToGroup = new AddItemToGroup(item, doc); - connect(addItemToGroup, &AddItemToGroup::UpdateGroups, window, &MainWindow::UpdateGroups); + AddItemToGroup *addItemToGroup = new AddItemToGroup(item, doc, groupId); + connect(addItemToGroup, &AddItemToGroup::UpdateGroups, window, &VAbstractMainWindow::UpdateGroups); qApp->getUndoStack()->push(addItemToGroup); } - } else if (selectedAction->actionGroup() == actionsRemoveFromGroup) { quint32 groupId = selectedAction->data().toUInt(); - doc->RemoveItemFromGroup(this->getId(), itemId, groupId); + QDomElement item = doc->RemoveItemFromGroup(this->getId(), itemId, groupId); + + VAbstractMainWindow *window = qobject_cast(qApp->getMainWindow()); + + SCASSERT(window != nullptr) + { + RemoveItemFromGroup *removeItemFromGroup = new RemoveItemFromGroup(item, doc, groupId); + connect(removeItemFromGroup, &RemoveItemFromGroup::UpdateGroups, window, &VAbstractMainWindow::UpdateGroups); + qApp->getUndoStack()->push(removeItemFromGroup); + } } } diff --git a/src/libs/vtools/undocommands/additemtogroup.cpp b/src/libs/vtools/undocommands/additemtogroup.cpp index 054412184..b4d3f93be 100644 --- a/src/libs/vtools/undocommands/additemtogroup.cpp +++ b/src/libs/vtools/undocommands/additemtogroup.cpp @@ -36,22 +36,15 @@ #include "../vmisc/def.h" #include "../vwidgets/vmaingraphicsview.h" #include "../ifc/xml/vabstractpattern.h" +#include "../vtools/tools/vdatatool.h" #include "vundocommand.h" //--------------------------------------------------------------------------------------------------------------------- -AddItemToGroup::AddItemToGroup(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent) - : VUndoCommand(xml, doc, parent), nameActivDraw(doc->GetNameActivPP()), toolId(0), objectId(0) +AddItemToGroup::AddItemToGroup(const QDomElement &xml, VAbstractPattern *doc, quint32 groupId, 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); - QDomNode parentNode = xml.parentNode(); - - if (parentNode.isElement()) - { - nodeId = doc->GetParametrId(parentNode.toElement()); // nodeId is the groupId - } + setText(tr("Add item to group")); + nodeId = groupId; } //--------------------------------------------------------------------------------------------------------------------- @@ -62,38 +55,44 @@ AddItemToGroup::~AddItemToGroup() //--------------------------------------------------------------------------------------------------------------------- void AddItemToGroup::undo() { - qCDebug(vUndo, "Undo."); + qCDebug(vUndo, "Undo the add item to group"); 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()) { - QDomElement group = doc->elementById(nodeId, VAbstractPattern::TagGroup); - if (group.isElement()) + if (group.removeChild(xml).isNull()) { - if (group.removeChild(xml).isNull()) - { - qCDebug(vUndo, "Can't delete item."); - return; - } - - doc->SetModified(true); - emit qApp->getCurrentDocument()->patternChanged(false); - - doc->ParseGroups(groups); - - emit UpdateGroups(); - } - else - { - qCDebug(vUndo, "Can't get group by id = %u.", nodeId); + 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 tag Groups."); + qCDebug(vUndo, "Can't get group by id = %u.", nodeId); return; } @@ -101,7 +100,42 @@ void AddItemToGroup::undo() emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo } +//--------------------------------------------------------------------------------------------------------------------- void AddItemToGroup::redo() { + qCDebug(vUndo, "Redo 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.appendChild(xml).isNull()) + { + qCDebug(vUndo, "Can't add 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 } diff --git a/src/libs/vtools/undocommands/additemtogroup.h b/src/libs/vtools/undocommands/additemtogroup.h index 2d005ada6..63bb4436f 100644 --- a/src/libs/vtools/undocommands/additemtogroup.h +++ b/src/libs/vtools/undocommands/additemtogroup.h @@ -42,13 +42,10 @@ class AddItemToGroup : public VUndoCommand { Q_OBJECT public: - AddItemToGroup(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent = nullptr); + AddItemToGroup(const QDomElement &xml, VAbstractPattern *doc, quint32 nodeId, QUndoCommand *parent = nullptr); virtual ~AddItemToGroup(); virtual void undo() Q_DECL_OVERRIDE; virtual void redo() Q_DECL_OVERRIDE; -protected: - quint32 toolId; - quint32 objectId; signals: void UpdateGroups(); private: diff --git a/src/libs/vtools/undocommands/removeitemfromgroup.cpp b/src/libs/vtools/undocommands/removeitemfromgroup.cpp index 97875f6c1..ffe2b93ad 100644 --- a/src/libs/vtools/undocommands/removeitemfromgroup.cpp +++ b/src/libs/vtools/undocommands/removeitemfromgroup.cpp @@ -1,6 +1,141 @@ +/************************************************************************ + ** + ** @file removeitemfromgroup.cpp + ** @author Roman Telezhynskyi + ** @date 1 4, 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 . + ** + *************************************************************************/ + #include "removeitemfromgroup.h" -//RemoveItemFromGroup::RemoveItemFromGroup() -//{ +#include +#include -//} +#include "../vmisc/logging.h" +#include "../vmisc/vabstractapplication.h" +#include "../vmisc/def.h" +#include "../vwidgets/vmaingraphicsview.h" +#include "../ifc/xml/vabstractpattern.h" +#include "../vtools/tools/vdatatool.h" +#include "vundocommand.h" + +//--------------------------------------------------------------------------------------------------------------------- + +RemoveItemFromGroup::RemoveItemFromGroup(const QDomElement &xml, VAbstractPattern *doc, quint32 groupId, QUndoCommand *parent) + : VUndoCommand(xml, doc, parent), nameActivDraw(doc->GetNameActivPP()) +{ + setText(tr("Remove item from group")); + 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 +} + +//--------------------------------------------------------------------------------------------------------------------- +void RemoveItemFromGroup::redo() +{ + qCDebug(vUndo, "Redo 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 +} diff --git a/src/libs/vtools/undocommands/removeitemfromgroup.h b/src/libs/vtools/undocommands/removeitemfromgroup.h index fc76a92e5..63bd0e464 100644 --- a/src/libs/vtools/undocommands/removeitemfromgroup.h +++ b/src/libs/vtools/undocommands/removeitemfromgroup.h @@ -1,11 +1,28 @@ #ifndef REMOVEITEMFROMGROUP_H #define REMOVEITEMFROMGROUP_H +#include +#include +#include +#include +#include +#include -//class RemoveItemFromGroup : public VUndoCommand -//{ -//public: -// RemoveItemFromGroup(); -//}; +#include "vundocommand.h" + +class RemoveItemFromGroup : public VUndoCommand +{ + Q_OBJECT +public: + RemoveItemFromGroup(const QDomElement &xml, VAbstractPattern *doc, quint32 groupId, QUndoCommand *parent = nullptr); + virtual ~RemoveItemFromGroup(); + virtual void undo() Q_DECL_OVERRIDE; + virtual void redo() Q_DECL_OVERRIDE; +signals: + void UpdateGroups(); +private: + Q_DISABLE_COPY(RemoveItemFromGroup) + const QString nameActivDraw; +}; #endif // REMOVEITEMFROMGROUP_H diff --git a/src/libs/vwidgets/vabstractmainwindow.h b/src/libs/vwidgets/vabstractmainwindow.h index 59a52e516..6a4d0fa67 100644 --- a/src/libs/vwidgets/vabstractmainwindow.h +++ b/src/libs/vwidgets/vabstractmainwindow.h @@ -46,6 +46,7 @@ public: public slots: virtual void ShowToolTip(const QString &toolTip)=0; + virtual void UpdateGroups()=0; protected slots: void WindowsLocale(); From 84bab5386b397cf6f7a3de9a8a4c54c085ea8c1d Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Mon, 2 Apr 2018 11:52:42 +0200 Subject: [PATCH 12/12] issue 826 clear selection when adding an item to a group. changelog and list of contributor --HG-- branch : feature --- ChangeLog.txt | 1 + src/app/valentina/dialogs/dialogaboutapp.ui | 5 +++-- src/libs/vtools/tools/drawTools/vdrawtool.h | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index bc5735ddd..861ec4b9e 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -48,6 +48,7 @@ - [#814] Make "\" valid character. - [#818] Improve Piece path validation. Check uniqueness. - [#819] Use OpenGL as render for view. +- [#826] New Feature. Add and remove items to groups from the context menu. # Version 0.5.1 - [#683] Tool Seam allowance's dialog is off screen on small resolutions. diff --git a/src/app/valentina/dialogs/dialogaboutapp.ui b/src/app/valentina/dialogs/dialogaboutapp.ui index 47c3db450..d67111aa7 100644 --- a/src/app/valentina/dialogs/dialogaboutapp.ui +++ b/src/app/valentina/dialogs/dialogaboutapp.ui @@ -10,7 +10,7 @@ 0 0 583 - 526 + 543 @@ -224,7 +224,8 @@ Fritz Rometsch Felix Ulber Alex Zaharov Valentina Zhuravska -Bettina Gatzlaff +Bettina Gatzlaff +Ronan Le Tiec diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.h b/src/libs/vtools/tools/drawTools/vdrawtool.h index e705023f4..f06c4a2b9 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -285,8 +285,11 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI quint32 groupId = selectedAction->data().toUInt(); QDomElement item = doc->AddItemToGroup(this->getId(), itemId, groupId); - VAbstractMainWindow *window = qobject_cast(qApp->getMainWindow()); + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) + scene->clearSelection(); + VAbstractMainWindow *window = qobject_cast(qApp->getMainWindow()); SCASSERT(window != nullptr) { AddItemToGroup *addItemToGroup = new AddItemToGroup(item, doc, groupId); @@ -300,7 +303,6 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI QDomElement item = doc->RemoveItemFromGroup(this->getId(), itemId, groupId); VAbstractMainWindow *window = qobject_cast(qApp->getMainWindow()); - SCASSERT(window != nullptr) { RemoveItemFromGroup *removeItemFromGroup = new RemoveItemFromGroup(item, doc, groupId);