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/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/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/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..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. @@ -4123,6 +4133,7 @@ void MainWindow::InitDocksContain() qCDebug(vMainWindow, "Initialization groups dock."); groupsWidget = new VWidgetGroups(doc, this); ui->dockWidgetGroups->setWidget(groupsWidget); + 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..841653c2a 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -68,8 +68,8 @@ public: public slots: void ProcessCMD(); - virtual void ShowToolTip(const QString &toolTip) Q_DECL_OVERRIDE; + virtual void UpdateGroups() Q_DECL_OVERRIDE; signals: void RefreshHistory(); 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 e712fe573..9968a652f 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -2376,6 +2376,223 @@ 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 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) +{ + 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) + { + 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 groupDomElement + * @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 + */ +QDomElement VAbstractPattern::AddItemToGroup(quint32 toolId, quint32 objectId, quint32 groupId) +{ + QDomElement group = elementById(groupId, TagGroup); + + if (group.isNull() == false) + { + if(objectId == 0) + { + objectId = toolId; + } + + QDomElement item = createElement(TagGroupItem); + item.setAttribute(AttrTool, toolId); + 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); + } + + return item; + } + else + { + qDebug() << "The group of id " << groupId << " doesn't exist"; + } + + return QDomElement(); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Removes the item of given toolId and objectId from the group of given groupId + * @param toolId + * @param objectId + * @param groupId + */ +QDomElement VAbstractPattern::RemoveItemFromGroup(quint32 toolId, quint32 objectId, quint32 groupId) +{ + QDomElement group = elementById(groupId, TagGroup); + + if (group.isNull() == false) + { + 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); + + // 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); + } + + return item; + } + } + } + itemNode = itemNode.nextSibling(); + } + } + else + { + qDebug() << "The group of id " << groupId << " doesn't exist"; + } + + return QDomElement(); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @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; + } +} + //--------------------------------------------------------------------------------------------------------------------- bool VAbstractPattern::GetGroupVisivility(quint32 id) { diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 248b9da29..2a3d2c067 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -195,6 +195,10 @@ public: QString GetGroupName(quint32 id); void SetGroupName(quint32 id, const QString &name); QMap > GetGroups(); + QMap GetGroupsContainingItem(quint32 toolId, quint32 objectId, bool containItem); + 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); @@ -385,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; @@ -435,6 +443,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/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(); diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.h b/src/libs/vtools/tools/drawTools/vdrawtool.h index 6bc8877e8..f06c4a2b9 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -48,8 +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 "../vtools/undocommands/removeitemfromgroup.h" template class QSharedPointer; @@ -146,13 +150,70 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI return; } + GOType itemType = GOType::Unknown; + if(itemId != NULL_ID) + { + 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."); 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")); + + QStringList list = QStringList(groupsNotContainingItem.values()); + list.sort(Qt::CaseInsensitive); + + for(int i=0; iaddAction(list[i]); + actionsAddToGroup->addAction(actionAddToGroup); + 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); + } + } + + // 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")); + + QStringList list = QStringList(groupsContainingItem.values()); + list.sort(Qt::CaseInsensitive); + + for(int i=0; iaddAction(list[i]); + actionsRemoveFromGroup->addAction(actionRemoveFromGroup); + const quint32 groupId = groupsContainingItem.key(list[i]); + actionRemoveFromGroup->setData(groupId); + groupsContainingItem.remove(groupId); + } + } + QAction *actionShowLabel = menu.addAction(tr("Show label")); actionShowLabel->setCheckable(true); - if (itemId != NULL_ID) + + if (itemType == GOType::Point) { actionShowLabel->setChecked(IsLabelVisible(itemId)); } @@ -190,7 +251,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 +280,36 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI { ChangeLabelVisibility(itemId, selectedAction->isChecked()); } + else if (selectedAction->actionGroup() == actionsAddToGroup) + { + quint32 groupId = selectedAction->data().toUInt(); + QDomElement item = doc->AddItemToGroup(this->getId(), itemId, groupId); + + 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); + connect(addItemToGroup, &AddItemToGroup::UpdateGroups, window, &VAbstractMainWindow::UpdateGroups); + qApp->getUndoStack()->push(addItemToGroup); + } + } + else if (selectedAction->actionGroup() == actionsRemoveFromGroup) + { + quint32 groupId = selectedAction->data().toUInt(); + 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 new file mode 100644 index 000000000..b4d3f93be --- /dev/null +++ b/src/libs/vtools/undocommands/additemtogroup.cpp @@ -0,0 +1,141 @@ +/************************************************************************ + ** + ** @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 "../vtools/tools/vdatatool.h" +#include "vundocommand.h" + +//--------------------------------------------------------------------------------------------------------------------- +AddItemToGroup::AddItemToGroup(const QDomElement &xml, VAbstractPattern *doc, quint32 groupId, QUndoCommand *parent) + : VUndoCommand(xml, doc, parent), nameActivDraw(doc->GetNameActivPP()) +{ + setText(tr("Add item to group")); + 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 +} + +//--------------------------------------------------------------------------------------------------------------------- +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 new file mode 100644 index 000000000..63bb4436f --- /dev/null +++ b/src/libs/vtools/undocommands/additemtogroup.h @@ -0,0 +1,56 @@ +/************************************************************************ + ** + ** @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, quint32 nodeId, QUndoCommand *parent = nullptr); + virtual ~AddItemToGroup(); + virtual void undo() Q_DECL_OVERRIDE; + virtual void redo() Q_DECL_OVERRIDE; +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..ffe2b93ad --- /dev/null +++ b/src/libs/vtools/undocommands/removeitemfromgroup.cpp @@ -0,0 +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" + +#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 new file mode 100644 index 000000000..63bd0e464 --- /dev/null +++ b/src/libs/vtools/undocommands/removeitemfromgroup.h @@ -0,0 +1,28 @@ +#ifndef REMOVEITEMFROMGROUP_H +#define REMOVEITEMFROMGROUP_H + +#include +#include +#include +#include +#include +#include + +#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/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 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(); 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); } //---------------------------------------------------------------------------------------------------------------------