diff --git a/src/container/vmeasurement.cpp b/src/container/vmeasurement.cpp index 5f9b9b56f..3aa743ce6 100644 --- a/src/container/vmeasurement.cpp +++ b/src/container/vmeasurement.cpp @@ -29,14 +29,23 @@ #include "vmeasurement.h" VMeasurement::VMeasurement() - :base(0), ksize(50.0), kheight(176.0), gui_text(QString()), number(QString()){} + :base(0), ksize(50.0), kheight(176.0), gui_text(QString()), number(QString()), virtualM(false), + _tagName(QString()) +{ + +} VMeasurement::VMeasurement(const qreal &base, const qreal &ksize, const qreal &kgrowth, - const QString &gui_text, const QString &number) - :base(base), ksize(ksize), kheight(kgrowth), gui_text(gui_text), number(number){} + const QString &gui_text, const QString &number, const QString &tagName) + :base(base), ksize(ksize), kheight(kgrowth), gui_text(gui_text), number(number), virtualM(false), + _tagName(tagName) +{ -VMeasurement::VMeasurement(const qreal &base, const QString &gui_text, const QString &number) - :base(base), ksize(50.0), kheight(176.0), gui_text(gui_text), number(number) +} + +VMeasurement::VMeasurement(const qreal &base, const QString &gui_text, const QString &number, const QString &tagName) + :base(base), ksize(50.0), kheight(176.0), gui_text(gui_text), number(number), virtualM(false), + _tagName(tagName) { } @@ -52,3 +61,7 @@ qreal VMeasurement::GetValue(const qreal &size, const qreal &height) const const qreal k_height = ( height - 176.0 ) / 6.0; return base + k_size * ksize + k_height * kheight; } + + + + diff --git a/src/container/vmeasurement.h b/src/container/vmeasurement.h index 7942df8d7..4dab3e8f4 100644 --- a/src/container/vmeasurement.h +++ b/src/container/vmeasurement.h @@ -49,15 +49,17 @@ public: * @param description description of increment */ VMeasurement(const qreal &base, const qreal &ksize, const qreal &kheight, - const QString &gui_text = QString(), const QString &number = QString()); + const QString &gui_text = QString(), const QString &number = QString(), + const QString &TagName = QString()); VMeasurement(const qreal &base, const QString &gui_text = QString(), - const QString &number = QString()); + const QString &number = QString(), const QString &TagName = QString()); ~VMeasurement(){} /** * @brief GetBase return value in base size and growth * @return value */ qreal GetBase() const; + void setBase(const qreal &value); /** * @brief GetKsize return increment in sizes * @return increment @@ -76,6 +78,10 @@ public: QString GetNumber() const; qreal GetValue() const; qreal GetValue(const qreal &size, const qreal &height) const; + QString TagName() const; + void setTagName(const QString &TagName); + bool Virtual() const; + void setVirtual(bool value); private: /** * @brief base value in base size and growth @@ -94,6 +100,8 @@ private: */ QString gui_text; QString number; + bool virtualM; + QString _tagName; }; inline qreal VMeasurement::GetBase() const @@ -101,6 +109,11 @@ inline qreal VMeasurement::GetBase() const return base; } +inline void VMeasurement::setBase(const qreal &value) +{ + base = value; +} + inline qreal VMeasurement::GetKsize() const { return ksize; @@ -121,4 +134,24 @@ inline QString VMeasurement::GetNumber() const return number; } +inline QString VMeasurement::TagName() const +{ + return _tagName; +} + +inline void VMeasurement::setTagName(const QString &tagName) +{ + _tagName = tagName; +} + +inline bool VMeasurement::Virtual() const +{ + return virtualM; +} + +inline void VMeasurement::setVirtual(bool value) +{ + virtualM = value; +} + #endif // VSTANDARDTABLEROW_H diff --git a/src/dialogs/app/dialogincrements.cpp b/src/dialogs/app/dialogincrements.cpp index 963d7e8c4..549cc687f 100644 --- a/src/dialogs/app/dialogincrements.cpp +++ b/src/dialogs/app/dialogincrements.cpp @@ -33,17 +33,18 @@ #include "../../exception/vexception.h" #include +#include DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *parent) - :DialogTool(data, parent), ui(new Ui::DialogIncrements), data(data), doc(doc), row(0), column(0) + :DialogTool(data, parent), ui(new Ui::DialogIncrements), data(data), doc(doc), row(0), column(0), m(nullptr) { ui->setupUi(this); TextDelegate *textDelegate = new TextDelegate(ui->tableWidgetIncrement); - ui->tableWidgetIncrement->setItemDelegateForColumn(0, textDelegate); + ui->tableWidgetIncrement->setItemDelegateForColumn(0, textDelegate);// name DoubleSpinBoxDelegate *doubleDelegate = new DoubleSpinBoxDelegate(ui->tableWidgetIncrement); - ui->tableWidgetIncrement->setItemDelegateForColumn(2, doubleDelegate); - ui->tableWidgetIncrement->setItemDelegateForColumn(3, doubleDelegate); - ui->tableWidgetIncrement->setItemDelegateForColumn(4, doubleDelegate); + ui->tableWidgetIncrement->setItemDelegateForColumn(2, doubleDelegate);// base value + ui->tableWidgetIncrement->setItemDelegateForColumn(3, doubleDelegate);// in sizes + ui->tableWidgetIncrement->setItemDelegateForColumn(4, doubleDelegate);// in heights if (qApp->patternType() == Pattern::Standard) { @@ -58,16 +59,15 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par } else { - ui->tableWidgetMeasurements->setColumnHidden( 1, true ); - ui->tableWidgetMeasurements->setColumnHidden( 3, true ); - ui->tableWidgetMeasurements->setColumnHidden( 4, true ); + ui->tableWidgetMeasurements->setColumnHidden( 1, true );// calculated value + ui->tableWidgetMeasurements->setColumnHidden( 3, true );// in sizes + ui->tableWidgetMeasurements->setColumnHidden( 4, true );// in heights - ui->tableWidgetIncrement->setColumnHidden( 1, true ); - ui->tableWidgetIncrement->setColumnHidden( 3, true ); - ui->tableWidgetIncrement->setColumnHidden( 4, true ); + ui->tableWidgetIncrement->setColumnHidden( 1, true );// calculated value + ui->tableWidgetIncrement->setColumnHidden( 3, true );// in sizes + ui->tableWidgetIncrement->setColumnHidden( 4, true );// in heights - ui->tableWidgetMeasurements->setItemDelegateForColumn(0, textDelegate); - ui->tableWidgetMeasurements->setItemDelegateForColumn(2, doubleDelegate); + ui->tableWidgetMeasurements->setItemDelegateForColumn(2, doubleDelegate);// base value connect(ui->tableWidgetMeasurements, &QTableWidget::cellChanged, this, &DialogIncrements::MeasurementsChanged); } @@ -87,21 +87,66 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par connect(this->doc, &VPattern::FullUpdateFromFile, this, &DialogIncrements::FullUpdateFromFile); ui->tabWidget->setCurrentIndex(0); + + if (qApp->patternType() == Pattern::Individual) + { + QString filePath = doc->MPath(); + QFile file(filePath); + if (file.open(QIODevice::ReadOnly)) + { + try + { + VDomDocument::ValidatePattern("://schema/individual_measurements.xsd", filePath); + } + catch(VException &e) + { + qWarning()<<"Validation file error."<setContent(&file); + } + catch(VException &e) + { + qWarning()<<"Parsing measurements file error."< *table = data->DataMeasurements(); - qint32 currentRow = -1; QHashIterator i(*table); - ui->tableWidgetMeasurements->setRowCount ( table->size() ); + QMap map; + //Sorting QHash by id while (i.hasNext()) { i.next(); - VMeasurement m = i.value(); + map.insert(i.key(), i.value()); + } + qint32 currentRow = -1; + QMapIterator iMap(map); + ui->tableWidgetMeasurements->setRowCount ( table->size() ); + while (iMap.hasNext()) + { + iMap.next(); + VMeasurement m = iMap.value(); currentRow++; - QTableWidgetItem *item = new QTableWidgetItem(QString(i.key())); + QTableWidgetItem *item = new QTableWidgetItem(QString(iMap.key())); item->setTextAlignment(Qt::AlignHCenter); item->setFont(QFont("Times", 12, QFont::Bold)); item->setToolTip(m.GetDescription()); @@ -109,7 +154,7 @@ void DialogIncrements::FillMeasurements() if (qApp->patternType() == Pattern::Standard) { - QTableWidgetItem *item = new QTableWidgetItem(QString().setNum(data->GetValueStandardTableRow(i.key()))); + QTableWidgetItem *item = new QTableWidgetItem(QString().setNum(data->GetValueStandardTableRow(iMap.key()))); item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetMeasurements->setItem(currentRow, 1, item); } @@ -133,9 +178,9 @@ void DialogIncrements::FillMeasurements() item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetMeasurements->setItem(currentRow, 5, item); } + ui->tableWidgetMeasurements->verticalHeader()->setDefaultSectionSize(20); ui->tableWidgetMeasurements->resizeColumnsToContents(); ui->tableWidgetMeasurements->resizeRowsToContents(); - ui->tableWidgetMeasurements->verticalHeader()->setDefaultSectionSize(20); } void DialogIncrements::FillIncrements() @@ -305,21 +350,20 @@ void DialogIncrements::FillLengthArcs() item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetArcs->setItem(currentRow, 1, item); } + ui->tableWidgetArcs->verticalHeader()->setDefaultSectionSize(20); ui->tableWidgetArcs->resizeColumnsToContents(); ui->tableWidgetArcs->resizeRowsToContents(); - ui->tableWidgetArcs->verticalHeader()->setDefaultSectionSize(20); } void DialogIncrements::FullUpdateFromFile() { - disconnect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, - &DialogIncrements::IncrementChanged); - ui->tableWidgetMeasurements->clearContents(); FillMeasurements(); + disconnect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, &DialogIncrements::IncrementChanged); ui->tableWidgetIncrement->clearContents(); FillIncrements(); + connect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, &DialogIncrements::IncrementChanged); ui->tableWidgetLines->clearContents(); FillLengthLines(); @@ -329,9 +373,6 @@ void DialogIncrements::FullUpdateFromFile() ui->tableWidgetArcs->clearContents(); FillLengthArcs(); - - connect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, - &DialogIncrements::IncrementChanged); } void DialogIncrements::clickedToolButtonAdd() @@ -350,15 +391,12 @@ void DialogIncrements::clickedToolButtonAdd() num++; } while (data->IncrementTableContains(name)); - quint32 id = data->getNextId(); - qreal base = 0; - qreal ksize = 0; - qreal kgrowth = 0; - QString description = QString(tr("Description")); - VIncrement incr = VIncrement(id, base, ksize, kgrowth, description); + const quint32 id = data->getNextId(); + const QString description(tr("Description")); + VIncrement incr = VIncrement(id, 0, 0, 0, description); data->AddIncrement(name, incr); - AddIncrementToFile(id, name, base, ksize, kgrowth, description); + AddIncrementToFile(id, name, 0, 0, 0, description); QTableWidgetItem *item = new QTableWidgetItem(name); item->setTextAlignment(Qt::AlignHCenter); @@ -367,7 +405,7 @@ void DialogIncrements::clickedToolButtonAdd() ui->tableWidgetIncrement->setItem(currentRow, 0, item); ui->tableWidgetIncrement->setCurrentCell(currentRow, 0, QItemSelectionModel::ClearAndSelect); - item = new QTableWidgetItem("0"); + item = new QTableWidgetItem("0");// calculated value item->setTextAlignment(Qt::AlignHCenter); // set the item non-editable (view only), and non-selectable Qt::ItemFlags flags = item->flags(); @@ -375,19 +413,19 @@ void DialogIncrements::clickedToolButtonAdd() item->setFlags(flags); ui->tableWidgetIncrement->setItem(currentRow, 1, item); - item = new QTableWidgetItem("0"); + item = new QTableWidgetItem("0");// base value item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetIncrement->setItem(currentRow, 2, item); - item = new QTableWidgetItem("0"); + item = new QTableWidgetItem("0");// in sizes item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetIncrement->setItem(currentRow, 3, item); - item = new QTableWidgetItem("0"); + item = new QTableWidgetItem("0"); // in heights item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetIncrement->setItem(currentRow, 4, item); - item = new QTableWidgetItem(tr("Description")); + item = new QTableWidgetItem(description); item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetIncrement->setItem(currentRow, 5, item); @@ -409,7 +447,7 @@ void DialogIncrements::clickedToolButtonRemove() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - QDomNodeList list = doc->elementsByTagName("increments"); + QDomNodeList list = doc->elementsByTagName(VPattern::TagIncrements); list.at(0).removeChild(domElement); } ui->tableWidgetIncrement->removeRow(row); @@ -422,134 +460,115 @@ void DialogIncrements::clickedToolButtonRemove() emit haveLiteChange(); } -void DialogIncrements::AddIncrementToFile(quint32 id, QString name, qreal base, qreal ksize, qreal kgrowth, - QString description) +void DialogIncrements::AddIncrementToFile(const quint32 &id, const QString &name, const qreal &base, const qreal &ksize, + const qreal &kheight, const QString &description) { - QDomNodeList list = doc->elementsByTagName("increments"); - QDomElement element = doc->createElement("increment"); + QDomElement element = doc->createElement(VPattern::TagIncrement); - QDomAttr drawAttr = doc->createAttribute("id"); - drawAttr.setValue(QString().setNum(id)); - element.setAttributeNode(drawAttr); - - drawAttr = doc->createAttribute("name"); - drawAttr.setValue(name); - element.setAttributeNode(drawAttr); - - drawAttr = doc->createAttribute("base"); - drawAttr.setValue(QString().setNum(base)); - element.setAttributeNode(drawAttr); - - drawAttr = doc->createAttribute("ksize"); - drawAttr.setValue(QString().setNum(ksize)); - element.setAttributeNode(drawAttr); - - drawAttr = doc->createAttribute("kgrowth"); - drawAttr.setValue(QString().setNum(kgrowth)); - element.setAttributeNode(drawAttr); - - drawAttr = doc->createAttribute("description"); - drawAttr.setValue(description); - element.setAttributeNode(drawAttr); + doc->SetAttribute(element, VDomDocument::AttrId, id); + doc->SetAttribute(element, VPattern::IncrementName, name); + doc->SetAttribute(element, VPattern::IncrementBase, base); + doc->SetAttribute(element, VPattern::IncrementKsize, ksize); + doc->SetAttribute(element, VPattern::IncrementKgrowth, kheight); + doc->SetAttribute(element, VPattern::IncrementDescription, description); + QDomNodeList list = doc->elementsByTagName(VPattern::TagIncrements); list.at(0).appendChild(element); } void DialogIncrements::IncrementChanged ( qint32 row, qint32 column ) { - QTableWidgetItem *item = nullptr; - QTableWidgetItem *itemName = nullptr; - quint32 id; - QDomElement domElement; + + const QTableWidgetItem *itemName = ui->tableWidgetIncrement->item(row, 0); + const QTableWidgetItem *item = ui->tableWidgetIncrement->item(row, column); + const quint32 id = qvariant_cast(itemName->data(Qt::UserRole)); + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement() == false) + { + qWarning()<<"Cant't find increment with id = "<row = row; switch (column) { - case 0: // name - item = ui->tableWidgetIncrement->item(row, 0); - id = qvariant_cast(item->data(Qt::UserRole)); - domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - domElement.setAttribute("name", item->text()); - data->ClearIncrementTable(); - this->column = 2; - emit FullUpdateTree(); - emit haveLiteChange(); - } + case 0: // VPattern::IncrementName + doc->SetAttribute(domElement, VPattern::IncrementName, item->text()); + data->ClearIncrementTable(); + this->column = 2; + emit FullUpdateTree(); break; - case 2: // base - itemName = ui->tableWidgetIncrement->item(row, 0); - item = ui->tableWidgetIncrement->item(row, column); - id = qvariant_cast(itemName->data(Qt::UserRole)); - domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - bool ok = false; - qreal value = item->text().replace(",", ".").toDouble(&ok); - if (ok) - { - domElement.setAttribute("base", value); - this->column = 3; - emit FullUpdateTree(); - emit haveLiteChange(); - } - else - { - throw VException(tr("Can't convert toDouble value.")); - } - } + case 2: // VPattern::IncrementBase + doc->SetAttribute(domElement, VPattern::IncrementBase, item->text()); + this->column = 3; + emit FullUpdateTree(); break; - case 3: // ksize - itemName = ui->tableWidgetIncrement->item(row, 0); - item = ui->tableWidgetIncrement->item(row, column); - id = qvariant_cast(itemName->data(Qt::UserRole)); - domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - domElement.setAttribute("ksize", item->text().replace(",", ".").toDouble()); - this->column = 4; - emit FullUpdateTree(); - emit haveLiteChange(); - } + case 3: // VPattern::IncrementKsize + doc->SetAttribute(domElement, VPattern::IncrementKsize, item->text()); + this->column = 4; + emit FullUpdateTree(); break; - case 4: // kgrowth - itemName = ui->tableWidgetIncrement->item(row, 0); - item = ui->tableWidgetIncrement->item(row, column); - id = qvariant_cast(itemName->data(Qt::UserRole)); - domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - domElement.setAttribute("kgrowth", item->text().replace(",", ".").toDouble()); - this->column = 5; - emit FullUpdateTree(); - emit haveLiteChange(); - } + case 4: // VPattern::IncrementKgrowth + doc->SetAttribute(domElement, VPattern::IncrementKgrowth, item->text()); + this->column = 5; + emit FullUpdateTree(); break; - case 5: // description - itemName = ui->tableWidgetIncrement->item(row, 0); - item = ui->tableWidgetIncrement->item(row, column); - id = qvariant_cast(itemName->data(Qt::UserRole)); - domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - domElement.setAttribute("description", item->text()); - VIncrement incr = data->GetIncrement(itemName->text()); - incr.setDescription(item->text()); - data->UpdateIncrement(itemName->text(), incr); - ui->tableWidgetIncrement->resizeColumnsToContents(); - ui->tableWidgetIncrement->resizeRowsToContents(); - ui->tableWidgetIncrement->setCurrentCell( row, 0 ); - emit haveLiteChange(); - } + case 5: // VPattern::IncrementDescription + { + doc->SetAttribute(domElement, VPattern::IncrementDescription, item->text()); + VIncrement incr = data->GetIncrement(itemName->text()); + incr.setDescription(item->text()); + data->UpdateIncrement(itemName->text(), incr); + ui->tableWidgetIncrement->resizeColumnsToContents(); + ui->tableWidgetIncrement->resizeRowsToContents(); + this->column = 0; + ui->tableWidgetIncrement->setCurrentCell( row, this->column ); break; + } default: break; } + emit haveLiteChange(); } void DialogIncrements::MeasurementsChanged(qint32 row, qint32 column) { + const QTableWidgetItem *itemName = ui->tableWidgetMeasurements->item(row, 0); + QTableWidgetItem *item = ui->tableWidgetMeasurements->item(row, 2); + VMeasurement measur = data->GetMeasurement(itemName->text()); + const QString tag = measur.TagName(); + VIndividualMeasurements m(data); + QDomNodeList list = m.elementsByTagName(tag); + QDomElement domElement = list.at(0).toElement(); + if (domElement.isElement() == false) + { + qWarning()<<"Cant't find measurement "<text()); + bool ok = false; + const qreal base = item->text().replace(",", ".").toDouble(&ok); + if (ok == false) + { + measur.setBase(0); + item->setText("0"); + qWarning()<<"Can't convert toDouble measurement value"<UpdateMeasurement(itemName->text(), measur); + break; + } + default: + break; + } + emit haveLiteChange(); } void DialogIncrements::closeEvent(QCloseEvent *event) diff --git a/src/dialogs/app/dialogincrements.h b/src/dialogs/app/dialogincrements.h index bb8256880..eb920b00c 100644 --- a/src/dialogs/app/dialogincrements.h +++ b/src/dialogs/app/dialogincrements.h @@ -31,6 +31,7 @@ #include "../tools/dialogtool.h" #include "../../xml/vpattern.h" +#include "../../xml/vindividualmeasurements.h" namespace Ui { @@ -105,6 +106,7 @@ private: * @brief column save number of column current selected cell */ qint32 column; + VIndividualMeasurements *m; /** * @brief FillMeasurements load measurements data */ @@ -131,11 +133,11 @@ private: * @param name name * @param base base value * @param ksize increment in sizes - * @param kgrowth increment in growths + * @param kheight increment in heights * @param description description of increment */ - void AddIncrementToFile(quint32 id, QString name, qreal base, qreal ksize, qreal kgrowth, - QString description); + void AddIncrementToFile(const quint32 &id, const QString &name, const qreal &base, + const qreal &ksize, const qreal &kheight, const QString &description); }; #endif // DIALOGINCREMENTS_H diff --git a/src/dialogs/app/dialogindividualmeasurements.cpp b/src/dialogs/app/dialogindividualmeasurements.cpp index 96e2e0e06..e5cf13870 100644 --- a/src/dialogs/app/dialogindividualmeasurements.cpp +++ b/src/dialogs/app/dialogindividualmeasurements.cpp @@ -217,7 +217,7 @@ void DialogIndividualMeasurements::LoadIndividualTables() { try { - VDomDocument::ValidatePattern("://schema/standard_measurements.xsd", allFiles.at(i)); + VDomDocument::ValidatePattern("://schema/individual_measurements.xsd", allFiles.at(i)); } catch(VException &e) { diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 873cb7bef..5a5afc784 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -49,8 +49,9 @@ MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainWindow), pattern(nullptr), doc(nullptr), tool(Valentina::ArrowTool), currentScene(nullptr), sceneDraw(nullptr), sceneDetails(nullptr), mouseCoordinate(nullptr), helpLabel(nullptr), view(nullptr), isInitialized(false), dialogTable(0), dialogTool(nullptr), dialogHistory(nullptr), - comboBoxDraws(nullptr), curFile(QString()), mode(Valentina::Calculation), currentDrawIndex(0), currentToolBoxIndex(0), - drawMode(true), recentFileActs{0, 0, 0, 0, 0}, separatorAct(nullptr), autoSaveTimer(nullptr) + comboBoxDraws(nullptr), curFile(QString()), mode(Valentina::Calculation), currentDrawIndex(0), + currentToolBoxIndex(0), drawMode(true), recentFileActs{0, 0, 0, 0, 0}, separatorAct(nullptr), + autoSaveTimer(nullptr) { CreateActions(); CreateMenus(); diff --git a/src/tools/drawTools/vtoolalongline.cpp b/src/tools/drawTools/vtoolalongline.cpp index 789a51a1c..ac8e65204 100644 --- a/src/tools/drawTools/vtoolalongline.cpp +++ b/src/tools/drawTools/vtoolalongline.cpp @@ -84,7 +84,7 @@ void VToolAlongLine::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, AttrId, id); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrName, point->name()); doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); diff --git a/src/tools/drawTools/vtoolarc.cpp b/src/tools/drawTools/vtoolarc.cpp index b47f5d495..032ca5d9b 100644 --- a/src/tools/drawTools/vtoolarc.cpp +++ b/src/tools/drawTools/vtoolarc.cpp @@ -182,7 +182,7 @@ void VToolArc::AddToFile() const VArc *arc = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, AttrId, id); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrCenter, arc->GetCenter().id()); doc->SetAttribute(domElement, AttrRadius, arc->GetFormulaRadius()); diff --git a/src/tools/drawTools/vtoolbisector.cpp b/src/tools/drawTools/vtoolbisector.cpp index 3656b4d2c..34bf702b6 100644 --- a/src/tools/drawTools/vtoolbisector.cpp +++ b/src/tools/drawTools/vtoolbisector.cpp @@ -182,7 +182,7 @@ void VToolBisector::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, AttrId, id); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrName, point->name()); doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); diff --git a/src/tools/drawTools/vtoolcutarc.cpp b/src/tools/drawTools/vtoolcutarc.cpp index 1b8c7ca6f..ef3ccad11 100644 --- a/src/tools/drawTools/vtoolcutarc.cpp +++ b/src/tools/drawTools/vtoolcutarc.cpp @@ -205,7 +205,7 @@ void VToolCutArc::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, AttrId, id); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrName, point->name()); doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); diff --git a/src/tools/drawTools/vtoolcutspline.cpp b/src/tools/drawTools/vtoolcutspline.cpp index 89ee51eb6..9c0e88a96 100644 --- a/src/tools/drawTools/vtoolcutspline.cpp +++ b/src/tools/drawTools/vtoolcutspline.cpp @@ -201,7 +201,7 @@ void VToolCutSpline::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, AttrId, id); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrName, point->name()); doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); diff --git a/src/tools/drawTools/vtoolcutsplinepath.cpp b/src/tools/drawTools/vtoolcutsplinepath.cpp index eabb9ba70..da87b2d83 100644 --- a/src/tools/drawTools/vtoolcutsplinepath.cpp +++ b/src/tools/drawTools/vtoolcutsplinepath.cpp @@ -275,7 +275,7 @@ void VToolCutSplinePath::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, AttrId, id); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrName, point->name()); doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); diff --git a/src/tools/drawTools/vtoolendline.cpp b/src/tools/drawTools/vtoolendline.cpp index 04a7201f4..98603c373 100644 --- a/src/tools/drawTools/vtoolendline.cpp +++ b/src/tools/drawTools/vtoolendline.cpp @@ -148,7 +148,7 @@ void VToolEndLine::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, AttrId, id); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrName, point->name()); doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); diff --git a/src/tools/drawTools/vtoolheight.cpp b/src/tools/drawTools/vtoolheight.cpp index b662422fb..5a0640718 100644 --- a/src/tools/drawTools/vtoolheight.cpp +++ b/src/tools/drawTools/vtoolheight.cpp @@ -154,7 +154,7 @@ void VToolHeight::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, AttrId, id); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrName, point->name()); doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); diff --git a/src/tools/drawTools/vtoolline.cpp b/src/tools/drawTools/vtoolline.cpp index 78cdea854..143022e42 100644 --- a/src/tools/drawTools/vtoolline.cpp +++ b/src/tools/drawTools/vtoolline.cpp @@ -155,7 +155,7 @@ void VToolLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) void VToolLine::AddToFile() { QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, AttrId, id); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrFirstPoint, firstPoint); doc->SetAttribute(domElement, AttrSecondPoint, secondPoint); doc->SetAttribute(domElement, AttrTypeLine, typeLine); diff --git a/src/tools/drawTools/vtoollineintersect.cpp b/src/tools/drawTools/vtoollineintersect.cpp index b607fcdf2..9598a3873 100644 --- a/src/tools/drawTools/vtoollineintersect.cpp +++ b/src/tools/drawTools/vtoollineintersect.cpp @@ -165,7 +165,7 @@ void VToolLineIntersect::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, AttrId, id); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrName, point->name()); doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); diff --git a/src/tools/drawTools/vtoolnormal.cpp b/src/tools/drawTools/vtoolnormal.cpp index 60c5e82d6..83b00e6af 100644 --- a/src/tools/drawTools/vtoolnormal.cpp +++ b/src/tools/drawTools/vtoolnormal.cpp @@ -168,7 +168,7 @@ void VToolNormal::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, AttrId, id); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrName, point->name()); doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); diff --git a/src/tools/drawTools/vtoolpointofcontact.cpp b/src/tools/drawTools/vtoolpointofcontact.cpp index 4f65ed382..b1221b45e 100644 --- a/src/tools/drawTools/vtoolpointofcontact.cpp +++ b/src/tools/drawTools/vtoolpointofcontact.cpp @@ -188,7 +188,7 @@ void VToolPointOfContact::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, AttrId, id); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrName, point->name()); doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); diff --git a/src/tools/drawTools/vtoolpointofintersection.cpp b/src/tools/drawTools/vtoolpointofintersection.cpp index 724999ede..c66fc0c04 100644 --- a/src/tools/drawTools/vtoolpointofintersection.cpp +++ b/src/tools/drawTools/vtoolpointofintersection.cpp @@ -138,7 +138,7 @@ void VToolPointOfIntersection::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, AttrId, id); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrName, point->name()); doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); diff --git a/src/tools/drawTools/vtoolshoulderpoint.cpp b/src/tools/drawTools/vtoolshoulderpoint.cpp index e96df9315..255fd6bfe 100644 --- a/src/tools/drawTools/vtoolshoulderpoint.cpp +++ b/src/tools/drawTools/vtoolshoulderpoint.cpp @@ -190,7 +190,7 @@ void VToolShoulderPoint::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, AttrId, id); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrName, point->name()); doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); diff --git a/src/tools/drawTools/vtoolsinglepoint.cpp b/src/tools/drawTools/vtoolsinglepoint.cpp index 757aded00..b723bff54 100644 --- a/src/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/tools/drawTools/vtoolsinglepoint.cpp @@ -66,7 +66,7 @@ void VToolSinglePoint::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, AttrId, id); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrName, point->name()); doc->SetAttribute(domElement, AttrX, qApp->fromPixel(point->x())); diff --git a/src/tools/drawTools/vtoolspline.cpp b/src/tools/drawTools/vtoolspline.cpp index 49c192724..6c545c5ee 100644 --- a/src/tools/drawTools/vtoolspline.cpp +++ b/src/tools/drawTools/vtoolspline.cpp @@ -176,7 +176,7 @@ void VToolSpline::AddToFile() const VSpline *spl = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, AttrId, id); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrPoint1, spl->GetP1().id()); doc->SetAttribute(domElement, AttrPoint4, spl->GetP4().id()); diff --git a/src/tools/drawTools/vtoolsplinepath.cpp b/src/tools/drawTools/vtoolsplinepath.cpp index ac7a43dd7..50586b9b6 100644 --- a/src/tools/drawTools/vtoolsplinepath.cpp +++ b/src/tools/drawTools/vtoolsplinepath.cpp @@ -214,7 +214,7 @@ void VToolSplinePath::AddToFile() VSplinePath splPath = *VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, AttrId, id); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrKCurve, splPath.getKCurve()); diff --git a/src/tools/drawTools/vtooltriangle.cpp b/src/tools/drawTools/vtooltriangle.cpp index 2467d527f..5fb1a7a0f 100644 --- a/src/tools/drawTools/vtooltriangle.cpp +++ b/src/tools/drawTools/vtooltriangle.cpp @@ -194,7 +194,7 @@ void VToolTriangle::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, AttrId, id); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrName, point->name()); doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); diff --git a/src/tools/nodeDetails/vnodearc.cpp b/src/tools/nodeDetails/vnodearc.cpp index f8e84eb4b..c115458f6 100644 --- a/src/tools/nodeDetails/vnodearc.cpp +++ b/src/tools/nodeDetails/vnodearc.cpp @@ -93,7 +93,7 @@ void VNodeArc::AddToFile() { QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, AttrId, id); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrIdObject, idNode); if (idTool != 0) diff --git a/src/tools/nodeDetails/vnodepoint.cpp b/src/tools/nodeDetails/vnodepoint.cpp index bdb6e7949..25126cf02 100644 --- a/src/tools/nodeDetails/vnodepoint.cpp +++ b/src/tools/nodeDetails/vnodepoint.cpp @@ -105,7 +105,7 @@ void VNodePoint::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, AttrId, id); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrIdObject, idNode); doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); diff --git a/src/tools/nodeDetails/vnodespline.cpp b/src/tools/nodeDetails/vnodespline.cpp index e20ee9078..3ffd0ad8f 100644 --- a/src/tools/nodeDetails/vnodespline.cpp +++ b/src/tools/nodeDetails/vnodespline.cpp @@ -97,7 +97,7 @@ void VNodeSpline::AddToFile() { QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, AttrId, id); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrIdObject, idNode); if (idTool != 0) diff --git a/src/tools/nodeDetails/vnodesplinepath.cpp b/src/tools/nodeDetails/vnodesplinepath.cpp index d3b6a436c..5c3c208b8 100644 --- a/src/tools/nodeDetails/vnodesplinepath.cpp +++ b/src/tools/nodeDetails/vnodesplinepath.cpp @@ -100,7 +100,7 @@ void VNodeSplinePath::AddToFile() { QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, AttrId, id); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrIdObject, idNode); if (idTool != 0) diff --git a/src/tools/vabstracttool.cpp b/src/tools/vabstracttool.cpp index 81337c83d..b61174d58 100644 --- a/src/tools/vabstracttool.cpp +++ b/src/tools/vabstracttool.cpp @@ -28,7 +28,6 @@ #include "vabstracttool.h" -const QString VAbstractTool::AttrId = QStringLiteral("id"); const QString VAbstractTool::AttrType = QStringLiteral("type"); const QString VAbstractTool::AttrMx = QStringLiteral("mx"); const QString VAbstractTool::AttrMy = QStringLiteral("my"); diff --git a/src/tools/vabstracttool.h b/src/tools/vabstracttool.h index 430d2d290..74cb53a17 100644 --- a/src/tools/vabstracttool.h +++ b/src/tools/vabstracttool.h @@ -102,7 +102,6 @@ public: * @param c c value */ static void LineCoefficients(const QLineF &line, qreal *a, qreal *b, qreal *c); - static const QString AttrId; static const QString AttrType; static const QString AttrMx; static const QString AttrMy; diff --git a/src/tools/vtooldetail.cpp b/src/tools/vtooldetail.cpp index 42c6caddb..641cf5ab7 100644 --- a/src/tools/vtooldetail.cpp +++ b/src/tools/vtooldetail.cpp @@ -228,7 +228,7 @@ void VToolDetail::AddToFile() VDetail detail = VAbstractTool::data.GetDetail(id); QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, AttrId, id); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrName, detail.getName()); doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(detail.getMx())); doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(detail.getMy())); diff --git a/src/tools/vtooluniondetails.cpp b/src/tools/vtooluniondetails.cpp index 73efd7f9a..aebabf4a4 100644 --- a/src/tools/vtooluniondetails.cpp +++ b/src/tools/vtooluniondetails.cpp @@ -615,7 +615,7 @@ void VToolUnionDetails::AddToFile() { QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, AttrId, id); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrIndexD1, indexD1); doc->SetAttribute(domElement, AttrIndexD2, indexD2); diff --git a/src/xml/vdomdocument.cpp b/src/xml/vdomdocument.cpp index bff6d5c19..a6464c53d 100644 --- a/src/xml/vdomdocument.cpp +++ b/src/xml/vdomdocument.cpp @@ -77,6 +77,12 @@ inline qint64 MessageHandler::column() const return m_sourceLocation.column(); } +const QString VDomDocument::AttrId = QStringLiteral("id"); +const QString VDomDocument::AttrUnit = QStringLiteral("unit"); +const QString VDomDocument::UnitMM = QStringLiteral("mm"); +const QString VDomDocument::UnitCM = QStringLiteral("cm"); +const QString VDomDocument::UnitIN = QStringLiteral("in"); + VDomDocument::VDomDocument(VContainer *data) : QDomDocument(), data(data), map(QHash()) { @@ -122,9 +128,9 @@ void VDomDocument::removeAllChilds(QDomElement &element) bool VDomDocument::find(const QDomElement &node, const QString& id) { - if (node.hasAttribute("id")) + if (node.hasAttribute(AttrId)) { - const QString value = node.attribute("id"); + const QString value = node.attribute(AttrId); this->map[value] = node; if (value == id) { @@ -311,7 +317,7 @@ void VDomDocument::setContent(QIODevice *dev) Valentina::Units VDomDocument::Units(const QString &unit) { QStringList units; - units << "mm" << "cm" << "in"; + units << UnitMM << UnitCM << UnitIN; Valentina::Units result = Valentina::Cm; switch (units.indexOf(unit)) { diff --git a/src/xml/vdomdocument.h b/src/xml/vdomdocument.h index bfe95376c..6692d0760 100644 --- a/src/xml/vdomdocument.h +++ b/src/xml/vdomdocument.h @@ -47,6 +47,11 @@ class VDomDocument : public QDomDocument { Q_DECLARE_TR_FUNCTIONS(VDomDocument) public: + static const QString AttrId; + static const QString AttrUnit; + static const QString UnitMM; + static const QString UnitCM; + static const QString UnitIN; /** * @brief VDomDocument constructor. * @param data container with variables. @@ -162,13 +167,20 @@ template <> inline void VDomDocument::SetAttribute(QDomElement &domElement, const QString &name, const Valentina::Units &value) { - if (value == Valentina::Cm || value == Valentina::Mm) + switch(value) { - domElement.setAttribute(name, "cm"); - } - else - { - domElement.setAttribute(name, "in"); + case Valentina::Mm: + domElement.setAttribute(name, "mm"); + break; + case Valentina::Cm: + domElement.setAttribute(name, "cm"); + break; + case Valentina::In: + domElement.setAttribute(name, "in"); + break; + default: + domElement.setAttribute(name, "cm"); + break; } } diff --git a/src/xml/vindividualmeasurements.cpp b/src/xml/vindividualmeasurements.cpp index e474fd179..375e56198 100644 --- a/src/xml/vindividualmeasurements.cpp +++ b/src/xml/vindividualmeasurements.cpp @@ -28,13 +28,25 @@ #include "vindividualmeasurements.h" +const QString VIndividualMeasurements::AttrIgnore = QStringLiteral("ignore"); +const QString VIndividualMeasurements::AttrName = QStringLiteral("name"); +const QString VIndividualMeasurements::AttrM_number = QStringLiteral("m_number"); +const QString VIndividualMeasurements::AttrGui_text = QStringLiteral("gui_text"); +const QString VIndividualMeasurements::AttrValue = QStringLiteral("value"); +const QString VIndividualMeasurements::AttrDescription = QStringLiteral("description"); +const QString VIndividualMeasurements::AttrLang = QStringLiteral("lang"); +const QString VIndividualMeasurements::AttrFamily_name = QStringLiteral("family-name"); +const QString VIndividualMeasurements::AttrGiven_name = QStringLiteral("given-name"); +const QString VIndividualMeasurements::AttrBirth_date = QStringLiteral("birth-date"); +const QString VIndividualMeasurements::AttrSex = QStringLiteral("sex"); + VIndividualMeasurements::VIndividualMeasurements(VContainer *data):VDomDocument(data) { } Valentina::Units VIndividualMeasurements::Unit() { - const QString unit = UniqueTagText("unit", "cm"); + const QString unit = UniqueTagText(AttrUnit, UnitCM); return VDomDocument::Units(unit); } @@ -145,24 +157,24 @@ void VIndividualMeasurements::Measurement(const QString &tag) const QDomElement domElement = domNode.toElement(); if (domElement.isNull() == false) { - const bool ignore = QVariant(GetParametrString(domElement, "ignore", "false")).toBool(); + const bool ignore = QVariant(GetParametrString(domElement, AttrIgnore, "false")).toBool(); if (ignore) { return; } - const QString name = GetParametrString(domElement, "name", ""); + const QString name = GetParametrString(domElement, AttrName, ""); if (name.isEmpty()) { return; } - const QString m_number = GetParametrString(domElement, "m_number", ""); - const QString gui_text = GetParametrString(domElement, "gui_text", ""); - const qreal value = GetParametrDouble(domElement, "value", "0.0"); - const QString description = GetParametrString(domElement, "description", ""); + const QString m_number = GetParametrString(domElement, AttrM_number, ""); + const QString gui_text = GetParametrString(domElement, AttrGui_text, ""); + const qreal value = GetParametrDouble(domElement, AttrValue, "0.0"); + const QString description = GetParametrString(domElement, AttrDescription, ""); if (Unit() == Valentina::Mm)//Convert to Cm. { - data->AddMeasurement(name, VMeasurement(value/10.0, gui_text, description)); + data->AddMeasurement(name, VMeasurement(value/10.0, gui_text, description, tag)); if (m_number.isEmpty()) { qWarning()<<"Can't find language-independent measurement name for "<< tag; @@ -170,12 +182,14 @@ void VIndividualMeasurements::Measurement(const QString &tag) } else { - data->AddMeasurement(m_number, VMeasurement(value/10.0, gui_text, description)); + VMeasurement m(value/10.0, gui_text, description, tag); + m.setVirtual(true); + data->AddMeasurement(m_number, m); } } else//Cm or inch. { - data->AddMeasurement(name, VMeasurement(value, gui_text, description)); + data->AddMeasurement(name, VMeasurement(value, gui_text, description, tag)); if (m_number.isEmpty()) { qWarning()<<"Can't find language-independent measurement name for "<< tag; @@ -183,7 +197,9 @@ void VIndividualMeasurements::Measurement(const QString &tag) } else { - data->AddMeasurement(m_number, VMeasurement(value, gui_text, description)); + VMeasurement m(value, gui_text, description, tag); + m.setVirtual(true); + data->AddMeasurement(m_number, m); } } } @@ -193,25 +209,25 @@ void VIndividualMeasurements::Measurement(const QString &tag) QString VIndividualMeasurements::Language() { - return UniqueTagText("lang", "en"); + return UniqueTagText(AttrLang, "en"); } QString VIndividualMeasurements::FamilyName() { - return UniqueTagText("family-name", ""); + return UniqueTagText(AttrFamily_name, ""); } QString VIndividualMeasurements::GivenName() { - return UniqueTagText("given-name", ""); + return UniqueTagText(AttrGiven_name, ""); } QString VIndividualMeasurements::BirthDate() { - return UniqueTagText("birth-date", ""); + return UniqueTagText(AttrBirth_date, ""); } QString VIndividualMeasurements::Sex() { - return UniqueTagText("sex", ""); + return UniqueTagText(AttrSex, ""); } diff --git a/src/xml/vindividualmeasurements.h b/src/xml/vindividualmeasurements.h index 55931039d..d2742c289 100644 --- a/src/xml/vindividualmeasurements.h +++ b/src/xml/vindividualmeasurements.h @@ -43,6 +43,17 @@ public: QString GivenName(); QString BirthDate(); QString Sex(); + static const QString AttrIgnore; + static const QString AttrName; + static const QString AttrM_number; + static const QString AttrGui_text; + static const QString AttrValue; + static const QString AttrDescription; + static const QString AttrLang; + static const QString AttrFamily_name; + static const QString AttrGiven_name; + static const QString AttrBirth_date; + static const QString AttrSex; }; #endif // VINDIVIDUALMEASUREMENTS_H diff --git a/src/xml/vpattern.cpp b/src/xml/vpattern.cpp index 61ab9a593..b236a987b 100644 --- a/src/xml/vpattern.cpp +++ b/src/xml/vpattern.cpp @@ -57,6 +57,7 @@ const QString VPattern::TagTools = QStringLiteral("tools"); const QString VPattern::AttrName = QStringLiteral("name"); const QString VPattern::AttrType = QStringLiteral("type"); +const QString VPattern::AttrPath = QStringLiteral("path"); const QString VPattern::IncrementName = QStringLiteral("name"); const QString VPattern::IncrementBase = QStringLiteral("base"); @@ -84,9 +85,9 @@ void VPattern::CreateEmptyFile(const QString &tablePath) patternElement.appendChild(createElement(TagNotes)); QDomElement measurements = createElement(TagMeasurements); - SetAttribute(measurements, "unit", qApp->patternUnit()); - SetAttribute(measurements, "type", qApp->patternType()); - SetAttribute(measurements, "path", tablePath); + SetAttribute(measurements, AttrUnit, qApp->patternUnit()); + SetAttribute(measurements, AttrType, qApp->patternType()); + SetAttribute(measurements, AttrPath, tablePath); patternElement.appendChild(measurements); patternElement.appendChild(createElement(TagIncrements)); @@ -412,6 +413,79 @@ bool VPattern::GetActivNodeElement(const QString &name, QDomElement &element) return false; } +QString VPattern::MPath() const +{ + QDomNodeList list = elementsByTagName(VPattern::TagMeasurements); + QDomElement element = list.at(0).toElement(); + if (element.isElement()) + { + return GetParametrString(element, AttrPath); + } + else + { + return QString(); + } +} + +Valentina::Units VPattern::MUnit() const +{ + QDomNodeList list = elementsByTagName(VPattern::TagMeasurements); + QDomElement element = list.at(0).toElement(); + if (element.isElement()) + { + QStringList units; + units << "mm" << "cm" << "in"; + QString unit = GetParametrString(element, AttrUnit); + switch(units.indexOf(unit)) + { + case 0:// mm + return Valentina::Mm; + break; + case 1:// cm + return Valentina::Cm; + break; + case 2:// in + return Valentina::In; + break; + default: + return Valentina::Cm; + break; + } + } + else + { + return Valentina::Cm; + } +} + +Pattern::Measurements VPattern::MType() const +{ + QDomNodeList list = elementsByTagName(VPattern::TagMeasurements); + QDomElement element = list.at(0).toElement(); + if (element.isElement()) + { + QString type = GetParametrString(element, AttrType); + QStringList types; + types << "standard" << "individual"; + switch(types.indexOf(type)) + { + case 0:// standard + return Pattern::Standard; + break; + case 1:// individual + return Pattern::Individual; + break; + default: + return Pattern::Individual; + break; + } + } + else + { + return Pattern::Individual; + } +} + void VPattern::FullUpdateTree() { VMainGraphicsScene *scene = new VMainGraphicsScene(); @@ -1263,7 +1337,7 @@ quint32 VPattern::GetParametrId(const QDomElement &domElement) const QString message = tr("Got wrong parameter id. Need only id > 0."); try { - id = GetParametrUInt(domElement, VAbstractTool::AttrId, "0"); + id = GetParametrUInt(domElement, VDomDocument::AttrId, "0"); if (id <= 0) { throw VExceptionWrongId(message, domElement); @@ -1280,7 +1354,7 @@ quint32 VPattern::GetParametrId(const QDomElement &domElement) const void VPattern::CollectId(const QDomElement &node, QVector &vector) const { - if (node.hasAttribute(VAbstractTool::AttrId)) + if (node.hasAttribute(VDomDocument::AttrId)) { const quint32 id = GetParametrId(node); if (vector.contains(id)) diff --git a/src/xml/vpattern.h b/src/xml/vpattern.h index d51f6cd16..f1e559543 100644 --- a/src/xml/vpattern.h +++ b/src/xml/vpattern.h @@ -165,6 +165,9 @@ public: * @return true if found. */ bool GetActivNodeElement(const QString& name, QDomElement& element); + QString MPath() const; + Valentina::Units MUnit() const; + Pattern::Measurements MType() const; static const QString TagPattern; static const QString TagCalculation; static const QString TagModeling; @@ -183,6 +186,7 @@ public: static const QString TagTools; static const QString AttrName; static const QString AttrType; + static const QString AttrPath; static const QString IncrementName; static const QString IncrementBase; static const QString IncrementKsize; diff --git a/src/xml/vstandardmeasurements.cpp b/src/xml/vstandardmeasurements.cpp index cf146f807..204687dfb 100644 --- a/src/xml/vstandardmeasurements.cpp +++ b/src/xml/vstandardmeasurements.cpp @@ -29,19 +29,30 @@ #include "vstandardmeasurements.h" #include +const QString VStandardMeasurements::TagMeasurement = QStringLiteral("measurement"); +const QString VStandardMeasurements::TagDescription = QStringLiteral("description"); +const QString VStandardMeasurements::TagSize = QStringLiteral("size"); +const QString VStandardMeasurements::TagHeight = QStringLiteral("height"); +const QString VStandardMeasurements::AttrName = QStringLiteral("name"); +const QString VStandardMeasurements::AttrGui_text = QStringLiteral("gui_text"); +const QString VStandardMeasurements::AttrBase = QStringLiteral("base"); +const QString VStandardMeasurements::AttrSize_increace = QStringLiteral("size_increace"); +const QString VStandardMeasurements::AttrHeight_increase = QStringLiteral("height_increase"); +const QString VStandardMeasurements::AttrNumber = QStringLiteral("number"); + VStandardMeasurements::VStandardMeasurements(VContainer *data):VDomDocument(data) { } Valentina::Units VStandardMeasurements::Unit() { - const QString unit = UniqueTagText("unit", "cm"); + const QString unit = UniqueTagText(AttrUnit, UnitCM); return VDomDocument::Units(unit); } QString VStandardMeasurements::Description() { - const QString desc = UniqueTagText("description", ""); + const QString desc = UniqueTagText(TagDescription, ""); if (desc.isEmpty()) { qWarning()<<"Empty description in standard table."<elementsByTagName("measurement"); + const QDomNodeList nodeList = this->elementsByTagName(TagMeasurement); if (nodeList.isEmpty()) { qWarning()<<"Measurement list is empty"<AddMeasurement(name, VMeasurement(base/10.0, size_increace/10.0, height_increase/10.0, gui_text, number)); } - else//Cm or inch. + else// Cm or inch. { data->AddMeasurement(name, VMeasurement(base, size_increace, height_increase, gui_text, number)); @@ -96,7 +107,7 @@ void VStandardMeasurements::Measurements() void VStandardMeasurements::SetSize() { - const QDomNodeList nodeList = this->elementsByTagName("size"); + const QDomNodeList nodeList = this->elementsByTagName(TagSize); if (nodeList.isEmpty()) { data->SetSize(50); @@ -110,14 +121,14 @@ void VStandardMeasurements::SetSize() const QDomElement domElement = domNode.toElement(); if (domElement.isNull() == false) { - const QString name = GetParametrString(domElement, "name", "Сг"); - const qreal base = GetParametrDouble(domElement, "base", "50.0"); - if (Unit() == Valentina::Mm)//Convert to Cm. + const QString name = GetParametrString(domElement, AttrName, "Сг"); + const qreal base = GetParametrDouble(domElement, AttrBase, "50.0"); + if (Unit() == Valentina::Mm)// Convert to Cm. { data->SetSize(base/10.0); data->SetSizeName(name); } - else//Cm or inch. + else// Cm or inch. { data->SetSize(base); data->SetSizeName(name); @@ -129,7 +140,7 @@ void VStandardMeasurements::SetSize() void VStandardMeasurements::SetHeight() { - const QDomNodeList nodeList = this->elementsByTagName("height"); + const QDomNodeList nodeList = this->elementsByTagName(TagHeight); if (nodeList.isEmpty()) { data->SetHeight(176); @@ -143,14 +154,14 @@ void VStandardMeasurements::SetHeight() const QDomElement domElement = domNode.toElement(); if (domElement.isNull() == false) { - const QString name = GetParametrString(domElement, "name", "Р"); - const qreal base = GetParametrDouble(domElement, "base", "176.0"); - if (Unit() == Valentina::Mm)//Convert to Cm. + const QString name = GetParametrString(domElement, AttrName, "Р"); + const qreal base = GetParametrDouble(domElement, AttrBase, "176.0"); + if (Unit() == Valentina::Mm)// Convert to Cm. { data->SetHeight(base/10.0); data->SetHeightName(name); } - else//Cm or inch. + else// Cm or inch. { data->SetHeight(base); data->SetHeightName(name); diff --git a/src/xml/vstandardmeasurements.h b/src/xml/vstandardmeasurements.h index 327c32caa..822df44b0 100644 --- a/src/xml/vstandardmeasurements.h +++ b/src/xml/vstandardmeasurements.h @@ -41,6 +41,16 @@ public: void Measurements(); void SetSize(); void SetHeight(); + static const QString TagMeasurement; + static const QString TagDescription; + static const QString TagSize; + static const QString TagHeight; + static const QString AttrName; + static const QString AttrGui_text; + static const QString AttrBase; + static const QString AttrSize_increace; + static const QString AttrHeight_increase; + static const QString AttrNumber; public slots: void Update(); };