Improve storing visibility group items. Don't store duplicate information.

This commit is contained in:
Roman Telezhynskyi 2021-11-17 16:18:29 +02:00
parent 2945da4d38
commit 888dccc2f3
6 changed files with 1165 additions and 10 deletions

View File

@ -19,6 +19,7 @@
- Improve validation grainline position. - Improve validation grainline position.
- Increased the limit for the Letter field. - Increased the limit for the Letter field.
- Fix double call of a main path context menu. - Fix double call of a main path context menu.
- Improve storing visibility group items. Don't store duplicate information.
# Valentina 0.7.49 July 1, 2021 # Valentina 0.7.49 July 1, 2021
- Fix crash. - Fix crash.

View File

@ -64,6 +64,7 @@
<file>schema/pattern/v0.8.10.xsd</file> <file>schema/pattern/v0.8.10.xsd</file>
<file>schema/pattern/v0.8.11.xsd</file> <file>schema/pattern/v0.8.11.xsd</file>
<file>schema/pattern/v0.8.12.xsd</file> <file>schema/pattern/v0.8.12.xsd</file>
<file>schema/pattern/v0.8.13.xsd</file>
<file>schema/multisize_measurements/v0.3.0.xsd</file> <file>schema/multisize_measurements/v0.3.0.xsd</file>
<file>schema/multisize_measurements/v0.4.0.xsd</file> <file>schema/multisize_measurements/v0.4.0.xsd</file>
<file>schema/multisize_measurements/v0.4.1.xsd</file> <file>schema/multisize_measurements/v0.4.1.xsd</file>

File diff suppressed because it is too large Load Diff

View File

