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 e712fe573..93528ac86 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -2376,6 +2376,191 @@ 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 + */ +void 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); + + emit UpdateGroups(); + } + else + { + qDebug() << "The group of id " << groupId << " doesn't exist"; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @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 (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); + emit UpdateGroups(); + break; + } + } + } + itemNode = itemNode.nextSibling(); + } + } + else + { + qDebug() << "The group of id " << groupId << " doesn't exist"; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @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..a86ec4f79 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); + 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); @@ -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..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); + } } //---------------------------------------------------------------------------------------------------------------------