diff --git a/src/app/dialogs/app/dialogincrements.cpp b/src/app/dialogs/app/dialogincrements.cpp index c95860b6b..055979b35 100644 --- a/src/app/dialogs/app/dialogincrements.cpp +++ b/src/app/dialogs/app/dialogincrements.cpp @@ -64,7 +64,7 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par { VDomDocument::ValidateXML("://schema/individual_measurements.xsd", filePath); m = new VIndividualMeasurements(data); - m->setContent(filePath); + m->setXMLContent(filePath); } catch (VException &e) { @@ -527,7 +527,7 @@ void DialogIncrements::OpenTable() VDomDocument::ValidateXML("://schema/individual_measurements.xsd", filePath); m1 = new VIndividualMeasurements(data); - m1->setContent(filePath); + m1->setXMLContent(filePath); } catch (VException &e) { @@ -567,7 +567,7 @@ void DialogIncrements::OpenTable() VDomDocument::ValidateXML("://schema/standard_measurements.xsd", filePath); m1 = new VStandardMeasurements(data); - m1->setContent(filePath); + m1->setXMLContent(filePath); Unit mUnit = m1->MUnit(); if (qApp->patternUnit() != mUnit) { diff --git a/src/app/dialogs/app/dialogindividualmeasurements.cpp b/src/app/dialogs/app/dialogindividualmeasurements.cpp index f7c8718ce..8adcc8649 100644 --- a/src/app/dialogs/app/dialogindividualmeasurements.cpp +++ b/src/app/dialogs/app/dialogindividualmeasurements.cpp @@ -111,7 +111,7 @@ void DialogIndividualMeasurements::DialogAccepted() { VDomDocument::ValidateXML("://schema/individual_measurements.xsd", _tablePath); VIndividualMeasurements m(data); - m.setContent(_tablePath); + m.setXMLContent(_tablePath); const qint32 index = ui->comboBoxUnits->currentIndex(); Unit unit = VDomDocument::StrToUnits(ui->comboBoxUnits->itemData(index).toString()); m.setUnit(unit); @@ -215,7 +215,7 @@ void DialogIndividualMeasurements::OpenTable() fileName.clear(); } VIndividualMeasurements m(data); - m.setContent(fileName); + m.setXMLContent(fileName); ui->labelGivenName->setText(m.GivenName()); ui->labelFamilyName->setText(m.FamilyName()); ui->lineEditPathExistM->setText(fileName); diff --git a/src/app/dialogs/app/dialogstandardmeasurements.cpp b/src/app/dialogs/app/dialogstandardmeasurements.cpp index e6701d4b5..356074ed7 100644 --- a/src/app/dialogs/app/dialogstandardmeasurements.cpp +++ b/src/app/dialogs/app/dialogstandardmeasurements.cpp @@ -99,7 +99,7 @@ void DialogStandardMeasurements::DialogAccepted() { VDomDocument::ValidateXML("://schema/standard_measurements.xsd", _tablePath); VStandardMeasurements m(data); - m.setContent(_tablePath); + m.setXMLContent(_tablePath); qApp->setPatternUnit(m.MUnit()); } catch (VException &e) @@ -170,7 +170,7 @@ void DialogStandardMeasurements::LoadStandardTables() { VDomDocument::ValidateXML("://schema/standard_measurements.xsd", fi.absoluteFilePath()); VStandardMeasurements m(data); - m.setContent(fi.absoluteFilePath()); + m.setXMLContent(fi.absoluteFilePath()); if (m.MUnit() == Unit::Inch) { qCWarning(vStMeasur)<<"We do not support inches for standard table. Ignore table" diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 4aff0a822..63219db05 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -167,7 +167,7 @@ void MainWindow::ActionNewPP() path = stMeasurements.tablePath(); qCDebug(vMainWindow)<<"Table path:"<setContent(fileName); + doc->setXMLContent(fileName); qApp->setPatternUnit(doc->MUnit()); qApp->setPatternType(doc->MType()); @@ -2369,7 +2369,7 @@ void MainWindow::LoadPattern(const QString &fileName) { VStandardMeasurements m(pattern); VDomDocument::ValidateXML("://schema/standard_measurements.xsd", path); - m.setContent(path); + m.setXMLContent(path); if (m.MUnit() == Unit::Inch) { QMessageBox::critical(this, tr("Wrong units."), diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index fc22c61d9..39ec6cca3 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -2572,14 +2572,14 @@ void VPattern::UpdateMeasurements() { VStandardMeasurements m(data); ValidateXML("://schema/standard_measurements.xsd", path); - m.setContent(path); + m.setXMLContent(path); m.Measurements(); } else { VIndividualMeasurements m(data); ValidateXML("://schema/individual_measurements.xsd", path); - m.setContent(path); + m.setXMLContent(path); m.Measurements(); } } diff --git a/src/libs/ifc/xml/vabstractconverter.cpp b/src/libs/ifc/xml/vabstractconverter.cpp index cfe0b6a50..0b9d2c220 100644 --- a/src/libs/ifc/xml/vabstractconverter.cpp +++ b/src/libs/ifc/xml/vabstractconverter.cpp @@ -27,9 +27,40 @@ *************************************************************************/ #include "vabstractconverter.h" +#include "exception/vexception.h" //--------------------------------------------------------------------------------------------------------------------- -VAbstractConverter::VAbstractConverter() - :VDomDocument() +VAbstractConverter::VAbstractConverter(const QString &fileName) + :VDomDocument(), fileName(fileName) { + this->setXMLContent(fileName); + QString version = GetVersionStr(); +} + +//--------------------------------------------------------------------------------------------------------------------- +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")); } diff --git a/src/libs/ifc/xml/vabstractconverter.h b/src/libs/ifc/xml/vabstractconverter.h index 39f5398f3..3886b042e 100644 --- a/src/libs/ifc/xml/vabstractconverter.h +++ b/src/libs/ifc/xml/vabstractconverter.h @@ -35,11 +35,14 @@ class VAbstractConverter :public VDomDocument { public: - VAbstractConverter(); + VAbstractConverter(const QString &fileName); virtual ~VAbstractConverter(){} private: Q_DISABLE_COPY(VAbstractConverter) + QString fileName; + + QString GetVersionStr() const; }; #endif // VABSTRACTCONVERTER_H diff --git a/src/libs/ifc/xml/vdomdocument.cpp b/src/libs/ifc/xml/vdomdocument.cpp index 1dd514e85..5dcf8d698 100644 --- a/src/libs/ifc/xml/vdomdocument.cpp +++ b/src/libs/ifc/xml/vdomdocument.cpp @@ -410,7 +410,7 @@ void VDomDocument::ValidateXML(const QString &schema, const QString &fileName) } //--------------------------------------------------------------------------------------------------------------------- -void VDomDocument::setContent(const QString &fileName) +void VDomDocument::setXMLContent(const QString &fileName) { QFile file(fileName); if (file.open(QIODevice::ReadOnly) == false) diff --git a/src/libs/ifc/xml/vdomdocument.h b/src/libs/ifc/xml/vdomdocument.h index a8e29ebb3..34aa2215f 100644 --- a/src/libs/ifc/xml/vdomdocument.h +++ b/src/libs/ifc/xml/vdomdocument.h @@ -106,7 +106,7 @@ public: qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue) const; static void ValidateXML(const QString &schema, const QString &fileName); - void setContent(const QString &fileName); + void setXMLContent(const QString &fileName); static Unit StrToUnits(const QString &unit); static QString UnitsToStr(const Unit &unit, const bool translate = false); virtual bool SaveDocument(const QString &fileName, QString &error); diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index 7d3ba374b..c763499a4 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -29,8 +29,8 @@ #include "vpatternconverter.h" //--------------------------------------------------------------------------------------------------------------------- -VPatternConverter::VPatternConverter() - :VAbstractConverter() +VPatternConverter::VPatternConverter(const QString &fileName) + :VAbstractConverter(fileName) { } diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index 295d10563..435c8e1e7 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -34,7 +34,7 @@ class VPatternConverter : public VAbstractConverter { public: - VPatternConverter(); + VPatternConverter(const QString &fileName); static QString CurrentSchema(); };