@ -1847,8 +1847,9 @@ QPair<bool, QMap<quint32, quint32> > VAbstractPattern::ParseItemElement(const QD
const QDomElement element = nodeList.at(i).toElement(); const QDomElement element = nodeList.at(i).toElement();
if (not element.isNull() && element.tagName() == TagGroupItem) if (not element.isNull() && element.tagName() == TagGroupItem)
{ {
const quint32 object = GetParametrUInt(element, AttrObject, NULL_ID_STR);
const quint32 tool = GetParametrUInt(element, AttrTool, NULL_ID_STR); const quint32 tool = GetParametrUInt(element, AttrTool, NULL_ID_STR);
const quint32 object = GetParametrUInt(element, AttrObject, QString::number(tool));
items.insert(object, tool); items.insert(object, tool);
} }
} }
@ -2037,8 +2038,9 @@ QDomElement VAbstractPattern::CreateGroup(quint32 id, const QString &name, const
while (i != groupData.constEnd()) while (i != groupData.constEnd())
{ {
QDomElement item = createElement(TagGroupItem); QDomElement item = createElement(TagGroupItem);
item.setAttribute(AttrObject, i.key());
item.setAttribute(AttrTool, i.value()); item.setAttribute(AttrTool, i.value());
SetAttributeOrRemoveIf<vidtype>(item, AttrObject, i.key(), [i](vidtype object) noexcept
{return object == i.value();});
group.appendChild(item); group.appendChild(item);
++i; ++i;
} }
@ -2256,7 +2258,7 @@ bool VAbstractPattern::GroupHasItem(const QDomElement &groupDomElement, quint32
if (item.isNull() == false) if (item.isNull() == false)
{ {
quint32 toolIdIterate= GetParametrUInt(item, AttrTool, QChar('0')); quint32 toolIdIterate= GetParametrUInt(item, AttrTool, QChar('0'));
quint32 objectIdIterate= GetParametrUInt(item, AttrObject, QChar('0')); quint32 objectIdIterate= GetParametrUInt(item, AttrObject, QString::number(toolIdIterate));
if(toolIdIterate == toolId && objectIdIterate == objectId) if(toolIdIterate == toolId && objectIdIterate == objectId)
{ {
@ -2358,7 +2360,8 @@ QDomElement VAbstractPattern::AddItemToGroup(quint32 toolId, quint32 objectId, q
QDomElement item = createElement(TagGroupItem); QDomElement item = createElement(TagGroupItem);
item.setAttribute(AttrTool, toolId); item.setAttribute(AttrTool, toolId);
item.setAttribute(AttrObject, objectId); SetAttributeOrRemoveIf<vidtype>(item, AttrObject, objectId, [toolId](vidtype object) noexcept
{return object == toolId;});
group.appendChild(item); group.appendChild(item);
// to signalised that the pattern was changed and need to be saved // to signalised that the pattern was changed and need to be saved
@ -2413,7 +2416,7 @@ QDomElement VAbstractPattern::RemoveItemFromGroup(quint32 toolId, quint32 object
if (item.isNull() == false) if (item.isNull() == false)
{ {
quint32 toolIdIterate= GetParametrUInt(item, AttrTool, QChar('0')); quint32 toolIdIterate= GetParametrUInt(item, AttrTool, QChar('0'));
quint32 objectIdIterate= GetParametrUInt(item, AttrObject, QChar('0')); quint32 objectIdIterate= GetParametrUInt(item, AttrObject, QString::number(toolIdIterate));
if(toolIdIterate == toolId && objectIdIterate == objectId) if(toolIdIterate == toolId && objectIdIterate == objectId)
{ {

View File

@ -60,8 +60,8 @@ class QDomElement;
*/ */
const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.4"); const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.4");
const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.8.12"); const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.8.13");
const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.8.12.xsd"); const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.8.13.xsd");
//VPatternConverter::PatternMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VPatternConverter::PatternMinVer; // <== DON'T FORGET TO UPDATE TOO!!!!
//VPatternConverter::PatternMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VPatternConverter::PatternMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!!
@ -245,7 +245,8 @@ auto VPatternConverter::XSDSchema(unsigned ver) const -> QString
std::make_pair(FormatVersion(0, 8, 9), QStringLiteral("://schema/pattern/v0.8.9.xsd")), std::make_pair(FormatVersion(0, 8, 9), QStringLiteral("://schema/pattern/v0.8.9.xsd")),
std::make_pair(FormatVersion(0, 8, 10), QStringLiteral("://schema/pattern/v0.8.10.xsd")), std::make_pair(FormatVersion(0, 8, 10), QStringLiteral("://schema/pattern/v0.8.10.xsd")),
std::make_pair(FormatVersion(0, 8, 11), QStringLiteral("://schema/pattern/v0.8.11.xsd")), std::make_pair(FormatVersion(0, 8, 11), QStringLiteral("://schema/pattern/v0.8.11.xsd")),
std::make_pair(FormatVersion(0, 8, 12), CurrentSchema) std::make_pair(FormatVersion(0, 8, 12), QStringLiteral("://schema/pattern/v0.8.12.xsd")),
std::make_pair(FormatVersion(0, 8, 13), CurrentSchema)
}; };
if (schemas.contains(ver)) if (schemas.contains(ver))
@ -514,6 +515,10 @@ void VPatternConverter::ApplyPatches()
ValidateXML(XSDSchema(FormatVersion(0, 8, 12))); ValidateXML(XSDSchema(FormatVersion(0, 8, 12)));
Q_FALLTHROUGH(); Q_FALLTHROUGH();
case (FormatVersion(0, 8, 12)): case (FormatVersion(0, 8, 12)):
ToV0_8_13();
ValidateXML(XSDSchema(FormatVersion(0, 8, 13)));
Q_FALLTHROUGH();
case (FormatVersion(0, 8, 13)):
break; break;
default: default:
InvalidVersion(m_ver); InvalidVersion(m_ver);
@ -531,7 +536,7 @@ void VPatternConverter::DowngradeToCurrentMaxVersion()
bool VPatternConverter::IsReadOnly() const bool VPatternConverter::IsReadOnly() const
{ {
// Check if attribute readOnly was not changed in file format // Check if attribute readOnly was not changed in file format
Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == FormatVersion(0, 8, 12), Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == FormatVersion(0, 8, 13),
"Check attribute readOnly."); "Check attribute readOnly.");
// Possibly in future attribute readOnly will change position etc. // Possibly in future attribute readOnly will change position etc.
@ -1223,6 +1228,16 @@ void VPatternConverter::ToV0_8_12()
Save(); Save();
} }
//---------------------------------------------------------------------------------------------------------------------
void VPatternConverter::ToV0_8_13()
{
// TODO. Delete if minimal supported version is 0.8.13
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FormatVersion(0, 8, 13),
"Time to refactor the code.");
SetVersion(QStringLiteral("0.8.13"));
Save();
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPatternConverter::TagUnitToV0_2_0() void VPatternConverter::TagUnitToV0_2_0()
{ {

View File

@ -53,7 +53,7 @@ public:
static const QString PatternMaxVerStr; static const QString PatternMaxVerStr;
static const QString CurrentSchema; static const QString CurrentSchema;
static Q_DECL_CONSTEXPR const unsigned PatternMinVer = FormatVersion(0, 1, 4); static Q_DECL_CONSTEXPR const unsigned PatternMinVer = FormatVersion(0, 1, 4);
static Q_DECL_CONSTEXPR const unsigned PatternMaxVer = FormatVersion(0, 8, 12); static Q_DECL_CONSTEXPR const unsigned PatternMaxVer = FormatVersion(0, 8, 13);
protected: protected:
virtual unsigned MinVer() const override; virtual unsigned MinVer() const override;
@ -135,6 +135,7 @@ private:
void ToV0_8_10(); void ToV0_8_10();
void ToV0_8_11(); void ToV0_8_11();
void ToV0_8_12(); void ToV0_8_12();
void ToV0_8_13();
void TagUnitToV0_2_0(); void TagUnitToV0_2_0();
void TagIncrementToV0_2_0(); void TagIncrementToV0_2_0();