Tracking changes/prevent "OK" recalculation after "Apply".

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2020-01-09 18:56:37 +02:00
parent 40363230dc
commit 078f6fad64
8 changed files with 339 additions and 4 deletions

View File

@ -37,6 +37,7 @@
- Added a ruler at the bottom of a tiled PDF document. - Added a ruler at the bottom of a tiled PDF document.
- Export tiled PDF with watermark. - Export tiled PDF with watermark.
- [#984] Issue with up to date list of unique names. - [#984] Issue with up to date list of unique names.
- Tracking changes/prevent "OK" recalculation after "Apply".
# Version 0.6.2 (unreleased) # Version 0.6.2 (unreleased)
- [#903] Bug in tool Cut Spline path. - [#903] Bug in tool Cut Spline path.

View File

@ -120,6 +120,122 @@ void SaveNodeCanonically(QXmlStreamWriter &stream, const QDomNode &domNode)
stream.writeCharacters(domNode.nodeValue()); stream.writeCharacters(domNode.nodeValue());
} }
} }
//---------------------------------------------------------------------------------------------------------------------
QList<QDomNode> GetChildElements(const QDomNode& e)
{
QDomNodeList children = e.childNodes();
QList<QDomNode> r;
r.reserve(children.size());
for (int k = 0; k < children.size(); ++k)
{
r << children.at(k);
}
return r;
}
//---------------------------------------------------------------------------------------------------------------------
QList<QDomNode> GetElementAttributes(const QDomNode& e)
{
QDomNamedNodeMap attributes = e.attributes();
QList<QDomNode> r;
r.reserve(attributes.size());
for (int k = 0; k < attributes.size(); ++k)
{
r << attributes.item(k);
}
return r;
}
//---------------------------------------------------------------------------------------------------------------------
bool LessThen(const QDomNode &element1, const QDomNode &element2)
{
if (element1.nodeType() != element2.nodeType())
{
return element1.nodeType() < element2.nodeType();
}
QString tag1 = element1.nodeName();
QString tag2 = element2.nodeName();
//qDebug() << tag1 <<tag2;
if (tag1 != tag2)
{
return tag1 < tag2;
}
// Compare attributes
QList<QDomNode> attributes1 = GetElementAttributes(element1);
QList<QDomNode> attributes2 = GetElementAttributes(element2);
if(attributes1.size() != attributes2.size())
{
return attributes1.size() < attributes2.size();
}
bool stop = false;
auto CompareDomNodeLists = [&stop](QList<QDomNode> list1, QList<QDomNode> list2)
{
stop = false;
std::sort(list1.begin(), list1.end(), LessThen);
std::sort(list2.begin(), list2.end(), LessThen);
//qDebug() << "comparing sorted lists";
for(int k = 0; k < list1.size(); ++k)
{
if (!LessThen(list1[k], list2[k]))
{
if (LessThen(list2[k], list1[k]))
{
stop = true;
//qDebug() << "false!";
return false;
}
}
else
{
stop = true;
//qDebug() << "true!";
return true;
}
}
return false;
};
bool result = CompareDomNodeLists(attributes1, attributes2);
if (stop)
{
return result;
}
// Compare children
QList<QDomNode> elts1 = GetChildElements(element1);
QList<QDomNode> elts2 = GetChildElements(element2);
QString value1, value2;
if(elts1.size() != elts2.size())
{
return elts1.size() < elts2.size();
}
if(elts1.isEmpty())
{
value1 = element1.nodeValue();
value2 = element2.nodeValue();
//qDebug() <<value1 << value2 << (value1 < value2);
return value1 < value2;
}
result = CompareDomNodeLists(elts1, elts2);
// cppcheck-suppress identicalConditionAfterEarlyExit
if (stop)
{
return result;
}
return false;
}
} }
//This class need for validation pattern file using XSD shema //This class need for validation pattern file using XSD shema
@ -658,6 +774,13 @@ void VDomDocument::RefreshElementIdCache()
} }
} }
//---------------------------------------------------------------------------------------------------------------------
bool VDomDocument::Compare(const QDomElement &element1, const QDomElement &element2)
{
QFuture<bool> lessThen2 = QtConcurrent::run(LessThen, element2, element1);
return !LessThen(element1, element2) && !lessThen2.result();
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VDomDocument::CacheRefreshed() void VDomDocument::CacheRefreshed()
{ {

View File

@ -147,6 +147,8 @@ public:
void RefreshElementIdCache(); void RefreshElementIdCache();
static bool Compare(const QDomElement &element1, const QDomElement &element2);
protected: protected:
bool setTagText(const QString &tag, const QString &text); bool setTagText(const QString &tag, const QString &text);
bool setTagText(const QDomElement &domElement, const QString &text); bool setTagText(const QDomElement &domElement, const QString &text);

View File

@ -115,11 +115,14 @@ void VDrawTool::SaveDialogChange(const QString &undoText)
QList<quint32> newDependencies; QList<quint32> newDependencies;
SaveDialog(newDomElement, oldDependencies, newDependencies); SaveDialog(newDomElement, oldDependencies, newDependencies);
if (newDependencies != oldDependencies || not VDomDocument::Compare(newDomElement, oldDomElement))
{
SaveToolOptions *saveOptions = new SaveToolOptions(oldDomElement, newDomElement, oldDependencies, SaveToolOptions *saveOptions = new SaveToolOptions(oldDomElement, newDomElement, oldDependencies,
newDependencies, doc, m_id); newDependencies, doc, m_id);
connect(saveOptions, &SaveToolOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); connect(saveOptions, &SaveToolOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(saveOptions); qApp->getUndoStack()->push(saveOptions);
} }
}
else else
{ {
qCDebug(vTool, "Can't find tool with id = %u", m_id); qCDebug(vTool, "Can't find tool with id = %u", m_id);

View File

@ -52,6 +52,7 @@ DEFINES += SRCDIR=\\\"$$PWD/\\\"
SOURCES += \ SOURCES += \
qttestmainlambda.cpp \ qttestmainlambda.cpp \
tst_vdomdocument.cpp \
tst_vposter.cpp \ tst_vposter.cpp \
tst_vspline.cpp \ tst_vspline.cpp \
tst_nameregexp.cpp \ tst_nameregexp.cpp \
@ -78,6 +79,7 @@ SOURCES += \
*msvc*:SOURCES += stable.cpp *msvc*:SOURCES += stable.cpp
HEADERS += \ HEADERS += \
tst_vdomdocument.h \
tst_vposter.h \ tst_vposter.h \
tst_vspline.h \ tst_vspline.h \
tst_nameregexp.h \ tst_nameregexp.h \

View File

@ -50,6 +50,7 @@
#include "tst_readval.h" #include "tst_readval.h"
#include "tst_vtranslatevars.h" #include "tst_vtranslatevars.h"
#include "tst_vtooluniondetails.h" #include "tst_vtooluniondetails.h"
#include "tst_vdomdocument.h"
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include "../qmuparser/qmudef.h" #include "../qmuparser/qmudef.h"

View File

@ -0,0 +1,157 @@
/************************************************************************
**
** @file tst_vdomdocument.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 9 1, 2020
**
** @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) 2020 Valentina project
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "tst_vdomdocument.h"
#include <QtTest>
#include "../ifc/xml/vdomdocument.h"
//---------------------------------------------------------------------------------------------------------------------
TST_VDomDocument::TST_VDomDocument(QObject *parent)
:QObject(parent)
{
}
//---------------------------------------------------------------------------------------------------------------------
void TST_VDomDocument::TestCompareDomElements_data()
{
QTest::addColumn<QString>("element1Content");
QTest::addColumn<QString>("element2Content");
QTest::addColumn<bool>("compare");
QTest::newRow("Base point")
<< "<point type=\"single\" x=\"0.819903\" y=\"23.1895\" id=\"1\" name=\"Т\" mx=\"0.132292\" "
"my=\"0.264583\"/>"
<< "<point type=\"single\" x=\"0.819903\" y=\"23.1895\" id=\"1\" name=\"Т\" mx=\"0.132292\" "
"my=\"0.264583\"/>"
<< true;
QTest::newRow("Base point. Change attribute order")
<< "<point type=\"single\" x=\"0.819903\" y=\"23.1895\" id=\"1\" name=\"Т\" mx=\"0.132292\" "
"my=\"0.264583\"/>"
<< "<point type=\"single\" id=\"1\" name=\"Т\" x=\"0.819903\" y=\"23.1895\" mx=\"0.132292\" "
"my=\"0.264583\"/>"
<< true;
QTest::newRow("Base point. Change attribute value")
<< "<point type=\"single\" x=\"0.819903\" y=\"23.1895\" id=\"1\" name=\"Т\" mx=\"0.132292\" "
"my=\"0.264583\"/>"
<< "<point type=\"single\" x=\"0.819903\" y=\"23.1895\" id=\"2\" name=\"Т\" mx=\"0.132292\" "
"my=\"0.264583\"/>"
<< false;
QTest::newRow("Dirrent types")
<< "<point type=\"single\" x=\"0.819903\" y=\"23.1895\" id=\"1\" name=\"Т\" mx=\"0.132292\" "
"my=\"0.264583\"/>"
<< "<spline angle1=\"229.381\" angle2=\"41.6325\" color=\"black\" id=\"4\" kAsm1=\"0.962941\" "
"kAsm2=\"1.00054\" kCurve=\"1\" point1=\"3\" point4=\"2\" type=\"simple\"/>"
<< false;
QTest::newRow("Equal details")
<< "<detail closed=\"1\" forbidFlipping=\"false\" forceFlipping=\"false\" hideMainPath=\"false\" id=\"24\" "
"mx=\"-11.7117\" my=\"4.05406\" name=\"Case 2\" seamAllowance=\"true\" version=\"2\" width=\"1\">"
"<data annotation=\"\" foldPosition=\"\" fontSize=\"0\" height=\"1\" letter=\"\" mx=\"0\" my=\"0\" "
"onFold=\"false\" orientation=\"\" quantity=\"1\" rotation=\"0\" rotationWay=\"\" tilt=\"\" "
"visible=\"false\" width=\"1\"/>"
"<patternInfo fontSize=\"0\" height=\"1\" mx=\"0\" my=\"0\" rotation=\"0\" visible=\"false\" "
"width=\"1\"/>"
"<grainline arrows=\"0\" length=\"1\" mx=\"0\" my=\"0\" rotation=\"90\" visible=\"false\"/>"
"<nodes>"
"<node idObject=\"19\" type=\"NodePoint\"/>"
"<node idObject=\"20\" type=\"NodePoint\"/>"
"<node idObject=\"21\" reverse=\"0\" type=\"NodeSpline\"/>"
"<node idObject=\"22\" type=\"NodePoint\"/>"
"</nodes>"
"</detail>"
<< "<detail closed=\"1\" forbidFlipping=\"false\" forceFlipping=\"false\" hideMainPath=\"false\" id=\"24\" "
"mx=\"-11.7117\" my=\"4.05406\" name=\"Case 2\" seamAllowance=\"true\" version=\"2\" width=\"1\">"
"<data annotation=\"\" foldPosition=\"\" fontSize=\"0\" height=\"1\" letter=\"\" mx=\"0\" my=\"0\" "
"onFold=\"false\" orientation=\"\" quantity=\"1\" rotation=\"0\" rotationWay=\"\" tilt=\"\" "
"visible=\"false\" width=\"1\"/>"
"<patternInfo fontSize=\"0\" height=\"1\" mx=\"0\" my=\"0\" rotation=\"0\" visible=\"false\" "
"width=\"1\"/>"
"<grainline arrows=\"0\" length=\"1\" mx=\"0\" my=\"0\" rotation=\"90\" visible=\"false\"/>"
"<nodes>"
"<node idObject=\"19\" type=\"NodePoint\"/>"
"<node idObject=\"20\" type=\"NodePoint\"/>"
"<node idObject=\"21\" reverse=\"0\" type=\"NodeSpline\"/>"
"<node idObject=\"22\" type=\"NodePoint\"/>"
"</nodes>"
"</detail>"
<< true;
QTest::newRow("Not equal details")
<< "<detail closed=\"1\" forbidFlipping=\"false\" forceFlipping=\"false\" hideMainPath=\"false\" id=\"24\" "
"mx=\"-11.7117\" my=\"4.05406\" name=\"Case 2\" seamAllowance=\"true\" version=\"2\" width=\"1\">"
"<data annotation=\"\" foldPosition=\"\" fontSize=\"0\" height=\"1\" letter=\"\" mx=\"0\" my=\"0\" "
"onFold=\"false\" orientation=\"\" quantity=\"1\" rotation=\"0\" rotationWay=\"\" tilt=\"\" "
"visible=\"false\" width=\"1\"/>"
"<patternInfo fontSize=\"0\" height=\"1\" mx=\"0\" my=\"0\" rotation=\"0\" visible=\"false\" "
"width=\"1\"/>"
"<grainline arrows=\"0\" length=\"1\" mx=\"0\" my=\"0\" rotation=\"90\" visible=\"false\"/>"
"<nodes>"
"<node idObject=\"19\" type=\"NodePoint\"/>"
"<node idObject=\"20\" type=\"NodePoint\"/>"
"<node idObject=\"21\" reverse=\"0\" type=\"NodeSpline\"/>"
"<node idObject=\"22\" type=\"NodePoint\"/>"
"</nodes>"
"</detail>"
<< "<detail closed=\"1\" forbidFlipping=\"false\" forceFlipping=\"false\" hideMainPath=\"false\" id=\"35\" "
"mx=\"7.71397\" my=\"-3.94145\" name=\"Case 1\" seamAllowance=\"true\" version=\"2\" width=\"2\">"
"<data annotation=\"\" foldPosition=\"\" fontSize=\"0\" height=\"1\" letter=\"\" mx=\"0\" my=\"0\" "
"onFold=\"false\" orientation=\"\" quantity=\"1\" rotation=\"0\" rotationWay=\"\" tilt=\"\" "
"visible=\"false\" width=\"1\"/>"
"<patternInfo fontSize=\"0\" height=\"1\" mx=\"0\" my=\"0\" rotation=\"0\" visible=\"false\" "
"width=\"1\"/>"
"<grainline arrows=\"0\" length=\"1\" mx=\"0\" my=\"0\" rotation=\"0\" visible=\"false\"/>"
"<nodes>"
"<node idObject=\"30\" type=\"NodePoint\"/>"
"<node idObject=\"31\" reverse=\"0\" type=\"NodeSpline\"/>"
"<node idObject=\"32\" type=\"NodePoint\"/>"
"<node idObject=\"33\" type=\"NodePoint\"/>"
"</nodes>"
"</detail>"
<< false;
}
//---------------------------------------------------------------------------------------------------------------------
void TST_VDomDocument::TestCompareDomElements()
{
QFETCH(QString, element1Content);
QFETCH(QString, element2Content);
QFETCH(bool, compare);
QDomDocument xmlDoc;
QVERIFY(xmlDoc.setContent(element1Content));
QDomElement element1 = xmlDoc.firstChild().toElement();
QVERIFY(xmlDoc.setContent(element2Content));
QDomElement element2 = xmlDoc.firstChild().toElement();
const bool result = VDomDocument::Compare(element1, element2);
QCOMPARE(compare, result);
}

View File

@ -0,0 +1,46 @@
/************************************************************************
**
** @file tst_vdomdocument.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 9 1, 2020
**
** @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) 2020 Valentina project
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef TST_VDOMDOCUMENT_H
#define TST_VDOMDOCUMENT_H
#include <QObject>
class TST_VDomDocument :public QObject
{
Q_OBJECT
public:
explicit TST_VDomDocument(QObject *parent = nullptr);
private slots:
void TestCompareDomElements_data();
void TestCompareDomElements();
private:
Q_DISABLE_COPY(TST_VDomDocument)
};
#endif // TST_VDOMDOCUMENT_H