Seepd up pattern file validation making it parallel.
--HG-- branch : develop
This commit is contained in:
parent
bac4e0872b
commit
5004c12342
|
@ -267,14 +267,14 @@ bool TMainWindow::LoadFile(const QString &path)
|
||||||
{
|
{
|
||||||
VVSTConverter converter(path);
|
VVSTConverter converter(path);
|
||||||
m_curFileFormatVersion = converter.GetCurrentFormatVersion();
|
m_curFileFormatVersion = converter.GetCurrentFormatVersion();
|
||||||
m_curFileFormatVersionStr = converter.GetVersionStr();
|
m_curFileFormatVersionStr = converter.GetFormatVersionStr();
|
||||||
m->setXMLContent(converter.Convert());// Read again after conversion
|
m->setXMLContent(converter.Convert());// Read again after conversion
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
VVITConverter converter(path);
|
VVITConverter converter(path);
|
||||||
m_curFileFormatVersion = converter.GetCurrentFormatVersion();
|
m_curFileFormatVersion = converter.GetCurrentFormatVersion();
|
||||||
m_curFileFormatVersionStr = converter.GetVersionStr();
|
m_curFileFormatVersionStr = converter.GetFormatVersionStr();
|
||||||
m->setXMLContent(converter.Convert());// Read again after conversion
|
m->setXMLContent(converter.Convert());// Read again after conversion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2910,7 +2910,7 @@ bool TMainWindow::LoadFromExistingFile(const QString &path)
|
||||||
{
|
{
|
||||||
VVITConverter converter(path);
|
VVITConverter converter(path);
|
||||||
m_curFileFormatVersion = converter.GetCurrentFormatVersion();
|
m_curFileFormatVersion = converter.GetCurrentFormatVersion();
|
||||||
m_curFileFormatVersionStr = converter.GetVersionStr();
|
m_curFileFormatVersionStr = converter.GetFormatVersionStr();
|
||||||
m->setXMLContent(converter.Convert());// Read again after conversion
|
m->setXMLContent(converter.Convert());// Read again after conversion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4487,6 +4487,12 @@ bool MainWindow::LoadPattern(QString fileName, const QString& customMeasureFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QFuture<VPatternConverter *> futureConverter = QtConcurrent::run([fileName]()
|
||||||
|
{
|
||||||
|
QScopedPointer<VPatternConverter> converter(new VPatternConverter(fileName));
|
||||||
|
return converter.take();
|
||||||
|
});
|
||||||
|
|
||||||
//We have unsaved changes or load more then one file per time
|
//We have unsaved changes or load more then one file per time
|
||||||
if (OpenNewValentina(fileName))
|
if (OpenNewValentina(fileName))
|
||||||
{
|
{
|
||||||
|
@ -4557,15 +4563,30 @@ bool MainWindow::LoadPattern(QString fileName, const QString& customMeasureFile)
|
||||||
qApp->setOpeningPattern();//Begin opening file
|
qApp->setOpeningPattern();//Begin opening file
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
VPatternConverter converter(fileName);
|
// Quick reading measurements
|
||||||
m_curFileFormatVersion = converter.GetCurrentFormatVersion();
|
doc->setXMLContent(fileName);
|
||||||
m_curFileFormatVersionStr = converter.GetVersionStr();
|
const int currentFormatVersion = doc->GetFormatVersion(doc->GetFormatVersionStr());
|
||||||
doc->setXMLContent(converter.Convert());
|
if (currentFormatVersion != VPatternConverter::PatternMaxVer)
|
||||||
if (!customMeasureFile.isEmpty())
|
{ // Because we rely on the fact that we know where is path to measurements optimization available only for
|
||||||
{
|
// the latest format version
|
||||||
doc->SetMPath(RelativeMPath(fileName, customMeasureFile));
|
QScopedPointer<VPatternConverter> converter(futureConverter.result());
|
||||||
|
m_curFileFormatVersion = converter->GetCurrentFormatVersion();
|
||||||
|
m_curFileFormatVersionStr = converter->GetFormatVersionStr();
|
||||||
|
doc->setXMLContent(converter->Convert());
|
||||||
|
if (!customMeasureFile.isEmpty())
|
||||||
|
{
|
||||||
|
doc->SetMPath(RelativeMPath(fileName, customMeasureFile));
|
||||||
|
}
|
||||||
|
qApp->setPatternUnit(doc->MUnit());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!customMeasureFile.isEmpty())
|
||||||
|
{
|
||||||
|
doc->SetMPath(RelativeMPath(fileName, customMeasureFile));
|
||||||
|
}
|
||||||
|
qApp->setPatternUnit(doc->MUnit());
|
||||||
}
|
}
|
||||||
qApp->setPatternUnit(doc->MUnit());
|
|
||||||
const QString path = AbsoluteMPath(fileName, doc->MPath());
|
const QString path = AbsoluteMPath(fileName, doc->MPath());
|
||||||
|
|
||||||
if (not path.isEmpty())
|
if (not path.isEmpty())
|
||||||
|
@ -4610,6 +4631,20 @@ bool MainWindow::LoadPattern(QString fileName, const QString& customMeasureFile)
|
||||||
{// Show toolbar only if was not uploaded any measurements.
|
{// Show toolbar only if was not uploaded any measurements.
|
||||||
ToolBarOption();
|
ToolBarOption();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (currentFormatVersion == VPatternConverter::PatternMaxVer)
|
||||||
|
{
|
||||||
|
// Real read
|
||||||
|
QScopedPointer<VPatternConverter> converter(futureConverter.result());
|
||||||
|
m_curFileFormatVersion = converter->GetCurrentFormatVersion();
|
||||||
|
m_curFileFormatVersionStr = converter->GetFormatVersionStr();
|
||||||
|
doc->setXMLContent(converter->Convert());
|
||||||
|
if (!customMeasureFile.isEmpty())
|
||||||
|
{
|
||||||
|
doc->SetMPath(RelativeMPath(fileName, customMeasureFile));
|
||||||
|
}
|
||||||
|
qApp->setPatternUnit(doc->MUnit());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (VException &e)
|
catch (VException &e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -132,7 +132,7 @@ void VPattern::CreateEmptyFile()
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VPattern::setXMLContent(const QString &fileName)
|
void VPattern::setXMLContent(const QString &fileName)
|
||||||
{
|
{
|
||||||
VDomDocument::setXMLContent(fileName);
|
VAbstractPattern::setXMLContent(fileName);
|
||||||
GarbageCollector();
|
GarbageCollector();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ int FvUpdater::CurrentVersion()
|
||||||
QTextStream in(&file);
|
QTextStream in(&file);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return VAbstractConverter::GetVersion(in.read(15));
|
return VAbstractConverter::GetFormatVersion(in.read(15));
|
||||||
}
|
}
|
||||||
catch(const VException &)
|
catch(const VException &)
|
||||||
{
|
{
|
||||||
|
@ -569,7 +569,7 @@ bool FvUpdater::VersionIsIgnored(const QString &version)
|
||||||
int decVersion = 0x0;
|
int decVersion = 0x0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
decVersion = VAbstractConverter::GetVersion(version);
|
decVersion = VAbstractConverter::GetFormatVersion(version);
|
||||||
}
|
}
|
||||||
catch (const VException &e)
|
catch (const VException &e)
|
||||||
{
|
{
|
||||||
|
@ -608,7 +608,7 @@ void FvUpdater::IgnoreVersion(const QString &version)
|
||||||
int decVersion = 0x0;
|
int decVersion = 0x0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
decVersion = VAbstractConverter::GetVersion(version);
|
decVersion = VAbstractConverter::GetFormatVersion(version);
|
||||||
}
|
}
|
||||||
catch (const VException &e)
|
catch (const VException &e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -55,7 +55,7 @@ VAbstractConverter::VAbstractConverter(const QString &fileName)
|
||||||
m_tmpFile()
|
m_tmpFile()
|
||||||
{
|
{
|
||||||
setXMLContent(m_convertedFileName);// Throw an exception on error
|
setXMLContent(m_convertedFileName);// Throw an exception on error
|
||||||
m_ver = GetVersion(GetVersionStr());
|
m_ver = GetFormatVersion(GetFormatVersionStr());
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -92,84 +92,6 @@ int VAbstractConverter::GetCurrentFormatVersion() const
|
||||||
return m_ver;
|
return m_ver;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
QString VAbstractConverter::GetVersionStr() const
|
|
||||||
{
|
|
||||||
const QDomNodeList nodeList = this->elementsByTagName(TagVersion);
|
|
||||||
if (nodeList.isEmpty())
|
|
||||||
{
|
|
||||||
const QString errorMsg(tr("Couldn't get version information."));
|
|
||||||
throw VException(errorMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nodeList.count() > 1)
|
|
||||||
{
|
|
||||||
const QString errorMsg(tr("Too many tags <%1> in file.").arg(TagVersion));
|
|
||||||
throw VException(errorMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
const QDomNode domNode = nodeList.at(0);
|
|
||||||
if (domNode.isNull() == false && domNode.isElement())
|
|
||||||
{
|
|
||||||
const QDomElement domElement = domNode.toElement();
|
|
||||||
if (domElement.isNull() == false)
|
|
||||||
{
|
|
||||||
return domElement.text();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return QString(QStringLiteral("0.0.0"));
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
int VAbstractConverter::GetVersion(const QString &version)
|
|
||||||
{
|
|
||||||
ValidateVersion(version);
|
|
||||||
|
|
||||||
const QStringList ver = version.split(QChar('.'));
|
|
||||||
|
|
||||||
bool ok = false;
|
|
||||||
const int major = ver.at(0).toInt(&ok);
|
|
||||||
if (not ok)
|
|
||||||
{
|
|
||||||
return 0x0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ok = false;
|
|
||||||
const int minor = ver.at(1).toInt(&ok);
|
|
||||||
if (not ok)
|
|
||||||
{
|
|
||||||
return 0x0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ok = false;
|
|
||||||
const int patch = ver.at(2).toInt(&ok);
|
|
||||||
if (not ok)
|
|
||||||
{
|
|
||||||
return 0x0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (major<<16)|(minor<<8)|(patch);
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
void VAbstractConverter::ValidateVersion(const QString &version)
|
|
||||||
{
|
|
||||||
const QRegularExpression rx(QStringLiteral("^([0-9]|[1-9][0-9]|[1-2][0-5][0-5]).([0-9]|[1-9][0-9]|[1-2][0-5][0-5])"
|
|
||||||
".([0-9]|[1-9][0-9]|[1-2][0-5][0-5])$"));
|
|
||||||
|
|
||||||
if (rx.match(version).hasMatch() == false)
|
|
||||||
{
|
|
||||||
const QString errorMsg(tr("Version \"%1\" invalid.").arg(version));
|
|
||||||
throw VException(errorMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (version == QLatin1String("0.0.0"))
|
|
||||||
{
|
|
||||||
const QString errorMsg(tr("Version \"0.0.0\" invalid."));
|
|
||||||
throw VException(errorMsg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VAbstractConverter::ReserveFile() const
|
void VAbstractConverter::ReserveFile() const
|
||||||
{
|
{
|
||||||
|
@ -178,7 +100,7 @@ void VAbstractConverter::ReserveFile() const
|
||||||
QString error;
|
QString error;
|
||||||
QFileInfo info(m_convertedFileName);
|
QFileInfo info(m_convertedFileName);
|
||||||
const QString reserveFileName = QString("%1/%2(v%3).%4.bak")
|
const QString reserveFileName = QString("%1/%2(v%3).%4.bak")
|
||||||
.arg(info.absoluteDir().absolutePath(), info.baseName(), GetVersionStr(), info.completeSuffix());
|
.arg(info.absoluteDir().absolutePath(), info.baseName(), GetFormatVersionStr(), info.completeSuffix());
|
||||||
if (not SafeCopy(m_convertedFileName, reserveFileName, error))
|
if (not SafeCopy(m_convertedFileName, reserveFileName, error))
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
|
|
|
@ -56,9 +56,6 @@ public:
|
||||||
QString Convert();
|
QString Convert();
|
||||||
|
|
||||||
int GetCurrentFormatVersion() const;
|
int GetCurrentFormatVersion() const;
|
||||||
QString GetVersionStr() const;
|
|
||||||
|
|
||||||
static int GetVersion(const QString &version);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int m_ver;
|
int m_ver;
|
||||||
|
@ -90,8 +87,6 @@ private:
|
||||||
|
|
||||||
QTemporaryFile m_tmpFile;
|
QTemporaryFile m_tmpFile;
|
||||||
|
|
||||||
static void ValidateVersion(const QString &version);
|
|
||||||
|
|
||||||
void ReserveFile() const;
|
void ReserveFile() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -208,6 +208,13 @@ bool VAbstractPattern::patternLabelWasChanged = false;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
// Need to be reinited in setXMLContent as well
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(QString, patternNumberCached, (unknownCharacter))
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(QString, labelDateFormatCached, (unknownCharacter))
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(QString, patternNameCached, (unknownCharacter))
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(QString, MPathCached, (unknownCharacter))
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(QString, companyNameCached, (unknownCharacter))
|
||||||
|
|
||||||
void ReadExpressionAttribute(QVector<VFormulaField> &expressions, const QDomElement &element, const QString &attribute)
|
void ReadExpressionAttribute(QVector<VFormulaField> &expressions, const QDomElement &element, const QString &attribute)
|
||||||
{
|
{
|
||||||
VFormulaField formula;
|
VFormulaField formula;
|
||||||
|
@ -601,6 +608,18 @@ void VAbstractPattern::setCursor(const quint32 &value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VAbstractPattern::setXMLContent(const QString &fileName)
|
||||||
|
{
|
||||||
|
VDomDocument::setXMLContent(fileName);
|
||||||
|
|
||||||
|
*patternNumberCached = unknownCharacter;
|
||||||
|
*labelDateFormatCached = unknownCharacter;
|
||||||
|
*patternNameCached = unknownCharacter;
|
||||||
|
*MPathCached = unknownCharacter;
|
||||||
|
*companyNameCached = unknownCharacter;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief getTool return tool from tool list.
|
* @brief getTool return tool from tool list.
|
||||||
|
@ -807,7 +826,11 @@ QVector<VToolRecord> VAbstractPattern::getLocalHistory() const
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QString VAbstractPattern::MPath() const
|
QString VAbstractPattern::MPath() const
|
||||||
{
|
{
|
||||||
return UniqueTagText(TagMeasurements);
|
if (*MPathCached == unknownCharacter)
|
||||||
|
{
|
||||||
|
*MPathCached = UniqueTagText(TagMeasurements);
|
||||||
|
}
|
||||||
|
return *MPathCached;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -817,6 +840,7 @@ void VAbstractPattern::SetMPath(const QString &path)
|
||||||
{
|
{
|
||||||
emit patternChanged(false);
|
emit patternChanged(false);
|
||||||
patternLabelWasChanged = true;
|
patternLabelWasChanged = true;
|
||||||
|
*MPathCached = path;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1303,14 +1327,19 @@ void VAbstractPattern::SetNotes(const QString &text)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QString VAbstractPattern::GetPatternName() const
|
QString VAbstractPattern::GetPatternName() const
|
||||||
{
|
{
|
||||||
return UniqueTagText(TagPatternName);
|
if (*patternNameCached == unknownCharacter)
|
||||||
|
{
|
||||||
|
*patternNameCached = UniqueTagText(TagPatternName);
|
||||||
|
}
|
||||||
|
return *patternNameCached;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VAbstractPattern::SetPatternName(const QString &qsName)
|
void VAbstractPattern::SetPatternName(const QString &qsName)
|
||||||
{
|
{
|
||||||
|
*patternNameCached = qsName;
|
||||||
CheckTagExists(TagPatternName);
|
CheckTagExists(TagPatternName);
|
||||||
setTagText(TagPatternName, qsName);
|
setTagText(TagPatternName, *patternNameCached);
|
||||||
patternLabelWasChanged = true;
|
patternLabelWasChanged = true;
|
||||||
modified = true;
|
modified = true;
|
||||||
emit patternChanged(false);
|
emit patternChanged(false);
|
||||||
|
@ -1319,14 +1348,19 @@ void VAbstractPattern::SetPatternName(const QString &qsName)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QString VAbstractPattern::GetCompanyName() const
|
QString VAbstractPattern::GetCompanyName() const
|
||||||
{
|
{
|
||||||
return UniqueTagText(TagCompanyName);
|
if (*companyNameCached == unknownCharacter)
|
||||||
|
{
|
||||||
|
*companyNameCached = UniqueTagText(TagCompanyName);
|
||||||
|
}
|
||||||
|
return *companyNameCached;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VAbstractPattern::SetCompanyName(const QString& qsName)
|
void VAbstractPattern::SetCompanyName(const QString& qsName)
|
||||||
{
|
{
|
||||||
|
*companyNameCached = qsName;
|
||||||
CheckTagExists(TagCompanyName);
|
CheckTagExists(TagCompanyName);
|
||||||
setTagText(TagCompanyName, qsName);
|
setTagText(TagCompanyName, *companyNameCached);
|
||||||
patternLabelWasChanged = true;
|
patternLabelWasChanged = true;
|
||||||
modified = true;
|
modified = true;
|
||||||
emit patternChanged(false);
|
emit patternChanged(false);
|
||||||
|
@ -1335,14 +1369,19 @@ void VAbstractPattern::SetCompanyName(const QString& qsName)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QString VAbstractPattern::GetPatternNumber() const
|
QString VAbstractPattern::GetPatternNumber() const
|
||||||
{
|
{
|
||||||
return UniqueTagText(TagPatternNum);
|
if (*patternNumberCached == unknownCharacter)
|
||||||
|
{
|
||||||
|
*patternNumberCached = UniqueTagText(TagPatternNum);
|
||||||
|
}
|
||||||
|
return *patternNumberCached;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VAbstractPattern::SetPatternNumber(const QString& qsNum)
|
void VAbstractPattern::SetPatternNumber(const QString& qsNum)
|
||||||
{
|
{
|
||||||
|
*patternNumberCached = qsNum;
|
||||||
CheckTagExists(TagPatternNum);
|
CheckTagExists(TagPatternNum);
|
||||||
setTagText(TagPatternNum, qsNum);
|
setTagText(TagPatternNum, *patternNumberCached);
|
||||||
patternLabelWasChanged = true;
|
patternLabelWasChanged = true;
|
||||||
modified = true;
|
modified = true;
|
||||||
emit patternChanged(false);
|
emit patternChanged(false);
|
||||||
|
@ -1367,23 +1406,34 @@ void VAbstractPattern::SetCustomerName(const QString& qsName)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QString VAbstractPattern::GetLabelDateFormat() const
|
QString VAbstractPattern::GetLabelDateFormat() const
|
||||||
{
|
{
|
||||||
QString globalLabelDateFormat = qApp->Settings()->GetLabelDateFormat();
|
if (*labelDateFormatCached == unknownCharacter)
|
||||||
|
|
||||||
const QDomNodeList list = elementsByTagName(TagPatternLabel);
|
|
||||||
if (list.isEmpty())
|
|
||||||
{
|
{
|
||||||
return globalLabelDateFormat;
|
const QString globalLabelDateFormat = qApp->Settings()->GetLabelDateFormat();
|
||||||
}
|
|
||||||
|
|
||||||
QDomElement tag = list.at(0).toElement();
|
const QDomNodeList list = elementsByTagName(TagPatternLabel);
|
||||||
return GetParametrString(tag, AttrDateFormat, globalLabelDateFormat);
|
if (list.isEmpty())
|
||||||
|
{
|
||||||
|
return globalLabelDateFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
*labelDateFormatCached = GetParametrString(list.at(0).toElement(), AttrDateFormat);
|
||||||
|
}
|
||||||
|
catch (const VExceptionEmptyParameter &)
|
||||||
|
{
|
||||||
|
return globalLabelDateFormat;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return *labelDateFormatCached;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VAbstractPattern::SetLabelDateFormat(const QString &format)
|
void VAbstractPattern::SetLabelDateFormat(const QString &format)
|
||||||
{
|
{
|
||||||
|
*labelDateFormatCached = format;
|
||||||
QDomElement tag = CheckTagExists(TagPatternLabel);
|
QDomElement tag = CheckTagExists(TagPatternLabel);
|
||||||
SetAttribute(tag, AttrDateFormat, format);
|
SetAttribute(tag, AttrDateFormat, *labelDateFormatCached);
|
||||||
patternLabelWasChanged = true;
|
patternLabelWasChanged = true;
|
||||||
modified = true;
|
modified = true;
|
||||||
emit patternChanged(false);
|
emit patternChanged(false);
|
||||||
|
|
|
@ -105,6 +105,8 @@ public:
|
||||||
quint32 getCursor() const;
|
quint32 getCursor() const;
|
||||||
void setCursor(const quint32 &value);
|
void setCursor(const quint32 &value);
|
||||||
|
|
||||||
|
virtual void setXMLContent(const QString &fileName) override;
|
||||||
|
|
||||||
virtual void IncrementReferens(quint32 id) const=0;
|
virtual void IncrementReferens(quint32 id) const=0;
|
||||||
virtual void DecrementReferens(quint32 id) const=0;
|
virtual void DecrementReferens(quint32 id) const=0;
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,7 @@
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QtConcurrentRun>
|
#include <QtConcurrentRun>
|
||||||
#include <QFutureWatcher>
|
#include <QFutureWatcher>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -795,6 +796,65 @@ QString VDomDocument::Patch() const
|
||||||
return v.at(2);
|
return v.at(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QString VDomDocument::GetFormatVersionStr() const
|
||||||
|
{
|
||||||
|
const QDomNodeList nodeList = this->elementsByTagName(TagVersion);
|
||||||
|
if (nodeList.isEmpty())
|
||||||
|
{
|
||||||
|
const QString errorMsg(tr("Couldn't get version information."));
|
||||||
|
throw VException(errorMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nodeList.count() > 1)
|
||||||
|
{
|
||||||
|
const QString errorMsg(tr("Too many tags <%1> in file.").arg(TagVersion));
|
||||||
|
throw VException(errorMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
const QDomNode domNode = nodeList.at(0);
|
||||||
|
if (domNode.isNull() == false && domNode.isElement())
|
||||||
|
{
|
||||||
|
const QDomElement domElement = domNode.toElement();
|
||||||
|
if (domElement.isNull() == false)
|
||||||
|
{
|
||||||
|
return domElement.text();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QString(QStringLiteral("0.0.0"));
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
int VDomDocument::GetFormatVersion(const QString &version)
|
||||||
|
{
|
||||||
|
ValidateVersion(version);
|
||||||
|
|
||||||
|
const QStringList ver = version.split(QChar('.'));
|
||||||
|
|
||||||
|
bool ok = false;
|
||||||
|
const int major = ver.at(0).toInt(&ok);
|
||||||
|
if (not ok)
|
||||||
|
{
|
||||||
|
return 0x0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ok = false;
|
||||||
|
const int minor = ver.at(1).toInt(&ok);
|
||||||
|
if (not ok)
|
||||||
|
{
|
||||||
|
return 0x0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ok = false;
|
||||||
|
const int patch = ver.at(2).toInt(&ok);
|
||||||
|
if (not ok)
|
||||||
|
{
|
||||||
|
return 0x0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (major<<16)|(minor<<8)|(patch);
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
bool VDomDocument::setTagText(const QString &tag, const QString &text)
|
bool VDomDocument::setTagText(const QString &tag, const QString &text)
|
||||||
{
|
{
|
||||||
|
@ -992,3 +1052,22 @@ void VDomDocument::SetLabelTemplate(QDomElement &element, const QVector<VLabelTe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VDomDocument::ValidateVersion(const QString &version)
|
||||||
|
{
|
||||||
|
const QRegularExpression rx(QStringLiteral("^([0-9]|[1-9][0-9]|[1-2][0-5][0-5]).([0-9]|[1-9][0-9]|[1-2][0-5][0-5])"
|
||||||
|
".([0-9]|[1-9][0-9]|[1-2][0-5][0-5])$"));
|
||||||
|
|
||||||
|
if (rx.match(version).hasMatch() == false)
|
||||||
|
{
|
||||||
|
const QString errorMsg(tr("Version \"%1\" invalid.").arg(version));
|
||||||
|
throw VException(errorMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version == QLatin1String("0.0.0"))
|
||||||
|
{
|
||||||
|
const QString errorMsg(tr("Version \"0.0.0\" invalid."));
|
||||||
|
throw VException(errorMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -123,6 +123,8 @@ public:
|
||||||
QString Major() const;
|
QString Major() const;
|
||||||
QString Minor() const;
|
QString Minor() const;
|
||||||
QString Patch() const;
|
QString Patch() const;
|
||||||
|
QString GetFormatVersionStr() const;
|
||||||
|
static int GetFormatVersion(const QString &version);
|
||||||
static void RemoveAllChildren(QDomElement &domElement);
|
static void RemoveAllChildren(QDomElement &domElement);
|
||||||
|
|
||||||
QDomNode ParentNodeById(const quint32 &nodeId);
|
QDomNode ParentNodeById(const quint32 &nodeId);
|
||||||
|
@ -142,6 +144,8 @@ protected:
|
||||||
QString UniqueTagText(const QString &tagName, const QString &defVal = QString()) const;
|
QString UniqueTagText(const QString &tagName, const QString &defVal = QString()) const;
|
||||||
void CollectId(const QDomElement &node, QVector<quint32> &vector)const;
|
void CollectId(const QDomElement &node, QVector<quint32> &vector)const;
|
||||||
|
|
||||||
|
static void ValidateVersion(const QString &version);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void RefreshElementIdCache();
|
void RefreshElementIdCache();
|
||||||
|
|
||||||
|
|
|
@ -34,3 +34,4 @@ const QString preferencesOtherIcon = QStringLiteral("preferences-other");
|
||||||
const QString degreeSymbol = QStringLiteral("°");
|
const QString degreeSymbol = QStringLiteral("°");
|
||||||
const QString trueStr = QStringLiteral("true");
|
const QString trueStr = QStringLiteral("true");
|
||||||
const QString falseStr = QStringLiteral("false");
|
const QString falseStr = QStringLiteral("false");
|
||||||
|
const QString unknownCharacter = QStringLiteral("<EFBFBD>");
|
||||||
|
|
|
@ -40,5 +40,6 @@ extern const QString preferencesOtherIcon;
|
||||||
extern const QString degreeSymbol;
|
extern const QString degreeSymbol;
|
||||||
extern const QString trueStr;
|
extern const QString trueStr;
|
||||||
extern const QString falseStr;
|
extern const QString falseStr;
|
||||||
|
extern const QString unknownCharacter;
|
||||||
|
|
||||||
#endif // LITERALS_H
|
#endif // LITERALS_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user