Remove tool from all visibility groups it in.
This commit is contained in:
parent
a915ef5a0d
commit
421a8df4be
|
@ -20,6 +20,7 @@
|
|||
- Increased the limit for the Letter field.
|
||||
- Fix double call of a main path context menu.
|
||||
- Improve storing visibility group items. Don't store duplicate information.
|
||||
- Remove tool from all visibility groups it in.
|
||||
|
||||
# Valentina 0.7.49 July 1, 2021
|
||||
- Fix crash.
|
||||
|
|
|
@ -349,7 +349,7 @@ void VWidgetGroups::FillTable(QMap<quint32, VGroupData> groups)
|
|||
item->setToolTip(tr("Categories: %1.").arg(data.tags.join(", ")));
|
||||
}
|
||||
|
||||
if(doc->GroupIsEmpty(i.key()))
|
||||
if(data.items.isEmpty())
|
||||
{
|
||||
QFont font = item->font();
|
||||
font.setStrikeOut(true);
|
||||
|
|
|
@ -1997,29 +1997,42 @@ QDomElement VAbstractPattern::GetDraw(const QString &name) const
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QDomElement VAbstractPattern::CreateGroups()
|
||||
auto VAbstractPattern::CreateGroups(const QString &patternPieceName) -> QDomElement
|
||||
{
|
||||
QDomElement draw;
|
||||
if (GetActivDrawElement(draw))
|
||||
|
||||
if (patternPieceName.isEmpty())
|
||||
{
|
||||
QDomElement groups = draw.firstChildElement(TagGroups);
|
||||
|
||||
if (groups.isNull())
|
||||
if (not GetActivDrawElement(draw))
|
||||
{
|
||||
groups = createElement(TagGroups);
|
||||
draw.appendChild(groups);
|
||||
return QDomElement();
|
||||
}
|
||||
|
||||
return groups;
|
||||
}
|
||||
return QDomElement();
|
||||
else
|
||||
{
|
||||
draw = GetPPElement(patternPieceName);
|
||||
if (not draw.isElement())
|
||||
{
|
||||
return QDomElement();
|
||||
}
|
||||
}
|
||||
|
||||
QDomElement groups = draw.firstChildElement(TagGroups);
|
||||
|
||||
if (groups.isNull())
|
||||
{
|
||||
groups = createElement(TagGroups);
|
||||
draw.appendChild(groups);
|
||||
}
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QDomElement VAbstractPattern::CreateGroup(quint32 id, const QString &name, const QStringList &tags,
|
||||
const QMap<quint32, quint32> &groupData, vidtype tool)
|
||||
auto VAbstractPattern::CreateGroup(quint32 id, const QString &name, const QStringList &tags,
|
||||
const QMap<quint32, quint32> &groupData, vidtype tool) -> QDomElement
|
||||
{
|
||||
if (id == NULL_ID || groupData.isEmpty())
|
||||
if (id == NULL_ID)
|
||||
{
|
||||
return QDomElement();
|
||||
}
|
||||
|
@ -2140,22 +2153,22 @@ QStringList VAbstractPattern::GetGroupCategories() const
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QMap<quint32, VGroupData> VAbstractPattern::GetGroups()
|
||||
auto VAbstractPattern::GetGroups(const QString &patternPieceName) -> QMap<quint32, VGroupData>
|
||||
{
|
||||
QMap<quint32, VGroupData> data;
|
||||
|
||||
try
|
||||
{
|
||||
QDomElement groups = CreateGroups();
|
||||
QDomElement groups = CreateGroups(patternPieceName);
|
||||
if (not groups.isNull())
|
||||
{
|
||||
QDomNode domNode = groups.firstChild();
|
||||
while (domNode.isNull() == false)
|
||||
while (not domNode.isNull())
|
||||
{
|
||||
if (domNode.isElement())
|
||||
{
|
||||
const QDomElement group = domNode.toElement();
|
||||
if (group.isNull() == false)
|
||||
if (not group.isNull())
|
||||
{
|
||||
if (group.tagName() == TagGroup)
|
||||
{
|
||||
|
@ -2164,6 +2177,25 @@ QMap<quint32, VGroupData> VAbstractPattern::GetGroups()
|
|||
groupData.visible = GetParametrBool(group, AttrVisible, trueStr);
|
||||
groupData.name = GetParametrString(group, AttrName, tr("New group"));
|
||||
groupData.tags = FilterGroupTags(GetParametrEmptyString(group, AttrTags));
|
||||
groupData.tool = GetParametrUInt(group, AttrTool, NULL_ID_STR);
|
||||
|
||||
QVector<QPair<quint32, quint32>> items;
|
||||
|
||||
const QDomNodeList nodeList = group.childNodes();
|
||||
const qint32 num = nodeList.size();
|
||||
for (qint32 i = 0; i < num; ++i)
|
||||
{
|
||||
const QDomElement element = nodeList.at(i).toElement();
|
||||
if (not element.isNull() && element.tagName() == TagGroupItem)
|
||||
{
|
||||
const quint32 tool = GetParametrUInt(element, AttrTool, NULL_ID_STR);
|
||||
const quint32 object = GetParametrUInt(element, AttrObject, QString::number(tool));
|
||||
|
||||
items.append(QPair<quint32, quint32>(object, tool));
|
||||
}
|
||||
}
|
||||
|
||||
groupData.items = items;
|
||||
|
||||
data.insert(id, groupData);
|
||||
}
|
||||
|
@ -2448,27 +2480,6 @@ QDomElement VAbstractPattern::RemoveItemFromGroup(quint32 toolId, quint32 object
|
|||
return QDomElement();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief Returns true if the given group is empty
|
||||
* @param id group id
|
||||
* @return true if the given group is empty
|
||||
*/
|
||||
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::GetGroupVisibility(quint32 id)
|
||||
{
|
||||
|
|
|
@ -83,6 +83,8 @@ struct VGroupData
|
|||
QString name{};
|
||||
bool visible{true};
|
||||
QStringList tags{};
|
||||
vidtype tool{NULL_ID};
|
||||
QVector<QPair<vidtype, vidtype>> items{};
|
||||
};
|
||||
|
||||
QT_WARNING_POP
|
||||
|
@ -212,7 +214,7 @@ public:
|
|||
QDomElement GetDraw(const QString &name) const;
|
||||
|
||||
void ParseGroups(const QDomElement &domElement);
|
||||
QDomElement CreateGroups();
|
||||
QDomElement CreateGroups(const QString &patternPieceName = QString());
|
||||
QDomElement CreateGroup(quint32 id, const QString &name, const QStringList &tags,
|
||||
const QMap<quint32, quint32> &groupData, vidtype tool=null_id);
|
||||
vidtype GroupLinkedToTool(vidtype toolId) const;
|
||||
|
@ -225,11 +227,10 @@ public:
|
|||
|
||||
QStringList GetGroupCategories() const;
|
||||
|
||||
QMap<quint32, VGroupData> GetGroups();
|
||||
QMap<quint32, VGroupData> GetGroups(const QString &patternPieceName = QString());
|
||||
QMap<quint32, QString> 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 GetGroupVisibility(quint32 id);
|
||||
|
||||
static QStringList FilterGroupTags(const QString &tags);
|
||||
|
|
|
@ -35,9 +35,25 @@
|
|||
#include "../vmisc/vabstractvalapplication.h"
|
||||
#include "vundocommand.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
auto FixGroups(QMap<quint32, VGroupData> groups, const QMap<quint32, VGroupData> &fix) -> QMap<quint32, VGroupData>
|
||||
{
|
||||
auto i = fix.constBegin();
|
||||
while (i != fix.constEnd())
|
||||
{
|
||||
groups.insert(i.key(), i.value());
|
||||
++i;
|
||||
}
|
||||
|
||||
return groups;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
DelTool::DelTool(VAbstractPattern *doc, quint32 id, QUndoCommand *parent)
|
||||
: VUndoCommand(QDomElement(), doc, parent), parentNode(QDomNode()), siblingId(NULL_ID),
|
||||
: VUndoCommand(QDomElement(), doc, parent),
|
||||
nameActivDraw(doc->GetNameActivPP())
|
||||
{
|
||||
setText(tr("delete tool"));
|
||||
|
@ -45,11 +61,35 @@ DelTool::DelTool(VAbstractPattern *doc, quint32 id, QUndoCommand *parent)
|
|||
siblingId = doc->SiblingNodeId(nodeId);
|
||||
parentNode = doc->ParentNodeById(nodeId);
|
||||
xml = doc->CloneNodeById(nodeId);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
DelTool::~DelTool()
|
||||
{}
|
||||
QMap<quint32, VGroupData> groups = doc->GetGroups(nameActivDraw);
|
||||
auto i = groups.constBegin();
|
||||
while (i != groups.constEnd())
|
||||
{
|
||||
VGroupData groupData = i.value();
|
||||
auto *itemRecord = std::find_if(groupData.items.begin(), groupData.items.end(),
|
||||
[id](const QPair<vidtype, vidtype> &item) { return item.second == id; });
|
||||
|
||||
if (itemRecord != groupData.items.end())
|
||||
{
|
||||
m_groupsBefore.insert(i.key(), groupData);
|
||||
|
||||
QVector<QPair<vidtype, vidtype>> cleanItems;
|
||||
for (auto item : groupData.items)
|
||||
{
|
||||
if (item.second != id)
|
||||
{
|
||||
cleanItems.append(item);
|
||||
}
|
||||
}
|
||||
|
||||
VGroupData cleanGroupData = groupData;
|
||||
cleanGroupData.items = cleanItems;
|
||||
m_groupsAfter.insert(i.key(), cleanGroupData);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DelTool::undo()
|
||||
|
@ -57,6 +97,12 @@ void DelTool::undo()
|
|||
qCDebug(vUndo, "Undo.");
|
||||
|
||||
UndoDeleteAfterSibling(parentNode, siblingId);
|
||||
|
||||
if (not m_groupsBefore.isEmpty())
|
||||
{
|
||||
UpdateGroups(FixGroups(doc->GetGroups(nameActivDraw), m_groupsBefore));
|
||||
}
|
||||
|
||||
emit NeedFullParsing();
|
||||
|
||||
if (VAbstractValApplication::VApp()->GetDrawMode() == Draw::Calculation)
|
||||
|
@ -76,5 +122,37 @@ void DelTool::redo()
|
|||
}
|
||||
QDomElement domElement = doc->NodeById(nodeId);
|
||||
parentNode.removeChild(domElement);
|
||||
|
||||
if (not m_groupsAfter.isEmpty())
|
||||
{
|
||||
UpdateGroups(FixGroups(doc->GetGroups(nameActivDraw), m_groupsAfter));
|
||||
}
|
||||
|
||||
emit NeedFullParsing();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DelTool::UpdateGroups(const QMap<quint32, VGroupData> &groups) const
|
||||
{
|
||||
QDomElement groupsTag = doc->CreateGroups(nameActivDraw);
|
||||
if (not groupsTag.isNull())
|
||||
{
|
||||
VDomDocument::RemoveAllChildren(groupsTag);
|
||||
|
||||
auto i = groups.constBegin();
|
||||
while (i != groups.constEnd())
|
||||
{
|
||||
QMap<vidtype, vidtype> groupMap;
|
||||
for (auto record : i.value().items)
|
||||
{
|
||||
groupMap.insert(record.first, record.second);
|
||||
}
|
||||
|
||||
QDomElement group = doc->CreateGroup(i.key(), i.value().name, i.value().tags, groupMap, i.value().tool);
|
||||
doc->SetAttribute(group, VAbstractPattern::AttrVisible, i.value().visible);
|
||||
groupsTag.appendChild(group);
|
||||
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,14 +43,18 @@ class DelTool : public VUndoCommand
|
|||
Q_OBJECT
|
||||
public:
|
||||
DelTool(VAbstractPattern *doc, quint32 id, QUndoCommand *parent = nullptr);
|
||||
virtual ~DelTool() override;
|
||||
virtual ~DelTool() override =default;
|
||||
virtual void undo() override;
|
||||
virtual void redo() override;
|
||||
private:
|
||||
Q_DISABLE_COPY(DelTool)
|
||||
QDomNode parentNode;
|
||||
quint32 siblingId;
|
||||
QDomNode parentNode{};
|
||||
quint32 siblingId{NULL_ID};
|
||||
const QString nameActivDraw;
|
||||
QMap<quint32, VGroupData> m_groupsBefore{};
|
||||
QMap<quint32, VGroupData> m_groupsAfter{};
|
||||
|
||||
void UpdateGroups(const QMap<quint32, VGroupData> &groups) const;
|
||||
};
|
||||
|
||||
#endif // DELTOOL_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user