From eaf69753315e42c19b63ef2b452ea75ae33e6874 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 8 Oct 2020 13:34:38 +0300 Subject: [PATCH] Dimension labels. --- .../tape/dialogs/dialogdimensionlabels.cpp | 223 ++++++++++++++++++ src/app/tape/dialogs/dialogdimensionlabels.h | 82 +++++++ src/app/tape/dialogs/dialogdimensionlabels.ui | 136 +++++++++++ .../tape/dialogs/dialogrestrictdimension.cpp | 64 ++++- src/app/tape/tape.pri | 3 + src/app/tape/tmainwindow.cpp | 89 +++++-- src/app/tape/tmainwindow.h | 2 + src/app/tape/tmainwindow.ui | 12 + .../schema/standard_measurements/v0.5.0.xsd | 14 ++ src/libs/vformat/vdimensions.h | 30 ++- src/libs/vformat/vmeasurements.cpp | 108 +++++++++ src/libs/vformat/vmeasurements.h | 8 + 12 files changed, 736 insertions(+), 35 deletions(-) create mode 100644 src/app/tape/dialogs/dialogdimensionlabels.cpp create mode 100644 src/app/tape/dialogs/dialogdimensionlabels.h create mode 100644 src/app/tape/dialogs/dialogdimensionlabels.ui diff --git a/src/app/tape/dialogs/dialogdimensionlabels.cpp b/src/app/tape/dialogs/dialogdimensionlabels.cpp new file mode 100644 index 000000000..fc5d4e0d4 --- /dev/null +++ b/src/app/tape/dialogs/dialogdimensionlabels.cpp @@ -0,0 +1,223 @@ +/************************************************************************ + ** + ** @file dialogdimensionlabels.cpp + ** @author Roman Telezhynskyi + ** @date 8 10, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ +#include "dialogdimensionlabels.h" +#include "ui_dialogdimensionlabels.h" + +//--------------------------------------------------------------------------------------------------------------------- +DialogDimensionLabels::DialogDimensionLabels(const QMap &dimensions, bool fullCircumference, + QWidget *parent) + : QDialog(parent), + ui(new Ui::DialogDimensionLabels), + m_dimensions(dimensions), + m_fullCircumference(fullCircumference) +{ + ui->setupUi(this); + + InitLabels(); + + InitDimensions(); + InitTable(); + + connect(ui->comboBoxDimensionLabels, QOverload::of(&QComboBox::currentIndexChanged), this, + &DialogDimensionLabels::DimensionChanged); + connect(ui->tableWidget, &QTableWidget::itemChanged, this, &DialogDimensionLabels::LabelChanged); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogDimensionLabels::~DialogDimensionLabels() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDimensionLabels::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::LanguageChange) + { + // retranslate designer form (single inheritance approach) + ui->retranslateUi(this); + + MeasurementDimension type = + static_cast(ui->comboBoxDimensionLabels->currentData().toInt()); + + InitDimensions(); + + int index = ui->comboBoxDimensionLabels->findData(static_cast(type)); + if (index != -1) + { + ui->comboBoxDimensionLabels->blockSignals(true); + ui->comboBoxDimensionLabels->setCurrentIndex(index); + ui->comboBoxDimensionLabels->blockSignals(false); + } + + const int row = ui->tableWidget->currentRow(); + InitTable(); + ui->tableWidget->blockSignals(true); + ui->tableWidget->selectRow(row); + ui->tableWidget->blockSignals(false); + } + + // remember to call base class implementation + QDialog::changeEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDimensionLabels::DimensionChanged() +{ + InitTable(); + ui->tableWidget->selectRow(0); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDimensionLabels::LabelChanged(QTableWidgetItem *item) +{ + if (item) + { + MeasurementDimension type = + static_cast(ui->comboBoxDimensionLabels->currentData().toInt()); + int value = item->data(Qt::UserRole).toInt(); + + DimesionLabels labels = m_labels.value(type); + labels.insert(value, item->text()); + + m_labels.insert(type, labels); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDimensionLabels::InitLabels() +{ + m_labels.clear(); + + const QList dimensions = m_dimensions.values(); + + for(auto &dimension : dimensions) + { + m_labels.insert(dimension->Type(), dimension->Labels()); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDimensionLabels::InitDimensions() +{ + ui->comboBoxDimensionLabels->blockSignals(true); + ui->comboBoxDimensionLabels->clear(); + + for(auto &dimension : m_dimensions) + { + ui->comboBoxDimensionLabels->addItem(VAbstartMeasurementDimension::DimensionName(dimension->Type()), + static_cast(dimension->Type())); + } + + ui->comboBoxDimensionLabels->blockSignals(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDimensionLabels::InitTable() +{ + ui->tableWidget->blockSignals(true); + ui->tableWidget->clearContents(); + + const MeasurementDimension type = + static_cast(ui->comboBoxDimensionLabels->currentData().toInt()); + + MeasurementDimension_p dimension; + + if (m_dimensions.contains(type)) + { + dimension = m_dimensions.value(type); + } + + if (dimension.isNull()) + { + return; + } + + const QVector bases = dimension->ValidBases(); + + ui->tableWidget->setRowCount(bases.size()); + + const DimesionLabels labels = m_labels.value(type); + + for(int row = 0; row < bases.size(); ++row) + { + const int base = bases.at(row); + + { + auto *itemValue = new QTableWidgetItem(DimensionValue(dimension, base)); + itemValue->setData(Qt::UserRole, base); + itemValue->setTextAlignment(Qt::AlignHCenter | Qt::AlignCenter); + + // set the item non-editable (view only), and non-selectable + Qt::ItemFlags flags = itemValue->flags(); + flags &= ~(Qt::ItemIsEditable); // reset/clear the flag + itemValue->setFlags(flags); + + ui->tableWidget->setItem(row, 0, itemValue); + } + + { + auto *itemLabel = new QTableWidgetItem(labels.value(base)); + itemLabel->setData(Qt::UserRole, base); + itemLabel->setTextAlignment(Qt::AlignHCenter | Qt::AlignCenter); + + ui->tableWidget->setItem(row, 1, itemLabel); + } + } + + ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + ui->tableWidget->blockSignals(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogDimensionLabels::DimensionValue(const MeasurementDimension_p &dimension, int value) +{ + QStringList labels; + + if (dimension->Type() == MeasurementDimension::X) + { + return QString::number(value); + } + else if (dimension->Type() == MeasurementDimension::Y) + { + if (dimension->IsCircumference()) + { + return QString::number(m_fullCircumference ? value*2 : value); + } + else + { + return QString::number(value); + } + } + else if (dimension->Type() == MeasurementDimension::W || dimension->Type() == MeasurementDimension::Z) + { + return QString::number(m_fullCircumference ? value*2 : value); + } + + return QString::number(value); +} diff --git a/src/app/tape/dialogs/dialogdimensionlabels.h b/src/app/tape/dialogs/dialogdimensionlabels.h new file mode 100644 index 000000000..7ef85bbf3 --- /dev/null +++ b/src/app/tape/dialogs/dialogdimensionlabels.h @@ -0,0 +1,82 @@ +/************************************************************************ + ** + ** @file dialogdimensionlabels.h + ** @author Roman Telezhynskyi + ** @date 8 10, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ +#ifndef DIALOGDIMENSIONLABELS_H +#define DIALOGDIMENSIONLABELS_H + +#include +#include + +#include "../vformat/vdimensions.h" + +namespace Ui +{ +class DialogDimensionLabels; +} + +class QTableWidgetItem; + +class DialogDimensionLabels : public QDialog +{ + Q_OBJECT + +public: + explicit DialogDimensionLabels(const QMap &dimensions, + bool fullCircumference, QWidget *parent = nullptr); + virtual ~DialogDimensionLabels(); + + QMap Labels() const; + +protected: + virtual void changeEvent(QEvent* event) override; + +private slots: + void DimensionChanged(); + void LabelChanged(QTableWidgetItem *item); + +private: + Q_DISABLE_COPY(DialogDimensionLabels) + Ui::DialogDimensionLabels *ui; + + QMap m_dimensions; + QMap m_labels{}; + bool m_fullCircumference; + + void InitLabels(); + void InitDimensions(); + void InitTable(); + + QString DimensionValue(const MeasurementDimension_p &dimension, int value); +}; + +//--------------------------------------------------------------------------------------------------------------------- +inline QMap DialogDimensionLabels::Labels() const +{ + return m_labels; +} + +#endif // DIALOGDIMENSIONLABELS_H diff --git a/src/app/tape/dialogs/dialogdimensionlabels.ui b/src/app/tape/dialogs/dialogdimensionlabels.ui new file mode 100644 index 000000000..4dbf89a00 --- /dev/null +++ b/src/app/tape/dialogs/dialogdimensionlabels.ui @@ -0,0 +1,136 @@ + + + DialogDimensionLabels + + + + 0 + 0 + 345 + 424 + + + + Dimension labels + + + + :/tapeicon/64x64/logo.png:/tapeicon/64x64/logo.png + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Dimension: + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + true + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + false + + + + Value + + + + + Label + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + DialogDimensionLabels + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogDimensionLabels + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/app/tape/dialogs/dialogrestrictdimension.cpp b/src/app/tape/dialogs/dialogrestrictdimension.cpp index dde1feca7..e9053ce41 100644 --- a/src/app/tape/dialogs/dialogrestrictdimension.cpp +++ b/src/app/tape/dialogs/dialogrestrictdimension.cpp @@ -538,26 +538,41 @@ void DialogRestrictDimension::FillBases(const QVector &bases, const Measure { SCASSERT(control != nullptr) + const DimesionLabels labels = dimension->Labels(); const QString units = UnitsToStr(dimension->Units(), true); if (dimension->Type() == MeasurementDimension::X) { for(auto base : bases) { - control->addItem(QString("%1 %2").arg(base).arg(units), base); + if (labels.contains(base) && not labels.value(base).isEmpty()) + { + control->addItem(labels.value(base), base); + } + else + { + control->addItem(QString("%1 %2").arg(base).arg(units), base); + } } } else if (dimension->Type() == MeasurementDimension::Y) { for(auto base : bases) { - if (dimension->IsCircumference()) + if (labels.contains(base) && not labels.value(base).isEmpty()) { - control->addItem(QString("%1 %2").arg(m_fullCircumference ? base*2 : base).arg(units), base); + control->addItem(labels.value(base), base); } else { - control->addItem(QString::number(base), base); + if (dimension->IsCircumference()) + { + control->addItem(QString("%1 %2").arg(m_fullCircumference ? base*2 : base).arg(units), base); + } + else + { + control->addItem(QString::number(base), base); + } } } } @@ -565,7 +580,14 @@ void DialogRestrictDimension::FillBases(const QVector &bases, const Measure { for(auto base : bases) { - control->addItem(QString("%1 %2").arg(m_fullCircumference ? base*2 : base).arg(units), base); + if (labels.contains(base) && not labels.value(base).isEmpty()) + { + control->addItem(labels.value(base), base); + } + else + { + control->addItem(QString("%1 %2").arg(m_fullCircumference ? base*2 : base).arg(units), base); + } } } } @@ -575,6 +597,7 @@ QStringList DialogRestrictDimension::DimensionLabels(const QVector &bases, { const bool showUnits = dimension->IsCircumference() || dimension->Type() == MeasurementDimension::X; const QString units = showUnits ? UnitsToStr(dimension->Units(), true) : QString(); + const DimesionLabels dimensionLabels = dimension->Labels(); QStringList labels; @@ -582,20 +605,34 @@ QStringList DialogRestrictDimension::DimensionLabels(const QVector &bases, { for(auto base : bases) { - labels.append(QString("%1 %2").arg(base).arg(units)); + if (dimensionLabels.contains(base) && not dimensionLabels.value(base).isEmpty()) + { + labels.append(dimensionLabels.value(base)); + } + else + { + labels.append(QString("%1 %2").arg(base).arg(units)); + } } } else if (dimension->Type() == MeasurementDimension::Y) { for(auto base : bases) { - if (dimension->IsCircumference()) + if (dimensionLabels.contains(base) && not dimensionLabels.value(base).isEmpty()) { - labels.append(QString("%1 %2").arg(m_fullCircumference ? base*2 : base).arg(units)); + labels.append(dimensionLabels.value(base)); } else { - labels.append(QString::number(base)); + if (dimension->IsCircumference()) + { + labels.append(QString("%1 %2").arg(m_fullCircumference ? base*2 : base).arg(units)); + } + else + { + labels.append(QString::number(base)); + } } } } @@ -603,7 +640,14 @@ QStringList DialogRestrictDimension::DimensionLabels(const QVector &bases, { for(auto base : bases) { - labels.append(QString("%1 %2").arg(m_fullCircumference ? base*2 : base).arg(units)); + if (dimensionLabels.contains(base) && not dimensionLabels.value(base).isEmpty()) + { + labels.append(dimensionLabels.value(base)); + } + else + { + labels.append(QString("%1 %2").arg(m_fullCircumference ? base*2 : base).arg(units)); + } } } diff --git a/src/app/tape/tape.pri b/src/app/tape/tape.pri index 219113ac5..f84d8133b 100644 --- a/src/app/tape/tape.pri +++ b/src/app/tape/tape.pri @@ -2,6 +2,7 @@ # This need for corect working file translations.pro SOURCES += \ + $$PWD/dialogs/dialogdimensionlabels.cpp \ $$PWD/dialogs/dialogrestrictdimension.cpp \ $$PWD/main.cpp \ $$PWD/tmainwindow.cpp \ @@ -18,6 +19,7 @@ SOURCES += \ *msvc*:SOURCES += $$PWD/stable.cpp HEADERS += \ + $$PWD/dialogs/dialogdimensionlabels.h \ $$PWD/dialogs/dialogrestrictdimension.h \ $$PWD/tmainwindow.h \ $$PWD/stable.h \ @@ -33,6 +35,7 @@ HEADERS += \ $$PWD/dialogs/dialogsetupmultisize.h FORMS += \ + $$PWD/dialogs/dialogdimensionlabels.ui \ $$PWD/dialogs/dialogrestrictdimension.ui \ $$PWD/tmainwindow.ui \ $$PWD/dialogs/dialogabouttape.ui \ diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 248d538f1..0bf555e76 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -34,6 +34,7 @@ #include "dialogs/dialogtapepreferences.h" #include "dialogs/dialogsetupmultisize.h" #include "dialogs/dialogrestrictdimension.h" +#include "dialogs/dialogdimensionlabels.h" #include "../vpatterndb/vcontainer.h" #include "../vpatterndb/calculator.h" #include "../vpatterndb/pmsystems.h" @@ -2229,6 +2230,25 @@ void TMainWindow::RestrictThirdDimesion() DimensionABaseChanged(); // trigger refresh } +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::EditDimensionLabels() +{ + const QMap dimensions = m->Dimensions(); + + DialogDimensionLabels dialog(dimensions, m->IsFullCircumference(), this); + if (dialog.exec() == QDialog::Rejected) + { + return; + } + + m->SetDimensionLabels(dialog.Labels()); + + MeasurementsWereSaved(false); + + InitDimensionsBaseValue(); + InitDimensionControls(); +} + //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::SetupMenu() { @@ -2516,10 +2536,6 @@ void TMainWindow::InitMenu() ui->actionRestrictSecondDimension->setEnabled(true); connect(ui->actionRestrictSecondDimension, &QAction::triggered, this, &TMainWindow::RestrictSecondDimesion); - separator = new QAction(this); - separator->setSeparator(true); - ui->menuMeasurements->insertAction(ui->actionRestrictSecondDimension, separator); - if (dimensions.size() > 2) { ui->actionRestrictThirdDimension->setVisible(true); @@ -2529,6 +2545,10 @@ void TMainWindow::InitMenu() } } + ui->actionDimensionLabels->setVisible(true); + ui->actionDimensionLabels->setEnabled(true); + connect(ui->actionDimensionLabels, &QAction::triggered, this, &TMainWindow::EditDimensionLabels); + // File ui->actionExportToIndividual->setVisible(true); ui->actionExportToIndividual->setEnabled(true); @@ -2556,20 +2576,29 @@ void TMainWindow::InitDimensionsBaseValue() dimension->IsCircumference(), m->IsFullCircumference())); - if (dimension->IsCircumference() || dimension->Type() == MeasurementDimension::X) + DimesionLabels labels = dimension->Labels(); + + if (labels.contains(dimension->BaseValue()) && not labels.value(dimension->BaseValue()).isEmpty()) { - if (dimension->Type() != MeasurementDimension::X && fc) - { - base->setText(QString("%1 %2").arg(dimension->BaseValue()*2).arg(unit)); - } - else - { - base->setText(QString("%1 %2").arg(dimension->BaseValue()).arg(unit)); - } + base->setText(labels.value(dimension->BaseValue())); } else { - base->setText(QString::number(dimension->BaseValue())); + if (dimension->IsCircumference() || dimension->Type() == MeasurementDimension::X) + { + if (dimension->Type() != MeasurementDimension::X && fc) + { + base->setText(QString("%1 %2").arg(dimension->BaseValue()*2).arg(unit)); + } + else + { + base->setText(QString("%1 %2").arg(dimension->BaseValue()).arg(unit)); + } + } + else + { + base->setText(QString::number(dimension->BaseValue())); + } } } }; @@ -2597,25 +2626,40 @@ void TMainWindow::InitDimensionGradation(int index, const MeasurementDimension_p control->clear(); const QVector bases = DimensionRestrictedValues(index, dimension); + const DimesionLabels labels = dimension->Labels(); if (dimension->Type() == MeasurementDimension::X) { for(auto base : bases) { - control->addItem(QString("%1 %2").arg(base).arg(unit), base); + if (labels.contains(base) && not labels.value(base).isEmpty()) + { + control->addItem(labels.value(base), base); + } + else + { + control->addItem(QString("%1 %2").arg(base).arg(unit), base); + } } } else if (dimension->Type() == MeasurementDimension::Y) { for(auto base : bases) { - if (dimension->IsCircumference()) + if (labels.contains(base) && not labels.value(base).isEmpty()) { - control->addItem(QString("%1 %2").arg(fc ? base*2 : base).arg(unit), base); + control->addItem(labels.value(base), base); } else { - control->addItem(QString::number(base), base); + if (dimension->IsCircumference()) + { + control->addItem(QString("%1 %2").arg(fc ? base*2 : base).arg(unit), base); + } + else + { + control->addItem(QString::number(base), base); + } } } } @@ -2623,7 +2667,14 @@ void TMainWindow::InitDimensionGradation(int index, const MeasurementDimension_p { for(auto base : bases) { - control->addItem(QString("%1 %2").arg(fc ? base*2 : base).arg(unit), base); + if (labels.contains(base) && not labels.value(base).isEmpty()) + { + control->addItem(labels.value(base), base); + } + else + { + control->addItem(QString("%1 %2").arg(fc ? base*2 : base).arg(unit), base); + } } } diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index f35022b9a..ec29eae4f 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -142,6 +142,8 @@ private slots: void RestrictSecondDimesion(); void RestrictThirdDimesion(); + void EditDimensionLabels(); + private: Q_DISABLE_COPY(TMainWindow) Ui::TMainWindow *ui; diff --git a/src/app/tape/tmainwindow.ui b/src/app/tape/tmainwindow.ui index a757d449c..211436dc9 100644 --- a/src/app/tape/tmainwindow.ui +++ b/src/app/tape/tmainwindow.ui @@ -995,6 +995,7 @@ + @@ -1389,6 +1390,17 @@ false + + + false + + + Dimension labels + + + false + + diff --git a/src/libs/ifc/schema/standard_measurements/v0.5.0.xsd b/src/libs/ifc/schema/standard_measurements/v0.5.0.xsd index 8d06f3cdd..b45ba1225 100644 --- a/src/libs/ifc/schema/standard_measurements/v0.5.0.xsd +++ b/src/libs/ifc/schema/standard_measurements/v0.5.0.xsd @@ -13,6 +13,20 @@ + + + + + + + + + + + + + + diff --git a/src/libs/vformat/vdimensions.h b/src/libs/vformat/vdimensions.h index 65873a0c6..69b4461fd 100644 --- a/src/libs/vformat/vdimensions.h +++ b/src/libs/vformat/vdimensions.h @@ -29,6 +29,7 @@ #define VDIMENSIONS_H #include +#include #include "../vmisc/def.h" @@ -44,6 +45,7 @@ class VAbstartMeasurementDimension; template class QSharedPointer; using MeasurementDimension_p = QSharedPointer; +using DimesionLabels = QMap; class VAbstartMeasurementDimension { @@ -87,13 +89,17 @@ public: static QString DimensionName(MeasurementDimension type); static QString DimensionToolTip(MeasurementDimension type, bool circumference, bool fc); + DimesionLabels Labels() const; + void SetLabels(const DimesionLabels &labels); + protected: - Unit m_units{Unit::Cm}; - int m_minValue{0}; - int m_maxValue{0}; - int m_step{-1}; - int m_baseValue{0}; - QString m_error{}; + Unit m_units{Unit::Cm}; + int m_minValue{0}; + int m_maxValue{0}; + int m_step{-1}; + int m_baseValue{0}; + QString m_error{}; + DimesionLabels m_labels{}; bool IsRangeValid(); bool IsStepValid(); @@ -167,6 +173,18 @@ inline bool VAbstartMeasurementDimension::IsCircumference() const return true; } +//--------------------------------------------------------------------------------------------------------------------- +inline DimesionLabels VAbstartMeasurementDimension::Labels() const +{ + return m_labels; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstartMeasurementDimension::SetLabels(const DimesionLabels &labels) +{ + m_labels = labels; +} + // VXMeasurementDimension //--------------------------------------------------------------------------------------------------------------------- class VXMeasurementDimension : public VAbstartMeasurementDimension diff --git a/src/libs/vformat/vmeasurements.cpp b/src/libs/vformat/vmeasurements.cpp index 941c82c3a..49bee2edb 100644 --- a/src/libs/vformat/vmeasurements.cpp +++ b/src/libs/vformat/vmeasurements.cpp @@ -74,6 +74,8 @@ const QString VMeasurements::TagRestrictions = QStringLiteral("restrictions" const QString VMeasurements::TagRestriction = QStringLiteral("restriction"); const QString VMeasurements::TagCorrections = QStringLiteral("corrections"); const QString VMeasurements::TagCorrection = QStringLiteral("correction"); +const QString VMeasurements::TagLabels = QStringLiteral("labels"); +const QString VMeasurements::TagLabel = QStringLiteral("label"); const QString VMeasurements::AttrBase = QStringLiteral("base"); const QString VMeasurements::AttrValue = QStringLiteral("value"); @@ -91,6 +93,7 @@ const QString VMeasurements::AttrMax = QStringLiteral("max"); const QString VMeasurements::AttrStep = QStringLiteral("step"); const QString VMeasurements::AttrCircumference = QStringLiteral("circumference"); const QString VMeasurements::AttrFullCircumference = QStringLiteral("fullCircumference"); +const QString VMeasurements::AttrLabel = QStringLiteral("label"); const QString VMeasurements::GenderMale = QStringLiteral("male"); const QString VMeasurements::GenderFemale = QStringLiteral("female"); @@ -822,10 +825,13 @@ QMap VMeasurements::Dimensions() const int step = GetParametrInt(dom, AttrStep, QString("-1")); const int base = GetParametrInt(dom, AttrBase, QChar('0')); + const DimesionLabels labels = ReadDimensionLabels(dom); + if (type == MeasurementDimension::X) { auto dimension = QSharedPointer::create(units, min, max, step); dimension->SetBaseValue(base); + dimension->SetLabels(labels); dimensionsCached->insert(type, dimension); } else if (type == MeasurementDimension::Y) @@ -833,18 +839,21 @@ QMap VMeasurements::Dimensions() auto dimension = QSharedPointer::create(units, min, max, step); dimension->SetBaseValue(base); dimension->SetCircumference(GetParametrBool(dom, AttrCircumference, trueStr)); + dimension->SetLabels(labels); dimensionsCached->insert(type, dimension); } else if (type == MeasurementDimension::W) { auto dimension = QSharedPointer::create(units, min, max, step); dimension->SetBaseValue(base); + dimension->SetLabels(labels); dimensionsCached->insert(type, dimension); } else if (type == MeasurementDimension::Z) { auto dimension = QSharedPointer::create(units, min, max, step); dimension->SetBaseValue(base); + dimension->SetLabels(labels); dimensionsCached->insert(type, dimension); } } @@ -908,6 +917,24 @@ QPair VMeasurements::Restriction(int base, int base2) const return restrictions.value(hash, QPair(0, 0)); } +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurements::SetDimensionLabels(const QMap &labels) +{ + const QDomNodeList list = elementsByTagName(TagDimension); + for (int i=0; i < list.size(); ++i) + { + QDomElement dom = list.at(i).toElement(); + const MeasurementDimension type = StrToDimensionType(GetParametrString(dom, AttrType)); + + if (labels.contains(type)) + { + SaveDimesionLabels(dom, labels.value(type)); + } + } + + dimensionsCached->clear(); // Invalidate cache +} + //--------------------------------------------------------------------------------------------------------------------- QString VMeasurements::GenderToStr(const GenderType &sex) { @@ -1311,3 +1338,84 @@ void VMeasurements::WriteCorrections(QDomElement &mElement, const QMap 0 && not label.isEmpty()) + { + labels.insert(value, label); + } + } + labelTag = labelTag.nextSibling(); + } + + return labels; +} diff --git a/src/libs/vformat/vmeasurements.h b/src/libs/vformat/vmeasurements.h index 2028115c0..818cdc311 100644 --- a/src/libs/vformat/vmeasurements.h +++ b/src/libs/vformat/vmeasurements.h @@ -121,6 +121,8 @@ public: QPair Restriction(int base, int base2=0) const; + void SetDimensionLabels(const QMap &labels); + static const QString TagVST; static const QString TagVIT; static const QString TagBodyMeasurements; @@ -139,6 +141,8 @@ public: static const QString TagRestriction; static const QString TagCorrections; static const QString TagCorrection; + static const QString TagLabels; + static const QString TagLabel; static const QString AttrBase; static const QString AttrValue; @@ -156,6 +160,7 @@ public: static const QString AttrStep; static const QString AttrCircumference; static const QString AttrFullCircumference; + static const QString AttrLabel; static const QString GenderMale; static const QString GenderFemale; @@ -206,6 +211,9 @@ private: QMap ReadCorrections(const QDomElement &mElement) const; void WriteCorrections(QDomElement &mElement, const QMap &corrections); + + void SaveDimesionLabels(QDomElement &dElement, const DimesionLabels &labels); + DimesionLabels ReadDimensionLabels(const QDomElement &dElement) const; }; #endif // VMEASUREMENTS_H