From 484b92a38ef27bba41e63898b109e108dc7457a9 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 28 Sep 2020 16:38:32 +0300 Subject: [PATCH 01/44] Dialog setup miltisize measurements. --- .../tapepreferencesconfigurationpage.cpp | 38 +- .../tapepreferencesconfigurationpage.h | 1 - .../tapepreferencesconfigurationpage.ui | 87 +-- .../tape/dialogs/dialognewmeasurements.cpp | 99 +-- src/app/tape/dialogs/dialognewmeasurements.h | 10 +- src/app/tape/dialogs/dialognewmeasurements.ui | 62 +- src/app/tape/dialogs/dialogsetupmultisize.cpp | 597 ++++++++++++++++++ src/app/tape/dialogs/dialogsetupmultisize.h | 99 +++ src/app/tape/dialogs/dialogsetupmultisize.ui | 480 ++++++++++++++ src/app/tape/tape.pri | 9 +- src/app/tape/tmainwindow.cpp | 18 +- src/libs/vformat/vdimensions.cpp | 372 +++++++++++ src/libs/vformat/vdimensions.h | 248 ++++++++ src/libs/vformat/vformat.pri | 2 + src/libs/vmisc/vtapesettings.cpp | 27 - src/libs/vmisc/vtapesettings.h | 6 - 16 files changed, 1831 insertions(+), 324 deletions(-) create mode 100644 src/app/tape/dialogs/dialogsetupmultisize.cpp create mode 100644 src/app/tape/dialogs/dialogsetupmultisize.h create mode 100644 src/app/tape/dialogs/dialogsetupmultisize.ui create mode 100644 src/libs/vformat/vdimensions.cpp create mode 100644 src/libs/vformat/vdimensions.h diff --git a/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.cpp b/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.cpp index b8d42f37f..b0854aa25 100644 --- a/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.cpp +++ b/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.cpp @@ -38,8 +38,7 @@ TapePreferencesConfigurationPage::TapePreferencesConfigurationPage(QWidget *pare : QWidget(parent), ui(new Ui::TapePreferencesConfigurationPage), m_langChanged(false), - m_systemChanged(false), - m_defGradationChanged(false) + m_systemChanged(false) { ui->setupUi(this); RetranslateUi(); @@ -84,31 +83,6 @@ TapePreferencesConfigurationPage::TapePreferencesConfigurationPage(QWidget *pare //----------------------- Toolbar ui->toolBarStyleCheck->setChecked(qApp->TapeSettings()->GetToolBarStyle()); - - //---------------------------Default height and size - // If change units don't forget about the label - ui->defHeightCombo->addItems(VMeasurement::WholeListHeights(Unit::Cm)); - index = ui->defHeightCombo->findText(QString().setNum(qApp->TapeSettings()->GetDefHeight())); - if (index != -1) - { - ui->defHeightCombo->setCurrentIndex(index); - } - - auto DefGradationChanged = [this]() - { - m_defGradationChanged = true; - }; - - connect(ui->defHeightCombo, QOverload::of(&QComboBox::currentIndexChanged), this, DefGradationChanged); - - // If change units don't forget about the label - ui->defSizeCombo->addItems(VMeasurement::WholeListSizes(Unit::Cm)); - index = ui->defSizeCombo->findText(QString().setNum(qApp->TapeSettings()->GetDefSize())); - if (index != -1) - { - ui->defSizeCombo->setCurrentIndex(index); - } - connect(ui->defSizeCombo, QOverload::of(&QComboBox::currentIndexChanged), this, DefGradationChanged); } //--------------------------------------------------------------------------------------------------------------------- @@ -150,13 +124,6 @@ QStringList TapePreferencesConfigurationPage::Apply() qApp->RetranslateGroups(); } - if (m_defGradationChanged) - { - settings->SetDefHeight(ui->defHeightCombo->currentText().toInt()); - settings->SetDefSize(ui->defSizeCombo->currentText().toInt()); - m_defGradationChanged = false; - } - return preferences; } @@ -187,7 +154,4 @@ void TapePreferencesConfigurationPage::RetranslateUi() ui->systemCombo->blockSignals(false); ui->systemCombo->setCurrentIndex(ui->systemCombo->findData(code)); } - - ui->labelHeightUnit->setText(UnitsToStr(Unit::Cm, true)); - ui->labelSizeUnit->setText(UnitsToStr(Unit::Cm, true)); } diff --git a/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.h b/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.h index 9ee0a6196..26e2931ae 100644 --- a/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.h +++ b/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.h @@ -52,7 +52,6 @@ private: Ui::TapePreferencesConfigurationPage *ui; bool m_langChanged; bool m_systemChanged; - bool m_defGradationChanged; void RetranslateUi(); }; diff --git a/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.ui b/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.ui index bc74e62dd..55a8f6328 100644 --- a/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.ui +++ b/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.ui @@ -7,7 +7,7 @@ 0 0 544 - 750 + 648 @@ -25,7 +25,7 @@ 0 0 524 - 730 + 628 @@ -165,89 +165,6 @@ - - - - Default height and size - - - - - - Default height: - - - - - - - - 0 - 0 - - - - - - - - Height unit - - - - - - - - 0 - 0 - - - - - - - - Size unit - - - - - - - Default size: - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - diff --git a/src/app/tape/dialogs/dialognewmeasurements.cpp b/src/app/tape/dialogs/dialognewmeasurements.cpp index 9643fa021..2d0fa2202 100644 --- a/src/app/tape/dialogs/dialognewmeasurements.cpp +++ b/src/app/tape/dialogs/dialognewmeasurements.cpp @@ -44,31 +44,7 @@ DialogNewMeasurements::DialogNewMeasurements(QWidget *parent) ui->setupUi(this); InitMTypes(); - InitUnits(MeasurementsType::Individual); - InitHeightsList(); - InitSizesList(); - - const VTapeSettings *settings = qApp->TapeSettings(); - - const int height = static_cast(UnitConvertor(settings->GetDefHeight(), Unit::Cm, MUnit())); - int index = ui->comboBoxBaseHeight->findText(QString().setNum(height)); - if (index != -1) - { - ui->comboBoxBaseHeight->setCurrentIndex(index); - } - - const int size = static_cast(UnitConvertor(settings->GetDefSize(), Unit::Cm, MUnit())); - index = ui->comboBoxBaseSize->findText(QString().setNum(size)); - if (index != -1) - { - ui->comboBoxBaseSize->setCurrentIndex(index); - } - - connect(ui->comboBoxMType, QOverload::of(&QComboBox::currentIndexChanged), this, - &DialogNewMeasurements::CurrentTypeChanged); - - connect(ui->comboBoxUnit, QOverload::of(&QComboBox::currentIndexChanged), this, - &DialogNewMeasurements::CurrentUnitChanged); + InitUnits(); } //--------------------------------------------------------------------------------------------------------------------- @@ -89,18 +65,6 @@ Unit DialogNewMeasurements::MUnit() const return static_cast(ui->comboBoxUnit->currentData().toInt()); } -//--------------------------------------------------------------------------------------------------------------------- -int DialogNewMeasurements::BaseSize() const -{ - return ui->comboBoxBaseSize->currentText().toInt(); -} - -//--------------------------------------------------------------------------------------------------------------------- -int DialogNewMeasurements::BaseHeight() const -{ - return ui->comboBoxBaseHeight->currentText().toInt(); -} - //--------------------------------------------------------------------------------------------------------------------- void DialogNewMeasurements::changeEvent(QEvent *event) { @@ -109,7 +73,7 @@ void DialogNewMeasurements::changeEvent(QEvent *event) // retranslate designer form (single inheritance approach) ui->retranslateUi(this); InitMTypes(); - InitUnits(static_cast(ui->comboBoxMType->currentData().toInt())); + InitUnits(); } // remember to call base class implementation @@ -137,40 +101,6 @@ void DialogNewMeasurements::showEvent(QShowEvent *event) isInitialized = true;//first show windows are held } -//--------------------------------------------------------------------------------------------------------------------- -void DialogNewMeasurements::CurrentTypeChanged(int index) -{ - const MeasurementsType type = static_cast(ui->comboBoxMType->itemData(index).toInt()); - if (type == MeasurementsType::Multisize) - { - ui->comboBoxBaseSize->setEnabled(true); - ui->comboBoxBaseHeight->setEnabled(true); - } - else - { - ui->comboBoxBaseSize->setEnabled(false); - ui->comboBoxBaseHeight->setEnabled(false); - } - InitUnits(type); -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogNewMeasurements::CurrentUnitChanged(int index) -{ - Q_UNUSED(index) - - if (MUnit() != Unit::Inch) - { - int i = ui->comboBoxBaseHeight->currentIndex(); - InitHeightsList(); - ui->comboBoxBaseHeight->setCurrentIndex(i); - - i = ui->comboBoxBaseSize->currentIndex(); - InitSizesList(); - ui->comboBoxBaseSize->setCurrentIndex(i); - } -} - //--------------------------------------------------------------------------------------------------------------------- void DialogNewMeasurements::InitMTypes() { @@ -194,23 +124,7 @@ void DialogNewMeasurements::InitMTypes() } //--------------------------------------------------------------------------------------------------------------------- -void DialogNewMeasurements::InitHeightsList() -{ - const QStringList list = VMeasurement::WholeListHeights(MUnit()); - ui->comboBoxBaseHeight->clear(); - ui->comboBoxBaseHeight->addItems(list); -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogNewMeasurements::InitSizesList() -{ - const QStringList list = VMeasurement::WholeListSizes(MUnit()); - ui->comboBoxBaseSize->clear(); - ui->comboBoxBaseSize->addItems(list); -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogNewMeasurements::InitUnits(const MeasurementsType &type) +void DialogNewMeasurements::InitUnits() { int val = static_cast(Unit::Cm); if (ui->comboBoxUnit->currentIndex() != -1) @@ -220,12 +134,11 @@ void DialogNewMeasurements::InitUnits(const MeasurementsType &type) ui->comboBoxUnit->blockSignals(true); ui->comboBoxUnit->clear(); + ui->comboBoxUnit->addItem(tr("Centimeters"), static_cast(Unit::Cm)); ui->comboBoxUnit->addItem(tr("Millimiters"), static_cast(Unit::Mm)); - if (type == MeasurementsType::Individual) - { - ui->comboBoxUnit->addItem(tr("Inches"), static_cast(Unit::Inch)); - } + ui->comboBoxUnit->addItem(tr("Inches"), static_cast(Unit::Inch)); + ui->comboBoxUnit->setCurrentIndex(-1); ui->comboBoxUnit->blockSignals(false); diff --git a/src/app/tape/dialogs/dialognewmeasurements.h b/src/app/tape/dialogs/dialognewmeasurements.h index bf81fa517..9b301a4d1 100644 --- a/src/app/tape/dialogs/dialognewmeasurements.h +++ b/src/app/tape/dialogs/dialognewmeasurements.h @@ -48,26 +48,18 @@ public: MeasurementsType Type() const; Unit MUnit() const; - int BaseSize() const; - int BaseHeight() const; protected: virtual void changeEvent(QEvent* event) override; virtual void showEvent(QShowEvent *event) override; -private slots: - void CurrentTypeChanged(int index); - void CurrentUnitChanged(int index); - private: Q_DISABLE_COPY(DialogNewMeasurements) Ui::DialogNewMeasurements *ui; bool isInitialized; void InitMTypes(); - void InitHeightsList(); - void InitSizesList(); - void InitUnits(const MeasurementsType &type); + void InitUnits(); }; #endif // DIALOGNEWMEASUREMENTS_H diff --git a/src/app/tape/dialogs/dialognewmeasurements.ui b/src/app/tape/dialogs/dialognewmeasurements.ui index de6b15994..16835baee 100644 --- a/src/app/tape/dialogs/dialognewmeasurements.ui +++ b/src/app/tape/dialogs/dialognewmeasurements.ui @@ -9,8 +9,8 @@ 0 0 - 244 - 185 + 220 + 104 @@ -60,64 +60,6 @@ - - - - Base size: - - - - - - - false - - - - 0 - 0 - - - - - 0 - 0 - - - - 3 - - - - - - - Base height: - - - - - - - false - - - - 0 - 0 - - - - - 0 - 0 - - - - 4 - - - diff --git a/src/app/tape/dialogs/dialogsetupmultisize.cpp b/src/app/tape/dialogs/dialogsetupmultisize.cpp new file mode 100644 index 000000000..4bbd8f71b --- /dev/null +++ b/src/app/tape/dialogs/dialogsetupmultisize.cpp @@ -0,0 +1,597 @@ +/************************************************************************ + ** + ** @file dialogsetupmultisize.cpp + ** @author Roman Telezhynskyi + ** @date 26 9, 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 "dialogsetupmultisize.h" +#include "ui_dialogsetupmultisize.h" + +#include +#include + +#include "../mapplication.h" +#include "../vmisc/backport/qoverload.h" + +//--------------------------------------------------------------------------------------------------------------------- +DialogSetupMultisize::DialogSetupMultisize(Unit unit, QWidget *parent) : + QDialog(parent), + ui(new Ui::DialogSetupMultisize), + m_xDimension(QSharedPointer::create(unit)), + m_yDimension(QSharedPointer::create(unit)), + m_wDimension(QSharedPointer::create(unit)), + m_zDimension(QSharedPointer::create(unit)) +{ + ui->setupUi(this); + + ui->labelError->clear(); + ui->checkBoxYDimensionCircumference->setChecked(m_yDimension->IsCircumference()); + + InitXDimension(); + InitYDimension(); + InitWDimension(); + InitZDimension(); + + // height + connect(ui->spinBoxXDimensionMinValue, QOverload::of(&QSpinBox::valueChanged), + this, [this](int value) + { + DimensionMinValueChanged(value, ui->spinBoxXDimensionMaxValue, ui->comboBoxXDimensionStep, + ui->comboBoxXDimensionBase, m_xDimension); + }); + connect(ui->spinBoxXDimensionMaxValue, QOverload::of(&QSpinBox::valueChanged), + this, [this](int value) + { + DimensionMaxValueChanged(value, ui->spinBoxXDimensionMinValue, ui->comboBoxXDimensionStep, + ui->comboBoxXDimensionBase, m_xDimension); + }); + connect(ui->comboBoxXDimensionStep, QOverload::of(&QComboBox::currentIndexChanged), + this, [this](int index) + { + DimensionStepChanged(index, ui->comboBoxXDimensionStep, ui->comboBoxXDimensionBase, m_xDimension); + }); + connect(ui->comboBoxXDimensionBase, QOverload::of(&QComboBox::currentIndexChanged), + this, [this](int index) + { + DimensionBaseChanged(index, ui->comboBoxXDimensionBase, m_xDimension); + }); + + // size + connect(ui->spinBoxYDimensionMinValue, QOverload::of(&QSpinBox::valueChanged), + this, [this](int value) + { + DimensionMinValueChanged(value, ui->spinBoxYDimensionMaxValue, ui->comboBoxYDimensionStep, + ui->comboBoxYDimensionBase, m_yDimension); + }); + connect(ui->spinBoxYDimensionMaxValue, QOverload::of(&QSpinBox::valueChanged), + this, [this](int value) + { + DimensionMaxValueChanged(value, ui->spinBoxYDimensionMinValue, ui->comboBoxYDimensionStep, + ui->comboBoxYDimensionBase, m_yDimension); + }); + connect(ui->comboBoxYDimensionStep, QOverload::of(&QComboBox::currentIndexChanged), + this, [this](int index) + { + DimensionStepChanged(index, ui->comboBoxYDimensionStep, ui->comboBoxYDimensionBase, m_yDimension); + }); + connect(ui->comboBoxYDimensionBase, QOverload::of(&QComboBox::currentIndexChanged), + this, [this](int index) + { + DimensionBaseChanged(index, ui->comboBoxYDimensionBase, m_yDimension); + }); + + // hip + connect(ui->spinBoxWDimensionMinValue, QOverload::of(&QSpinBox::valueChanged), + this, [this](int value) + { + DimensionMinValueChanged(value, ui->spinBoxWDimensionMaxValue, ui->comboBoxWDimensionStep, + ui->comboBoxWDimensionBase, m_wDimension); + }); + connect(ui->spinBoxWDimensionMaxValue, QOverload::of(&QSpinBox::valueChanged), + this, [this](int value) + { + DimensionMaxValueChanged(value, ui->spinBoxWDimensionMinValue, ui->comboBoxWDimensionStep, + ui->comboBoxWDimensionBase, m_wDimension); + }); + connect(ui->comboBoxWDimensionStep, QOverload::of(&QComboBox::currentIndexChanged), + this, [this](int index) + { + DimensionStepChanged(index, ui->comboBoxWDimensionStep, ui->comboBoxWDimensionBase, m_wDimension); + }); + connect(ui->comboBoxWDimensionBase, QOverload::of(&QComboBox::currentIndexChanged), + this, [this](int index) + { + DimensionBaseChanged(index, ui->comboBoxWDimensionBase, m_wDimension); + }); + + // waist + connect(ui->spinBoxZDimensionMinValue, QOverload::of(&QSpinBox::valueChanged), + this, [this](int value) + { + DimensionMinValueChanged(value, ui->spinBoxZDimensionMaxValue, ui->comboBoxZDimensionStep, + ui->comboBoxZDimensionBase, m_zDimension); + }); + connect(ui->spinBoxZDimensionMaxValue, QOverload::of(&QSpinBox::valueChanged), + this, [this](int value) + { + DimensionMaxValueChanged(value, ui->spinBoxZDimensionMinValue, ui->comboBoxZDimensionStep, + ui->comboBoxZDimensionBase, m_zDimension); + }); + connect(ui->comboBoxZDimensionStep, QOverload::of(&QComboBox::currentIndexChanged), + this, [this](int index) + { + DimensionStepChanged(index, ui->comboBoxZDimensionStep, ui->comboBoxZDimensionBase, m_zDimension); + }); + connect(ui->comboBoxZDimensionBase, QOverload::of(&QComboBox::currentIndexChanged), + this, [this](int index) + { + DimensionBaseChanged(index, ui->comboBoxZDimensionBase, m_zDimension); + }); + + + connect(ui->groupBoxXDimension, &QGroupBox::clicked, this, [this](){CheckState();}); + connect(ui->groupBoxYDimension, &QGroupBox::clicked, this, [this](){CheckState();}); + connect(ui->groupBoxWDimension, &QGroupBox::clicked, this, [this](){CheckState();}); + connect(ui->groupBoxZDimension, &QGroupBox::clicked, this, [this](){CheckState();}); + + connect(ui->checkBoxFullCircumference, &QCheckBox::stateChanged, + this, &DialogSetupMultisize::ShowFullCircumference); + connect(ui->checkBoxYDimensionCircumference, &QCheckBox::stateChanged, + this, &DialogSetupMultisize::YDimensionCircumferenceChanged); + + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogSetupMultisize::~DialogSetupMultisize() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector > DialogSetupMultisize::Dimensions() const +{ + QVector > dimensions; + + if (ui->groupBoxXDimension->isChecked()) + { + dimensions.append(m_xDimension); + } + + if (ui->groupBoxYDimension->isChecked()) + { + dimensions.append(m_yDimension); + } + + if (ui->groupBoxWDimension->isChecked()) + { + dimensions.append(m_wDimension); + } + + if (ui->groupBoxZDimension->isChecked()) + { + dimensions.append(m_zDimension); + } + + return dimensions; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSetupMultisize::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::LanguageChange) + { + // retranslate designer form (single inheritance approach) + ui->retranslateUi(this); + } + + // remember to call base class implementation + QDialog::changeEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSetupMultisize::showEvent(QShowEvent *event) +{ + QDialog::showEvent( event ); + if ( event->spontaneous() ) + { + return; + } + + if (m_isInitialized) + { + return; + } + // do your init stuff here + + setMaximumSize(size()); + setMinimumSize(size()); + + m_isInitialized = true;//first show windows are held +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSetupMultisize::ShowFullCircumference() +{ + auto ShowDimensionFullCircumference = [this](QSpinBox *spinboxMinValue, QSpinBox *spinboxMaxValue, + QComboBox *comboBoxStep, QComboBox *comboBoxBase, + const QSharedPointer &dimension) + { + SCASSERT(spinboxMinValue != nullptr) + SCASSERT(spinboxMaxValue != nullptr) + SCASSERT(comboBoxStep != nullptr) + SCASSERT(comboBoxBase != nullptr) + + InitDimension(spinboxMinValue, spinboxMaxValue, comboBoxStep, dimension); + UpdateBase(comboBoxBase, dimension); + + comboBoxBase->blockSignals(true); + comboBoxBase->setCurrentIndex(-1); + comboBoxBase->blockSignals(false); + }; + + ShowDimensionFullCircumference(ui->spinBoxYDimensionMinValue, ui->spinBoxYDimensionMaxValue, + ui->comboBoxYDimensionStep, ui->comboBoxYDimensionBase, m_yDimension); + ShowDimensionFullCircumference(ui->spinBoxWDimensionMinValue, ui->spinBoxWDimensionMaxValue, + ui->comboBoxWDimensionStep, ui->comboBoxWDimensionBase, m_wDimension); + ShowDimensionFullCircumference(ui->spinBoxZDimensionMinValue, ui->spinBoxZDimensionMaxValue, + ui->comboBoxZDimensionStep, ui->comboBoxZDimensionBase, m_zDimension); + + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSetupMultisize::YDimensionCircumferenceChanged() +{ + bool checked = ui->checkBoxYDimensionCircumference->isChecked(); + m_yDimension->SetCircumference(checked); + + const bool c = m_yDimension->IsCircumference(); + const QString unitStr = c ? " " + UnitsToStr(m_yDimension->Units()) : QString(); + + ui->spinBoxYDimensionMinValue->setSuffix(unitStr); + ui->spinBoxYDimensionMaxValue->setSuffix(unitStr); + + InitDimension(ui->spinBoxYDimensionMinValue, ui->spinBoxYDimensionMaxValue, ui->comboBoxYDimensionStep, + m_yDimension); + + UpdateBase(ui->comboBoxYDimensionBase, m_yDimension); + + ui->comboBoxYDimensionBase->blockSignals(true); + ui->comboBoxYDimensionBase->setCurrentIndex(-1); + ui->comboBoxYDimensionBase->blockSignals(false); + + bool ok = false; + const int base = ui->comboBoxYDimensionBase->currentData().toInt(&ok); + m_yDimension->SetBaseValue(ok ? base : -1); + + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSetupMultisize::CheckState() +{ + ui->labelError->clear(); + + bool xDimensionValid = true; + bool yDimensionValid = true; + bool wDimensionValid = true; + bool zDimensionValid = true; + + int dimensions = 0; + + auto CheckDimension = [this](QGroupBox *group, bool &dimensionValid, int &dimensions, + const QSharedPointer &dimension) + { + SCASSERT(group != nullptr) + + if (group->isChecked()) + { + dimensionValid = dimension->IsValid(); + ++dimensions; + + if (ui->labelError->text().isEmpty() && not dimensionValid) + { + ui->labelError->setText(tr("Please, provide correct data for dimensions")); + } + } + }; + + CheckDimension(ui->groupBoxXDimension, xDimensionValid, dimensions, m_xDimension); + CheckDimension(ui->groupBoxYDimension, yDimensionValid, dimensions, m_yDimension); + CheckDimension(ui->groupBoxWDimension, wDimensionValid, dimensions, m_wDimension); + CheckDimension(ui->groupBoxZDimension, zDimensionValid, dimensions, m_zDimension); + + if (ui->labelError->text().isEmpty() && dimensions == 0) + { + ui->labelError->setText(tr("Please, select at least one dimension")); + } + else if (ui->labelError->text().isEmpty() && dimensions > 3) + { + ui->labelError->setText(tr("No more than 3 dimensions allowed")); + } + + const bool enough = dimensions > 0 && dimensions <= 3; + + QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok); + SCASSERT(bOk != nullptr) + bOk->setEnabled(enough && xDimensionValid && yDimensionValid && wDimensionValid && zDimensionValid); + + if (ui->labelError->text().isEmpty()) + { + ui->labelError->setText(tr("Ready")); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSetupMultisize::InitDimensionMinMax(QSpinBox *spinboxMinValue, QSpinBox *spinboxMaxValue, + const QSharedPointer &dimension) +{ + SCASSERT(spinboxMinValue != nullptr) + SCASSERT(spinboxMaxValue != nullptr) + + dimension->SetMinValue(dimension->RangeMin()); + dimension->SetMaxValue(dimension->RangeMax()); + + const bool fc = ui->checkBoxFullCircumference->isChecked(); + const bool c = dimension->IsCircumference(); + + spinboxMinValue->blockSignals(true); + const QString unitStr = " " + UnitsToStr(dimension->Units()); + if (c) + { + spinboxMinValue->setSuffix(unitStr); + } + + spinboxMinValue->setMinimum(c && fc ? dimension->RangeMin()*2 : dimension->RangeMin()); + spinboxMinValue->setMaximum(c && fc ? dimension->MaxValue()*2 : dimension->MaxValue()); + spinboxMinValue->setValue(c && fc ? dimension->MinValue()*2 : dimension->MinValue()); + spinboxMinValue->blockSignals(false); + + spinboxMaxValue->blockSignals(true); + if (c) + { + spinboxMaxValue->setSuffix(unitStr); + } + spinboxMaxValue->setMinimum(c && fc ? dimension->MinValue()*2 : dimension->MinValue()); + spinboxMaxValue->setMaximum(c && fc ? dimension->RangeMax()*2 : dimension->RangeMax()); + spinboxMaxValue->setValue(c && fc ? dimension->RangeMax()*2 : dimension->RangeMax()); + spinboxMaxValue->setValue(c && fc ? dimension->MaxValue()*2 : dimension->MaxValue()); + spinboxMaxValue->blockSignals(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSetupMultisize::InitDimensionStep(QComboBox *comboBoxStep, + const QSharedPointer &dimension) +{ + SCASSERT(comboBoxStep != nullptr) + + const bool fc = ui->checkBoxFullCircumference->isChecked(); + const bool c = dimension->IsCircumference(); + const QString unitStr = " " + UnitsToStr(dimension->Units()); + + dimension->SetStep(-1); + + comboBoxStep->blockSignals(true); + const QVector steps = dimension->ValidSteps(); + comboBoxStep->clear(); + for(auto step : steps) + { + comboBoxStep->addItem(QString("%1%2").arg(c && fc ? step*2 : step) + .arg(c ? unitStr : QString()), step); + } + + comboBoxStep->setCurrentIndex(-1); // force a user to select + comboBoxStep->blockSignals(false); + + bool ok = false; + const int step = comboBoxStep->currentData().toInt(&ok); + dimension->SetStep(ok ? step : -1); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSetupMultisize::InitDimension(QSpinBox *spinboxMinValue, QSpinBox *spinboxMaxValue, QComboBox *comboBoxStep, + const QSharedPointer &dimension) +{ + InitDimensionMinMax(spinboxMinValue, spinboxMaxValue, dimension); + InitDimensionStep(comboBoxStep, dimension); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSetupMultisize::InitXDimension() +{ + InitDimension(ui->spinBoxXDimensionMinValue, ui->spinBoxXDimensionMaxValue, ui->comboBoxXDimensionStep, + m_xDimension); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSetupMultisize::InitYDimension() +{ + InitDimension(ui->spinBoxYDimensionMinValue, ui->spinBoxYDimensionMaxValue, ui->comboBoxYDimensionStep, + m_yDimension); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSetupMultisize::InitWDimension() +{ + InitDimension(ui->spinBoxWDimensionMinValue, ui->spinBoxWDimensionMaxValue, ui->comboBoxWDimensionStep, + m_wDimension); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSetupMultisize::InitZDimension() +{ + InitDimension(ui->spinBoxZDimensionMinValue, ui->spinBoxZDimensionMaxValue, ui->comboBoxZDimensionStep, + m_zDimension); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSetupMultisize::DimensionMinValueChanged(int value, QSpinBox *spinboxMaxValue, QComboBox *comboBoxStep, + QComboBox *comboBoxBase, + const QSharedPointer &dimension) +{ + SCASSERT(spinboxMaxValue != nullptr) + SCASSERT(comboBoxStep != nullptr) + SCASSERT(comboBoxBase != nullptr) + + const bool fc = ui->checkBoxFullCircumference->isChecked(); + const bool c = dimension->IsCircumference(); + + dimension->SetMinValue(c && fc ? value / 2 : value); + + spinboxMaxValue->blockSignals(true); + spinboxMaxValue->setMinimum(value); + spinboxMaxValue->blockSignals(false); + + dimension->SetMaxValue(c && fc ? spinboxMaxValue->value() / 2 : spinboxMaxValue->value()); + + UpdateSteps(comboBoxStep, dimension); + UpdateBase(comboBoxBase, dimension); + + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSetupMultisize::DimensionMaxValueChanged(int value, QSpinBox *spinboxMinValue, QComboBox *comboBoxStep, + QComboBox *comboBoxBase, + const QSharedPointer &dimension) +{ + SCASSERT(spinboxMinValue != nullptr) + SCASSERT(comboBoxStep != nullptr) + SCASSERT(comboBoxBase != nullptr) + + const bool fc = ui->checkBoxFullCircumference->isChecked(); + const bool c = dimension->IsCircumference(); + + dimension->SetMaxValue(c && fc ? value / 2 : value); + + spinboxMinValue->blockSignals(true); + spinboxMinValue->setMaximum(value); + spinboxMinValue->blockSignals(false); + + dimension->SetMinValue(c && fc ? spinboxMinValue->value() / 2 : spinboxMinValue->value()); + + UpdateSteps(comboBoxStep, dimension); + UpdateBase(comboBoxBase, dimension); + + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSetupMultisize::DimensionStepChanged(int index, QComboBox *comboBoxStep, QComboBox *comboBoxBase, + const QSharedPointer &dimension) +{ + SCASSERT(comboBoxStep != nullptr) + SCASSERT(comboBoxBase != nullptr) + + bool ok = false; + const int step = comboBoxStep->itemData(index).toInt(&ok); + dimension->SetStep(ok ? step : -1); + + UpdateBase(comboBoxBase, dimension); + + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSetupMultisize::DimensionBaseChanged(int index, QComboBox *comboBoxBase, + const QSharedPointer &dimension) +{ + SCASSERT(comboBoxBase != nullptr) + + bool ok = false; + const int base = comboBoxBase->itemData(index).toInt(&ok); + dimension->SetBaseValue(ok ? base : -1); + + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSetupMultisize::UpdateSteps(QComboBox *comboBoxStep, + const QSharedPointer &dimension) +{ + SCASSERT(comboBoxStep != nullptr) + + int oldStep = -1; + if (comboBoxStep->currentIndex() != -1) + { + oldStep = comboBoxStep->currentData().toInt(); + } + + comboBoxStep->blockSignals(true); + + const QString unitStr = " " + UnitsToStr(dimension->Units()); + const QVector steps = dimension->ValidSteps(); + comboBoxStep->clear(); + + const bool fc = ui->checkBoxFullCircumference->isChecked(); + const bool c = dimension->IsCircumference(); + + for(auto step : steps) + { + comboBoxStep->addItem(QString("%1%2").arg(c && fc ? step * 2 : step) + .arg(c ? unitStr : QString()), step); + } + + comboBoxStep->setCurrentIndex(comboBoxStep->findData(oldStep)); + comboBoxStep->blockSignals(false); + + bool ok = false; + const int step = comboBoxStep->currentData().toInt(&ok); + dimension->SetStep(ok ? step : -1); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSetupMultisize::UpdateBase(QComboBox *comboBoxBase, + const QSharedPointer &dimension) +{ + SCASSERT(comboBoxBase != nullptr) + + int oldBase = -1; + if (comboBoxBase->currentIndex() != -1) + { + oldBase = comboBoxBase->currentData().toInt(); + } + + comboBoxBase->blockSignals(true); + + const QString unitStr = " " + UnitsToStr(dimension->Units()); + const QVector bases = dimension->ValidBases(); + comboBoxBase->clear(); + const bool fc = ui->checkBoxFullCircumference->isChecked(); + const bool c = dimension->IsCircumference(); + + for(auto base : bases) + { + comboBoxBase->addItem(QString("%1%2").arg(c && fc ? base * 2 : base).arg(c ? unitStr : QString()), base); + } + + comboBoxBase->setCurrentIndex(comboBoxBase->findData(oldBase)); + comboBoxBase->blockSignals(false); + + bool ok = false; + const int base = comboBoxBase->currentData().toInt(&ok); + dimension->SetBaseValue(ok ? base : -1); +} + diff --git a/src/app/tape/dialogs/dialogsetupmultisize.h b/src/app/tape/dialogs/dialogsetupmultisize.h new file mode 100644 index 000000000..a70449b96 --- /dev/null +++ b/src/app/tape/dialogs/dialogsetupmultisize.h @@ -0,0 +1,99 @@ +/************************************************************************ + ** + ** @file dialogsetupmultisize.h + ** @author Roman Telezhynskyi + ** @date 26 9, 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 DIALOGSETUPMULTISIZE_H +#define DIALOGSETUPMULTISIZE_H + +#include + +#include "../vformat/vdimensions.h" +#include "../vmisc/def.h" + +class QSpinBox; + +namespace Ui +{ +class DialogSetupMultisize; +} + +class DialogSetupMultisize : public QDialog +{ + Q_OBJECT + +public: + explicit DialogSetupMultisize(Unit unit, QWidget *parent = nullptr); + ~DialogSetupMultisize(); + + QVector > Dimensions() const; + +protected: + virtual void changeEvent(QEvent* event) override; + virtual void showEvent(QShowEvent *event) override; + +private slots: + void ShowFullCircumference(); + void YDimensionCircumferenceChanged(); + +private: + Q_DISABLE_COPY(DialogSetupMultisize) + Ui::DialogSetupMultisize *ui; + bool m_isInitialized{false}; + QSharedPointer m_xDimension; + QSharedPointer m_yDimension; + QSharedPointer m_wDimension; + QSharedPointer m_zDimension; + + void CheckState(); + + void InitDimensionMinMax(QSpinBox *spinboxMinValue, QSpinBox *spinboxMaxValue, + const QSharedPointer &dimension); + void InitDimensionStep(QComboBox *comboBoxStep,const QSharedPointer &dimension); + + void InitDimension(QSpinBox *spinboxMinValue, QSpinBox *spinboxMaxValue, QComboBox *comboBoxStep, + const QSharedPointer &dimension); + void InitXDimension(); + void InitYDimension(); + void InitWDimension(); + void InitZDimension(); + + void DimensionMinValueChanged(int value, QSpinBox *spinboxMaxValue, QComboBox *comboBoxStep, + QComboBox *comboBoxBase, + const QSharedPointer &dimension); + void DimensionMaxValueChanged(int value, QSpinBox *spinboxMinValue, QComboBox *comboBoxStep, + QComboBox *comboBoxBase, + const QSharedPointer &dimension); + + void DimensionStepChanged(int index, QComboBox *comboBoxStep, QComboBox *comboBoxBase, + const QSharedPointer &dimension); + void DimensionBaseChanged(int index, QComboBox *comboBoxBase, + const QSharedPointer &dimension); + + void UpdateSteps(QComboBox *comboBoxStep, const QSharedPointer &dimension); + void UpdateBase(QComboBox *comboBoxBase, const QSharedPointer &dimension); +}; + +#endif // DIALOGSETUPMULTISIZE_H diff --git a/src/app/tape/dialogs/dialogsetupmultisize.ui b/src/app/tape/dialogs/dialogsetupmultisize.ui new file mode 100644 index 000000000..a09b0aac6 --- /dev/null +++ b/src/app/tape/dialogs/dialogsetupmultisize.ui @@ -0,0 +1,480 @@ + + + DialogSetupMultisize + + + + 0 + 0 + 734 + 289 + + + + Setup multisize measurements + + + + :/tapeicon/64x64/logo.png:/tapeicon/64x64/logo.png + + + + + + Use full circumference + + + + + + + + + Height + + + true + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Min value: + + + + + + + Minimal value described in the column + + + + + + + + + + Max value: + + + + + + + Maximal value described in the column + + + + + + + Step: + + + + + + + + 0 + 0 + + + + Single-step between the column values + + + + + + + Base: + + + + + + + + 0 + 0 + + + + The base value for the column + + + + + + + + + + + + Size + + + true + + + true + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Min value: + + + + + + + Minimal value described in the column + + + + + + + Max value: + + + + + + + Maximal value described in the column + + + + + + + Step: + + + + + + + + 0 + 0 + + + + Single-step between the column values + + + + + + + Base: + + + + + + + + 0 + 0 + + + + The base value for the column + + + + + + + + + Circumference + + + true + + + + + + + + + + Hip + + + true + + + false + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Min value: + + + + + + + Minimal value described in the column + + + + + + + Max value: + + + + + + + Maximal value described in the column + + + + + + + Step: + + + + + + + + 0 + 0 + + + + Single-step between the column values + + + + + + + Base: + + + + + + + + 0 + 0 + + + + The base value for the column + + + + + + + + + + + + Waist + + + true + + + false + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Min value: + + + + + + + Minimal value described in the column + + + + + + + Max value: + + + + + + + Maximal value described in the column + + + + + + + Step: + + + + + + + + 0 + 0 + + + + Single-step between the column values + + + + + + + Base: + + + + + + + + 0 + 0 + + + + The base value for the column + + + + + + + + + + + + + + _ + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + groupBoxXDimension + spinBoxXDimensionMinValue + spinBoxXDimensionMaxValue + comboBoxXDimensionStep + comboBoxXDimensionBase + groupBoxYDimension + spinBoxYDimensionMinValue + spinBoxYDimensionMaxValue + comboBoxYDimensionStep + comboBoxYDimensionBase + groupBoxWDimension + spinBoxWDimensionMinValue + spinBoxWDimensionMaxValue + comboBoxWDimensionStep + comboBoxWDimensionBase + groupBoxZDimension + spinBoxZDimensionMinValue + spinBoxZDimensionMaxValue + comboBoxZDimensionStep + comboBoxZDimensionBase + + + + + + + buttonBox + accepted() + DialogSetupMultisize + accept() + + + 746 + 383 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogSetupMultisize + reject() + + + 746 + 383 + + + 286 + 274 + + + + + diff --git a/src/app/tape/tape.pri b/src/app/tape/tape.pri index 6f46e9e94..64c1e6023 100644 --- a/src/app/tape/tape.pri +++ b/src/app/tape/tape.pri @@ -11,7 +11,8 @@ SOURCES += \ $$PWD/vlitepattern.cpp \ $$PWD/dialogs/dialogtapepreferences.cpp \ $$PWD/dialogs/configpages/tapepreferencesconfigurationpage.cpp \ - $$PWD/dialogs/configpages/tapepreferencespathpage.cpp + $$PWD/dialogs/configpages/tapepreferencespathpage.cpp \ + $$PWD/dialogs/dialogsetupmultisize.cpp *msvc*:SOURCES += $$PWD/stable.cpp @@ -26,7 +27,8 @@ HEADERS += \ $$PWD/vlitepattern.h \ $$PWD/dialogs/dialogtapepreferences.h \ $$PWD/dialogs/configpages/tapepreferencesconfigurationpage.h \ - $$PWD/dialogs/configpages/tapepreferencespathpage.h + $$PWD/dialogs/configpages/tapepreferencespathpage.h \ + $$PWD/dialogs/dialogsetupmultisize.h FORMS += \ $$PWD/tmainwindow.ui \ @@ -35,4 +37,5 @@ FORMS += \ $$PWD/dialogs/dialogmdatabase.ui \ $$PWD/dialogs/dialogtapepreferences.ui \ $$PWD/dialogs/configpages/tapepreferencesconfigurationpage.ui \ - $$PWD/dialogs/configpages/tapepreferencespathpage.ui + $$PWD/dialogs/configpages/tapepreferencespathpage.ui \ + $$PWD/dialogs/dialogsetupmultisize.ui diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 889f2e3b8..636dd5c64 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -32,6 +32,7 @@ #include "dialogs/dialognewmeasurements.h" #include "dialogs/dialogmdatabase.h" #include "dialogs/dialogtapepreferences.h" +#include "dialogs/dialogsetupmultisize.h" #include "../vpatterndb/vcontainer.h" #include "../vpatterndb/calculator.h" #include "../vpatterndb/pmsystems.h" @@ -371,13 +372,24 @@ void TMainWindow::FileNew() pUnit = mUnit; mType = measurements.Type(); + if (mType == MeasurementsType::Multisize) + { + DialogSetupMultisize setup(mUnit, this); + if (setup.exec() == QDialog::Rejected) + { + return; + } + } + + return; // temporary + data = new VContainer(qApp->TrVars(), &mUnit, VContainer::UniqueNamespace()); - currentHeight = measurements.BaseHeight(); - currentSize = measurements.BaseSize(); +// currentHeight = measurements.BaseHeight(); +// currentSize = measurements.BaseSize(); if (mType == MeasurementsType::Multisize) { - m = new VMeasurements(mUnit, measurements.BaseSize(), measurements.BaseHeight(), data); + m = new VMeasurements(mUnit, /*measurements.BaseSize(), measurements.BaseHeight(),*/ data); m_curFileFormatVersion = VVSTConverter::MeasurementMaxVer; m_curFileFormatVersionStr = VVSTConverter::MeasurementMaxVerStr; } diff --git a/src/libs/vformat/vdimensions.cpp b/src/libs/vformat/vdimensions.cpp new file mode 100644 index 000000000..68cf958fd --- /dev/null +++ b/src/libs/vformat/vdimensions.cpp @@ -0,0 +1,372 @@ +/************************************************************************ + ** + ** @file vdimensions.cpp + ** @author Roman Telezhynskyi + ** @date 25 9, 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 "vdimensions.h" + +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- +VAbstartMeasurementDimension::VAbstartMeasurementDimension(Unit units) + : m_units(units) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstartMeasurementDimension::VAbstartMeasurementDimension(Unit units, int min, int max, int step) + : m_units(units), + m_minValue(min), + m_maxValue(max), + m_step(step) +{} + +//--------------------------------------------------------------------------------------------------------------------- +bool VAbstartMeasurementDimension::IsValid() +{ + m_error.clear(); + return IsUnitsValid() && IsRangeValid() && IsStepValid() && IsBaseValid(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector VAbstartMeasurementDimension::ValidSteps() const +{ + QVector steps; + + const int diff = m_maxValue - m_minValue; + if (diff == 0) + { + steps.append(0); // only one possible value + } + else if (diff > 0) + { + steps.append(1); + + auto AddStep = [&steps, diff](int step) + { + if (diff % step == 0) + { + steps.append(step); + } + }; + + for (int i=2; i < 9; ++i) + { + AddStep(i); + } + } + + return steps; +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector VAbstartMeasurementDimension::ValidBases() const +{ + QVector validBases; + int step = Step(); + + if (step < 0) + { + return validBases; + } + else if (step == 0) + { + step = 1; + } + + for (int value = MinValue(); value <= MaxValue(); value += step) + { + validBases.append(value); + } + + return validBases; +} + +//--------------------------------------------------------------------------------------------------------------------- +QStringList VAbstartMeasurementDimension::ValidBasesList() const +{ + QVector bases = ValidBases(); + QStringList list; + for(auto &base : bases) + { + list.append(QString::number(base)); + } + return list; + +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VAbstartMeasurementDimension::IsRangeValid() +{ + bool valid = m_minValue > 0 && m_maxValue > 0 && m_minValue >= RangeMin() && m_minValue <= RangeMax() + && m_minValue <= m_maxValue; + + if (not valid) + { + m_error = tr("Invalid min/max range"); + } + + return valid; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VAbstartMeasurementDimension::IsStepValid() +{ + bool valid = ValidSteps().indexOf(m_step) != -1; + if (not valid) + { + m_error = tr("Invalid step"); + } + + return valid; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VAbstartMeasurementDimension::IsBaseValid() +{ + bool valid = ValidBases().indexOf(m_baseValue) != -1; + if (not valid) + { + m_error = tr("Base value invalid"); + } + + return valid; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VAbstartMeasurementDimension::IsUnitsValid() +{ + return m_units == Unit::Cm || m_units == Unit::Mm || m_units == Unit::Inch; +} + +// VXMeasurementDimension +//--------------------------------------------------------------------------------------------------------------------- +VXMeasurementDimension::VXMeasurementDimension(Unit units) + : VAbstartMeasurementDimension(units) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VXMeasurementDimension::VXMeasurementDimension(Unit units, int min, int max, int step) + : VAbstartMeasurementDimension(units, min, max, step) +{} + +//--------------------------------------------------------------------------------------------------------------------- +MeasurementDimension VXMeasurementDimension::Type() const +{ + return MeasurementDimension::X; +} + +//--------------------------------------------------------------------------------------------------------------------- +int VXMeasurementDimension::RangeMin() const +{ + switch(m_units) + { + case Unit::Cm: + return 50; + case Unit::Mm: + return 500; + case Unit::Inch: + return 19; + default: + return 0; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +int VXMeasurementDimension::RangeMax() const +{ + switch(m_units) + { + case Unit::Cm: + return 272; + case Unit::Mm: + return 2720; + case Unit::Inch: + return 107; + default: + return 0; + } +} + +// VYMeasurementDimension +//--------------------------------------------------------------------------------------------------------------------- +VYMeasurementDimension::VYMeasurementDimension(Unit units) + : VAbstartMeasurementDimension(units) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VYMeasurementDimension::VYMeasurementDimension(Unit units, int min, int max, int step) + : VAbstartMeasurementDimension(units, min, max, step) +{} + +//--------------------------------------------------------------------------------------------------------------------- +MeasurementDimension VYMeasurementDimension::Type() const +{ + return MeasurementDimension::Y; +} + +//--------------------------------------------------------------------------------------------------------------------- +int VYMeasurementDimension::RangeMin() const +{ + if (m_circumference) + { + switch(m_units) + { + case Unit::Cm: + return 22; + case Unit::Mm: + return 220; + case Unit::Inch: + return 8; + default: + return 0; + } + } + else + { + return 6; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +int VYMeasurementDimension::RangeMax() const +{ + if (m_circumference) + { + switch(m_units) + { + case Unit::Cm: + return 72; + case Unit::Mm: + return 720; + case Unit::Inch: + return 29; + default: + return 0; + } + } + else + { + return 58; + } +} + +// VWMeasurementDimension +//--------------------------------------------------------------------------------------------------------------------- +VWMeasurementDimension::VWMeasurementDimension(Unit units) + : VAbstartMeasurementDimension(units) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VWMeasurementDimension::VWMeasurementDimension(Unit units, int min, int max, int step) + : VAbstartMeasurementDimension(units, min, max, step) +{} + +//--------------------------------------------------------------------------------------------------------------------- +MeasurementDimension VWMeasurementDimension::Type() const +{ + return MeasurementDimension::W; +} + +//--------------------------------------------------------------------------------------------------------------------- +int VWMeasurementDimension::RangeMin() const +{ + switch(m_units) + { + case Unit::Cm: + return 33; + case Unit::Mm: + return 330; + case Unit::Inch: + return 12; + default: + return 0; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +int VWMeasurementDimension::RangeMax() const +{ + switch(m_units) + { + case Unit::Cm: + return 63; + case Unit::Mm: + return 630; + case Unit::Inch: + return 25; + default: + return 0; + } +} + +// VZMeasurementDimension +//--------------------------------------------------------------------------------------------------------------------- +VZMeasurementDimension::VZMeasurementDimension(Unit units) + : VAbstartMeasurementDimension(units) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VZMeasurementDimension::VZMeasurementDimension(Unit units, int min, int max, int step) + : VAbstartMeasurementDimension(units, min, max, step) +{} + +//--------------------------------------------------------------------------------------------------------------------- +MeasurementDimension VZMeasurementDimension::Type() const +{ + return MeasurementDimension::Z; +} + +//--------------------------------------------------------------------------------------------------------------------- +int VZMeasurementDimension::RangeMin() const +{ + switch(m_units) + { + case Unit::Cm: + return 33; + case Unit::Mm: + return 330; + case Unit::Inch: + return 12; + default: + return 0; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +int VZMeasurementDimension::RangeMax() const +{ + switch(m_units) + { + case Unit::Cm: + return 63; + case Unit::Mm: + return 630; + case Unit::Inch: + return 25; + default: + return 0; + } +} diff --git a/src/libs/vformat/vdimensions.h b/src/libs/vformat/vdimensions.h new file mode 100644 index 000000000..efcd1d5bb --- /dev/null +++ b/src/libs/vformat/vdimensions.h @@ -0,0 +1,248 @@ +/************************************************************************ + ** + ** @file vdimensions.h + ** @author Roman Telezhynskyi + ** @date 25 9, 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 VDIMENSIONS_H +#define VDIMENSIONS_H + +#include + +#include "../vmisc/def.h" + +enum class MeasurementDimension: qint8 +{ + X, // height + Y, // size (chest half circumference) + W, // hip half circumference + Z // waist half circumference +}; + + +class VAbstartMeasurementDimension +{ + Q_DECLARE_TR_FUNCTIONS(VAbstartMeasurementDimension) +public: + VAbstartMeasurementDimension() =default; + explicit VAbstartMeasurementDimension(Unit units); + VAbstartMeasurementDimension(Unit units, int min, int max, int step); + virtual ~VAbstartMeasurementDimension() =default; + + virtual MeasurementDimension Type() const =0; + + virtual bool IsValid(); + + int MinValue() const; + void SetMinValue(int minValue); + + int MaxValue() const; + void SetMaxValue(int maxValue); + + int Step() const; + void SetStep(int step); + + int BaseValue() const; + void SetBaseValue(int baseValue); + + QString Error() const; + + Unit Units() const; + + virtual bool IsCircumference() const; + + virtual int RangeMin() const =0; + virtual int RangeMax() const =0; + + QVector ValidSteps() const; + QVector ValidBases() const; + QStringList ValidBasesList() const; + +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{}; + + bool IsRangeValid(); + bool IsStepValid(); + bool IsBaseValid(); + bool IsUnitsValid(); +}; + +//--------------------------------------------------------------------------------------------------------------------- +inline int VAbstartMeasurementDimension::MinValue() const +{ + return m_minValue; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstartMeasurementDimension::SetMinValue(int minValue) +{ + m_minValue = minValue; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline int VAbstartMeasurementDimension::MaxValue() const +{ + return m_maxValue; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstartMeasurementDimension::SetMaxValue(int maxValue) +{ + m_maxValue = maxValue; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline int VAbstartMeasurementDimension::Step() const +{ + return m_step; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstartMeasurementDimension::SetStep(int step) +{ + m_step = step; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline int VAbstartMeasurementDimension::BaseValue() const +{ + return m_baseValue; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstartMeasurementDimension::SetBaseValue(int baseValue) +{ + m_baseValue = baseValue; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline QString VAbstartMeasurementDimension::Error() const +{ + return m_error; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline Unit VAbstartMeasurementDimension::Units() const +{ + return m_units; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline bool VAbstartMeasurementDimension::IsCircumference() const +{ + return true; +} + +// VXMeasurementDimension +//--------------------------------------------------------------------------------------------------------------------- +class VXMeasurementDimension : public VAbstartMeasurementDimension +{ +public: + VXMeasurementDimension() =default; + explicit VXMeasurementDimension(Unit units); + VXMeasurementDimension(Unit units, int min, int max, int step); + + virtual MeasurementDimension Type() const override; + + virtual int RangeMin() const override; + virtual int RangeMax() const override; + + virtual bool IsCircumference() const override; +}; + +//--------------------------------------------------------------------------------------------------------------------- +inline bool VXMeasurementDimension::IsCircumference() const +{ + return false; +} + +// VYMeasurementDimension +//--------------------------------------------------------------------------------------------------------------------- +class VYMeasurementDimension : public VAbstartMeasurementDimension +{ +public: + VYMeasurementDimension() =default; + explicit VYMeasurementDimension(Unit units); + VYMeasurementDimension(Unit units, int min, int max, int step); + + virtual MeasurementDimension Type() const override; + + virtual int RangeMin() const override; + virtual int RangeMax() const override; + + virtual bool IsCircumference() const override; + void SetCircumference(bool circumference); + +private: + bool m_circumference{true}; +}; + +//--------------------------------------------------------------------------------------------------------------------- +inline bool VYMeasurementDimension::IsCircumference() const +{ + return m_circumference; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VYMeasurementDimension::SetCircumference(bool circumference) +{ + m_circumference = circumference; +} + +// VWMeasurementDimension +//--------------------------------------------------------------------------------------------------------------------- +class VWMeasurementDimension : public VAbstartMeasurementDimension +{ +public: + VWMeasurementDimension() =default; + explicit VWMeasurementDimension(Unit units); + VWMeasurementDimension(Unit units, int min, int max, int step); + + virtual MeasurementDimension Type() const override; + + virtual int RangeMin() const override; + virtual int RangeMax() const override; +}; + +// VZMeasurementDimension +//--------------------------------------------------------------------------------------------------------------------- +class VZMeasurementDimension : public VAbstartMeasurementDimension +{ +public: + VZMeasurementDimension() =default; + explicit VZMeasurementDimension(Unit units); + VZMeasurementDimension(Unit units, int min, int max, int step); + + virtual MeasurementDimension Type() const override; + + virtual int RangeMin() const override; + virtual int RangeMax() const override; +}; + +#endif // VDIMENSIONS_H diff --git a/src/libs/vformat/vformat.pri b/src/libs/vformat/vformat.pri index 77773b0b9..50b3cae4c 100644 --- a/src/libs/vformat/vformat.pri +++ b/src/libs/vformat/vformat.pri @@ -2,6 +2,7 @@ # This need for corect working file translations.pro SOURCES += \ + $$PWD/vdimensions.cpp \ $$PWD/vmeasurements.cpp \ $$PWD/vlabeltemplate.cpp \ $$PWD/vpatternrecipe.cpp \ @@ -10,6 +11,7 @@ SOURCES += \ *msvc*:SOURCES += $$PWD/stable.cpp HEADERS += \ + $$PWD/vdimensions.h \ $$PWD/vmeasurements.h \ $$PWD/stable.h \ $$PWD/vlabeltemplate.h \ diff --git a/src/libs/vmisc/vtapesettings.cpp b/src/libs/vmisc/vtapesettings.cpp index 4fef2e705..283becaac 100644 --- a/src/libs/vmisc/vtapesettings.cpp +++ b/src/libs/vmisc/vtapesettings.cpp @@ -37,9 +37,6 @@ namespace { Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDataBaseGeometry, (QLatin1String("database/geometry"))) - -Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDefHeight, (QLatin1String("gradation/defHeight"))) -Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDefSize, (QLatin1String("gradation/defSize"))) } //--------------------------------------------------------------------------------------------------------------------- @@ -60,27 +57,3 @@ void VTapeSettings::SetDataBaseGeometry(const QByteArray &value) { setValue(*settingDataBaseGeometry, value); } - -//--------------------------------------------------------------------------------------------------------------------- -void VTapeSettings::SetDefHeight(int value) -{ - setValue(*settingDefHeight, value); -} - -//--------------------------------------------------------------------------------------------------------------------- -int VTapeSettings::GetDefHeight() const -{ - return value(*settingDefHeight, 176).toInt(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VTapeSettings::SetDefSize(int value) -{ - setValue(*settingDefSize, value); -} - -//--------------------------------------------------------------------------------------------------------------------- -int VTapeSettings::GetDefSize() const -{ - return value(*settingDefSize, 50).toInt(); -} diff --git a/src/libs/vmisc/vtapesettings.h b/src/libs/vmisc/vtapesettings.h index 8624fe07e..752267303 100644 --- a/src/libs/vmisc/vtapesettings.h +++ b/src/libs/vmisc/vtapesettings.h @@ -49,12 +49,6 @@ public: QByteArray GetDataBaseGeometry() const; void SetDataBaseGeometry(const QByteArray &value); - void SetDefHeight(int value); - int GetDefHeight() const; - - void SetDefSize(int value); - int GetDefSize() const; - private: Q_DISABLE_COPY(VTapeSettings) }; From cea2671687720b998b32c4dd41f56cb1447bdf7e Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 1 Oct 2020 13:32:02 +0300 Subject: [PATCH 02/44] Saving dimensions. Reading dimensions. --- src/app/tape/dialogs/dialogsetupmultisize.cpp | 26 +-- src/app/tape/dialogs/dialogsetupmultisize.h | 20 +- src/app/tape/tmainwindow.cpp | 49 ++--- src/app/tape/tmainwindow.h | 5 +- src/app/valentina/mainwindow.cpp | 4 +- src/libs/vformat/vdimensions.h | 12 +- src/libs/vformat/vmeasurements.cpp | 186 +++++++++++++++--- src/libs/vformat/vmeasurements.h | 32 ++- src/test/ValentinaTest/tst_vmeasurements.cpp | 4 +- 9 files changed, 240 insertions(+), 98 deletions(-) diff --git a/src/app/tape/dialogs/dialogsetupmultisize.cpp b/src/app/tape/dialogs/dialogsetupmultisize.cpp index 4bbd8f71b..16db93d50 100644 --- a/src/app/tape/dialogs/dialogsetupmultisize.cpp +++ b/src/app/tape/dialogs/dialogsetupmultisize.cpp @@ -170,9 +170,9 @@ DialogSetupMultisize::~DialogSetupMultisize() } //--------------------------------------------------------------------------------------------------------------------- -QVector > DialogSetupMultisize::Dimensions() const +QVector DialogSetupMultisize::Dimensions() const { - QVector > dimensions; + QVector dimensions; if (ui->groupBoxXDimension->isChecked()) { @@ -236,7 +236,7 @@ void DialogSetupMultisize::ShowFullCircumference() { auto ShowDimensionFullCircumference = [this](QSpinBox *spinboxMinValue, QSpinBox *spinboxMaxValue, QComboBox *comboBoxStep, QComboBox *comboBoxBase, - const QSharedPointer &dimension) + const MeasurementDimension_p &dimension) { SCASSERT(spinboxMinValue != nullptr) SCASSERT(spinboxMaxValue != nullptr) @@ -302,7 +302,7 @@ void DialogSetupMultisize::CheckState() int dimensions = 0; auto CheckDimension = [this](QGroupBox *group, bool &dimensionValid, int &dimensions, - const QSharedPointer &dimension) + const MeasurementDimension_p &dimension) { SCASSERT(group != nullptr) @@ -346,7 +346,7 @@ void DialogSetupMultisize::CheckState() //--------------------------------------------------------------------------------------------------------------------- void DialogSetupMultisize::InitDimensionMinMax(QSpinBox *spinboxMinValue, QSpinBox *spinboxMaxValue, - const QSharedPointer &dimension) + const MeasurementDimension_p &dimension) { SCASSERT(spinboxMinValue != nullptr) SCASSERT(spinboxMaxValue != nullptr) @@ -383,7 +383,7 @@ void DialogSetupMultisize::InitDimensionMinMax(QSpinBox *spinboxMinValue, QSpinB //--------------------------------------------------------------------------------------------------------------------- void DialogSetupMultisize::InitDimensionStep(QComboBox *comboBoxStep, - const QSharedPointer &dimension) + const MeasurementDimension_p &dimension) { SCASSERT(comboBoxStep != nullptr) @@ -412,7 +412,7 @@ void DialogSetupMultisize::InitDimensionStep(QComboBox *comboBoxStep, //--------------------------------------------------------------------------------------------------------------------- void DialogSetupMultisize::InitDimension(QSpinBox *spinboxMinValue, QSpinBox *spinboxMaxValue, QComboBox *comboBoxStep, - const QSharedPointer &dimension) + const MeasurementDimension_p &dimension) { InitDimensionMinMax(spinboxMinValue, spinboxMaxValue, dimension); InitDimensionStep(comboBoxStep, dimension); @@ -449,7 +449,7 @@ void DialogSetupMultisize::InitZDimension() //--------------------------------------------------------------------------------------------------------------------- void DialogSetupMultisize::DimensionMinValueChanged(int value, QSpinBox *spinboxMaxValue, QComboBox *comboBoxStep, QComboBox *comboBoxBase, - const QSharedPointer &dimension) + const MeasurementDimension_p &dimension) { SCASSERT(spinboxMaxValue != nullptr) SCASSERT(comboBoxStep != nullptr) @@ -475,7 +475,7 @@ void DialogSetupMultisize::DimensionMinValueChanged(int value, QSpinBox *spinbox //--------------------------------------------------------------------------------------------------------------------- void DialogSetupMultisize::DimensionMaxValueChanged(int value, QSpinBox *spinboxMinValue, QComboBox *comboBoxStep, QComboBox *comboBoxBase, - const QSharedPointer &dimension) + const MeasurementDimension_p &dimension) { SCASSERT(spinboxMinValue != nullptr) SCASSERT(comboBoxStep != nullptr) @@ -500,7 +500,7 @@ void DialogSetupMultisize::DimensionMaxValueChanged(int value, QSpinBox *spinbox //--------------------------------------------------------------------------------------------------------------------- void DialogSetupMultisize::DimensionStepChanged(int index, QComboBox *comboBoxStep, QComboBox *comboBoxBase, - const QSharedPointer &dimension) + const MeasurementDimension_p &dimension) { SCASSERT(comboBoxStep != nullptr) SCASSERT(comboBoxBase != nullptr) @@ -516,7 +516,7 @@ void DialogSetupMultisize::DimensionStepChanged(int index, QComboBox *comboBoxSt //--------------------------------------------------------------------------------------------------------------------- void DialogSetupMultisize::DimensionBaseChanged(int index, QComboBox *comboBoxBase, - const QSharedPointer &dimension) + const MeasurementDimension_p &dimension) { SCASSERT(comboBoxBase != nullptr) @@ -529,7 +529,7 @@ void DialogSetupMultisize::DimensionBaseChanged(int index, QComboBox *comboBoxBa //--------------------------------------------------------------------------------------------------------------------- void DialogSetupMultisize::UpdateSteps(QComboBox *comboBoxStep, - const QSharedPointer &dimension) + const MeasurementDimension_p &dimension) { SCASSERT(comboBoxStep != nullptr) @@ -564,7 +564,7 @@ void DialogSetupMultisize::UpdateSteps(QComboBox *comboBoxStep, //--------------------------------------------------------------------------------------------------------------------- void DialogSetupMultisize::UpdateBase(QComboBox *comboBoxBase, - const QSharedPointer &dimension) + const MeasurementDimension_p &dimension) { SCASSERT(comboBoxBase != nullptr) diff --git a/src/app/tape/dialogs/dialogsetupmultisize.h b/src/app/tape/dialogs/dialogsetupmultisize.h index a70449b96..38bf76735 100644 --- a/src/app/tape/dialogs/dialogsetupmultisize.h +++ b/src/app/tape/dialogs/dialogsetupmultisize.h @@ -48,7 +48,7 @@ public: explicit DialogSetupMultisize(Unit unit, QWidget *parent = nullptr); ~DialogSetupMultisize(); - QVector > Dimensions() const; + QVector Dimensions() const; protected: virtual void changeEvent(QEvent* event) override; @@ -70,11 +70,11 @@ private: void CheckState(); void InitDimensionMinMax(QSpinBox *spinboxMinValue, QSpinBox *spinboxMaxValue, - const QSharedPointer &dimension); - void InitDimensionStep(QComboBox *comboBoxStep,const QSharedPointer &dimension); + const MeasurementDimension_p &dimension); + void InitDimensionStep(QComboBox *comboBoxStep,const MeasurementDimension_p &dimension); void InitDimension(QSpinBox *spinboxMinValue, QSpinBox *spinboxMaxValue, QComboBox *comboBoxStep, - const QSharedPointer &dimension); + const MeasurementDimension_p &dimension); void InitXDimension(); void InitYDimension(); void InitWDimension(); @@ -82,18 +82,18 @@ private: void DimensionMinValueChanged(int value, QSpinBox *spinboxMaxValue, QComboBox *comboBoxStep, QComboBox *comboBoxBase, - const QSharedPointer &dimension); + const MeasurementDimension_p &dimension); void DimensionMaxValueChanged(int value, QSpinBox *spinboxMinValue, QComboBox *comboBoxStep, QComboBox *comboBoxBase, - const QSharedPointer &dimension); + const MeasurementDimension_p &dimension); void DimensionStepChanged(int index, QComboBox *comboBoxStep, QComboBox *comboBoxBase, - const QSharedPointer &dimension); + const MeasurementDimension_p &dimension); void DimensionBaseChanged(int index, QComboBox *comboBoxBase, - const QSharedPointer &dimension); + const MeasurementDimension_p &dimension); - void UpdateSteps(QComboBox *comboBoxStep, const QSharedPointer &dimension); - void UpdateBase(QComboBox *comboBoxBase, const QSharedPointer &dimension); + void UpdateSteps(QComboBox *comboBoxStep, const MeasurementDimension_p &dimension); + void UpdateBase(QComboBox *comboBoxBase, const MeasurementDimension_p &dimension); }; #endif // DIALOGSETUPMULTISIZE_H diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 636dd5c64..8b8fd2c1e 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -92,8 +92,6 @@ TMainWindow::TMainWindow(QWidget *parent) mUnit(Unit::Cm), pUnit(Unit::Cm), mType(MeasurementsType::Individual), - currentSize(0), - currentHeight(0), curFile(), gradationHeights(nullptr), gradationSizes(nullptr), @@ -182,10 +180,10 @@ void TMainWindow::SetBaseMHeight(int height) if (mType == MeasurementsType::Multisize) { const int row = ui->tableWidget->currentRow(); - currentHeight = UnitConvertor(height, Unit::Cm, mUnit); + currentDimensionA = UnitConvertor(height, Unit::Cm, mUnit); gradationHeights->blockSignals(true); - SetDefaultHeight(static_cast(currentHeight)); + SetDefaultHeight(static_cast(currentDimensionA)); gradationHeights->blockSignals(false); RefreshData(); @@ -203,10 +201,10 @@ void TMainWindow::SetBaseMSize(int size) if (mType == MeasurementsType::Multisize) { const int row = ui->tableWidget->currentRow(); - currentSize = UnitConvertor(size, Unit::Cm, mUnit); + currentDimensionB = UnitConvertor(size, Unit::Cm, mUnit); gradationSizes->blockSignals(true); - SetDefaultSize(static_cast(currentSize)); + SetDefaultSize(static_cast(currentDimensionB)); gradationSizes->blockSignals(false); RefreshData(); @@ -298,8 +296,8 @@ bool TMainWindow::LoadFile(const QString &path) mUnit = m->MUnit(); pUnit = mUnit; - currentSize = m->BaseSize(); - currentHeight = m->BaseHeight(); + currentDimensionB = m->DimensionABase(); + currentDimensionA = m->DimensionBBase(); ui->labelToolTip->setVisible(false); ui->tabWidget->setVisible(true); @@ -379,22 +377,17 @@ void TMainWindow::FileNew() { return; } - } - return; // temporary + data = new VContainer(qApp->TrVars(), &mUnit, VContainer::UniqueNamespace()); - data = new VContainer(qApp->TrVars(), &mUnit, VContainer::UniqueNamespace()); -// currentHeight = measurements.BaseHeight(); -// currentSize = measurements.BaseSize(); - - if (mType == MeasurementsType::Multisize) - { - m = new VMeasurements(mUnit, /*measurements.BaseSize(), measurements.BaseHeight(),*/ data); + m = new VMeasurements(mUnit, setup.Dimensions(), data); m_curFileFormatVersion = VVSTConverter::MeasurementMaxVer; m_curFileFormatVersionStr = VVSTConverter::MeasurementMaxVerStr; } else { + data = new VContainer(qApp->TrVars(), &mUnit, VContainer::UniqueNamespace()); + m = new VMeasurements(mUnit, data); m_curFileFormatVersion = VVITConverter::MeasurementMaxVer; m_curFileFormatVersionStr = VVITConverter::MeasurementMaxVerStr; @@ -568,9 +561,9 @@ void TMainWindow::changeEvent(QEvent *event) if (mType == MeasurementsType::Multisize) { ui->labelMType->setText(tr("Multisize measurements")); - ui->labelBaseSizeValue->setText(QString().setNum(m->BaseSize()) + QChar(QChar::Space) + + ui->labelBaseSizeValue->setText(QString().setNum(m->DimensionABase()) + QChar(QChar::Space) + UnitsToStr(m->MUnit(), true)); - ui->labelBaseHeightValue->setText(QString().setNum(m->BaseHeight()) + QChar(QChar::Space) + + ui->labelBaseHeightValue->setText(QString().setNum(m->DimensionBBase()) + QChar(QChar::Space) + UnitsToStr(m->MUnit(), true)); labelGradationHeights->setText(tr("Height (%1):").arg(UnitsToStr(mUnit))); @@ -1468,7 +1461,7 @@ void TMainWindow::ImportFromPattern() void TMainWindow::ChangedSize(const QString &text) { const int row = ui->tableWidget->currentRow(); - currentSize = text.toInt(); + currentDimensionB = text.toInt(); RefreshData(); search->RefreshList(ui->lineEditFind->text()); ui->tableWidget->selectRow(row); @@ -1478,7 +1471,7 @@ void TMainWindow::ChangedSize(const QString &text) void TMainWindow::ChangedHeight(const QString &text) { const int row = ui->tableWidget->currentRow(); - currentHeight = text.toInt(); + currentDimensionA = text.toInt(); RefreshData(); search->RefreshList(ui->lineEditFind->text()); ui->tableWidget->selectRow(row); @@ -2031,9 +2024,9 @@ void TMainWindow::InitWindow() if (mType == MeasurementsType::Multisize) { ui->labelMType->setText(tr("Multisize measurements")); - ui->labelBaseSizeValue->setText(QString().setNum(m->BaseSize()) + QChar(QChar::Space) + + ui->labelBaseSizeValue->setText(QString().setNum(m->DimensionABase()) + QChar(QChar::Space) + UnitsToStr(m->MUnit(), true)); - ui->labelBaseHeightValue->setText(QString().setNum(m->BaseHeight()) + QChar(QChar::Space) + + ui->labelBaseHeightValue->setText(QString().setNum(m->DimensionBBase()) + QChar(QChar::Space) + UnitsToStr(m->MUnit(), true)); // Because Qt Designer doesn't know about our deleting we will create empty objects for correct @@ -2379,7 +2372,7 @@ void TMainWindow::SetDefaultHeight(int value) } else { - currentHeight = gradationHeights->currentText().toInt(); + currentDimensionA = gradationHeights->currentText().toInt(); } } @@ -2393,7 +2386,7 @@ void TMainWindow::SetDefaultSize(int value) } else { - currentSize = gradationSizes->currentText().toInt(); + currentDimensionB = gradationSizes->currentText().toInt(); } } @@ -2402,7 +2395,7 @@ void TMainWindow::RefreshData(bool freshCall) { data->ClearUniqueNames(); data->ClearVariables(VarType::Measurement); - m->ReadMeasurements(currentHeight, currentSize); + m->ReadMeasurements(currentDimensionA, currentDimensionB); RefreshTable(freshCall); } @@ -2884,8 +2877,8 @@ bool TMainWindow::LoadFromExistingFile(const QString &path) mUnit = m->MUnit(); pUnit = mUnit; - currentHeight = m->BaseHeight(); - currentSize = m->BaseSize(); + currentDimensionA = m->DimensionBBase(); + currentDimensionB = m->DimensionABase(); ui->labelToolTip->setVisible(false); ui->tabWidget->setVisible(true); diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index 17bf00074..15795d3d4 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -135,8 +135,9 @@ private: Unit mUnit; Unit pUnit; MeasurementsType mType; - qreal currentSize; - qreal currentHeight; + int currentDimensionA{0}; + int currentDimensionB{0}; + int currentDimensionC{0}; QString curFile; QComboBox *gradationHeights; QComboBox *gradationSizes; diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index f7caa17e9..3c1ac6bab 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -499,8 +499,8 @@ bool MainWindow::LoadMeasurements(const QString &path) return false; } - const qreal size = UnitConvertor(m->BaseSize(), m->MUnit(), *m->GetData()->GetPatternUnit()); - const qreal height = UnitConvertor(m->BaseHeight(), m->MUnit(), *m->GetData()->GetPatternUnit()); + const qreal size = UnitConvertor(m->DimensionABase(), m->MUnit(), *m->GetData()->GetPatternUnit()); + const qreal height = UnitConvertor(m->DimensionBBase(), m->MUnit(), *m->GetData()->GetPatternUnit()); try { diff --git a/src/libs/vformat/vdimensions.h b/src/libs/vformat/vdimensions.h index efcd1d5bb..2b58e772d 100644 --- a/src/libs/vformat/vdimensions.h +++ b/src/libs/vformat/vdimensions.h @@ -34,12 +34,16 @@ enum class MeasurementDimension: qint8 { - X, // height - Y, // size (chest half circumference) - W, // hip half circumference - Z // waist half circumference + X = 0, // height + Y = 1, // size (chest half circumference) + W = 2, // hip half circumference + Z = 3 // waist half circumference }; +class VAbstartMeasurementDimension; +template class QSharedPointer; + +using MeasurementDimension_p = QSharedPointer; class VAbstartMeasurementDimension { diff --git a/src/libs/vformat/vmeasurements.cpp b/src/libs/vformat/vmeasurements.cpp index e99373c08..b566c2685 100644 --- a/src/libs/vformat/vmeasurements.cpp +++ b/src/libs/vformat/vmeasurements.cpp @@ -60,8 +60,6 @@ const QString VMeasurements::TagVST = QStringLiteral("vst"); const QString VMeasurements::TagVIT = QStringLiteral("vit"); const QString VMeasurements::TagBodyMeasurements = QStringLiteral("body-measurements"); const QString VMeasurements::TagNotes = QStringLiteral("notes"); -const QString VMeasurements::TagSize = QStringLiteral("size"); -const QString VMeasurements::TagHeight = QStringLiteral("height"); const QString VMeasurements::TagPersonal = QStringLiteral("personal"); const QString VMeasurements::TagCustomer = QStringLiteral("customer"); const QString VMeasurements::TagBirthDate = QStringLiteral("birth-date"); @@ -70,6 +68,9 @@ const QString VMeasurements::TagPMSystem = QStringLiteral("pm_system"); const QString VMeasurements::TagEmail = QStringLiteral("email"); const QString VMeasurements::TagReadOnly = QStringLiteral("read-only"); const QString VMeasurements::TagMeasurement = QStringLiteral("m"); +const QString VMeasurements::TagDimensions = QStringLiteral("dimensions"); +const QString VMeasurements::TagDimension = QStringLiteral("dimension"); +const QString VMeasurements::TagRestrictions = QStringLiteral("restrictions"); const QString VMeasurements::AttrBase = QStringLiteral("base"); const QString VMeasurements::AttrValue = QStringLiteral("value"); @@ -78,11 +79,20 @@ const QString VMeasurements::AttrHeightIncrease = QStringLiteral("height_increas const QString VMeasurements::AttrDescription = QStringLiteral("description"); const QString VMeasurements::AttrName = QStringLiteral("name"); const QString VMeasurements::AttrFullName = QStringLiteral("full_name"); +const QString VMeasurements::AttrMin = QStringLiteral("min"); +const QString VMeasurements::AttrMax = QStringLiteral("max"); +const QString VMeasurements::AttrStep = QStringLiteral("step"); +const QString VMeasurements::AttrCircumference = QStringLiteral("circumference"); const QString VMeasurements::GenderMale = QStringLiteral("male"); const QString VMeasurements::GenderFemale = QStringLiteral("female"); const QString VMeasurements::GenderUnknown = QStringLiteral("unknown"); +const QString VMeasurements::DimensionX = QStringLiteral("x"); +const QString VMeasurements::DimensionY = QStringLiteral("y"); +const QString VMeasurements::DimensionW = QStringLiteral("w"); +const QString VMeasurements::DimensionZ = QStringLiteral("z"); + namespace { Q_GLOBAL_STATIC_WITH_ARGS(const QString, defBirthDate, (QLatin1String("1800-01-01"))) @@ -112,18 +122,19 @@ VMeasurements::VMeasurements(Unit unit, VContainer *data) { SCASSERT(data != nullptr) - CreateEmptyIndividualFile(unit); + CreateEmptyIndividualFile(unit); } //--------------------------------------------------------------------------------------------------------------------- -VMeasurements::VMeasurements(Unit unit, int baseSize, int baseHeight, VContainer *data) +VMeasurements::VMeasurements(Unit unit, const QVector &dimensions, + VContainer *data) :VDomDocument(), - data(data), - type(MeasurementsType::Multisize) + data(data), + type(MeasurementsType::Multisize) { SCASSERT(data != nullptr) - CreateEmptyMultisizeFile(unit, baseSize, baseHeight); + CreateEmptyMultisizeFile(unit, dimensions); } //--------------------------------------------------------------------------------------------------------------------- @@ -282,8 +293,8 @@ void VMeasurements::ReadMeasurements(qreal height, qreal size) const qreal ksize = GetParametrDouble(dom, AttrSizeIncrease, QChar('0')); qreal kheight = GetParametrDouble(dom, AttrHeightIncrease, QChar('0')); - tempMeash = QSharedPointer(new VMeasurement(static_cast(i), name, BaseSize(), - BaseHeight(), base, ksize, kheight)); + tempMeash = QSharedPointer(new VMeasurement(static_cast(i), name, DimensionABase(), + DimensionBBase(), base, ksize, kheight)); tempMeash->SetSize(size); tempMeash->SetHeight(height); tempMeash->SetUnit(data->GetPatternUnit()); @@ -292,8 +303,8 @@ void VMeasurements::ReadMeasurements(qreal height, qreal size) const ksize = UnitConvertor(ksize, MUnit(), *data->GetPatternUnit()); kheight = UnitConvertor(kheight, MUnit(), *data->GetPatternUnit()); - const qreal baseSize = UnitConvertor(BaseSize(), MUnit(), *data->GetPatternUnit()); - const qreal baseHeight = UnitConvertor(BaseHeight(), MUnit(), *data->GetPatternUnit()); + const qreal baseSize = UnitConvertor(DimensionABase(), MUnit(), *data->GetPatternUnit()); + const qreal baseHeight = UnitConvertor(DimensionBBase(), MUnit(), *data->GetPatternUnit()); meash = QSharedPointer(new VMeasurement(static_cast(i), name, baseSize, baseHeight, base, ksize, kheight, fullName, description)); @@ -352,29 +363,48 @@ MeasurementsType VMeasurements::Type() const } //--------------------------------------------------------------------------------------------------------------------- -int VMeasurements::BaseSize() const +int VMeasurements::DimensionABase() const { if (type == MeasurementsType::Multisize) { - return static_cast(UniqueTagAttr(TagSize, AttrBase, 50)); - } - else - { - return 0; + const auto dimensions = Dimensions(); + if (not dimensions.isEmpty()) + { + return dimensions.first()->BaseValue(); + } } + + return 0; } //--------------------------------------------------------------------------------------------------------------------- -int VMeasurements::BaseHeight() const +int VMeasurements::DimensionBBase() const { if (type == MeasurementsType::Multisize) { - return static_cast(UniqueTagAttr(TagHeight, AttrBase, 176)); + const auto dimensions = Dimensions(); + if (not dimensions.isEmpty() && dimensions.size() >= 2) + { + return dimensions.values().at(1)->BaseValue(); + } } - else + + return 0; +} + +//--------------------------------------------------------------------------------------------------------------------- +int VMeasurements::DimensionCBase() const +{ + if (type == MeasurementsType::Multisize) { - return 0; + const auto dimensions = Dimensions(); + if (not dimensions.isEmpty() && dimensions.size() >= 3) + { + return dimensions.last()->BaseValue(); + } } + + return 0; } //--------------------------------------------------------------------------------------------------------------------- @@ -577,6 +607,45 @@ void VMeasurements::SetMFullName(const QString &name, const QString &text) } } +//--------------------------------------------------------------------------------------------------------------------- +QMap VMeasurements::Dimensions() const +{ + QMap dimesions; + + const Unit units = MUnit(); + const QDomNodeList list = elementsByTagName(TagDimension); + for (int i=0; i < list.size(); ++i) + { + const QDomElement dom = list.at(i).toElement(); + const MeasurementDimension type = StrToDimensionType(GetParametrString(dom, AttrType)); + const int min = GetParametrInt(dom, AttrMin, QChar('0')); + const int max = GetParametrInt(dom, AttrMax, QChar('0')); + const int step = GetParametrInt(dom, AttrStep, QString("-1")); + + if (type == MeasurementDimension::X) + { + dimesions.insert(type, QSharedPointer::create(units, min, max, step)); + } + else if (type == MeasurementDimension::Y) + { + auto dimension = QSharedPointer::create(units, min, max, step); + dimension->SetCircumference(GetParametrBool(dom, AttrCircumference, trueStr)); + + dimesions.insert(type, dimension); + } + else if (type == MeasurementDimension::W) + { + dimesions.insert(type, QSharedPointer::create(units, min, max, step)); + } + else if (type == MeasurementDimension::Z) + { + dimesions.insert(type, QSharedPointer::create(units, min, max, step)); + } + } + + return dimesions; +} + //--------------------------------------------------------------------------------------------------------------------- QString VMeasurements::GenderToStr(const GenderType &sex) { @@ -608,6 +677,41 @@ GenderType VMeasurements::StrToGender(const QString &sex) } } +//--------------------------------------------------------------------------------------------------------------------- +QString VMeasurements::DimensionTypeToStr(const MeasurementDimension &type) +{ + switch (type) + { + case MeasurementDimension::Y: + return DimensionY; + case MeasurementDimension::W: + return DimensionW; + case MeasurementDimension::Z: + return DimensionZ; + case MeasurementDimension::X: + default: + return DimensionX; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +MeasurementDimension VMeasurements::StrToDimensionType(const QString &type) +{ + const QStringList dimensions = QStringList{DimensionX, DimensionY, DimensionW, DimensionZ}; + switch (dimensions.indexOf(type)) + { + case 1: // DimensionY + return MeasurementDimension::Y; + case 2: // DimensionW + return MeasurementDimension::W; + case 3: // DimensionZ + return MeasurementDimension::Z; + case 0: // DimensionX + default: + return MeasurementDimension::X; + } +} + //--------------------------------------------------------------------------------------------------------------------- QStringList VMeasurements::ListAll() const { @@ -672,7 +776,8 @@ VContainer *VMeasurements::GetData() const } //--------------------------------------------------------------------------------------------------------------------- -void VMeasurements::CreateEmptyMultisizeFile(Unit unit, int baseSize, int baseHeight) +void VMeasurements::CreateEmptyMultisizeFile(Unit unit, + const QVector &dimensions) { this->clear(); QDomElement mElement = this->createElement(TagVST); @@ -683,15 +788,8 @@ void VMeasurements::CreateEmptyMultisizeFile(Unit unit, int baseSize, int baseHe mElement.appendChild(createElement(TagNotes)); mElement.appendChild(CreateElementWithText(TagUnit, UnitsToStr(unit))); mElement.appendChild(CreateElementWithText(TagPMSystem, ClearPMCode(p998_S))); - - QDomElement size = createElement(TagSize); - SetAttribute(size, AttrBase, QString().setNum(baseSize)); - mElement.appendChild(size); - - QDomElement height = createElement(TagHeight); - SetAttribute(height, AttrBase, QString().setNum(baseHeight)); - mElement.appendChild(height); - + mElement.appendChild(CreateDimensions(dimensions)); + mElement.appendChild(createElement(TagRestrictions)); mElement.appendChild(createElement(TagBodyMeasurements)); this->appendChild(mElement); @@ -727,6 +825,32 @@ void VMeasurements::CreateEmptyIndividualFile(Unit unit) QStringLiteral("version=\"1.0\" encoding=\"UTF-8\"")), this->firstChild()); } +//--------------------------------------------------------------------------------------------------------------------- +QDomElement VMeasurements::CreateDimensions(const QVector &dimensions) +{ + QDomElement dimensionsTag = createElement(TagDimensions); + + for(auto &dimension : dimensions) + { + QDomElement dimensionTag = createElement(TagDimension); + + SetAttribute(dimensionTag, AttrType, DimensionTypeToStr(dimension->Type())); + SetAttribute(dimensionTag, AttrBase, dimension->BaseValue()); + SetAttribute(dimensionTag, AttrMin, dimension->MinValue()); + SetAttribute(dimensionTag, AttrMax, dimension->MaxValue()); + SetAttribute(dimensionTag, AttrStep, dimension->Step()); + + if (dimension->Type() == MeasurementDimension::Y) + { + SetAttribute(dimensionTag, AttrCircumference, dimension->IsCircumference()); + } + + dimensionsTag.appendChild(dimensionTag); + } + + return dimensionsTag; +} + //--------------------------------------------------------------------------------------------------------------------- qreal VMeasurements::UniqueTagAttr(const QString &tag, const QString &attr, qreal defValue) const { diff --git a/src/libs/vformat/vmeasurements.h b/src/libs/vformat/vmeasurements.h index 277470b9b..142ae6a7b 100644 --- a/src/libs/vformat/vmeasurements.h +++ b/src/libs/vformat/vmeasurements.h @@ -38,6 +38,7 @@ #include "../ifc/xml/vdomdocument.h" #include "../vmisc/def.h" +#include "vdimensions.h" class VContainer; @@ -49,7 +50,8 @@ class VMeasurements : public VDomDocument public: explicit VMeasurements(VContainer *data); VMeasurements(Unit unit, VContainer *data); - VMeasurements(Unit unit, int baseSize, int baseHeight, VContainer *data); + VMeasurements(Unit unit, const QVector &dimensions, + VContainer *data); virtual ~VMeasurements() Q_DECL_EQ_DEFAULT; virtual void setXMLContent(const QString &fileName) override; @@ -69,8 +71,9 @@ public: void ClearForExport(); MeasurementsType Type() const; - int BaseSize() const; - int BaseHeight() const; + int DimensionABase() const; + int DimensionBBase() const; + int DimensionCBase() const; QString Notes() const; void SetNotes(const QString &text); @@ -101,12 +104,12 @@ public: void SetMDescription(const QString &name, const QString &text); void SetMFullName(const QString &name, const QString &text); + QMap Dimensions() const; + static const QString TagVST; static const QString TagVIT; static const QString TagBodyMeasurements; static const QString TagNotes; - static const QString TagSize; - static const QString TagHeight; static const QString TagPersonal; static const QString TagCustomer; static const QString TagBirthDate; @@ -115,6 +118,9 @@ public: static const QString TagEmail; static const QString TagReadOnly; static const QString TagMeasurement; + static const QString TagDimensions; + static const QString TagDimension; + static const QString TagRestrictions; static const QString AttrBase; static const QString AttrValue; @@ -123,14 +129,26 @@ public: static const QString AttrDescription; static const QString AttrName; static const QString AttrFullName; + static const QString AttrMin; + static const QString AttrMax; + static const QString AttrStep; + static const QString AttrCircumference; static const QString GenderMale; static const QString GenderFemale; static const QString GenderUnknown; + static const QString DimensionX; + static const QString DimensionY; + static const QString DimensionW; + static const QString DimensionZ; + static QString GenderToStr(const GenderType &sex); static GenderType StrToGender(const QString &sex); + static QString DimensionTypeToStr(const MeasurementDimension &type); + static MeasurementDimension StrToDimensionType(const QString &type); + QStringList ListAll() const; QStringList ListKnown() const; @@ -148,9 +166,11 @@ private: /** @brief m_keepNames store names in container to check uniqueness. */ bool m_keepNames{true}; - void CreateEmptyMultisizeFile(Unit unit, int baseSize, int baseHeight); + void CreateEmptyMultisizeFile(Unit unit, const QVector &dimensions); void CreateEmptyIndividualFile(Unit unit); + QDomElement CreateDimensions(const QVector &dimensions); + qreal UniqueTagAttr(const QString &tag, const QString &attr, qreal defValue) const; QDomElement MakeEmpty(const QString &name, const QString &formula); diff --git a/src/test/ValentinaTest/tst_vmeasurements.cpp b/src/test/ValentinaTest/tst_vmeasurements.cpp index 8a749a379..46761aeac 100644 --- a/src/test/ValentinaTest/tst_vmeasurements.cpp +++ b/src/test/ValentinaTest/tst_vmeasurements.cpp @@ -57,7 +57,7 @@ void TST_VMeasurements::CreateEmptyMultisizeFile() data->SetSize(size); QSharedPointer m = - QSharedPointer(new VMeasurements(mUnit, size, height, data.data())); + QSharedPointer(new VMeasurements(mUnit, /*size, height,*/ data.data())); QTemporaryFile file; QString fileName; @@ -147,7 +147,7 @@ void TST_VMeasurements::ValidPMCodesMultisizeFile() data->SetSize(size); QSharedPointer m = - QSharedPointer(new VMeasurements(mUnit, size, height, data.data())); + QSharedPointer(new VMeasurements(mUnit, /*size, height,*/ data.data())); const QStringList listSystems = ListPMSystems(); for (int i = 0; i < listSystems.size(); ++i) From daef1799ab8202c305eb99c46fcc6b00325dea7e Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 1 Oct 2020 19:09:05 +0300 Subject: [PATCH 03/44] New format version. Basic implementation. --- src/libs/ifc/schema.qrc | 1 + .../schema/standard_measurements/v0.5.0.xsd | 95 +++++++++++++++++++ src/libs/ifc/xml/vvstconverter.cpp | 77 +++++++++------ src/libs/ifc/xml/vvstconverter.h | 5 +- 4 files changed, 145 insertions(+), 33 deletions(-) create mode 100644 src/libs/ifc/schema/standard_measurements/v0.5.0.xsd diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index 5d41d6883..c98ebbe84 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -65,6 +65,7 @@ schema/standard_measurements/v0.4.2.xsd schema/standard_measurements/v0.4.3.xsd schema/standard_measurements/v0.4.4.xsd + schema/standard_measurements/v0.5.0.xsd schema/individual_measurements/v0.2.0.xsd schema/individual_measurements/v0.3.0.xsd schema/individual_measurements/v0.3.1.xsd diff --git a/src/libs/ifc/schema/standard_measurements/v0.5.0.xsd b/src/libs/ifc/schema/standard_measurements/v0.5.0.xsd new file mode 100644 index 000000000..00a520ec5 --- /dev/null +++ b/src/libs/ifc/schema/standard_measurements/v0.5.0.xsd @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vvstconverter.cpp b/src/libs/ifc/xml/vvstconverter.cpp index e6bc9c2d9..4de64c117 100644 --- a/src/libs/ifc/xml/vvstconverter.cpp +++ b/src/libs/ifc/xml/vvstconverter.cpp @@ -54,8 +54,8 @@ */ const QString VVSTConverter::MeasurementMinVerStr = QStringLiteral("0.3.0"); -const QString VVSTConverter::MeasurementMaxVerStr = QStringLiteral("0.4.4"); -const QString VVSTConverter::CurrentSchema = QStringLiteral("://schema/standard_measurements/v0.4.4.xsd"); +const QString VVSTConverter::MeasurementMaxVerStr = QStringLiteral("0.5.0"); +const QString VVSTConverter::CurrentSchema = QStringLiteral("://schema/standard_measurements/v0.5.0.xsd"); //VVSTConverter::MeasurementMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VVSTConverter::MeasurementMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! @@ -75,25 +75,25 @@ VVSTConverter::VVSTConverter(const QString &fileName) //--------------------------------------------------------------------------------------------------------------------- QString VVSTConverter::XSDSchema(int ver) const { - switch (ver) + QHash schemas = { - case (0x000300): - return QStringLiteral("://schema/standard_measurements/v0.3.0.xsd"); - case (0x000400): - return QStringLiteral("://schema/standard_measurements/v0.4.0.xsd"); - case (0x000401): - return QStringLiteral("://schema/standard_measurements/v0.4.1.xsd"); - case (0x000402): - return QStringLiteral("://schema/standard_measurements/v0.4.2.xsd"); - case (0x000403): - return QStringLiteral("://schema/standard_measurements/v0.4.3.xsd"); - case (0x000404): - return CurrentSchema; - default: - InvalidVersion(ver); - break; + std::make_pair(FORMAT_VERSION(0, 3, 0), QStringLiteral("://schema/standard_measurements/v0.3.0.xsd")), + std::make_pair(FORMAT_VERSION(0, 4, 0), QStringLiteral("://schema/standard_measurements/v0.4.0.xsd")), + std::make_pair(FORMAT_VERSION(0, 4, 1), QStringLiteral("://schema/standard_measurements/v0.4.1.xsd")), + std::make_pair(FORMAT_VERSION(0, 4, 2), QStringLiteral("://schema/standard_measurements/v0.4.2.xsd")), + std::make_pair(FORMAT_VERSION(0, 4, 3), QStringLiteral("://schema/standard_measurements/v0.4.3.xsd")), + std::make_pair(FORMAT_VERSION(0, 4, 4), QStringLiteral("://schema/standard_measurements/v0.4.4.xsd")), + std::make_pair(FORMAT_VERSION(0, 5, 0), CurrentSchema), + }; + + if (schemas.contains(ver)) + { + return schemas.value(ver); + } + else + { + InvalidVersion(ver); } - return QString();//unreachable code } //--------------------------------------------------------------------------------------------------------------------- @@ -101,27 +101,31 @@ void VVSTConverter::ApplyPatches() { switch (m_ver) { - case (0x000300): + case (FORMAT_VERSION(0, 3, 0)): ToV0_4_0(); - ValidateXML(XSDSchema(0x000400)); + ValidateXML(XSDSchema(FORMAT_VERSION(0, 4, 0))); Q_FALLTHROUGH(); - case (0x000400): + case (FORMAT_VERSION(0, 4, 0)): ToV0_4_1(); - ValidateXML(XSDSchema(0x000401)); + ValidateXML(XSDSchema(FORMAT_VERSION(0, 4, 1))); Q_FALLTHROUGH(); - case (0x000401): + case (FORMAT_VERSION(0, 4, 1)): ToV0_4_2(); - ValidateXML(XSDSchema(0x000402)); + ValidateXML(XSDSchema(FORMAT_VERSION(0, 4, 2))); Q_FALLTHROUGH(); - case (0x000402): + case (FORMAT_VERSION(0, 4, 2)): ToV0_4_3(); - ValidateXML(XSDSchema(0x000403)); + ValidateXML(XSDSchema(FORMAT_VERSION(0, 4, 3))); Q_FALLTHROUGH(); - case (0x000403): + case (FORMAT_VERSION(0, 4, 3)): ToV0_4_4(); - ValidateXML(XSDSchema(0x000404)); + ValidateXML(XSDSchema(FORMAT_VERSION(0, 4, 4))); Q_FALLTHROUGH(); - case (0x000404): + case (FORMAT_VERSION(0, 4, 4)): + ToV0_5_0(); + ValidateXML(XSDSchema(FORMAT_VERSION(0, 5, 0))); + Q_FALLTHROUGH(); + case (FORMAT_VERSION(0, 5, 0)): break; default: InvalidVersion(m_ver); @@ -140,7 +144,7 @@ void VVSTConverter::DowngradeToCurrentMaxVersion() bool VVSTConverter::IsReadOnly() const { // Check if attribute read-only was not changed in file format - Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMaxVer == FORMAT_VERSION(0, 4, 4), + Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMaxVer == FORMAT_VERSION(0, 5, 0), "Check attribute read-only."); // Possibly in future attribute read-only will change position etc. @@ -368,3 +372,14 @@ void VVSTConverter::ToV0_4_4() SetVersion(QStringLiteral("0.4.4")); Save(); } + +//--------------------------------------------------------------------------------------------------------------------- +void VVSTConverter::ToV0_5_0() +{ + // TODO. Delete if minimal supported version is 0.5.0 + Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < FORMAT_VERSION(0, 5, 0), + "Time to refactor the code."); + + SetVersion(QStringLiteral("0.5.0")); + Save(); +} diff --git a/src/libs/ifc/xml/vvstconverter.h b/src/libs/ifc/xml/vvstconverter.h index e7daed282..907b4d421 100644 --- a/src/libs/ifc/xml/vvstconverter.h +++ b/src/libs/ifc/xml/vvstconverter.h @@ -51,10 +51,10 @@ public: // GCC 4.6 doesn't allow constexpr and const together #if !defined(__INTEL_COMPILER) && !defined(__clang__) && defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) <= 406 static Q_DECL_CONSTEXPR int MeasurementMinVer = FORMAT_VERSION(0, 3, 0); - static Q_DECL_CONSTEXPR int MeasurementMaxVer = FORMAT_VERSION(0, 4, 4); + static Q_DECL_CONSTEXPR int MeasurementMaxVer = FORMAT_VERSION(0, 5, 0); #else static Q_DECL_CONSTEXPR const int MeasurementMinVer = FORMAT_VERSION(0, 3, 0); - static Q_DECL_CONSTEXPR const int MeasurementMaxVer = FORMAT_VERSION(0, 4, 4); + static Q_DECL_CONSTEXPR const int MeasurementMaxVer = FORMAT_VERSION(0, 5, 0); #endif protected: @@ -85,6 +85,7 @@ private: void ToV0_4_2(); void ToV0_4_3(); void ToV0_4_4(); + void ToV0_5_0(); }; //--------------------------------------------------------------------------------------------------------------------- From a0cfebf10db4a8fb9f9c13ed9fe1146d79ed025a Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 1 Oct 2020 14:16:21 +0300 Subject: [PATCH 04/44] Save option Full Circumference. --- src/app/tape/dialogs/dialogsetupmultisize.cpp | 6 ++++ src/app/tape/dialogs/dialogsetupmultisize.h | 2 ++ src/app/tape/tmainwindow.cpp | 1 + .../schema/standard_measurements/v0.5.0.xsd | 1 + src/libs/vformat/vmeasurements.cpp | 31 +++++++++++++++++++ src/libs/vformat/vmeasurements.h | 4 +++ 6 files changed, 45 insertions(+) diff --git a/src/app/tape/dialogs/dialogsetupmultisize.cpp b/src/app/tape/dialogs/dialogsetupmultisize.cpp index 16db93d50..4d22fcf7e 100644 --- a/src/app/tape/dialogs/dialogsetupmultisize.cpp +++ b/src/app/tape/dialogs/dialogsetupmultisize.cpp @@ -197,6 +197,12 @@ QVector DialogSetupMultisize::Dimensions() const return dimensions; } +//--------------------------------------------------------------------------------------------------------------------- +bool DialogSetupMultisize::FullCircumference() const +{ + return ui->checkBoxFullCircumference->isChecked(); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSetupMultisize::changeEvent(QEvent *event) { diff --git a/src/app/tape/dialogs/dialogsetupmultisize.h b/src/app/tape/dialogs/dialogsetupmultisize.h index 38bf76735..9751f5587 100644 --- a/src/app/tape/dialogs/dialogsetupmultisize.h +++ b/src/app/tape/dialogs/dialogsetupmultisize.h @@ -50,6 +50,8 @@ public: QVector Dimensions() const; + bool FullCircumference() const; + protected: virtual void changeEvent(QEvent* event) override; virtual void showEvent(QShowEvent *event) override; diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 8b8fd2c1e..05d5726cc 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -381,6 +381,7 @@ void TMainWindow::FileNew() data = new VContainer(qApp->TrVars(), &mUnit, VContainer::UniqueNamespace()); m = new VMeasurements(mUnit, setup.Dimensions(), data); + m->SetFullCircumference(setup.FullCircumference()); m_curFileFormatVersion = VVSTConverter::MeasurementMaxVer; m_curFileFormatVersionStr = VVSTConverter::MeasurementMaxVerStr; } 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 00a520ec5..c7981e296 100644 --- a/src/libs/ifc/schema/standard_measurements/v0.5.0.xsd +++ b/src/libs/ifc/schema/standard_measurements/v0.5.0.xsd @@ -22,6 +22,7 @@ + diff --git a/src/libs/vformat/vmeasurements.cpp b/src/libs/vformat/vmeasurements.cpp index b566c2685..17eccc695 100644 --- a/src/libs/vformat/vmeasurements.cpp +++ b/src/libs/vformat/vmeasurements.cpp @@ -83,6 +83,7 @@ const QString VMeasurements::AttrMin = QStringLiteral("min"); 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::GenderMale = QStringLiteral("male"); const QString VMeasurements::GenderFemale = QStringLiteral("female"); @@ -509,6 +510,36 @@ void VMeasurements::SetReadOnly(bool ro) setTagText(TagReadOnly, ro ? trueStr : falseStr); } +//--------------------------------------------------------------------------------------------------------------------- +bool VMeasurements::IsFullCircumference() const +{ + QDomElement dimenstionsTag = firstChildElement(TagDimensions); + if (not dimenstionsTag.isNull()) + { + return GetParametrBool(dimenstionsTag, AttrFullCircumference, falseStr); + } + else + { + qDebug()<<"Can't read full circumference "< Date: Thu, 1 Oct 2020 16:27:40 +0300 Subject: [PATCH 05/44] Missed reading base value. --- src/libs/vformat/vmeasurements.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/libs/vformat/vmeasurements.cpp b/src/libs/vformat/vmeasurements.cpp index 17eccc695..074cd07df 100644 --- a/src/libs/vformat/vmeasurements.cpp +++ b/src/libs/vformat/vmeasurements.cpp @@ -652,25 +652,32 @@ QMap VMeasurements::Dimensions() const int min = GetParametrInt(dom, AttrMin, QChar('0')); const int max = GetParametrInt(dom, AttrMax, QChar('0')); const int step = GetParametrInt(dom, AttrStep, QString("-1")); + const int base = GetParametrInt(dom, AttrBase, QChar('0')); if (type == MeasurementDimension::X) { - dimesions.insert(type, QSharedPointer::create(units, min, max, step)); + auto dimension = QSharedPointer::create(units, min, max, step); + dimension->SetBaseValue(base); + dimesions.insert(type, dimension); } else if (type == MeasurementDimension::Y) { auto dimension = QSharedPointer::create(units, min, max, step); + dimension->SetBaseValue(base); dimension->SetCircumference(GetParametrBool(dom, AttrCircumference, trueStr)); - dimesions.insert(type, dimension); } else if (type == MeasurementDimension::W) { - dimesions.insert(type, QSharedPointer::create(units, min, max, step)); + auto dimension = QSharedPointer::create(units, min, max, step); + dimension->SetBaseValue(base); + dimesions.insert(type, dimension); } else if (type == MeasurementDimension::Z) { - dimesions.insert(type, QSharedPointer::create(units, min, max, step)); + auto dimension = QSharedPointer::create(units, min, max, step); + dimension->SetBaseValue(base); + dimesions.insert(type, dimension); } } From 4db0f3a420506b330076c3bd59991ba910987876 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 1 Oct 2020 16:56:44 +0300 Subject: [PATCH 06/44] Prepare base values. --- src/app/tape/tmainwindow.cpp | 142 +++++++++- src/app/tape/tmainwindow.h | 6 + src/app/tape/tmainwindow.ui | 532 +++++++++++++++++++---------------- 3 files changed, 424 insertions(+), 256 deletions(-) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 05d5726cc..b596ba0ba 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -562,10 +562,8 @@ void TMainWindow::changeEvent(QEvent *event) if (mType == MeasurementsType::Multisize) { ui->labelMType->setText(tr("Multisize measurements")); - ui->labelBaseSizeValue->setText(QString().setNum(m->DimensionABase()) + QChar(QChar::Space) + - UnitsToStr(m->MUnit(), true)); - ui->labelBaseHeightValue->setText(QString().setNum(m->DimensionBBase()) + QChar(QChar::Space) + - UnitsToStr(m->MUnit(), true)); + + RetranslateDimensionBaseValues(); labelGradationHeights->setText(tr("Height (%1):").arg(UnitsToStr(mUnit))); labelGradationSizes->setText(tr("Size (%1):").arg(UnitsToStr(mUnit))); @@ -2017,7 +2015,7 @@ void TMainWindow::InitWindow() SCASSERT(m != nullptr) ui->labelToolTip->setVisible(false); ui->tabWidget->setVisible(true); - ui->tabWidget->setCurrentIndex(0); + ui->tabWidget->setCurrentIndex(0); // measurements ui->plainTextEditNotes->setEnabled(true); ui->toolBarGradation->setVisible(true); @@ -2025,10 +2023,8 @@ void TMainWindow::InitWindow() if (mType == MeasurementsType::Multisize) { ui->labelMType->setText(tr("Multisize measurements")); - ui->labelBaseSizeValue->setText(QString().setNum(m->DimensionABase()) + QChar(QChar::Space) + - UnitsToStr(m->MUnit(), true)); - ui->labelBaseHeightValue->setText(QString().setNum(m->DimensionBBase()) + QChar(QChar::Space) + - UnitsToStr(m->MUnit(), true)); + + InitDimensionsBaseValue(); // Because Qt Designer doesn't know about our deleting we will create empty objects for correct // working the retranslation UI @@ -2091,10 +2087,14 @@ void TMainWindow::InitWindow() HackWidget(&ui->labelInHeights); // Tab Information - HackWidget(&ui->labelBaseSize); - HackWidget(&ui->labelBaseSizeValue); - HackWidget(&ui->labelBaseHeight); - HackWidget(&ui->labelBaseHeightValue); + HackWidget(&ui->labelDimensionA); + HackWidget(&ui->labelDimensionABase); + HackWidget(&ui->labelDimensionB); + HackWidget(&ui->labelDimensionBBase); + HackWidget(&ui->labelDimensionC); + HackWidget(&ui->labelDimensionCBase); + HackWidget(&ui->frameBaseValue); + HackWidget(&ui->labelBaseValues); ui->lineEditCustomerName->setText(m->Customer()); @@ -2179,6 +2179,44 @@ void TMainWindow::InitWindow() InitTable(); } +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::InitDimensionsBaseValue() +{ + const QList dimensions = m->Dimensions().values(); + const QString unit = UnitsToStr(m->MUnit(), true); + + auto DimensionsBaseValue = [this, dimensions, unit](int index, QLabel *name, QLabel *base) + { + SCASSERT(name != nullptr) + SCASSERT(base != nullptr) + + if (dimensions.size() > index) + { + MeasurementDimension_p dimension = dimensions.at(index); + name->setText(DimensionName(dimension->Type())+QChar(':')); + name->setToolTip(DimensionToolTip(dimension->Type(), dimension->IsCircumference())); + + if (dimension->IsCircumference() || dimension->Type() == MeasurementDimension::X) + { + base->setText(QString("%1 %2").arg(dimension->BaseValue()).arg(unit)); + } + else + { + base->setText(QString::number(dimension->BaseValue())); + } + } + else + { + HackWidget(&name); + HackWidget(&base); + } + }; + + DimensionsBaseValue(0, ui->labelDimensionA, ui->labelDimensionABase); + DimensionsBaseValue(1, ui->labelDimensionB, ui->labelDimensionBBase); + DimensionsBaseValue(2, ui->labelDimensionC, ui->labelDimensionCBase); +} + //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::InitTable() { @@ -3306,6 +3344,84 @@ void TMainWindow::SetCurrentPatternUnit() } } +//--------------------------------------------------------------------------------------------------------------------- +QString TMainWindow::DimensionName(MeasurementDimension type) +{ + switch(type) + { + case MeasurementDimension::X: + return tr("Height"); + case MeasurementDimension::Y: + return tr("Size"); + case MeasurementDimension::W: + return tr("Hip"); + case MeasurementDimension::Z: + return tr("Waist"); + default: + return QString(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::RetranslateDimensionBaseValues() +{ + const QList dimensions = m->Dimensions().values(); + const QString unit = UnitsToStr(m->MUnit(), true); + + auto DimensionsBaseValue = [this, dimensions, unit](int index, QLabel *name, QLabel *base) + { + SCASSERT(name != nullptr) + SCASSERT(base != nullptr) + + if (dimensions.size() > index) + { + MeasurementDimension_p dimension = dimensions.at(index); + name->setText(DimensionName(dimension->Type())+QChar(':')); + name->setToolTip(DimensionToolTip(dimension->Type(), dimension->IsCircumference())); + + if (dimension->IsCircumference()) + { + base->setText(QString("%1 %2").arg(dimension->BaseValue()).arg(unit)); + } + else + { + base->setText(QString::number(dimension->BaseValue())); + } + } + }; + + DimensionsBaseValue(0, ui->labelDimensionA, ui->labelDimensionABase); + DimensionsBaseValue(1, ui->labelDimensionC, ui->labelDimensionCBase); + DimensionsBaseValue(2, ui->labelDimensionB, ui->labelDimensionBBase); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString TMainWindow::DimensionToolTip(MeasurementDimension type, bool circumference) +{ + const bool fc = m->IsFullCircumference(); + switch(type) + { + case MeasurementDimension::X: + return tr("Height"); + case MeasurementDimension::Y: + if (circumference) + { + return fc ? tr("Chest full circumference") : tr("Chest half circumference"); + } + else + { + return tr("Size"); + } + return circumference ? tr("Chest circumference") : tr("Size"); + case MeasurementDimension::W: + return fc ? tr("Hip full circumference") : tr("Hip half circumference"); + case MeasurementDimension::Z: + return fc ? tr("Waist full circumference") : tr("Waist half circumference"); + default: + return QString(); + } +} + //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::SetDecimals() { diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index 15795d3d4..316ad399c 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -155,6 +155,7 @@ private: void SetupMenu(); void InitWindow(); + void InitDimensionsBaseValue(); void InitTable(); void SetDecimals(); void InitUnits(); @@ -218,6 +219,11 @@ private: void ImportMultisizeMeasurements(const QxtCsvModel &csv); void SetCurrentPatternUnit(); + + QString DimensionName(MeasurementDimension type); + QString DimensionToolTip(MeasurementDimension type, bool circumference); + + void RetranslateDimensionBaseValues(); }; #endif // TMAINWINDOW_H diff --git a/src/app/tape/tmainwindow.ui b/src/app/tape/tmainwindow.ui index 62e6dab34..511467ada 100644 --- a/src/app/tape/tmainwindow.ui +++ b/src/app/tape/tmainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 835 - 726 + 1034 + 896 @@ -24,7 +24,7 @@ 0 - + @@ -47,7 +47,7 @@ - 0 + 1 @@ -572,261 +572,307 @@ Information - - - - - Type: + + + + + QFormLayout::ExpandingFieldsGrow - - - - - - Measurement type - - - - - - - Path: - - - - - - - - - - 0 - 0 - - - - false - - - background: transparent; - - - false - - - true - - - Path to the measurement file + + + + Type: - - + + + + Measurement type + + + + + + + Path: + + + + + + + + + + 0 + 0 + + + + false + + + background: transparent; + + + false + + + true + + + Path to the measurement file + + + + + + + false + + + + 0 + 0 + + + + Show in Explorer + + + + + + + + + PM system: + + + + + false - + + 0 + 0 + + + + + 0 + 0 + + + + + + + + 0 0 - Show in Explorer + Base Values: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + Customer name: + + + + + + + false + + + + 0 + 0 + + + + Customer's name + + + + + + + Birth date: + + + + + + + false + + + + 0 + 0 + + + + + 124 + 0 + + + + yyyy-MM-dd + + + true + + + 0 + + + + 1800 + 1 + 1 + + + + + + + + Gender: + + + + + + + false + + + + 0 + 0 + + + + + + + + Email: + + + + + + + false + + + + 0 + 0 + + + + Customer's email address + + + + + + + Notes: + + + + + + + false + + + + 0 + 1 + + + + + + + + QFrame::Box + + + QFrame::Sunken + + + 1 + + + + + + A + + + + + + + Base + + + + + + + B + + + + + + + Base + + + + + + + C + + + + + + + Base + + + + + + - - - - PM system: - - - - - - - false - - - - 0 - 0 - - - - - 0 - 0 - - - - - - - - Base size: - - - - - - - Base size value - - - - - - - Base height: - - - - - - - Base height value - - - - - - - Customer name: - - - - - - - false - - - - 0 - 0 - - - - Customer's name - - - - - - - Birth date: - - - - - - - false - - - - 0 - 0 - - - - - 124 - 0 - - - - yyyy-MM-dd - - - true - - - 0 - - - - 1800 - 1 - 1 - - - - - - - - Gender: - - - - - - - false - - - - 0 - 0 - - - - - 0 - 0 - - - - - - - - Email: - - - - - - - false - - - - 0 - 0 - - - - Customer's email address - - - - - - - Notes: - - - - - - - false - - - - 0 - 1 - - - - @@ -838,8 +884,8 @@ 0 0 - 835 - 22 + 1034 + 21 From 1ffbc0a720e610cfd0298b825c8d8426490af558 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 1 Oct 2020 19:03:28 +0300 Subject: [PATCH 07/44] Fix reading/writing Full circumference. --- src/libs/vformat/vmeasurements.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/vformat/vmeasurements.cpp b/src/libs/vformat/vmeasurements.cpp index 074cd07df..7301e3279 100644 --- a/src/libs/vformat/vmeasurements.cpp +++ b/src/libs/vformat/vmeasurements.cpp @@ -513,7 +513,7 @@ void VMeasurements::SetReadOnly(bool ro) //--------------------------------------------------------------------------------------------------------------------- bool VMeasurements::IsFullCircumference() const { - QDomElement dimenstionsTag = firstChildElement(TagDimensions); + QDomElement dimenstionsTag = documentElement().firstChildElement(TagDimensions); if (not dimenstionsTag.isNull()) { return GetParametrBool(dimenstionsTag, AttrFullCircumference, falseStr); @@ -529,7 +529,7 @@ bool VMeasurements::IsFullCircumference() const //--------------------------------------------------------------------------------------------------------------------- void VMeasurements::SetFullCircumference(bool fc) { - QDomElement dimenstionsTag = firstChildElement(TagDimensions); + QDomElement dimenstionsTag = documentElement().firstChildElement(TagDimensions); if (not dimenstionsTag.isNull()) { SetAttributeOrRemoveIf(dimenstionsTag, AttrFullCircumference, fc, not fc); From 15978bd8681fb6e60a4627a3de1a0231ba9b7953 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 1 Oct 2020 19:06:20 +0300 Subject: [PATCH 08/44] Refactoring. Unify initialization and translation dimensions base value. --- src/app/tape/tmainwindow.cpp | 70 +++++++++++++----------------------- src/app/tape/tmainwindow.h | 3 +- 2 files changed, 26 insertions(+), 47 deletions(-) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index b596ba0ba..b3106a4f6 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -563,7 +563,7 @@ void TMainWindow::changeEvent(QEvent *event) { ui->labelMType->setText(tr("Multisize measurements")); - RetranslateDimensionBaseValues(); + InitDimensionsBaseValue(); labelGradationHeights->setText(tr("Height (%1):").arg(UnitsToStr(mUnit))); labelGradationSizes->setText(tr("Size (%1):").arg(UnitsToStr(mUnit))); @@ -2025,6 +2025,7 @@ void TMainWindow::InitWindow() ui->labelMType->setText(tr("Multisize measurements")); InitDimensionsBaseValue(); + HackDimensionBaseValue(); // Because Qt Designer doesn't know about our deleting we will create empty objects for correct // working the retranslation UI @@ -2087,12 +2088,7 @@ void TMainWindow::InitWindow() HackWidget(&ui->labelInHeights); // Tab Information - HackWidget(&ui->labelDimensionA); - HackWidget(&ui->labelDimensionABase); - HackWidget(&ui->labelDimensionB); - HackWidget(&ui->labelDimensionBBase); - HackWidget(&ui->labelDimensionC); - HackWidget(&ui->labelDimensionCBase); + HackDimensionBaseValue(); HackWidget(&ui->frameBaseValue); HackWidget(&ui->labelBaseValues); @@ -2205,11 +2201,6 @@ void TMainWindow::InitDimensionsBaseValue() base->setText(QString::number(dimension->BaseValue())); } } - else - { - HackWidget(&name); - HackWidget(&base); - } }; DimensionsBaseValue(0, ui->labelDimensionA, ui->labelDimensionABase); @@ -3068,6 +3059,28 @@ bool TMainWindow::IgnoreLocking(int error, const QString &path) return true; } +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::HackDimensionBaseValue() +{ + const QList dimensions = m->Dimensions().values(); + + auto DimensionsBaseValue = [this, dimensions](int index, QLabel *name, QLabel *base) + { + SCASSERT(name != nullptr) + SCASSERT(base != nullptr) + + if (dimensions.size() <= index) + { + HackWidget(&name); + HackWidget(&base); + } + }; + + DimensionsBaseValue(0, ui->labelDimensionA, ui->labelDimensionABase); + DimensionsBaseValue(1, ui->labelDimensionB, ui->labelDimensionBBase); + DimensionsBaseValue(2, ui->labelDimensionC, ui->labelDimensionCBase); +} + //--------------------------------------------------------------------------------------------------------------------- QString TMainWindow::CheckMName(const QString &name, const QSet &importedNames) const { @@ -3362,39 +3375,6 @@ QString TMainWindow::DimensionName(MeasurementDimension type) } } -//--------------------------------------------------------------------------------------------------------------------- -void TMainWindow::RetranslateDimensionBaseValues() -{ - const QList dimensions = m->Dimensions().values(); - const QString unit = UnitsToStr(m->MUnit(), true); - - auto DimensionsBaseValue = [this, dimensions, unit](int index, QLabel *name, QLabel *base) - { - SCASSERT(name != nullptr) - SCASSERT(base != nullptr) - - if (dimensions.size() > index) - { - MeasurementDimension_p dimension = dimensions.at(index); - name->setText(DimensionName(dimension->Type())+QChar(':')); - name->setToolTip(DimensionToolTip(dimension->Type(), dimension->IsCircumference())); - - if (dimension->IsCircumference()) - { - base->setText(QString("%1 %2").arg(dimension->BaseValue()).arg(unit)); - } - else - { - base->setText(QString::number(dimension->BaseValue())); - } - } - }; - - DimensionsBaseValue(0, ui->labelDimensionA, ui->labelDimensionABase); - DimensionsBaseValue(1, ui->labelDimensionC, ui->labelDimensionCBase); - DimensionsBaseValue(2, ui->labelDimensionB, ui->labelDimensionBBase); -} - //--------------------------------------------------------------------------------------------------------------------- QString TMainWindow::DimensionToolTip(MeasurementDimension type, bool circumference) { diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index 316ad399c..de44cd2d3 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -210,6 +210,7 @@ private: template void HackWidget(T **widget); + void HackDimensionBaseValue(); QString CheckMName(const QString &name, const QSet &importedNames) const; void ShowError(const QString &text); @@ -222,8 +223,6 @@ private: QString DimensionName(MeasurementDimension type); QString DimensionToolTip(MeasurementDimension type, bool circumference); - - void RetranslateDimensionBaseValues(); }; #endif // TMAINWINDOW_H From a16e6bc08256b786a4a7fa3a6c01d1374e89c5f7 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 1 Oct 2020 19:26:56 +0300 Subject: [PATCH 09/44] Basic implementation for Full circumference trigger. --- src/app/tape/tmainwindow.cpp | 38 ++++++++++++++++++++++++++++++++++-- src/app/tape/tmainwindow.h | 4 ++++ src/app/tape/tmainwindow.ui | 2 +- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index b3106a4f6..342cafa84 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -561,6 +561,8 @@ void TMainWindow::changeEvent(QEvent *event) if (mType == MeasurementsType::Multisize) { + actionFullCircumference->setText(tr("Use full circumference")); + ui->labelMType->setText(tr("Multisize measurements")); InitDimensionsBaseValue(); @@ -1915,6 +1917,14 @@ void TMainWindow::SaveMFullName() } } +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::FullCircumferenceChanged(bool checked) +{ + m->SetFullCircumference(checked); + MeasurementsWereSaved(false); + InitDimensionsBaseValue(); +} + //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::SetupMenu() { @@ -2022,6 +2032,7 @@ void TMainWindow::InitWindow() if (mType == MeasurementsType::Multisize) { + InitMenu(); ui->labelMType->setText(tr("Multisize measurements")); InitDimensionsBaseValue(); @@ -2175,13 +2186,29 @@ void TMainWindow::InitWindow() InitTable(); } +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::InitMenu() +{ + if (mType == MeasurementsType::Multisize) + { + ui->menuMeasurements->addSeparator(); + + actionFullCircumference = new QAction(tr("Use full circumference"), this); + actionFullCircumference->setCheckable(true); + actionFullCircumference->setChecked(m->IsFullCircumference()); + ui->menuMeasurements->addAction(actionFullCircumference); + connect(actionFullCircumference, &QAction::triggered, this, &TMainWindow::FullCircumferenceChanged); + } +} + //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::InitDimensionsBaseValue() { const QList dimensions = m->Dimensions().values(); const QString unit = UnitsToStr(m->MUnit(), true); + const bool fc = m->IsFullCircumference(); - auto DimensionsBaseValue = [this, dimensions, unit](int index, QLabel *name, QLabel *base) + auto DimensionsBaseValue = [this, dimensions, unit, fc](int index, QLabel *name, QLabel *base) { SCASSERT(name != nullptr) SCASSERT(base != nullptr) @@ -2194,7 +2221,14 @@ void TMainWindow::InitDimensionsBaseValue() if (dimension->IsCircumference() || dimension->Type() == MeasurementDimension::X) { - base->setText(QString("%1 %2").arg(dimension->BaseValue()).arg(unit)); + 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 { diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index de44cd2d3..f96367ea4 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -127,6 +127,8 @@ private slots: void SaveMDescription(); void SaveMFullName(); + void FullCircumferenceChanged(bool checked); + private: Q_DISABLE_COPY(TMainWindow) Ui::TMainWindow *ui; @@ -150,11 +152,13 @@ private: QLabel *labelPatternUnit; bool isInitialized; bool mIsReadOnly; + QAction *actionFullCircumference{nullptr}; QVector hackedWidgets; void SetupMenu(); void InitWindow(); + void InitMenu(); void InitDimensionsBaseValue(); void InitTable(); void SetDecimals(); diff --git a/src/app/tape/tmainwindow.ui b/src/app/tape/tmainwindow.ui index 511467ada..cd66e0e29 100644 --- a/src/app/tape/tmainwindow.ui +++ b/src/app/tape/tmainwindow.ui @@ -47,7 +47,7 @@ - 1 + 0 From 20675a081a46a954d7b6368b69ce1ada747fc4af Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 3 Oct 2020 07:33:56 +0300 Subject: [PATCH 10/44] Changes to CLI. --- dist/debian/tape.1 | 20 ++- src/app/tape/mapplication.cpp | 228 ++++++++++++++++++++-------------- src/app/tape/tmainwindow.cpp | 113 ++++++++++------- src/app/tape/tmainwindow.h | 41 +++--- 4 files changed, 231 insertions(+), 171 deletions(-) diff --git a/dist/debian/tape.1 b/dist/debian/tape.1 index 83d3dfc27..97e240551 100644 --- a/dist/debian/tape.1 +++ b/dist/debian/tape.1 @@ -1,6 +1,6 @@ .\" Manpage for tape. .\" Contact dismine@gmail.com to correct errors. -.TH tape 1 "10 March, 2017" "tape man page" +.TH tape 1 "3 October, 2020" "tape man page" .SH NAME Tape \- Valentina's measurements editor. .SH SYNOPSIS @@ -20,12 +20,14 @@ is a part of Valentina. And used for creating and editing measurement files. Displays this help. .IP "-v, --version" Displays version information. -.IP "-e, --height " -Open with the base height. Valid values: 92, 98, 104, 110, 116, 122, 128, 134, 140, 146, 152, 158, 164, 170, 176, 182, 188, 194, 200cm. -.IP "-s, --size " -Open with the base size. Valid values: 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56cm. -.IP "-u, --unit " -Set pattern file unit: cm, mm, inch. +.IP "-a, --dimensionA " +Set base for dimension A in the table units. +.IP "-b, --dimensionB " +Set base for dimension B in the table units. +.IP "-c, --dimensionA " +Set base for dimension C in the table units. +.IP "-u, --units " +Set pattern file units: cm, mm, inch. .IP "--test" Use for unit testing. Run the program and open a file without showing the main window. .IP "--no-scaling" @@ -35,9 +37,5 @@ Disable high dpi scaling. Call this option if has problem with scaling (by defau \- the measurement file. .SH AUTHOR .RI "This manual page was written by Roman Telezhynskyi <" dismine@gmail.com ">" -.SH "SEE ALSO" -.RB "Full " "User Manual" " is availiable in" -.UR https://bitbucket.org/dismine/valentina/wiki/manual/Content -.UE .BR valentina (1) diff --git a/src/app/tape/mapplication.cpp b/src/app/tape/mapplication.cpp index f69427993..2773da8ce 100644 --- a/src/app/tape/mapplication.cpp +++ b/src/app/tape/mapplication.cpp @@ -599,96 +599,46 @@ void MApplication::ParseCommandLine(const SocketConnection &connection, const QS parser.addHelpOption(); parser.addVersionOption(); parser.addPositionalArgument("filename", tr("The measurement file.")); - //----- - QCommandLineOption heightOption(QStringList() << "e" << "height", - tr("Open with the base height. Valid values: %1cm.") - .arg(VMeasurement::WholeListHeights(Unit::Cm).join(", ")), - tr("The base height")); - parser.addOption(heightOption); - //----- - QCommandLineOption sizeOption(QStringList() << "s" << "size", - tr("Open with the base size. Valid values: %1cm.").arg(VMeasurement::WholeListSizes(Unit::Cm).join(", ")), - tr("The base size")); - parser.addOption(sizeOption); - //----- - QCommandLineOption unitOption(QStringList() << "u" << "unit", - tr("Set pattern file unit: cm, mm, inch."), - tr("The pattern unit")); - parser.addOption(unitOption); - //----- - QCommandLineOption testOption(QStringList() << "test", - tr("Use for unit testing. Run the program and open a file without showing the main window.")); - parser.addOption(testOption); - //----- - QCommandLineOption scalingOption(QStringList() << LONG_OPTION_NO_HDPI_SCALING, - tr("Disable high dpi scaling. Call this option if has problem with scaling (by default scaling enabled). " - "Alternatively you can use the %1 environment variable.").arg("QT_AUTO_SCREEN_SCALE_FACTOR=0")); - parser.addOption(scalingOption); - //----- + + const QString LONG_OPTION_DIMENSION_A = QStringLiteral("dimensionA"); + const QString SINGLE_OPTION_DIMENSION_A = QChar('a'); + + const QString LONG_OPTION_DIMENSION_B = QStringLiteral("dimensionB"); + const QString SINGLE_OPTION_DIMENSION_B = QChar('b'); + + const QString LONG_OPTION_DIMENSION_C = QStringLiteral("dimensionC"); + const QString SINGLE_OPTION_DIMENSION_C = QChar('c'); + + const QString LONG_OPTION_UNITS = QStringLiteral("units"); + const QString SINGLE_OPTION_UNITS = QChar('u'); + + const QString LONG_OPTION_TEST = QStringLiteral("test"); + + parser.addOptions( + { + {{SINGLE_OPTION_DIMENSION_A, LONG_OPTION_DIMENSION_A}, tr("Set base for dimension A in the table units."), + tr("The dimension A base")}, + + {{SINGLE_OPTION_DIMENSION_B, LONG_OPTION_DIMENSION_B}, tr("Set base for dimension B in the table units."), + tr("The dimension B base")}, + + {{SINGLE_OPTION_DIMENSION_C, LONG_OPTION_DIMENSION_C}, tr("Set base for dimension C in the table units."), + tr("The dimension C base")}, + + {{SINGLE_OPTION_UNITS, LONG_OPTION_UNITS}, tr("Set pattern file units: cm, mm, inch."), + tr("The pattern units")}, + + {LONG_OPTION_TEST, + tr("Use for unit testing. Run the program and open a file without showing the main window.")}, + + {LONG_OPTION_NO_HDPI_SCALING, + tr("Disable high dpi scaling. Call this option if has problem with scaling (by default scaling enabled). " + "Alternatively you can use the %1 environment variable.").arg("QT_AUTO_SCREEN_SCALE_FACTOR=0")}, + }); + parser.process(arguments); - bool flagHeight = false; - bool flagSize = false; - bool flagUnit = false; - - int size = 0; - int height = 0; - Unit unit = Unit::Cm; - - if (parser.isSet(heightOption)) - { - const QString heightValue = parser.value(heightOption); - if (VMeasurement::IsGradationHeightValid(heightValue)) - { - flagHeight = true; - height = heightValue.toInt(); - } - else - { - qCCritical(mApp, "%s\n", - qPrintable(tr("Invalid base height argument. Must be %1cm.") - .arg(VMeasurement::WholeListHeights(Unit::Cm).join(", ")))); - parser.showHelp(V_EX_USAGE); - } - } - - if (parser.isSet(sizeOption)) - { - const QString sizeValue = parser.value(sizeOption); - if (VMeasurement::IsGradationSizeValid(sizeValue)) - { - flagSize = true; - size = sizeValue.toInt(); - } - else - { - qCCritical(mApp, "%s\n", - qPrintable(tr("Invalid base size argument. Must be %1cm.") - .arg(VMeasurement::WholeListSizes(Unit::Cm).join(", ")))); - parser.showHelp(V_EX_USAGE); - } - } - - { - const QString unitValue = parser.value(unitOption); - if (not unitValue.isEmpty()) - { - - const QStringList units = QStringList() << unitMM << unitCM << unitINCH; - if (units.contains(unitValue)) - { - flagUnit = true; - unit = StrToUnits(unitValue); - } - else - { - qCCritical(mApp, "%s\n", qPrintable(tr("Invalid base size argument. Must be cm, mm or inch."))); - parser.showHelp(V_EX_USAGE); - } - } - } - - testMode = parser.isSet(testOption); + testMode = parser.isSet(LONG_OPTION_TEST); if (not testMode && connection == SocketConnection::Client) { @@ -737,6 +687,84 @@ void MApplication::ParseCommandLine(const SocketConnection &connection, const QS parser.showHelp(V_EX_USAGE); } + bool flagDimensionA = false; + bool flagDimensionB = false; + bool flagDimensionC = false; + bool flagUnits = false; + + int dimensionAValue = 0; + int dimensionBValue = 0; + int dimensionCValue = 0; + Unit unit = Unit::Cm; + + if (parser.isSet(LONG_OPTION_DIMENSION_A)) + { + const QString value = parser.value(LONG_OPTION_DIMENSION_A); + + bool ok = false; + dimensionAValue = value.toInt(&ok); + if(ok && dimensionAValue > 0) + { + flagDimensionA = true; + } + else + { + qCCritical(mApp, "%s\n", qPrintable(tr("Invalid dimension A base value."))); + parser.showHelp(V_EX_USAGE); + } + } + + if (parser.isSet(LONG_OPTION_DIMENSION_B)) + { + const QString value = parser.value(LONG_OPTION_DIMENSION_B); + + bool ok = false; + dimensionBValue = value.toInt(&ok); + if(ok && dimensionBValue > 0) + { + flagDimensionB = true; + } + else + { + qCCritical(mApp, "%s\n", qPrintable(tr("Invalid dimension B base value."))); + parser.showHelp(V_EX_USAGE); + } + } + + if (parser.isSet(LONG_OPTION_DIMENSION_C)) + { + const QString value = parser.value(LONG_OPTION_DIMENSION_C); + + bool ok = false; + dimensionCValue = value.toInt(&ok); + if(ok && dimensionCValue > 0) + { + flagDimensionC = true; + } + else + { + qCCritical(mApp, "%s\n", qPrintable(tr("Invalid dimension C base value."))); + parser.showHelp(V_EX_USAGE); + } + } + + { + const QString unitValue = parser.value(LONG_OPTION_UNITS); + if (not unitValue.isEmpty()) + { + if (QStringList{unitMM, unitCM, unitINCH}.contains(unitValue)) + { + flagUnits = true; + unit = StrToUnits(unitValue); + } + else + { + qCCritical(mApp, "%s\n", qPrintable(tr("Invalid base size argument. Must be cm, mm or inch."))); + parser.showHelp(V_EX_USAGE); + } + } + } + for (auto &arg : args) { NewMainWindow(); @@ -750,17 +778,31 @@ void MApplication::ParseCommandLine(const SocketConnection &connection, const QS continue; } - if (flagSize) + if (flagDimensionA) { - MainWindow()->SetBaseMSize(size); + if (not MainWindow()->SetDimensionABase(dimensionAValue)) + { + parser.showHelp(V_EX_USAGE); + } } - if (flagHeight) + if (flagDimensionB) { - MainWindow()->SetBaseMHeight(height); + if (MainWindow()->SetDimensionBBase(dimensionBValue)) + { + parser.showHelp(V_EX_USAGE); + } } - if (flagUnit) + if (flagDimensionC) + { + if (MainWindow()->SetDimensionCBase(dimensionCValue)) + { + parser.showHelp(V_EX_USAGE); + } + } + + if (flagUnits) { MainWindow()->SetPUnit(unit); } diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 342cafa84..115ced42a 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -87,24 +87,7 @@ enum {ColumnName = 0, ColumnFullName, ColumnCalcValue, ColumnFormula, ColumnBase TMainWindow::TMainWindow(QWidget *parent) : VAbstractMainWindow(parent), ui(new Ui::TMainWindow), - m(nullptr), - data(nullptr), - mUnit(Unit::Cm), - pUnit(Unit::Cm), - mType(MeasurementsType::Individual), - curFile(), - gradationHeights(nullptr), - gradationSizes(nullptr), - comboBoxUnits(nullptr), - formulaBaseHeight(0), - lock(nullptr), - search(), - labelGradationHeights(nullptr), - labelGradationSizes(nullptr), - labelPatternUnit(nullptr), - isInitialized(false), - mIsReadOnly(false), - hackedWidgets() + formulaBaseHeight(0) { ui->setupUi(this); @@ -173,45 +156,79 @@ void TMainWindow::RetranslateTable() } //--------------------------------------------------------------------------------------------------------------------- -void TMainWindow::SetBaseMHeight(int height) +bool TMainWindow::SetDimensionABase(int base) { - if (m != nullptr) + const QList dimensions = m->Dimensions().values(); + + if (dimensions.isEmpty()) { - if (mType == MeasurementsType::Multisize) - { - const int row = ui->tableWidget->currentRow(); - currentDimensionA = UnitConvertor(height, Unit::Cm, mUnit); - - gradationHeights->blockSignals(true); - SetDefaultHeight(static_cast(currentDimensionA)); - gradationHeights->blockSignals(false); - - RefreshData(); - search->RefreshList(ui->lineEditFind->text()); - ui->tableWidget->selectRow(row); - } + qCCritical(tMainWindow, "%s\n", qPrintable(tr("The table doesn't provide dimensions"))); + return false; } + + const qint32 i = gradationDimensionA->findData(base); + if (i != -1) + { + gradationDimensionA->setCurrentIndex(i); + } + + if (base != currentDimensionA) + { + qCCritical(tMainWindow, "%s\n", qPrintable(tr("Invalid base value for dimension A"))); + return false; + } + return true; } //--------------------------------------------------------------------------------------------------------------------- -void TMainWindow::SetBaseMSize(int size) +bool TMainWindow::SetDimensionBBase(int base) { - if (m != nullptr) + const QList dimensions = m->Dimensions().values(); + + if (dimensions.size() <= 1) { - if (mType == MeasurementsType::Multisize) - { - const int row = ui->tableWidget->currentRow(); - currentDimensionB = UnitConvertor(size, Unit::Cm, mUnit); - - gradationSizes->blockSignals(true); - SetDefaultSize(static_cast(currentDimensionB)); - gradationSizes->blockSignals(false); - - RefreshData(); - search->RefreshList(ui->lineEditFind->text()); - ui->tableWidget->selectRow(row); - } + qCCritical(tMainWindow, "%s\n", qPrintable(tr("The table doesn't support dimension B"))); + return false; } + + const qint32 i = gradationDimensionB->findData(base); + if (i != -1) + { + gradationDimensionB->setCurrentIndex(i); + } + + if (base != currentDimensionB) + { + qCCritical(tMainWindow, "%s\n", qPrintable(tr("Invalid base value for dimension B"))); + return false; + } + + return true; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool TMainWindow::SetDimensionCBase(int base) +{ + const QList dimensions = m->Dimensions().values(); + + if (dimensions.size() <= 2) + { + qCCritical(tMainWindow, "%s\n", qPrintable(tr("The table doesn't support dimension C"))); + return false; + } + + const qint32 i = gradationDimensionC->findData(base); + if (i != -1) + { + gradationDimensionC->setCurrentIndex(i); + } + + if (base != currentDimensionC) + { + qCCritical(tMainWindow, "%s\n", qPrintable(tr("Invalid base value for dimension C"))); + return false; + } + return true; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index f96367ea4..e115f7a75 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -57,8 +57,9 @@ public: void RetranslateTable(); - void SetBaseMHeight(int height); - void SetBaseMSize(int size); + bool SetDimensionABase(int base); + bool SetDimensionBBase(int base); + bool SetDimensionCBase(int base); void SetPUnit(Unit unit); bool LoadFile(const QString &path); @@ -132,29 +133,31 @@ private slots: private: Q_DISABLE_COPY(TMainWindow) Ui::TMainWindow *ui; - VMeasurements *m; - VContainer *data; - Unit mUnit; - Unit pUnit; - MeasurementsType mType; + VMeasurements *m{nullptr}; + VContainer *data{nullptr}; + Unit mUnit{Unit::Cm}; + Unit pUnit{Unit::Cm}; + MeasurementsType mType{MeasurementsType::Individual}; int currentDimensionA{0}; int currentDimensionB{0}; int currentDimensionC{0}; - QString curFile; - QComboBox *gradationHeights; - QComboBox *gradationSizes; - QComboBox *comboBoxUnits; + QString curFile{}; + QComboBox *gradationDimensionA{nullptr}; + QComboBox *gradationDimensionB{nullptr}; + QComboBox *gradationDimensionC{nullptr}; + QComboBox *comboBoxUnits{nullptr}; int formulaBaseHeight; - QSharedPointer> lock; - QSharedPointer search; - QLabel *labelGradationHeights; - QLabel *labelGradationSizes; - QLabel *labelPatternUnit; - bool isInitialized; - bool mIsReadOnly; + QSharedPointer> lock{nullptr}; + QSharedPointer search{}; + QLabel *labelGradationDimensionA{nullptr}; + QLabel *labelGradationDimensionB{nullptr}; + QLabel *labelGradationDimensionC{nullptr}; + QLabel *labelPatternUnit{nullptr}; + bool isInitialized{false}; + bool mIsReadOnly{false}; QAction *actionFullCircumference{nullptr}; - QVector hackedWidgets; + QVector hackedWidgets{}; void SetupMenu(); void InitWindow(); From ecb62257c2d35344bae6991d512b8c99056c6ec4 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 3 Oct 2020 07:34:25 +0300 Subject: [PATCH 11/44] Dimension controls. --- src/app/tape/tmainwindow.cpp | 388 ++++++++++++++++++++++++----- src/app/tape/tmainwindow.h | 21 +- src/libs/vformat/vmeasurements.cpp | 12 + src/libs/vformat/vmeasurements.h | 3 + 4 files changed, 350 insertions(+), 74 deletions(-) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 115ced42a..7ebaeda13 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -64,6 +64,7 @@ #include #include #include +#include #if defined(Q_OS_MAC) #include @@ -87,7 +88,8 @@ enum {ColumnName = 0, ColumnFullName, ColumnCalcValue, ColumnFormula, ColumnBase TMainWindow::TMainWindow(QWidget *parent) : VAbstractMainWindow(parent), ui(new Ui::TMainWindow), - formulaBaseHeight(0) + formulaBaseHeight(0), + gradation(new QTimer(this)) { ui->setupUi(this); @@ -110,6 +112,8 @@ TMainWindow::TMainWindow(QWidget *parent) m_recentFileActs.fill(nullptr); + connect(gradation, &QTimer::timeout, this, &TMainWindow::GradationChanged); + SetupMenu(); UpdateWindowTitle(); ReadSettings(); @@ -401,6 +405,8 @@ void TMainWindow::FileNew() m->SetFullCircumference(setup.FullCircumference()); m_curFileFormatVersion = VVSTConverter::MeasurementMaxVer; m_curFileFormatVersionStr = VVSTConverter::MeasurementMaxVerStr; + + SetCurrentDimensionValues(); } else { @@ -583,9 +589,7 @@ void TMainWindow::changeEvent(QEvent *event) ui->labelMType->setText(tr("Multisize measurements")); InitDimensionsBaseValue(); - - labelGradationHeights->setText(tr("Height (%1):").arg(UnitsToStr(mUnit))); - labelGradationSizes->setText(tr("Size (%1):").arg(UnitsToStr(mUnit))); + InitDimensionControls(); } else { @@ -609,7 +613,7 @@ void TMainWindow::changeEvent(QEvent *event) } { - labelPatternUnit = new QLabel(tr("Pattern unit:")); + labelPatternUnit->setText(tr("Pattern unit:")); if (comboBoxUnits != nullptr) { @@ -1476,20 +1480,54 @@ void TMainWindow::ImportFromPattern() } //--------------------------------------------------------------------------------------------------------------------- -void TMainWindow::ChangedSize(const QString &text) +void TMainWindow::DimensionABaseChanged() { - const int row = ui->tableWidget->currentRow(); - currentDimensionB = text.toInt(); - RefreshData(); - search->RefreshList(ui->lineEditFind->text()); - ui->tableWidget->selectRow(row); + currentDimensionA = gradationDimensionA->currentData().toInt(); + + const QList dimensions = m->Dimensions().values(); + if (dimensions.size() > 1) + { + MeasurementDimension_p dimension = dimensions.at(1); + InitDimensionGradation(1, dimension, gradationDimensionB); + + if (dimensions.size() > 2) + { + dimension = dimensions.at(2); + InitDimensionGradation(2, dimension, gradationDimensionC); + } + } + + gradation->start(); } //--------------------------------------------------------------------------------------------------------------------- -void TMainWindow::ChangedHeight(const QString &text) +void TMainWindow::DimensionBBaseChanged() { + currentDimensionB = gradationDimensionB->currentData().toInt(); + + const QList dimensions = m->Dimensions().values(); + + if (dimensions.size() > 2) + { + MeasurementDimension_p dimension = dimensions.at(2); + InitDimensionGradation(2, dimension, gradationDimensionC); + } + + gradation->start(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::DimensionCBaseChanged() +{ + currentDimensionC = gradationDimensionC->currentData().toInt(); + gradation->start(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::GradationChanged() +{ + gradation->stop(); const int row = ui->tableWidget->currentRow(); - currentDimensionA = text.toInt(); RefreshData(); search->RefreshList(ui->lineEditFind->text()); ui->tableWidget->selectRow(row); @@ -1940,6 +1978,7 @@ void TMainWindow::FullCircumferenceChanged(bool checked) m->SetFullCircumference(checked); MeasurementsWereSaved(false); InitDimensionsBaseValue(); + InitDimensionControls(); } //--------------------------------------------------------------------------------------------------------------------- @@ -2074,20 +2113,9 @@ void TMainWindow::InitWindow() HackWidget(&ui->labelGender); HackWidget(&ui->labelEmail); - const QStringList listHeights = VMeasurement::WholeListHeights(mUnit); - const QStringList listSizes = VMeasurement::WholeListSizes(mUnit); - - labelGradationHeights = new QLabel(tr("Height (%1):").arg(UnitsToStr(mUnit))); - gradationHeights = SetGradationList(labelGradationHeights, listHeights); - SetDefaultHeight(static_cast(data->height())); - connect(gradationHeights, &QComboBox::currentTextChanged, - this, &TMainWindow::ChangedHeight); - - labelGradationSizes = new QLabel(tr("Size (%1):").arg(UnitsToStr(mUnit))); - gradationSizes = SetGradationList(labelGradationSizes, listSizes); - SetDefaultSize(static_cast(data->size())); - connect(gradationSizes, &QComboBox::currentTextChanged, - this, &TMainWindow::ChangedSize); + InitDimensionControls(); + ShowDimensionControls(); + SetDimensionBases(); connect(ui->doubleSpinBoxBaseValue, QOverload::of(&QDoubleSpinBox::valueChanged), this, &TMainWindow::SaveMBaseValue); @@ -2259,6 +2287,107 @@ void TMainWindow::InitDimensionsBaseValue() DimensionsBaseValue(2, ui->labelDimensionC, ui->labelDimensionCBase); } +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::InitDimensionGradation(int index, const MeasurementDimension_p &dimension, QComboBox *control) +{ + SCASSERT(control != nullptr) + + const bool fc = m->IsFullCircumference(); + const QString unit = UnitsToStr(m->MUnit(), true); + + int current = -1; + if (control->currentIndex() != -1) + { + current = control->currentData().toInt(); + } + + control->blockSignals(true); + control->clear(); + + if (dimension->Type() == MeasurementDimension::X) + { + const QVector bases = DimensionRestrictedValues(index, dimension); + + for(auto base : bases) + { + control->addItem(QString("%1 %2").arg(base).arg(unit), base); + } + } + else if (dimension->Type() == MeasurementDimension::Y) + { + const QVector bases = dimension->ValidBases(); + + for(auto base : bases) + { + if (dimension->IsCircumference()) + { + control->addItem(QString("%1 %2").arg(fc ? base*2 : base).arg(unit), base); + } + else + { + control->addItem(QString::number(base), base); + } + } + } + else if (dimension->Type() == MeasurementDimension::W || dimension->Type() == MeasurementDimension::Z) + { + const QVector bases = dimension->ValidBases(); + + for(auto base : bases) + { + control->addItem(QString("%1 %2").arg(fc ? base*2 : base).arg(unit), base); + } + } + + int i = control->findData(current); + if (i != -1) + { + control->setCurrentIndex(i); + control->blockSignals(false); + } + else + { + control->blockSignals(false); + control->setCurrentIndex(0); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::InitDimensionControls() +{ + const QList dimensions = m->Dimensions().values(); + const QString unit = UnitsToStr(m->MUnit(), true); + + auto InitControl = [this, dimensions, unit](int index, QLabel *&name, QComboBox *&control) + { + if (dimensions.size() > index) + { + MeasurementDimension_p dimension = dimensions.at(index); + + if (name == nullptr) + { + name = new QLabel(DimensionName(dimension->Type())+QChar(':')); + } + else + { + name->setText(DimensionName(dimension->Type())+QChar(':')); + } + name->setToolTip(DimensionToolTip(dimension->Type(), dimension->IsCircumference())); + + if (control == nullptr) + { + control = new QComboBox; + } + + InitDimensionGradation(index, dimension, control); + } + }; + + InitControl(0, labelGradationDimensionA, gradationDimensionA); + InitControl(1, labelGradationDimensionB, gradationDimensionB); + InitControl(2, labelGradationDimensionC, gradationDimensionC); +} + //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::InitTable() { @@ -2431,46 +2560,6 @@ QTableWidgetItem *TMainWindow::AddCell(const QString &text, int row, int column, return item; } -//--------------------------------------------------------------------------------------------------------------------- -QComboBox *TMainWindow::SetGradationList(QLabel *label, const QStringList &list) -{ - ui->toolBarGradation->addWidget(label); - - auto *comboBox = new QComboBox; - comboBox->addItems(list); - ui->toolBarGradation->addWidget(comboBox); - - return comboBox; -} - -//--------------------------------------------------------------------------------------------------------------------- -void TMainWindow::SetDefaultHeight(int value) -{ - const qint32 index = gradationHeights->findText(QString::number(value)); - if (index != -1) - { - gradationHeights->setCurrentIndex(index); - } - else - { - currentDimensionA = gradationHeights->currentText().toInt(); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void TMainWindow::SetDefaultSize(int value) -{ - const qint32 index = gradationSizes->findText(QString::number(value)); - if (index != -1) - { - gradationSizes->setCurrentIndex(index); - } - else - { - currentDimensionB = gradationSizes->currentText().toInt(); - } -} - //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::RefreshData(bool freshCall) { @@ -3453,6 +3542,171 @@ QString TMainWindow::DimensionToolTip(MeasurementDimension type, bool circumfere } } +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::ShowDimensionControls() +{ + const QList dimensions = m->Dimensions().values(); + + auto ShowControl = [this, dimensions](int index, QLabel *name, QComboBox *control) + { + if (dimensions.size() > index) + { + SCASSERT(name != nullptr) + SCASSERT(control != nullptr) + + ui->toolBarGradation->addWidget(name); + ui->toolBarGradation->addWidget(control); + } + }; + + ShowControl(0, labelGradationDimensionA, gradationDimensionA); + ShowControl(1, labelGradationDimensionB, gradationDimensionB); + ShowControl(2, labelGradationDimensionC, gradationDimensionC); + + if (gradationDimensionA) + { + connect(gradationDimensionA, QOverload::of(&QComboBox::currentIndexChanged), + this, &TMainWindow::DimensionABaseChanged); + } + + if (gradationDimensionB) + { + connect(gradationDimensionB, QOverload::of(&QComboBox::currentIndexChanged), + this, &TMainWindow::DimensionBBaseChanged); + } + + if (gradationDimensionC) + { + connect(gradationDimensionC, QOverload::of(&QComboBox::currentIndexChanged), + this, &TMainWindow::DimensionCBaseChanged); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::SetDimensionBases() +{ + const QList dimensions = m->Dimensions().values(); + + auto SetBase = [dimensions](int index, QComboBox *control, int &value) + { + if (dimensions.size() > index) + { + SCASSERT(control != nullptr) + + MeasurementDimension_p dimension = dimensions.at(index); + + const qint32 i = control->findData(value); + if (i != -1) + { + control->setCurrentIndex(i); + } + else + { + value = control->currentData().toInt(); + } + } + }; + + SetBase(0, gradationDimensionA, currentDimensionA); + SetBase(1, gradationDimensionB, currentDimensionB); + SetBase(2, gradationDimensionC, currentDimensionC); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::SetCurrentDimensionValues() +{ + const QList dimensions = m->Dimensions().values(); + + auto SetDimensionValue = [dimensions](int index, int &value) + { + if (dimensions.size() > index) + { + MeasurementDimension_p dimension = dimensions.at(index); + value = dimension->BaseValue(); + } + }; + + SetDimensionValue(0, currentDimensionA); + SetDimensionValue(1, currentDimensionB); + SetDimensionValue(2, currentDimensionC); +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector TMainWindow::DimensionRestrictedValues(int index, const MeasurementDimension_p &dimension) +{ + if (index == 0) + { + return dimension->ValidBases(); + } + + if (dimension->Type() == MeasurementDimension::X) + { + return dimension->ValidBases(); + } + else if (dimension->Type() == MeasurementDimension::Y) + { + const QPair restriction = m->OneDimensionRestriction(currentDimensionA); + VYMeasurementDimension restricted(dimension->Units(), restriction.first, restriction.second, dimension->Step()); + restricted.SetCircumference(dimension->IsCircumference()); + + if (restriction.first < dimension->MinValue() || restriction.second > dimension->MaxValue() + || not restricted.IsValid()) + { // invalid restriction + return dimension->ValidBases(); + } + + return restricted.ValidBases(); + } + else if (dimension->Type() == MeasurementDimension::W) + { + QPair restriction; + + if (index == 1) + { + restriction = m->OneDimensionRestriction(currentDimensionA); + } + else + { + restriction = m->TwoDimensionRestriction(currentDimensionA, currentDimensionB); + } + + VWMeasurementDimension restricted(dimension->Units(), restriction.first, restriction.second, dimension->Step()); + + if (restriction.first < dimension->MinValue() || restriction.second > dimension->MaxValue() + || not restricted.IsValid()) + { // invalid restriction + return dimension->ValidBases(); + } + + return restricted.ValidBases(); + } + else if (dimension->Type() == MeasurementDimension::Z) + { + QPair restriction; + + if (index == 1) + { + restriction = m->OneDimensionRestriction(currentDimensionA); + } + else + { + restriction = m->TwoDimensionRestriction(currentDimensionA, currentDimensionB); + } + + VZMeasurementDimension restricted(dimension->Units(), restriction.first, restriction.second, dimension->Step()); + + if (restriction.first < dimension->MinValue() || restriction.second > dimension->MaxValue() + || not restricted.IsValid()) + { // invalid restriction + return dimension->ValidBases(); + } + + return restricted.ValidBases(); + } + + return QVector(); +} + //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::SetDecimals() { diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index e115f7a75..d500a86a2 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -113,8 +113,11 @@ private slots: void AddKnown(); void ImportFromPattern(); - void ChangedSize(const QString &text); - void ChangedHeight(const QString & text); + void DimensionABaseChanged(); + void DimensionBBaseChanged(); + void DimensionCBaseChanged(); + + void GradationChanged(); void ShowMData(); @@ -156,6 +159,7 @@ private: bool isInitialized{false}; bool mIsReadOnly{false}; QAction *actionFullCircumference{nullptr}; + QTimer *gradation; QVector hackedWidgets{}; @@ -163,6 +167,8 @@ private: void InitWindow(); void InitMenu(); void InitDimensionsBaseValue(); + void InitDimensionGradation(int index, const MeasurementDimension_p &dimension, QComboBox *control); + void InitDimensionControls(); void InitTable(); void SetDecimals(); void InitUnits(); @@ -181,11 +187,6 @@ private: QTableWidgetItem *AddCell(const QString &text, int row, int column, int aligment, bool ok = true); - Q_REQUIRED_RESULT QComboBox *SetGradationList(QLabel *label, const QStringList &list); - - void SetDefaultHeight(int value); - void SetDefaultSize(int value); - void RefreshData(bool freshCall = false); void RefreshTable(bool freshCall = false); @@ -230,6 +231,12 @@ private: QString DimensionName(MeasurementDimension type); QString DimensionToolTip(MeasurementDimension type, bool circumference); + + void ShowDimensionControls(); + void SetDimensionBases(); + void SetCurrentDimensionValues(); + + QVector DimensionRestrictedValues(int index, const MeasurementDimension_p &dimension); }; #endif // TMAINWINDOW_H diff --git a/src/libs/vformat/vmeasurements.cpp b/src/libs/vformat/vmeasurements.cpp index 7301e3279..456b9bdef 100644 --- a/src/libs/vformat/vmeasurements.cpp +++ b/src/libs/vformat/vmeasurements.cpp @@ -684,6 +684,18 @@ QMap VMeasurements::Dimensions() return dimesions; } +//--------------------------------------------------------------------------------------------------------------------- +QPair VMeasurements::OneDimensionRestriction(int base) const +{ + return QPair(0, 0); +} + +//--------------------------------------------------------------------------------------------------------------------- +QPair VMeasurements::TwoDimensionRestriction(int base1, int base2) const +{ + return QPair(0, 0); +} + //--------------------------------------------------------------------------------------------------------------------- QString VMeasurements::GenderToStr(const GenderType &sex) { diff --git a/src/libs/vformat/vmeasurements.h b/src/libs/vformat/vmeasurements.h index 810d347a9..a3797a32a 100644 --- a/src/libs/vformat/vmeasurements.h +++ b/src/libs/vformat/vmeasurements.h @@ -109,6 +109,9 @@ public: QMap Dimensions() const; + QPair OneDimensionRestriction(int base) const; + QPair TwoDimensionRestriction(int base1, int base2) const; + static const QString TagVST; static const QString TagVIT; static const QString TagBodyMeasurements; From 16ce597a3743061731e2e660d5b4acf8e7ba5065 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 3 Oct 2020 18:52:31 +0300 Subject: [PATCH 12/44] Reading/Writing a measurement data. --- src/app/tape/tmainwindow.cpp | 377 +++++++++-- src/app/tape/tmainwindow.h | 12 +- src/app/tape/tmainwindow.ui | 590 ++++++++++-------- src/libs/vformat/vmeasurements.cpp | 397 +++++++++--- src/libs/vformat/vmeasurements.h | 26 +- .../vpatterndb/variables/vmeasurement.cpp | 210 +++++-- src/libs/vpatterndb/variables/vmeasurement.h | 50 +- .../vpatterndb/variables/vmeasurement_p.h | 97 ++- src/libs/vpatterndb/variables/vvariable.h | 2 +- 9 files changed, 1217 insertions(+), 544 deletions(-) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 7ebaeda13..4a974957d 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -81,8 +81,23 @@ Q_LOGGING_CATEGORY(tMainWindow, "t.mainwindow") QT_WARNING_POP +namespace +{ +enum class MUnits : qint8 { Table, Degrees}; +} + // We need this enum in case we will add or delete a column. And also make code more readable. -enum {ColumnName = 0, ColumnFullName, ColumnCalcValue, ColumnFormula, ColumnBaseValue, ColumnInSizes, ColumnInHeights}; +enum { + ColumnName = 0, + ColumnFullName = 1, + ColumnCalcValue = 2, + ColumnFormula = 3, + ColumnBaseValue = 4, + ColumnShiftA = 5, + ColumnShiftB = 6, + ColumnShiftC = 7, + ColumnCorrection = 8 +}; //--------------------------------------------------------------------------------------------------------------------- TMainWindow::TMainWindow(QWidget *parent) @@ -582,6 +597,8 @@ void TMainWindow::changeEvent(QEvent *event) // retranslate designer form (single inheritance approach) ui->retranslateUi(this); + InitMeasurementUnits(); + if (mType == MeasurementsType::Multisize) { actionFullCircumference->setText(tr("Use full circumference")); @@ -590,6 +607,7 @@ void TMainWindow::changeEvent(QEvent *event) InitDimensionsBaseValue(); InitDimensionControls(); + InitDimesionShifts(); } else { @@ -1158,22 +1176,32 @@ void TMainWindow::Remove() ui->lineEditFullName->setText(QString()); ui->lineEditFullName->blockSignals(false); + ui->comboBoxMUnits->blockSignals(true); + ui->comboBoxMUnits->setCurrentIndex(-1); + ui->comboBoxMUnits->blockSignals(false); + if (mType == MeasurementsType::Multisize) { ui->labelCalculatedValue->blockSignals(true); ui->doubleSpinBoxBaseValue->blockSignals(true); - ui->doubleSpinBoxInSizes->blockSignals(true); - ui->doubleSpinBoxInHeights->blockSignals(true); + ui->doubleSpinBoxCorrection->blockSignals(true); + ui->doubleSpinBoxShiftA->blockSignals(true); + ui->doubleSpinBoxShiftB->blockSignals(true); + ui->doubleSpinBoxShiftC->blockSignals(true); ui->labelCalculatedValue->setText(QString()); ui->doubleSpinBoxBaseValue->setValue(0); - ui->doubleSpinBoxInSizes->setValue(0); - ui->doubleSpinBoxInHeights->setValue(0); + ui->doubleSpinBoxCorrection->setValue(0); + ui->doubleSpinBoxShiftA->setValue(0); + ui->doubleSpinBoxShiftB->setValue(0); + ui->doubleSpinBoxShiftC->setValue(0); ui->labelCalculatedValue->blockSignals(false); ui->doubleSpinBoxBaseValue->blockSignals(false); - ui->doubleSpinBoxInSizes->blockSignals(false); - ui->doubleSpinBoxInHeights->blockSignals(false); + ui->doubleSpinBoxCorrection->blockSignals(false); + ui->doubleSpinBoxShiftA->blockSignals(false); + ui->doubleSpinBoxShiftB->blockSignals(false); + ui->doubleSpinBoxShiftC->blockSignals(false); } else { @@ -1590,12 +1618,17 @@ void TMainWindow::ShowNewMData(bool fresh) connect(ui->lineEditName, &QLineEdit::textEdited, this, &TMainWindow::SaveMName); ui->plainTextEditDescription->blockSignals(false); + ui->comboBoxMUnits->setCurrentIndex( + ui->comboBoxMUnits->findData(static_cast(meash->IsSpecialUnits() ? MUnits::Degrees : MUnits::Table))); + if (mType == MeasurementsType::Multisize) { ui->labelCalculatedValue->blockSignals(true); ui->doubleSpinBoxBaseValue->blockSignals(true); - ui->doubleSpinBoxInSizes->blockSignals(true); - ui->doubleSpinBoxInHeights->blockSignals(true); + ui->doubleSpinBoxCorrection->blockSignals(true); + ui->doubleSpinBoxShiftA->blockSignals(true); + ui->doubleSpinBoxShiftB->blockSignals(true); + ui->doubleSpinBoxShiftC->blockSignals(true); const QString postfix = UnitsToStr(pUnit);//Show unit in dialog lable (cm, mm or inch) const qreal value = UnitConvertor(*data->DataVariables()->value(meash->GetName())->GetValue(), mUnit, @@ -1605,14 +1638,19 @@ void TMainWindow::ShowNewMData(bool fresh) if (fresh) { ui->doubleSpinBoxBaseValue->setValue(meash->GetBase()); - ui->doubleSpinBoxInSizes->setValue(meash->GetKsize()); - ui->doubleSpinBoxInHeights->setValue(meash->GetKheight()); + ui->doubleSpinBoxCorrection->setValue( + meash->GetCorrection(currentDimensionA, currentDimensionB, currentDimensionC)); + ui->doubleSpinBoxShiftA->setValue(meash->GetShiftA()); + ui->doubleSpinBoxShiftB->setValue(meash->GetShiftB()); + ui->doubleSpinBoxShiftC->setValue(meash->GetShiftC()); } ui->labelCalculatedValue->blockSignals(false); ui->doubleSpinBoxBaseValue->blockSignals(false); - ui->doubleSpinBoxInSizes->blockSignals(false); - ui->doubleSpinBoxInHeights->blockSignals(false); + ui->doubleSpinBoxCorrection->blockSignals(false); + ui->doubleSpinBoxShiftA->blockSignals(false); + ui->doubleSpinBoxShiftB->blockSignals(false); + ui->doubleSpinBoxShiftC->blockSignals(false); } else { @@ -1851,7 +1889,7 @@ void TMainWindow::SaveMBaseValue(double value) } //--------------------------------------------------------------------------------------------------------------------- -void TMainWindow::SaveMSizeIncrease(double value) +void TMainWindow::SaveMShiftA(double value) { const int row = ui->tableWidget->currentRow(); @@ -1861,7 +1899,7 @@ void TMainWindow::SaveMSizeIncrease(double value) } const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName); - m->SetMSizeIncrease(nameField->data(Qt::UserRole).toString(), value); + m->SetMShiftA(nameField->data(Qt::UserRole).toString(), value); MeasurementsWereSaved(false); @@ -1876,7 +1914,7 @@ void TMainWindow::SaveMSizeIncrease(double value) } //--------------------------------------------------------------------------------------------------------------------- -void TMainWindow::SaveMHeightIncrease(double value) +void TMainWindow::SaveMShiftB(double value) { const int row = ui->tableWidget->currentRow(); @@ -1886,7 +1924,58 @@ void TMainWindow::SaveMHeightIncrease(double value) } const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName); - m->SetMHeightIncrease(nameField->data(Qt::UserRole).toString(), value); + m->SetMShiftB(nameField->data(Qt::UserRole).toString(), value); + + MeasurementsWereSaved(false); + + RefreshData(); + search->RefreshList(ui->lineEditFind->text()); + + ui->tableWidget->blockSignals(true); + ui->tableWidget->selectRow(row); + ui->tableWidget->blockSignals(false); + + ShowNewMData(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::SaveMShiftC(double value) +{ + const int row = ui->tableWidget->currentRow(); + + if (row == -1) + { + return; + } + + const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName); + m->SetMShiftC(nameField->data(Qt::UserRole).toString(), value); + + MeasurementsWereSaved(false); + + RefreshData(); + search->RefreshList(ui->lineEditFind->text()); + + ui->tableWidget->blockSignals(true); + ui->tableWidget->selectRow(row); + ui->tableWidget->blockSignals(false); + + ShowNewMData(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::SaveMCorrectionValue(double value) +{ + const int row = ui->tableWidget->currentRow(); + + if (row == -1) + { + return; + } + + const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName); + m->SetMCorrectionValue(nameField->data(Qt::UserRole).toString(), + currentDimensionA, currentDimensionB, currentDimensionC, value); MeasurementsWereSaved(false); @@ -1972,6 +2061,32 @@ void TMainWindow::SaveMFullName() } } +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::SaveMUnits() +{ + const int row = ui->tableWidget->currentRow(); + + if (row == -1) + { + return; + } + + const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName); + const MUnits units = static_cast(ui->comboBoxMUnits->currentData().toInt()); + m->SetMSpecialUnits(nameField->data(Qt::UserRole).toString(), units == MUnits::Degrees); + + MeasurementsWereSaved(false); + + RefreshData(); + search->RefreshList(ui->lineEditFind->text()); + + ui->tableWidget->blockSignals(true); + ui->tableWidget->selectRow(row); + ui->tableWidget->blockSignals(false); + + ShowNewMData(false); +} + //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::FullCircumferenceChanged(bool checked) { @@ -2117,12 +2232,20 @@ void TMainWindow::InitWindow() ShowDimensionControls(); SetDimensionBases(); + InitDimesionShifts(); + HackDimensionShifts(); + connect(ui->doubleSpinBoxBaseValue, QOverload::of(&QDoubleSpinBox::valueChanged), this, &TMainWindow::SaveMBaseValue); - connect(ui->doubleSpinBoxInSizes, QOverload::of(&QDoubleSpinBox::valueChanged), - this, &TMainWindow::SaveMSizeIncrease); - connect(ui->doubleSpinBoxInHeights, QOverload::of(&QDoubleSpinBox::valueChanged), - this, &TMainWindow::SaveMHeightIncrease); + connect(ui->doubleSpinBoxCorrection, QOverload::of(&QDoubleSpinBox::valueChanged), + this, &TMainWindow::SaveMCorrectionValue); + + connect(ui->doubleSpinBoxShiftA, QOverload::of(&QDoubleSpinBox::valueChanged), + this, &TMainWindow::SaveMShiftA); + connect(ui->doubleSpinBoxShiftB, QOverload::of(&QDoubleSpinBox::valueChanged), + this, &TMainWindow::SaveMShiftB); + connect(ui->doubleSpinBoxShiftC, QOverload::of(&QDoubleSpinBox::valueChanged), + this, &TMainWindow::SaveMShiftC); SetDecimals(); } @@ -2137,11 +2260,10 @@ void TMainWindow::InitWindow() // Tab Measurements HackWidget(&ui->doubleSpinBoxBaseValue); - HackWidget(&ui->doubleSpinBoxInSizes); - HackWidget(&ui->doubleSpinBoxInHeights); + HackWidget(&ui->doubleSpinBoxCorrection); HackWidget(&ui->labelBaseValue); - HackWidget(&ui->labelInSizes); - HackWidget(&ui->labelInHeights); + HackWidget(&ui->labelCorrection); + HackDimensionShifts(); // Tab Information HackDimensionBaseValue(); @@ -2226,7 +2348,14 @@ void TMainWindow::InitWindow() ShowInGraphicalShell(curFile); }); - InitUnits(); + InitPatternUnits(); + InitMeasurementUnits(); + + ui->comboBoxMUnits->blockSignals(true); + ui->comboBoxMUnits->setCurrentIndex(-1); + ui->comboBoxMUnits->blockSignals(false); + + connect(ui->comboBoxMUnits, QOverload::of(&QComboBox::currentIndexChanged), this, &TMainWindow::SaveMUnits); InitTable(); } @@ -2388,18 +2517,72 @@ void TMainWindow::InitDimensionControls() InitControl(2, labelGradationDimensionC, gradationDimensionC); } +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::InitDimesionShifts() +{ + const QList dimensions = m->Dimensions().values(); + + auto InitShift = [this, dimensions](int index, QLabel *name) + { + if (dimensions.size() > index) + { + MeasurementDimension_p dimension = dimensions.at(index); + + name->setText(tr("Shift (%1):").arg(DimensionName(dimension->Type()))); + name->setToolTip(DimensionToolTip(dimension->Type(), dimension->IsCircumference())); + } + }; + + InitShift(0, ui->labelShiftA); + InitShift(1, ui->labelShiftB); + InitShift(2, ui->labelShiftC); +} + //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::InitTable() { if (mType == MeasurementsType::Multisize) { ui->tableWidget->setColumnHidden( ColumnFormula, true );// formula + + const QList< MeasurementDimension_p > dimensions = m->Dimensions().values(); + + if (dimensions.size() > 0) + { + MeasurementDimension_p dimension = dimensions.at(0); + ui->tableWidget->horizontalHeaderItem(ColumnShiftA)->setText( + tr("%1 shift").arg(DimensionName(dimension->Type()))); + } + + if (dimensions.size() < 2) + { + ui->tableWidget->setColumnHidden( ColumnShiftB, true ); + } + else + { + MeasurementDimension_p dimension = dimensions.at(1); + ui->tableWidget->horizontalHeaderItem(ColumnShiftB)->setText( + tr("%1 shift").arg(DimensionName(dimension->Type()))); + } + + if (dimensions.size() < 3) + { + ui->tableWidget->setColumnHidden( ColumnShiftC, true ); + } + else + { + MeasurementDimension_p dimension = dimensions.at(2); + ui->tableWidget->horizontalHeaderItem(ColumnShiftC)->setText( + tr("%1 shift").arg(DimensionName(dimension->Type()))); + } } else { ui->tableWidget->setColumnHidden( ColumnBaseValue, true );// base value - ui->tableWidget->setColumnHidden( ColumnInSizes, true );// in sizes - ui->tableWidget->setColumnHidden( ColumnInHeights, true );// in heights + ui->tableWidget->setColumnHidden( ColumnShiftA, true ); + ui->tableWidget->setColumnHidden( ColumnShiftB, true ); + ui->tableWidget->setColumnHidden( ColumnShiftC, true ); + ui->tableWidget->setColumnHidden( ColumnCorrection, true ); } connect(ui->tableWidget, &QTableWidget::itemSelectionChanged, this, &TMainWindow::ShowMData); @@ -2419,8 +2602,10 @@ void TMainWindow::ShowUnits() ShowHeaderUnits(ui->tableWidget, ColumnCalcValue, UnitsToStr(pUnit));// calculated value ShowHeaderUnits(ui->tableWidget, ColumnFormula, unit);// formula ShowHeaderUnits(ui->tableWidget, ColumnBaseValue, unit);// base value - ShowHeaderUnits(ui->tableWidget, ColumnInSizes, unit);// in sizes - ShowHeaderUnits(ui->tableWidget, ColumnInHeights, unit);// in heights + ShowHeaderUnits(ui->tableWidget, ColumnShiftA, unit); + ShowHeaderUnits(ui->tableWidget, ColumnShiftB, unit); + ShowHeaderUnits(ui->tableWidget, ColumnShiftC, unit); + ShowHeaderUnits(ui->tableWidget, ColumnCorrection, unit); } //--------------------------------------------------------------------------------------------------------------------- @@ -2641,11 +2826,17 @@ void TMainWindow::RefreshTable(bool freshCall) AddCell(locale().toString(meash->GetBase()), currentRow, ColumnBaseValue, Qt::AlignHCenter | Qt::AlignVCenter); // base value - AddCell(locale().toString(meash->GetKsize()), currentRow, ColumnInSizes, - Qt::AlignHCenter | Qt::AlignVCenter); // in sizes + AddCell(locale().toString(meash->GetShiftA()), currentRow, ColumnShiftA, + Qt::AlignHCenter | Qt::AlignVCenter); - AddCell(locale().toString(meash->GetKheight()), currentRow, ColumnInHeights, - Qt::AlignHCenter | Qt::AlignVCenter); // in heights + AddCell(locale().toString(meash->GetShiftB()), currentRow, ColumnShiftB, + Qt::AlignHCenter | Qt::AlignVCenter); + + AddCell(locale().toString(meash->GetShiftC()), currentRow, ColumnShiftC, + Qt::AlignHCenter | Qt::AlignVCenter); + + AddCell(locale().toString(meash->GetCorrection(currentDimensionA, currentDimensionB, currentDimensionC)), + currentRow, ColumnCorrection, Qt::AlignHCenter | Qt::AlignVCenter); } } @@ -2725,12 +2916,15 @@ void TMainWindow::MFields(bool enabled) ui->lineEditName->setEnabled(enabled); ui->plainTextEditDescription->setEnabled(enabled); ui->lineEditFullName->setEnabled(enabled); + ui->comboBoxMUnits->setEnabled(enabled); if (mType == MeasurementsType::Multisize) { ui->doubleSpinBoxBaseValue->setEnabled(enabled); - ui->doubleSpinBoxInSizes->setEnabled(enabled); - ui->doubleSpinBoxInHeights->setEnabled(enabled); + ui->doubleSpinBoxShiftA->setEnabled(enabled); + ui->doubleSpinBoxShiftB->setEnabled(enabled); + ui->doubleSpinBoxShiftC->setEnabled(enabled); + ui->doubleSpinBoxCorrection->setEnabled(enabled); } else { @@ -3221,6 +3415,28 @@ void TMainWindow::HackDimensionBaseValue() DimensionsBaseValue(2, ui->labelDimensionC, ui->labelDimensionCBase); } +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::HackDimensionShifts() +{ + const QList dimensions = m->Dimensions().values(); + + auto HackShift = [this, dimensions](int index, QLabel *name, QDoubleSpinBox *shift) + { + SCASSERT(name != nullptr) + SCASSERT(shift != nullptr) + + if (dimensions.size() <= index) + { + HackWidget(&name); + HackWidget(&shift); + } + }; + + HackShift(0, ui->labelShiftA, ui->doubleSpinBoxShiftA); + HackShift(0, ui->labelShiftB, ui->doubleSpinBoxShiftB); + HackShift(0, ui->labelShiftC, ui->doubleSpinBoxShiftC); +} + //--------------------------------------------------------------------------------------------------------------------- QString TMainWindow::CheckMName(const QString &name, const QSet &importedNames) const { @@ -3465,8 +3681,8 @@ void TMainWindow::ImportMultisizeMeasurements(const QxtCsvModel &csv) { m->AddEmpty(mm.name); m->SetMBaseValue(mm.name, mm.base); - m->SetMSizeIncrease(mm.name, mm.sizeIncrease); - m->SetMHeightIncrease(mm.name, mm.heightIncrease); + m->SetMShiftB(mm.name, mm.sizeIncrease); + m->SetMShiftA(mm.name, mm.heightIncrease); if (not mm.fullName.isEmpty()) { @@ -3716,31 +3932,49 @@ void TMainWindow::SetDecimals() ui->doubleSpinBoxBaseValue->setDecimals(2); ui->doubleSpinBoxBaseValue->setSingleStep(0.01); - ui->doubleSpinBoxInSizes->setDecimals(2); - ui->doubleSpinBoxInSizes->setSingleStep(0.01); + ui->doubleSpinBoxCorrection->setDecimals(2); + ui->doubleSpinBoxCorrection->setSingleStep(0.01); - ui->doubleSpinBoxInHeights->setDecimals(2); - ui->doubleSpinBoxInHeights->setSingleStep(0.01); + ui->doubleSpinBoxShiftA->setDecimals(2); + ui->doubleSpinBoxShiftA->setSingleStep(0.01); + + ui->doubleSpinBoxShiftB->setDecimals(2); + ui->doubleSpinBoxShiftB->setSingleStep(0.01); + + ui->doubleSpinBoxShiftC->setDecimals(2); + ui->doubleSpinBoxShiftC->setSingleStep(0.01); break; case Unit::Mm: ui->doubleSpinBoxBaseValue->setDecimals(1); ui->doubleSpinBoxBaseValue->setSingleStep(0.1); - ui->doubleSpinBoxInSizes->setDecimals(1); - ui->doubleSpinBoxInSizes->setSingleStep(0.1); + ui->doubleSpinBoxCorrection->setDecimals(1); + ui->doubleSpinBoxCorrection->setSingleStep(0.1); - ui->doubleSpinBoxInHeights->setDecimals(1); - ui->doubleSpinBoxInHeights->setSingleStep(0.1); + ui->doubleSpinBoxShiftA->setDecimals(1); + ui->doubleSpinBoxShiftA->setSingleStep(0.1); + + ui->doubleSpinBoxShiftB->setDecimals(1); + ui->doubleSpinBoxShiftB->setSingleStep(0.1); + + ui->doubleSpinBoxShiftC->setDecimals(1); + ui->doubleSpinBoxShiftC->setSingleStep(0.1); break; case Unit::Inch: ui->doubleSpinBoxBaseValue->setDecimals(5); ui->doubleSpinBoxBaseValue->setSingleStep(0.00001); - ui->doubleSpinBoxInSizes->setDecimals(5); - ui->doubleSpinBoxInSizes->setSingleStep(0.00001); + ui->doubleSpinBoxCorrection->setDecimals(5); + ui->doubleSpinBoxCorrection->setSingleStep(0.00001); - ui->doubleSpinBoxInHeights->setDecimals(5); - ui->doubleSpinBoxInHeights->setSingleStep(0.00001); + ui->doubleSpinBoxShiftA->setDecimals(5); + ui->doubleSpinBoxShiftA->setSingleStep(0.00001); + + ui->doubleSpinBoxShiftB->setDecimals(5); + ui->doubleSpinBoxShiftB->setSingleStep(0.00001); + + ui->doubleSpinBoxShiftC->setDecimals(5); + ui->doubleSpinBoxShiftC->setSingleStep(0.00001); break; default: break; @@ -3748,7 +3982,7 @@ void TMainWindow::SetDecimals() } //--------------------------------------------------------------------------------------------------------------------- -void TMainWindow::InitUnits() +void TMainWindow::InitPatternUnits() { labelPatternUnit = new QLabel(tr("Pattern unit:")); ui->toolBarGradation->addWidget(labelPatternUnit); @@ -3776,6 +4010,47 @@ void TMainWindow::InitComboBoxUnits() comboBoxUnits->addItem(UnitsToStr(Unit::Inch, true), QVariant(static_cast(Unit::Inch))); } +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::InitMeasurementUnits() +{ + ui->comboBoxMUnits->blockSignals(true); + + int current = -1; + if (ui->comboBoxMUnits->currentIndex() != -1) + { + current = ui->comboBoxMUnits->currentData().toInt(); + } + + QString units; + switch (m->MUnit()) + { + case Unit::Mm: + units = tr("Millimeters"); + break; + case Unit::Inch: + units = tr("Inches"); + break; + case Unit::Cm: + units = tr("Centimeters"); + break; + default: + units = ""; + break; + } + + ui->comboBoxMUnits->clear(); + ui->comboBoxMUnits->addItem(units, QVariant(static_cast(MUnits::Table))); + ui->comboBoxMUnits->addItem(tr("Degrees"), QVariant(static_cast(MUnits::Degrees))); + + int i = ui->comboBoxMUnits->findData(current); + if (i != -1) + { + ui->comboBoxMUnits->setCurrentIndex(i); + } + + ui->comboBoxMUnits->blockSignals(false); +} + //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::InitGender(QComboBox *gender) { diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index d500a86a2..79b9406a5 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -126,10 +126,13 @@ private slots: void SaveMName(const QString &text); void SaveMValue(); void SaveMBaseValue(double value); - void SaveMSizeIncrease(double value); - void SaveMHeightIncrease(double value); + void SaveMShiftA(double value); + void SaveMShiftB(double value); + void SaveMShiftC(double value); + void SaveMCorrectionValue(double value); void SaveMDescription(); void SaveMFullName(); + void SaveMUnits(); void FullCircumferenceChanged(bool checked); @@ -169,10 +172,12 @@ private: void InitDimensionsBaseValue(); void InitDimensionGradation(int index, const MeasurementDimension_p &dimension, QComboBox *control); void InitDimensionControls(); + void InitDimesionShifts(); void InitTable(); void SetDecimals(); - void InitUnits(); + void InitPatternUnits(); void InitComboBoxUnits(); + void InitMeasurementUnits(); void InitGender(QComboBox *gender); void ShowNewMData(bool fresh); @@ -219,6 +224,7 @@ private: template void HackWidget(T **widget); void HackDimensionBaseValue(); + void HackDimensionShifts(); QString CheckMName(const QString &name, const QSet &importedNames) const; void ShowError(const QString &text); diff --git a/src/app/tape/tmainwindow.ui b/src/app/tape/tmainwindow.ui index cd66e0e29..e5ce51c77 100644 --- a/src/app/tape/tmainwindow.ui +++ b/src/app/tape/tmainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 1034 - 896 + 1188 + 836 @@ -24,7 +24,7 @@ 0 - + @@ -173,12 +173,22 @@ - In sizes + Shift A - In heights + Shift B + + + + + Shift C + + + + + Correction @@ -198,173 +208,12 @@ Details - - - QFormLayout::ExpandingFieldsGrow - - - - - Name: - - - - - - - false - - - Measurement's name in a formula - - - Measurement's name in a formula. - - - - - - - Formula: - - - - - - - - - false - - - - 0 - 0 - - - - - 16777215 - 28 - - - - true - - - - - - - false - - - - 18 - 18 - - - - - 0 - 0 - - - - <html><head/><body><p>Show full calculation in message box</p></body></html> - - - - - - - ../../libs/vtools/dialogs/support../../libs/vtools/dialogs/support - - - - 16 - 16 - - - - true - - - - - - - false - - - Function Wizard - - - ... - - - - :/tapeicon/24x24/fx.png:/tapeicon/24x24/fx.png - - - - 24 - 24 - - - - - - - - - - Base value: - - - - - - - In sizes: - - - - - - - In heights: - - - - - - - Description: - - - - - - - false - - - - 0 - 1 - - - - - 0 - 28 - - - - - + + + + 9 + @@ -433,23 +282,6 @@ - - - - Qt::Horizontal - - - - 5000 - 20 - - - - - - - - @@ -457,13 +289,13 @@ - 5000 + 40 20 - + false @@ -482,81 +314,309 @@ - - - - Calculated value: + + + + QFormLayout::ExpandingFieldsGrow - - - - - - Calculated value - - - - - - - - - - false - - - -10000.000000000000000 - - - 10000.000000000000000 - - - - - - - false - - - -10000.000000000000000 - - - 10000.000000000000000 - - - - - - - false - - - -10000.000000000000000 - - - 10000.000000000000000 - - - - - - - Full name: - - - - - - - false - - - - - - Measurement's human-readable name. - - + + + + Units: + + + + + + + false + + + + 0 + 0 + + + + + + + + Name: + + + + + + + false + + + Measurement's name in a formula + + + Measurement's name in a formula. + + + + + + + Calculated value: + + + + + + + Calculated value + + + + + + + + + + Formula: + + + + + + + + + false + + + + 0 + 0 + + + + + 16777215 + 28 + + + + true + + + + + + + false + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + ../../libs/vtools/dialogs/support../../libs/vtools/dialogs/support + + + + 16 + 16 + + + + true + + + + + + + false + + + Function Wizard + + + ... + + + + :/tapeicon/24x24/fx.png:/tapeicon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + Base value: + + + + + + + false + + + -10000.000000000000000 + + + 10000.000000000000000 + + + + + + + Shift A + + + + + + + false + + + -10000.000000000000000 + + + 10000.000000000000000 + + + + + + + Shift B + + + + + + + false + + + -10000.000000000000000 + + + 10000.000000000000000 + + + + + + + Shift C + + + + + + + false + + + -10000.000000000000000 + + + 10000.000000000000000 + + + + + + + Correction: + + + + + + + false + + + -10000.000000000000000 + + + 10000.000000000000000 + + + + + + + Full name: + + + + + + + false + + + + + + Measurement's human-readable name. + + + + + + + Description: + + + + + + + false + + + + 0 + 1 + + + + + 0 + 28 + + + + + @@ -884,7 +944,7 @@ 0 0 - 1034 + 1188 21 diff --git a/src/libs/vformat/vmeasurements.cpp b/src/libs/vformat/vmeasurements.cpp index 456b9bdef..8a8916a1a 100644 --- a/src/libs/vformat/vmeasurements.cpp +++ b/src/libs/vformat/vmeasurements.cpp @@ -71,18 +71,24 @@ const QString VMeasurements::TagMeasurement = QStringLiteral("m"); const QString VMeasurements::TagDimensions = QStringLiteral("dimensions"); const QString VMeasurements::TagDimension = QStringLiteral("dimension"); const QString VMeasurements::TagRestrictions = QStringLiteral("restrictions"); +const QString VMeasurements::TagCorrections = QStringLiteral("corrections"); +const QString VMeasurements::TagCorrection = QStringLiteral("correction"); -const QString VMeasurements::AttrBase = QStringLiteral("base"); -const QString VMeasurements::AttrValue = QStringLiteral("value"); -const QString VMeasurements::AttrSizeIncrease = QStringLiteral("size_increase"); -const QString VMeasurements::AttrHeightIncrease = QStringLiteral("height_increase"); -const QString VMeasurements::AttrDescription = QStringLiteral("description"); -const QString VMeasurements::AttrName = QStringLiteral("name"); -const QString VMeasurements::AttrFullName = QStringLiteral("full_name"); -const QString VMeasurements::AttrMin = QStringLiteral("min"); -const QString VMeasurements::AttrMax = QStringLiteral("max"); -const QString VMeasurements::AttrStep = QStringLiteral("step"); -const QString VMeasurements::AttrCircumference = QStringLiteral("circumference"); +const QString VMeasurements::AttrBase = QStringLiteral("base"); +const QString VMeasurements::AttrValue = QStringLiteral("value"); +const QString VMeasurements::AttrShiftA = QStringLiteral("shiftA"); +const QString VMeasurements::AttrShiftB = QStringLiteral("shiftB"); +const QString VMeasurements::AttrShiftC = QStringLiteral("shiftC"); +const QString VMeasurements::AttrCorrection = QStringLiteral("correction"); +const QString VMeasurements::AttrCoordinates = QStringLiteral("coordinates"); +const QString VMeasurements::AttrSpecialUnits = QStringLiteral("specialUnits"); +const QString VMeasurements::AttrDescription = QStringLiteral("description"); +const QString VMeasurements::AttrName = QStringLiteral("name"); +const QString VMeasurements::AttrFullName = QStringLiteral("full_name"); +const QString VMeasurements::AttrMin = QStringLiteral("min"); +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::GenderMale = QStringLiteral("male"); @@ -96,7 +102,10 @@ const QString VMeasurements::DimensionZ = QStringLiteral("z"); namespace { +using VDimensions = QMap; + Q_GLOBAL_STATIC_WITH_ARGS(const QString, defBirthDate, (QLatin1String("1800-01-01"))) +Q_GLOBAL_STATIC(VDimensions, dimensionsCached) //--------------------------------------------------------------------------------------------------------------------- QString FileComment() @@ -268,14 +277,19 @@ void VMeasurements::StoreNames(bool store) } //--------------------------------------------------------------------------------------------------------------------- -void VMeasurements::ReadMeasurements(qreal height, qreal size) const +void VMeasurements::ReadMeasurements(qreal baseA, qreal baseB, qreal baseC) const { // For conversion values we must first calculate all data in measurement file's unit. // That's why we need two containers: one for converted values, second for real data. // Container for values in measurement file's unit - QScopedPointer tempData(new VContainer(data->GetTrVars(), data->GetPatternUnit(), - VContainer::UniqueNamespace())); + QSharedPointer tempData; + + if (type == MeasurementsType::Individual) + { + tempData = QSharedPointer::create(data->GetTrVars(), data->GetPatternUnit(), + VContainer::UniqueNamespace()); + } const QDomNodeList list = elementsByTagName(TagMeasurement); for (int i=0; i < list.size(); ++i) @@ -285,33 +299,66 @@ void VMeasurements::ReadMeasurements(qreal height, qreal size) const const QString name = GetParametrString(dom, AttrName).simplified(); const QString description = GetParametrEmptyString(dom, AttrDescription); const QString fullName = GetParametrEmptyString(dom, AttrFullName); + const bool specialUnits = GetParametrBool(dom, AttrSpecialUnits, falseStr); QSharedPointer meash; QSharedPointer tempMeash; if (type == MeasurementsType::Multisize) { qreal base = GetParametrDouble(dom, AttrBase, QChar('0')); - qreal ksize = GetParametrDouble(dom, AttrSizeIncrease, QChar('0')); - qreal kheight = GetParametrDouble(dom, AttrHeightIncrease, QChar('0')); + qreal shiftA = GetParametrDouble(dom, AttrShiftA, QChar('0')); + qreal shiftB = GetParametrDouble(dom, AttrShiftB, QChar('0')); + qreal shiftC = GetParametrDouble(dom, AttrShiftC, QChar('0')); + QMap corrections = ReadCorrections(dom); - tempMeash = QSharedPointer(new VMeasurement(static_cast(i), name, DimensionABase(), - DimensionBBase(), base, ksize, kheight)); - tempMeash->SetSize(size); - tempMeash->SetHeight(height); - tempMeash->SetUnit(data->GetPatternUnit()); + qreal convertedBaseA = DimensionABase(); + qreal convertedBaseB = DimensionBBase(); + qreal convertedBaseC = DimensionCBase(); + qreal convertedStepA = DimensionAStep(); + qreal convertedStepB = DimensionBStep(); + qreal convertedStepC = DimensionCStep(); - base = UnitConvertor(base, MUnit(), *data->GetPatternUnit()); - ksize = UnitConvertor(ksize, MUnit(), *data->GetPatternUnit()); - kheight = UnitConvertor(kheight, MUnit(), *data->GetPatternUnit()); + if (not specialUnits) + { + base = UnitConvertor(base, MUnit(), *data->GetPatternUnit()); + shiftA = UnitConvertor(shiftA, MUnit(), *data->GetPatternUnit()); + shiftB = UnitConvertor(shiftB, MUnit(), *data->GetPatternUnit()); + shiftC = UnitConvertor(shiftC, MUnit(), *data->GetPatternUnit()); - const qreal baseSize = UnitConvertor(DimensionABase(), MUnit(), *data->GetPatternUnit()); - const qreal baseHeight = UnitConvertor(DimensionBBase(), MUnit(), *data->GetPatternUnit()); + QMutableMapIterator iterator(corrections); + while (iterator.hasNext()) + { + iterator.next(); + iterator.setValue(UnitConvertor(iterator.value(), MUnit(), *data->GetPatternUnit())); + } - meash = QSharedPointer(new VMeasurement(static_cast(i), name, baseSize, baseHeight, - base, ksize, kheight, fullName, description)); - meash->SetSize(size); - meash->SetHeight(height); - meash->SetUnit(data->GetPatternUnit()); + convertedBaseA = UnitConvertor(convertedBaseA, MUnit(), *data->GetPatternUnit()); + convertedBaseB = UnitConvertor(convertedBaseB, MUnit(), *data->GetPatternUnit()); + convertedBaseC = UnitConvertor(convertedBaseC, MUnit(), *data->GetPatternUnit()); + + convertedStepA = UnitConvertor(convertedStepA, MUnit(), *data->GetPatternUnit()); + convertedStepB = UnitConvertor(convertedStepB, MUnit(), *data->GetPatternUnit()); + convertedStepC = UnitConvertor(convertedStepC, MUnit(), *data->GetPatternUnit()); + } + + meash = QSharedPointer::create(static_cast(i), name, + convertedBaseA, convertedBaseB, convertedBaseC, base); + meash->SetBaseA(baseA); + meash->SetBaseB(baseB); + meash->SetBaseC(baseC); + + meash->SetShiftA(shiftA); + meash->SetShiftB(shiftB); + meash->SetShiftC(shiftC); + + meash->SetStepA(convertedStepA); + meash->SetStepB(convertedStepB); + meash->SetStepC(convertedStepC); + + meash->SetSpecialUnits(specialUnits); + meash->SetCorrections(corrections); + meash->SetGuiText(fullName); + meash->SetDescription(description); } else { @@ -319,21 +366,34 @@ void VMeasurements::ReadMeasurements(qreal height, qreal size) const bool ok = false; qreal value = EvalFormula(tempData.data(), formula, &ok); - tempMeash = QSharedPointer(new VMeasurement(tempData.data(), static_cast(i), name, - value, formula, ok)); + tempMeash = QSharedPointer::create(tempData.data(), static_cast(i), name, value, + formula, ok); - value = UnitConvertor(value, MUnit(), *data->GetPatternUnit()); - meash = QSharedPointer(new VMeasurement(data, static_cast(i), name, value, formula, - ok, fullName, description)); + if (not specialUnits) + { + value = UnitConvertor(value, MUnit(), *data->GetPatternUnit()); + } + + meash = QSharedPointer::create(data, static_cast(i), name, value, formula, ok); + meash->SetGuiText(fullName); + meash->SetDescription(description); + meash->SetSpecialUnits(specialUnits); } + if (m_keepNames) { - tempData->AddUniqueVariable(tempMeash); + if (not tempData.isNull()) + { + tempData->AddUniqueVariable(tempMeash); + } data->AddUniqueVariable(meash); } else { - tempData->AddVariable(tempMeash); + if (not tempData.isNull()) + { + tempData->AddVariable(tempMeash); + } data->AddVariable(meash); } } @@ -399,7 +459,7 @@ int VMeasurements::DimensionCBase() const if (type == MeasurementsType::Multisize) { const auto dimensions = Dimensions(); - if (not dimensions.isEmpty() && dimensions.size() >= 3) + if (not dimensions.isEmpty() && dimensions.size() == 3) { return dimensions.last()->BaseValue(); } @@ -408,6 +468,51 @@ int VMeasurements::DimensionCBase() const return 0; } +//--------------------------------------------------------------------------------------------------------------------- +int VMeasurements::DimensionAStep() const +{ + if (type == MeasurementsType::Multisize) + { + const auto dimensions = Dimensions(); + if (not dimensions.isEmpty()) + { + return dimensions.first()->Step(); + } + } + + return 0; +} + +//--------------------------------------------------------------------------------------------------------------------- +int VMeasurements::DimensionBStep() const +{ + if (type == MeasurementsType::Multisize) + { + const auto dimensions = Dimensions(); + if (not dimensions.isEmpty() && dimensions.size() >= 2) + { + return dimensions.values().at(1)->Step(); + } + } + + return 0; +} + +//--------------------------------------------------------------------------------------------------------------------- +int VMeasurements::DimensionCStep() const +{ + if (type == MeasurementsType::Multisize) + { + const auto dimensions = Dimensions(); + if (not dimensions.isEmpty() && dimensions.size() == 3) + { + return dimensions.last()->Step(); + } + } + + return 0; +} + //--------------------------------------------------------------------------------------------------------------------- QString VMeasurements::Notes() const { @@ -583,12 +688,12 @@ void VMeasurements::SetMBaseValue(const QString &name, double value) } //--------------------------------------------------------------------------------------------------------------------- -void VMeasurements::SetMSizeIncrease(const QString &name, double value) +void VMeasurements::SetMShiftA(const QString &name, double value) { QDomElement node = FindM(name); if (not node.isNull()) { - SetAttribute(node, AttrSizeIncrease, value); + SetAttribute(node, AttrShiftA, value); } else { @@ -597,12 +702,69 @@ void VMeasurements::SetMSizeIncrease(const QString &name, double value) } //--------------------------------------------------------------------------------------------------------------------- -void VMeasurements::SetMHeightIncrease(const QString &name, double value) +void VMeasurements::SetMShiftB(const QString &name, double value) { QDomElement node = FindM(name); if (not node.isNull()) { - SetAttribute(node, AttrHeightIncrease, value); + SetAttribute(node, AttrShiftB, value); + } + else + { + qWarning() << tr("Can't find measurement '%1'").arg(name); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurements::SetMShiftC(const QString &name, double value) +{ + QDomElement node = FindM(name); + if (not node.isNull()) + { + SetAttribute(node, AttrShiftC, value); + } + else + { + qWarning() << tr("Can't find measurement '%1'").arg(name); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurements::SetMSpecialUnits(const QString &name, bool special) +{ + QDomElement node = FindM(name); + if (not node.isNull()) + { + SetAttributeOrRemoveIf(node, AttrSpecialUnits, special, not special); + } + else + { + qWarning() << tr("Can't find measurement '%1'").arg(name); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurements::SetMCorrectionValue(const QString &name, qreal baseA, qreal baseB, qreal baseC, double value) +{ + QDomElement mElement = FindM(name); + if (not mElement.isNull()) + { + QMap corrections = ReadCorrections(mElement); + const QString hash = VMeasurement::CorrectionHash(baseA, baseB, baseC); + + if (not qFuzzyIsNull(value)) + { + corrections.insert(hash, value); + } + else + { + if (corrections.contains(hash)) + { + corrections.remove(hash); + } + } + + WriteCorrections(mElement, corrections); } else { @@ -641,47 +803,53 @@ void VMeasurements::SetMFullName(const QString &name, const QString &text) //--------------------------------------------------------------------------------------------------------------------- QMap VMeasurements::Dimensions() const { - QMap dimesions; - - const Unit units = MUnit(); - const QDomNodeList list = elementsByTagName(TagDimension); - for (int i=0; i < list.size(); ++i) + if (type != MeasurementsType::Multisize) { - const QDomElement dom = list.at(i).toElement(); - const MeasurementDimension type = StrToDimensionType(GetParametrString(dom, AttrType)); - const int min = GetParametrInt(dom, AttrMin, QChar('0')); - const int max = GetParametrInt(dom, AttrMax, QChar('0')); - const int step = GetParametrInt(dom, AttrStep, QString("-1")); - const int base = GetParametrInt(dom, AttrBase, QChar('0')); + return QMap(); + } - if (type == MeasurementDimension::X) + if (dimensionsCached->isEmpty()) + { + const Unit units = MUnit(); + const QDomNodeList list = elementsByTagName(TagDimension); + for (int i=0; i < list.size(); ++i) { - auto dimension = QSharedPointer::create(units, min, max, step); - dimension->SetBaseValue(base); - dimesions.insert(type, dimension); - } - else if (type == MeasurementDimension::Y) - { - auto dimension = QSharedPointer::create(units, min, max, step); - dimension->SetBaseValue(base); - dimension->SetCircumference(GetParametrBool(dom, AttrCircumference, trueStr)); - dimesions.insert(type, dimension); - } - else if (type == MeasurementDimension::W) - { - auto dimension = QSharedPointer::create(units, min, max, step); - dimension->SetBaseValue(base); - dimesions.insert(type, dimension); - } - else if (type == MeasurementDimension::Z) - { - auto dimension = QSharedPointer::create(units, min, max, step); - dimension->SetBaseValue(base); - dimesions.insert(type, dimension); + const QDomElement dom = list.at(i).toElement(); + const MeasurementDimension type = StrToDimensionType(GetParametrString(dom, AttrType)); + const int min = GetParametrInt(dom, AttrMin, QChar('0')); + const int max = GetParametrInt(dom, AttrMax, QChar('0')); + const int step = GetParametrInt(dom, AttrStep, QString("-1")); + const int base = GetParametrInt(dom, AttrBase, QChar('0')); + + if (type == MeasurementDimension::X) + { + auto dimension = QSharedPointer::create(units, min, max, step); + dimension->SetBaseValue(base); + dimensionsCached->insert(type, dimension); + } + else if (type == MeasurementDimension::Y) + { + auto dimension = QSharedPointer::create(units, min, max, step); + dimension->SetBaseValue(base); + dimension->SetCircumference(GetParametrBool(dom, AttrCircumference, trueStr)); + dimensionsCached->insert(type, dimension); + } + else if (type == MeasurementDimension::W) + { + auto dimension = QSharedPointer::create(units, min, max, step); + dimension->SetBaseValue(base); + dimensionsCached->insert(type, dimension); + } + else if (type == MeasurementDimension::Z) + { + auto dimension = QSharedPointer::create(units, min, max, step); + dimension->SetBaseValue(base); + dimensionsCached->insert(type, dimension); + } } } - return dimesions; + return *dimensionsCached; } //--------------------------------------------------------------------------------------------------------------------- @@ -936,8 +1104,7 @@ QDomElement VMeasurements::MakeEmpty(const QString &name, const QString &formula if (type == MeasurementsType::Multisize) { SetAttribute(element, AttrBase, QChar('0')); - SetAttribute(element, AttrSizeIncrease, QChar('0')); - SetAttribute(element, AttrHeightIncrease, QChar('0')); + SetAttribute(element, AttrShiftA, QChar('0')); } else { @@ -1030,3 +1197,73 @@ QString VMeasurements::ClearPMCode(const QString &code) const } return clear; } + +//--------------------------------------------------------------------------------------------------------------------- +QMap VMeasurements::ReadCorrections(const QDomElement &mElement) const +{ + if (mElement.isNull()) + { + return QMap(); + } + + QDomElement correctionsTag = mElement.firstChildElement(TagCorrections); + if (correctionsTag.isNull()) + { + return QMap(); + } + + QMap corrections; + + QDomNode correctionTag = correctionsTag.firstChild(); + while (not correctionTag.isNull()) + { + if (correctionTag.isElement()) + { + const QDomElement c = correctionTag.toElement(); + const QString hash = GetParametrString(c, AttrCoordinates); + const qreal correction = GetParametrDouble(c, AttrCorrection, QChar('0')); + + corrections.insert(hash, correction); + } + correctionTag = correctionTag.nextSibling(); + } + + return corrections; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurements::WriteCorrections(QDomElement &mElement, const QMap &corrections) +{ + QDomElement correctionsTag = mElement.firstChildElement(TagCorrections); + if (not corrections.isEmpty()) + { + if (not correctionsTag.isNull()) + { + RemoveAllChildren(correctionsTag); + } + else + { + correctionsTag = createElement(TagCorrections); + mElement.appendChild(correctionsTag); + } + + QMap::const_iterator i = corrections.constBegin(); + while (i != corrections.constEnd()) + { + QDomElement correctionTag = createElement(TagCorrection); + + SetAttribute(correctionTag, AttrCorrection, i.value()); + SetAttribute(correctionTag, AttrCoordinates, i.key()); + + correctionsTag.appendChild(correctionTag); + ++i; + } + } + else + { + if (not correctionsTag.isNull()) + { + mElement.removeChild(correctionsTag); + } + } +} diff --git a/src/libs/vformat/vmeasurements.h b/src/libs/vformat/vmeasurements.h index a3797a32a..d6ec2c641 100644 --- a/src/libs/vformat/vmeasurements.h +++ b/src/libs/vformat/vmeasurements.h @@ -67,7 +67,7 @@ public: void StoreNames(bool store); - void ReadMeasurements(qreal height, qreal size) const; + void ReadMeasurements(qreal baseA, qreal baseB=0, qreal baseC=0) const; void ClearForExport(); MeasurementsType Type() const; @@ -75,6 +75,10 @@ public: int DimensionBBase() const; int DimensionCBase() const; + int DimensionAStep() const; + int DimensionBStep() const; + int DimensionCStep() const; + QString Notes() const; void SetNotes(const QString &text); @@ -102,8 +106,11 @@ public: void SetMName(const QString &name, const QString &text); void SetMValue(const QString &name, const QString &text); void SetMBaseValue(const QString &name, double value); - void SetMSizeIncrease(const QString &name, double value); - void SetMHeightIncrease(const QString &name, double value); + void SetMShiftA(const QString &name, double value); + void SetMShiftB(const QString &name, double value); + void SetMShiftC(const QString &name, double value); + void SetMSpecialUnits(const QString &name, bool special); + void SetMCorrectionValue(const QString &name, qreal baseA, qreal baseB, qreal baseC, double value); void SetMDescription(const QString &name, const QString &text); void SetMFullName(const QString &name, const QString &text); @@ -127,11 +134,17 @@ public: static const QString TagDimensions; static const QString TagDimension; static const QString TagRestrictions; + static const QString TagCorrections; + static const QString TagCorrection; static const QString AttrBase; static const QString AttrValue; - static const QString AttrSizeIncrease; - static const QString AttrHeightIncrease; + static const QString AttrShiftA; + static const QString AttrShiftB; + static const QString AttrShiftC; + static const QString AttrCorrection; + static const QString AttrCoordinates; + static const QString AttrSpecialUnits; static const QString AttrDescription; static const QString AttrName; static const QString AttrFullName; @@ -187,6 +200,9 @@ private: qreal EvalFormula(VContainer *data, const QString &formula, bool *ok) const; QString ClearPMCode(const QString &code) const; + + QMap ReadCorrections(const QDomElement &mElement) const; + void WriteCorrections(QDomElement &mElement, const QMap &corrections); }; #endif // VMEASUREMENTS_H diff --git a/src/libs/vpatterndb/variables/vmeasurement.cpp b/src/libs/vpatterndb/variables/vmeasurement.cpp index fa9126cd6..51a714fac 100644 --- a/src/libs/vpatterndb/variables/vmeasurement.cpp +++ b/src/libs/vpatterndb/variables/vmeasurement.cpp @@ -40,36 +40,25 @@ /** * @brief VMeasurement create measurement for multisize table * @param name measurement's name - * @param base value in base size and height - * @param ksize increment in sizes - * @param kheight increment in heights - * @param gui_text shor tooltip for user - * @param description measurement full description - * @param tagName measurement's tag name in file + * @param base measurement's base value */ -VMeasurement::VMeasurement(quint32 index, const QString &name, qreal baseSize, qreal baseHeight, const qreal &base, - const qreal &ksize, const qreal &kheight, const QString &gui_text, - const QString &description, const QString &tagName) - :VVariable(name, description), - d(new VMeasurementData(index, gui_text, tagName, baseSize, baseHeight, base, ksize, kheight)) +VMeasurement::VMeasurement(quint32 index, const QString &name, qreal baseA, qreal baseB, qreal baseC, qreal base) + :VVariable(name), + d(new VMeasurementData(index, baseA, baseB, baseC, base)) { SetType(VarType::Measurement); - VInternalVariable::SetValue(d->base); + VInternalVariable::SetValue(d->shiftBase); } //--------------------------------------------------------------------------------------------------------------------- /** * @brief VMeasurement create measurement for individual table - * @param name measurement's name + * @param name measurement's base value * @param base value in base size and height - * @param gui_text shor tooltip for user - * @param description measurement full description - * @param tagName measurement's tag name in file */ VMeasurement::VMeasurement(VContainer *data, quint32 index, const QString &name, const qreal &base, - const QString &formula, bool ok, const QString &gui_text, const QString &description, - const QString &tagName) - :VVariable(name, description), d(new VMeasurementData(data, index, formula, ok, gui_text, tagName, base)) + const QString &formula, bool ok) + :VVariable(name), d(new VMeasurementData(data, index, formula, ok, base)) { SetType(VarType::Measurement); VInternalVariable::SetValue(base); @@ -231,27 +220,38 @@ bool VMeasurement::IsGradationHeightValid(const QString &height) } } +//--------------------------------------------------------------------------------------------------------------------- +QString VMeasurement::CorrectionHash(qreal baseA, qreal baseB, qreal baseC) +{ + return QStringList({QString::number(baseA), QString::number(baseB), QString::number(baseC)}).join(';'); +} + //--------------------------------------------------------------------------------------------------------------------- qreal VMeasurement::CalcValue() const { - if (d->currentUnit == nullptr || qFuzzyIsNull(d->currentSize) || qFuzzyIsNull(d->currentHeight)) + if (qFuzzyIsNull(d->currentBaseA)) { return VInternalVariable::GetValue(); } - if (*d->currentUnit == Unit::Inch) + // Formula for calculation gradation + const qreal kA = d->stepA > 0 ? (d->currentBaseA - d->baseA) / d->stepA : 0; + const qreal kB = d->stepB > 0 ? (d->currentBaseB - d->baseB) / d->stepB : 0; + const qreal kC = d->stepC > 0 ? (d->currentBaseC - d->baseC) / d->stepC : 0; + + return d->shiftBase + kA * d->shiftA + kB * d->shiftB + kC * d->shiftC + Correction(); +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VMeasurement::Correction() const +{ + const QString hash = CorrectionHash(d->currentBaseA, d->currentBaseB, d->currentBaseC); + if (d->corrections.contains(hash)) { - qWarning("Gradation doesn't support inches"); - return 0; + return d->corrections.value(hash); } - const qreal sizeIncrement = UnitConvertor(2.0, Unit::Cm, *d->currentUnit); - const qreal heightIncrement = UnitConvertor(6.0, Unit::Cm, *d->currentUnit); - - // Formula for calculation gradation - const qreal k_size = ( d->currentSize - d->baseSize ) / sizeIncrement; - const qreal k_height = ( d->currentHeight - d->baseHeight ) / heightIncrement; - return d->base + k_size * d->ksize + k_height * d->kheight; + return 0; } //--------------------------------------------------------------------------------------------------------------------- @@ -265,15 +265,9 @@ QString VMeasurement::GetGuiText() const } //--------------------------------------------------------------------------------------------------------------------- -QString VMeasurement::TagName() const +void VMeasurement::SetGuiText(const QString &guiText) { - return d->_tagName; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VMeasurement::setTagName(const QString &tagName) -{ - d->_tagName = tagName; + d->gui_text = guiText; } //--------------------------------------------------------------------------------------------------------------------- @@ -303,7 +297,7 @@ bool VMeasurement::IsFormulaOk() const //--------------------------------------------------------------------------------------------------------------------- bool VMeasurement::IsNotUsed() const { - return qFuzzyIsNull(d->base) && qFuzzyIsNull(d->ksize) && qFuzzyIsNull(d->kheight); + return qFuzzyIsNull(d->shiftBase) && qFuzzyIsNull(d->shiftB) && qFuzzyIsNull(d->shiftA); } //--------------------------------------------------------------------------------------------------------------------- @@ -326,21 +320,21 @@ VContainer *VMeasurement::GetData() } //--------------------------------------------------------------------------------------------------------------------- -void VMeasurement::SetSize(qreal size) +void VMeasurement::SetBaseA(qreal base) { - d->currentSize = size; + d->currentBaseA = base; } //--------------------------------------------------------------------------------------------------------------------- -void VMeasurement::SetHeight(qreal height) +void VMeasurement::SetBaseB(qreal base) { - d->currentHeight = height; + d->currentBaseB = base; } //--------------------------------------------------------------------------------------------------------------------- -void VMeasurement::SetUnit(const Unit *unit) +void VMeasurement::SetBaseC(qreal base) { - d->currentUnit = unit; + d->currentBaseC = base; } //--------------------------------------------------------------------------------------------------------------------- @@ -350,30 +344,13 @@ void VMeasurement::SetUnit(const Unit *unit) */ qreal VMeasurement::GetBase() const { - return d->base; + return d->shiftBase; } //--------------------------------------------------------------------------------------------------------------------- -void VMeasurement::SetBase(const qreal &value) +void VMeasurement::SetBase(qreal value) { - d->base = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetKsize return increment in sizes - * @return increment - */ -qreal VMeasurement::GetKsize() const -{ - return d->ksize; -} - -//--------------------------------------------------------------------------------------------------------------------- -// cppcheck-suppress unusedFunction -void VMeasurement::SetKsize(const qreal &value) -{ - d->ksize = value; + d->shiftBase = value; } //--------------------------------------------------------------------------------------------------------------------- @@ -381,14 +358,109 @@ void VMeasurement::SetKsize(const qreal &value) * @brief GetKheight return increment in heights * @return increment */ -qreal VMeasurement::GetKheight() const +qreal VMeasurement::GetShiftA() const { - return d->kheight; + return d->shiftA; } //--------------------------------------------------------------------------------------------------------------------- // cppcheck-suppress unusedFunction -void VMeasurement::SetKheight(const qreal &value) +void VMeasurement::SetShiftA(qreal value) { - d->kheight = value; + d->shiftA = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetKsize return increment in sizes + * @return increment + */ +qreal VMeasurement::GetShiftB() const +{ + return d->shiftB; +} + +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction +void VMeasurement::SetShiftB(qreal value) +{ + d->shiftB = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VMeasurement::GetShiftC() const +{ + return d->shiftC; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurement::SetShiftC(qreal value) +{ + d->shiftC = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VMeasurement::GetStepA() const +{ + return d->shiftA; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurement::SetStepA(qreal value) +{ + d->stepA = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VMeasurement::GetStepB() const +{ + return d->stepB; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurement::SetStepB(qreal value) +{ + d->stepB = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VMeasurement::GetStepC() const +{ + return d->stepC; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurement::SetStepC(qreal value) +{ + d->stepC = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VMeasurement::IsSpecialUnits() const +{ + return d->specialUnits; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurement::SetSpecialUnits(bool special) +{ + d->specialUnits = special; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VMeasurement::GetCorrection(int baseA, int baseB, int baseC) const +{ + return d->corrections.value(VMeasurement::CorrectionHash(baseA, baseB, baseC), 0); +} + +//--------------------------------------------------------------------------------------------------------------------- +QMap VMeasurement::GetCorrections() const +{ + return d->corrections; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurement::SetCorrections(const QMap &corrections) +{ + d->corrections = corrections; } diff --git a/src/libs/vpatterndb/variables/vmeasurement.h b/src/libs/vpatterndb/variables/vmeasurement.h index fe542ca71..badc40980 100644 --- a/src/libs/vpatterndb/variables/vmeasurement.h +++ b/src/libs/vpatterndb/variables/vmeasurement.h @@ -50,12 +50,9 @@ class VMeasurementData; class VMeasurement :public VVariable { public: - VMeasurement(quint32 index, const QString &name, qreal baseSize, qreal baseHeight, const qreal &base, - const qreal &ksize, const qreal &kheight, const QString &gui_text = QString(), - const QString &description = QString(), const QString &tagName = QString()); + VMeasurement(quint32 index, const QString &name, qreal baseA, qreal baseB, qreal baseC, qreal base); VMeasurement(VContainer *data, quint32 index, const QString &name, const qreal &base, const QString &formula, - bool ok, const QString &gui_text = QString(), const QString &description = QString(), - const QString &tagName = QString()); + bool ok); VMeasurement(const VMeasurement &m); virtual ~VMeasurement() override; @@ -67,9 +64,7 @@ public: #endif QString GetGuiText() const; - - QString TagName() const; - void setTagName(const QString &tagName); + void SetGuiText(const QString &guiText); QString GetFormula() const; @@ -85,19 +80,38 @@ public: VContainer *GetData(); - void SetSize(qreal size); - void SetHeight(qreal height); + void SetBaseA(qreal base); + void SetBaseB(qreal base); + void SetBaseC(qreal base); - void SetUnit(const Unit *unit); + qreal GetBase() const; + void SetBase(qreal value); - qreal GetBase() const; - void SetBase(const qreal &value); + qreal GetShiftA() const; + void SetShiftA(qreal value); - qreal GetKsize() const; - void SetKsize(const qreal &value); + qreal GetShiftB() const; + void SetShiftB(qreal value); - qreal GetKheight() const; - void SetKheight(const qreal &value); + qreal GetShiftC() const; + void SetShiftC(qreal value); + + qreal GetStepA() const; + void SetStepA(qreal value); + + qreal GetStepB() const; + void SetStepB(qreal value); + + qreal GetStepC() const; + void SetStepC(qreal value); + + bool IsSpecialUnits() const; + void SetSpecialUnits(bool special); + + qreal GetCorrection(int baseA, int baseB, int baseC) const; + + QMap GetCorrections() const; + void SetCorrections(const QMap &corrections); static QStringList ListHeights(const QMap &heights, Unit patternUnit); static QStringList ListSizes(const QMap &sizes, Unit patternUnit); @@ -105,10 +119,12 @@ public: static QStringList WholeListSizes(Unit patternUnit); static bool IsGradationSizeValid(const QString &size); static bool IsGradationHeightValid(const QString &height); + static QString CorrectionHash(qreal baseA, qreal baseB, qreal baseC); private: QSharedDataPointer d; qreal CalcValue() const; + qreal Correction() const; }; Q_DECLARE_TYPEINFO(VMeasurement, Q_MOVABLE_TYPE); diff --git a/src/libs/vpatterndb/variables/vmeasurement_p.h b/src/libs/vpatterndb/variables/vmeasurement_p.h index 9a7329fc2..30ffd828d 100644 --- a/src/libs/vpatterndb/variables/vmeasurement_p.h +++ b/src/libs/vpatterndb/variables/vmeasurement_p.h @@ -42,40 +42,20 @@ class VMeasurementData : public QSharedData { public: - VMeasurementData(quint32 index, const QString &gui_text, const QString &tagName, qreal baseSize, qreal baseHeight, - qreal base, qreal ksize, qreal kheight ) - : data(), - index(index), - formula(), - gui_text(gui_text), - _tagName(tagName), - formulaOk(true), - currentSize(0), - currentHeight(0), - currentUnit(nullptr), - base(base), - ksize(ksize), - kheight(kheight), - baseSize(baseSize), - baseHeight(baseHeight) + VMeasurementData(quint32 index, qreal baseA, qreal baseB, qreal baseC, qreal base) + : index(index), + shiftBase(base), + baseA(baseA), + baseB(baseB), + baseC(baseC) {} - VMeasurementData(VContainer *data, quint32 index, const QString &formula, bool ok, const QString &gui_text, - const QString &tagName, qreal base) + VMeasurementData(VContainer *data, quint32 index, const QString &formula, bool ok, qreal base) : data(QSharedPointer(new VContainer(*data))), index(index), formula(formula), - gui_text(gui_text), - _tagName(tagName), formulaOk(ok), - currentSize(0), - currentHeight(0), - currentUnit(nullptr), - base(base), - ksize(0), - kheight(0), - baseSize(0), - baseHeight(0) + shiftBase(base) {} VMeasurementData(const VMeasurementData &m) @@ -84,42 +64,53 @@ public: index(m.index), formula(m.formula), gui_text(m.gui_text), - _tagName(m._tagName), formulaOk(m.formulaOk), - currentSize(m.currentSize), - currentHeight(m.currentHeight), - currentUnit(m.currentUnit), - base(m.base), - ksize(m.ksize), - kheight(m.kheight), - baseSize(m.baseSize), - baseHeight(m.baseHeight) + currentBaseA(m.currentBaseA), + currentBaseB(m.currentBaseB), + currentBaseC(m.currentBaseC), + shiftBase(m.shiftBase), + shiftA(m.shiftA), + shiftB(m.shiftB), + shiftC(m.shiftC), + stepA(m.stepA), + stepB(m.stepB), + stepC(m.stepC), + baseA(m.baseA), + baseB(m.baseB), + baseC(m.baseC), + corrections(m.corrections), + specialUnits(m.specialUnits) {} virtual ~VMeasurementData(); - QSharedPointer data; + QSharedPointer data{}; quint32 index; - QString formula; - QString gui_text; - QString _tagName; - bool formulaOk; + QString formula{}; + QString gui_text{}; + bool formulaOk{true}; - qreal currentSize; - qreal currentHeight; - const Unit *currentUnit; + qreal currentBaseA{0}; + qreal currentBaseB{0}; + qreal currentBaseC{0}; - /** @brief base value in base size and height */ - qreal base; + qreal shiftBase{0}; - /** @brief ksize increment in sizes */ - qreal ksize; + qreal shiftA{0}; + qreal shiftB{0}; + qreal shiftC{0}; - /** @brief kgrowth increment in heights */ - qreal kheight; + qreal stepA{0}; + qreal stepB{0}; + qreal stepC{0}; - qreal baseSize; - qreal baseHeight; + qreal baseA{0}; + qreal baseB{0}; + qreal baseC{0}; + + QMap corrections{}; + + bool specialUnits{false}; private: Q_DISABLE_ASSIGN(VMeasurementData) diff --git a/src/libs/vpatterndb/variables/vvariable.h b/src/libs/vpatterndb/variables/vvariable.h index 759924be8..04d35d750 100644 --- a/src/libs/vpatterndb/variables/vvariable.h +++ b/src/libs/vpatterndb/variables/vvariable.h @@ -45,7 +45,7 @@ class VVariable :public VInternalVariable { public: VVariable(); - VVariable(const QString &name, const QString &description = QString()); + explicit VVariable(const QString &name, const QString &description = QString()); VVariable(const VVariable &var); virtual ~VVariable() override; From a8ddcc56cc9540a43e62a44223b8c4f298aa67d3 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 3 Oct 2020 17:21:17 +0300 Subject: [PATCH 13/44] Update individual measurements schema. Added special units attribute. --- src/libs/ifc/schema.qrc | 1 + .../schema/individual_measurements/v0.5.1.xsd | 73 +++++++++++++++++++ src/libs/ifc/xml/vvitconverter.cpp | 24 +++++- src/libs/ifc/xml/vvitconverter.h | 3 +- 4 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 src/libs/ifc/schema/individual_measurements/v0.5.1.xsd diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index c98ebbe84..a906c1e05 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -73,6 +73,7 @@ schema/individual_measurements/v0.3.3.xsd schema/individual_measurements/v0.4.0.xsd schema/individual_measurements/v0.5.0.xsd + schema/individual_measurements/v0.5.1.xsd schema/label_template/v1.0.0.xsd schema/watermark/v1.0.0.xsd diff --git a/src/libs/ifc/schema/individual_measurements/v0.5.1.xsd b/src/libs/ifc/schema/individual_measurements/v0.5.1.xsd new file mode 100644 index 000000000..80d99fcc9 --- /dev/null +++ b/src/libs/ifc/schema/individual_measurements/v0.5.1.xsd @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vvitconverter.cpp b/src/libs/ifc/xml/vvitconverter.cpp index a9e9c2bdd..c4da6193a 100644 --- a/src/libs/ifc/xml/vvitconverter.cpp +++ b/src/libs/ifc/xml/vvitconverter.cpp @@ -54,8 +54,8 @@ */ const QString VVITConverter::MeasurementMinVerStr = QStringLiteral("0.2.0"); -const QString VVITConverter::MeasurementMaxVerStr = QStringLiteral("0.5.0"); -const QString VVITConverter::CurrentSchema = QStringLiteral("://schema/individual_measurements/v0.5.0.xsd"); +const QString VVITConverter::MeasurementMaxVerStr = QStringLiteral("0.5.1"); +const QString VVITConverter::CurrentSchema = QStringLiteral("://schema/individual_measurements/v0.5.1.xsd"); //VVITConverter::MeasurementMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VVITConverter::MeasurementMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! @@ -89,7 +89,8 @@ QString VVITConverter::XSDSchema(int ver) const std::make_pair(FORMAT_VERSION(0, 3, 2), QStringLiteral("://schema/individual_measurements/v0.3.2.xsd")), std::make_pair(FORMAT_VERSION(0, 3, 3), QStringLiteral("://schema/individual_measurements/v0.3.3.xsd")), std::make_pair(FORMAT_VERSION(0, 4, 0), QStringLiteral("://schema/individual_measurements/v0.4.0.xsd")), - std::make_pair(FORMAT_VERSION(0, 5, 0), CurrentSchema), + std::make_pair(FORMAT_VERSION(0, 5, 0), QStringLiteral("://schema/individual_measurements/v0.5.0.xsd")), + std::make_pair(FORMAT_VERSION(0, 5, 1), CurrentSchema), }; if (schemas.contains(ver)) @@ -132,6 +133,10 @@ void VVITConverter::ApplyPatches() ValidateXML(XSDSchema(FORMAT_VERSION(0, 5, 0))); Q_FALLTHROUGH(); case (FORMAT_VERSION(0, 5, 0)): + ToV0_5_1(); + ValidateXML(XSDSchema(FORMAT_VERSION(0, 5, 1))); + Q_FALLTHROUGH(); + case (FORMAT_VERSION(0, 5, 1)): break; default: InvalidVersion(m_ver); @@ -150,7 +155,7 @@ void VVITConverter::DowngradeToCurrentMaxVersion() bool VVITConverter::IsReadOnly() const { // Check if attribute read-only was not changed in file format - Q_STATIC_ASSERT_X(VVITConverter::MeasurementMaxVer == FORMAT_VERSION(0, 5, 0), + Q_STATIC_ASSERT_X(VVITConverter::MeasurementMaxVer == FORMAT_VERSION(0, 5, 1), "Check attribute read-only."); // Possibly in future attribute read-only will change position etc. @@ -428,3 +433,14 @@ void VVITConverter::ToV0_5_0() SetVersion(QStringLiteral("0.5.0")); Save(); } + +//--------------------------------------------------------------------------------------------------------------------- +void VVITConverter::ToV0_5_1() +{ + // TODO. Delete if minimal supported version is 0.5.1 + Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < FORMAT_VERSION(0, 5, 1), + "Time to refactor the code."); + + SetVersion(QStringLiteral("0.5.1")); + Save(); +} diff --git a/src/libs/ifc/xml/vvitconverter.h b/src/libs/ifc/xml/vvitconverter.h index fa7a8bba0..aa7360f71 100644 --- a/src/libs/ifc/xml/vvitconverter.h +++ b/src/libs/ifc/xml/vvitconverter.h @@ -49,7 +49,7 @@ public: static const QString MeasurementMaxVerStr; static const QString CurrentSchema; static Q_DECL_CONSTEXPR const int MeasurementMinVer = FORMAT_VERSION(0, 2, 0); - static Q_DECL_CONSTEXPR const int MeasurementMaxVer = FORMAT_VERSION(0, 5, 0); + static Q_DECL_CONSTEXPR const int MeasurementMaxVer = FORMAT_VERSION(0, 5, 1); protected: virtual int MinVer() const override; @@ -82,6 +82,7 @@ private: void ToV0_3_3(); void ToV0_4_0(); void ToV0_5_0(); + void ToV0_5_1(); }; //--------------------------------------------------------------------------------------------------------------------- From ab5892d3ef8f72997d30d6ce2f0b752712862b95 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 3 Oct 2020 17:47:42 +0300 Subject: [PATCH 14/44] Show calculated value according to option Special units. --- src/app/tape/tmainwindow.cpp | 67 ++++++++++++++++++++++++++++-------- src/app/tape/tmainwindow.h | 2 +- 2 files changed, 53 insertions(+), 16 deletions(-) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 4a974957d..ae9862c6c 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -1630,10 +1630,21 @@ void TMainWindow::ShowNewMData(bool fresh) ui->doubleSpinBoxShiftB->blockSignals(true); ui->doubleSpinBoxShiftC->blockSignals(true); - const QString postfix = UnitsToStr(pUnit);//Show unit in dialog lable (cm, mm or inch) - const qreal value = UnitConvertor(*data->DataVariables()->value(meash->GetName())->GetValue(), mUnit, - pUnit); - ui->labelCalculatedValue->setText(qApp->LocaleToString(value) + QChar(QChar::Space) +postfix); + QString calculatedValue; + + if (meash->IsSpecialUnits()) + { + const QString postfix = UnitsToStr(pUnit);//Show unit in dialog lable (cm, mm or inch) + const qreal value = UnitConvertor(*data->DataVariables()->value(meash->GetName())->GetValue(), mUnit, + pUnit); + calculatedValue = qApp->LocaleToString(value) + QChar(QChar::Space) + postfix; + } + else + { + const qreal value = *data->DataVariables()->value(meash->GetName())->GetValue(); + calculatedValue = qApp->LocaleToString(value) + QChar(QChar::Space) + degreeSymbol; + } + ui->labelCalculatedValue->setText(calculatedValue); if (fresh) { @@ -1654,7 +1665,8 @@ void TMainWindow::ShowNewMData(bool fresh) } else { - EvalFormula(meash->GetFormula(), false, meash->GetData(), ui->labelCalculatedValue); + EvalFormula(meash->GetFormula(), false, meash->GetData(), ui->labelCalculatedValue, + meash->IsSpecialUnits()); ui->plainTextEditFormula->blockSignals(true); @@ -1833,7 +1845,7 @@ void TMainWindow::SaveMValue() return; } - if (not EvalFormula(text, true, meash->GetData(), ui->labelCalculatedValue)) + if (not EvalFormula(text, true, meash->GetData(), ui->labelCalculatedValue, meash->IsSpecialUnits())) { return; } @@ -2750,7 +2762,7 @@ void TMainWindow::RefreshData(bool freshCall) { data->ClearUniqueNames(); data->ClearVariables(VarType::Measurement); - m->ReadMeasurements(currentDimensionA, currentDimensionB); + m->ReadMeasurements(currentDimensionA, currentDimensionB, currentDimensionC); RefreshTable(freshCall); } @@ -2795,8 +2807,17 @@ void TMainWindow::RefreshTable(bool freshCall) AddCell(qApp->TrVars()->GuiText(meash->GetName()), currentRow, ColumnFullName, Qt::AlignVCenter); } - const qreal value = UnitConvertor(*meash->GetValue(), mUnit, pUnit); - AddCell(locale().toString(value), currentRow, ColumnCalcValue, Qt::AlignHCenter | Qt::AlignVCenter, + QString calculatedValue; + if (meash->IsSpecialUnits()) + { + calculatedValue = locale().toString(*meash->GetValue()) + degreeSymbol; + } + else + { + calculatedValue = locale().toString(UnitConvertor(*meash->GetValue(), mUnit, pUnit)); + } + + AddCell(calculatedValue, currentRow, ColumnCalcValue, Qt::AlignHCenter | Qt::AlignVCenter, meash->IsFormulaOk()); // calculated value QString formula = VTranslateVars::TryFormulaToUser(meash->GetFormula(), qApp->Settings()->GetOsSeparator()); @@ -2818,9 +2839,20 @@ void TMainWindow::RefreshTable(bool freshCall) AddCell(qApp->TrVars()->GuiText(meash->GetName()), currentRow, ColumnFullName, Qt::AlignVCenter); } - const qreal value = UnitConvertor(*data->DataVariables()->value(meash->GetName())->GetValue(), mUnit, - pUnit); - AddCell(locale().toString(value), currentRow, ColumnCalcValue, + QString calculatedValue; + if (meash->IsSpecialUnits()) + { + const qreal value = *data->DataVariables()->value(meash->GetName())->GetValue(); + calculatedValue = locale().toString(value) + degreeSymbol; + } + else + { + const qreal value = UnitConvertor(*data->DataVariables()->value(meash->GetName())->GetValue(), mUnit, + pUnit); + calculatedValue = locale().toString(value); + } + + AddCell(calculatedValue, currentRow, ColumnCalcValue, Qt::AlignHCenter | Qt::AlignVCenter, meash->IsFormulaOk()); // calculated value AddCell(locale().toString(meash->GetBase()), currentRow, ColumnBaseValue, @@ -3012,9 +3044,11 @@ QString TMainWindow::ClearCustomName(const QString &name) const } //--------------------------------------------------------------------------------------------------------------------- -bool TMainWindow::EvalFormula(const QString &formula, bool fromUser, VContainer *data, QLabel *label) +bool TMainWindow::EvalFormula(const QString &formula, bool fromUser, VContainer *data, QLabel *label, + bool specialUnits) { - const QString postfix = UnitsToStr(pUnit);//Show unit in dialog lable (cm, mm or inch) + const QString postfix = specialUnits ? degreeSymbol : UnitsToStr(pUnit); + if (formula.isEmpty()) { label->setText(tr("Error") + QStringLiteral(" (") + postfix + QStringLiteral("). ") + tr("Empty field.")); @@ -3044,7 +3078,10 @@ bool TMainWindow::EvalFormula(const QString &formula, bool fromUser, VContainer return false; } - result = UnitConvertor(result, mUnit, pUnit); + if (not specialUnits) + { + result = UnitConvertor(result, mUnit, pUnit); + } label->setText(qApp->LocaleToString(result) + QChar(QChar::Space) +postfix); label->setToolTip(tr("Value")); diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index 79b9406a5..ef81284cc 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -198,7 +198,7 @@ private: QString GetCustomName() const; QString ClearCustomName(const QString &name) const; - bool EvalFormula(const QString &formula, bool fromUser, VContainer *data, QLabel *label); + bool EvalFormula(const QString &formula, bool fromUser, VContainer *data, QLabel *label, bool specialUnits); void ShowMDiagram(const QString &name); void Open(const QString &pathTo, const QString &filter); From 31c0a523e4dfb54a7f1446abbbc178e3677b452a Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 3 Oct 2020 18:45:21 +0300 Subject: [PATCH 15/44] Block signals when set a measurement units. --- src/app/tape/tmainwindow.cpp | 39 +++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index ae9862c6c..9834a4715 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -1618,8 +1618,10 @@ void TMainWindow::ShowNewMData(bool fresh) connect(ui->lineEditName, &QLineEdit::textEdited, this, &TMainWindow::SaveMName); ui->plainTextEditDescription->blockSignals(false); + ui->comboBoxMUnits->blockSignals(true); ui->comboBoxMUnits->setCurrentIndex( ui->comboBoxMUnits->findData(static_cast(meash->IsSpecialUnits() ? MUnits::Degrees : MUnits::Table))); + ui->comboBoxMUnits->blockSignals(false); if (mType == MeasurementsType::Multisize) { @@ -1633,17 +1635,17 @@ void TMainWindow::ShowNewMData(bool fresh) QString calculatedValue; if (meash->IsSpecialUnits()) + { + const qreal value = *data->DataVariables()->value(meash->GetName())->GetValue(); + calculatedValue = qApp->LocaleToString(value) + QChar(QChar::Space) + degreeSymbol; + } + else { const QString postfix = UnitsToStr(pUnit);//Show unit in dialog lable (cm, mm or inch) const qreal value = UnitConvertor(*data->DataVariables()->value(meash->GetName())->GetValue(), mUnit, pUnit); calculatedValue = qApp->LocaleToString(value) + QChar(QChar::Space) + postfix; } - else - { - const qreal value = *data->DataVariables()->value(meash->GetName())->GetValue(); - calculatedValue = qApp->LocaleToString(value) + QChar(QChar::Space) + degreeSymbol; - } ui->labelCalculatedValue->setText(calculatedValue); if (fresh) @@ -2245,7 +2247,6 @@ void TMainWindow::InitWindow() SetDimensionBases(); InitDimesionShifts(); - HackDimensionShifts(); connect(ui->doubleSpinBoxBaseValue, QOverload::of(&QDoubleSpinBox::valueChanged), this, &TMainWindow::SaveMBaseValue); @@ -2259,6 +2260,8 @@ void TMainWindow::InitWindow() connect(ui->doubleSpinBoxShiftC, QOverload::of(&QDoubleSpinBox::valueChanged), this, &TMainWindow::SaveMShiftC); + HackDimensionShifts(); + SetDecimals(); } else @@ -3457,7 +3460,7 @@ void TMainWindow::HackDimensionShifts() { const QList dimensions = m->Dimensions().values(); - auto HackShift = [this, dimensions](int index, QLabel *name, QDoubleSpinBox *shift) + auto HackShift = [this, dimensions](int index, QLabel *&name, QDoubleSpinBox *&shift) { SCASSERT(name != nullptr) SCASSERT(shift != nullptr) @@ -3470,8 +3473,8 @@ void TMainWindow::HackDimensionShifts() }; HackShift(0, ui->labelShiftA, ui->doubleSpinBoxShiftA); - HackShift(0, ui->labelShiftB, ui->doubleSpinBoxShiftB); - HackShift(0, ui->labelShiftC, ui->doubleSpinBoxShiftC); + HackShift(1, ui->labelShiftB, ui->doubleSpinBoxShiftB); + HackShift(2, ui->labelShiftC, ui->doubleSpinBoxShiftC); } //--------------------------------------------------------------------------------------------------------------------- @@ -3840,6 +3843,24 @@ void TMainWindow::SetDimensionBases() { const QList dimensions = m->Dimensions().values(); + if (dimensions.size() > 0) + { + MeasurementDimension_p dimension = dimensions.at(0); + currentDimensionA = dimension->BaseValue(); + } + + if (dimensions.size() > 1) + { + MeasurementDimension_p dimension = dimensions.at(1); + currentDimensionB = dimension->BaseValue(); + } + + if (dimensions.size() > 2) + { + MeasurementDimension_p dimension = dimensions.at(2); + currentDimensionC = dimension->BaseValue(); + } + auto SetBase = [dimensions](int index, QComboBox *control, int &value) { if (dimensions.size() > index) From eef01f1d3e70c31eea6f06853e8bb882433b02e8 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 3 Oct 2020 18:46:20 +0300 Subject: [PATCH 16/44] Add changes to the multisize measurements schema. --- .../schema/standard_measurements/v0.5.0.xsd | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) 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 c7981e296..1e8e44c81 100644 --- a/src/libs/ifc/schema/standard_measurements/v0.5.0.xsd +++ b/src/libs/ifc/schema/standard_measurements/v0.5.0.xsd @@ -32,12 +32,28 @@ + + + + + + + + + + + + + + - - + + + + @@ -92,5 +108,4 @@ - From a083d2ff186f043ddbe8abb33e5aa1caf619f1ce Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 3 Oct 2020 18:52:10 +0300 Subject: [PATCH 17/44] Hash must contains only active dimensions. --- src/libs/vpatterndb/variables/vmeasurement.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libs/vpatterndb/variables/vmeasurement.cpp b/src/libs/vpatterndb/variables/vmeasurement.cpp index 51a714fac..a60e0a78a 100644 --- a/src/libs/vpatterndb/variables/vmeasurement.cpp +++ b/src/libs/vpatterndb/variables/vmeasurement.cpp @@ -223,7 +223,18 @@ bool VMeasurement::IsGradationHeightValid(const QString &height) //--------------------------------------------------------------------------------------------------------------------- QString VMeasurement::CorrectionHash(qreal baseA, qreal baseB, qreal baseC) { - return QStringList({QString::number(baseA), QString::number(baseB), QString::number(baseC)}).join(';'); + QStringList hashBlocks{QString::number(baseA)}; + + if (baseB > 0) + { + hashBlocks.append(QString::number(baseB)); + } + + if (baseC > 0) + { + hashBlocks.append(QString::number(baseC)); + } + return hashBlocks.join(';'); } //--------------------------------------------------------------------------------------------------------------------- From cfe46d97e4161819fc43d13712dd0d12b37d7a38 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 5 Oct 2020 10:13:44 +0300 Subject: [PATCH 18/44] Fix calculation a dimension step. Value for millimeters is to small. --- src/libs/vformat/vdimensions.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/libs/vformat/vdimensions.cpp b/src/libs/vformat/vdimensions.cpp index 68cf958fd..c5cd70ce5 100644 --- a/src/libs/vformat/vdimensions.cpp +++ b/src/libs/vformat/vdimensions.cpp @@ -62,19 +62,13 @@ QVector VAbstartMeasurementDimension::ValidSteps() const } else if (diff > 0) { - steps.append(1); - - auto AddStep = [&steps, diff](int step) + for (int i=1; i < 9; ++i) { + const int step = (m_units == Unit::Mm ? i * 10 : i); if (diff % step == 0) { steps.append(step); } - }; - - for (int i=2; i < 9; ++i) - { - AddStep(i); } } From 214170a9b253ba46247581f6fdd4b82c334b0b63 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 5 Oct 2020 10:14:31 +0300 Subject: [PATCH 19/44] Height is not a circumference, but still a distance. --- src/app/tape/dialogs/dialogsetupmultisize.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/app/tape/dialogs/dialogsetupmultisize.cpp b/src/app/tape/dialogs/dialogsetupmultisize.cpp index 4d22fcf7e..b68463284 100644 --- a/src/app/tape/dialogs/dialogsetupmultisize.cpp +++ b/src/app/tape/dialogs/dialogsetupmultisize.cpp @@ -365,7 +365,7 @@ void DialogSetupMultisize::InitDimensionMinMax(QSpinBox *spinboxMinValue, QSpinB spinboxMinValue->blockSignals(true); const QString unitStr = " " + UnitsToStr(dimension->Units()); - if (c) + if (c || dimension->Type() == MeasurementDimension::X) { spinboxMinValue->setSuffix(unitStr); } @@ -376,7 +376,7 @@ void DialogSetupMultisize::InitDimensionMinMax(QSpinBox *spinboxMinValue, QSpinB spinboxMinValue->blockSignals(false); spinboxMaxValue->blockSignals(true); - if (c) + if (c || dimension->Type() == MeasurementDimension::X) { spinboxMaxValue->setSuffix(unitStr); } @@ -405,7 +405,7 @@ void DialogSetupMultisize::InitDimensionStep(QComboBox *comboBoxStep, for(auto step : steps) { comboBoxStep->addItem(QString("%1%2").arg(c && fc ? step*2 : step) - .arg(c ? unitStr : QString()), step); + .arg(c || dimension->Type() == MeasurementDimension::X ? unitStr : QString()), step); } comboBoxStep->setCurrentIndex(-1); // force a user to select @@ -590,7 +590,8 @@ void DialogSetupMultisize::UpdateBase(QComboBox *comboBoxBase, for(auto base : bases) { - comboBoxBase->addItem(QString("%1%2").arg(c && fc ? base * 2 : base).arg(c ? unitStr : QString()), base); + comboBoxBase->addItem(QString("%1%2").arg(c && fc ? base * 2 : base) + .arg(c || dimension->Type() == MeasurementDimension::X ? unitStr : QString()), base); } comboBoxBase->setCurrentIndex(comboBoxBase->findData(oldBase)); From 7c66482b67d01b874a0c5dda52a23e53cbff904c Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 5 Oct 2020 10:17:39 +0300 Subject: [PATCH 20/44] Conversion multisize measurements to version 0.5.0. --- .../schema/standard_measurements/v0.5.0.xsd | 2 +- src/libs/ifc/xml/vvstconverter.cpp | 109 ++++++++++++++++++ src/libs/ifc/xml/vvstconverter.h | 4 + 3 files changed, 114 insertions(+), 1 deletion(-) 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 1e8e44c81..8d06f3cdd 100644 --- a/src/libs/ifc/schema/standard_measurements/v0.5.0.xsd +++ b/src/libs/ifc/schema/standard_measurements/v0.5.0.xsd @@ -105,7 +105,7 @@ - + diff --git a/src/libs/ifc/xml/vvstconverter.cpp b/src/libs/ifc/xml/vvstconverter.cpp index 4de64c117..2ca06eec5 100644 --- a/src/libs/ifc/xml/vvstconverter.cpp +++ b/src/libs/ifc/xml/vvstconverter.cpp @@ -312,6 +312,112 @@ void VVSTConverter::ConvertMeasurementsToV0_4_2() } } +//--------------------------------------------------------------------------------------------------------------------- +void VVSTConverter::AddNewTagsForV0_5_0() +{ + // TODO. Delete if minimal supported version is 0.5.0 + Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < FORMAT_VERSION(0, 5, 0), + "Time to refactor the code."); + + QDomElement root = documentElement(); + const QDomElement pmSystemTag = root.firstChildElement(QStringLiteral("pm_system")); + if (pmSystemTag.isNull()) + { + return; + } + + QDomElement dimensionsTag = createElement(QStringLiteral("dimensions")); + + auto Base = [this](const QString &base) + { + const QDomElement root = documentElement(); + const QDomElement baseTag = root.firstChildElement(base); + if (baseTag.isNull()) + { + return 0; + } + + return GetParametrInt(baseTag, QStringLiteral("base"), QChar('0')); + }; + + const Unit units = MUnit(); + + { + const int step = static_cast(UnitConvertor(6, Unit::Cm, units)); + const int min = static_cast(UnitConvertor(50, Unit::Cm, units)); + const int max = static_cast(UnitConvertor(200, Unit::Cm, units)); + + QDomElement dimensionX = createElement(QStringLiteral("dimension")); + SetAttribute(dimensionX, QStringLiteral("type"), QChar('x')); + SetAttribute(dimensionX, QStringLiteral("step"), step); + SetAttribute(dimensionX, QStringLiteral("min"), min); + SetAttribute(dimensionX, QStringLiteral("max"), max); + SetAttribute(dimensionX, QStringLiteral("base"), Base(QStringLiteral("height"))); + dimensionsTag.appendChild(dimensionX); + } + + { + const int step = static_cast(UnitConvertor(2, Unit::Cm, units)); + const int min = static_cast(UnitConvertor(22, Unit::Cm, units)); + const int max = static_cast(UnitConvertor(72, Unit::Cm, units)); + + QDomElement dimensionY = createElement(QStringLiteral("dimension")); + SetAttribute(dimensionY, QStringLiteral("type"), QChar('y')); + SetAttribute(dimensionY, QStringLiteral("step"), step); + SetAttribute(dimensionY, QStringLiteral("min"), min); + SetAttribute(dimensionY, QStringLiteral("max"), max); + SetAttribute(dimensionY, QStringLiteral("base"), Base(QStringLiteral("size"))); + SetAttribute(dimensionY, QStringLiteral("circumference"), true); + dimensionsTag.appendChild(dimensionY); + } + + root.insertAfter(dimensionsTag, pmSystemTag); + + root.insertAfter(createElement(QStringLiteral("restrictions")), dimensionsTag); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VVSTConverter::RemoveTagsForV0_5_0() +{ + // TODO. Delete if minimal supported version is 0.5.0 + Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < FORMAT_VERSION(0, 5, 0), + "Time to refactor the code."); + + QDomElement root = documentElement(); + + const QDomElement sizeTag = root.firstChildElement(QStringLiteral("size")); + if (not sizeTag.isNull()) + { + root.removeChild(sizeTag); + } + + const QDomElement heightTag = root.firstChildElement(QStringLiteral("height")); + if (not heightTag.isNull()) + { + root.removeChild(heightTag); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VVSTConverter::ConvertMeasurementsToV0_5_0() +{ + // TODO. Delete if minimal supported version is 0.5.0 + Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < FORMAT_VERSION(0, 5, 0), + "Time to refactor the code."); + + const QDomNodeList measurements = elementsByTagName(QStringLiteral("m")); + for (int i = 0; i < measurements.size(); ++i) + { + QDomElement m = measurements.at(i).toElement(); + + SetAttribute(m, QStringLiteral("shiftA"), GetParametrString(m, QStringLiteral("height_increase"))); + m.removeAttribute(QStringLiteral("height_increase")); + + SetAttribute(m, QStringLiteral("shiftB"), GetParametrString(m, QStringLiteral("size_increase"))); + m.removeAttribute(QStringLiteral("size_increase")); + } +} + //--------------------------------------------------------------------------------------------------------------------- void VVSTConverter::ToV0_4_0() { @@ -381,5 +487,8 @@ void VVSTConverter::ToV0_5_0() "Time to refactor the code."); SetVersion(QStringLiteral("0.5.0")); + AddNewTagsForV0_5_0(); + RemoveTagsForV0_5_0(); + ConvertMeasurementsToV0_5_0(); Save(); } diff --git a/src/libs/ifc/xml/vvstconverter.h b/src/libs/ifc/xml/vvstconverter.h index 907b4d421..869679bca 100644 --- a/src/libs/ifc/xml/vvstconverter.h +++ b/src/libs/ifc/xml/vvstconverter.h @@ -80,6 +80,10 @@ private: void PM_SystemV0_4_1(); void ConvertMeasurementsToV0_4_2(); + void AddNewTagsForV0_5_0(); + void RemoveTagsForV0_5_0(); + void ConvertMeasurementsToV0_5_0(); + void ToV0_4_0(); void ToV0_4_1(); void ToV0_4_2(); From f96fd45a90eab119522ef324a76840c35e769ad7 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 5 Oct 2020 11:45:16 +0300 Subject: [PATCH 21/44] New feature Export to individual measurements. --- src/app/tape/tmainwindow.cpp | 108 ++++++++++++++++++++++++++--- src/app/tape/tmainwindow.h | 5 ++ src/app/tape/tmainwindow.ui | 21 ++++++ src/libs/vformat/vmeasurements.cpp | 2 +- 4 files changed, 126 insertions(+), 10 deletions(-) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 9834a4715..50ee030f2 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -2110,6 +2110,85 @@ void TMainWindow::FullCircumferenceChanged(bool checked) InitDimensionControls(); } +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::ExportToIndividual() +{ + QString dir; + if (curFile.isEmpty()) + { + dir = qApp->TapeSettings()->GetPathIndividualMeasurements(); + } + else + { + dir = QFileInfo(curFile).absolutePath(); + } + + bool usedNotExistedDir = false; + QDir directory(dir); + if (not directory.exists()) + { + usedNotExistedDir = directory.mkpath(QChar('.')); + } + + QString filters = tr("Individual measurements") + QStringLiteral(" (*.vit)"); + QString fName = tr("measurements.vit"); + QString fileName = QFileDialog::getSaveFileName(this, tr("Export to individual"), dir + QChar('/') + fName, + filters); + + auto RemoveTempDir = qScopeGuard([usedNotExistedDir, dir]() + { + if (usedNotExistedDir) + { + QDir(dir).rmpath(QChar('.')); + } + }); + + if (fileName.isEmpty()) + { + return; + } + + QString suffix = QStringLiteral("vit"); + QFileInfo f( fileName ); + if (f.suffix().isEmpty() && f.suffix() != suffix) + { + fileName += QChar('.') + suffix; + } + + QScopedPointer tmpData(new VContainer(qApp->TrVars(), &mUnit, VContainer::UniqueNamespace())); + + VMeasurements individualMeasurements(mUnit, tmpData.data()); + + const QMap > orderedTable = OrderedMeasurments(); + QMap >::const_iterator iMap; + for (iMap = orderedTable.constBegin(); iMap != orderedTable.constEnd(); ++iMap) + { + const QSharedPointer &meash = iMap.value(); + individualMeasurements.AddEmpty(meash->GetName()); + individualMeasurements.SetMValue(meash->GetName(), QString::number(*meash->GetValue())); + individualMeasurements.SetMSpecialUnits(meash->GetName(), meash->IsSpecialUnits()); + if (meash->IsCustom()) + { + individualMeasurements.SetMDescription(meash->GetName(), meash->GetDescription()); + individualMeasurements.SetMFullName(meash->GetName(), meash->GetGuiText()); + } + } + + QString error; + const bool result = individualMeasurements.SaveDocument(fileName, error); + if (not result) + { + QMessageBox messageBox; + messageBox.setIcon(QMessageBox::Warning); + messageBox.setInformativeText(tr("Could not save the file")); + messageBox.setDefaultButton(QMessageBox::Ok); + messageBox.setDetailedText(error); + messageBox.setStandardButtons(QMessageBox::Ok); + messageBox.exec(); + return; + } +} + //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::SetupMenu() { @@ -2387,6 +2466,10 @@ void TMainWindow::InitMenu() actionFullCircumference->setChecked(m->IsFullCircumference()); ui->menuMeasurements->addAction(actionFullCircumference); connect(actionFullCircumference, &QAction::triggered, this, &TMainWindow::FullCircumferenceChanged); + + ui->actionExportToIndividual->setVisible(true); + ui->actionExportToIndividual->setEnabled(true); + connect(ui->actionExportToIndividual, &QAction::triggered, this, &TMainWindow::ExportToIndividual); } } @@ -2778,15 +2861,7 @@ void TMainWindow::RefreshTable(bool freshCall) ShowUnits(); - const QMap > table = data->DataMeasurements(); - QMap > orderedTable; - QMap >::const_iterator iterMap; - for (iterMap = table.constBegin(); iterMap != table.constEnd(); ++iterMap) - { - const QSharedPointer &meash = iterMap.value(); - orderedTable.insert(meash->Index(), meash); - } - + const QMap > orderedTable = OrderedMeasurments(); qint32 currentRow = -1; QMap >::const_iterator iMap; ui->tableWidget->setRowCount ( orderedTable.size() ); @@ -3981,6 +4056,21 @@ QVector TMainWindow::DimensionRestrictedValues(int index, const Measurement return QVector(); } +//--------------------------------------------------------------------------------------------------------------------- +QMap > TMainWindow::OrderedMeasurments() const +{ + const QMap > table = data->DataMeasurements(); + QMap > orderedTable; + QMap >::const_iterator iterMap; + for (iterMap = table.constBegin(); iterMap != table.constEnd(); ++iterMap) + { + const QSharedPointer &meash = iterMap.value(); + orderedTable.insert(meash->Index(), meash); + } + + return orderedTable; +} + //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::SetDecimals() { diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index ef81284cc..c7b26a8ad 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -44,6 +44,7 @@ namespace Ui class QLabel; class QxtCsvModel; +class VMeasurement; class TMainWindow : public VAbstractMainWindow { @@ -136,6 +137,8 @@ private slots: void FullCircumferenceChanged(bool checked); + void ExportToIndividual(); + private: Q_DISABLE_COPY(TMainWindow) Ui::TMainWindow *ui; @@ -243,6 +246,8 @@ private: void SetCurrentDimensionValues(); QVector DimensionRestrictedValues(int index, const MeasurementDimension_p &dimension); + + QMap > OrderedMeasurments() const; }; #endif // TMAINWINDOW_H diff --git a/src/app/tape/tmainwindow.ui b/src/app/tape/tmainwindow.ui index e5ce51c77..5fee81df1 100644 --- a/src/app/tape/tmainwindow.ui +++ b/src/app/tape/tmainwindow.ui @@ -963,6 +963,7 @@ + @@ -1332,6 +1333,26 @@ QAction::NoRole + + + false + + + false + + + Export to individual + + + Export to individual measurements + + + false + + + QAction::NoRole + + diff --git a/src/libs/vformat/vmeasurements.cpp b/src/libs/vformat/vmeasurements.cpp index 8a8916a1a..033f3ef63 100644 --- a/src/libs/vformat/vmeasurements.cpp +++ b/src/libs/vformat/vmeasurements.cpp @@ -132,7 +132,7 @@ VMeasurements::VMeasurements(Unit unit, VContainer *data) { SCASSERT(data != nullptr) - CreateEmptyIndividualFile(unit); + CreateEmptyIndividualFile(unit); } //--------------------------------------------------------------------------------------------------------------------- From 0668a99cb5884f04bbfcecc868c3c8bc0e72c515 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 5 Oct 2020 11:58:03 +0300 Subject: [PATCH 22/44] Redesign a way we define the action. --- src/app/tape/tmainwindow.cpp | 17 +++++++++-------- src/app/tape/tmainwindow.h | 1 - src/app/tape/tmainwindow.ui | 12 ++++++++++++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 50ee030f2..389c0f12c 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -601,8 +601,6 @@ void TMainWindow::changeEvent(QEvent *event) if (mType == MeasurementsType::Multisize) { - actionFullCircumference->setText(tr("Use full circumference")); - ui->labelMType->setText(tr("Multisize measurements")); InitDimensionsBaseValue(); @@ -2459,14 +2457,17 @@ void TMainWindow::InitMenu() { if (mType == MeasurementsType::Multisize) { - ui->menuMeasurements->addSeparator(); + // Measurements + ui->actionUseFullCircumference->setVisible(true); + ui->actionUseFullCircumference->setEnabled(true); + ui->actionUseFullCircumference->setChecked(m->IsFullCircumference()); + connect(ui->actionUseFullCircumference, &QAction::triggered, this, &TMainWindow::FullCircumferenceChanged); - actionFullCircumference = new QAction(tr("Use full circumference"), this); - actionFullCircumference->setCheckable(true); - actionFullCircumference->setChecked(m->IsFullCircumference()); - ui->menuMeasurements->addAction(actionFullCircumference); - connect(actionFullCircumference, &QAction::triggered, this, &TMainWindow::FullCircumferenceChanged); + QAction *separator = new QAction(this); + separator->setSeparator(true); + ui->menuMeasurements->insertAction(ui->actionUseFullCircumference, separator); + // File ui->actionExportToIndividual->setVisible(true); ui->actionExportToIndividual->setEnabled(true); connect(ui->actionExportToIndividual, &QAction::triggered, this, &TMainWindow::ExportToIndividual); diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index c7b26a8ad..853708972 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -164,7 +164,6 @@ private: QLabel *labelPatternUnit{nullptr}; bool isInitialized{false}; bool mIsReadOnly{false}; - QAction *actionFullCircumference{nullptr}; QTimer *gradation; QVector hackedWidgets{}; diff --git a/src/app/tape/tmainwindow.ui b/src/app/tape/tmainwindow.ui index 5fee81df1..37c218def 100644 --- a/src/app/tape/tmainwindow.ui +++ b/src/app/tape/tmainwindow.ui @@ -992,6 +992,7 @@ + @@ -1353,6 +1354,17 @@ QAction::NoRole + + + true + + + Use full circumference + + + false + + From df2f2f7f832438068e253c30a30ec281a1c2fb98 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 5 Oct 2020 15:14:38 +0300 Subject: [PATCH 23/44] Dialog Restrict dimension. --- .../tape/dialogs/dialogrestrictdimension.cpp | 50 +++++ .../tape/dialogs/dialogrestrictdimension.h | 69 ++++++ .../tape/dialogs/dialogrestrictdimension.ui | 211 ++++++++++++++++++ src/app/tape/tape.pri | 3 + src/app/tape/tmainwindow.cpp | 69 +++++- src/app/tape/tmainwindow.h | 3 + src/app/tape/tmainwindow.ui | 24 ++ src/libs/vformat/vmeasurements.cpp | 52 ++++- src/libs/vformat/vmeasurements.h | 7 +- 9 files changed, 477 insertions(+), 11 deletions(-) create mode 100644 src/app/tape/dialogs/dialogrestrictdimension.cpp create mode 100644 src/app/tape/dialogs/dialogrestrictdimension.h create mode 100644 src/app/tape/dialogs/dialogrestrictdimension.ui diff --git a/src/app/tape/dialogs/dialogrestrictdimension.cpp b/src/app/tape/dialogs/dialogrestrictdimension.cpp new file mode 100644 index 000000000..90004601c --- /dev/null +++ b/src/app/tape/dialogs/dialogrestrictdimension.cpp @@ -0,0 +1,50 @@ +/************************************************************************ + ** + ** @file dialogrestrictdimension.cpp + ** @author Roman Telezhynskyi + ** @date 5 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 "dialogrestrictdimension.h" +#include "ui_dialogrestrictdimension.h" + +//--------------------------------------------------------------------------------------------------------------------- +DialogRestrictDimension::DialogRestrictDimension(const QList &dimensions, + const QMap> &restrictions, + bool oneDimesionRestriction, bool fullCircumference, + QWidget *parent) : + QDialog(parent), + ui(new Ui::DialogRestrictDimension), + m_oneDimesionRestriction(oneDimesionRestriction), + m_fullCircumference(fullCircumference), + m_dimensions(dimensions), + m_restrictions(restrictions) +{ + ui->setupUi(this); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogRestrictDimension::~DialogRestrictDimension() +{ + delete ui; +} diff --git a/src/app/tape/dialogs/dialogrestrictdimension.h b/src/app/tape/dialogs/dialogrestrictdimension.h new file mode 100644 index 000000000..58d2aca6a --- /dev/null +++ b/src/app/tape/dialogs/dialogrestrictdimension.h @@ -0,0 +1,69 @@ +/************************************************************************ + ** + ** @file dialogrestrictdimension.h + ** @author Roman Telezhynskyi + ** @date 5 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 DIALOGRESTRICTDIMENSION_H +#define DIALOGRESTRICTDIMENSION_H + +#include +#include + +#include "../vformat/vdimensions.h" + +namespace Ui +{ + class DialogRestrictDimension; +} + +class DialogRestrictDimension : public QDialog +{ + Q_OBJECT + +public: + DialogRestrictDimension(const QList &dimensions, + const QMap> &restrictions, bool oneDimesionRestriction, + bool fullCircumference, QWidget *parent = nullptr); + virtual ~DialogRestrictDimension(); + + QMap > Restrictions() const; + +private: + Q_DISABLE_COPY(DialogRestrictDimension) + Ui::DialogRestrictDimension *ui; + + bool m_oneDimesionRestriction; + bool m_fullCircumference; + QList m_dimensions; + QMap> m_restrictions; +}; + +//--------------------------------------------------------------------------------------------------------------------- +inline QMap > DialogRestrictDimension::Restrictions() const +{ + return m_restrictions; +} + +#endif // DIALOGRESTRICTDIMENSION_H diff --git a/src/app/tape/dialogs/dialogrestrictdimension.ui b/src/app/tape/dialogs/dialogrestrictdimension.ui new file mode 100644 index 000000000..918dd785f --- /dev/null +++ b/src/app/tape/dialogs/dialogrestrictdimension.ui @@ -0,0 +1,211 @@ + + + DialogRestrictDimension + + + + 0 + 0 + 844 + 683 + + + + Dialog + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + Dimension B: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Dimension A: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + + 0 + 4 + + + + + + false + + + Restriction + + + + + + + + + Min: + + + + + + + Max: + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + DialogRestrictDimension + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogRestrictDimension + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/app/tape/tape.pri b/src/app/tape/tape.pri index 64c1e6023..219113ac5 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/dialogrestrictdimension.cpp \ $$PWD/main.cpp \ $$PWD/tmainwindow.cpp \ $$PWD/mapplication.cpp \ @@ -17,6 +18,7 @@ SOURCES += \ *msvc*:SOURCES += $$PWD/stable.cpp HEADERS += \ + $$PWD/dialogs/dialogrestrictdimension.h \ $$PWD/tmainwindow.h \ $$PWD/stable.h \ $$PWD/mapplication.h \ @@ -31,6 +33,7 @@ HEADERS += \ $$PWD/dialogs/dialogsetupmultisize.h FORMS += \ + $$PWD/dialogs/dialogrestrictdimension.ui \ $$PWD/tmainwindow.ui \ $$PWD/dialogs/dialogabouttape.ui \ $$PWD/dialogs/dialognewmeasurements.ui \ diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 389c0f12c..f404e88d3 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -33,6 +33,7 @@ #include "dialogs/dialogmdatabase.h" #include "dialogs/dialogtapepreferences.h" #include "dialogs/dialogsetupmultisize.h" +#include "dialogs/dialogrestrictdimension.h" #include "../vpatterndb/vcontainer.h" #include "../vpatterndb/calculator.h" #include "../vpatterndb/pmsystems.h" @@ -2187,6 +2188,44 @@ void TMainWindow::ExportToIndividual() } } +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::RestrictSecondDimesion() +{ + const QList dimensions = m->Dimensions().values(); + const QMap> restrictions = m->GetRestrictions(); + + bool oneDimesionRestriction = true; + bool fullCircumference = m->IsFullCircumference(); + + DialogRestrictDimension dialog(dimensions, restrictions, oneDimesionRestriction, fullCircumference, this); + if (dialog.exec() == QDialog::Rejected) + { + return; + } + + m->SetRestrictions(dialog.Restrictions()); + MeasurementsWereSaved(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::RestrictThirdDimesion() +{ + const QList dimensions = m->Dimensions().values(); + const QMap> restrictions = m->GetRestrictions(); + + bool oneDimesionRestriction = false; + bool fullCircumference = m->IsFullCircumference(); + + DialogRestrictDimension dialog(dimensions, restrictions, oneDimesionRestriction, fullCircumference, this); + if (dialog.exec() == QDialog::Rejected) + { + return; + } + + m->SetRestrictions(dialog.Restrictions()); + MeasurementsWereSaved(false); +} + //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::SetupMenu() { @@ -2467,6 +2506,26 @@ void TMainWindow::InitMenu() separator->setSeparator(true); ui->menuMeasurements->insertAction(ui->actionUseFullCircumference, separator); + const QList dimensions = m->Dimensions().values(); + if (dimensions.size() > 1) + { + ui->actionRestrictSecondDimension->setVisible(true); + 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); + ui->actionRestrictThirdDimension->setEnabled(true); + connect(ui->actionRestrictThirdDimension, &QAction::triggered, this, + &TMainWindow::RestrictThirdDimesion); + } + } + // File ui->actionExportToIndividual->setVisible(true); ui->actionExportToIndividual->setEnabled(true); @@ -3995,7 +4054,7 @@ QVector TMainWindow::DimensionRestrictedValues(int index, const Measurement } else if (dimension->Type() == MeasurementDimension::Y) { - const QPair restriction = m->OneDimensionRestriction(currentDimensionA); + const QPair restriction = m->Restriction(currentDimensionA); VYMeasurementDimension restricted(dimension->Units(), restriction.first, restriction.second, dimension->Step()); restricted.SetCircumference(dimension->IsCircumference()); @@ -4013,11 +4072,11 @@ QVector TMainWindow::DimensionRestrictedValues(int index, const Measurement if (index == 1) { - restriction = m->OneDimensionRestriction(currentDimensionA); + restriction = m->Restriction(currentDimensionA); } else { - restriction = m->TwoDimensionRestriction(currentDimensionA, currentDimensionB); + restriction = m->Restriction(currentDimensionA, currentDimensionB); } VWMeasurementDimension restricted(dimension->Units(), restriction.first, restriction.second, dimension->Step()); @@ -4036,11 +4095,11 @@ QVector TMainWindow::DimensionRestrictedValues(int index, const Measurement if (index == 1) { - restriction = m->OneDimensionRestriction(currentDimensionA); + restriction = m->Restriction(currentDimensionA); } else { - restriction = m->TwoDimensionRestriction(currentDimensionA, currentDimensionB); + restriction = m->Restriction(currentDimensionA, currentDimensionB); } VZMeasurementDimension restricted(dimension->Units(), restriction.first, restriction.second, dimension->Step()); diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index 853708972..8388f647a 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -139,6 +139,9 @@ private slots: void ExportToIndividual(); + void RestrictSecondDimesion(); + void RestrictThirdDimesion(); + private: Q_DISABLE_COPY(TMainWindow) Ui::TMainWindow *ui; diff --git a/src/app/tape/tmainwindow.ui b/src/app/tape/tmainwindow.ui index 37c218def..a757d449c 100644 --- a/src/app/tape/tmainwindow.ui +++ b/src/app/tape/tmainwindow.ui @@ -993,6 +993,8 @@ + + @@ -1365,6 +1367,28 @@ false + + + false + + + Restrict second dimension + + + false + + + + + false + + + Restrict third dimension + + + false + + diff --git a/src/libs/vformat/vmeasurements.cpp b/src/libs/vformat/vmeasurements.cpp index 033f3ef63..941c82c3a 100644 --- a/src/libs/vformat/vmeasurements.cpp +++ b/src/libs/vformat/vmeasurements.cpp @@ -71,6 +71,7 @@ const QString VMeasurements::TagMeasurement = QStringLiteral("m"); const QString VMeasurements::TagDimensions = QStringLiteral("dimensions"); const QString VMeasurements::TagDimension = QStringLiteral("dimension"); const QString VMeasurements::TagRestrictions = QStringLiteral("restrictions"); +const QString VMeasurements::TagRestriction = QStringLiteral("restriction"); const QString VMeasurements::TagCorrections = QStringLiteral("corrections"); const QString VMeasurements::TagCorrection = QStringLiteral("correction"); @@ -853,15 +854,58 @@ QMap VMeasurements::Dimensions() } //--------------------------------------------------------------------------------------------------------------------- -QPair VMeasurements::OneDimensionRestriction(int base) const +QMap > VMeasurements::GetRestrictions() const { - return QPair(0, 0); + QMap > restrictions; + + const QDomNodeList list = elementsByTagName(TagRestriction); + for (int i=0; i < list.size(); ++i) + { + const QDomElement res = list.at(i).toElement(); + + QString coordinates = GetParametrString(res, AttrCoordinates); + const int min = GetParametrInt(res, AttrMin, QChar('0')); + const int max = GetParametrInt(res, AttrMax, QChar('0')); + + restrictions.insert(coordinates, qMakePair(min, max)); + } + + return restrictions; } //--------------------------------------------------------------------------------------------------------------------- -QPair VMeasurements::TwoDimensionRestriction(int base1, int base2) const +void VMeasurements::SetRestrictions(const QMap > &restrictions) { - return QPair(0, 0); + QDomElement root = documentElement(); + QDomElement restrictionsTag = root.firstChildElement(TagRestrictions); + + if (restrictionsTag.isNull()) + { + qDebug() << "Can't find restrictions tag"; + } + + RemoveAllChildren(restrictionsTag); + + QMap >::const_iterator i = restrictions.constBegin(); + while (i != restrictions.constEnd()) + { + QDomElement restrictionTag = createElement(TagRestriction); + + SetAttribute(restrictionTag, AttrCoordinates, i.key()); + SetAttribute(restrictionTag, AttrMin, i.value().first); + SetAttribute(restrictionTag, AttrMax, i.value().second); + + restrictionsTag.appendChild(restrictionTag); + ++i; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QPair VMeasurements::Restriction(int base, int base2) const +{ + const QMap > restrictions = GetRestrictions(); + const QString hash = VMeasurement::CorrectionHash(base, base2, 0); + return restrictions.value(hash, QPair(0, 0)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vformat/vmeasurements.h b/src/libs/vformat/vmeasurements.h index d6ec2c641..2028115c0 100644 --- a/src/libs/vformat/vmeasurements.h +++ b/src/libs/vformat/vmeasurements.h @@ -116,8 +116,10 @@ public: QMap Dimensions() const; - QPair OneDimensionRestriction(int base) const; - QPair TwoDimensionRestriction(int base1, int base2) const; + QMap > GetRestrictions() const; + void SetRestrictions(const QMap > &restrictions); + + QPair Restriction(int base, int base2=0) const; static const QString TagVST; static const QString TagVIT; @@ -134,6 +136,7 @@ public: static const QString TagDimensions; static const QString TagDimension; static const QString TagRestrictions; + static const QString TagRestriction; static const QString TagCorrections; static const QString TagCorrection; From e655a31ed20c71163fd93215aa1da7d9cc4cc50d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 28 Sep 2020 16:42:31 +0300 Subject: [PATCH 24/44] Fix bogus newline in src/test/ValentinaTest/tst_vabstractpiece.cpp. Closes #61 (cherry picked from commit 12c360b33a8bd91c7630449af944026a203ad87c) --- src/test/ValentinaTest/tst_vabstractpiece.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ValentinaTest/tst_vabstractpiece.cpp b/src/test/ValentinaTest/tst_vabstractpiece.cpp index af18a3795..284c43056 100644 --- a/src/test/ValentinaTest/tst_vabstractpiece.cpp +++ b/src/test/ValentinaTest/tst_vabstractpiece.cpp @@ -939,7 +939,7 @@ void TST_VAbstractPiece::BrokenDetailEquidistant_data() ekvOrig.append(QPointF(787.1898456692913, 1663.5186141732283)); // Disabled due to "undefined behavior" problem -#if !defined(Q_OS_WIN) && !defined(Q_CC_CLANG) && !defined(Q_PROCESSOR_X86_64) && !defined(Q_PROCESSOR_S390) +#if !defined(Q_OS_WIN) && !defined(Q_CC_CLANG) && !defined(Q_PROCESSOR_X86_64) && !defined(Q_PROCESSOR_S390) \ && !defined(Q_PROCESSOR_S390_X) QTest::newRow("GAVAUDAN Laure.") << points << 37.795275590551185 << ekvOrig; #endif From 1483f7a0cca57e69dd092e56c158e919d01c0d3d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 5 Oct 2020 16:39:01 +0300 Subject: [PATCH 25/44] Improve warning about error in calculating a curve segment. Added in the message information about the path name. (cherry picked from commit 75e296e83945ccdffd6b437a0fdfe78dd8892a19) --- src/libs/vgeometry/vabstractcurve.cpp | 16 +++++++++++++--- src/libs/vgeometry/vabstractcurve.h | 3 ++- src/libs/vpatterndb/vpiece.cpp | 11 +++++++---- src/libs/vpatterndb/vpiecepath.cpp | 19 ++++++++++--------- src/libs/vpatterndb/vpiecepath.h | 6 ++++-- 5 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/libs/vgeometry/vabstractcurve.cpp b/src/libs/vgeometry/vabstractcurve.cpp index bf224393c..15e6d466d 100644 --- a/src/libs/vgeometry/vabstractcurve.cpp +++ b/src/libs/vgeometry/vabstractcurve.cpp @@ -126,15 +126,25 @@ QVector VAbstractCurve::GetSegmentPoints(const QVector &points } //--------------------------------------------------------------------------------------------------------------------- -QVector VAbstractCurve::GetSegmentPoints(const QPointF &begin, const QPointF &end, bool reverse) const +QVector VAbstractCurve::GetSegmentPoints(const QPointF &begin, const QPointF &end, bool reverse, + const QString &piece) const { QString error; QVector segment = GetSegmentPoints(GetPoints(), begin, end, reverse, error); if (not error.isEmpty()) { - const QString errorMsg = QObject::tr("Error calculating segment for curve '%1'. %2") - .arg(name(), error); + QString errorMsg; + if (piece.isEmpty()) + { + errorMsg = QObject::tr("Error calculating segment for curve '%1'. %2") + .arg(name(), error); + } + else + { + errorMsg = QObject::tr("Error in path '%1'. Calculating segment for curve '%2' has failed. %3") + .arg(piece, name(), error); + } qApp->IsPedantic() ? throw VExceptionObjectError(errorMsg) : qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; } diff --git a/src/libs/vgeometry/vabstractcurve.h b/src/libs/vgeometry/vabstractcurve.h index 2b38cd1fa..f72d8e60f 100644 --- a/src/libs/vgeometry/vabstractcurve.h +++ b/src/libs/vgeometry/vabstractcurve.h @@ -64,7 +64,8 @@ public: virtual QVector GetPoints() const =0; static QVector GetSegmentPoints(const QVector &points, const QPointF &begin, const QPointF &end, bool reverse, QString &error); - QVector GetSegmentPoints(const QPointF &begin, const QPointF &end, bool reverse) const; + QVector GetSegmentPoints(const QPointF &begin, const QPointF &end, bool reverse, + const QString &piece = QString()) const; virtual QPainterPath GetPath() const; virtual qreal GetLength() const =0; diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index 1e8fccdad..44ee8202a 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -174,7 +174,10 @@ QVector VPiece::MainPathPoints(const VContainer *data) const { // DumpPiece(*this, data); // Uncomment for dumping test data - QVector points = GetPath().PathPoints(data); + VPiecePath mainPath = GetPath(); + mainPath.SetName(tr("Main path of piece %1").arg(GetName())); + + QVector points = mainPath.PathPoints(data); points = CheckLoops(CorrectEquidistantPoints(points));//A path can contains loops // DumpVector(points); // Uncomment for dumping test data @@ -184,7 +187,7 @@ QVector VPiece::MainPathPoints(const VContainer *data) const //--------------------------------------------------------------------------------------------------------------------- QVector VPiece::UniteMainPathPoints(const VContainer *data) const { - QVector points = VPiecePath::NodesToPoints(data, GetUnitedPath(data)); + QVector points = VPiecePath::NodesToPoints(data, GetUnitedPath(data), GetName()); points = CheckLoops(CorrectEquidistantPoints(points));//A path can contains loops return points; } @@ -731,7 +734,7 @@ QVector VPiece::SeamAllowancePointsWithRotation(const VContainer *data, const QSharedPointer curve = data->GeometricObject(node.GetId()); pointsEkv += VPiecePath::CurveSeamAllowanceSegment(data, unitedPath, curve, i, node.GetReverse(), - width); + width, GetName()); } } break; @@ -899,7 +902,7 @@ QVector VPiece::GetNodeSAPoints(const QVector &path, int i const QSharedPointer curve = data->GeometricObject(node.GetId()); const qreal width = ToPixel(GetSAWidth(), *data->GetPatternUnit()); - points += VPiecePath::CurveSeamAllowanceSegment(data, path, curve, index, node.GetReverse(), width); + points += VPiecePath::CurveSeamAllowanceSegment(data, path, curve, index, node.GetReverse(), width, GetName()); } return points; } diff --git a/src/libs/vpatterndb/vpiecepath.cpp b/src/libs/vpatterndb/vpiecepath.cpp index dbaced0b3..9ba8fa888 100644 --- a/src/libs/vpatterndb/vpiecepath.cpp +++ b/src/libs/vpatterndb/vpiecepath.cpp @@ -366,7 +366,7 @@ bool VPiecePath::IsLastToCuttingCountour() const //--------------------------------------------------------------------------------------------------------------------- QVector VPiecePath::PathPoints(const VContainer *data, const QVector &cuttingPath) const { - QVector points = NodesToPoints(data, d->m_nodes); + QVector points = NodesToPoints(data, d->m_nodes, GetName()); if (GetType() == PiecePathType::InternalPath && not cuttingPath.isEmpty() && points.size() > 1) { @@ -464,7 +464,7 @@ QVector > VPiecePath::PathCurvePoints(const VContainer *data) c const QPointF begin = StartSegment(data, i, at(i).GetReverse()); const QPointF end = EndSegment(data, i, at(i).GetReverse()); - curves.append(curve->GetSegmentPoints(begin, end, at(i).GetReverse())); + curves.append(curve->GetSegmentPoints(begin, end, at(i).GetReverse(), GetName())); break; } case (Tool::NodePoint): @@ -498,7 +498,7 @@ QVector VPiecePath::SeamAllowancePoints(const VContainer *data, qreal case (Tool::NodeSplinePath): { const QSharedPointer curve = data->GeometricObject(node.GetId()); - pointsEkv += CurveSeamAllowanceSegment(data, d->m_nodes, curve, i, node.GetReverse(), width); + pointsEkv += CurveSeamAllowanceSegment(data, d->m_nodes, curve, i, node.GetReverse(), width, GetName()); } break; default: @@ -882,7 +882,7 @@ QPointF VPiecePath::NodePreviousPoint(const VContainer *data, int i) const const VSAPoint begin = StartSegment(data, d->m_nodes, index, node.GetReverse()); const VSAPoint end = EndSegment(data, d->m_nodes, index, node.GetReverse()); - const QVector points = curve->GetSegmentPoints(begin, end, node.GetReverse()); + const QVector points = curve->GetSegmentPoints(begin, end, node.GetReverse(), GetName()); if (points.size() > 1) { return points.at(points.size()-2); @@ -934,7 +934,7 @@ QPointF VPiecePath::NodeNextPoint(const VContainer *data, int i) const const VSAPoint begin = StartSegment(data, d->m_nodes, index, node.GetReverse()); const VSAPoint end = EndSegment(data, d->m_nodes, index, node.GetReverse()); - const QVector points = curve->GetSegmentPoints(begin, end, node.GetReverse()); + const QVector points = curve->GetSegmentPoints(begin, end, node.GetReverse(), GetName()); if (points.size() > 1) { return points.at(1); @@ -1084,14 +1084,14 @@ VSAPoint VPiecePath::PreparePointEkv(const VPieceNode &node, const VContainer *d //--------------------------------------------------------------------------------------------------------------------- QVector VPiecePath::CurveSeamAllowanceSegment(const VContainer *data, const QVector &nodes, const QSharedPointer &curve, int i, - bool reverse, qreal width) + bool reverse, qreal width, const QString &piece) { QVector pointsEkv; const VSAPoint begin = StartSegment(data, nodes, i, reverse); const VSAPoint end = EndSegment(data, nodes, i, reverse); - const QVector points = curve->GetSegmentPoints(begin, end, reverse); + const QVector points = curve->GetSegmentPoints(begin, end, reverse, piece); if (points.isEmpty()) { return pointsEkv; @@ -1193,7 +1193,8 @@ QString VPiecePath::NodeName(const QVector &nodes, int nodeIndex, co } //--------------------------------------------------------------------------------------------------------------------- -QVector VPiecePath::NodesToPoints(const VContainer *data, const QVector &nodes) +QVector VPiecePath::NodesToPoints(const VContainer *data, const QVector &nodes, + const QString &piece) { QVector points; for (int i = 0; i < nodes.size(); ++i) @@ -1223,7 +1224,7 @@ QVector VPiecePath::NodesToPoints(const VContainer *data, const QVector const QPointF begin = StartSegment(data, nodes, i, node.GetReverse()); const QPointF end = EndSegment(data, nodes, i, node.GetReverse()); - points << curve->GetSegmentPoints(begin, end, node.GetReverse()); + points << curve->GetSegmentPoints(begin, end, node.GetReverse(), piece); } break; default: diff --git a/src/libs/vpatterndb/vpiecepath.h b/src/libs/vpatterndb/vpiecepath.h index 4998d1672..ffaef1573 100644 --- a/src/libs/vpatterndb/vpiecepath.h +++ b/src/libs/vpatterndb/vpiecepath.h @@ -133,11 +133,13 @@ public: static QVector CurveSeamAllowanceSegment(const VContainer *data, const QVector &nodes, const QSharedPointer &curve, - int i, bool reverse, qreal width); + int i, bool reverse, qreal width, + const QString &piece = QString()); static QString NodeName(const QVector &nodes, int nodeIndex, const VContainer *data); - static QVector NodesToPoints(const VContainer *data, const QVector &nodes); + static QVector NodesToPoints(const VContainer *data, const QVector &nodes, + const QString &piece = QString()); private: QSharedDataPointer d; From 4a1d20810c3b0bd48c5f7cea96de75085ec5d7ab Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 5 Oct 2020 16:49:42 +0300 Subject: [PATCH 26/44] New warning check. Piece name is not unique. (cherry picked from commit d5fd1380dc9fe4ce0fe2923a273b05590bb40dd4) --- src/app/valentina/mainwindow.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 3c1ac6bab..e3651d4ec 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -156,6 +156,30 @@ QVector SortDetailsForLayout(const QHash *allD return details; } +//--------------------------------------------------------------------------------------------------------------------- +void WarningNotUniquePieceName(const QHash *allDetails) +{ + QHash::const_iterator i = allDetails->constBegin(); + QSet uniqueNames; + + while (i != allDetails->constEnd()) + { + const QString pieceName = i.value().GetName(); + if (not uniqueNames.contains(pieceName)) + { + uniqueNames.insert(pieceName); + } + else + { + const QString errorMsg = QObject::tr("Piece name '%1' is not unique.").arg(pieceName); + qApp->IsPedantic() ? throw VException(errorMsg) : + qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + } + + ++i; + } +} + } // anonymous namespace //--------------------------------------------------------------------------------------------------------------------- @@ -2780,6 +2804,8 @@ void MainWindow::ActionDetails(bool checked) ui->dockWidgetToolOptions->setVisible(isDockToolOptionsVisible); m_statusLabel->setText(QString()); + + WarningNotUniquePieceName(pattern->DataPieces()); } else { @@ -2826,6 +2852,7 @@ void MainWindow::ActionLayout(bool checked) } else { + WarningNotUniquePieceName(allDetails); details = SortDetailsForLayout(allDetails); if (details.count() == 0) From 4a12c1ca74241b1385840282fe50bd56887eac5b Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 6 Oct 2020 18:00:53 +0300 Subject: [PATCH 27/44] Continue improving dialog Dimension restrictions. --- .../tape/dialogs/dialogrestrictdimension.cpp | 542 ++++++++++++++++++ .../tape/dialogs/dialogrestrictdimension.h | 28 +- .../tape/dialogs/dialogrestrictdimension.ui | 195 +++---- src/app/tape/tmainwindow.cpp | 79 +-- src/app/tape/tmainwindow.h | 3 - src/libs/vformat/vdimensions.cpp | 44 ++ src/libs/vformat/vdimensions.h | 3 + src/libs/vmisc/share/resources/icon.qrc | 4 + .../share/resources/icon/24x24/close.png | Bin 0 -> 548 bytes .../share/resources/icon/24x24/close@2x.png | Bin 0 -> 753 bytes .../vmisc/share/resources/icon/24x24/star.png | Bin 0 -> 659 bytes .../share/resources/icon/24x24/star@2x.png | Bin 0 -> 827 bytes src/libs/vpatterndb/variables/vmeasurement.h | 2 +- src/libs/vwidgets/vcomboboxdelegate.h | 2 +- .../vwidgets/vdecorationaligningdelegate.cpp | 48 ++ .../vwidgets/vdecorationaligningdelegate.h | 57 ++ src/libs/vwidgets/vwidgets.pri | 2 + 17 files changed, 829 insertions(+), 180 deletions(-) create mode 100644 src/libs/vmisc/share/resources/icon/24x24/close.png create mode 100644 src/libs/vmisc/share/resources/icon/24x24/close@2x.png create mode 100644 src/libs/vmisc/share/resources/icon/24x24/star.png create mode 100644 src/libs/vmisc/share/resources/icon/24x24/star@2x.png create mode 100644 src/libs/vwidgets/vdecorationaligningdelegate.cpp create mode 100644 src/libs/vwidgets/vdecorationaligningdelegate.h diff --git a/src/app/tape/dialogs/dialogrestrictdimension.cpp b/src/app/tape/dialogs/dialogrestrictdimension.cpp index 90004601c..7e66555c7 100644 --- a/src/app/tape/dialogs/dialogrestrictdimension.cpp +++ b/src/app/tape/dialogs/dialogrestrictdimension.cpp @@ -28,6 +28,55 @@ #include "dialogrestrictdimension.h" #include "ui_dialogrestrictdimension.h" +#include + +#include "../vpatterndb/variables/vmeasurement.h" +#include "../vwidgets/vdecorationaligningdelegate.h" + + +namespace +{ +//--------------------------------------------------------------------------------------------------------------------- +QVector FilterByMinimum(const QVector &base, int restriction) +{ + if (restriction <= 0) + { + return base; + } + + QVector filtered; + filtered.reserve(base.size()); + for(auto &b : base) + { + if (b >= restriction) + { + filtered.append(b); + } + } + return filtered; +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector FilterByMaximum(const QVector &base, int restriction) +{ + if (restriction <= 0) + { + return base; + } + + QVector filtered; + filtered.reserve(base.size()); + for(auto &b : base) + { + if (b <= restriction) + { + filtered.append(b); + } + } + return filtered; +} +} + //--------------------------------------------------------------------------------------------------------------------- DialogRestrictDimension::DialogRestrictDimension(const QList &dimensions, const QMap> &restrictions, @@ -41,6 +90,22 @@ DialogRestrictDimension::DialogRestrictDimension(const QListsetupUi(this); + + ui->tableWidget->setItemDelegate( + new VDecorationAligningDelegate(Qt::AlignHCenter | Qt::AlignCenter, ui->tableWidget)); + + connect(ui->tableWidget, &QTableWidget::itemSelectionChanged, this, &DialogRestrictDimension::RowSelected); + + connect(ui->comboBoxDimensionA, QOverload::of(&QComboBox::currentIndexChanged), this, + &DialogRestrictDimension::DimensionAChanged); + + connect(ui->comboBoxMin, QOverload::of(&QComboBox::currentIndexChanged), this, + &DialogRestrictDimension::MinRestrictionChanged); + connect(ui->comboBoxMax, QOverload::of(&QComboBox::currentIndexChanged), this, + &DialogRestrictDimension::MaxRestrictionChanged); + + InitDimensionsBaseValues(); + InitTable(); } //--------------------------------------------------------------------------------------------------------------------- @@ -48,3 +113,480 @@ DialogRestrictDimension::~DialogRestrictDimension() { delete ui; } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRestrictDimension::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::LanguageChange) + { + // retranslate designer form (single inheritance approach) + ui->retranslateUi(this); + + auto RetranslateControls = [this](int index, QLabel *name, QComboBox *control) + { + SCASSERT(name != nullptr) + SCASSERT(control != nullptr) + + if (m_dimensions.size() > index) + { + MeasurementDimension_p dimension = m_dimensions.at(index); + + name->setText(VAbstartMeasurementDimension::DimensionName(dimension->Type())+QChar(':')); + name->setToolTip(VAbstartMeasurementDimension::DimensionToolTip(dimension->Type(), + dimension->IsCircumference(), + m_fullCircumference)); + + InitDimensionGradation(dimension, control); + } + }; + + if (not m_oneDimesionRestriction) + { + RetranslateControls(0, ui->labelDimensionA, ui->comboBoxDimensionA); + } + } + + // remember to call base class implementation + QDialog::changeEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRestrictDimension::RowSelected() +{ + EnableRestrictionControls(false); + + QTableWidgetItem *item = ui->tableWidget->currentItem(); + + if (item) + { + int base1 = 0; + int base2 = 0; + MeasurementDimension_p dimension; + + if (m_oneDimesionRestriction) + { + base1 = item->data(Qt::UserRole).toInt(); + + if (m_dimensions.size() > 1) + { + dimension = m_dimensions.at(1); + } + } + else + { + base1 = ui->comboBoxDimensionA->currentData().toInt(); + base2 = item->data(Qt::UserRole).toInt(); + + if (m_dimensions.size() > 2) + { + dimension = m_dimensions.at(2); + } + } + + QPair restriction = m_restrictions.value(VMeasurement::CorrectionHash(base1, base2), + QPair(0, 0)); + + if (dimension.isNull()) + { + return; + } + + const QVector bases = dimension->ValidBases(); + + ui->comboBoxMin->blockSignals(true); + ui->comboBoxMin->clear(); + QVector filtered = FilterByMaximum(bases, restriction.second); + FillBases(filtered, dimension, ui->comboBoxMin); + int index = ui->comboBoxMin->findData(restriction.first); + ui->comboBoxMin->setCurrentIndex(index != -1 ? index : 0); + ui->comboBoxMin->blockSignals(false); + + ui->comboBoxMax->blockSignals(true); + ui->comboBoxMax->clear(); + filtered = FilterByMinimum(bases, restriction.first); + FillBases(FilterByMinimum(bases, restriction.first), dimension, ui->comboBoxMax); + index = ui->comboBoxMax->findData(restriction.second); + ui->comboBoxMax->setCurrentIndex(index != -1 ? index : ui->comboBoxMax->count() - 1); + ui->comboBoxMax->blockSignals(false); + + EnableRestrictionControls(true); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRestrictDimension::DimensionAChanged() +{ + InitTable(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRestrictDimension::MinRestrictionChanged() +{ + QTableWidgetItem *item = ui->tableWidget->currentItem(); + + if (item) + { + int base1 = 0; + int base2 = 0; + + if (m_oneDimesionRestriction) + { + base1 = item->data(Qt::UserRole).toInt(); + } + else + { + base1 = ui->comboBoxDimensionA->currentData().toInt(); + base2 = item->data(Qt::UserRole).toInt(); + } + + const QString coordinates = VMeasurement::CorrectionHash(base1, base2); + QPair restriction = m_restrictions.value(coordinates, QPair(0, 0)); + + restriction.first = ui->comboBoxMin->currentData().toInt(); + m_restrictions.insert(coordinates, restriction); + + const int currentRow = ui->tableWidget->currentRow(); + RefreshTable(); + + ui->tableWidget->blockSignals(true); + ui->tableWidget->selectRow(currentRow); + ui->tableWidget->blockSignals(false); + + RowSelected(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRestrictDimension::MaxRestrictionChanged() +{ + QTableWidgetItem *item = ui->tableWidget->currentItem(); + + if (item) + { + int base1 = 0; + int base2 = 0; + + if (m_oneDimesionRestriction) + { + base1 = item->data(Qt::UserRole).toInt(); + } + else + { + base1 = ui->comboBoxDimensionA->currentData().toInt(); + base2 = item->data(Qt::UserRole).toInt(); + } + + const QString coordinates = VMeasurement::CorrectionHash(base1, base2); + QPair restriction = m_restrictions.value(coordinates, QPair(0, 0)); + + restriction.second = ui->comboBoxMax->currentData().toInt(); + m_restrictions.insert(coordinates, restriction); + + const int currentRow = ui->tableWidget->currentRow(); + RefreshTable(); + + ui->tableWidget->blockSignals(true); + ui->tableWidget->selectRow(currentRow); + ui->tableWidget->blockSignals(false); + + RowSelected(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRestrictDimension::InitDimensionsBaseValues() +{ + auto DimensionsBaseValue = [this](int index, QLabel *name, QComboBox *control) + { + SCASSERT(name != nullptr) + SCASSERT(control != nullptr) + + if (m_dimensions.size() > index) + { + MeasurementDimension_p dimension = m_dimensions.at(index); + const QString unit = UnitsToStr(dimension->Units(), true); + name->setText(VAbstartMeasurementDimension::DimensionName(dimension->Type())+QChar(':')); + name->setToolTip(VAbstartMeasurementDimension::DimensionToolTip(dimension->Type(), + dimension->IsCircumference(), + m_fullCircumference)); + + InitDimensionGradation(dimension, control); + } + }; + + if (not m_oneDimesionRestriction) + { + if (m_dimensions.size() > 0) + { + DimensionsBaseValue(0, ui->labelDimensionA, ui->comboBoxDimensionA); + } + else + { + ui->labelDimensionA->setVisible(false); + ui->comboBoxDimensionA->setVisible(false); + } + } + else + { + ui->labelDimensionA->setVisible(false); + ui->comboBoxDimensionA->setVisible(false); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRestrictDimension::InitDimensionGradation(const MeasurementDimension_p &dimension, QComboBox *control) +{ + SCASSERT(control != nullptr) + + int current = -1; + if (control->currentIndex() != -1) + { + current = control->currentData().toInt(); + } + + control->blockSignals(true); + control->clear(); + + FillBases(dimension->ValidBases(), dimension, control); + + int i = control->findData(current); + if (i != -1) + { + control->setCurrentIndex(i); + control->blockSignals(false); + } + else + { + control->blockSignals(false); + control->setCurrentIndex(0); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRestrictDimension::InitTable() +{ + ui->tableWidget->blockSignals(true); + ui->tableWidget->clear(); + + auto InitHeaders = [this](int index) + { + if (m_dimensions.size() > index) + { + MeasurementDimension_p dimensionA = m_dimensions.at(index-1); + const QVector basesA = dimensionA->ValidBases(); + ui->tableWidget->setRowCount(basesA.size()); + ui->tableWidget->setVerticalHeaderLabels(DimensionLabels(basesA, dimensionA)); + + MeasurementDimension_p dimensionB = m_dimensions.at(index); + const QVector basesB = dimensionB->ValidBases(); + ui->tableWidget->setColumnCount(basesB.size()); + ui->tableWidget->setHorizontalHeaderLabels(DimensionLabels(basesB, dimensionB)); + } + }; + + InitHeaders(m_oneDimesionRestriction ? 1 : 2); + ui->tableWidget->blockSignals(false); + + RefreshTable(); + ui->tableWidget->selectRow(0); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRestrictDimension::RefreshTable() +{ + QVector basesRow; + QVector basesColumn; + + if (m_oneDimesionRestriction) + { + if (m_dimensions.size() >= 2) + { + MeasurementDimension_p dimensionA = m_dimensions.at(0); + basesRow = dimensionA->ValidBases(); + + MeasurementDimension_p dimensionB = m_dimensions.at(1); + basesColumn = dimensionB->ValidBases(); + } + else + { + return; + } + } + else + { + if (m_dimensions.size() >= 3) + { + MeasurementDimension_p dimensionA = m_dimensions.at(1); + basesRow = dimensionA->ValidBases(); + + MeasurementDimension_p dimensionB = m_dimensions.at(2); + basesColumn = dimensionB->ValidBases(); + } + else + { + return; + } + } + + ui->tableWidget->blockSignals(true); + ui->tableWidget->clearContents(); + + for(int row=0; row < basesRow.size(); ++row) + { + for(int column=0; column < basesColumn.size(); ++column) + { + AddCell(row, column, basesRow.at(row), basesColumn.at(column)); + } + } + + ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + ui->tableWidget->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch); + + ui->tableWidget->blockSignals(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRestrictDimension::AddCell(int row, int column, int rowValue, int columnValue) +{ + auto *item = new QTableWidgetItem(); + item->setData(Qt::UserRole, rowValue); + + int base1 = 0; + int base2 = 0; + + if (m_oneDimesionRestriction) + { + base1 = rowValue; + } + else + { + base1 = ui->comboBoxDimensionA->currentData().toInt(); + base2 = rowValue; + } + + QPair restriction = m_restrictions.value(VMeasurement::CorrectionHash(base1, base2), + QPair(0, 0)); + + bool leftRestriction = true; + if (restriction.first > 0 && restriction.first <= restriction.second) + { + leftRestriction = columnValue >= restriction.first; + } + + bool rightRestriction = true; + if (restriction.second > 0 && restriction.second >= restriction.first) + { + rightRestriction = columnValue <= restriction.second; + } + + if (leftRestriction && rightRestriction) + { + item->setIcon(QIcon("://icon/24x24/star.png")); + } + else + { + item->setIcon(QIcon("://icon/24x24/close.png")); + } + + // set the item non-editable (view only), and non-selectable + Qt::ItemFlags flags = item->flags(); + flags &= ~(Qt::ItemIsEditable); // reset/clear the flag + item->setFlags(flags); + + ui->tableWidget->setItem(row, column, item); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRestrictDimension::EnableRestrictionControls(bool enable) +{ + if (not enable) + { + ui->comboBoxMin->blockSignals(true); + ui->comboBoxMin->setCurrentIndex(-1); + ui->comboBoxMin->blockSignals(false); + + ui->comboBoxMax->blockSignals(true); + ui->comboBoxMax->setCurrentIndex(-1); + ui->comboBoxMax->blockSignals(false); + } + + ui->groupBoxRestriction->setEnabled(enable); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRestrictDimension::FillBases(const QVector &bases, const MeasurementDimension_p &dimension, + QComboBox *control) +{ + SCASSERT(control != nullptr) + + 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); + } + } + else if (dimension->Type() == MeasurementDimension::Y) + { + for(auto base : bases) + { + if (dimension->IsCircumference()) + { + control->addItem(QString("%1 %2").arg(m_fullCircumference ? base*2 : base).arg(units), base); + } + else + { + control->addItem(QString::number(base), base); + } + } + } + else if (dimension->Type() == MeasurementDimension::W || dimension->Type() == MeasurementDimension::Z) + { + for(auto base : bases) + { + control->addItem(QString("%1 %2").arg(m_fullCircumference ? base*2 : base).arg(units), base); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QStringList DialogRestrictDimension::DimensionLabels(const QVector &bases, const MeasurementDimension_p &dimension) +{ + const bool showUnits = dimension->IsCircumference() || dimension->Type() == MeasurementDimension::X; + const QString units = showUnits ? UnitsToStr(dimension->Units(), true) : QString(); + + QStringList labels; + + if (dimension->Type() == MeasurementDimension::X) + { + for(auto base : bases) + { + labels.append(QString("%1 %2").arg(base).arg(units)); + } + } + else if (dimension->Type() == MeasurementDimension::Y) + { + for(auto base : bases) + { + if (dimension->IsCircumference()) + { + labels.append(QString("%1 %2").arg(m_fullCircumference ? base*2 : base).arg(units)); + } + else + { + labels.append(QString::number(base)); + } + } + } + else if (dimension->Type() == MeasurementDimension::W || dimension->Type() == MeasurementDimension::Z) + { + for(auto base : bases) + { + labels.append(QString("%1 %2").arg(m_fullCircumference ? base*2 : base).arg(units)); + } + } + + return labels; +} diff --git a/src/app/tape/dialogs/dialogrestrictdimension.h b/src/app/tape/dialogs/dialogrestrictdimension.h index 58d2aca6a..0a3c03335 100644 --- a/src/app/tape/dialogs/dialogrestrictdimension.h +++ b/src/app/tape/dialogs/dialogrestrictdimension.h @@ -35,9 +35,12 @@ namespace Ui { - class DialogRestrictDimension; +class DialogRestrictDimension; } +class QTableWidgetItem; + + class DialogRestrictDimension : public QDialog { Q_OBJECT @@ -50,6 +53,15 @@ public: QMap > Restrictions() const; +protected: + virtual void changeEvent(QEvent* event) override; + +protected slots: + void RowSelected(); + void DimensionAChanged(); + void MinRestrictionChanged(); + void MaxRestrictionChanged(); + private: Q_DISABLE_COPY(DialogRestrictDimension) Ui::DialogRestrictDimension *ui; @@ -58,6 +70,20 @@ private: bool m_fullCircumference; QList m_dimensions; QMap> m_restrictions; + + void InitDimensionsBaseValues(); + void InitDimensionGradation(const MeasurementDimension_p &dimension, QComboBox *control); + void InitTable(); + + void RefreshTable(); + + void AddCell(int row, int column, int rowValue, int columnValue); + + void EnableRestrictionControls(bool enable); + + void FillBases(const QVector &bases, const MeasurementDimension_p &dimension, QComboBox *control); + + QStringList DimensionLabels(const QVector &bases, const MeasurementDimension_p &dimension); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tape/dialogs/dialogrestrictdimension.ui b/src/app/tape/dialogs/dialogrestrictdimension.ui index 918dd785f..3aefc5815 100644 --- a/src/app/tape/dialogs/dialogrestrictdimension.ui +++ b/src/app/tape/dialogs/dialogrestrictdimension.ui @@ -6,44 +6,22 @@ 0 0 - 844 - 683 + 699 + 566 - Dialog + Restrict dimension + + + + :/tapeicon/64x64/logo.png:/tapeicon/64x64/logo.png - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - Dimension B: - - - - - + + Qt::Horizontal @@ -62,21 +40,11 @@ - - - - Qt::Horizontal - - - - 40 - 20 - - - + + - - + + Qt::Horizontal @@ -91,74 +59,73 @@ - - - Qt::Vertical + + + + 0 + 4 + - - - - 0 - 4 - - - - - - false - - - Restriction - - - - - - - - - Min: - - - - - - - Max: - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - + + QAbstractItemView::CurrentChanged|QAbstractItemView::SelectedClicked + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + + 24 + 24 + + + + + + + + false + + + Restriction + + + + + + Min: + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Max: + + + + + + + @@ -173,7 +140,9 @@ - + + + buttonBox diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index f404e88d3..de3ec5aca 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -2548,8 +2548,10 @@ void TMainWindow::InitDimensionsBaseValue() if (dimensions.size() > index) { MeasurementDimension_p dimension = dimensions.at(index); - name->setText(DimensionName(dimension->Type())+QChar(':')); - name->setToolTip(DimensionToolTip(dimension->Type(), dimension->IsCircumference())); + name->setText(VAbstartMeasurementDimension::DimensionName(dimension->Type())+QChar(':')); + name->setToolTip(VAbstartMeasurementDimension::DimensionToolTip(dimension->Type(), + dimension->IsCircumference(), + m->IsFullCircumference())); if (dimension->IsCircumference() || dimension->Type() == MeasurementDimension::X) { @@ -2591,10 +2593,10 @@ void TMainWindow::InitDimensionGradation(int index, const MeasurementDimension_p control->blockSignals(true); control->clear(); + const QVector bases = DimensionRestrictedValues(index, dimension); + if (dimension->Type() == MeasurementDimension::X) { - const QVector bases = DimensionRestrictedValues(index, dimension); - for(auto base : bases) { control->addItem(QString("%1 %2").arg(base).arg(unit), base); @@ -2602,8 +2604,6 @@ void TMainWindow::InitDimensionGradation(int index, const MeasurementDimension_p } else if (dimension->Type() == MeasurementDimension::Y) { - const QVector bases = dimension->ValidBases(); - for(auto base : bases) { if (dimension->IsCircumference()) @@ -2618,8 +2618,6 @@ void TMainWindow::InitDimensionGradation(int index, const MeasurementDimension_p } else if (dimension->Type() == MeasurementDimension::W || dimension->Type() == MeasurementDimension::Z) { - const QVector bases = dimension->ValidBases(); - for(auto base : bases) { control->addItem(QString("%1 %2").arg(fc ? base*2 : base).arg(unit), base); @@ -2653,13 +2651,15 @@ void TMainWindow::InitDimensionControls() if (name == nullptr) { - name = new QLabel(DimensionName(dimension->Type())+QChar(':')); + name = new QLabel(VAbstartMeasurementDimension::DimensionName(dimension->Type())+QChar(':')); } else { - name->setText(DimensionName(dimension->Type())+QChar(':')); + name->setText(VAbstartMeasurementDimension::DimensionName(dimension->Type())+QChar(':')); } - name->setToolTip(DimensionToolTip(dimension->Type(), dimension->IsCircumference())); + name->setToolTip(VAbstartMeasurementDimension::DimensionToolTip(dimension->Type(), + dimension->IsCircumference(), + m->IsFullCircumference())); if (control == nullptr) { @@ -2686,8 +2686,10 @@ void TMainWindow::InitDimesionShifts() { MeasurementDimension_p dimension = dimensions.at(index); - name->setText(tr("Shift (%1):").arg(DimensionName(dimension->Type()))); - name->setToolTip(DimensionToolTip(dimension->Type(), dimension->IsCircumference())); + name->setText(tr("Shift (%1):").arg(VAbstartMeasurementDimension::DimensionName(dimension->Type()))); + name->setToolTip(VAbstartMeasurementDimension::DimensionToolTip(dimension->Type(), + dimension->IsCircumference(), + m->IsFullCircumference())); } }; @@ -2709,7 +2711,7 @@ void TMainWindow::InitTable() { MeasurementDimension_p dimension = dimensions.at(0); ui->tableWidget->horizontalHeaderItem(ColumnShiftA)->setText( - tr("%1 shift").arg(DimensionName(dimension->Type()))); + tr("%1 shift").arg(VAbstartMeasurementDimension::DimensionName(dimension->Type()))); } if (dimensions.size() < 2) @@ -2720,7 +2722,7 @@ void TMainWindow::InitTable() { MeasurementDimension_p dimension = dimensions.at(1); ui->tableWidget->horizontalHeaderItem(ColumnShiftB)->setText( - tr("%1 shift").arg(DimensionName(dimension->Type()))); + tr("%1 shift").arg(VAbstartMeasurementDimension::DimensionName(dimension->Type()))); } if (dimensions.size() < 3) @@ -2731,7 +2733,7 @@ void TMainWindow::InitTable() { MeasurementDimension_p dimension = dimensions.at(2); ui->tableWidget->horizontalHeaderItem(ColumnShiftC)->setText( - tr("%1 shift").arg(DimensionName(dimension->Type()))); + tr("%1 shift").arg(VAbstartMeasurementDimension::DimensionName(dimension->Type()))); } } else @@ -3888,51 +3890,6 @@ void TMainWindow::SetCurrentPatternUnit() } } -//--------------------------------------------------------------------------------------------------------------------- -QString TMainWindow::DimensionName(MeasurementDimension type) -{ - switch(type) - { - case MeasurementDimension::X: - return tr("Height"); - case MeasurementDimension::Y: - return tr("Size"); - case MeasurementDimension::W: - return tr("Hip"); - case MeasurementDimension::Z: - return tr("Waist"); - default: - return QString(); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -QString TMainWindow::DimensionToolTip(MeasurementDimension type, bool circumference) -{ - const bool fc = m->IsFullCircumference(); - switch(type) - { - case MeasurementDimension::X: - return tr("Height"); - case MeasurementDimension::Y: - if (circumference) - { - return fc ? tr("Chest full circumference") : tr("Chest half circumference"); - } - else - { - return tr("Size"); - } - return circumference ? tr("Chest circumference") : tr("Size"); - case MeasurementDimension::W: - return fc ? tr("Hip full circumference") : tr("Hip half circumference"); - case MeasurementDimension::Z: - return fc ? tr("Waist full circumference") : tr("Waist half circumference"); - default: - return QString(); - } -} - //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::ShowDimensionControls() { diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index 8388f647a..f35022b9a 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -240,9 +240,6 @@ private: void SetCurrentPatternUnit(); - QString DimensionName(MeasurementDimension type); - QString DimensionToolTip(MeasurementDimension type, bool circumference); - void ShowDimensionControls(); void SetDimensionBases(); void SetCurrentDimensionValues(); diff --git a/src/libs/vformat/vdimensions.cpp b/src/libs/vformat/vdimensions.cpp index c5cd70ce5..4c5bbdbec 100644 --- a/src/libs/vformat/vdimensions.cpp +++ b/src/libs/vformat/vdimensions.cpp @@ -155,6 +155,50 @@ bool VAbstartMeasurementDimension::IsUnitsValid() return m_units == Unit::Cm || m_units == Unit::Mm || m_units == Unit::Inch; } +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstartMeasurementDimension::DimensionName(MeasurementDimension type) +{ + switch(type) + { + case MeasurementDimension::X: + return tr("Height"); + case MeasurementDimension::Y: + return tr("Size"); + case MeasurementDimension::W: + return tr("Hip"); + case MeasurementDimension::Z: + return tr("Waist"); + default: + return QString(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstartMeasurementDimension::DimensionToolTip(MeasurementDimension type, bool circumference, bool fc) +{ + switch(type) + { + case MeasurementDimension::X: + return tr("Height"); + case MeasurementDimension::Y: + if (circumference) + { + return fc ? tr("Chest full circumference") : tr("Chest half circumference"); + } + else + { + return tr("Size"); + } + return circumference ? tr("Chest circumference") : tr("Size"); + case MeasurementDimension::W: + return fc ? tr("Hip full circumference") : tr("Hip half circumference"); + case MeasurementDimension::Z: + return fc ? tr("Waist full circumference") : tr("Waist half circumference"); + default: + return QString(); + } +} + // VXMeasurementDimension //--------------------------------------------------------------------------------------------------------------------- VXMeasurementDimension::VXMeasurementDimension(Unit units) diff --git a/src/libs/vformat/vdimensions.h b/src/libs/vformat/vdimensions.h index 2b58e772d..fad7934bb 100644 --- a/src/libs/vformat/vdimensions.h +++ b/src/libs/vformat/vdimensions.h @@ -83,6 +83,9 @@ public: QVector ValidBases() const; QStringList ValidBasesList() const; + static QString DimensionName(MeasurementDimension type); + static QString DimensionToolTip(MeasurementDimension type, bool circumference, bool fc); + protected: Unit m_units{Unit::Cm}; int m_minValue{0}; diff --git a/src/libs/vmisc/share/resources/icon.qrc b/src/libs/vmisc/share/resources/icon.qrc index f4cff9ed5..72ed1fe0f 100644 --- a/src/libs/vmisc/share/resources/icon.qrc +++ b/src/libs/vmisc/share/resources/icon.qrc @@ -89,5 +89,9 @@ icon/32x32/broken_link@2x.png icon/32x32/link.png icon/32x32/link@2x.png + icon/24x24/star.png + icon/24x24/star@2x.png + icon/24x24/close.png + icon/24x24/close@2x.png diff --git a/src/libs/vmisc/share/resources/icon/24x24/close.png b/src/libs/vmisc/share/resources/icon/24x24/close.png new file mode 100644 index 0000000000000000000000000000000000000000..6847dbcada2de3f319e5b1425593d7c828842c21 GIT binary patch literal 548 zcmV+<0^9wGP)r zI$1Mag9AutQs?RDKi~j6YBY7gUdv3h!~}a#_ zYnVO@!o{29^835nVm-{pGEO}rGvmeJvYM>mW|{`!v+5O_4KWhuY#9r`Bj}O{%sg{# zaBpMBpR}h1?q5k?i3c7OL`wp202i8d*iXQGbpx#7N7(O4=TThqtRLYhK@WJRmb zBG0aX{l4%>$&~|^+rj|`<^0sJ*PimyNje6uw}E#^uGP5Xznh$Aj|@HnyTCXptMgd+ mdKP*1QcxJwg3)eSefa}%U;5IbRN}S(0000K|%ag*JJ5~P;)(egP+iNJfk>wE9p?%mz@ z`{mxMt6#&cQx;gdjUan!BXyeFWy1-4OUy-#cJ0AwFNjWTz5 znv~M+#tkX`Y{iGC7X+>!%8ouwuY7qX^;~uecoR5T^n;ga6r-+$7DwIs=HQ~JOa=}R zrer&pT^BeTnk1rx5e^8fJ0fIyB@&g%`sU!G7DwGA;Q$I5N0lX0!hR%d;Q*?#U zM5rVo(GMJ<;-`2d0JZ$s&es*n*T)< z3A~g>g&z~>TS6$K>VsU10uL1ETf!zn;GqJEO7wvD6i7tE05=N6lCXeV33Me=43t$F zx1;N~b}N-P!2ukbbeT+Zr?ba~9UK&=HgxJ&!)B~epnJ(U!c|)VLGyq7k@s3SmoksF zfLmQM!Rd{UnoxoGa65@Wf#l$3iDP@9&%*M355AfOv=Fu@4hcl4YM0v5$t!%0Dsk`& z;*``lrCj2|yAf4F`hG^ynHXNKZUuGM@?%3T17$33%!AiP)|f|wy6Nej@W4Jb2n|e4sx0fnYVO-uBVZ9?Lcqnq3V4B?TbwPpynU6b5ys}ckiHD zxSC)Num{h((oLS&ftJ`yknabl59uDpP@-DA$7~9MHJtjYjq*JfpvC+}%&vj;g9d;; zpwO+d4)B3Bu& z37QA;|7hMsHf6=yJVb7hD&ASpV_^4Rnr|R3ThV{^hlpKMmGj4N>?v?4qxlL16E@y> z8zy59%}Vum7;_oT!MGDOPYh^5Co%^}$CKy|0d_ibKnG3y3|{ZrPqXnYdjJsR2CP(F z4O8(BHtX9}ztR4Z;Wkc2sd#|wOrlsk!F7gk-9bzbNqU$;e4BC!R;ME456GsiSSyFP zNmaZB&|To@7Hh-;5)RqC_RmjXmR^52V%}OcUVBNeKMc&a*M_yB%m}nx7-W<4xb7nx t`Lz-+APz0}9H6;*i5$;u#Qzwc`wb>op(gGM+UNiP002ovPDHLkV1m=r9t;2g literal 0 HcmV?d00001 diff --git a/src/libs/vmisc/share/resources/icon/24x24/star@2x.png b/src/libs/vmisc/share/resources/icon/24x24/star@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..608044078206fe7aa72ece992ccb3c1477a0426d GIT binary patch literal 827 zcmV-B1H}A^P)iZf8U+yn<6CAw5185{)C{CN`!`)HX#-k zVnYy3L}Eo)+F@l)Bv^MLDO-tzFfAL)mJlI`KUG9Rnx^wc-D5EmVZ1ly%@k*KbI-Zo z_shAt_r3=Wgbf9&Z75jXh=!}%Jl}i}^a%8*G_EgHm-!$m+B469CFQAC_;8u}m`(YC~$n`wpCzVD#2REAn`IiF0F^eZcGk&W(ZpNHO#N=Pi=u zgWaIBh^0VKlR@KA#CU@v_aL&o0_N0kjPRVHF@Ld$2iBd!7S8Z@6o>{T|r9+ixJ3)CCl1YK;< z9MFY0^Qr))wYH&g0PC)njRmklQWzT>2Vj#8l1dCfds7#U??1p?TAS7-2f+2rfO#nt zuT=%WHqRJ96|HpqBK--#Kv&AceN_9nk&<=5Zp~>2I;&Ve!Puc(;ec|51E5~uK^53e z8=k$eW&nb(TVjMJL1$S=N2M`>cUfhN{py<>kF5U%WO7{DVn5zxF-FSM z9&`62>*IuMC|HMgEl{{u&rc_S-64%@?g4wJT=+Dq<~tPt*!}0zAmIQ2002ovPDHLk FV1kYiZUq1U literal 0 HcmV?d00001 diff --git a/src/libs/vpatterndb/variables/vmeasurement.h b/src/libs/vpatterndb/variables/vmeasurement.h index badc40980..2b3a708d1 100644 --- a/src/libs/vpatterndb/variables/vmeasurement.h +++ b/src/libs/vpatterndb/variables/vmeasurement.h @@ -119,7 +119,7 @@ public: static QStringList WholeListSizes(Unit patternUnit); static bool IsGradationSizeValid(const QString &size); static bool IsGradationHeightValid(const QString &height); - static QString CorrectionHash(qreal baseA, qreal baseB, qreal baseC); + static QString CorrectionHash(qreal baseA, qreal baseB=0, qreal baseC=0); private: QSharedDataPointer d; diff --git a/src/libs/vwidgets/vcomboboxdelegate.h b/src/libs/vwidgets/vcomboboxdelegate.h index 1cd27652d..301a39918 100644 --- a/src/libs/vwidgets/vcomboboxdelegate.h +++ b/src/libs/vwidgets/vcomboboxdelegate.h @@ -34,7 +34,7 @@ class VComboBoxDelegate : public QItemDelegate { Q_OBJECT public: - VComboBoxDelegate(const QStringList &items, QObject *parent = nullptr); + explicit VComboBoxDelegate(const QStringList &items, QObject *parent = nullptr); virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; diff --git a/src/libs/vwidgets/vdecorationaligningdelegate.cpp b/src/libs/vwidgets/vdecorationaligningdelegate.cpp new file mode 100644 index 000000000..f81974444 --- /dev/null +++ b/src/libs/vwidgets/vdecorationaligningdelegate.cpp @@ -0,0 +1,48 @@ +/************************************************************************ + ** + ** @file vdecorationaligningdelegate.cpp + ** @author Roman Telezhynskyi + ** @date 6 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 "vdecorationaligningdelegate.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +VDecorationAligningDelegate::VDecorationAligningDelegate(Qt::Alignment alignment, QObject *parent) + : QStyledItemDelegate(parent), m_alignment(alignment) +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VDecorationAligningDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + QIcon icon = QIcon(qvariant_cast(index.data(Qt::DecorationRole))); + + if (option.state & QStyle::State_Selected) + { + painter->fillRect(option.rect, option.palette.highlight()); + } + + icon.paint(painter, option.rect, m_alignment); +} diff --git a/src/libs/vwidgets/vdecorationaligningdelegate.h b/src/libs/vwidgets/vdecorationaligningdelegate.h new file mode 100644 index 000000000..2bfb424ac --- /dev/null +++ b/src/libs/vwidgets/vdecorationaligningdelegate.h @@ -0,0 +1,57 @@ +/************************************************************************ + ** + ** @file vdecorationaligningdelegate.h + ** @author Roman Telezhynskyi + ** @date 6 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 VDECORATIONALIGNINGDELEGATE_H +#define VDECORATIONALIGNINGDELEGATE_H + +#include + + + +class VDecorationAligningDelegate : public QStyledItemDelegate +{ + Q_OBJECT + +public: + explicit VDecorationAligningDelegate(Qt::Alignment alignment, QObject *parent = nullptr); + + Qt::Alignment Alignment() const; + + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + +private: + Q_DISABLE_COPY(VDecorationAligningDelegate) + Qt::Alignment const m_alignment; +}; + +//--------------------------------------------------------------------------------------------------------------------- +inline Qt::Alignment VDecorationAligningDelegate::Alignment() const +{ + return m_alignment; +} + +#endif // VDECORATIONALIGNINGDELEGATE_H diff --git a/src/libs/vwidgets/vwidgets.pri b/src/libs/vwidgets/vwidgets.pri index 602602a14..eaf29bd78 100644 --- a/src/libs/vwidgets/vwidgets.pri +++ b/src/libs/vwidgets/vwidgets.pri @@ -3,6 +3,7 @@ SOURCES += \ $$PWD/vcomboboxdelegate.cpp \ + $$PWD/vdecorationaligningdelegate.cpp \ $$PWD/velidedlabel.cpp \ $$PWD/vmaingraphicsscene.cpp \ $$PWD/vmaingraphicsview.cpp \ @@ -33,6 +34,7 @@ SOURCES += \ HEADERS += \ $$PWD/stable.h \ $$PWD/vcomboboxdelegate.h \ + $$PWD/vdecorationaligningdelegate.h \ $$PWD/velidedlabel.h \ $$PWD/vmaingraphicsscene.h \ $$PWD/vmaingraphicsview.h \ From 506ce6fb5e8008cd2bf0017b4ac942f77dca481c Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 7 Oct 2020 17:12:53 +0300 Subject: [PATCH 28/44] Redesign filtering bases. --- src/app/tape/tmainwindow.cpp | 76 ++++++-------------------------- src/libs/vformat/vdimensions.cpp | 41 +++++++++-------- src/libs/vformat/vdimensions.h | 1 + 3 files changed, 37 insertions(+), 81 deletions(-) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index de3ec5aca..7c7c673a7 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -4000,77 +4000,27 @@ void TMainWindow::SetCurrentDimensionValues() //--------------------------------------------------------------------------------------------------------------------- QVector TMainWindow::DimensionRestrictedValues(int index, const MeasurementDimension_p &dimension) { + QPair restriction; + if (index == 0) { return dimension->ValidBases(); } - - if (dimension->Type() == MeasurementDimension::X) + else if (index == 1) { + restriction = m->Restriction(currentDimensionA); + } + else + { + restriction = m->Restriction(currentDimensionA, currentDimensionB); + } + + if (restriction.first < dimension->MinValue() || restriction.second > dimension->MaxValue()) + { // invalid restriction return dimension->ValidBases(); } - else if (dimension->Type() == MeasurementDimension::Y) - { - const QPair restriction = m->Restriction(currentDimensionA); - VYMeasurementDimension restricted(dimension->Units(), restriction.first, restriction.second, dimension->Step()); - restricted.SetCircumference(dimension->IsCircumference()); - if (restriction.first < dimension->MinValue() || restriction.second > dimension->MaxValue() - || not restricted.IsValid()) - { // invalid restriction - return dimension->ValidBases(); - } - - return restricted.ValidBases(); - } - else if (dimension->Type() == MeasurementDimension::W) - { - QPair restriction; - - if (index == 1) - { - restriction = m->Restriction(currentDimensionA); - } - else - { - restriction = m->Restriction(currentDimensionA, currentDimensionB); - } - - VWMeasurementDimension restricted(dimension->Units(), restriction.first, restriction.second, dimension->Step()); - - if (restriction.first < dimension->MinValue() || restriction.second > dimension->MaxValue() - || not restricted.IsValid()) - { // invalid restriction - return dimension->ValidBases(); - } - - return restricted.ValidBases(); - } - else if (dimension->Type() == MeasurementDimension::Z) - { - QPair restriction; - - if (index == 1) - { - restriction = m->Restriction(currentDimensionA); - } - else - { - restriction = m->Restriction(currentDimensionA, currentDimensionB); - } - - VZMeasurementDimension restricted(dimension->Units(), restriction.first, restriction.second, dimension->Step()); - - if (restriction.first < dimension->MinValue() || restriction.second > dimension->MaxValue() - || not restricted.IsValid()) - { // invalid restriction - return dimension->ValidBases(); - } - - return restricted.ValidBases(); - } - - return QVector(); + return VAbstartMeasurementDimension::ValidBases(restriction.first, restriction.second, dimension->Step()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vformat/vdimensions.cpp b/src/libs/vformat/vdimensions.cpp index 4c5bbdbec..1063c5216 100644 --- a/src/libs/vformat/vdimensions.cpp +++ b/src/libs/vformat/vdimensions.cpp @@ -78,24 +78,7 @@ QVector VAbstartMeasurementDimension::ValidSteps() const //--------------------------------------------------------------------------------------------------------------------- QVector VAbstartMeasurementDimension::ValidBases() const { - QVector validBases; - int step = Step(); - - if (step < 0) - { - return validBases; - } - else if (step == 0) - { - step = 1; - } - - for (int value = MinValue(); value <= MaxValue(); value += step) - { - validBases.append(value); - } - - return validBases; + return VAbstartMeasurementDimension::ValidBases(m_minValue, m_maxValue, m_step); } //--------------------------------------------------------------------------------------------------------------------- @@ -111,6 +94,28 @@ QStringList VAbstartMeasurementDimension::ValidBasesList() const } +//--------------------------------------------------------------------------------------------------------------------- +QVector VAbstartMeasurementDimension::ValidBases(int min, int max, int step) +{ + QVector validBases; + + if (step < 0) + { + return validBases; + } + else if (step == 0) + { + step = 1; + } + + for (int value = min; value <= max; value += step) + { + validBases.append(value); + } + + return validBases; +} + //--------------------------------------------------------------------------------------------------------------------- bool VAbstartMeasurementDimension::IsRangeValid() { diff --git a/src/libs/vformat/vdimensions.h b/src/libs/vformat/vdimensions.h index fad7934bb..65873a0c6 100644 --- a/src/libs/vformat/vdimensions.h +++ b/src/libs/vformat/vdimensions.h @@ -83,6 +83,7 @@ public: QVector ValidBases() const; QStringList ValidBasesList() const; + static QVector ValidBases(int min, int max, int step); static QString DimensionName(MeasurementDimension type); static QString DimensionToolTip(MeasurementDimension type, bool circumference, bool fc); From 1bb0a896f5ae2782df12212be3f4ef8aff2655ff Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 7 Oct 2020 17:14:12 +0300 Subject: [PATCH 29/44] Update base lists after changing restrictions. --- src/app/tape/tmainwindow.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 7c7c673a7..49eaad996 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -2205,6 +2205,7 @@ void TMainWindow::RestrictSecondDimesion() m->SetRestrictions(dialog.Restrictions()); MeasurementsWereSaved(false); + DimensionABaseChanged(); // trigger refresh } //--------------------------------------------------------------------------------------------------------------------- @@ -2224,6 +2225,7 @@ void TMainWindow::RestrictThirdDimesion() m->SetRestrictions(dialog.Restrictions()); MeasurementsWereSaved(false); + DimensionABaseChanged(); // trigger refresh } //--------------------------------------------------------------------------------------------------------------------- @@ -2624,6 +2626,10 @@ void TMainWindow::InitDimensionGradation(int index, const MeasurementDimension_p } } + // after initialization the current index is 0. The signal for changing the index will not be triggered if not make + // it invalid first + control->setCurrentIndex(-1); + int i = control->findData(current); if (i != -1) { From f072ee588810981efbac3e27135b9b878e294613 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 7 Oct 2020 18:09:27 +0300 Subject: [PATCH 30/44] Correct way to apply restrictions. --- .../tape/dialogs/dialogrestrictdimension.cpp | 35 ++++++++++++++----- src/app/tape/tmainwindow.cpp | 24 ++++++++----- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/src/app/tape/dialogs/dialogrestrictdimension.cpp b/src/app/tape/dialogs/dialogrestrictdimension.cpp index 7e66555c7..dde1feca7 100644 --- a/src/app/tape/dialogs/dialogrestrictdimension.cpp +++ b/src/app/tape/dialogs/dialogrestrictdimension.cpp @@ -453,31 +453,50 @@ void DialogRestrictDimension::AddCell(int row, int column, int rowValue, int col int base1 = 0; int base2 = 0; + MeasurementDimension_p dimension; + QVector bases; if (m_oneDimesionRestriction) { base1 = rowValue; + + if (m_dimensions.size() >= 2) + { + dimension = m_dimensions.at(1); + bases = dimension->ValidBases(); + } } else { base1 = ui->comboBoxDimensionA->currentData().toInt(); base2 = rowValue; + + if (m_dimensions.size() >= 3) + { + dimension = m_dimensions.at(2); + bases = dimension->ValidBases(); + } } QPair restriction = m_restrictions.value(VMeasurement::CorrectionHash(base1, base2), QPair(0, 0)); + int min = INT32_MIN; + int max = INT32_MAX; - bool leftRestriction = true; - if (restriction.first > 0 && restriction.first <= restriction.second) + if (not dimension.isNull()) { - leftRestriction = columnValue >= restriction.first; + min = bases.indexOf(restriction.first) != -1 ? restriction.first : dimension->MinValue(); + max = bases.indexOf(restriction.second) != -1 ? restriction.second : dimension->MaxValue(); + + if (max < min) + { + min = dimension->MinValue(); + max = dimension->MaxValue(); + } } - bool rightRestriction = true; - if (restriction.second > 0 && restriction.second >= restriction.first) - { - rightRestriction = columnValue <= restriction.second; - } + const bool leftRestriction = columnValue >= min; + const bool rightRestriction = columnValue <= max; if (leftRestriction && rightRestriction) { diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 49eaad996..248d538f1 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -333,8 +333,9 @@ bool TMainWindow::LoadFile(const QString &path) mUnit = m->MUnit(); pUnit = mUnit; - currentDimensionB = m->DimensionABase(); - currentDimensionA = m->DimensionBBase(); + currentDimensionA = m->DimensionABase(); + currentDimensionB = m->DimensionBBase(); + currentDimensionC = m->DimensionCBase(); ui->labelToolTip->setVisible(false); ui->tabWidget->setVisible(true); @@ -3424,8 +3425,9 @@ bool TMainWindow::LoadFromExistingFile(const QString &path) mUnit = m->MUnit(); pUnit = mUnit; - currentDimensionA = m->DimensionBBase(); - currentDimensionB = m->DimensionABase(); + currentDimensionA = m->DimensionABase(); + currentDimensionB = m->DimensionBBase(); + currentDimensionC = m->DimensionCBase(); ui->labelToolTip->setVisible(false); ui->tabWidget->setVisible(true); @@ -4021,12 +4023,18 @@ QVector TMainWindow::DimensionRestrictedValues(int index, const Measurement restriction = m->Restriction(currentDimensionA, currentDimensionB); } - if (restriction.first < dimension->MinValue() || restriction.second > dimension->MaxValue()) - { // invalid restriction - return dimension->ValidBases(); + const QVector bases = dimension->ValidBases(); + + int min = bases.indexOf(restriction.first) != -1 ? restriction.first : dimension->MinValue(); + int max = bases.indexOf(restriction.second) != -1 ? restriction.second : dimension->MaxValue(); + + if (min > max) + { + min = dimension->MinValue(); + max = dimension->MaxValue(); } - return VAbstartMeasurementDimension::ValidBases(restriction.first, restriction.second, dimension->Step()); + return VAbstartMeasurementDimension::ValidBases(min, max, dimension->Step()); } //--------------------------------------------------------------------------------------------------------------------- From eaf69753315e42c19b63ef2b452ea75ae33e6874 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 8 Oct 2020 13:34:38 +0300 Subject: [PATCH 31/44] 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 From 7ba9b380b74ec15ae1a37db24967ed2f7e2840dd Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 10 Oct 2020 19:31:23 +0300 Subject: [PATCH 32/44] Redesign measurements import. --- .../dialogs/dialogmeasurementscsvcolumns.cpp | 916 ++++++++++++++++++ .../dialogs/dialogmeasurementscsvcolumns.h | 149 +++ .../dialogs/dialogmeasurementscsvcolumns.ui | 204 ++++ src/app/tape/tape.pri | 3 + src/app/tape/tmainwindow.cpp | 125 ++- src/app/tape/tmainwindow.h | 4 +- 6 files changed, 1371 insertions(+), 30 deletions(-) create mode 100644 src/app/tape/dialogs/dialogmeasurementscsvcolumns.cpp create mode 100644 src/app/tape/dialogs/dialogmeasurementscsvcolumns.h create mode 100644 src/app/tape/dialogs/dialogmeasurementscsvcolumns.ui diff --git a/src/app/tape/dialogs/dialogmeasurementscsvcolumns.cpp b/src/app/tape/dialogs/dialogmeasurementscsvcolumns.cpp new file mode 100644 index 000000000..44d496507 --- /dev/null +++ b/src/app/tape/dialogs/dialogmeasurementscsvcolumns.cpp @@ -0,0 +1,916 @@ +/************************************************************************ + ** + ** @file dialogmeasurementscsvcolumns.cpp + ** @author Roman Telezhynskyi + ** @date 9 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 "dialogmeasurementscsvcolumns.h" +#include "ui_dialogmeasurementscsvcolumns.h" + +#include "../vmisc/qxtcsvmodel.h" +#include "../vtools/dialogs/dialogtoolbox.h" + +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- +DialogMeasurementsCSVColumns::DialogMeasurementsCSVColumns(const QString &filename, MeasurementsType type, + QWidget *parent) : + QDialog(parent), + ui(new Ui::DialogMeasurementsCSVColumns), + m_fileName{filename}, + m_type(type) +{ + ui->setupUi(this); + + HackColumnControls(); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogMeasurementsCSVColumns::DialogMeasurementsCSVColumns(const QString &filename, MeasurementsType type, + const QList &dimensions, + QWidget *parent) : + QDialog(parent), + ui(new Ui::DialogMeasurementsCSVColumns), + m_fileName{filename}, + m_type(type), + m_dimensions{dimensions} +{ + ui->setupUi(this); + + HackColumnControls(); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogMeasurementsCSVColumns::~DialogMeasurementsCSVColumns() +{ + qDeleteAll(m_hackedWidgets); + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMeasurementsCSVColumns::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::LanguageChange) + { + // retranslate designer form (single inheritance approach) + ui->retranslateUi(this); + + RetranslateLabels(); + InitColumnsControls(); + InitImportHeaders(); + ShowImportPreview(); + CheckStatus(); + } + + // remember to call base class implementation + QDialog::changeEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMeasurementsCSVColumns::showEvent(QShowEvent *event) +{ + QDialog::showEvent( event ); + if ( event->spontaneous() ) + { + return; + } + + if (m_isInitialized) + { + return; + } + // do your init stuff here + + if (not m_fileName.isEmpty()) + { + InitColumnsMap(); + ShowInputPreview(); + InitColumnsControls(); + RetranslateLabels(); + InitColumnsControls(); + SetDefaultColumns(); + InitImportHeaders(); + ShowImportPreview(); + + connect(ui->comboBoxName, QOverload::of(&QComboBox::currentIndexChanged), + this, &DialogMeasurementsCSVColumns::ColumnChanged); + connect(ui->comboBoxValue, QOverload::of(&QComboBox::currentIndexChanged), + this, &DialogMeasurementsCSVColumns::ColumnChanged); + + if (m_type == MeasurementsType::Multisize) + { + if (m_dimensions.size() > 0) + { + connect(ui->comboBoxShiftA, QOverload::of(&QComboBox::currentIndexChanged), + this, &DialogMeasurementsCSVColumns::ColumnChanged); + } + + if (m_dimensions.size() > 1) + { + connect(ui->comboBoxShiftB, QOverload::of(&QComboBox::currentIndexChanged), + this, &DialogMeasurementsCSVColumns::ColumnChanged); + } + + if (m_dimensions.size() > 2) + { + connect(ui->comboBoxShiftC, QOverload::of(&QComboBox::currentIndexChanged), + this, &DialogMeasurementsCSVColumns::ColumnChanged); + } + } + + + connect(ui->comboBoxFullName, QOverload::of(&QComboBox::currentIndexChanged), + this, &DialogMeasurementsCSVColumns::ColumnChanged); + connect(ui->comboBoxDescription, QOverload::of(&QComboBox::currentIndexChanged), + this, &DialogMeasurementsCSVColumns::ColumnChanged); + + CheckStatus(); + } + + m_isInitialized = true;//first show windows are held +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMeasurementsCSVColumns::ColumnChanged() +{ + auto *control = qobject_cast(sender()); + + auto SaveColum = [this, control](int column) + { + m_columnsMap[column] = control->currentData().toInt(); + ShowImportPreview(); + CheckStatus(); + }; + + if (control == ui->comboBoxName) + { + if (m_type == MeasurementsType::Individual) + { + SaveColum(static_cast(IndividualMeasurementsColumns::Name)); + } + else + { + SaveColum(static_cast(MultisizeMeasurementsColumns::Name)); + } + } + else if (control == ui->comboBoxValue) + { + if (m_type == MeasurementsType::Individual) + { + SaveColum(static_cast(IndividualMeasurementsColumns::Value)); + } + else + { + SaveColum(static_cast(MultisizeMeasurementsColumns::BaseValue)); + } + } + else if (control == ui->comboBoxShiftA) + { + SaveColum(static_cast(MultisizeMeasurementsColumns::ShiftA)); + } + else if (control == ui->comboBoxShiftB) + { + SaveColum(static_cast(MultisizeMeasurementsColumns::ShiftB)); + } + else if (control == ui->comboBoxShiftC) + { + SaveColum(static_cast(MultisizeMeasurementsColumns::ShiftC)); + } + else if (control == ui->comboBoxFullName) + { + if (m_type == MeasurementsType::Individual) + { + SaveColum(static_cast(IndividualMeasurementsColumns::FullName)); + } + else + { + SaveColum(static_cast(MultisizeMeasurementsColumns::FullName)); + } + } + else if (control == ui->comboBoxDescription) + { + if (m_type == MeasurementsType::Individual) + { + SaveColum(static_cast(IndividualMeasurementsColumns::Description)); + } + else + { + SaveColum(static_cast(MultisizeMeasurementsColumns::Description)); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +bool DialogMeasurementsCSVColumns::ColumnMandatory(int column) const +{ + if (m_type == MeasurementsType::Individual) + { + return column < static_cast(IndividualMeasurementsColumns::FullName); + } + else + { + int mandatory = 3; + + if (m_dimensions.size() > 1) + { + mandatory += qMin(m_dimensions.size(), 2); + } + + return static_cast(column) < mandatory; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogMeasurementsCSVColumns::ColumnHeader(int column) const +{ + if (m_type == MeasurementsType::Individual) + { + const auto individualColumn = static_cast(column); + switch(individualColumn) + { + case IndividualMeasurementsColumns::Name: + return tr("Name"); + case IndividualMeasurementsColumns::Value: + return tr("Value"); + case IndividualMeasurementsColumns::FullName: + return tr("Full name"); + case IndividualMeasurementsColumns::Description: + return tr("Description"); + default: + return QString(); + } + } + else + { + const auto multisizeColumn = static_cast(column); + switch(multisizeColumn) + { + case MultisizeMeasurementsColumns::Name: + return tr("Name"); + case MultisizeMeasurementsColumns::BaseValue: + return tr("Base value"); + case MultisizeMeasurementsColumns::ShiftA: + if (m_dimensions.size() > 0) + { + MeasurementDimension_p dimension = m_dimensions.at(0); + return tr("Shift (%1):").arg(VAbstartMeasurementDimension::DimensionName(dimension->Type())); + } + else + { + return "Shift A"; + } + case MultisizeMeasurementsColumns::ShiftB: + if (m_dimensions.size() > 1) + { + MeasurementDimension_p dimension = m_dimensions.at(1); + return tr("Shift (%1):").arg(VAbstartMeasurementDimension::DimensionName(dimension->Type())); + } + else + { + return "Shift B"; + } + case MultisizeMeasurementsColumns::ShiftC: + if (m_dimensions.size() > 2) + { + MeasurementDimension_p dimension = m_dimensions.at(2); + return tr("Shift (%1):").arg(VAbstartMeasurementDimension::DimensionName(dimension->Type())); + } + else + { + return "Shift C"; + } + case MultisizeMeasurementsColumns::FullName: + return tr("Full name"); + case MultisizeMeasurementsColumns::Description: + return tr("Description"); + default: + return QString(); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +int DialogMeasurementsCSVColumns::ImportColumnCount() const +{ + if (m_type == MeasurementsType::Individual) + { + return static_cast(IndividualMeasurementsColumns::LAST_DO_NOT_USE); + } + else + { + return static_cast(MultisizeMeasurementsColumns::LAST_DO_NOT_USE); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +int DialogMeasurementsCSVColumns::MinimumColumns() const +{ + if (m_type == MeasurementsType::Individual) + { + return 2; + } + else + { + int mandatory = 3; + + if (m_dimensions.size() > 1) + { + mandatory += qMin(m_dimensions.size(), 2); + } + + return mandatory; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +bool DialogMeasurementsCSVColumns::ColumnsValid() +{ + ChangeColor(ui->labelName, OkColor(this)); + ChangeColor(ui->labelValue, OkColor(this)); + if (m_type == MeasurementsType::Multisize) + { + if (m_dimensions.size() > 0) + { + ChangeColor(ui->labelShiftA, OkColor(this)); + } + + if (m_dimensions.size() > 1) + { + ChangeColor(ui->labelShiftB, OkColor(this)); + } + + if (m_dimensions.size() > 2) + { + ChangeColor(ui->labelShiftC, OkColor(this)); + } + } + ChangeColor(ui->labelFullName, OkColor(this)); + ChangeColor(ui->labelDescription, OkColor(this)); + + auto ColumnValid = [this](int column) + { + int value = m_columnsMap.at(column); + + if (value == -1 && not ColumnMandatory(column)) + { + return true; + } + + for (int c=0; c < m_columnsMap.size(); ++c) + { + if (c == column) + { + continue; + } + + if (value == m_columnsMap.at(c)) + { + return false; + } + } + + return true; + }; + + bool columnNameFlag = true; + bool columnValueFlag = true; + bool columnShiftAFlag = true; + bool columnShiftBFlag = true; + bool columnShiftCFlag = true; + bool columnFullNameFlag = true; + bool columnDescriptionFlag = true; + + const QColor errorColor = Qt::red; + + + if (m_type == MeasurementsType::Multisize) + { + if (not ColumnValid(static_cast(MultisizeMeasurementsColumns::Name))) + { + ChangeColor(ui->labelName, errorColor); + columnNameFlag = false; + } + } + else + { + if (not ColumnValid(static_cast(IndividualMeasurementsColumns::Name))) + { + ChangeColor(ui->labelName, errorColor); + columnNameFlag = false; + } + } + + if (m_type == MeasurementsType::Multisize) + { + if (not ColumnValid(static_cast(MultisizeMeasurementsColumns::BaseValue))) + { + ChangeColor(ui->labelValue, errorColor); + columnValueFlag = false; + } + } + else + { + if (not ColumnValid(static_cast(IndividualMeasurementsColumns::Value))) + { + ChangeColor(ui->labelValue, errorColor); + columnValueFlag = false; + } + } + + if (m_type == MeasurementsType::Multisize) + { + if (m_dimensions.size() > 0) + { + if (not ColumnValid(static_cast(MultisizeMeasurementsColumns::ShiftA))) + { + ChangeColor(ui->labelShiftA, errorColor); + columnShiftAFlag = false; + } + } + + if (m_dimensions.size() > 1) + { + if (not ColumnValid(static_cast(MultisizeMeasurementsColumns::ShiftB))) + { + ChangeColor(ui->labelShiftB, errorColor); + columnShiftBFlag = false; + } + } + + if (m_dimensions.size() > 2) + { + if (not ColumnValid(static_cast(MultisizeMeasurementsColumns::ShiftC))) + { + ChangeColor(ui->labelShiftC, errorColor); + columnShiftCFlag = false; + } + } + } + + if (not ColumnValid(m_type == MeasurementsType::Multisize + ? static_cast(MultisizeMeasurementsColumns::FullName) + : static_cast(IndividualMeasurementsColumns::FullName))) + { + ChangeColor(ui->labelFullName, errorColor); + columnFullNameFlag = false; + } + + if (not ColumnValid(m_type == MeasurementsType::Multisize + ? static_cast(MultisizeMeasurementsColumns::Description) + : static_cast(IndividualMeasurementsColumns::Description))) + { + ChangeColor(ui->labelDescription, errorColor); + columnDescriptionFlag = false; + } + + return columnNameFlag && columnValueFlag && columnShiftAFlag && columnShiftBFlag && columnShiftCFlag && + columnFullNameFlag && columnDescriptionFlag; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMeasurementsCSVColumns::InitColumnsMap() +{ + QSharedPointer csv = DialogMeasurementsCSVColumns::CSVModel(); + m_columnsMap.clear(); + + auto InitColumn = [this, csv](int column, bool forceSkip=false) + { + if (forceSkip) + { + m_columnsMap[column] = -1; + } + else + { + if (ColumnMandatory(column)) + { + m_columnsMap[column] = column; + } + else + { + m_columnsMap[column] = csv->columnCount() >= column ? column : -1; + } + } + }; + + if (m_type == MeasurementsType::Individual) + { + m_columnsMap.resize(static_cast(IndividualMeasurementsColumns::LAST_DO_NOT_USE)); + + for(int column = 0; column < static_cast(IndividualMeasurementsColumns::LAST_DO_NOT_USE); ++column) + { + InitColumn(column); + } + } + else + { + m_columnsMap.resize(static_cast(MultisizeMeasurementsColumns::LAST_DO_NOT_USE)); + + InitColumn(static_cast(MultisizeMeasurementsColumns::Name)); + InitColumn(static_cast(MultisizeMeasurementsColumns::BaseValue)); + InitColumn(static_cast(MultisizeMeasurementsColumns::ShiftA)); + InitColumn(static_cast(MultisizeMeasurementsColumns::ShiftB), m_dimensions.size() < 2); + InitColumn(static_cast(MultisizeMeasurementsColumns::ShiftC), m_dimensions.size() < 3); + InitColumn(static_cast(MultisizeMeasurementsColumns::FullName)); + InitColumn(static_cast(MultisizeMeasurementsColumns::Description)); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMeasurementsCSVColumns::InitColumnsControls() +{ + const int inputColumnCount = CSVModel()->columnCount(); + + auto InitControl = [this, inputColumnCount](QComboBox *control, int column) + { + SCASSERT(control != nullptr) + + int currentColumn = -2; + int index = control->currentIndex(); + if (index != -1) + { + currentColumn = control->currentData().toInt(); + } + + control->blockSignals(true); + control->clear(); + + for(int i=0; i < inputColumnCount; ++i) + { + control->addItem(QString::number(i+1), i); + } + + if (not ColumnMandatory(column)) + { + control->addItem(tr("Skip"), -1); + } + + control->setCurrentIndex(-1); + + index = control->findData(currentColumn); + if (index != -1) + { + control->setCurrentIndex(index); + control->blockSignals(false); + } + else + { + control->blockSignals(false); + control->setCurrentIndex(0); + } + }; + + if (m_type == MeasurementsType::Individual) + { + InitControl(ui->comboBoxName, static_cast(IndividualMeasurementsColumns::Name)); + InitControl(ui->comboBoxValue, static_cast(IndividualMeasurementsColumns::Value)); + InitControl(ui->comboBoxFullName, static_cast(IndividualMeasurementsColumns::FullName)); + InitControl(ui->comboBoxDescription, static_cast(IndividualMeasurementsColumns::Description)); + } + else + { + InitControl(ui->comboBoxName, static_cast(MultisizeMeasurementsColumns::Name)); + InitControl(ui->comboBoxValue, static_cast(MultisizeMeasurementsColumns::BaseValue)); + + if (m_dimensions.size() > 0) + { + InitControl(ui->comboBoxShiftA, static_cast(MultisizeMeasurementsColumns::ShiftA)); + } + + if (m_dimensions.size() > 1) + { + InitControl(ui->comboBoxShiftB, static_cast(MultisizeMeasurementsColumns::ShiftB)); + } + + if (m_dimensions.size() > 2) + { + InitControl(ui->comboBoxShiftC, static_cast(MultisizeMeasurementsColumns::ShiftC)); + } + + InitControl(ui->comboBoxFullName, static_cast(MultisizeMeasurementsColumns::FullName)); + InitControl(ui->comboBoxDescription, static_cast(MultisizeMeasurementsColumns::Description)); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMeasurementsCSVColumns::InitImportHeaders() +{ + if (m_fileName.isEmpty()) + { + return; + } + + const int columns = ImportColumnCount(); + + ui->tableWidgetImport->clear(); + ui->tableWidgetImport->setColumnCount(columns); + + auto AddHeader = [this](int column, bool visible=true) + { + QTableWidgetItem *header = new QTableWidgetItem(ColumnHeader(column)); + ui->tableWidgetImport->setHorizontalHeaderItem(column, header); + ui->tableWidgetImport->setColumnHidden(column, not visible); + }; + + if (m_type == MeasurementsType::Individual) + { + AddHeader(static_cast(IndividualMeasurementsColumns::Name)); + AddHeader(static_cast(IndividualMeasurementsColumns::Value)); + AddHeader(static_cast(IndividualMeasurementsColumns::FullName)); + AddHeader(static_cast(IndividualMeasurementsColumns::Description)); + } + else + { + AddHeader(static_cast(MultisizeMeasurementsColumns::Name)); + AddHeader(static_cast(MultisizeMeasurementsColumns::BaseValue)); + AddHeader(static_cast(MultisizeMeasurementsColumns::ShiftA), m_dimensions.size() > 0); + AddHeader(static_cast(MultisizeMeasurementsColumns::ShiftB), m_dimensions.size() > 1); + AddHeader(static_cast(MultisizeMeasurementsColumns::ShiftC), m_dimensions.size() > 2); + AddHeader(static_cast(MultisizeMeasurementsColumns::FullName)); + AddHeader(static_cast(MultisizeMeasurementsColumns::Description)); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QSharedPointer DialogMeasurementsCSVColumns::CSVModel() const +{ + return QSharedPointer::create(m_fileName, nullptr, m_withHeader, m_separator, m_codec); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMeasurementsCSVColumns::ShowInputPreview() +{ + if (m_fileName.isEmpty()) + { + return; + } + + QSharedPointer csv = DialogMeasurementsCSVColumns::CSVModel(); + + const int columns = csv->columnCount(); + const int rows = csv->rowCount(); + + ui->tableWidgetInput->clear(); + ui->tableWidgetInput->setColumnCount(columns); + ui->tableWidgetInput->setRowCount(rows); + + ui->tableWidgetInput->horizontalHeader()->setVisible(m_withHeader); + if (m_withHeader) + { + for(int column=0; columnheaderText(column)); + header->setToolTip(QString::number(column+1)); + ui->tableWidgetInput->setHorizontalHeaderItem(column, header); + } + } + + for (int row=0; row < rows; ++row) + { + for(int column=0; columntext(row, column); + QTableWidgetItem *item = new QTableWidgetItem(text); + item->setToolTip(text); + + // set the item non-editable (view only), and non-selectable + Qt::ItemFlags flags = item->flags(); + flags &= ~(Qt::ItemIsEditable); // reset/clear the flag + item->setFlags(flags); + + ui->tableWidgetInput->setItem(row, column, item); + } + } + + ui->tableWidgetInput->resizeColumnsToContents(); + ui->tableWidgetInput->resizeRowsToContents(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMeasurementsCSVColumns::ShowImportPreview() +{ + if (m_fileName.isEmpty()) + { + return; + } + + QSharedPointer csv = DialogMeasurementsCSVColumns::CSVModel(); + + const int importColumns = ImportColumnCount(); + const int columns = csv->columnCount(); + const int rows = csv->rowCount(); + + ui->tableWidgetImport->clearContents(); + ui->tableWidgetImport->setRowCount(rows); + + for (int row=0; row < rows; ++row) + { + for(int column=0; column < importColumns; ++column) + { + const int tableColumn = m_columnsMap.at(column); + if (tableColumn >= 0 && tableColumn < columns) + { + const QString text = csv->text(row, tableColumn); + QTableWidgetItem *item = new QTableWidgetItem(text); + item->setToolTip(text); + + // set the item non-editable (view only), and non-selectable + Qt::ItemFlags flags = item->flags(); + flags &= ~(Qt::ItemIsEditable); // reset/clear the flag + item->setFlags(flags); + + ui->tableWidgetImport->setItem(row, column, item); + } + } + } + + ui->tableWidgetImport->resizeColumnsToContents(); + ui->tableWidgetImport->resizeRowsToContents(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMeasurementsCSVColumns::HackColumnControls() +{ + if (m_type == MeasurementsType::Individual) + { + HackWidget(&ui->labelShiftA); + HackWidget(&ui->labelShiftB); + HackWidget(&ui->labelShiftC); + + HackWidget(&ui->comboBoxShiftA); + HackWidget(&ui->comboBoxShiftB); + HackWidget(&ui->comboBoxShiftC); + } + else + { + if (m_dimensions.size() < 2) + { + HackWidget(&ui->labelShiftB); + HackWidget(&ui->comboBoxShiftB); + } + + if (m_dimensions.size() < 3) + { + HackWidget(&ui->labelShiftC); + HackWidget(&ui->comboBoxShiftC); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMeasurementsCSVColumns::RetranslateLabels() +{ + ui->labelName->setText(tr("Name") + "*:"); + + if (m_type == MeasurementsType::Individual) + { + ui->labelValue->setText(tr("Value") + "*:"); + } + else + { + ui->labelValue->setText(tr("Base value") + "*:"); + + if (m_dimensions.size() > 0) + { + MeasurementDimension_p dimension = m_dimensions.at(0); + ui->labelShiftA->setText(tr("Shift (%1)*:") + .arg(VAbstartMeasurementDimension::DimensionName(dimension->Type()))); + } + + if (m_dimensions.size() > 1) + { + MeasurementDimension_p dimension = m_dimensions.at(1); + ui->labelShiftB->setText(tr("Shift (%1)*:") + .arg(VAbstartMeasurementDimension::DimensionName(dimension->Type()))); + } + + if (m_dimensions.size() > 2) + { + MeasurementDimension_p dimension = m_dimensions.at(2); + ui->labelShiftC->setText(tr("Shift (%1)*:") + .arg(VAbstartMeasurementDimension::DimensionName(dimension->Type()))); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMeasurementsCSVColumns::SetDefaultColumns() +{ + auto SetDefault = [this](QComboBox *control, int column) + { + SCASSERT(control != nullptr) + + int index = control->findData(m_columnsMap.at(column)); + if (index != -1) + { + control->setCurrentIndex(index); + } + }; + + if (m_type == MeasurementsType::Individual) + { + SetDefault(ui->comboBoxName, static_cast(IndividualMeasurementsColumns::Name)); + SetDefault(ui->comboBoxValue, static_cast(IndividualMeasurementsColumns::Value)); + SetDefault(ui->comboBoxFullName, static_cast(IndividualMeasurementsColumns::FullName)); + SetDefault(ui->comboBoxDescription, static_cast(IndividualMeasurementsColumns::Description)); + } + else + { + SetDefault(ui->comboBoxName, static_cast(MultisizeMeasurementsColumns::Name)); + SetDefault(ui->comboBoxValue, static_cast(MultisizeMeasurementsColumns::BaseValue)); + + if (m_dimensions.size() > 0) + { + SetDefault(ui->comboBoxShiftA, static_cast(MultisizeMeasurementsColumns::ShiftA)); + } + + if (m_dimensions.size() > 1) + { + SetDefault(ui->comboBoxShiftB, static_cast(MultisizeMeasurementsColumns::ShiftB)); + } + + if (m_dimensions.size() > 2) + { + SetDefault(ui->comboBoxShiftC, static_cast(MultisizeMeasurementsColumns::ShiftC)); + } + + SetDefault(ui->comboBoxFullName, static_cast(MultisizeMeasurementsColumns::FullName)); + SetDefault(ui->comboBoxDescription, static_cast(MultisizeMeasurementsColumns::Description)); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMeasurementsCSVColumns::CheckStatus() +{ + auto SetStatus = [this](bool status) + { + QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok); + SCASSERT(bOk != nullptr) + bOk->setEnabled(status); + }; + + if (m_fileName.isEmpty()) + { + SetStatus(false); + ui->labelStatus->setText(tr("File path is empty")); + return; + } + + QSharedPointer csv = DialogMeasurementsCSVColumns::CSVModel(); + + const int columns = csv->columnCount(); + if (columns < MinimumColumns()) + { + SetStatus(false); + ui->labelStatus->setText(tr("Not enough columns")); + return; + } + + const int rows = csv->rowCount(); + if (rows < 1) + { + SetStatus(false); + ui->labelStatus->setText(tr("Not enough data to import")); + return; + } + + if (not ColumnsValid()) + { + SetStatus(false); + ui->labelStatus->setText(tr("Please, select unique number for each column")); + return; + } + + SetStatus(true); + ui->labelStatus->setText(tr("Ready")); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void DialogMeasurementsCSVColumns::HackWidget(T **widget) +{ + delete *widget; + *widget = new T(); + m_hackedWidgets.append(*widget); +} diff --git a/src/app/tape/dialogs/dialogmeasurementscsvcolumns.h b/src/app/tape/dialogs/dialogmeasurementscsvcolumns.h new file mode 100644 index 000000000..5745476e9 --- /dev/null +++ b/src/app/tape/dialogs/dialogmeasurementscsvcolumns.h @@ -0,0 +1,149 @@ +/************************************************************************ + ** + ** @file dialogmeasurementscsvcolumns.h + ** @author Roman Telezhynskyi + ** @date 9 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 DIALOGMEASUREMENTSCSVCOLUMNS_H +#define DIALOGMEASUREMENTSCSVCOLUMNS_H + +#include + +#include "../vformat/vdimensions.h" + +class QxtCsvModel; + +enum class IndividualMeasurementsColumns: qint8 +{ + Name = 0, + Value = 1, + FullName = 2, // optional + Description = 3, // optional + LAST_DO_NOT_USE = 4 +}; + +enum class MultisizeMeasurementsColumns: qint8 +{ + Name = 0, + BaseValue = 1, + ShiftA = 2, + ShiftB = 3, // optional if not required + ShiftC = 4, // optional if not required + FullName = 5, // optional + Description = 6, // optional + LAST_DO_NOT_USE = 7 +}; + + +namespace Ui { +class DialogMeasurementsCSVColumns; +} + +class DialogMeasurementsCSVColumns : public QDialog +{ + Q_OBJECT + +public: + DialogMeasurementsCSVColumns(const QString &filename, MeasurementsType type, QWidget *parent = nullptr); + DialogMeasurementsCSVColumns(const QString &filename, MeasurementsType type, + const QList &dimensions, QWidget *parent = nullptr); + virtual ~DialogMeasurementsCSVColumns(); + + QVector ColumnsMap() const; + + void SetWithHeader(bool withHeader); + void SetSeparator(const QChar &separator); + void SetCodec(QTextCodec *codec); + +protected: + virtual void changeEvent(QEvent* event) override; + virtual void showEvent(QShowEvent *event) override; + +private slots: + void ColumnChanged(); + +private: + Q_DISABLE_COPY(DialogMeasurementsCSVColumns) + Ui::DialogMeasurementsCSVColumns *ui; + bool m_isInitialized{false}; + QString m_fileName; + bool m_withHeader{false}; + QChar m_separator{','}; + QTextCodec *m_codec{nullptr}; + QVector m_columnsMap{}; + MeasurementsType m_type; + QList m_dimensions{}; + QVector m_hackedWidgets{}; + + bool ColumnMandatory(int column) const; + QString ColumnHeader(int column) const; + int ImportColumnCount() const; + int MinimumColumns() const; + bool ColumnsValid(); + + void InitColumnsMap(); + void InitColumnsControls(); + void InitImportHeaders(); + + QSharedPointer CSVModel() const; + + void ShowInputPreview(); + void ShowImportPreview(); + + template + void HackWidget(T **widget); + void HackColumnControls(); + + void RetranslateLabels(); + + void SetDefaultColumns(); + + void CheckStatus(); +}; + +//--------------------------------------------------------------------------------------------------------------------- +inline QVector DialogMeasurementsCSVColumns::ColumnsMap() const +{ + return m_columnsMap; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void DialogMeasurementsCSVColumns::SetWithHeader(bool withHeader) +{ + m_withHeader = withHeader; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void DialogMeasurementsCSVColumns::SetSeparator(const QChar &separator) +{ + m_separator = separator; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void DialogMeasurementsCSVColumns::SetCodec(QTextCodec *codec) +{ + m_codec = codec; +} + +#endif // DIALOGMEASUREMENTSCSVCOLUMNS_H diff --git a/src/app/tape/dialogs/dialogmeasurementscsvcolumns.ui b/src/app/tape/dialogs/dialogmeasurementscsvcolumns.ui new file mode 100644 index 000000000..e3aa17d38 --- /dev/null +++ b/src/app/tape/dialogs/dialogmeasurementscsvcolumns.ui @@ -0,0 +1,204 @@ + + + DialogMeasurementsCSVColumns + + + + 0 + 0 + 908 + 703 + + + + Setup columns + + + + :/tapeicon/64x64/logo.png:/tapeicon/64x64/logo.png + + + + + + + + Preview + + + + + + Input + + + + + + false + + + + + + + + + + Import + + + + + + false + + + + + + + + + + + + + Columns + + + + 6 + + + + + Name: + + + + + + + + + + Value: + + + + + + + + + + ShiftA: + + + + + + + + + + ShiftB: + + + + + + + + + + ShiftC: + + + + + + + + + + Full name: + + + + + + + + + + Description: + + + + + + + + + + + + + + + Ready + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + DialogMeasurementsCSVColumns + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogMeasurementsCSVColumns + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/app/tape/tape.pri b/src/app/tape/tape.pri index f84d8133b..32d965def 100644 --- a/src/app/tape/tape.pri +++ b/src/app/tape/tape.pri @@ -3,6 +3,7 @@ SOURCES += \ $$PWD/dialogs/dialogdimensionlabels.cpp \ + $$PWD/dialogs/dialogmeasurementscsvcolumns.cpp \ $$PWD/dialogs/dialogrestrictdimension.cpp \ $$PWD/main.cpp \ $$PWD/tmainwindow.cpp \ @@ -20,6 +21,7 @@ SOURCES += \ HEADERS += \ $$PWD/dialogs/dialogdimensionlabels.h \ + $$PWD/dialogs/dialogmeasurementscsvcolumns.h \ $$PWD/dialogs/dialogrestrictdimension.h \ $$PWD/tmainwindow.h \ $$PWD/stable.h \ @@ -36,6 +38,7 @@ HEADERS += \ FORMS += \ $$PWD/dialogs/dialogdimensionlabels.ui \ + $$PWD/dialogs/dialogmeasurementscsvcolumns.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 0bf555e76..b9e172c81 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -35,6 +35,7 @@ #include "dialogs/dialogsetupmultisize.h" #include "dialogs/dialogrestrictdimension.h" #include "dialogs/dialogdimensionlabels.h" +#include "dialogs/dialogmeasurementscsvcolumns.h" #include "../vpatterndb/vcontainer.h" #include "../vpatterndb/calculator.h" #include "../vpatterndb/pmsystems.h" @@ -1020,16 +1021,34 @@ void TMainWindow::ImportDataFromCSV() qApp->Settings()->SetCSVCodec(dialog.GetSelectedMib()); qApp->Settings()->SetCSVWithHeader(dialog.IsWithHeader()); - QxtCsvModel csv(fileName, nullptr, dialog.IsWithHeader(), dialog.GetSeparator(), - QTextCodec::codecForMib(dialog.GetSelectedMib())); - - if (m->Type() == MeasurementsType::Individual) + QSharedPointer columns; + if (m->Type() == MeasurementsType::Multisize) { - ImportIndividualMeasurements(csv); + const QList dimensions = m->Dimensions().values(); + columns = QSharedPointer::create(fileName, m->Type(), dimensions, this); } else { - ImportMultisizeMeasurements(csv); + columns = QSharedPointer::create(fileName, m->Type(), this); + } + columns->SetWithHeader(dialog.IsWithHeader()); + columns->SetSeparator(dialog.GetSeparator()); + columns->SetCodec(QTextCodec::codecForMib(dialog.GetSelectedMib())); + + if (columns->exec() == QDialog::Accepted) + { + QxtCsvModel csv(fileName, nullptr, dialog.IsWithHeader(), dialog.GetSeparator(), + QTextCodec::codecForMib(dialog.GetSelectedMib())); + const QVector map = columns->ColumnsMap(); + + if (m->Type() == MeasurementsType::Individual) + { + ImportIndividualMeasurements(csv, map); + } + else + { + ImportMultisizeMeasurements(csv, map); + } } } } @@ -3740,7 +3759,7 @@ void TMainWindow::RefreshDataAfterImport() } //--------------------------------------------------------------------------------------------------------------------- -void TMainWindow::ImportIndividualMeasurements(const QxtCsvModel &csv) +void TMainWindow::ImportIndividualMeasurements(const QxtCsvModel &csv, const QVector &map) { const int columns = csv.columnCount(); const int rows = csv.rowCount(); @@ -3773,7 +3792,8 @@ void TMainWindow::ImportIndividualMeasurements(const QxtCsvModel &csv) { try { - const QString name = csv.text(i, 0).simplified(); + const int nameColumn = map.at(static_cast(IndividualMeasurementsColumns::Name)); + const QString name = csv.text(i, nameColumn).simplified(); if (name.isEmpty()) { ShowError(tr("Error in row %1. Measurement name is empty.").arg(i)); @@ -3784,17 +3804,28 @@ void TMainWindow::ImportIndividualMeasurements(const QxtCsvModel &csv) const QString mName = CheckMName(qApp->TrVars()->MFromUser(name), importedNames); importedNames.insert(mName); measurement.name = mName; - measurement.value = VTranslateVars::TryFormulaFromUser(csv.text(i, 1), qApp->Settings()->GetOsSeparator()); - const bool custom = csv.text(i, 0).simplified().startsWith(CustomMSign); + const int valueColumn = map.at(static_cast(IndividualMeasurementsColumns::Value)); + measurement.value = VTranslateVars::TryFormulaFromUser(csv.text(i, valueColumn), + qApp->Settings()->GetOsSeparator()); + + const bool custom = name.startsWith(CustomMSign); if (columns > 2 && custom) { - measurement.fullName = csv.text(i, 2).simplified(); + const int fullNameColumn = map.at(static_cast(IndividualMeasurementsColumns::FullName)); + if (fullNameColumn >= 0) + { + measurement.fullName = csv.text(i, fullNameColumn).simplified(); + } } if (columns > 3 && custom) { - measurement.description = csv.text(i, 3).simplified(); + const int descriptionColumn = map.at(static_cast(IndividualMeasurementsColumns::Description)); + if (descriptionColumn >= 0) + { + measurement.description = csv.text(i, descriptionColumn).simplified(); + } } measurements.append(measurement); @@ -3825,7 +3856,7 @@ void TMainWindow::ImportIndividualMeasurements(const QxtCsvModel &csv) } //--------------------------------------------------------------------------------------------------------------------- -void TMainWindow::ImportMultisizeMeasurements(const QxtCsvModel &csv) +void TMainWindow::ImportMultisizeMeasurements(const QxtCsvModel &csv, const QVector &map) { const int columns = csv.columnCount(); const int rows = csv.rowCount(); @@ -3838,9 +3869,10 @@ void TMainWindow::ImportMultisizeMeasurements(const QxtCsvModel &csv) auto ConverToDouble = [](QString text, const QString &error) { + text.replace(" ", QString()); text = VTranslateVars::TryFormulaFromUser(text, qApp->Settings()->GetOsSeparator()); bool ok = false; - QLocale::c(); + const qreal value = QLocale::c().toDouble(text, &ok); if (not ok) { @@ -3859,8 +3891,9 @@ void TMainWindow::ImportMultisizeMeasurements(const QxtCsvModel &csv) QString name; qreal base{0}; - qreal heightIncrease{0}; - qreal sizeIncrease{0}; + qreal shiftA{0}; + qreal shiftB{0}; + qreal shiftC{0}; QString fullName; QString description; }; @@ -3868,11 +3901,14 @@ void TMainWindow::ImportMultisizeMeasurements(const QxtCsvModel &csv) QVector measurements; QSet importedNames; + const QMap dimensions = m->Dimensions(); + for(int i=0; i < rows; ++i) { try { - const QString name = csv.text(i, 0).simplified(); + const int nameColumn = map.at(static_cast(MultisizeMeasurementsColumns::Name)); + const QString name = csv.text(i, nameColumn).simplified(); if (name.isEmpty()) { ShowError(tr("Error in row %1. Measurement name is empty.").arg(i)); @@ -3884,24 +3920,48 @@ void TMainWindow::ImportMultisizeMeasurements(const QxtCsvModel &csv) importedNames.insert(mName); measurement.name = mName; - measurement.base = ConverToDouble(csv.text(i, 1), - tr("Cannot convert base size value to double in column 2.")); + const int baseValueColumn = map.at(static_cast(MultisizeMeasurementsColumns::BaseValue)); + measurement.base = ConverToDouble(csv.text(i, baseValueColumn), + tr("Cannot convert base value to double in column 2.")); - measurement.heightIncrease = ConverToDouble(csv.text(i, 2), - tr("Cannot convert height increase value to double in column 3.")); + const int shiftAColumn = map.at(static_cast(MultisizeMeasurementsColumns::ShiftA)); + measurement.shiftA = ConverToDouble(csv.text(i, shiftAColumn), + tr("Cannot convert shift value to double in column %1.") + .arg(shiftAColumn)); - measurement.sizeIncrease = ConverToDouble(csv.text(i, 3), - tr("Cannot convert size increase value to double in column 4.")); + if (dimensions.size() > 1) + { + const int shiftBColumn = map.at(static_cast(MultisizeMeasurementsColumns::ShiftB)); + measurement.shiftB = ConverToDouble(csv.text(i, shiftBColumn), + tr("Cannot convert shift value to double in column %1.") + .arg(shiftBColumn)); + } - const bool custom = csv.text(i, 0).simplified().startsWith(CustomMSign); + if (dimensions.size() > 2) + { + const int shiftCColumn = map.at(static_cast(MultisizeMeasurementsColumns::ShiftC)); + measurement.shiftC = ConverToDouble(csv.text(i, shiftCColumn), + tr("Cannot convert shift value to double in column %1.") + .arg(shiftCColumn)); + } + + const bool custom = name.startsWith(CustomMSign); if (columns > 4 && custom) { - measurement.fullName = csv.text(i, 4).simplified(); + const int fullNameColumn = map.at(static_cast(MultisizeMeasurementsColumns::FullName)); + if (fullNameColumn >= 0) + { + measurement.fullName = csv.text(i, fullNameColumn).simplified(); + } } if (columns > 5 && custom) { - measurement.description = csv.text(i, 5).simplified(); + const int descriptionColumn = map.at(static_cast(MultisizeMeasurementsColumns::Description)); + if (descriptionColumn >= 0) + { + measurement.description = csv.text(i, descriptionColumn).simplified(); + } } measurements.append(measurement); @@ -3917,8 +3977,17 @@ void TMainWindow::ImportMultisizeMeasurements(const QxtCsvModel &csv) { m->AddEmpty(mm.name); m->SetMBaseValue(mm.name, mm.base); - m->SetMShiftB(mm.name, mm.sizeIncrease); - m->SetMShiftA(mm.name, mm.heightIncrease); + m->SetMShiftA(mm.name, mm.shiftA); + + if (dimensions.size() > 1) + { + m->SetMShiftB(mm.name, mm.shiftB); + } + + if (dimensions.size() > 2) + { + m->SetMShiftC(mm.name, mm.shiftC); + } if (not mm.fullName.isEmpty()) { diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index ec29eae4f..7d9f29f13 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -237,8 +237,8 @@ private: void ShowError(const QString &text); void RefreshDataAfterImport(); - void ImportIndividualMeasurements(const QxtCsvModel &csv); - void ImportMultisizeMeasurements(const QxtCsvModel &csv); + void ImportIndividualMeasurements(const QxtCsvModel &csv, const QVector &map); + void ImportMultisizeMeasurements(const QxtCsvModel &csv, const QVector &map); void SetCurrentPatternUnit(); From ed2bf34f1e5276729e52115114025eaecb557ba4 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 13 Oct 2020 09:43:19 +0300 Subject: [PATCH 33/44] Refactoring. Rename folder standard_measurements to multisize_measurements. Standard measurements is old definition. It was replace with new multisize measurements. --- src/libs/ifc/schema.qrc | 14 +++++++------- .../v0.3.0.xsd | 0 .../v0.4.0.xsd | 0 .../v0.4.1.xsd | 0 .../v0.4.2.xsd | 0 .../v0.4.3.xsd | 0 .../v0.4.4.xsd | 0 .../v0.5.0.xsd | 0 src/libs/ifc/xml/vvstconverter.cpp | 14 +++++++------- 9 files changed, 14 insertions(+), 14 deletions(-) rename src/libs/ifc/schema/{standard_measurements => multisize_measurements}/v0.3.0.xsd (100%) rename src/libs/ifc/schema/{standard_measurements => multisize_measurements}/v0.4.0.xsd (100%) rename src/libs/ifc/schema/{standard_measurements => multisize_measurements}/v0.4.1.xsd (100%) rename src/libs/ifc/schema/{standard_measurements => multisize_measurements}/v0.4.2.xsd (100%) rename src/libs/ifc/schema/{standard_measurements => multisize_measurements}/v0.4.3.xsd (100%) rename src/libs/ifc/schema/{standard_measurements => multisize_measurements}/v0.4.4.xsd (100%) rename src/libs/ifc/schema/{standard_measurements => multisize_measurements}/v0.5.0.xsd (100%) diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index a906c1e05..9ea2fec3e 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -59,13 +59,13 @@ schema/pattern/v0.8.5.xsd schema/pattern/v0.8.6.xsd schema/pattern/v0.8.7.xsd - schema/standard_measurements/v0.3.0.xsd - schema/standard_measurements/v0.4.0.xsd - schema/standard_measurements/v0.4.1.xsd - schema/standard_measurements/v0.4.2.xsd - schema/standard_measurements/v0.4.3.xsd - schema/standard_measurements/v0.4.4.xsd - schema/standard_measurements/v0.5.0.xsd + schema/multisize_measurements/v0.3.0.xsd + schema/multisize_measurements/v0.4.0.xsd + schema/multisize_measurements/v0.4.1.xsd + schema/multisize_measurements/v0.4.2.xsd + schema/multisize_measurements/v0.4.3.xsd + schema/multisize_measurements/v0.4.4.xsd + schema/multisize_measurements/v0.5.0.xsd schema/individual_measurements/v0.2.0.xsd schema/individual_measurements/v0.3.0.xsd schema/individual_measurements/v0.3.1.xsd diff --git a/src/libs/ifc/schema/standard_measurements/v0.3.0.xsd b/src/libs/ifc/schema/multisize_measurements/v0.3.0.xsd similarity index 100% rename from src/libs/ifc/schema/standard_measurements/v0.3.0.xsd rename to src/libs/ifc/schema/multisize_measurements/v0.3.0.xsd diff --git a/src/libs/ifc/schema/standard_measurements/v0.4.0.xsd b/src/libs/ifc/schema/multisize_measurements/v0.4.0.xsd similarity index 100% rename from src/libs/ifc/schema/standard_measurements/v0.4.0.xsd rename to src/libs/ifc/schema/multisize_measurements/v0.4.0.xsd diff --git a/src/libs/ifc/schema/standard_measurements/v0.4.1.xsd b/src/libs/ifc/schema/multisize_measurements/v0.4.1.xsd similarity index 100% rename from src/libs/ifc/schema/standard_measurements/v0.4.1.xsd rename to src/libs/ifc/schema/multisize_measurements/v0.4.1.xsd diff --git a/src/libs/ifc/schema/standard_measurements/v0.4.2.xsd b/src/libs/ifc/schema/multisize_measurements/v0.4.2.xsd similarity index 100% rename from src/libs/ifc/schema/standard_measurements/v0.4.2.xsd rename to src/libs/ifc/schema/multisize_measurements/v0.4.2.xsd diff --git a/src/libs/ifc/schema/standard_measurements/v0.4.3.xsd b/src/libs/ifc/schema/multisize_measurements/v0.4.3.xsd similarity index 100% rename from src/libs/ifc/schema/standard_measurements/v0.4.3.xsd rename to src/libs/ifc/schema/multisize_measurements/v0.4.3.xsd diff --git a/src/libs/ifc/schema/standard_measurements/v0.4.4.xsd b/src/libs/ifc/schema/multisize_measurements/v0.4.4.xsd similarity index 100% rename from src/libs/ifc/schema/standard_measurements/v0.4.4.xsd rename to src/libs/ifc/schema/multisize_measurements/v0.4.4.xsd diff --git a/src/libs/ifc/schema/standard_measurements/v0.5.0.xsd b/src/libs/ifc/schema/multisize_measurements/v0.5.0.xsd similarity index 100% rename from src/libs/ifc/schema/standard_measurements/v0.5.0.xsd rename to src/libs/ifc/schema/multisize_measurements/v0.5.0.xsd diff --git a/src/libs/ifc/xml/vvstconverter.cpp b/src/libs/ifc/xml/vvstconverter.cpp index 2ca06eec5..2c2cb0b7a 100644 --- a/src/libs/ifc/xml/vvstconverter.cpp +++ b/src/libs/ifc/xml/vvstconverter.cpp @@ -55,7 +55,7 @@ const QString VVSTConverter::MeasurementMinVerStr = QStringLiteral("0.3.0"); const QString VVSTConverter::MeasurementMaxVerStr = QStringLiteral("0.5.0"); -const QString VVSTConverter::CurrentSchema = QStringLiteral("://schema/standard_measurements/v0.5.0.xsd"); +const QString VVSTConverter::CurrentSchema = QStringLiteral("://schema/multisize_measurements/v0.5.0.xsd"); //VVSTConverter::MeasurementMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VVSTConverter::MeasurementMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! @@ -77,12 +77,12 @@ QString VVSTConverter::XSDSchema(int ver) const { QHash schemas = { - std::make_pair(FORMAT_VERSION(0, 3, 0), QStringLiteral("://schema/standard_measurements/v0.3.0.xsd")), - std::make_pair(FORMAT_VERSION(0, 4, 0), QStringLiteral("://schema/standard_measurements/v0.4.0.xsd")), - std::make_pair(FORMAT_VERSION(0, 4, 1), QStringLiteral("://schema/standard_measurements/v0.4.1.xsd")), - std::make_pair(FORMAT_VERSION(0, 4, 2), QStringLiteral("://schema/standard_measurements/v0.4.2.xsd")), - std::make_pair(FORMAT_VERSION(0, 4, 3), QStringLiteral("://schema/standard_measurements/v0.4.3.xsd")), - std::make_pair(FORMAT_VERSION(0, 4, 4), QStringLiteral("://schema/standard_measurements/v0.4.4.xsd")), + std::make_pair(FORMAT_VERSION(0, 3, 0), QStringLiteral("://schema/multisize_measurements/v0.3.0.xsd")), + std::make_pair(FORMAT_VERSION(0, 4, 0), QStringLiteral("://schema/multisize_measurements/v0.4.0.xsd")), + std::make_pair(FORMAT_VERSION(0, 4, 1), QStringLiteral("://schema/multisize_measurements/v0.4.1.xsd")), + std::make_pair(FORMAT_VERSION(0, 4, 2), QStringLiteral("://schema/multisize_measurements/v0.4.2.xsd")), + std::make_pair(FORMAT_VERSION(0, 4, 3), QStringLiteral("://schema/multisize_measurements/v0.4.3.xsd")), + std::make_pair(FORMAT_VERSION(0, 4, 4), QStringLiteral("://schema/multisize_measurements/v0.4.4.xsd")), std::make_pair(FORMAT_VERSION(0, 5, 0), CurrentSchema), }; From 23e6d0f830c131dbc2d3f410c9ccb4955fad54a8 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 15 Oct 2020 09:35:08 +0300 Subject: [PATCH 34/44] Allow a user to select dimensions for individual measurements. --- src/app/tape/tmainwindow.cpp | 68 ++++++++++ src/app/tape/tmainwindow.h | 2 + src/app/tape/tmainwindow.ui | 63 +++++++--- src/app/valentina/mainwindowsnogui.cpp | 15 --- .../schema/individual_measurements/v0.5.1.xsd | 10 ++ src/libs/vformat/vdimensions.cpp | 20 +-- src/libs/vformat/vmeasurements.cpp | 118 ++++++++++++++++++ src/libs/vformat/vmeasurements.h | 12 ++ src/libs/vmisc/def.h | 9 ++ .../vpatterndb/variables/vmeasurement.cpp | 12 ++ src/libs/vpatterndb/variables/vmeasurement.h | 3 + .../vpatterndb/variables/vmeasurement_p.h | 5 +- 12 files changed, 291 insertions(+), 46 deletions(-) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index b9e172c81..e02bdfe23 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -621,6 +621,8 @@ void TMainWindow::changeEvent(QEvent *event) InitGender(ui->comboBoxGender); ui->comboBoxGender->setCurrentIndex(index); ui->comboBoxGender->blockSignals(false); + + InitMeasurementDimension(); } { @@ -1696,6 +1698,11 @@ void TMainWindow::ShowNewMData(bool fresh) ui->plainTextEditFormula->setPlainText(formula); ui->plainTextEditFormula->blockSignals(false); + + ui->comboBoxDimension->blockSignals(true); + ui->comboBoxDimension->setCurrentIndex( + ui->comboBoxDimension->findData(static_cast(meash->GetDimension()))); + ui->comboBoxDimension->blockSignals(false); } MeasurementGUI(); @@ -2121,6 +2128,32 @@ void TMainWindow::SaveMUnits() ShowNewMData(false); } +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::SaveMDimension() +{ + const int row = ui->tableWidget->currentRow(); + + if (row == -1) + { + return; + } + + const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName); + const IMD dimension = static_cast(ui->comboBoxDimension->currentData().toInt()); + m->SetMDimension(nameField->data(Qt::UserRole).toString(), dimension); + + MeasurementsWereSaved(false); + + RefreshData(); + search->RefreshList(ui->lineEditFind->text()); + + ui->tableWidget->blockSignals(true); + ui->tableWidget->selectRow(row); + ui->tableWidget->blockSignals(false); + + ShowNewMData(false); +} + //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::FullCircumferenceChanged(bool checked) { @@ -2389,6 +2422,8 @@ void TMainWindow::InitWindow() HackWidget(&ui->toolButtonExpr); HackWidget(&ui->labelFormula); HackWidget(&ui->pushButtonGrow); + HackWidget(&ui->labelDimension); + HackWidget(&ui->comboBoxDimension); // Tab Information HackWidget(&ui->lineEditCustomerName); @@ -2471,6 +2506,10 @@ void TMainWindow::InitWindow() Qt::UniqueConnection); connect(ui->toolButtonExpr, &QToolButton::clicked, this, &TMainWindow::Fx); + + InitMeasurementDimension(); + connect(ui->comboBoxDimension, QOverload::of(&QComboBox::currentIndexChanged), this, + &TMainWindow::SaveMDimension); } ui->comboBoxPMSystem->setEnabled(true); @@ -3180,6 +3219,7 @@ void TMainWindow::MFields(bool enabled) ui->plainTextEditFormula->setEnabled(enabled); ui->pushButtonGrow->setEnabled(enabled); ui->toolButtonExpr->setEnabled(enabled); + ui->comboBoxDimension->setEnabled(enabled); } ui->lineEditFind->setEnabled(enabled); @@ -4309,6 +4349,34 @@ void TMainWindow::InitGender(QComboBox *gender) gender->addItem(tr("female", "gender"), QVariant(static_cast(GenderType::Female))); } +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::InitMeasurementDimension() +{ + ui->comboBoxDimension->blockSignals(true); + + int current = -1; + if (ui->comboBoxDimension->currentIndex() != -1) + { + current = ui->comboBoxDimension->currentData().toInt(); + } + + ui->comboBoxDimension->clear(); + + ui->comboBoxDimension->addItem(VMeasurements::IMDName(IMD::N), QVariant(static_cast(IMD::N))); + ui->comboBoxDimension->addItem(VMeasurements::IMDName(IMD::X), QVariant(static_cast(IMD::X))); + ui->comboBoxDimension->addItem(VMeasurements::IMDName(IMD::Y), QVariant(static_cast(IMD::Y))); + ui->comboBoxDimension->addItem(VMeasurements::IMDName(IMD::W), QVariant(static_cast(IMD::W))); + ui->comboBoxDimension->addItem(VMeasurements::IMDName(IMD::Z), QVariant(static_cast(IMD::Z))); + + int i = ui->comboBoxDimension->findData(current); + if (i != -1) + { + ui->comboBoxDimension->setCurrentIndex(i); + } + + ui->comboBoxDimension->blockSignals(false); +} + //--------------------------------------------------------------------------------------------------------------------- template void TMainWindow::HackWidget(T **widget) diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index 7d9f29f13..ff641374f 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -134,6 +134,7 @@ private slots: void SaveMDescription(); void SaveMFullName(); void SaveMUnits(); + void SaveMDimension(); void FullCircumferenceChanged(bool checked); @@ -186,6 +187,7 @@ private: void InitComboBoxUnits(); void InitMeasurementUnits(); void InitGender(QComboBox *gender); + void InitMeasurementDimension(); void ShowNewMData(bool fresh); void ShowUnits(); diff --git a/src/app/tape/tmainwindow.ui b/src/app/tape/tmainwindow.ui index 211436dc9..66d7f956b 100644 --- a/src/app/tape/tmainwindow.ui +++ b/src/app/tape/tmainwindow.ui @@ -339,14 +339,14 @@ - + Name: - + false @@ -359,14 +359,14 @@ - + Calculated value: - + Calculated value @@ -376,14 +376,14 @@ - + Formula: - + @@ -470,14 +470,14 @@ - + Base value: - + false @@ -490,14 +490,14 @@ - + Shift A - + false @@ -510,14 +510,14 @@ - + Shift B - + false @@ -530,14 +530,14 @@ - + Shift C - + false @@ -550,14 +550,14 @@ - + Correction: - + false @@ -570,14 +570,14 @@ - + Full name: - + false @@ -590,14 +590,14 @@ - + Description: - + false @@ -616,6 +616,29 @@ + + + + Dimension: + + + + + + + false + + + + 0 + 0 + + + + Select one of the dimensions to later use the measurement value in piece label + + + diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 559a02dcd..119693d95 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -2191,21 +2191,6 @@ QSharedPointer MainWindowsNoGUI::OpenMeasurementFile(const QStrin } CheckRequiredMeasurements(m.data()); - - if (m->Type() == MeasurementsType::Multisize) - { - if (m->MUnit() == Unit::Inch) - { - qCCritical(vMainNoGUIWindow, "%s\n\n%s", qUtf8Printable(tr("Wrong units.")), - qUtf8Printable(tr("Application doesn't support multisize table with inches."))); - m->clear(); - if (not VApplication::IsGUIMode()) - { - qApp->exit(V_EX_DATAERR); - } - return m; - } - } } catch (VException &e) { diff --git a/src/libs/ifc/schema/individual_measurements/v0.5.1.xsd b/src/libs/ifc/schema/individual_measurements/v0.5.1.xsd index 80d99fcc9..6a174d8f9 100644 --- a/src/libs/ifc/schema/individual_measurements/v0.5.1.xsd +++ b/src/libs/ifc/schema/individual_measurements/v0.5.1.xsd @@ -28,6 +28,7 @@ + @@ -70,4 +71,13 @@ + + + + + + + + + diff --git a/src/libs/vformat/vdimensions.cpp b/src/libs/vformat/vdimensions.cpp index 1063c5216..46ff44d87 100644 --- a/src/libs/vformat/vdimensions.cpp +++ b/src/libs/vformat/vdimensions.cpp @@ -165,16 +165,16 @@ QString VAbstartMeasurementDimension::DimensionName(MeasurementDimension type) { switch(type) { - case MeasurementDimension::X: - return tr("Height"); - case MeasurementDimension::Y: - return tr("Size"); - case MeasurementDimension::W: - return tr("Hip"); - case MeasurementDimension::Z: - return tr("Waist"); - default: - return QString(); + case MeasurementDimension::X: + return tr("Height"); + case MeasurementDimension::Y: + return tr("Size"); + case MeasurementDimension::W: + return tr("Hip"); + case MeasurementDimension::Z: + return tr("Waist"); + default: + return QString(); } } diff --git a/src/libs/vformat/vmeasurements.cpp b/src/libs/vformat/vmeasurements.cpp index 49bee2edb..d0da8a185 100644 --- a/src/libs/vformat/vmeasurements.cpp +++ b/src/libs/vformat/vmeasurements.cpp @@ -94,11 +94,13 @@ 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::AttrDimension = QStringLiteral("dimension"); const QString VMeasurements::GenderMale = QStringLiteral("male"); const QString VMeasurements::GenderFemale = QStringLiteral("female"); const QString VMeasurements::GenderUnknown = QStringLiteral("unknown"); +const QString VMeasurements::DimensionN = QStringLiteral("n"); const QString VMeasurements::DimensionX = QStringLiteral("x"); const QString VMeasurements::DimensionY = QStringLiteral("y"); const QString VMeasurements::DimensionW = QStringLiteral("w"); @@ -366,6 +368,8 @@ void VMeasurements::ReadMeasurements(qreal baseA, qreal baseB, qreal baseC) cons } else { + const IMD dimension = + VMeasurements::StrToIMD(GetParametrString(dom, AttrDimension, VMeasurements::IMDToStr(IMD::N))); const QString formula = GetParametrString(dom, AttrValue, QChar('0')); bool ok = false; qreal value = EvalFormula(tempData.data(), formula, &ok); @@ -382,6 +386,7 @@ void VMeasurements::ReadMeasurements(qreal baseA, qreal baseB, qreal baseC) cons meash->SetGuiText(fullName); meash->SetDescription(description); meash->SetSpecialUnits(specialUnits); + meash->SetDimension(dimension); } if (m_keepNames) @@ -804,6 +809,41 @@ void VMeasurements::SetMFullName(const QString &name, const QString &text) } } +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurements::SetMDimension(const QString &name, IMD type) +{ + ClearDimension(type); + QDomElement node = FindM(name); + if (not node.isNull()) + { + SetAttributeOrRemoveIf(node, AttrDimension, VMeasurements::IMDToStr(type), type == IMD::N); + } + else + { + qWarning() << tr("Can't find measurement '%1'").arg(name); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VMeasurements::MeasurementForDimension(IMD type) const +{ + const QString d = VMeasurements::IMDToStr(type); + QDomNodeList list = elementsByTagName(TagMeasurement); + + for (int i=0; i < list.size(); ++i) + { + const QDomElement domElement = list.at(i).toElement(); + if (domElement.isNull() == false) + { + if (domElement.attribute(AttrDimension) == d) + { + return domElement.attribute(AttrName); + } + } + } + return QString(); +} + //--------------------------------------------------------------------------------------------------------------------- QMap VMeasurements::Dimensions() const { @@ -1001,6 +1041,65 @@ MeasurementDimension VMeasurements::StrToDimensionType(const QString &type) } } +//--------------------------------------------------------------------------------------------------------------------- +QString VMeasurements::IMDToStr(const IMD &type) +{ + switch (type) + { + case IMD::X: + return DimensionX; + case IMD::Y: + return DimensionY; + case IMD::W: + return DimensionW; + case IMD::Z: + return DimensionZ; + case IMD::N: + default: + return DimensionN; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +IMD VMeasurements::StrToIMD(const QString &type) +{ + const QStringList dimensions = QStringList{DimensionN, DimensionX, DimensionY, DimensionW, DimensionZ}; + switch (dimensions.indexOf(type)) + { + case 1: // DimensionX + return IMD::X; + case 2: // DimensionY + return IMD::Y; + case 3: // DimensionW + return IMD::W; + case 4: // DimensionZ + return IMD::Z; + case 0: // DimensionN + default: + return IMD::N; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VMeasurements::IMDName(IMD type) +{ + switch(type) + { + case IMD::N: + return tr("None"); + case IMD::X: + return tr("Height"); + case IMD::Y: + return tr("Size"); + case IMD::W: + return tr("Hip"); + case IMD::Z: + return tr("Waist"); + default: + return QString(); + } +} + //--------------------------------------------------------------------------------------------------------------------- QStringList VMeasurements::ListAll() const { @@ -1419,3 +1518,22 @@ DimesionLabels VMeasurements::ReadDimensionLabels(const QDomElement &dElement) c return labels; } + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurements::ClearDimension(IMD type) +{ + const QString d = VMeasurements::IMDToStr(type); + QDomNodeList list = elementsByTagName(TagMeasurement); + + for (int i=0; i < list.size(); ++i) + { + QDomElement domElement = list.at(i).toElement(); + if (domElement.isNull() == false) + { + if (domElement.attribute(AttrDimension) == d) + { + domElement.removeAttribute(AttrDimension); + } + } + } +} diff --git a/src/libs/vformat/vmeasurements.h b/src/libs/vformat/vmeasurements.h index 818cdc311..cffb1bc0b 100644 --- a/src/libs/vformat/vmeasurements.h +++ b/src/libs/vformat/vmeasurements.h @@ -113,6 +113,9 @@ public: void SetMCorrectionValue(const QString &name, qreal baseA, qreal baseB, qreal baseC, double value); void SetMDescription(const QString &name, const QString &text); void SetMFullName(const QString &name, const QString &text); + void SetMDimension(const QString &name, IMD type); + + QString MeasurementForDimension(IMD type) const; QMap Dimensions() const; @@ -161,11 +164,13 @@ public: static const QString AttrCircumference; static const QString AttrFullCircumference; static const QString AttrLabel; + static const QString AttrDimension; static const QString GenderMale; static const QString GenderFemale; static const QString GenderUnknown; + static const QString DimensionN; static const QString DimensionX; static const QString DimensionY; static const QString DimensionW; @@ -177,6 +182,11 @@ public: static QString DimensionTypeToStr(const MeasurementDimension &type); static MeasurementDimension StrToDimensionType(const QString &type); + static QString IMDToStr(const IMD &type); + static IMD StrToIMD(const QString &type); + + static QString IMDName(IMD type); + QStringList ListAll() const; QStringList ListKnown() const; @@ -214,6 +224,8 @@ private: void SaveDimesionLabels(QDomElement &dElement, const DimesionLabels &labels); DimesionLabels ReadDimensionLabels(const QDomElement &dElement) const; + + void ClearDimension(IMD type); }; #endif // VMEASUREMENTS_H diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 384af6fb2..619469ddb 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -288,6 +288,15 @@ enum class GSizes : quint8 { ALL, S42=42, S44=44, S46=46, S48=48, S50=50, S52=52, S54=54, S56=56, S58=58, S60=60, S62=62, S64=64, S66=66, S68=68, S70=70, S72=72 }; +enum class IMD: qint8 // Individual measurement dimension +{ + N, // None + X, // height + Y, // size (chest half circumference) + W, // hip half circumference + Z // waist half circumference +}; + /* QImage supports a maximum of 32768x32768 px images (signed short). * This follows from the condition: width * height * colordepth < INT_MAX (4 billion) -> 32768 * 32768 * 4 = 4 billion. * The second condition is of course that malloc is able to allocate the requested memory. diff --git a/src/libs/vpatterndb/variables/vmeasurement.cpp b/src/libs/vpatterndb/variables/vmeasurement.cpp index a60e0a78a..a667af48e 100644 --- a/src/libs/vpatterndb/variables/vmeasurement.cpp +++ b/src/libs/vpatterndb/variables/vmeasurement.cpp @@ -458,6 +458,18 @@ void VMeasurement::SetSpecialUnits(bool special) d->specialUnits = special; } +//--------------------------------------------------------------------------------------------------------------------- +IMD VMeasurement::GetDimension() const +{ + return d->dimension; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurement::SetDimension(IMD type) +{ + d->dimension = type; +} + //--------------------------------------------------------------------------------------------------------------------- qreal VMeasurement::GetCorrection(int baseA, int baseB, int baseC) const { diff --git a/src/libs/vpatterndb/variables/vmeasurement.h b/src/libs/vpatterndb/variables/vmeasurement.h index 2b3a708d1..d54ea5f50 100644 --- a/src/libs/vpatterndb/variables/vmeasurement.h +++ b/src/libs/vpatterndb/variables/vmeasurement.h @@ -108,6 +108,9 @@ public: bool IsSpecialUnits() const; void SetSpecialUnits(bool special); + IMD GetDimension() const; + void SetDimension(IMD type); + qreal GetCorrection(int baseA, int baseB, int baseC) const; QMap GetCorrections() const; diff --git a/src/libs/vpatterndb/variables/vmeasurement_p.h b/src/libs/vpatterndb/variables/vmeasurement_p.h index 30ffd828d..132360f74 100644 --- a/src/libs/vpatterndb/variables/vmeasurement_p.h +++ b/src/libs/vpatterndb/variables/vmeasurement_p.h @@ -79,7 +79,8 @@ public: baseB(m.baseB), baseC(m.baseC), corrections(m.corrections), - specialUnits(m.specialUnits) + specialUnits(m.specialUnits), + dimension(m.dimension) {} virtual ~VMeasurementData(); @@ -112,6 +113,8 @@ public: bool specialUnits{false}; + IMD dimension{IMD::N}; + private: Q_DISABLE_ASSIGN(VMeasurementData) }; From 4cea74d63b895dd2d49d293a1a2113b14f8bf38c Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 15 Oct 2020 18:05:21 +0300 Subject: [PATCH 35/44] Loading measurements in Valentina. --- src/app/tape/mapplication.cpp | 2 +- src/app/valentina/core/vapplication.cpp | 6 +- src/app/valentina/core/vapplication.h | 7 +- .../core/vtooloptionspropertybrowser.cpp | 8 +- .../dialogs/dialogfinalmeasurements.cpp | 10 +- .../valentina/dialogs/dialogincrements.cpp | 10 +- .../valentina/dialogs/dialoglayoutscale.cpp | 8 +- .../dialogs/dialogpatternproperties.cpp | 6 +- .../valentina/dialogs/dialogsavelayout.cpp | 8 +- src/app/valentina/dialogs/vwidgetdetails.cpp | 2 +- src/app/valentina/dialogs/vwidgetgroups.cpp | 2 +- src/app/valentina/mainwindow.cpp | 679 ++++++++++++------ src/app/valentina/mainwindow.h | 47 +- src/app/valentina/mainwindowsnogui.cpp | 32 +- src/app/valentina/mainwindowsnogui.h | 5 +- src/app/valentina/xml/vpattern.cpp | 2 +- src/app/valentina/xml/vpattern.h | 2 + src/libs/fervor/fvupdater.cpp | 2 +- src/libs/ifc/xml/vabstractpattern.cpp | 2 +- .../vdxf/libdxfrw/intern/drw_textcodec.cpp | 5 +- src/libs/vformat/vmeasurements.h | 2 +- src/libs/vformat/vpatternrecipe.cpp | 4 +- src/libs/vgeometry/vabstractcurve.cpp | 4 +- src/libs/vgeometry/varc_p.h | 2 +- src/libs/vgeometry/vellipticalarc_p.h | 2 +- src/libs/vgeometry/vspline_p.h | 2 +- src/libs/vlayout/vabstractpiece.cpp | 4 +- src/libs/vlayout/vbank.cpp | 10 +- src/libs/vlayout/vlayoutpiece.cpp | 16 +- src/libs/vlayout/vposter.cpp | 9 +- src/libs/vlayout/vtextmanager.cpp | 8 +- src/libs/vmisc/def.h | 2 +- src/libs/vmisc/dialogs/dialogexporttocsv.cpp | 1 + src/libs/vmisc/testvapplication.h | 1 + src/libs/vmisc/vabstractapplication.cpp | 174 +---- src/libs/vmisc/vabstractapplication.h | 142 +--- src/libs/vmisc/vabstractvalapplication.cpp | 80 +++ src/libs/vmisc/vabstractvalapplication.h | 394 ++++++++++ src/libs/vmisc/vmisc.pri | 2 + src/libs/vpatterndb/variables/vmeasurement.h | 1 + src/libs/vpatterndb/vpassmark.cpp | 22 +- src/libs/vpatterndb/vpiece.cpp | 10 +- src/libs/vpatterndb/vpiecenode.cpp | 12 +- src/libs/vpatterndb/vpiecepath.cpp | 6 +- .../dialogs/support/dialogeditlabel.cpp | 24 +- .../support/dialogeditwrongformula.cpp | 12 +- .../vtools/dialogs/support/dialogundo.cpp | 2 +- .../vtools/dialogs/tools/dialogalongline.cpp | 4 +- src/libs/vtools/dialogs/tools/dialogarc.cpp | 4 +- .../dialogs/tools/dialogarcwithlength.cpp | 8 +- .../vtools/dialogs/tools/dialogbisector.cpp | 4 +- .../vtools/dialogs/tools/dialogcutarc.cpp | 4 +- .../vtools/dialogs/tools/dialogcutspline.cpp | 4 +- .../dialogs/tools/dialogcutsplinepath.cpp | 4 +- .../dialogs/tools/dialogellipticalarc.cpp | 6 +- .../vtools/dialogs/tools/dialogendline.cpp | 4 +- src/libs/vtools/dialogs/tools/dialogmove.cpp | 4 +- .../vtools/dialogs/tools/dialognormal.cpp | 4 +- .../tools/dialogpointfromcircleandtangent.cpp | 4 +- .../dialogs/tools/dialogpointofcontact.cpp | 4 +- .../dialogpointofintersectioncircles.cpp | 8 +- .../dialogs/tools/dialogshoulderpoint.cpp | 4 +- .../vtools/dialogs/tools/dialogspline.cpp | 8 +- .../vtools/dialogs/tools/dialogsplinepath.cpp | 8 +- .../dialogs/tools/piece/dialogpiecepath.cpp | 22 +- .../dialogs/tools/piece/dialogplacelabel.cpp | 12 +- .../tools/piece/dialogseamallowance.cpp | 32 +- .../operation/vabstractoperation.cpp | 2 +- .../tools/drawTools/operation/vtoolmove.cpp | 4 +- .../drawTools/toolcurve/vabstractspline.cpp | 2 +- .../tools/drawTools/toolcurve/vtoolarc.cpp | 4 +- .../toolcurve/vtoolarcwithlength.cpp | 6 +- .../toolcurve/vtoolellipticalarc.cpp | 6 +- .../toolsinglepoint/toolcut/vtoolcut.cpp | 2 +- .../toolsinglepoint/toolcut/vtoolcutarc.cpp | 2 +- .../toolcut/vtoolcutspline.cpp | 2 +- .../toolcut/vtoolcutsplinepath.cpp | 2 +- .../toollinepoint/vtoolalongline.cpp | 2 +- .../toollinepoint/vtoolcurveintersectaxis.cpp | 2 +- .../toollinepoint/vtoolheight.cpp | 2 +- .../toollinepoint/vtoollineintersectaxis.cpp | 4 +- .../toollinepoint/vtoollinepoint.cpp | 4 +- .../toollinepoint/vtoolshoulderpoint.cpp | 2 +- .../toolsinglepoint/vtoollineintersect.cpp | 4 +- .../vtoolpointfromarcandtangent.cpp | 2 +- .../vtoolpointfromcircleandtangent.cpp | 4 +- .../toolsinglepoint/vtoolpointofcontact.cpp | 6 +- .../vtoolpointofintersectionarcs.cpp | 2 +- .../vtoolpointofintersectioncircles.cpp | 6 +- .../vtoolpointofintersectioncurves.cpp | 2 +- .../toolsinglepoint/vtooltriangle.cpp | 2 +- src/libs/vtools/tools/drawTools/vtoolline.cpp | 2 +- src/libs/vtools/tools/vtoolseamallowance.cpp | 2 +- src/libs/vtools/undocommands/addtocalc.cpp | 2 +- .../undocommands/deletepatternpiece.cpp | 2 +- src/libs/vtools/undocommands/deltool.cpp | 2 +- src/libs/vtools/undocommands/movespline.cpp | 2 +- src/libs/vtools/undocommands/movespoint.cpp | 2 +- src/libs/vtools/undocommands/undogroup.cpp | 2 +- .../line/operation/vistoolmove.cpp | 2 +- .../visualization/line/vistoolendline.cpp | 2 +- src/libs/vtools/visualization/visualization.h | 2 +- src/libs/vwidgets/vgraphicssimpletextitem.cpp | 2 +- src/libs/vwidgets/vmaingraphicsview.cpp | 2 +- src/test/ValentinaTest/tst_vpiece.cpp | 4 +- 105 files changed, 1227 insertions(+), 824 deletions(-) create mode 100644 src/libs/vmisc/vabstractvalapplication.cpp create mode 100644 src/libs/vmisc/vabstractvalapplication.h diff --git a/src/app/tape/mapplication.cpp b/src/app/tape/mapplication.cpp index 2773da8ce..f0056eeab 100644 --- a/src/app/tape/mapplication.cpp +++ b/src/app/tape/mapplication.cpp @@ -216,7 +216,7 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con { if (topWinAllowsPop) { - messageBox.setText(VAbstractApplication::ClearMessage(msg)); + messageBox.setText(msg); messageBox.setStandardButtons(QMessageBox::Ok); messageBox.setWindowModality(Qt::ApplicationModal); messageBox.setModal(true); diff --git a/src/app/valentina/core/vapplication.cpp b/src/app/valentina/core/vapplication.cpp index 4392fd613..e76c3d7ab 100644 --- a/src/app/valentina/core/vapplication.cpp +++ b/src/app/valentina/core/vapplication.cpp @@ -150,7 +150,7 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con const bool isPatternMessage = qApp->IsPatternMessage(msg); if (isPatternMessage) { - logMsg = logMsg.remove(VAbstractApplication::patternMessageSignature); + logMsg = logMsg.remove(VAbstractValApplication::patternMessageSignature); } { @@ -249,7 +249,7 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con break; } - messageBox.setText(VAbstractApplication::ClearMessage(logMsg)); + messageBox.setText(VAbstractValApplication::ClearMessage(logMsg)); messageBox.setStandardButtons(QMessageBox::Ok); messageBox.setWindowModality(Qt::ApplicationModal); messageBox.setModal(true); @@ -287,7 +287,7 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con * @param argv command line. */ VApplication::VApplication(int &argc, char **argv) - : VAbstractApplication(argc, argv), + : VAbstractValApplication(argc, argv), trVars(nullptr), autoSaveTimer(nullptr), lockLog(), diff --git a/src/app/valentina/core/vapplication.h b/src/app/valentina/core/vapplication.h index d01d0f2ab..b025e82b3 100644 --- a/src/app/valentina/core/vapplication.h +++ b/src/app/valentina/core/vapplication.h @@ -29,11 +29,12 @@ #ifndef VAPPLICATION_H #define VAPPLICATION_H -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "../vwidgets/vmaingraphicsview.h" #include "../vpatterndb/vtranslatevars.h" #include "vsettings.h" #include "vcmdexport.h" +#include "vlockguard.h" class VApplication;// use in define @@ -45,7 +46,7 @@ class VApplication;// use in define /** * @brief The VApplication class reimplamentation QApplication class. */ -class VApplication : public VAbstractApplication +class VApplication : public VAbstractValApplication { Q_OBJECT public: @@ -114,7 +115,5 @@ inline void VApplication::setAutoSaveTimer(QTimer *value) { autoSaveTimer = value; } -//--------------------------------------------------------------------------------------------------------------------- - #endif // VAPPLICATION_H diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index 2c8f9bd16..874c154cc 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -2318,7 +2318,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolSpline(QGraphicsItem *item) VFormula length1(spl.GetC1LengthFormula(), i->getData()); length1.setCheckZero(false); length1.setToolId(i->getId()); - length1.setPostfix(UnitsToStr(qApp->patternUnit())); + length1.setPostfix(UnitsToStr(qApp->patternUnits())); length1.Eval(); AddPropertyFormula(tr("C1: length:"), length1, AttrLength1); @@ -2332,7 +2332,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolSpline(QGraphicsItem *item) VFormula length2(spl.GetC2LengthFormula(), i->getData()); length2.setCheckZero(false); length2.setToolId(i->getId()); - length2.setPostfix(UnitsToStr(qApp->patternUnit())); + length2.setPostfix(UnitsToStr(qApp->patternUnits())); length2.Eval(); AddPropertyFormula(tr("C2: length:"), length2, AttrLength2); @@ -3046,7 +3046,7 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolSpline() VFormula length1F(spl.GetC1LengthFormula(), i->getData()); length1F.setCheckZero(false); length1F.setToolId(i->getId()); - length1F.setPostfix(UnitsToStr(qApp->patternUnit())); + length1F.setPostfix(UnitsToStr(qApp->patternUnits())); length1F.Eval(); QVariant length1; length1.setValue(length1F); @@ -3064,7 +3064,7 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolSpline() VFormula length2F(spl.GetC2LengthFormula(), i->getData()); length2F.setCheckZero(false); length2F.setToolId(i->getId()); - length2F.setPostfix(UnitsToStr(qApp->patternUnit())); + length2F.setPostfix(UnitsToStr(qApp->patternUnits())); length2F.Eval(); QVariant length2; length2.setValue(length2F); diff --git a/src/app/valentina/dialogs/dialogfinalmeasurements.cpp b/src/app/valentina/dialogs/dialogfinalmeasurements.cpp index eed634d6a..923e22a69 100644 --- a/src/app/valentina/dialogs/dialogfinalmeasurements.cpp +++ b/src/app/valentina/dialogs/dialogfinalmeasurements.cpp @@ -373,7 +373,7 @@ void DialogFinalMeasurements::SaveFormula() { QTableWidgetItem *result = ui->tableWidget->item(row, 1); //Show unit in dialog lable (cm, mm or inch) - const QString postfix = UnitsToStr(qApp->patternUnit()); + const QString postfix = UnitsToStr(qApp->patternUnits()); ui->labelCalculatedValue->setText(result->text() + QChar(QChar::Space) +postfix); return; } @@ -381,7 +381,7 @@ void DialogFinalMeasurements::SaveFormula() if (text.isEmpty()) { //Show unit in dialog lable (cm, mm or inch) - const QString postfix = UnitsToStr(qApp->patternUnit()); + const QString postfix = UnitsToStr(qApp->patternUnits()); ui->labelCalculatedValue->setText(tr("Error") + " (" + postfix + "). " + tr("Empty field.")); return; } @@ -455,7 +455,7 @@ void DialogFinalMeasurements::Fx() dialog->setWindowTitle(tr("Edit measurement")); dialog->SetFormula(qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditFormula->toPlainText(), qApp->Settings()->GetOsSeparator())); - const QString postfix = UnitsToStr(qApp->patternUnit(), true); + const QString postfix = UnitsToStr(qApp->patternUnits(), true); dialog->setPostfix(postfix);//Show unit in dialog lable (cm, mm or inch) if (dialog->exec() == QDialog::Accepted) @@ -513,7 +513,7 @@ void DialogFinalMeasurements::FillFinalMeasurements(bool freshCall) //--------------------------------------------------------------------------------------------------------------------- void DialogFinalMeasurements::ShowUnits() { - const QString unit = UnitsToStr(qApp->patternUnit()); + const QString unit = UnitsToStr(qApp->patternUnits()); { // calculated value @@ -554,7 +554,7 @@ void DialogFinalMeasurements::AddCell(const QString &text, int row, int column, //--------------------------------------------------------------------------------------------------------------------- bool DialogFinalMeasurements::EvalUserFormula(const QString &formula, bool fromUser) { - const QString postfix = UnitsToStr(qApp->patternUnit());//Show unit in dialog lable (cm, mm or inch) + const QString postfix = UnitsToStr(qApp->patternUnits());//Show unit in dialog lable (cm, mm or inch) if (formula.isEmpty()) { ui->labelCalculatedValue->setText(tr("Error") + " (" + postfix + "). " + tr("Empty field.")); diff --git a/src/app/valentina/dialogs/dialogincrements.cpp b/src/app/valentina/dialogs/dialogincrements.cpp index 890452cb4..da7c69478 100644 --- a/src/app/valentina/dialogs/dialogincrements.cpp +++ b/src/app/valentina/dialogs/dialogincrements.cpp @@ -268,7 +268,7 @@ void DialogIncrements::FillAnglesCurves() //--------------------------------------------------------------------------------------------------------------------- void DialogIncrements::ShowUnits() { - const QString unit = UnitsToStr(qApp->patternUnit()); + const QString unit = UnitsToStr(qApp->patternUnits()); ShowHeaderUnits(ui->tableWidgetIncrement, 1, unit);// calculated value ShowHeaderUnits(ui->tableWidgetIncrement, 2, unit);// formula @@ -361,7 +361,7 @@ QString DialogIncrements::ClearIncrementName(const QString &name) const //--------------------------------------------------------------------------------------------------------------------- bool DialogIncrements::EvalIncrementFormula(const QString &formula, bool fromUser, VContainer *data, QLabel *label) { - const QString postfix = UnitsToStr(qApp->patternUnit());//Show unit in dialog lable (cm, mm or inch) + const QString postfix = UnitsToStr(qApp->patternUnits());//Show unit in dialog lable (cm, mm or inch) if (formula.isEmpty()) { label->setText(tr("Error") + " (" + postfix + "). " + tr("Empty field.")); @@ -1228,7 +1228,7 @@ void DialogIncrements::SaveIncrFormula() { QTableWidgetItem *result = table->item(row, 1); //Show unit in dialog lable (cm, mm or inch) - const QString postfix = UnitsToStr(qApp->patternUnit()); + const QString postfix = UnitsToStr(qApp->patternUnits()); labelCalculatedValue->setText(result->text() + QChar(QChar::Space) +postfix); return; } @@ -1236,7 +1236,7 @@ void DialogIncrements::SaveIncrFormula() if (text.isEmpty()) { //Show unit in dialog lable (cm, mm or inch) - const QString postfix = UnitsToStr(qApp->patternUnit()); + const QString postfix = UnitsToStr(qApp->patternUnits()); labelCalculatedValue->setText(tr("Error") + " (" + postfix + "). " + tr("Empty field.")); return; } @@ -1374,7 +1374,7 @@ void DialogIncrements::Fx() dialog->SetFormula(qApp->TrVars()->TryFormulaFromUser(plainTextEditFormula->toPlainText(), qApp->Settings()->GetOsSeparator())); - const QString postfix = UnitsToStr(qApp->patternUnit(), true); + const QString postfix = UnitsToStr(qApp->patternUnits(), true); dialog->setPostfix(postfix);//Show unit in dialog lable (cm, mm or inch) if (dialog->exec() == QDialog::Accepted) diff --git a/src/app/valentina/dialogs/dialoglayoutscale.cpp b/src/app/valentina/dialogs/dialoglayoutscale.cpp index 256c66f14..e2d374a9b 100644 --- a/src/app/valentina/dialogs/dialoglayoutscale.cpp +++ b/src/app/valentina/dialogs/dialoglayoutscale.cpp @@ -71,7 +71,7 @@ DialogLayoutScale::~DialogLayoutScale() void DialogLayoutScale::SetTiledMargins(QMarginsF margins) { // read Margins top, right, bottom, left - margins = UnitConvertor(margins, Unit::Mm, qApp->patternUnit()); + margins = UnitConvertor(margins, Unit::Mm, qApp->patternUnits()); ui->doubleSpinBoxLeftField->setValue(margins.left()); ui->doubleSpinBoxTopField->setValue(margins.top()); @@ -89,7 +89,7 @@ QMarginsF DialogLayoutScale::GetTiledMargins() const ui->doubleSpinBoxBottomField->value() ); - return UnitConvertor(margins, qApp->patternUnit(), Unit::Mm); + return UnitConvertor(margins, qApp->patternUnits(), Unit::Mm); } //--------------------------------------------------------------------------------------------------------------------- @@ -181,7 +181,7 @@ void DialogLayoutScale::VerticalScaleChanged(double d) void DialogLayoutScale::ReadSettings() { VSettings *settings = qApp->ValentinaSettings(); - const Unit unit = qApp->patternUnit(); + const Unit unit = qApp->patternUnits(); // read Margins top, right, bottom, left const QMarginsF margins = settings->GetTiledPDFMargins(unit); @@ -201,7 +201,7 @@ void DialogLayoutScale::ReadSettings() void DialogLayoutScale::WriteSettings() const { VSettings *settings = qApp->ValentinaSettings(); - const Unit unit = qApp->patternUnit(); + const Unit unit = qApp->patternUnits(); // write Margins top, right, bottom, left QMarginsF margins = QMarginsF( diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index a4a70120a..068d20550 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -140,7 +140,7 @@ DialogPatternProperties::DialogPatternProperties(VPattern *doc, VContainer *pat connect(bCancel, &QPushButton::clicked, this, &DialogPatternProperties::close); ui->tabWidget->setCurrentIndex(0); - if (qApp->patternType() != MeasurementsType::Multisize) + if (qApp->GetMeasurementsType() != MeasurementsType::Multisize) { ui->tabWidget->setTabEnabled(1, false); } @@ -198,7 +198,7 @@ DialogPatternProperties::DialogPatternProperties(VPattern *doc, VContainer *pat ui->lineEditPatternNumber->setText(doc->GetPatternNumber()); ui->lineEditCompanyName->setText(doc->GetCompanyName()); - if (qApp->patternType() == MeasurementsType::Individual) + if (qApp->GetMeasurementsType() == MeasurementsType::Individual) { ui->lineEditCustomerName->setText(qApp->GetCustomerName()); ui->lineEditCustomerName->setReadOnly(true); @@ -629,7 +629,7 @@ void DialogPatternProperties::SaveLabelData() doc->SetPatternName(ui->lineEditPatternName->text()); doc->SetPatternNumber(ui->lineEditPatternNumber->text()); doc->SetCompanyName(ui->lineEditCompanyName->text()); - if (qApp->patternType() != MeasurementsType::Individual) + if (qApp->GetMeasurementsType() != MeasurementsType::Individual) { doc->SetCustomerName(ui->lineEditCustomerName->text()); } diff --git a/src/app/valentina/dialogs/dialogsavelayout.cpp b/src/app/valentina/dialogs/dialogsavelayout.cpp index c17f43f19..af2a962c9 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.cpp +++ b/src/app/valentina/dialogs/dialogsavelayout.cpp @@ -676,7 +676,7 @@ void DialogSaveLayout::SetTiledExportMode(bool tiledExportMode) void DialogSaveLayout::SetTiledMargins(QMarginsF margins) { // read Margins top, right, bottom, left - margins = UnitConvertor(margins, Unit::Mm, qApp->patternUnit()); + margins = UnitConvertor(margins, Unit::Mm, qApp->patternUnits()); ui->doubleSpinBoxLeftField->setValue(margins.left()); ui->doubleSpinBoxTopField->setValue(margins.top()); @@ -694,7 +694,7 @@ QMarginsF DialogSaveLayout::GetTiledMargins() const ui->doubleSpinBoxBottomField->value() ); - return UnitConvertor(margins, qApp->patternUnit(), Unit::Mm); + return UnitConvertor(margins, qApp->patternUnits(), Unit::Mm); } //--------------------------------------------------------------------------------------------------------------------- @@ -892,7 +892,7 @@ void DialogSaveLayout::RemoveFormatFromList(LayoutExportFormats format) void DialogSaveLayout::ReadSettings() { VSettings *settings = qApp->ValentinaSettings(); - const Unit unit = qApp->patternUnit(); + const Unit unit = qApp->patternUnits(); // read Margins top, right, bottom, left const QMarginsF margins = settings->GetTiledPDFMargins(unit); @@ -946,7 +946,7 @@ void DialogSaveLayout::WriteSettings() const } VSettings *settings = qApp->ValentinaSettings(); - const Unit unit = qApp->patternUnit(); + const Unit unit = qApp->patternUnits(); // write Margins top, right, bottom, left QMarginsF margins = QMarginsF( diff --git a/src/app/valentina/dialogs/vwidgetdetails.cpp b/src/app/valentina/dialogs/vwidgetdetails.cpp index 084ababfa..609d533a9 100644 --- a/src/app/valentina/dialogs/vwidgetdetails.cpp +++ b/src/app/valentina/dialogs/vwidgetdetails.cpp @@ -297,7 +297,7 @@ void VWidgetDetails::ShowContextMenu(const QPoint &pos) catch (const VExceptionBadId &) { const QString errorMsg = tr("Cannot find piece by id '%1'").arg(id); - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } } diff --git a/src/app/valentina/dialogs/vwidgetgroups.cpp b/src/app/valentina/dialogs/vwidgetgroups.cpp index 827bf5ee2..af6bb0c5a 100644 --- a/src/app/valentina/dialogs/vwidgetgroups.cpp +++ b/src/app/valentina/dialogs/vwidgetgroups.cpp @@ -230,7 +230,7 @@ void VWidgetGroups::CtxMenu(const QPoint &pos) } else if (selectedAction == actionPreferences) { - QScopedPointer fackeContainer(new VContainer(qApp->TrVars(), qApp->patternUnitP(), + QScopedPointer fackeContainer(new VContainer(qApp->TrVars(), qApp->patternUnitsP(), VContainer::UniqueNamespace())); QScopedPointer dialog(new DialogGroup(fackeContainer.data(), NULL_ID, this)); dialog->SetName(doc->GetGroupName(id)); diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index e3651d4ec..7297708f8 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -173,7 +173,7 @@ void WarningNotUniquePieceName(const QHash *allDetails) { const QString errorMsg = QObject::tr("Piece name '%1' is not unique.").arg(pieceName); qApp->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } ++i; @@ -200,23 +200,20 @@ MainWindow::MainWindow(QWidget *parent) currentDrawIndex(0), currentToolBoxIndex(0), drawMode(true), leftGoToStage(nullptr), rightGoToStage(nullptr), autoSaveTimer(nullptr), guiEnabled(true), - gradationHeights(nullptr), - gradationSizes(nullptr), - gradationHeightsLabel(nullptr), - gradationSizesLabel(nullptr), - zoomScale(nullptr), - doubleSpinBoxScale(nullptr), toolOptions(nullptr), groupsWidget(nullptr), detailsWidget(nullptr), lock(nullptr), toolButtonPointerList(), m_progressBar(new QProgressBar(this)), - m_statusLabel(new QLabel(this)) + m_statusLabel(new QLabel(this)), + m_gradation(new QTimer(this)) { CreateActions(); InitScenes(); + connect(m_gradation, &QTimer::timeout, this, &MainWindow::GradationChanged); + doc = new VPattern(pattern, sceneDraw, sceneDetails); connect(doc, &VPattern::ClearMainWindow, this, &MainWindow::Clear); connect(doc, &VPattern::patternChanged, this, &MainWindow::PatternChangesWereSaved); @@ -510,33 +507,33 @@ void MainWindow::InitScenes() //--------------------------------------------------------------------------------------------------------------------- bool MainWindow::LoadMeasurements(const QString &path) { - QSharedPointer m = OpenMeasurementFile(path); + m = OpenMeasurementFile(path); if (m->isNull()) { return false; } - if (qApp->patternUnit() == Unit::Inch && m->Type() == MeasurementsType::Multisize) - { - qWarning()<DimensionABase(), m->MUnit(), *m->GetData()->GetPatternUnit()); - const qreal height = UnitConvertor(m->DimensionBBase(), m->MUnit(), *m->GetData()->GetPatternUnit()); - try { - qApp->setPatternType(m->Type()); + qApp->SetMeasurementsType(m->Type()); if (m->Type() == MeasurementsType::Individual) { qApp->SetCustomerName(m->Customer()); + qApp->SetCustomerBirthDate(m->BirthDate()); + qApp->SetCustomerEmail(m->Email()); + } + else if (m->Type() == MeasurementsType::Multisize) + { + m_currentDimensionA = m->DimensionABase(); + m_currentDimensionB = m->DimensionBBase(); + m_currentDimensionC = m->DimensionCBase(); } ToolBarOption(); + SetDimensionBases(); pattern->ClearVariables(VarType::Measurement); m->StoreNames(false); - m->ReadMeasurements(height, size); + m->ReadMeasurements(m_currentDimensionA, m_currentDimensionB, m_currentDimensionC); } catch (VExceptionEmptyParameter &e) { @@ -551,31 +548,33 @@ bool MainWindow::LoadMeasurements(const QString &path) if (m->Type() == MeasurementsType::Multisize) { - pattern->SetSize(size); - pattern->SetHeight(height); + StoreMultisizeMDimensions(); doc->SetPatternWasChanged(true); emit doc->UpdatePatternLabel(); } else if (m->Type() == MeasurementsType::Individual) { - SetSizeHeightForIndividualM(); + StoreIndividualMDimensions(); + + doc->SetPatternWasChanged(true); + emit doc->UpdatePatternLabel(); } return true; } //--------------------------------------------------------------------------------------------------------------------- -bool MainWindow::UpdateMeasurements(const QString &path, int size, int height) +bool MainWindow::UpdateMeasurements(const QString &path, int baseA, int baseB, int baseC) { - QSharedPointer m = OpenMeasurementFile(path); + m = OpenMeasurementFile(path); if (m->isNull()) { return false; } - if (qApp->patternType() != m->Type()) + if (qApp->GetMeasurementsType() != m->Type()) { qCCritical(vMainWindow, "%s", qUtf8Printable(tr("Measurement files types have not match."))); if (not VApplication::IsGUIMode()) @@ -589,10 +588,12 @@ bool MainWindow::UpdateMeasurements(const QString &path, int size, int height) { pattern->ClearVariables(VarType::Measurement); m->StoreNames(false); - m->ReadMeasurements(height, size); + m->ReadMeasurements(baseA, baseB, baseC); if (m->Type() == MeasurementsType::Individual) { qApp->SetCustomerName(m->Customer()); + qApp->SetCustomerBirthDate(m->BirthDate()); + qApp->SetCustomerEmail(m->Email()); } } catch (VExceptionEmptyParameter &e) @@ -608,15 +609,17 @@ bool MainWindow::UpdateMeasurements(const QString &path, int size, int height) if (m->Type() == MeasurementsType::Multisize) { - pattern->SetSize(size); - pattern->SetHeight(height); + StoreMultisizeMDimensions(); doc->SetPatternWasChanged(true); emit doc->UpdatePatternLabel(); } else if (m->Type() == MeasurementsType::Individual) { - SetSizeHeightForIndividualM(); + StoreIndividualMDimensions(); + + doc->SetPatternWasChanged(true); + emit doc->UpdatePatternLabel(); } return true; @@ -1570,6 +1573,8 @@ void MainWindow::changeEvent(QEvent *event) ui->dockWidgetGroups->setToolTip(tr("Show which details will go in layout")); } + ToolBarOption(); + UpdateWindowTitle(); emit sceneDetails->LanguageChanged(); } @@ -1792,14 +1797,14 @@ void MainWindow::LoadMultisize() if (not mPath.isEmpty()) { QString hText; - if (not gradationHeights.isNull()) + if (not dimensionA.isNull()) { - hText = gradationHeights->currentText(); + hText = dimensionA->currentText(); } QString sText; - if (not gradationSizes.isNull()) + if (not dimensionB.isNull()) { - sText = gradationSizes->currentText(); + sText = dimensionB->currentText(); } if(LoadMeasurements(mPath)) @@ -1818,16 +1823,16 @@ void MainWindow::LoadMultisize() UpdateWindowTitle(); - if (qApp->patternType() == MeasurementsType::Multisize) + if (qApp->GetMeasurementsType() == MeasurementsType::Multisize) { - if (not hText.isEmpty() && not gradationHeights.isNull()) + if (not hText.isEmpty() && not dimensionA.isNull()) { - gradationHeights->setCurrentText(hText); + dimensionA->setCurrentText(hText); } - if (not sText.isEmpty() && not gradationSizes.isNull()) + if (not sText.isEmpty() && not dimensionB.isNull()) { - gradationSizes->setCurrentText(sText); + dimensionB->setCurrentText(sText); } } } @@ -1846,11 +1851,35 @@ void MainWindow::UnloadMeasurements() if (doc->ListMeasurements().isEmpty()) { watcher->removePath(AbsoluteMPath(qApp->GetPatternPath(), doc->MPath())); - if (qApp->patternType() == MeasurementsType::Multisize) + + const MeasurementsType oldType = qApp->GetMeasurementsType(); + qApp->SetMeasurementsType(MeasurementsType::Unknown); + + m.clear(); + + if (oldType == MeasurementsType::Multisize) { + m_currentDimensionA = 0; + m_currentDimensionB = 0; + m_currentDimensionC = 0; + ToolBarOption(); } - qApp->setPatternType(MeasurementsType::Unknown); + else if (oldType == MeasurementsType::Individual) + { + qApp->SetCustomerBirthDate(QDate()); + qApp->SetCustomerEmail(QString()); + qApp->SetCustomerName(QString()); + + qApp->SetDimensionHeight(0); + qApp->SetDimensionSize(0); + qApp->SetDimensionHip(0); + qApp->SetDimensionWaist(0); + + qApp->SetMeasurementsUnits(Unit::LAST_UNIT_DO_NOT_USE); + qApp->SetDimensionSizeUnits(Unit::LAST_UNIT_DO_NOT_USE); + } + doc->SetMPath(QString()); emit doc->UpdatePatternLabel(); PatternChangesWereSaved(false); @@ -1875,12 +1904,12 @@ void MainWindow::ShowMeasurements() const QString absoluteMPath = AbsoluteMPath(qApp->GetPatternPath(), doc->MPath()); QStringList arguments; - if (qApp->patternType() == MeasurementsType::Multisize) + if (qApp->GetMeasurementsType() == MeasurementsType::Multisize) { arguments = QStringList() << absoluteMPath << "-u" - << UnitsToStr(qApp->patternUnit()) + << UnitsToStr(qApp->patternUnits()) << "-e" << QString().setNum(static_cast(UnitConvertor(pattern->height(), doc->MUnit(), Unit::Cm))) << "-s" @@ -1890,7 +1919,7 @@ void MainWindow::ShowMeasurements() { arguments = QStringList() << absoluteMPath << "-u" - << UnitsToStr(qApp->patternUnit()); + << UnitsToStr(qApp->patternUnits()); } if (isNoScaling) @@ -1945,7 +1974,7 @@ void MainWindow::SyncMeasurements() if (mChanges) { const QString path = AbsoluteMPath(qApp->GetPatternPath(), doc->MPath()); - if(UpdateMeasurements(path, static_cast(pattern->size()), static_cast(pattern->height()))) + if(UpdateMeasurements(path, m_currentDimensionA, m_currentDimensionB, m_currentDimensionC)) { if (not watcher->files().contains(path)) { @@ -2031,6 +2060,150 @@ void MainWindow::CleanWaterkmarkEditors() } } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::StoreMultisizeMDimensions() +{ + qApp->SetMeasurementsUnits(m->MUnit()); + + QList dimensions = m->Dimensions().values(); + + auto StoreDimension = [this, dimensions](int index, int currentBase) + { + if (dimensions.size() > index) + { + MeasurementDimension_p dimension = dimensions.at(index); + + switch(dimension->Type()) + { + case MeasurementDimension::X: + qApp->SetDimensionHeight(currentBase); + break; + case MeasurementDimension::Y: + { + const bool fc = m->IsFullCircumference(); + qApp->SetDimensionSize(fc ? currentBase*2 : currentBase); + const bool circumference = dimension->IsCircumference(); + qApp->SetDimensionSizeUnits(circumference ? m->MUnit() : Unit::LAST_UNIT_DO_NOT_USE); + break; + } + case MeasurementDimension::W: + Q_FALLTHROUGH(); + case MeasurementDimension::Z: + { + const bool fc = m->IsFullCircumference(); + qApp->SetDimensionSize(fc ? currentBase*2 : currentBase); + break; + } + default: + break; + } + } + }; + + StoreDimension(0, m_currentDimensionA); + StoreDimension(1, m_currentDimensionB); + StoreDimension(2, m_currentDimensionC); +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::StoreIndividualMDimensions() +{ + QMap > measurements = pattern->DataMeasurements(); + + auto StoreDimension = [this, measurements](IMD type) + { + const QString name = m->MeasurementForDimension(type); + if (not name.isEmpty() && measurements.contains(name)) + { + switch(type) + { + case IMD::X: + qApp->SetDimensionHeight(*measurements.value(name)->GetValue()); + break; + case IMD::Y: + qApp->SetDimensionSize(*measurements.value(name)->GetValue()); + break; + case IMD::W: + qApp->SetDimensionHip(*measurements.value(name)->GetValue()); + break; + case IMD::Z: + qApp->SetDimensionWaist(*measurements.value(name)->GetValue()); + break; + case IMD::N: + default: + break; + } + } + }; + + StoreDimension(IMD::X); + StoreDimension(IMD::Y); + StoreDimension(IMD::W); + StoreDimension(IMD::Z); +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector MainWindow::DimensionRestrictedValues(int index, const MeasurementDimension_p &dimension) +{ + QPair restriction; + + if (index == 0) + { + return dimension->ValidBases(); + } + else if (index == 1) + { + restriction = m->Restriction(m_currentDimensionA); + } + else + { + restriction = m->Restriction(m_currentDimensionA, m_currentDimensionB); + } + + const QVector bases = dimension->ValidBases(); + + int min = bases.indexOf(restriction.first) != -1 ? restriction.first : dimension->MinValue(); + int max = bases.indexOf(restriction.second) != -1 ? restriction.second : dimension->MaxValue(); + + if (min > max) + { + min = dimension->MinValue(); + max = dimension->MaxValue(); + } + + return VAbstartMeasurementDimension::ValidBases(min, max, dimension->Step()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::SetDimensionBases() +{ + const QList dimensions = m->Dimensions().values(); + + auto SetBase = [dimensions](int index, QPointer control, int &value) + { + if (dimensions.size() > index) + { + SCASSERT(control != nullptr) + + MeasurementDimension_p dimension = dimensions.at(index); + + const qint32 i = control->findData(value); + if (i != -1) + { + control->setCurrentIndex(i); + } + else + { + value = control->currentData().toInt(); + } + } + }; + + SetBase(0, dimensionA, m_currentDimensionA); + SetBase(1, dimensionB, m_currentDimensionB); + SetBase(2, dimensionC, m_currentDimensionC); +} + //--------------------------------------------------------------------------------------------------------------------- #if defined(Q_OS_MAC) void MainWindow::OpenAt(QAction *where) @@ -2053,22 +2226,7 @@ void MainWindow::OpenAt(QAction *where) void MainWindow::ToolBarOption() { ui->toolBarOption->clear(); - if (not gradationHeights.isNull()) - { - delete gradationHeights; - } - if (not gradationSizes.isNull()) - { - delete gradationSizes; - } - if (not gradationHeightsLabel.isNull()) - { - delete gradationHeightsLabel; - } - if (not gradationSizesLabel.isNull()) - { - delete gradationSizesLabel; - } + if (not zoomScale.isNull()) { delete zoomScale; @@ -2078,32 +2236,18 @@ void MainWindow::ToolBarOption() delete doubleSpinBoxScale; } - if (qApp->patternType() == MeasurementsType::Multisize) + if (not m_mouseCoordinate.isNull()) { - const QStringList listHeights = VMeasurement::ListHeights(doc->GetGradationHeights(), qApp->patternUnit()); - const QStringList listSizes = VMeasurement::ListSizes(doc->GetGradationSizes(), qApp->patternUnit()); - - gradationHeightsLabel = new QLabel(tr("Height:"), this); - gradationHeights = SetGradationList(gradationHeightsLabel, listHeights); - - // set default height - SetDefaultHeight(); - - connect(gradationHeights.data(), &QComboBox::currentTextChanged, - this, &MainWindow::ChangedHeight); - - gradationSizesLabel = new QLabel(tr("Size:"), this); - gradationSizes = SetGradationList(gradationSizesLabel, listSizes); - - // set default size - SetDefaultSize(); - - connect(gradationSizes.data(), &QComboBox::currentTextChanged, - this, &MainWindow::ChangedSize); - - ui->toolBarOption->addSeparator(); + delete m_mouseCoordinate; } + if (not m_unreadPatternMessage.isNull()) + { + delete m_unreadPatternMessage; + } + + InitDimensionControls(); + zoomScale = new QLabel(tr("Scale:"), this); ui->toolBarOption->addWidget(zoomScale); @@ -2111,13 +2255,13 @@ void MainWindow::ToolBarOption() doubleSpinBoxScale->setDecimals(1); doubleSpinBoxScale->setSuffix("%"); ScaleChanged(ui->view->transform().m11()); - connect(doubleSpinBoxScale.data(), QOverload::of(&QDoubleSpinBox::valueChanged), + connect(doubleSpinBoxScale, QOverload::of(&QDoubleSpinBox::valueChanged), this, [this](double d){ui->view->Zoom(d/100.0);}); ui->toolBarOption->addWidget(doubleSpinBoxScale); ui->toolBarOption->addSeparator(); - m_mouseCoordinate = new QLabel(QString("0, 0 (%1)").arg(UnitsToStr(qApp->patternUnit(), true))); + m_mouseCoordinate = new QLabel(QString("0, 0 (%1)").arg(UnitsToStr(qApp->patternUnits(), true))); ui->toolBarOption->addWidget(m_mouseCoordinate); ui->toolBarOption->addSeparator(); @@ -2125,18 +2269,6 @@ void MainWindow::ToolBarOption() ui->toolBarOption->addWidget(m_unreadPatternMessage); } -//--------------------------------------------------------------------------------------------------------------------- -QComboBox *MainWindow::SetGradationList(QLabel *label, const QStringList &list) -{ - ui->toolBarOption->addWidget(label); - - QComboBox *comboBox = new QComboBox(this); - comboBox->addItems(list); - ui->toolBarOption->addWidget(comboBox); - - return comboBox; -} - //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ToolBarStages() { @@ -2363,7 +2495,7 @@ void MainWindow::MouseMove(const QPointF &scenePos) m_mouseCoordinate->setText(QStringLiteral("%1, %2 (%3)") .arg(static_cast(qApp->fromPixel(scenePos.x()))) .arg(static_cast(qApp->fromPixel(scenePos.y()))) - .arg(UnitsToStr(qApp->patternUnit(), true))); + .arg(UnitsToStr(qApp->patternUnits(), true))); } } @@ -2714,7 +2846,7 @@ void MainWindow::ActionDraw(bool checked) SetEnableWidgets(true); ui->toolBox->setCurrentIndex(currentToolBoxIndex); - if (qApp->patternType() == MeasurementsType::Multisize) + if (qApp->GetMeasurementsType() == MeasurementsType::Multisize) { ui->toolBarOption->setVisible(true); } @@ -2789,7 +2921,7 @@ void MainWindow::ActionDetails(bool checked) SetEnableWidgets(true); ui->toolBox->setCurrentIndex(ui->toolBox->indexOf(ui->detailPage)); - if (qApp->patternType() == MeasurementsType::Multisize) + if (qApp->GetMeasurementsType() == MeasurementsType::Multisize) { ui->toolBarOption->setVisible(true); } @@ -2904,7 +3036,7 @@ void MainWindow::ActionLayout(bool checked) m_mouseCoordinate->setText(QString()); } - if (qApp->patternType() == MeasurementsType::Multisize) + if (qApp->GetMeasurementsType() == MeasurementsType::Multisize) { ui->toolBarOption->setVisible(false); } @@ -3227,8 +3359,8 @@ void MainWindow::Clear() ui->actionPreviousPatternPiece->setEnabled(false); ui->actionNextPatternPiece->setEnabled(false); SetEnableTool(false); - qApp->setPatternUnit(Unit::Cm); - qApp->setPatternType(MeasurementsType::Unknown); + qApp->SetPatternUnits(Unit::Cm); + qApp->SetMeasurementsType(MeasurementsType::Unknown); ui->toolBarOption->clear(); #ifndef QT_NO_CURSOR QGuiApplication::restoreOverrideCursor(); @@ -3626,56 +3758,6 @@ void MainWindow::SetEnableWidgets(bool enable) ui->view->setEnabled(enable); } -//--------------------------------------------------------------------------------------------------------------------- -void MainWindow::UpdateHeightsList(const QStringList &list) -{ - QString val; - if (gradationHeights->currentIndex() != -1) - { - val = gradationHeights->currentText(); - } - - gradationHeights->blockSignals(true); - gradationHeights->clear(); - gradationHeights->addItems(list); - gradationHeights->blockSignals(false); - - int index = gradationHeights->findText(val); - if (index != -1) - { - gradationHeights->setCurrentIndex(index); - } - else - { - ChangedHeight(list.at(0)); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void MainWindow::UpdateSizesList(const QStringList &list) -{ - QString val; - if (gradationSizes->currentIndex() != -1) - { - val = gradationSizes->currentText(); - } - - gradationSizes->blockSignals(true); - gradationSizes->clear(); - gradationSizes->addItems(list); - gradationSizes->blockSignals(false); - - int index = gradationSizes->findText(val); - if (index != -1) - { - gradationSizes->setCurrentIndex(index); - } - else - { - ChangedSize(list.at(0)); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief on_actionNew_triggered create new empty pattern. @@ -3693,7 +3775,7 @@ void MainWindow::on_actionNew_triggered() if (newPattern.exec() == QDialog::Accepted) { patternPieceName = newPattern.name(); - qApp->setPatternUnit(newPattern.PatternUnit()); + qApp->SetPatternUnits(newPattern.PatternUnit()); qCDebug(vMainWindow, "PP name: %s", qUtf8Printable(patternPieceName)); } else @@ -3708,7 +3790,7 @@ void MainWindow::on_actionNew_triggered() AddPP(patternPieceName); - m_mouseCoordinate = new QLabel(QString("0, 0 (%1)").arg(UnitsToStr(qApp->patternUnit(), true))); + m_mouseCoordinate = new QLabel(QString("0, 0 (%1)").arg(UnitsToStr(qApp->patternUnits(), true))); ui->toolBarOption->addWidget(m_mouseCoordinate); m_curFileFormatVersion = VPatternConverter::PatternMaxVer; @@ -3739,45 +3821,55 @@ void MainWindow::PatternChangesWereSaved(bool saved) } //--------------------------------------------------------------------------------------------------------------------- -/** - * @brief ChangedSize change new size value. - * @param text value size. - */ -void MainWindow::ChangedSize(const QString & text) +void MainWindow::DimensionABaseChanged() { - const int size = static_cast(pattern->size()); - if (UpdateMeasurements(AbsoluteMPath(qApp->GetPatternPath(), doc->MPath()), text.toInt(), - static_cast(pattern->height()))) - { - doc->LiteParseTree(Document::FullLiteParse); - emit sceneDetails->DimensionsChanged(); - } - else - { - qCWarning(vMainWindow, "%s", qUtf8Printable(tr("Couldn't update measurements."))); + m_currentDimensionA = dimensionA->currentData().toInt(); - const qint32 index = gradationSizes->findText(QString().setNum(size)); - if (index != -1) + const QList dimensions = m->Dimensions().values(); + if (dimensions.size() > 1) + { + MeasurementDimension_p dimension = dimensions.at(1); + InitDimensionGradation(1, dimension, dimensionB); + + if (dimensions.size() > 2) { - gradationSizes->setCurrentIndex(index); - } - else - { - qCDebug(vMainWindow, "Couldn't restore size value."); + dimension = dimensions.at(2); + InitDimensionGradation(2, dimension, dimensionC); } } + + m_gradation->start(); } //--------------------------------------------------------------------------------------------------------------------- -/** - * @brief ChangedGrowth change new height value. - * @param text value height. - */ -void MainWindow::ChangedHeight(const QString &text) +void MainWindow::DimensionBBaseChanged() { - const int height = static_cast(pattern->height()); - if (UpdateMeasurements(AbsoluteMPath(qApp->GetPatternPath(), doc->MPath()), static_cast(pattern->size()), - text.toInt())) + m_currentDimensionB = dimensionB->currentData().toInt(); + + const QList dimensions = m->Dimensions().values(); + + if (dimensions.size() > 2) + { + MeasurementDimension_p dimension = dimensions.at(2); + InitDimensionGradation(2, dimension, dimensionC); + } + + m_gradation->start(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::DimensionCBaseChanged() +{ + m_currentDimensionC = dimensionC->currentData().toInt(); + m_gradation->start(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::GradationChanged() +{ + m_gradation->stop(); + if (UpdateMeasurements(AbsoluteMPath(qApp->GetPatternPath(), doc->MPath()), m_currentDimensionA, + m_currentDimensionB, m_currentDimensionC)) { doc->LiteParseTree(Document::FullLiteParse); emit sceneDetails->DimensionsChanged(); @@ -3785,16 +3877,6 @@ void MainWindow::ChangedHeight(const QString &text) else { qCWarning(vMainWindow, "%s", qUtf8Printable(tr("Couldn't update measurements."))); - - const qint32 index = gradationHeights->findText(QString().setNum(height)); - if (index != -1) - { - gradationHeights->setCurrentIndex(index); - } - else - { - qCDebug(vMainWindow, "Couldn't restore height value."); - } } } @@ -3823,43 +3905,181 @@ void MainWindow::ClearPatternMessages() } //--------------------------------------------------------------------------------------------------------------------- -void MainWindow::SetDefaultHeight() +void MainWindow::InitDimensionControls() { - const QString defHeight = QString().setNum(doc->GetDefCustomHeight()); - int index = gradationHeights->findText(defHeight); - if (index != -1) + if (not dimensionA.isNull()) { - gradationHeights->setCurrentIndex(index); + delete dimensionA; } - else + if (not dimensionALabel.isNull()) { - index = gradationHeights->findText(QString().setNum(pattern->height())); - if (index != -1) + delete dimensionALabel; + } + + if (not dimensionB.isNull()) + { + delete dimensionB; + } + if (not dimensionBLabel.isNull()) + { + delete dimensionBLabel; + } + + if (not dimensionC.isNull()) + { + delete dimensionC; + } + if (not dimensionCLabel.isNull()) + { + delete dimensionCLabel; + } + + if (qApp->GetMeasurementsType() == MeasurementsType::Multisize) + { + const QList dimensions = m->Dimensions().values(); + const QString unit = UnitsToStr(qApp->MeasurementsUnits(), true); + + auto InitControl = [this, dimensions, unit](int index, QPointer &name, QPointer &control) { - gradationHeights->setCurrentIndex(index); + if (dimensions.size() > index) + { + MeasurementDimension_p dimension = dimensions.at(index); + + if (name.isNull()) + { + name = new QLabel(VAbstartMeasurementDimension::DimensionName(dimension->Type())+QChar(':')); + } + else + { + name->setText(VAbstartMeasurementDimension::DimensionName(dimension->Type())+QChar(':')); + } + name->setToolTip(VAbstartMeasurementDimension::DimensionToolTip(dimension->Type(), + dimension->IsCircumference(), + m->IsFullCircumference())); + + if (control.isNull()) + { + control = new QComboBox; + } + + InitDimensionGradation(index, dimension, control); + + ui->toolBarOption->addWidget(name); + ui->toolBarOption->addWidget(control); + } + }; + + InitControl(0, dimensionALabel, dimensionA); + InitControl(1, dimensionBLabel, dimensionB); + InitControl(2, dimensionCLabel, dimensionC); + + if (not dimensionA.isNull()) + { + connect(dimensionA, QOverload::of(&QComboBox::currentIndexChanged), + this, &MainWindow::DimensionABaseChanged); } + + if (not dimensionB.isNull()) + { + connect(dimensionB, QOverload::of(&QComboBox::currentIndexChanged), + this, &MainWindow::DimensionBBaseChanged); + } + + if (not dimensionC.isNull()) + { + connect(dimensionC, QOverload::of(&QComboBox::currentIndexChanged), + this, &MainWindow::DimensionCBaseChanged); + } + + ui->toolBarOption->addSeparator(); } - pattern->SetHeight(gradationHeights->currentText().toInt()); } //--------------------------------------------------------------------------------------------------------------------- -void MainWindow::SetDefaultSize() +void MainWindow::InitDimensionGradation(int index, const MeasurementDimension_p &dimension, QPointer control) { - const QString defSize = QString().setNum(doc->GetDefCustomSize()); - int index = gradationSizes->findText(defSize); - if (index != -1) + SCASSERT(control != nullptr) + + const bool fc = m->IsFullCircumference(); + const QString unit = UnitsToStr(qApp->MeasurementsUnits(), true); + + int current = -1; + if (control->currentIndex() != -1) { - gradationSizes->setCurrentIndex(index); + current = control->currentData().toInt(); + } + + control->blockSignals(true); + control->clear(); + + const QVector bases = DimensionRestrictedValues(index, dimension); + const DimesionLabels labels = dimension->Labels(); + + if (dimension->Type() == MeasurementDimension::X) + { + for(auto base : bases) + { + 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 (labels.contains(base) && not labels.value(base).isEmpty()) + { + control->addItem(labels.value(base), base); + } + else + { + if (dimension->IsCircumference()) + { + control->addItem(QString("%1 %2").arg(fc ? base*2 : base).arg(unit), base); + } + else + { + control->addItem(QString::number(base), base); + } + } + } + } + else if (dimension->Type() == MeasurementDimension::W || dimension->Type() == MeasurementDimension::Z) + { + for(auto base : bases) + { + 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); + } + } + } + + // after initialization the current index is 0. The signal for changing the index will not be triggered if not make + // it invalid first + control->setCurrentIndex(-1); + + int i = control->findData(current); + if (i != -1) + { + control->setCurrentIndex(i); + control->blockSignals(false); } else { - index = gradationSizes->findText(QString().setNum(pattern->size())); - if (index != -1) - { - gradationSizes->setCurrentIndex(index); - } + control->blockSignals(false); + control->setCurrentIndex(0); } - pattern->SetSize(gradationSizes->currentText().toInt()); } //--------------------------------------------------------------------------------------------------------------------- @@ -4629,11 +4849,6 @@ void MainWindow::CreateActions() connect(ui->actionPattern_properties, &QAction::triggered, this, [this]() { DialogPatternProperties proper(doc, pattern, this); - connect(&proper, &DialogPatternProperties::UpdateGradation, this, [this]() - { - UpdateHeightsList(VMeasurement::ListHeights(doc->GetGradationHeights(), qApp->patternUnit())); - UpdateSizesList(VMeasurement::ListSizes(doc->GetGradationSizes(), qApp->patternUnit())); - }); proper.exec(); }); @@ -4909,7 +5124,7 @@ bool MainWindow::LoadPattern(QString fileName, const QString& customMeasureFile) { doc->SetMPath(RelativeMPath(fileName, customMeasureFile)); } - qApp->setPatternUnit(doc->MUnit()); + qApp->SetPatternUnits(doc->MUnit()); QString path = AbsoluteMPath(fileName, doc->MPath()); QString fixedMPath; @@ -4976,7 +5191,7 @@ bool MainWindow::LoadPattern(QString fileName, const QString& customMeasureFile) } } - if (qApp->patternType() == MeasurementsType::Unknown) + if (qApp->GetMeasurementsType() == MeasurementsType::Unknown) {// Show toolbar only if was not uploaded any measurements. ToolBarOption(); } @@ -4996,7 +5211,7 @@ bool MainWindow::LoadPattern(QString fileName, const QString& customMeasureFile) { doc->SetMPath(RelativeMPath(fileName, fixedMPath)); } - qApp->setPatternUnit(doc->MUnit()); + qApp->SetPatternUnits(doc->MUnit()); } } catch (VException &e) @@ -5463,7 +5678,7 @@ QString MainWindow::CheckPathToMeasurements(const QString &patternPath, const QS CheckRequiredMeasurements(m.data()); - qApp->setPatternType(patternType); + qApp->SetMeasurementsType(patternType); doc->SetMPath(RelativeMPath(patternPath, mPath)); return mPath; } @@ -5700,13 +5915,13 @@ bool MainWindow::SetSize(const QString &text) { if (this->isWindowModified() || not qApp->GetPatternPath().isEmpty()) { - if (qApp->patternType() == MeasurementsType::Multisize) + if (qApp->GetMeasurementsType() == MeasurementsType::Multisize) { const int size = static_cast(UnitConvertor(text.toInt(), Unit::Cm, *pattern->GetPatternUnit())); - const qint32 index = gradationSizes->findText(QString().setNum(size)); + const qint32 index = dimensionB->findText(QString().setNum(size)); if (index != -1) { - gradationSizes->setCurrentIndex(index); + dimensionB->setCurrentIndex(index); } else { @@ -5743,13 +5958,13 @@ bool MainWindow::SetHeight(const QString &text) { if (this->isWindowModified() || not qApp->GetPatternPath().isEmpty()) { - if (qApp->patternType() == MeasurementsType::Multisize) + if (qApp->GetMeasurementsType() == MeasurementsType::Multisize) { const int height = static_cast(UnitConvertor(text.toInt(), Unit::Cm, *pattern->GetPatternUnit())); - const qint32 index = gradationHeights->findText(QString().setNum(height)); + const qint32 index = dimensionA->findText(QString().setNum(height)); if (index != -1) { - gradationHeights->setCurrentIndex(index); + dimensionA->setCurrentIndex(index); } else { diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index 1ec84656f..fd8e2f172 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -32,7 +32,9 @@ #include "mainwindowsnogui.h" #include "core/vcmdexport.h" #include "../vmisc/vlockguard.h" +#include "../vformat/vdimensions.h" +#include #include namespace Ui @@ -51,7 +53,6 @@ class DialogFinalMeasurements; class VWidgetGroups; class VWidgetDetails; class QToolButton; -class QDoubleSpinBox; class QProgressBar; class WatermarkWindow; @@ -208,8 +209,11 @@ private slots: void OpenAt(QAction *where); #endif //defined(Q_OS_MAC) - void ChangedSize(const QString &text); - void ChangedHeight(const QString &text); + void DimensionABaseChanged(); + void DimensionBBaseChanged(); + void DimensionCBaseChanged(); + + void GradationChanged(); void ShowProgress(); void ClearPatternMessages(); @@ -267,12 +271,14 @@ private: QLabel *rightGoToStage; QTimer *autoSaveTimer; bool guiEnabled; - QPointer gradationHeights; - QPointer gradationSizes; - QPointer gradationHeightsLabel; - QPointer gradationSizesLabel; - QPointer zoomScale; - QPointer doubleSpinBoxScale; + QPointer dimensionA{nullptr}; + QPointer dimensionB{nullptr}; + QPointer dimensionC{nullptr}; + QPointer dimensionALabel{nullptr}; + QPointer dimensionBLabel{nullptr}; + QPointer dimensionCLabel{nullptr}; + QPointer zoomScale{nullptr}; + QPointer doubleSpinBoxScale{nullptr}; VToolOptionsPropertyBrowser *toolOptions; VWidgetGroups *groupsWidget; VWidgetDetails *detailsWidget; @@ -285,8 +291,16 @@ private: QList> m_watermarkEditors{}; - void SetDefaultHeight(); - void SetDefaultSize(); + int m_currentDimensionA{0}; + int m_currentDimensionB{0}; + int m_currentDimensionC{0}; + + QSharedPointer m{}; + + QTimer *m_gradation; + + void InitDimensionControls(); + void InitDimensionGradation(int index, const MeasurementDimension_p &dimension, QPointer control); void ToolBarOption(); void ToolBarStages(); @@ -338,15 +352,12 @@ private: void InitAutoSave(); bool PatternPieceName(QString &name); QString CheckPathToMeasurements(const QString &patternPath, const QString &path); - QComboBox *SetGradationList(QLabel *label, const QStringList &list); void ChangePP(int index, bool zoomBestFit = true); /** * @brief EndVisualization try show dialog after and working with tool visualization. */ void EndVisualization(bool click = false); void ZoomFirstShow(); - void UpdateHeightsList(const QStringList &list); - void UpdateSizesList(const QStringList &list); void AddDocks(); void InitDocksContain(); @@ -360,7 +371,7 @@ private: void InitScenes(); bool LoadMeasurements(const QString &path); - bool UpdateMeasurements(const QString &path, int size, int height); + bool UpdateMeasurements(const QString &path, int baseA, int baseB, int baseC); void ReopenFilesAfterCrash(QStringList &args); bool DoExport(const VCommandLinePtr& expParams); @@ -393,6 +404,12 @@ private: void OpenWatermark(const QString &path = QString()); void CleanWaterkmarkEditors(); + + void StoreMultisizeMDimensions(); + void StoreIndividualMDimensions(); + + QVector DimensionRestrictedValues(int index, const MeasurementDimension_p &dimension); + void SetDimensionBases(); }; #endif // MAINWINDOW_H diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 119693d95..5798faabb 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -136,7 +136,7 @@ MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent) listDetails(), currentScene(nullptr), tempSceneLayout(nullptr), - pattern(new VContainer(qApp->TrVars(), qApp->patternUnitP(), valentinaNamespace)), + pattern(new VContainer(qApp->TrVars(), qApp->patternUnitsP(), valentinaNamespace)), doc(nullptr), papers(), shadows(), @@ -155,7 +155,6 @@ MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent) margins(), paperSize(), m_dialogSaveLayout(), - m_mouseCoordinate(), #if defined(Q_OS_WIN32) && QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) m_taskbarButton(new QWinTaskbarButton(this)), m_taskbarProgress(nullptr), @@ -930,7 +929,7 @@ void MainWindowsNoGUI::PrintPages(QPrinter *printer) { const QString errorMsg = tr("File error.\n\n%1\n\n%2").arg(e.ErrorMessage(), e.DetailedInformation()); qApp->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } } @@ -2047,33 +2046,6 @@ QString MainWindowsNoGUI::FileName() const return QFileInfo(fileName).baseName(); } -//--------------------------------------------------------------------------------------------------------------------- -void MainWindowsNoGUI::SetSizeHeightForIndividualM() const -{ - const QHash > * vars = pattern->DataVariables(); - - if (vars->contains(size_M)) - { - pattern->SetSize(*vars->value(size_M)->GetValue()); - } - else - { - pattern->SetSize(0); - } - - if (vars->contains(height_M)) - { - pattern->SetHeight(*vars->value(height_M)->GetValue()); - } - else - { - pattern->SetHeight(0); - } - - doc->SetPatternWasChanged(true); - emit doc->UpdatePatternLabel(); -} - //--------------------------------------------------------------------------------------------------------------------- bool MainWindowsNoGUI::ExportFMeasurementsToCSVData(const QString &fileName, bool withHeader, int mib, const QChar &separator) const diff --git a/src/app/valentina/mainwindowsnogui.h b/src/app/valentina/mainwindowsnogui.h index 77a69eb86..409398df6 100644 --- a/src/app/valentina/mainwindowsnogui.h +++ b/src/app/valentina/mainwindowsnogui.h @@ -122,8 +122,8 @@ protected: QSharedPointer m_dialogSaveLayout; /** @brief mouseCoordinate pointer to label who show mouse coordinate. */ - QPointer m_mouseCoordinate; - QPointer m_unreadPatternMessage{}; + QPointer m_mouseCoordinate{nullptr}; + QPointer m_unreadPatternMessage{nullptr}; #if defined(Q_OS_WIN) && QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) QWinTaskbarButton *m_taskbarButton; @@ -142,7 +142,6 @@ protected: bool GenerateLayout(VLayoutGenerator& lGenerator); int ContinueIfLayoutStale(); QString FileName() const; - void SetSizeHeightForIndividualM() const; bool ExportFMeasurementsToCSVData(const QString &fileName, bool withHeader, int mib, const QChar &separator) const; diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 763ae9415..500fd223e 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -127,7 +127,7 @@ void VPattern::CreateEmptyFile() patternElement.appendChild(createComment(FileComment())); patternElement.appendChild(CreateElementWithText(TagVersion, VPatternConverter::PatternMaxVerStr)); - patternElement.appendChild(CreateElementWithText(TagUnit, UnitsToStr(qApp->patternUnit()))); + patternElement.appendChild(CreateElementWithText(TagUnit, UnitsToStr(qApp->patternUnits()))); patternElement.appendChild(createElement(TagDescription)); patternElement.appendChild(createElement(TagNotes)); diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index 599b282c6..8605e0ce4 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -100,9 +100,11 @@ public: bool IsDefCustom() const; void SetDefCustom(bool value); + // TODO: remove int GetDefCustomHeight() const; void SetDefCustomHeight(int value); + // TODO: remove int GetDefCustomSize() const; void SetDefCustomSize(int value); diff --git a/src/libs/fervor/fvupdater.cpp b/src/libs/fervor/fvupdater.cpp index 854dd46b3..e9ee9128c 100644 --- a/src/libs/fervor/fvupdater.cpp +++ b/src/libs/fervor/fvupdater.cpp @@ -48,7 +48,7 @@ #include "../ifc/exception/vexception.h" #include "../ifc/xml/vabstractconverter.h" #include "../vmisc/projectversion.h" -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "../vmisc/vcommonsettings.h" #include "fvavailableupdate.h" #include "fvupdatewindow.h" diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index c45c7a026..6d0e3857d 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -54,7 +54,7 @@ #include "vpatternconverter.h" #include "vdomdocument.h" #include "vtoolrecord.h" -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "../vmisc/compatibility.h" #include "../vlayout/vtextmanager.h" diff --git a/src/libs/vdxf/libdxfrw/intern/drw_textcodec.cpp b/src/libs/vdxf/libdxfrw/intern/drw_textcodec.cpp index 796b41bb6..3cfd120c0 100644 --- a/src/libs/vdxf/libdxfrw/intern/drw_textcodec.cpp +++ b/src/libs/vdxf/libdxfrw/intern/drw_textcodec.cpp @@ -4,8 +4,9 @@ #include #include #include +#include #include "../drw_base.h" -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "../ifc/exception/vexception.h" namespace @@ -112,7 +113,7 @@ void DRW_TextCodec::setCodePage(const std::string *c, bool dxfFormat){ const QString errorMsg = QCoreApplication::translate("DRW_TextCodec", "No available codec for code page '%1'.") .arg(cp.c_str()); qApp->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; if (version < DRW::AC1021 && cp == "UTF-8") { diff --git a/src/libs/vformat/vmeasurements.h b/src/libs/vformat/vmeasurements.h index cffb1bc0b..b8415e621 100644 --- a/src/libs/vformat/vmeasurements.h +++ b/src/libs/vformat/vmeasurements.h @@ -89,7 +89,7 @@ public: void SetBirthDate(const QDate &date); GenderType Gender() const; - void SetGender(const GenderType &gender); + void SetGender(const GenderType &gender); QString PMSystem() const; void SetPMSystem(const QString &system); diff --git a/src/libs/vformat/vpatternrecipe.cpp b/src/libs/vformat/vpatternrecipe.cpp index 6a2756448..921781aa6 100644 --- a/src/libs/vformat/vpatternrecipe.cpp +++ b/src/libs/vformat/vpatternrecipe.cpp @@ -118,7 +118,7 @@ QDomElement VPatternRecipe::Prerequisite() QDomElement prerequisiteElement = createElement(QStringLiteral("prerequisite")); prerequisiteElement.appendChild(CreateElementWithText(QStringLiteral("valentina"), APP_VERSION_STR)); - prerequisiteElement.appendChild(CreateElementWithText(QStringLiteral("unit"), UnitsToStr(qApp->patternUnit()))); + prerequisiteElement.appendChild(CreateElementWithText(QStringLiteral("unit"), UnitsToStr(qApp->patternUnits()))); prerequisiteElement.appendChild(CreateElementWithText(QStringLiteral("author"), m_pattern->GetCompanyName())); prerequisiteElement.appendChild(CreateElementWithText(QStringLiteral("pattenName"), m_pattern->GetPatternName())); prerequisiteElement.appendChild(CreateElementWithText(QStringLiteral("description"), m_pattern->GetDescription())); @@ -437,7 +437,7 @@ QDomElement VPatternRecipe::FinalMeasurement(const VFinalMeasurement &fm) tr("Value for final measurtement '%1' is infinite or NaN. " "Please, check your calculations.").arg(fm.name)); qApp->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } SetAttribute(recipeFinalMeasurement, QStringLiteral("value"), result); diff --git a/src/libs/vgeometry/vabstractcurve.cpp b/src/libs/vgeometry/vabstractcurve.cpp index 15e6d466d..2636be479 100644 --- a/src/libs/vgeometry/vabstractcurve.cpp +++ b/src/libs/vgeometry/vabstractcurve.cpp @@ -36,7 +36,7 @@ #include #include "vabstractcurve_p.h" -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "../vmisc/compatibility.h" #include "../ifc/exception/vexceptionobjecterror.h" @@ -146,7 +146,7 @@ QVector VAbstractCurve::GetSegmentPoints(const QPointF &begin, const QP .arg(piece, name(), error); } qApp->IsPedantic() ? throw VExceptionObjectError(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } return segment; diff --git a/src/libs/vgeometry/varc_p.h b/src/libs/vgeometry/varc_p.h index 53f6289d1..4530b02a2 100644 --- a/src/libs/vgeometry/varc_p.h +++ b/src/libs/vgeometry/varc_p.h @@ -31,7 +31,7 @@ #include #include "vgeometrydef.h" -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "../vmisc/diagnostic.h" QT_WARNING_PUSH diff --git a/src/libs/vgeometry/vellipticalarc_p.h b/src/libs/vgeometry/vellipticalarc_p.h index 869ba0945..ee00d533d 100644 --- a/src/libs/vgeometry/vellipticalarc_p.h +++ b/src/libs/vgeometry/vellipticalarc_p.h @@ -2,7 +2,7 @@ #define VELLIPTICALARC_P #include -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "../vmisc/diagnostic.h" #include "vpointf.h" diff --git a/src/libs/vgeometry/vspline_p.h b/src/libs/vgeometry/vspline_p.h index 0c76aa5b3..1b71ca5a6 100644 --- a/src/libs/vgeometry/vspline_p.h +++ b/src/libs/vgeometry/vspline_p.h @@ -33,7 +33,7 @@ #include #include "vpointf.h" -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "../vmisc/vmath.h" QT_WARNING_PUSH diff --git a/src/libs/vlayout/vabstractpiece.cpp b/src/libs/vlayout/vabstractpiece.cpp index 4ba2d8b78..85f9d0d16 100644 --- a/src/libs/vlayout/vabstractpiece.cpp +++ b/src/libs/vlayout/vabstractpiece.cpp @@ -28,7 +28,7 @@ #include "vabstractpiece.h" #include "vabstractpiece_p.h" -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "../vgeometry/vpointf.h" #include "../ifc/exception/vexception.h" #include "../vmisc/vmath.h" @@ -1072,7 +1072,7 @@ QVector VAbstractPiece::Equidistant(QVector points, qreal wid { const QString errorMsg = tr("Piece '%1'. Not enough points to build seam allowance.").arg(name); qApp->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; return QVector(); } diff --git a/src/libs/vlayout/vbank.cpp b/src/libs/vlayout/vbank.cpp index 1df82536c..12861e401 100644 --- a/src/libs/vlayout/vbank.cpp +++ b/src/libs/vlayout/vbank.cpp @@ -32,7 +32,7 @@ #include #include "../vmisc/diagnostic.h" -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "../vmisc/compatibility.h" #include "vlayoutdef.h" #include "../ifc/exception/vexception.h" @@ -335,7 +335,7 @@ bool VBank::PrepareUnsorted() const qint64 square = details.at(i).Square(); if (square <= 0) { - qCCritical(lBank) << VAbstractApplication::patternMessageSignature + + qCCritical(lBank) << VAbstractValApplication::patternMessageSignature + tr("Preparing data for layout error: Detail '%1' square <= 0") .arg(details.at(i).GetName()); prepare = false; @@ -360,7 +360,7 @@ bool VBank::PrepareDetails() { if (layoutWidth <= 0) { - qCCritical(lBank) << VAbstractApplication::patternMessageSignature + + qCCritical(lBank) << VAbstractValApplication::patternMessageSignature + tr("Preparing data for layout error: Layout paper sheet <= 0"); prepare = false; return prepare; @@ -368,7 +368,7 @@ bool VBank::PrepareDetails() if (details.isEmpty()) { - qCCritical(lBank) << VAbstractApplication::patternMessageSignature + + qCCritical(lBank) << VAbstractValApplication::patternMessageSignature + tr("Preparing data for layout error: List of details is empty"); prepare = false; return prepare; @@ -391,7 +391,7 @@ bool VBank::PrepareDetails() const QString errorMsg = QObject::tr("Piece '%1' has invalid layout allowance. Please, check seam allowance" " to check how seam allowance behave.").arg(details.at(i).GetName()); qApp->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } const qreal d = details.at(i).Diagonal(); diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index b9fc0c890..6f0d74f9f 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -48,7 +48,7 @@ #include "../vpatterndb/floatItemData/vpatternlabeldata.h" #include "../vpatterndb/floatItemData/vpiecelabeldata.h" #include "../vmisc/vmath.h" -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "../vmisc/compatibility.h" #include "../vpatterndb/vcontainer.h" #include "../vpatterndb/calculator.h" @@ -269,7 +269,7 @@ QVector ConvertPassmarks(const VPiece &piece, const VContainer QObject::tr("Cannot prepare builtin passmark '%1' for piece '%2'. Passmark is empty.") .arg(pData.nodeName, piece.GetName()); qApp->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; return; } @@ -283,7 +283,7 @@ QVector ConvertPassmarks(const VPiece &piece, const VContainer "empty.") .arg(pData.nodeName, piece.GetName()); qApp->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; return; } layoutPassmark.baseLine = ConstFirst (baseLines); @@ -300,7 +300,7 @@ QVector ConvertPassmarks(const VPiece &piece, const VContainer QObject::tr("Passmark '%1' is not part of piece '%2'.") .arg(pData.nodeName, piece.GetName()); qApp->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } }; @@ -326,7 +326,7 @@ QVector ConvertPassmarks(const VPiece &piece, const VContainer QObject::tr("Cannot prepare passmark '%1' for piece '%2'. Passmark base line is empty.") .arg(pData.nodeName, piece.GetName()); qApp->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; return; } @@ -346,7 +346,7 @@ QVector ConvertPassmarks(const VPiece &piece, const VContainer QObject::tr("Cannot prepare passmark '%1' for piece '%2'. Passmark is empty.") .arg(pData.nodeName, piece.GetName()); qApp->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; return; } @@ -362,7 +362,7 @@ QVector ConvertPassmarks(const VPiece &piece, const VContainer QObject::tr("Passmark '%1' is not part of piece '%2'.") .arg(pData.nodeName, piece.GetName()); qApp->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } }; @@ -508,7 +508,7 @@ VLayoutPiece VLayoutPiece::Create(const VPiece &piece, vidtype id, const VContai const QString errorMsg = QObject::tr("Piece '%1'. Seam allowance is not valid.") .arg(piece.GetName()); qApp->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } det.SetCountourPoints(futureMainPath.result(), diff --git a/src/libs/vlayout/vposter.cpp b/src/libs/vlayout/vposter.cpp index 82069b214..f7d73c80e 100644 --- a/src/libs/vlayout/vposter.cpp +++ b/src/libs/vlayout/vposter.cpp @@ -43,10 +43,11 @@ #include #include #include +#include #include "../vmisc/vmath.h" #include "../vmisc/def.h" -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "../ifc/exception/vexception.h" namespace @@ -309,7 +310,7 @@ QVector VPoster::ImageWatermark(QGraphicsItem *parent, const Po { const QString errorMsg = tr("Cannot open the watermark image.") + QChar(' ') + error; qApp->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; return data; } @@ -319,7 +320,7 @@ QVector VPoster::ImageWatermark(QGraphicsItem *parent, const Po { const QString errorMsg = tr("Not supported file suffix '%1'").arg(f.suffix()); qApp->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; return data; } @@ -455,7 +456,7 @@ void VPoster::Ruler(QVector &data, QGraphicsItem *parent, QRect const qreal notchHeight = ToPixel(3); // mm const qreal shortNotchHeight = ToPixel(1.1); // mm - Unit patternUnits = qApp->patternUnit(); + Unit patternUnits = qApp->patternUnits(); const qreal step = UnitConvertor(1, patternUnits, Unit::Px); double marksCount = rec.width() / step; int i = 0; diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index ec1300081..c6ff72ff7 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -37,7 +37,7 @@ #include "../ifc/xml/vabstractpattern.h" #include "../vpatterndb/floatItemData/vpiecelabeldata.h" -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "../vmisc/vmath.h" #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) # include "../vmisc/vdatastreamenum.h" @@ -185,7 +185,7 @@ QMap PreparePlaceholders(const VAbstractPattern *doc) placeholders.insert(pl_patternNumber, doc->GetPatternNumber()); placeholders.insert(pl_author, doc->GetCompanyName()); - if (qApp->patternType() == MeasurementsType::Individual) + if (qApp->GetMeasurementsType() == MeasurementsType::Individual) { placeholders.insert(pl_customer, qApp->GetCustomerName()); } @@ -201,13 +201,13 @@ QMap PreparePlaceholders(const VAbstractPattern *doc) QString curSize; QString curHeight; QString mExt; - if (qApp->patternType() == MeasurementsType::Multisize) + if (qApp->GetMeasurementsType() == MeasurementsType::Multisize) { curSize = QString::number(VContainer::size(valentinaNamespace)); curHeight = QString::number(VContainer::height(valentinaNamespace)); mExt = QStringLiteral("vst"); } - else if (qApp->patternType() == MeasurementsType::Individual) + else if (qApp->GetMeasurementsType() == MeasurementsType::Individual) { curSize = QString::number(VContainer::size(valentinaNamespace)); curHeight = QString::number(VContainer::height(valentinaNamespace)); diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 619469ddb..7aa912374 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -82,7 +82,7 @@ extern const int maxLabelFontSize; enum class NodeDetail : qint8 { Contour, Modeling }; enum class SceneObject : qint8 { Point, Line, Spline, Arc, ElArc, SplinePath, Detail, Unknown }; -enum class MeasurementsType : qint8 { Multisize, Individual , Unknown}; +enum class MeasurementsType : qint8 { Multisize, Individual, Unknown}; enum class Unit : qint8 { Mm = 0, Cm, Inch, Px, LAST_UNIT_DO_NOT_USE}; enum class Source : qint8 { FromGui, FromFile, FromTool }; enum class NodeUsage : bool {NotInUse = false, InUse = true}; diff --git a/src/libs/vmisc/dialogs/dialogexporttocsv.cpp b/src/libs/vmisc/dialogs/dialogexporttocsv.cpp index afe54328d..c6ae57e5d 100644 --- a/src/libs/vmisc/dialogs/dialogexporttocsv.cpp +++ b/src/libs/vmisc/dialogs/dialogexporttocsv.cpp @@ -36,6 +36,7 @@ #include #include #include +#include //--------------------------------------------------------------------------------------------------------------------- DialogExportToCSV::DialogExportToCSV(QWidget *parent) diff --git a/src/libs/vmisc/testvapplication.h b/src/libs/vmisc/testvapplication.h index b19c21541..a4eea8699 100644 --- a/src/libs/vmisc/testvapplication.h +++ b/src/libs/vmisc/testvapplication.h @@ -31,6 +31,7 @@ #include "vabstractapplication.h" #include "projectversion.h" +#include "../vmisc/vsettings.h" #if defined(qApp) #undef qApp diff --git a/src/libs/vmisc/vabstractapplication.cpp b/src/libs/vmisc/vabstractapplication.cpp index f201134e7..78d06a864 100644 --- a/src/libs/vmisc/vabstractapplication.cpp +++ b/src/libs/vmisc/vabstractapplication.cpp @@ -42,9 +42,6 @@ #include #include -#include "../vmisc/def.h" -#include "../vmisc/customevents.h" - #ifdef Q_OS_UNIX # include #endif @@ -53,29 +50,10 @@ # include "appimage.h" #endif // defined(APPIMAGE) && defined(Q_OS_LINUX) -const QString VAbstractApplication::patternMessageSignature = QStringLiteral("[PATTERN MESSAGE]"); - //--------------------------------------------------------------------------------------------------------------------- VAbstractApplication::VAbstractApplication(int &argc, char **argv) :QApplication(argc, argv), - undoStack(new QUndoStack(this)), - mainWindow(nullptr), - settings(nullptr), - qtTranslator(nullptr), - qtxmlTranslator(nullptr), - qtBaseTranslator(nullptr), - appTranslator(nullptr), - pmsTranslator(nullptr), - _patternUnit(Unit::Cm), - _patternType(MeasurementsType::Unknown), - patternFilePath(), - currentScene(nullptr), - sceneView(nullptr), - doc(nullptr), - m_customerName(), - m_userMaterials(), - openingPattern(false), - mode(Draw::Calculation) + undoStack(new QUndoStack(this)) { QString rules; @@ -121,10 +99,6 @@ VAbstractApplication::VAbstractApplication(int &argc, char **argv) connect(this, &QApplication::aboutToQuit, this, &VAbstractApplication::AboutToQuit); } -//--------------------------------------------------------------------------------------------------------------------- -VAbstractApplication::~VAbstractApplication() -{} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief translationsPath return path to the root directory that contain QM files. @@ -189,56 +163,6 @@ QString VAbstractApplication::translationsPath(const QString &locale) const #endif } -//--------------------------------------------------------------------------------------------------------------------- -MeasurementsType VAbstractApplication::patternType() const -{ - return _patternType; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VAbstractApplication::setPatternType(const MeasurementsType &patternType) -{ - _patternType = patternType; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VAbstractApplication::setCurrentDocument(VAbstractPattern *doc) -{ - this->doc = doc; -} - -//--------------------------------------------------------------------------------------------------------------------- -VAbstractPattern *VAbstractApplication::getCurrentDocument() const -{ - SCASSERT(doc != nullptr) - return doc; -} - -//--------------------------------------------------------------------------------------------------------------------- -bool VAbstractApplication::getOpeningPattern() const -{ - return openingPattern; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VAbstractApplication::setOpeningPattern() -{ - openingPattern = !openingPattern; -} - -//--------------------------------------------------------------------------------------------------------------------- -QWidget *VAbstractApplication::getMainWindow() const -{ - return mainWindow; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VAbstractApplication::setMainWindow(QWidget *value) -{ - SCASSERT(value != nullptr) - mainWindow = value; -} - //--------------------------------------------------------------------------------------------------------------------- QUndoStack *VAbstractApplication::getUndoStack() const { @@ -251,47 +175,6 @@ bool VAbstractApplication::IsPedantic() const return false; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief ClearMessage helps to clear a message string from standard Qt function. - * @param msg the message that contains '"' at the start and at the end - * @return cleared string - */ -QString VAbstractApplication::ClearMessage(QString msg) -{ - if (msg.startsWith('"') && msg.endsWith('"')) - { - msg.remove(0, 1); - msg.chop(1); - } - - return msg; -} - -//--------------------------------------------------------------------------------------------------------------------- -const Draw &VAbstractApplication::GetDrawMode() const -{ - return mode; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VAbstractApplication::SetDrawMode(const Draw &value) -{ - mode = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VAbstractApplication::PostPatternMessage(const QString &message, QtMsgType severity) const -{ - QApplication::postEvent(mainWindow, new PatternMessageEvent(VAbstractApplication::ClearMessage(message), severity)); -} - -//--------------------------------------------------------------------------------------------------------------------- -bool VAbstractApplication::IsPatternMessage(const QString &message) const -{ - return VAbstractApplication::ClearMessage(message).startsWith(patternMessageSignature); -} - //--------------------------------------------------------------------------------------------------------------------- #if defined(Q_OS_WIN) void VAbstractApplication::WinAttachConsole() @@ -312,24 +195,6 @@ void VAbstractApplication::WinAttachConsole() } #endif -//--------------------------------------------------------------------------------------------------------------------- -Unit VAbstractApplication::patternUnit() const -{ - return _patternUnit; -} - -//--------------------------------------------------------------------------------------------------------------------- -const Unit *VAbstractApplication::patternUnitP() const -{ - return &_patternUnit; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VAbstractApplication::setPatternUnit(const Unit &patternUnit) -{ - _patternUnit = patternUnit; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief getSettings hide settings constructor. @@ -341,43 +206,6 @@ VCommonSettings *VAbstractApplication::Settings() return settings; } -//--------------------------------------------------------------------------------------------------------------------- -QGraphicsScene *VAbstractApplication::getCurrentScene() const -{ - SCASSERT(*currentScene != nullptr) - return *currentScene; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VAbstractApplication::setCurrentScene(QGraphicsScene **value) -{ - currentScene = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -VMainGraphicsView *VAbstractApplication::getSceneView() const -{ - return sceneView; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VAbstractApplication::setSceneView(VMainGraphicsView *value) -{ - sceneView = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -double VAbstractApplication::toPixel(double val) const -{ - return ToPixel(val, _patternUnit); -} - -//--------------------------------------------------------------------------------------------------------------------- -double VAbstractApplication::fromPixel(double pix) const -{ - return FromPixel(pix, _patternUnit); -} - //--------------------------------------------------------------------------------------------------------------------- void VAbstractApplication::LoadTranslation(const QString &locale) { diff --git a/src/libs/vmisc/vabstractapplication.h b/src/libs/vmisc/vabstractapplication.h index d3e16cd5a..b7f9e5231 100644 --- a/src/libs/vmisc/vabstractapplication.h +++ b/src/libs/vmisc/vabstractapplication.h @@ -32,25 +32,21 @@ #include #include #include -#include #include #include #include #include #include #include +#include #include "../vmisc/def.h" #include "../vpatterndb/vtranslatevars.h" -#include "def.h" #include "vcommonsettings.h" -#include "vlockguard.h" -#include "vsettings.h" class QUndoStack; class VAbstractApplication;// use in define -class VAbstractPattern; -class VMainGraphicsView; +class VCommonSettings; #if defined(qApp) #undef qApp @@ -62,92 +58,42 @@ class VAbstractApplication : public QApplication Q_OBJECT public: VAbstractApplication(int &argc, char ** argv); - virtual ~VAbstractApplication() override; + virtual ~VAbstractApplication() =default; virtual const VTranslateVars *TrVars()=0; - QString translationsPath(const QString &locale = QString()) const; + QString translationsPath(const QString &locale = QString()) const; - void LoadTranslation(const QString &locale); - - Unit patternUnit() const; - const Unit *patternUnitP() const; - void setPatternUnit(const Unit &patternUnit); - - MeasurementsType patternType() const; - void setPatternType(const MeasurementsType &patternType); - - QString GetCustomerName() const; - void SetCustomerName(const QString &name); + void LoadTranslation(const QString &locale); virtual void OpenSettings()=0; VCommonSettings *Settings(); template - QString LocaleToString(const T &value); + QString LocaleToString(const T &value); - QGraphicsScene *getCurrentScene() const; - void setCurrentScene(QGraphicsScene **value); + QUndoStack *getUndoStack() const; - VMainGraphicsView *getSceneView() const; - void setSceneView(VMainGraphicsView *value); - - double toPixel(double val) const; - double fromPixel(double pix) const; - - void setCurrentDocument(VAbstractPattern *doc); - VAbstractPattern *getCurrentDocument()const; - - bool getOpeningPattern() const; - void setOpeningPattern(); - - QWidget *getMainWindow() const; - void setMainWindow(QWidget *value); - - QUndoStack *getUndoStack() const; - - virtual bool IsAppInGUIMode()const =0; - virtual bool IsPedantic() const; - - QString GetPatternPath() const; - void SetPatternPath(const QString &value); + virtual bool IsAppInGUIMode()const =0; + virtual bool IsPedantic() const; #if defined(Q_OS_WIN) static void WinAttachConsole(); #endif - static QString ClearMessage(QString msg); - - QMap GetUserMaterials() const; - void SetUserMaterials(const QMap &userMaterials); - - const Draw &GetDrawMode() const; - void SetDrawMode(const Draw &value); - - void PostPatternMessage(const QString &message, QtMsgType severity) const; - - static const QString patternMessageSignature; - bool IsPatternMessage(const QString &message) const; - protected: - QUndoStack *undoStack; - - /** - * @brief mainWindow pointer to main window. Usefull if need create modal dialog. Without pointer to main window - * modality doesn't work. - */ - QWidget *mainWindow; + QUndoStack *undoStack; /** * @brief settings pointer to settings. Help hide constructor creation settings. Make make code more readable. */ - VCommonSettings *settings; + VCommonSettings *settings{nullptr}; - QPointer qtTranslator; - QPointer qtxmlTranslator; - QPointer qtBaseTranslator; - QPointer appTranslator; - QPointer pmsTranslator; + QPointer qtTranslator{nullptr}; + QPointer qtxmlTranslator{nullptr}; + QPointer qtBaseTranslator{nullptr}; + QPointer appTranslator{nullptr}; + QPointer pmsTranslator{nullptr}; virtual void InitTrVars()=0; @@ -156,66 +102,10 @@ protected slots: private: Q_DISABLE_COPY(VAbstractApplication) - Unit _patternUnit; - MeasurementsType _patternType; - QString patternFilePath; - - QGraphicsScene **currentScene; - VMainGraphicsView *sceneView; - - VAbstractPattern *doc; - QString m_customerName; - - QMap m_userMaterials; - - /** - * @brief openingPattern true when we opening pattern. If something will be wrong in formula this help understand if - * we can allow user use Undo option. - */ - bool openingPattern; - - /** @brief mode keep current draw mode. */ - Draw mode; void ClearTranslation(); }; -//--------------------------------------------------------------------------------------------------------------------- -inline QString VAbstractApplication::GetCustomerName() const -{ - return m_customerName; -} - -//--------------------------------------------------------------------------------------------------------------------- -inline void VAbstractApplication::SetCustomerName(const QString &name) -{ - m_customerName = name; -} - -//--------------------------------------------------------------------------------------------------------------------- -inline QString VAbstractApplication::GetPatternPath() const -{ - return patternFilePath; -} - -//--------------------------------------------------------------------------------------------------------------------- -inline void VAbstractApplication::SetPatternPath(const QString &value) -{ - patternFilePath = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -inline QMap VAbstractApplication::GetUserMaterials() const -{ - return m_userMaterials; -} - -//--------------------------------------------------------------------------------------------------------------------- -inline void VAbstractApplication::SetUserMaterials(const QMap &userMaterials) -{ - m_userMaterials = userMaterials; -} - //--------------------------------------------------------------------------------------------------------------------- template inline QString VAbstractApplication::LocaleToString(const T &value) diff --git a/src/libs/vmisc/vabstractvalapplication.cpp b/src/libs/vmisc/vabstractvalapplication.cpp new file mode 100644 index 000000000..f9bec265a --- /dev/null +++ b/src/libs/vmisc/vabstractvalapplication.cpp @@ -0,0 +1,80 @@ +/************************************************************************ + ** + ** @file vabstractvalapplication.cpp + ** @author Roman Telezhynskyi + ** @date 15 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 "vabstractvalapplication.h" +#include "../vmisc/customevents.h" + +#include + +const QString VAbstractValApplication::patternMessageSignature = QStringLiteral("[PATTERN MESSAGE]"); + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractValApplication::VAbstractValApplication(int &argc, char **argv) + : VAbstractApplication(argc, argv) +{} + +//--------------------------------------------------------------------------------------------------------------------- +double VAbstractValApplication::toPixel(double val) const +{ + return ToPixel(val, m_patternUnits); +} + +//--------------------------------------------------------------------------------------------------------------------- +double VAbstractValApplication::fromPixel(double pix) const +{ + return FromPixel(pix, m_patternUnits); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractValApplication::PostPatternMessage(const QString &message, QtMsgType severity) const +{ + QApplication::postEvent(mainWindow, + new PatternMessageEvent(VAbstractValApplication::ClearMessage(message), severity)); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief ClearMessage helps to clear a message string from standard Qt function. + * @param msg the message that contains '"' at the start and at the end + * @return cleared string + */ +QString VAbstractValApplication::ClearMessage(QString msg) +{ + if (msg.startsWith('"') && msg.endsWith('"')) + { + msg.remove(0, 1); + msg.chop(1); + } + + return msg; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VAbstractValApplication::IsPatternMessage(const QString &message) const +{ + return VAbstractValApplication::ClearMessage(message).startsWith(patternMessageSignature); +} diff --git a/src/libs/vmisc/vabstractvalapplication.h b/src/libs/vmisc/vabstractvalapplication.h new file mode 100644 index 000000000..105040311 --- /dev/null +++ b/src/libs/vmisc/vabstractvalapplication.h @@ -0,0 +1,394 @@ +/************************************************************************ + ** + ** @file vabstractvalapplication.h + ** @author Roman Telezhynskyi + ** @date 15 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 VABSTRACTVALAPPLICATION_H +#define VABSTRACTVALAPPLICATION_H + +#include "vabstractapplication.h" + +#include + +class VAbstractValApplication;// use in define +class VAbstractPattern; +class VMainGraphicsView; +class QGraphicsScene; + +#if defined(qApp) +#undef qApp +#endif +#define qApp (static_cast(QCoreApplication::instance())) + +class VAbstractValApplication : public VAbstractApplication +{ + Q_OBJECT +public: + VAbstractValApplication(int &argc, char **argv); + virtual ~VAbstractValApplication() =default; + + QString GetCustomerName() const; + void SetCustomerName(const QString &name); + + QDate GetCustomerBirthDate() const; + void SetCustomerBirthDate(const QDate &date); + + QString CustomerEmail() const; + void SetCustomerEmail(const QString &email); + + Unit patternUnits() const; + const Unit *patternUnitsP() const; + void SetPatternUnits(const Unit &patternUnit); + + MeasurementsType GetMeasurementsType() const; + void SetMeasurementsType(const MeasurementsType &patternType); + + Unit MeasurementsUnits() const; + void SetMeasurementsUnits(const Unit &measurementsUnits); + + Unit DimensionSizeUnits() const; + void SetDimensionSizeUnits(const Unit &sizeUnits); + + double toPixel(double val) const; + double fromPixel(double pix) const; + + void setCurrentDocument(VAbstractPattern *doc); + VAbstractPattern *getCurrentDocument() const; + + VMainGraphicsView *getSceneView() const; + void setSceneView(VMainGraphicsView *value); + + QGraphicsScene *getCurrentScene() const; + void setCurrentScene(QGraphicsScene **value); + + QWidget *getMainWindow() const; + void setMainWindow(QWidget *value); + + QString GetPatternPath() const; + void SetPatternPath(const QString &value); + + QMap GetUserMaterials() const; + void SetUserMaterials(const QMap &userMaterials); + + const Draw &GetDrawMode() const; + void SetDrawMode(const Draw &value); + + bool getOpeningPattern() const; + void setOpeningPattern(); + + void PostPatternMessage(const QString &message, QtMsgType severity) const; + + static QString ClearMessage(QString msg); + + static const QString patternMessageSignature; + bool IsPatternMessage(const QString &message) const; + + qreal GetDimensionHeight() const; + void SetDimensionHeight(qreal dimensionHeight); + + qreal GetDimensionSize() const; + void SetDimensionSize(qreal dimensionSize); + + qreal GetDimensionHip() const; + void SetDimensionHip(qreal dimensionHip); + + qreal GetDimensionWaist() const; + void SetDimensionWaist(qreal dimensionWaist); + +protected: + QString m_customerName{}; + QDate m_customerBirthDate{}; + QString m_customerEmail{}; + + Unit m_patternUnits{Unit::Cm}; + MeasurementsType m_measurementsType{MeasurementsType::Unknown}; + Unit m_measurementsUnits{Unit::Cm}; + VAbstractPattern *m_doc{nullptr}; + VMainGraphicsView *m_sceneView{nullptr}; + QGraphicsScene **m_currentScene{nullptr}; + QString m_patternFilePath{}; + QMap m_userMaterials{}; + + qreal m_dimensionHeight{0}; + qreal m_dimensionSize{0}; + qreal m_dimensionHip{0}; + qreal m_dimensionWaist{0}; + + Unit m_dimensionSizeUnits{Unit::Cm}; + + /** + * @brief mainWindow pointer to main window. Usefull if need create modal dialog. Without pointer to main window + * modality doesn't work. + */ + QWidget *mainWindow{nullptr}; + + /** @brief mode keep current draw mode. */ + Draw m_mode{Draw::Calculation}; + + /** + * @brief openingPattern true when we opening pattern. If something will be wrong in formula this help understand if + * we can allow user use Undo option. + */ + bool openingPattern{false}; + +private: + Q_DISABLE_COPY(VAbstractValApplication) +}; + +//--------------------------------------------------------------------------------------------------------------------- +inline QString VAbstractValApplication::GetCustomerName() const +{ + return m_customerName; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstractValApplication::SetCustomerName(const QString &name) +{ + m_customerName = name; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline Unit VAbstractValApplication::patternUnits() const +{ + return m_patternUnits; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline const Unit *VAbstractValApplication::patternUnitsP() const +{ + return &m_patternUnits; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstractValApplication::SetPatternUnits(const Unit &patternUnit) +{ + m_patternUnits = patternUnit; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline MeasurementsType VAbstractValApplication::GetMeasurementsType() const +{ + return m_measurementsType; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstractValApplication::SetMeasurementsType(const MeasurementsType &patternType) +{ + m_measurementsType = patternType; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline Unit VAbstractValApplication::MeasurementsUnits() const +{ + return m_measurementsUnits; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstractValApplication::SetMeasurementsUnits(const Unit &measurementsUnits) +{ + m_measurementsUnits = measurementsUnits; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline Unit VAbstractValApplication::DimensionSizeUnits() const +{ + return m_dimensionSizeUnits; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstractValApplication::SetDimensionSizeUnits(const Unit &sizeUnits) +{ + m_dimensionSizeUnits = sizeUnits; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstractValApplication::setCurrentDocument(VAbstractPattern *doc) +{ + m_doc = doc; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline VAbstractPattern *VAbstractValApplication::getCurrentDocument() const +{ + return m_doc; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline VMainGraphicsView *VAbstractValApplication::getSceneView() const +{ + return m_sceneView; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstractValApplication::setSceneView(VMainGraphicsView *value) +{ + m_sceneView = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline QGraphicsScene *VAbstractValApplication::getCurrentScene() const +{ + return *m_currentScene; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstractValApplication::setCurrentScene(QGraphicsScene **value) +{ + m_currentScene = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline QWidget *VAbstractValApplication::getMainWindow() const +{ + return mainWindow; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstractValApplication::setMainWindow(QWidget *value) +{ + mainWindow = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline QString VAbstractValApplication::GetPatternPath() const +{ + return m_patternFilePath; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstractValApplication::SetPatternPath(const QString &value) +{ + m_patternFilePath = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline QMap VAbstractValApplication::GetUserMaterials() const +{ + return m_userMaterials; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstractValApplication::SetUserMaterials(const QMap &userMaterials) +{ + m_userMaterials = userMaterials; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline const Draw &VAbstractValApplication::GetDrawMode() const +{ + return m_mode; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstractValApplication::SetDrawMode(const Draw &value) +{ + m_mode = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline bool VAbstractValApplication::getOpeningPattern() const +{ + return openingPattern; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstractValApplication::setOpeningPattern() +{ + openingPattern = !openingPattern; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline qreal VAbstractValApplication::GetDimensionHeight() const +{ + return m_dimensionHeight; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstractValApplication::SetDimensionHeight(qreal dimensionHeight) +{ + m_dimensionHeight = dimensionHeight; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline qreal VAbstractValApplication::GetDimensionSize() const +{ + return m_dimensionSize; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstractValApplication::SetDimensionSize(qreal dimensionSize) +{ + m_dimensionSize = dimensionSize; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline qreal VAbstractValApplication::GetDimensionHip() const +{ + return m_dimensionHip; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstractValApplication::SetDimensionHip(qreal dimensionHip) +{ + m_dimensionHip = dimensionHip; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline qreal VAbstractValApplication::GetDimensionWaist() const +{ + return m_dimensionWaist; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstractValApplication::SetDimensionWaist(qreal dimensionWaist) +{ + m_dimensionWaist = dimensionWaist; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline QDate VAbstractValApplication::GetCustomerBirthDate() const +{ + return m_customerBirthDate; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstractValApplication::SetCustomerBirthDate(const QDate &date) +{ + m_customerBirthDate = date; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline QString VAbstractValApplication::CustomerEmail() const +{ + return m_customerEmail; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstractValApplication::SetCustomerEmail(const QString &email) +{ + m_customerEmail = email; +} + +#endif // VABSTRACTVALAPPLICATION_H diff --git a/src/libs/vmisc/vmisc.pri b/src/libs/vmisc/vmisc.pri index e62231411..0381a3d48 100644 --- a/src/libs/vmisc/vmisc.pri +++ b/src/libs/vmisc/vmisc.pri @@ -3,6 +3,7 @@ SOURCES += \ $$PWD/def.cpp \ + $$PWD/vabstractvalapplication.cpp \ $$PWD/vsettings.cpp \ $$PWD/vabstractapplication.cpp \ $$PWD/projectversion.cpp \ @@ -27,6 +28,7 @@ HEADERS += \ $$PWD/compatibility.h \ $$PWD/stable.h \ $$PWD/def.h \ + $$PWD/vabstractvalapplication.h \ $$PWD/vmath.h \ $$PWD/vsettings.h \ $$PWD/vabstractapplication.h \ diff --git a/src/libs/vpatterndb/variables/vmeasurement.h b/src/libs/vpatterndb/variables/vmeasurement.h index d54ea5f50..41f340965 100644 --- a/src/libs/vpatterndb/variables/vmeasurement.h +++ b/src/libs/vpatterndb/variables/vmeasurement.h @@ -116,6 +116,7 @@ public: QMap GetCorrections() const; void SetCorrections(const QMap &corrections); + // TODO: remove static QStringList ListHeights(const QMap &heights, Unit patternUnit); static QStringList ListSizes(const QMap &sizes, Unit patternUnit); static QStringList WholeListHeights(Unit patternUnit); diff --git a/src/libs/vpatterndb/vpassmark.cpp b/src/libs/vpatterndb/vpassmark.cpp index 88a7597bc..5edeb1ae5 100644 --- a/src/libs/vpatterndb/vpassmark.cpp +++ b/src/libs/vpatterndb/vpassmark.cpp @@ -29,7 +29,7 @@ #include #include "vpassmark.h" -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "../ifc/exception/vexceptioninvalidnotch.h" #include "../vgeometry/vabstractcurve.h" #include "../vgeometry/varc.h" @@ -579,7 +579,7 @@ QVector PassmarkBisectorBaseLine(PassmarkStatus seamPassmarkType, const "than minimal allowed.") .arg(passmarkData.nodeName, passmarkData.pieceName); qApp->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; return QVector(); } @@ -788,7 +788,7 @@ QVector VPassmark::BuiltInSAPassmarkBaseLine(const VPiece &piece) const "than minimal allowed.") .arg(m_data.nodeName, m_data.pieceName); qApp->IsPedantic() ? throw VExceptionInvalidNotch(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; return QVector(); } } @@ -804,7 +804,7 @@ QVector VPassmark::BuiltInSAPassmarkBaseLine(const VPiece &piece) const "seam allowance. User must manually provide length.") .arg(m_data.nodeName, m_data.pieceName); qApp->IsPedantic() ? throw VExceptionInvalidNotch(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; return QVector(); } } @@ -848,7 +848,7 @@ QVector VPassmark::SAPassmarkBaseLine(const QVector &seamAllowa const QString errorMsg = QObject::tr("Cannot calculate a notch for point '%1' in piece '%2'. Seam allowance is " "empty.").arg(m_data.nodeName, m_data.pieceName); qApp->IsPedantic() ? throw VExceptionInvalidNotch(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; return QVector(); // Something wrong } @@ -860,7 +860,7 @@ QVector VPassmark::SAPassmarkBaseLine(const QVector &seamAllowa "position for a notch.") .arg(m_data.nodeName, m_data.pieceName); qApp->IsPedantic() ? throw VExceptionInvalidNotch(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; return QVector(); // Something wrong } @@ -870,7 +870,7 @@ QVector VPassmark::SAPassmarkBaseLine(const QVector &seamAllowa "notch position.") .arg(m_data.nodeName, m_data.pieceName); qApp->IsPedantic() ? throw VExceptionInvalidNotch(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } auto PassmarkIntersection = [this, seamAllowance] (QLineF line, qreal width) @@ -892,7 +892,7 @@ QVector VPassmark::SAPassmarkBaseLine(const QVector &seamAllowa "less than minimal allowed.") .arg(m_data.nodeName, m_data.pieceName); qApp->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; return QLineF(); } line.setLength(length); @@ -909,7 +909,7 @@ QVector VPassmark::SAPassmarkBaseLine(const QVector &seamAllowa "collapse.") .arg(m_data.nodeName, m_data.pieceName); qApp->IsPedantic() ? throw VExceptionInvalidNotch(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } } else @@ -918,7 +918,7 @@ QVector VPassmark::SAPassmarkBaseLine(const QVector &seamAllowa "intersection.") .arg(m_data.nodeName, m_data.pieceName); qApp->IsPedantic() ? throw VExceptionInvalidNotch(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } return QLineF(); @@ -933,7 +933,7 @@ QVector VPassmark::SAPassmarkBaseLine(const QVector &seamAllowa "than minimal allowed.") .arg(m_data.nodeName, m_data.pieceName); qApp->IsPedantic() ? throw VExceptionInvalidNotch(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } else { diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index 44ee8202a..b5c7ff486 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -34,7 +34,7 @@ #include "../vgeometry/vplacelabelitem.h" #include "../vgeometry/varc.h" #include "vcontainer.h" -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "../vmisc/compatibility.h" #include "../ifc/exception/vexceptioninvalidnotch.h" #include "../vlayout/testpath.h" @@ -937,7 +937,7 @@ bool VPiece::GetPassmarkPreviousSAPoints(const QVector &path, int in const QString errorMsg = tr("Cannot calculate a notch for point '%1' in piece '%2'.") .arg(VPiecePath::NodeName(path, passmarkIndex, data), GetName()); qApp->IsPedantic() ? throw VExceptionInvalidNotch(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; return false; // Something wrong } @@ -976,7 +976,7 @@ bool VPiece::GetPassmarkNextSAPoints(const QVector &path, int index, const QString errorMsg = tr("Cannot calculate a notch for point '%1' in piece '%2'.") .arg(VPiecePath::NodeName(path, passmarkIndex, data), GetName()); qApp->IsPedantic() ? throw VExceptionInvalidNotch(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; return false; // Something wrong } @@ -1060,7 +1060,7 @@ VPassmark VPiece::CreatePassmark(const QVector &path, int previousIn const QString errorMsg = tr("Cannot calculate a notch for point '%1' in piece '%2'.") .arg(VPiecePath::NodeName(path, passmarkIndex, data), GetName()); qApp->IsPedantic() ? throw VExceptionInvalidNotch(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; return VPassmark(); } @@ -1089,7 +1089,7 @@ VPassmark VPiece::CreatePassmark(const QVector &path, int previousIn const QString infoMsg = tr("Notch for point '%1' in piece '%2' will be disabled. Manual length is less than " "allowed value.") .arg(VPiecePath::NodeName(path, passmarkIndex, data), GetName()); - qInfo() << VAbstractApplication::patternMessageSignature + infoMsg; + qInfo() << VAbstractValApplication::patternMessageSignature + infoMsg; return VPassmark(); } diff --git a/src/libs/vpatterndb/vpiecenode.cpp b/src/libs/vpatterndb/vpiecenode.cpp index db9b995bb..1798f2a02 100644 --- a/src/libs/vpatterndb/vpiecenode.cpp +++ b/src/libs/vpatterndb/vpiecenode.cpp @@ -31,7 +31,7 @@ #include "vcontainer.h" #include "calculator.h" #include "vformula.h" -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include #include @@ -162,7 +162,7 @@ qreal VPieceNode::GetSABefore(const VContainer *data) const const QString errorMsg = QObject::tr("Cannot calculate seam allowance before for point '%1'. Reason: %2.") .arg(nodeName, formula.Reason()); qApp->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; return -1; } return formula.getDoubleValue(); @@ -193,7 +193,7 @@ qreal VPieceNode::GetSABefore(const VContainer *data, Unit unit) const const QString errorMsg = QObject::tr("Cannot calculate seam allowance before for point '%1'. Reason: %2.") .arg(nodeName, formula.Reason()); qApp->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; return -1; } @@ -245,7 +245,7 @@ qreal VPieceNode::GetSAAfter(const VContainer *data) const const QString errorMsg = QObject::tr("Cannot calculate seam allowance after for point '%1'. Reason: %2.") .arg(nodeName, formula.Reason()); qApp->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; return -1; } @@ -277,7 +277,7 @@ qreal VPieceNode::GetSAAfter(const VContainer *data, Unit unit) const const QString errorMsg = QObject::tr("Cannot calculate seam allowance after for point '%1'. Reason: ") .arg(nodeName, formula.Reason()); qApp->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; return -1; } @@ -343,7 +343,7 @@ qreal VPieceNode::GetPassmarkLength(const VContainer *data, Unit unit) const const QString errorMsg = QObject::tr("Cannot calculate passmark length for point '%1'. Reason: %2.") .arg(nodeName, formula.Reason()); qApp->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; return VSAPoint::maxPassmarkLength; } diff --git a/src/libs/vpatterndb/vpiecepath.cpp b/src/libs/vpatterndb/vpiecepath.cpp index 9ba8fa888..59c2ebb73 100644 --- a/src/libs/vpatterndb/vpiecepath.cpp +++ b/src/libs/vpatterndb/vpiecepath.cpp @@ -32,7 +32,7 @@ #include "../vgeometry/vpointf.h" #include "../vlayout/vabstractpiece.h" #include "calculator.h" -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "../vmisc/compatibility.h" #include "../ifc/exception/vexceptionobjecterror.h" @@ -385,7 +385,7 @@ QVector VPiecePath::PathPoints(const VContainer *data, const QVectorIsPedantic() ? throw VExceptionObjectError(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } } @@ -402,7 +402,7 @@ QVector VPiecePath::PathPoints(const VContainer *data, const QVectorIsPedantic() ? throw VExceptionObjectError(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } } diff --git a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp index 8dd194a58..d31ccd589 100644 --- a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp +++ b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp @@ -500,7 +500,7 @@ void DialogEditLabel::InitPlaceholders() m_placeholders.insert(pl_patternNumber, qMakePair(tr("Pattern number"), m_doc->GetPatternNumber())); m_placeholders.insert(pl_author, qMakePair(tr("Company name or designer name"), m_doc->GetCompanyName())); - if (qApp->patternType() == MeasurementsType::Individual) + if (qApp->GetMeasurementsType() == MeasurementsType::Individual) { m_placeholders.insert(pl_customer, qMakePair(tr("Customer name"), qApp->GetCustomerName())); } @@ -520,13 +520,13 @@ void DialogEditLabel::InitPlaceholders() QString curSize; QString curHeight; QString mExt; - if (qApp->patternType() == MeasurementsType::Multisize) + if (qApp->GetMeasurementsType() == MeasurementsType::Multisize) { curSize = QString::number(VContainer::size(valentinaNamespace)); curHeight = QString::number(VContainer::height(valentinaNamespace)); mExt = "vst"; } - else if (qApp->patternType() == MeasurementsType::Individual) + else if (qApp->GetMeasurementsType() == MeasurementsType::Individual) { curSize = QString::number(VContainer::size(valentinaNamespace)); curHeight = QString::number(VContainer::height(valentinaNamespace)); @@ -553,20 +553,20 @@ void DialogEditLabel::InitPlaceholders() } // Piece tags - m_placeholders.insert(pl_pLetter, qMakePair(tr("Piece letter"), QString(QString()))); - m_placeholders.insert(pl_pAnnotation, qMakePair(tr("Piece annotation"), QString(QString()))); - m_placeholders.insert(pl_pOrientation, qMakePair(tr("Piece orientation"), QString(QString()))); - m_placeholders.insert(pl_pRotation, qMakePair(tr("Piece rotation"), QString(QString()))); - m_placeholders.insert(pl_pTilt, qMakePair(tr("Piece tilt"), QString(QString()))); - m_placeholders.insert(pl_pFoldPosition, qMakePair(tr("Piece fold position"), QString(QString()))); - m_placeholders.insert(pl_pName, qMakePair(tr("Piece name"), QString(QString()))); - m_placeholders.insert(pl_pQuantity, qMakePair(tr("Quantity"), QString(QString()))); + m_placeholders.insert(pl_pLetter, qMakePair(tr("Piece letter"), QString())); + m_placeholders.insert(pl_pAnnotation, qMakePair(tr("Piece annotation"), QString())); + m_placeholders.insert(pl_pOrientation, qMakePair(tr("Piece orientation"), QString())); + m_placeholders.insert(pl_pRotation, qMakePair(tr("Piece rotation"), QString())); + m_placeholders.insert(pl_pTilt, qMakePair(tr("Piece tilt"), QString())); + m_placeholders.insert(pl_pFoldPosition, qMakePair(tr("Piece fold position"), QString())); + m_placeholders.insert(pl_pName, qMakePair(tr("Piece name"), QString())); + m_placeholders.insert(pl_pQuantity, qMakePair(tr("Quantity"), QString())); m_placeholders.insert(pl_mFabric, qMakePair(tr("Material: Fabric"), tr("Fabric"))); m_placeholders.insert(pl_mLining, qMakePair(tr("Material: Lining"), tr("Lining"))); m_placeholders.insert(pl_mInterfacing, qMakePair(tr("Material: Interfacing"), tr("Interfacing"))); m_placeholders.insert(pl_mInterlining, qMakePair(tr("Material: Interlining"), tr("Interlining"))); m_placeholders.insert(pl_wCut, qMakePair(tr("Word: Cut"), tr("Cut"))); - m_placeholders.insert(pl_wOnFold, qMakePair(tr("Word: on fold"), QString(QString())));// By default should be empty + m_placeholders.insert(pl_wOnFold, qMakePair(tr("Word: on fold"), QString()));// By default should be empty } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp b/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp index a7d3663ab..2d09c188f 100644 --- a/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp +++ b/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp @@ -191,30 +191,30 @@ void DialogEditWrongFormula::ValChanged(int row) if (ui->radioButtonStandardTable->isChecked()) { const QSharedPointer stable = data->GetVariable(name); - SetDescription(item->text(), *stable->GetValue(), UnitsToStr(qApp->patternUnit(), true), + SetDescription(item->text(), *stable->GetValue(), UnitsToStr(qApp->patternUnits(), true), stable->GetGuiText()); } else if (ui->radioButtonIncrements->isChecked()) { const QSharedPointer incr = data->GetVariable(name); - SetDescription(item->text(), *incr->GetValue(), UnitsToStr(qApp->patternUnit(), true), + SetDescription(item->text(), *incr->GetValue(), UnitsToStr(qApp->patternUnits(), true), incr->GetDescription()); } else if (ui->radioButtonPC->isChecked()) { const QSharedPointer incr = data->GetVariable(name); - SetDescription(item->text(), *incr->GetValue(), UnitsToStr(qApp->patternUnit(), true), + SetDescription(item->text(), *incr->GetValue(), UnitsToStr(qApp->patternUnits(), true), incr->GetDescription()); } else if (ui->radioButtonLengthLine->isChecked()) { SetDescription(item->text(), *data->GetVariable(name)->GetValue(), - UnitsToStr(qApp->patternUnit(), true), tr("Line length")); + UnitsToStr(qApp->patternUnits(), true), tr("Line length")); } else if (ui->radioButtonLengthSpline->isChecked()) { SetDescription(item->text(), *data->GetVariable(name)->GetValue(), - UnitsToStr(qApp->patternUnit(), true), tr("Curve length")); + UnitsToStr(qApp->patternUnits(), true), tr("Curve length")); } else if (ui->radioButtonAngleLine->isChecked()) { @@ -224,7 +224,7 @@ void DialogEditWrongFormula::ValChanged(int row) else if (ui->radioButtonRadiusesArcs->isChecked()) { SetDescription(item->text(), *data->GetVariable(name)->GetValue(), - UnitsToStr(qApp->patternUnit(), true), tr("Arc radius")); + UnitsToStr(qApp->patternUnits(), true), tr("Arc radius")); } else if (ui->radioButtonAnglesCurves->isChecked()) { diff --git a/src/libs/vtools/dialogs/support/dialogundo.cpp b/src/libs/vtools/dialogs/support/dialogundo.cpp index 658ca7041..ba6d48eec 100644 --- a/src/libs/vtools/dialogs/support/dialogundo.cpp +++ b/src/libs/vtools/dialogs/support/dialogundo.cpp @@ -33,7 +33,7 @@ #include #include -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "../vmisc/vcommonsettings.h" #include "ui_dialogundo.h" diff --git a/src/libs/vtools/dialogs/tools/dialogalongline.cpp b/src/libs/vtools/dialogs/tools/dialogalongline.cpp index 787dad156..7a3da95c7 100644 --- a/src/libs/vtools/dialogs/tools/dialogalongline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogalongline.cpp @@ -141,7 +141,7 @@ void DialogAlongLine::FXLength() DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); dialog->setWindowTitle(tr("Edit length")); dialog->SetFormula(GetFormula()); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetFormula(dialog->GetFormula()); @@ -157,7 +157,7 @@ void DialogAlongLine::EvalFormula() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditFormula; formulaData.labelResult = ui->labelResultCalculation; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); formulaData.checkZero = false; Eval(formulaData, flagFormula); diff --git a/src/libs/vtools/dialogs/tools/dialogarc.cpp b/src/libs/vtools/dialogs/tools/dialogarc.cpp index beaed8f44..b69adf174 100644 --- a/src/libs/vtools/dialogs/tools/dialogarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogarc.cpp @@ -328,7 +328,7 @@ void DialogArc::FXRadius() DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); dialog->setWindowTitle(tr("Edit radius")); dialog->SetFormula(GetRadius()); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetRadius(dialog->GetFormula()); @@ -375,7 +375,7 @@ void DialogArc::EvalRadius() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditRadius; formulaData.labelResult = ui->labelResultRadius; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); const qreal radius = Eval(formulaData, flagRadius); diff --git a/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp b/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp index ee683aa07..36c8f9126 100644 --- a/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp +++ b/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp @@ -290,7 +290,7 @@ void DialogArcWithLength::FXRadius() DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); dialog->setWindowTitle(tr("Edit radius")); dialog->SetFormula(GetRadius()); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetRadius(dialog->GetFormula()); @@ -318,7 +318,7 @@ void DialogArcWithLength::FXLength() DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); dialog->setWindowTitle(tr("Edit the arc length")); dialog->SetFormula(GetLength()); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetLength(dialog->GetFormula()); @@ -367,7 +367,7 @@ void DialogArcWithLength::Radius() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditRadius; formulaData.labelResult = ui->labelResultRadius; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); formulaData.checkLessThanZero = true; Eval(formulaData, flagRadius); @@ -381,7 +381,7 @@ void DialogArcWithLength::Length() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditLength; formulaData.labelResult = ui->labelResultLength; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); Eval(formulaData, flagLength); } diff --git a/src/libs/vtools/dialogs/tools/dialogbisector.cpp b/src/libs/vtools/dialogs/tools/dialogbisector.cpp index 802538840..02149eb73 100644 --- a/src/libs/vtools/dialogs/tools/dialogbisector.cpp +++ b/src/libs/vtools/dialogs/tools/dialogbisector.cpp @@ -139,7 +139,7 @@ void DialogBisector::FXLength() DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); dialog->setWindowTitle(tr("Edit length")); dialog->SetFormula(GetFormula()); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetFormula(dialog->GetFormula()); @@ -155,7 +155,7 @@ void DialogBisector::EvalFormula() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditFormula; formulaData.labelResult = ui->labelResultCalculation; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); formulaData.checkZero = false; Eval(formulaData, flagFormula); diff --git a/src/libs/vtools/dialogs/tools/dialogcutarc.cpp b/src/libs/vtools/dialogs/tools/dialogcutarc.cpp index f69231475..58a4e1132 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutarc.cpp @@ -102,7 +102,7 @@ void DialogCutArc::FXLength() DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); dialog->setWindowTitle(tr("Edit length")); dialog->SetFormula(GetFormula()); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetFormula(dialog->GetFormula()); @@ -118,7 +118,7 @@ void DialogCutArc::EvalFormula() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditFormula; formulaData.labelResult = ui->labelResultCalculation; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); formulaData.checkZero = false; Eval(formulaData, flagFormula); diff --git a/src/libs/vtools/dialogs/tools/dialogcutspline.cpp b/src/libs/vtools/dialogs/tools/dialogcutspline.cpp index 9b6c00ec0..57eca1a02 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutspline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutspline.cpp @@ -217,7 +217,7 @@ void DialogCutSpline::FXLength() DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); dialog->setWindowTitle(tr("Edit length")); dialog->SetFormula(GetFormula()); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetFormula(dialog->GetFormula()); @@ -233,7 +233,7 @@ void DialogCutSpline::EvalFormula() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditFormula; formulaData.labelResult = ui->labelResultCalculation; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); formulaData.checkZero = false; Eval(formulaData, flagFormula); diff --git a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp index 3492f4dcd..500c44bd4 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp @@ -217,7 +217,7 @@ void DialogCutSplinePath::FXLength() DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); dialog->setWindowTitle(tr("Edit length")); dialog->SetFormula(GetFormula()); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetFormula(dialog->GetFormula()); @@ -233,7 +233,7 @@ void DialogCutSplinePath::EvalFormula() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditFormula; formulaData.labelResult = ui->labelResultCalculation; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); formulaData.checkZero = false; Eval(formulaData, flagFormula); diff --git a/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp b/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp index 03284d2c5..6c5a409a6 100644 --- a/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp @@ -387,7 +387,7 @@ void DialogEllipticalArc::EvalRadiuses() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditRadius1; formulaData.labelResult = ui->labelResultRadius1; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); formulaData.checkLessThanZero = true; Eval(formulaData, flagRadius1); @@ -434,7 +434,7 @@ void DialogEllipticalArc::FXRadius1() DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); dialog->setWindowTitle(tr("Edit radius1")); dialog->SetFormula(GetRadius1()); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetRadius1(dialog->GetFormula()); @@ -448,7 +448,7 @@ void DialogEllipticalArc::FXRadius2() DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); dialog->setWindowTitle(tr("Edit radius2")); dialog->SetFormula(GetRadius2()); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetRadius2(dialog->GetFormula()); diff --git a/src/libs/vtools/dialogs/tools/dialogendline.cpp b/src/libs/vtools/dialogs/tools/dialogendline.cpp index b8cef020f..89f1e4801 100644 --- a/src/libs/vtools/dialogs/tools/dialogendline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogendline.cpp @@ -150,7 +150,7 @@ void DialogEndLine::EvalLength() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditFormula; formulaData.labelResult = ui->labelResultCalculation; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); formulaData.checkLessThanZero = false; Eval(formulaData, flagFormula); @@ -188,7 +188,7 @@ void DialogEndLine::FXLength() DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); dialog->setWindowTitle(tr("Edit length")); dialog->SetFormula(GetFormula()); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetFormula(dialog->GetFormula()); diff --git a/src/libs/vtools/dialogs/tools/dialogmove.cpp b/src/libs/vtools/dialogs/tools/dialogmove.cpp index c079a97a5..0105f8e4b 100644 --- a/src/libs/vtools/dialogs/tools/dialogmove.cpp +++ b/src/libs/vtools/dialogs/tools/dialogmove.cpp @@ -479,7 +479,7 @@ void DialogMove::FXLength() DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); dialog->setWindowTitle(tr("Edit length")); dialog->SetFormula(GetLength()); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetLength(dialog->GetFormula()); @@ -630,7 +630,7 @@ void DialogMove::EvalLength() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditLength; formulaData.labelResult = ui->labelResultLength; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); Eval(formulaData, flagLength); } diff --git a/src/libs/vtools/dialogs/tools/dialognormal.cpp b/src/libs/vtools/dialogs/tools/dialognormal.cpp index 749d0931d..3c727291f 100644 --- a/src/libs/vtools/dialogs/tools/dialognormal.cpp +++ b/src/libs/vtools/dialogs/tools/dialognormal.cpp @@ -141,7 +141,7 @@ void DialogNormal::FXLength() DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); dialog->setWindowTitle(tr("Edit length")); dialog->SetFormula(GetFormula()); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetFormula(dialog->GetFormula()); @@ -157,7 +157,7 @@ void DialogNormal::EvalFormula() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditFormula; formulaData.labelResult = ui->labelResultCalculation; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); Eval(formulaData, flagFormula); } diff --git a/src/libs/vtools/dialogs/tools/dialogpointfromcircleandtangent.cpp b/src/libs/vtools/dialogs/tools/dialogpointfromcircleandtangent.cpp index 1ea5dc7d6..cf7e656c1 100644 --- a/src/libs/vtools/dialogs/tools/dialogpointfromcircleandtangent.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpointfromcircleandtangent.cpp @@ -272,7 +272,7 @@ void DialogPointFromCircleAndTangent::FXCircleRadius() DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); dialog->setWindowTitle(tr("Edit radius")); dialog->SetFormula(GetCircleRadius()); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetCircleRadius(dialog->GetFormula()); @@ -288,7 +288,7 @@ void DialogPointFromCircleAndTangent::EvalCircleRadius() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditRadius; formulaData.labelResult = ui->labelResultCircleRadius; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); const qreal radius = Eval(formulaData, flagCircleRadius); diff --git a/src/libs/vtools/dialogs/tools/dialogpointofcontact.cpp b/src/libs/vtools/dialogs/tools/dialogpointofcontact.cpp index 74743ca3a..36f303936 100644 --- a/src/libs/vtools/dialogs/tools/dialogpointofcontact.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpointofcontact.cpp @@ -149,7 +149,7 @@ void DialogPointOfContact::FXRadius() DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); dialog->setWindowTitle(tr("Edit radius")); dialog->SetFormula(getRadius()); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { setRadius(dialog->GetFormula()); @@ -165,7 +165,7 @@ void DialogPointOfContact::EvalFormula() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditFormula; formulaData.labelResult = ui->labelResultCalculation; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); Eval(formulaData, flagFormula); } diff --git a/src/libs/vtools/dialogs/tools/dialogpointofintersectioncircles.cpp b/src/libs/vtools/dialogs/tools/dialogpointofintersectioncircles.cpp index 9691d0775..ee63bcc80 100644 --- a/src/libs/vtools/dialogs/tools/dialogpointofintersectioncircles.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpointofintersectioncircles.cpp @@ -323,7 +323,7 @@ void DialogPointOfIntersectionCircles::FXCircle1Radius() DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); dialog->setWindowTitle(tr("Edit first circle radius")); dialog->SetFormula(GetFirstCircleRadius()); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetFirstCircleRadius(dialog->GetFormula()); @@ -337,7 +337,7 @@ void DialogPointOfIntersectionCircles::FXCircle2Radius() DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); dialog->setWindowTitle(tr("Edit second circle radius")); dialog->SetFormula(GetSecondCircleRadius()); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetSecondCircleRadius(dialog->GetFormula()); @@ -353,7 +353,7 @@ void DialogPointOfIntersectionCircles::EvalCircle1Radius() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditCircle1Radius; formulaData.labelResult = ui->labelResultCircle1Radius; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); const qreal radius = Eval(formulaData, flagCircle1Radius); @@ -376,7 +376,7 @@ void DialogPointOfIntersectionCircles::EvalCircle2Radius() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditCircle2Radius; formulaData.labelResult = ui->labelResultCircle2Radius; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); const qreal radius = Eval(formulaData, flagCircle2Radius); diff --git a/src/libs/vtools/dialogs/tools/dialogshoulderpoint.cpp b/src/libs/vtools/dialogs/tools/dialogshoulderpoint.cpp index affd4479d..8c8d6b5d4 100644 --- a/src/libs/vtools/dialogs/tools/dialogshoulderpoint.cpp +++ b/src/libs/vtools/dialogs/tools/dialogshoulderpoint.cpp @@ -139,7 +139,7 @@ void DialogShoulderPoint::FXLength() DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); dialog->setWindowTitle(tr("Edit length")); dialog->SetFormula(GetFormula()); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetFormula(dialog->GetFormula()); @@ -155,7 +155,7 @@ void DialogShoulderPoint::EvalFormula() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditFormula; formulaData.labelResult = ui->labelResultCalculation; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); Eval(formulaData, flagFormula); } diff --git a/src/libs/vtools/dialogs/tools/dialogspline.cpp b/src/libs/vtools/dialogs/tools/dialogspline.cpp index e6da0a10f..0cda9f9da 100644 --- a/src/libs/vtools/dialogs/tools/dialogspline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogspline.cpp @@ -321,7 +321,7 @@ void DialogSpline::FXLength1() QString length1F = qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditLength1F->toPlainText(), qApp->Settings()->GetOsSeparator()); dialog->SetFormula(length1F); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { length1F = qApp->TrVars()->FormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator()); @@ -344,7 +344,7 @@ void DialogSpline::FXLength2() QString length2F = qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditLength2F->toPlainText(), qApp->Settings()->GetOsSeparator()); dialog->SetFormula(length2F); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { length2F = qApp->TrVars()->FormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator()); @@ -407,7 +407,7 @@ void DialogSpline::EvalLength1() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditLength1; formulaData.labelResult = ui->labelResultLength1; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); formulaData.checkZero = false; formulaData.checkLessThanZero = true; @@ -422,7 +422,7 @@ void DialogSpline::EvalLength2() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditLength2; formulaData.labelResult = ui->labelResultLength2; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); formulaData.checkZero = false; formulaData.checkLessThanZero = true; diff --git a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp index ab2f9694a..232e2c6c3 100644 --- a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp @@ -447,7 +447,7 @@ void DialogSplinePath::FXLength1() qApp->Settings()->GetOsSeparator()); dialog->SetFormula(length1F); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { length1F = VTranslateVars::TryFormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator()); @@ -472,7 +472,7 @@ void DialogSplinePath::FXLength2() qApp->Settings()->GetOsSeparator()); dialog->SetFormula(length2F); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { length2F = VTranslateVars::TryFormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator()); @@ -553,7 +553,7 @@ void DialogSplinePath::EvalLength1() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditLength1; formulaData.labelResult = ui->labelResultLength1; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); formulaData.checkZero = false; formulaData.checkLessThanZero = true; @@ -580,7 +580,7 @@ void DialogSplinePath::EvalLength2() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditLength2; formulaData.labelResult = ui->labelResultLength2; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); formulaData.checkZero = false; formulaData.checkLessThanZero = true; diff --git a/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.cpp b/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.cpp index d87813835..19ec44b48 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.cpp @@ -545,7 +545,7 @@ void DialogPiecePath::PassmarkChanged(int index) if (passmarkLength.isEmpty()) { - qreal length = UnitConvertor(1, Unit::Cm, qApp->patternUnit()); + qreal length = UnitConvertor(1, Unit::Cm, qApp->patternUnits()); ui->plainTextEditPassmarkLength->setPlainText(qApp->LocaleToString(length)); } else @@ -555,7 +555,7 @@ void DialogPiecePath::PassmarkChanged(int index) } else { - qreal length = UnitConvertor(1, Unit::Cm, qApp->patternUnit()); + qreal length = UnitConvertor(1, Unit::Cm, qApp->patternUnits()); ui->plainTextEditPassmarkLength->setPlainText(qApp->LocaleToString(length)); } @@ -796,7 +796,7 @@ void DialogPiecePath::EvalWidth() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditWidth; formulaData.labelResult = ui->labelResultWidth; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); formulaData.checkZero = false; formulaData.checkLessThanZero = true; @@ -827,7 +827,7 @@ void DialogPiecePath::EvalWidthBefore() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditBefore; formulaData.labelResult = ui->labelResultBefore; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); formulaData.checkZero = false; formulaData.checkLessThanZero = true; @@ -862,7 +862,7 @@ void DialogPiecePath::EvalWidthAfter() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditAfter; formulaData.labelResult = ui->labelResultAfter; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); formulaData.checkZero = false; formulaData.checkLessThanZero = true; @@ -910,7 +910,7 @@ void DialogPiecePath::EvalPassmarkLength() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditPassmarkLength; formulaData.labelResult = ui->labelResultPassmarkLength; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); formulaData.checkZero = false; formulaData.checkLessThanZero = false; @@ -927,7 +927,7 @@ void DialogPiecePath::FXWidth() dialog->setWindowTitle(tr("Edit seam allowance width")); dialog->SetFormula(GetFormulaSAWidth()); dialog->setCheckLessThanZero(true); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetFormulaSAWidth(dialog->GetFormula()); @@ -941,7 +941,7 @@ void DialogPiecePath::FXWidthBefore() dialog->setWindowTitle(tr("Edit seam allowance width before")); dialog->SetFormula(GetFormulaSAWidthBefore()); dialog->setCheckLessThanZero(true); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetCurrentSABefore(dialog->GetFormula()); @@ -955,7 +955,7 @@ void DialogPiecePath::FXWidthAfter() dialog->setWindowTitle(tr("Edit seam allowance width after")); dialog->SetFormula(GetFormulaSAWidthAfter()); dialog->setCheckLessThanZero(true); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetCurrentSAAfter(dialog->GetFormula()); @@ -980,7 +980,7 @@ void DialogPiecePath::FXPassmarkLength() QScopedPointer dialog(new DialogEditWrongFormula(data, toolId, this)); dialog->setWindowTitle(tr("Edit passmark length")); dialog->SetFormula(GetFormulaPassmarkLength()); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetFormulaPassmarkLength(dialog->GetFormula()); @@ -1099,7 +1099,7 @@ void DialogPiecePath::InitSeamAllowanceTab() connect(m_timerWidthAfter, &QTimer::timeout, this, &DialogPiecePath::EvalWidthAfter); // Default value for seam allowence is 1 cm. But pattern have different units, so just set 1 in dialog not enough. - m_saWidth = UnitConvertor(1, Unit::Cm, qApp->patternUnit()); + m_saWidth = UnitConvertor(1, Unit::Cm, qApp->patternUnits()); ui->plainTextEditFormulaWidth->setPlainText(qApp->LocaleToString(m_saWidth)); InitNodesList(); diff --git a/src/libs/vtools/dialogs/tools/piece/dialogplacelabel.cpp b/src/libs/vtools/dialogs/tools/piece/dialogplacelabel.cpp index da2049771..b5e4e59b4 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogplacelabel.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialogplacelabel.cpp @@ -315,7 +315,7 @@ void DialogPlaceLabel::EvalWidth() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditFormulaWidth; formulaData.labelResult = ui->labelResultCalculationWidth; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); formulaData.checkLessThanZero = true; Eval(formulaData, m_flagWidth); @@ -329,7 +329,7 @@ void DialogPlaceLabel::EvalHeight() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = ui->labelEditFormulaHeight; formulaData.labelResult = ui->labelResultCalculationHeight; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); formulaData.checkLessThanZero = true; Eval(formulaData, m_flagHeight); @@ -370,7 +370,7 @@ void DialogPlaceLabel::FXWidth() QScopedPointer dialog(new DialogEditWrongFormula(data, toolId, this)); dialog->setWindowTitle(tr("Edit rectangle width")); dialog->SetFormula(GetWidth()); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetWidth(dialog->GetFormula()); @@ -383,7 +383,7 @@ void DialogPlaceLabel::FXHeight() QScopedPointer dialog(new DialogEditWrongFormula(data, toolId, this)); dialog->setWindowTitle(tr("Edit rectangle width")); dialog->SetFormula(GetHeight()); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetHeight(dialog->GetFormula()); @@ -429,8 +429,8 @@ void DialogPlaceLabel::InitPlaceLabelTab() ui->plainTextEditFormulaHeight->installEventFilter(this); ui->plainTextEditFormulaAngle->installEventFilter(this); - ui->plainTextEditFormulaWidth->setPlainText(QString::number(UnitConvertor(1, Unit::Cm, qApp->patternUnit()))); - ui->plainTextEditFormulaHeight->setPlainText(QString::number(UnitConvertor(1, Unit::Cm, qApp->patternUnit()))); + ui->plainTextEditFormulaWidth->setPlainText(QString::number(UnitConvertor(1, Unit::Cm, qApp->patternUnits()))); + ui->plainTextEditFormulaHeight->setPlainText(QString::number(UnitConvertor(1, Unit::Cm, qApp->patternUnits()))); connect(ui->toolButtonExprWidth, &QPushButton::clicked, this, &DialogPlaceLabel::FXWidth); connect(ui->toolButtonExprHeight, &QPushButton::clicked, this, &DialogPlaceLabel::FXHeight); diff --git a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp index 964493504..73103d4c8 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp @@ -1050,7 +1050,7 @@ void DialogSeamAllowance::PassmarkChanged(int index) if (passmarkLength.isEmpty()) { - qreal length = UnitConvertor(1, Unit::Cm, qApp->patternUnit()); + qreal length = UnitConvertor(1, Unit::Cm, qApp->patternUnits()); uiTabPassmarks->plainTextEditPassmarkLength->setPlainText(qApp->LocaleToString(length)); } else @@ -1060,7 +1060,7 @@ void DialogSeamAllowance::PassmarkChanged(int index) } else { - qreal length = UnitConvertor(1, Unit::Cm, qApp->patternUnit()); + qreal length = UnitConvertor(1, Unit::Cm, qApp->patternUnits()); uiTabPassmarks->plainTextEditPassmarkLength->setPlainText(qApp->LocaleToString(length)); } @@ -1598,7 +1598,7 @@ void DialogSeamAllowance::UpdateGrainlineValues() { plbVal = uiTabGrainline->labelLen; plbText = uiTabGrainline->labelEditLen; - qsUnit = QChar(QChar::Space) + UnitsToStr(qApp->patternUnit()); + qsUnit = QChar(QChar::Space) + UnitsToStr(qApp->patternUnits()); } plbVal->setToolTip(tr("Value")); @@ -1667,13 +1667,13 @@ void DialogSeamAllowance::UpdateDetailLabelValues() { plbVal = uiTabLabels->labelDLWidth; plbText = uiTabLabels->labelEditDLWidth; - qsUnit = QChar(QChar::Space) + UnitsToStr(qApp->patternUnit()); + qsUnit = QChar(QChar::Space) + UnitsToStr(qApp->patternUnits()); } else if (i == 1) { plbVal = uiTabLabels->labelDLHeight; plbText = uiTabLabels->labelEditDLHeight; - qsUnit = QChar(QChar::Space) + UnitsToStr(qApp->patternUnit()); + qsUnit = QChar(QChar::Space) + UnitsToStr(qApp->patternUnits()); } else { @@ -1753,13 +1753,13 @@ void DialogSeamAllowance::UpdatePatternLabelValues() { plbVal = uiTabLabels->labelPLWidth; plbText = uiTabLabels->labelEditPLWidth; - qsUnit = QChar(QChar::Space) + UnitsToStr(qApp->patternUnit()); + qsUnit = QChar(QChar::Space) + UnitsToStr(qApp->patternUnits()); } else if (i == 1) { plbVal = uiTabLabels->labelPLHeight; plbText = uiTabLabels->labelEditPLHeight; - qsUnit = QChar(QChar::Space) + UnitsToStr(qApp->patternUnit()); + qsUnit = QChar(QChar::Space) + UnitsToStr(qApp->patternUnits()); } else { @@ -2133,7 +2133,7 @@ void DialogSeamAllowance::EvalWidth() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = uiTabPaths->labelEditWidth; formulaData.labelResult = uiTabPaths->labelResultWidth; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); formulaData.checkZero = false; formulaData.checkLessThanZero = true; @@ -2166,7 +2166,7 @@ void DialogSeamAllowance::EvalWidthBefore() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = uiTabPaths->labelEditBefore; formulaData.labelResult = uiTabPaths->labelResultBefore; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); formulaData.checkZero = false; formulaData.checkLessThanZero = true; @@ -2197,7 +2197,7 @@ void DialogSeamAllowance::EvalWidthAfter() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = uiTabPaths->labelEditAfter; formulaData.labelResult = uiTabPaths->labelResultAfter; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); formulaData.checkZero = false; formulaData.checkLessThanZero = true; @@ -2228,7 +2228,7 @@ void DialogSeamAllowance::EvalPassmarkLength() formulaData.variables = data->DataVariables(); formulaData.labelEditFormula = uiTabPassmarks->labelEditPassmarkLength; formulaData.labelResult = uiTabPassmarks->labelResultPassmarkLength; - formulaData.postfix = UnitsToStr(qApp->patternUnit(), true); + formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); formulaData.checkZero = false; formulaData.checkLessThanZero = false; @@ -2252,7 +2252,7 @@ void DialogSeamAllowance::FXWidth() dialog->setWindowTitle(tr("Edit seam allowance width")); dialog->SetFormula(GetFormulaSAWidth()); dialog->setCheckLessThanZero(true); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetFormulaSAWidth(dialog->GetFormula()); @@ -2266,7 +2266,7 @@ void DialogSeamAllowance::FXWidthBefore() dialog->setWindowTitle(tr("Edit seam allowance width before")); dialog->SetFormula(GetFormulaFromUser(uiTabPaths->plainTextEditFormulaWidthBefore)); dialog->setCheckLessThanZero(true); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetCurrentSABefore(dialog->GetFormula()); @@ -2280,7 +2280,7 @@ void DialogSeamAllowance::FXWidthAfter() dialog->setWindowTitle(tr("Edit seam allowance width after")); dialog->SetFormula(GetFormulaFromUser(uiTabPaths->plainTextEditFormulaWidthAfter)); dialog->setCheckLessThanZero(true); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetCurrentSAAfter(dialog->GetFormula()); @@ -2293,7 +2293,7 @@ void DialogSeamAllowance::FXPassmarkLength() QScopedPointer dialog(new DialogEditWrongFormula(data, toolId, this)); dialog->setWindowTitle(tr("Edit passmark length")); dialog->SetFormula(GetFormulaFromUser(uiTabPassmarks->plainTextEditPassmarkLength)); - dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); + dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true)); if (dialog->exec() == QDialog::Accepted) { SetFormularPassmarkLength(dialog->GetFormula()); @@ -2923,7 +2923,7 @@ void DialogSeamAllowance::InitSeamAllowanceTab() // init the default seam allowance, convert the value if app unit is different than pattern unit m_saWidth = UnitConvertor(qApp->Settings()->GetDefaultSeamAllowance(), - StrToUnits(qApp->Settings()->GetUnit()), qApp->patternUnit()); + StrToUnits(qApp->Settings()->GetUnit()), qApp->patternUnits()); uiTabPaths->plainTextEditFormulaWidth->setPlainText(qApp->LocaleToString(m_saWidth)); diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp index cda19cca6..434741545 100644 --- a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp @@ -890,7 +890,7 @@ QString VAbstractOperation::ComplexCurveToolTip(quint32 itemId) const "") .arg(tr("Label"), curve->name(), tr("Length")) .arg(qApp->fromPixel(curve->GetLength())) - .arg(UnitsToStr(qApp->patternUnit(), true), MakeToolTip()); + .arg(UnitsToStr(qApp->patternUnits(), true), MakeToolTip()); return toolTip; } diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp index 1e494a755..37621d7a7 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp @@ -398,7 +398,7 @@ VFormula VToolMove::GetFormulaLength() const VFormula fLength(formulaLength, getData()); fLength.setCheckZero(true); fLength.setToolId(m_id); - fLength.setPostfix(UnitsToStr(qApp->patternUnit())); + fLength.setPostfix(UnitsToStr(qApp->patternUnits())); fLength.Eval(); return fLength; } @@ -523,7 +523,7 @@ QString VToolMove::MakeToolTip() const .arg(GetFormulaAngle().getDoubleValue()) // 2 .arg(tr("Length")) // 3 .arg(GetFormulaLength().getDoubleValue()) // 4 - .arg(UnitsToStr(qApp->patternUnit(), true), // 5 + .arg(UnitsToStr(qApp->patternUnits(), true), // 5 tr("Rotation angle")) // 6 .arg(GetFormulaRotationAngle().getDoubleValue()) // 7 .arg(tr("Rotation origin point"), // 8 diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp index ccf490ad5..39963cb20 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp @@ -202,7 +202,7 @@ QString VAbstractSpline::MakeToolTip() const "") .arg(tr("Length")) .arg(qApp->fromPixel(curve->GetLength())) - .arg(UnitsToStr(qApp->patternUnit(), true), tr("Label"), curve->name()); + .arg(UnitsToStr(qApp->patternUnits(), true), tr("Label"), curve->name()); return toolTip; } diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp index 2331135d7..801137749 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp @@ -192,7 +192,7 @@ VFormula VToolArc::GetFormulaRadius() const VFormula radius(arc->GetFormulaRadius(), getData()); radius.setCheckZero(true); radius.setToolId(m_id); - radius.setPostfix(UnitsToStr(qApp->patternUnit())); + radius.setPostfix(UnitsToStr(qApp->patternUnits())); radius.Eval(); return radius; } @@ -387,7 +387,7 @@ QString VToolArc::MakeToolTip() const "") .arg(tr("Length")) .arg(qApp->fromPixel(arc->GetLength())) - .arg(UnitsToStr(qApp->patternUnit(), true), tr("Radius")) + .arg(UnitsToStr(qApp->patternUnits(), true), tr("Radius")) .arg(qApp->fromPixel(arc->GetRadius())) .arg(tr("Start angle")) .arg(arc->GetStartAngle()) diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp index 466066be4..dfa297148 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp @@ -173,7 +173,7 @@ VFormula VToolArcWithLength::GetFormulaRadius() const VFormula radius(arc->GetFormulaRadius(), getData()); radius.setCheckZero(true); radius.setToolId(m_id); - radius.setPostfix(UnitsToStr(qApp->patternUnit())); + radius.setPostfix(UnitsToStr(qApp->patternUnits())); radius.Eval(); return radius; } @@ -232,7 +232,7 @@ VFormula VToolArcWithLength::GetFormulaLength() const VFormula radius(arc->GetFormulaLength(), getData()); radius.setCheckZero(true); radius.setToolId(m_id); - radius.setPostfix(UnitsToStr(qApp->patternUnit())); + radius.setPostfix(UnitsToStr(qApp->patternUnits())); radius.Eval(); return radius; } @@ -366,7 +366,7 @@ QString VToolArcWithLength::MakeToolTip() const "") .arg(tr("Length")) .arg(qApp->fromPixel(arc->GetLength())) - .arg(UnitsToStr(qApp->patternUnit(), true), tr("Radius")) + .arg(UnitsToStr(qApp->patternUnits(), true), tr("Radius")) .arg(qApp->fromPixel(arc->GetRadius())) .arg(tr("Start angle")) .arg(arc->GetStartAngle()) diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.cpp index 3f0ba3fab..556faf696 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.cpp @@ -201,7 +201,7 @@ VFormula VToolEllipticalArc::GetFormulaRadius1() const VFormula radius1(elArc->GetFormulaRadius1(), getData()); radius1.setCheckZero(true); radius1.setToolId(m_id); - radius1.setPostfix(UnitsToStr(qApp->patternUnit())); + radius1.setPostfix(UnitsToStr(qApp->patternUnits())); radius1.Eval(); return radius1; } @@ -230,7 +230,7 @@ VFormula VToolEllipticalArc::GetFormulaRadius2() const VFormula radius2(elArc->GetFormulaRadius2(), getData()); radius2.setCheckZero(true); radius2.setToolId(m_id); - radius2.setPostfix(UnitsToStr(qApp->patternUnit())); + radius2.setPostfix(UnitsToStr(qApp->patternUnits())); radius2.Eval(); return radius2; } @@ -440,7 +440,7 @@ QString VToolEllipticalArc::MakeToolTip() const "") .arg(tr("Length")) // 1 .arg(qApp->fromPixel(elArc->GetLength())) // 2 - .arg(UnitsToStr(qApp->patternUnit(), true), // 3 + .arg(UnitsToStr(qApp->patternUnits(), true), // 3 tr("Radius") + QLatin1Char('1')) // 4 .arg(qApp->fromPixel(elArc->GetRadius1())) // 5 .arg(tr("Radius") + QLatin1Char('2')) // 6 diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp index 8977b5fe1..f0de213d4 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp @@ -83,7 +83,7 @@ VFormula VToolCut::GetFormula() const VFormula val(formula, getData()); val.setCheckZero(true); val.setToolId(m_id); - val.setPostfix(UnitsToStr(qApp->patternUnit())); + val.setPostfix(UnitsToStr(qApp->patternUnits())); val.Eval(); return val; } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp index 96d8c3a6d..9231b893d 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp @@ -283,7 +283,7 @@ QString VToolCutArc::MakeToolTip() const " %8: %9° ") .arg(arcStr + arcNumber + QChar(QChar::Space) + lengthStr) .arg(qApp->fromPixel(arc.GetLength())) - .arg(UnitsToStr(qApp->patternUnit(), true), arcStr + arcNumber + QChar(QChar::Space) + radiusStr) + .arg(UnitsToStr(qApp->patternUnits(), true), arcStr + arcNumber + QChar(QChar::Space) + radiusStr) .arg(qApp->fromPixel(arc.GetRadius())) .arg(arcStr + arcNumber + QChar(QChar::Space) + startAngleStr) .arg(arc.GetStartAngle()) diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp index 5468ff2ce..9e056c490 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp @@ -277,7 +277,7 @@ QString VToolCutSpline::MakeToolTip() const "") .arg(curveStr + QLatin1String("1 ") + lengthStr) .arg(qApp->fromPixel(spline1.GetLength())) - .arg(UnitsToStr(qApp->patternUnit(), true), curveStr + QLatin1String("2 ") + lengthStr) + .arg(UnitsToStr(qApp->patternUnits(), true), curveStr + QLatin1String("2 ") + lengthStr) .arg(qApp->fromPixel(spline2.GetLength())) .arg(curveStr + QLatin1String(" 1") + tr("label"), spline1.name(), curveStr + QLatin1String(" 2") + tr("label"), spline2.name()); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp index 4bd33786f..d37b00fa2 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp @@ -367,7 +367,7 @@ QString VToolCutSplinePath::MakeToolTip() const "") .arg(curveStr + QLatin1String("1 ") + lengthStr) .arg(qApp->fromPixel(splPath1->GetLength())) - .arg(UnitsToStr(qApp->patternUnit(), true), curveStr + QLatin1String("2 ") + lengthStr) + .arg(UnitsToStr(qApp->patternUnits(), true), curveStr + QLatin1String("2 ") + lengthStr) .arg(qApp->fromPixel(splPath2->GetLength())) .arg(curveStr + QLatin1String(" 1") + tr("label"), splPath1->name(), curveStr + QLatin1String(" 2") + tr("label"), splPath2->name()); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp index 206cfe524..9e1cffc36 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp @@ -162,7 +162,7 @@ QString VToolAlongLine::MakeToolTip() const "") .arg(tr("Length")) .arg(qApp->fromPixel(curLine.length())) - .arg(UnitsToStr(qApp->patternUnit(), true), tr("Angle")) + .arg(UnitsToStr(qApp->patternUnits(), true), tr("Angle")) .arg(curLine.angle()) .arg(QStringLiteral("%1->%2").arg(basePoint->name(), current->name()), QStringLiteral("%1->%2").arg(current->name(), secondPoint->name())) diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp index 6e5735029..1ea2ef245 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp @@ -143,7 +143,7 @@ VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(VToolCurveIntersectAxis " through point '%3' with angle %4°") .arg(initData.name, curve->name(), basePoint->name()).arg(angle); qApp->IsPedantic() ? throw VExceptionObjectError(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } const qreal segLength = curve->GetLengthByPoint(fPoint); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolheight.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolheight.cpp index b6e02024b..40c28fd76 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolheight.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolheight.cpp @@ -281,7 +281,7 @@ QString VToolHeight::MakeToolTip() const "") .arg(tr("Length")) .arg(qApp->fromPixel(curLine.length())) - .arg(UnitsToStr(qApp->patternUnit(), true), tr("Angle")) + .arg(UnitsToStr(qApp->patternUnits(), true), tr("Angle")) .arg(curLine.angle()) .arg(QString("%1->%2").arg(p1Line->name(), current->name())) .arg(qApp->fromPixel(p1ToCur.length())) diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp index 7c9cc6b96..a154972ba 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp @@ -135,7 +135,7 @@ VToolLineIntersectAxis *VToolLineIntersectAxis::Create(VToolLineIntersectAxisIni "through point '%4' and angle %5°") .arg(initData.name, firstPoint->name(), secondPoint->name(), basePoint->name()).arg(axis.angle()); qApp->IsPedantic() ? throw VExceptionObjectError(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my); @@ -342,7 +342,7 @@ QString VToolLineIntersectAxis::MakeToolTip() const "") .arg(tr("Length")) .arg(qApp->fromPixel(curLine.length())) - .arg(UnitsToStr(qApp->patternUnit(), true), tr("Angle")) + .arg(UnitsToStr(qApp->patternUnits(), true), tr("Angle")) .arg(curLine.angle()) .arg(QString("%1->%2").arg(firstPoint->name(), current->name())) .arg(qApp->fromPixel(firstToCur.length())) diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.cpp index 9e36108f4..eff502941 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.cpp @@ -158,7 +158,7 @@ QString VToolLinePoint::MakeToolTip() const "") .arg(tr("Length")) .arg(qApp->fromPixel(line.length())) - .arg(UnitsToStr(qApp->patternUnit(), true), tr("Angle")) + .arg(UnitsToStr(qApp->patternUnits(), true), tr("Angle")) .arg(line.angle()) .arg(tr("Label"), second->name()); return toolTip; @@ -217,7 +217,7 @@ VFormula VToolLinePoint::GetFormulaLength() const VFormula fLength(formulaLength, this->getData()); fLength.setCheckZero(false); fLength.setToolId(m_id); - fLength.setPostfix(UnitsToStr(qApp->patternUnit())); + fLength.setPostfix(UnitsToStr(qApp->patternUnits())); fLength.Eval(); return fLength; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.cpp index e85768593..bd87e2e88 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.cpp @@ -339,7 +339,7 @@ QString VToolShoulderPoint::MakeToolTip() const "") .arg(tr("Length")) .arg(qApp->fromPixel(firstToCur.length())) - .arg(UnitsToStr(qApp->patternUnit(), true), tr("Angle")) + .arg(UnitsToStr(qApp->patternUnits(), true), tr("Angle")) .arg(firstToCur.angle()) .arg(QString("%1->%2").arg(second->name(), current->name())) .arg(qApp->fromPixel(secondToCur.length())) diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.cpp index 99b269d9e..5a34b2776 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.cpp @@ -150,7 +150,7 @@ VToolLineIntersect* VToolLineIntersect::Create(VToolLineIntersectInitData initDa "intersection") .arg(initData.name, p1Line1->name(), p2Line1->name(), p1Line2->name(), p2Line2->name()); qApp->IsPedantic() ? throw VExceptionObjectError(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my); @@ -321,7 +321,7 @@ QString VToolLineIntersect::MakeToolTip() const "") .arg(QString("%1->%2").arg(p1L1->name(), current->name())) .arg(qApp->fromPixel(p1L1ToCur.length())) - .arg(UnitsToStr(qApp->patternUnit(), true), QString("%1->%2").arg(current->name(), p2L1->name())) + .arg(UnitsToStr(qApp->patternUnits(), true), QString("%1->%2").arg(current->name(), p2L1->name())) .arg(qApp->fromPixel(curToP2L1.length())) .arg(QString("%1->%2").arg(p1L2->name(), current->name())) .arg(qApp->fromPixel(p1L2ToCur.length())) diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp index b9974f66e..f99b82692 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp @@ -122,7 +122,7 @@ VToolPointFromArcAndTangent *VToolPointFromArcAndTangent::Create(VToolPointFromA const QString errorMsg = tr("Error calculating point '%1'. Tangent to arc '%2' from point '%3' cannot be found") .arg(initData.name, arc.name(), tPoint.name()); qApp->IsPedantic() ? throw VExceptionObjectError(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp index 53acddb37..230df2356 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp @@ -131,7 +131,7 @@ VToolPointFromCircleAndTangent *VToolPointFromCircleAndTangent::Create(VToolPoin .arg(initData.name, cPoint.name()).arg(radius).arg(tPoint.name()); qApp->IsPedantic() ? throw VExceptionObjectError(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my); @@ -206,7 +206,7 @@ VFormula VToolPointFromCircleAndTangent::GetCircleRadius() const VFormula radius(circleRadius, getData()); radius.setCheckZero(true); radius.setToolId(m_id); - radius.setPostfix(UnitsToStr(qApp->patternUnit())); + radius.setPostfix(UnitsToStr(qApp->patternUnits())); radius.Eval(); return radius; } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp index d771b059b..9aa1ad7ac 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp @@ -217,7 +217,7 @@ VToolPointOfContact* VToolPointOfContact::Create(VToolPointOfContactInitData &in "intersection with line (%4;%5)") .arg(initData.name, centerP->name()).arg(result).arg(firstP->name(), secondP->name()); qApp->IsPedantic() ? throw VExceptionObjectError(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my); @@ -373,7 +373,7 @@ QString VToolPointOfContact::MakeToolTip() const "") .arg(QStringLiteral("%1->%2").arg(p1->name(), current->name())) .arg(qApp->fromPixel(p1ToCur.length())) - .arg(UnitsToStr(qApp->patternUnit(), true), QStringLiteral("%1->%2").arg(p2->name(), current->name())) + .arg(UnitsToStr(qApp->patternUnits(), true), QStringLiteral("%1->%2").arg(p2->name(), current->name())) .arg(qApp->fromPixel(p2ToCur.length())) .arg(QStringLiteral("%1 %2->%3").arg(tr("Length"), centerP->name(), current->name())) .arg(qApp->fromPixel(centerToCur.length())) @@ -409,7 +409,7 @@ VFormula VToolPointOfContact::getArcRadius() const VFormula radius(arcRadius, this->getData()); radius.setCheckZero(true); radius.setToolId(m_id); - radius.setPostfix(UnitsToStr(qApp->patternUnit())); + radius.setPostfix(UnitsToStr(qApp->patternUnits())); radius.Eval(); return radius; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.cpp index 8e258a64b..081c3b8d4 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.cpp @@ -121,7 +121,7 @@ VToolPointOfIntersectionArcs *VToolPointOfIntersectionArcs::Create(VToolPointOfI const QString errorMsg = tr("Error calculating point '%1'. Arcs '%2' and '%3' have no point of intersection") .arg(initData.name, firstArc->name(), secondArc->name()); qApp->IsPedantic() ? throw VExceptionObjectError(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.cpp index 61e5a68a0..80cd70d7c 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.cpp @@ -135,7 +135,7 @@ VToolPointOfIntersectionCircles::Create(VToolPointOfIntersectionCirclesInitData const QString errorMsg = tr("Error calculating point '%1'. Circles with centers in points '%2' and '%3' have " "no point of intersection").arg(initData.name, c1Point.name(), c2Point.name()); qApp->IsPedantic() ? throw VExceptionObjectError(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my); @@ -219,7 +219,7 @@ VFormula VToolPointOfIntersectionCircles::GetFirstCircleRadius() const VFormula radius(firstCircleRadius, getData()); radius.setCheckZero(true); radius.setToolId(m_id); - radius.setPostfix(UnitsToStr(qApp->patternUnit())); + radius.setPostfix(UnitsToStr(qApp->patternUnits())); radius.Eval(); return radius; } @@ -244,7 +244,7 @@ VFormula VToolPointOfIntersectionCircles::GetSecondCircleRadius() const VFormula radius(secondCircleRadius, getData()); radius.setCheckZero(true); radius.setToolId(m_id); - radius.setPostfix(UnitsToStr(qApp->patternUnit())); + radius.setPostfix(UnitsToStr(qApp->patternUnits())); radius.Eval(); return radius; } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.cpp index 1c1f23e07..9927b79d0 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.cpp @@ -126,7 +126,7 @@ VToolPointOfIntersectionCurves *VToolPointOfIntersectionCurves::Create(VToolPoin const QString errorMsg = tr("Error calculating point '%1'. Curves '%2' and '%3' have no point of intersection") .arg(initData.name, curve1->name(), curve2->name()); qApp->IsPedantic() ? throw VExceptionObjectError(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.cpp index 67b0c80dd..d71ee141c 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.cpp @@ -148,7 +148,7 @@ VToolTriangle* VToolTriangle::Create(VToolTriangleInitData initData) const QString errorMsg = tr("Error calculating point '%1'. Point of intersection cannot be found") .arg(initData.name); qApp->IsPedantic() ? throw VExceptionObjectError(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my); diff --git a/src/libs/vtools/tools/drawTools/vtoolline.cpp b/src/libs/vtools/tools/drawTools/vtoolline.cpp index c6db258d9..b054c4edd 100644 --- a/src/libs/vtools/tools/drawTools/vtoolline.cpp +++ b/src/libs/vtools/tools/drawTools/vtoolline.cpp @@ -442,7 +442,7 @@ QString VToolLine::MakeToolTip() const "") .arg(tr("Length")) .arg(qApp->fromPixel(line.length())) - .arg(UnitsToStr(qApp->patternUnit(), true), tr("Angle")) + .arg(UnitsToStr(qApp->patternUnits(), true), tr("Angle")) .arg(line.angle()); return toolTip; } diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 261691386..c5646374e 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -1321,7 +1321,7 @@ void VToolSeamAllowance::RefreshGeometry(bool updateChildren) const QString errorMsg = QObject::tr("Piece '%1'. Seam allowance is not valid.") .arg(detail.GetName()); qApp->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } path.addPath(detail.SeamAllowancePath(futureSeamAllowance.result())); path.setFillRule(Qt::OddEvenFill); diff --git a/src/libs/vtools/undocommands/addtocalc.cpp b/src/libs/vtools/undocommands/addtocalc.cpp index af22114b7..a91bc142c 100644 --- a/src/libs/vtools/undocommands/addtocalc.cpp +++ b/src/libs/vtools/undocommands/addtocalc.cpp @@ -33,7 +33,7 @@ #include "../vwidgets/vmaingraphicsview.h" #include "../ifc/xml/vabstractpattern.h" #include "../ifc/ifcdef.h" -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "../vmisc/customevents.h" #include "vundocommand.h" diff --git a/src/libs/vtools/undocommands/deletepatternpiece.cpp b/src/libs/vtools/undocommands/deletepatternpiece.cpp index 240906984..43f930a5b 100644 --- a/src/libs/vtools/undocommands/deletepatternpiece.cpp +++ b/src/libs/vtools/undocommands/deletepatternpiece.cpp @@ -31,7 +31,7 @@ #include #include -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "../ifc/xml/vabstractpattern.h" #include "vundocommand.h" diff --git a/src/libs/vtools/undocommands/deltool.cpp b/src/libs/vtools/undocommands/deltool.cpp index 30e89c96c..cf4642163 100644 --- a/src/libs/vtools/undocommands/deltool.cpp +++ b/src/libs/vtools/undocommands/deltool.cpp @@ -32,7 +32,7 @@ #include "../ifc/ifcdef.h" #include "../ifc/xml/vabstractpattern.h" -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "vundocommand.h" //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/undocommands/movespline.cpp b/src/libs/vtools/undocommands/movespline.cpp index 785f01a69..170839705 100644 --- a/src/libs/vtools/undocommands/movespline.cpp +++ b/src/libs/vtools/undocommands/movespline.cpp @@ -32,7 +32,7 @@ #include "../ifc/ifcdef.h" #include "../ifc/xml/vabstractpattern.h" -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "../vmisc/def.h" #include "../vwidgets/vmaingraphicsview.h" #include "../vgeometry/vpointf.h" diff --git a/src/libs/vtools/undocommands/movespoint.cpp b/src/libs/vtools/undocommands/movespoint.cpp index 2ba0029a7..123ecf020 100644 --- a/src/libs/vtools/undocommands/movespoint.cpp +++ b/src/libs/vtools/undocommands/movespoint.cpp @@ -32,7 +32,7 @@ #include "../ifc/xml/vabstractpattern.h" #include "../ifc/ifcdef.h" -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "../vmisc/def.h" #include "vundocommand.h" diff --git a/src/libs/vtools/undocommands/undogroup.cpp b/src/libs/vtools/undocommands/undogroup.cpp index 1ef1cec28..3dde2498a 100644 --- a/src/libs/vtools/undocommands/undogroup.cpp +++ b/src/libs/vtools/undocommands/undogroup.cpp @@ -31,7 +31,7 @@ #include #include -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "../vmisc/def.h" #include "../vwidgets/vmaingraphicsview.h" #include "../ifc/xml/vabstractpattern.h" diff --git a/src/libs/vtools/visualization/line/operation/vistoolmove.cpp b/src/libs/vtools/visualization/line/operation/vistoolmove.cpp index 627df2a79..984540d0f 100644 --- a/src/libs/vtools/visualization/line/operation/vistoolmove.cpp +++ b/src/libs/vtools/visualization/line/operation/vistoolmove.cpp @@ -170,7 +170,7 @@ void VisToolMove::RefreshGeometry() DrawLine(this, line, supportColor2, Qt::DashLine); DrawPoint(pointFinish, line.p2(), supportColor); - static const QString prefix = UnitsToStr(qApp->patternUnit(), true); + static const QString prefix = UnitsToStr(qApp->patternUnits(), true); if (qFuzzyIsNull(length)) { Visualization::toolTip = tr("Length = %1%2, angle = %3°, %4 - sticking angle, " diff --git a/src/libs/vtools/visualization/line/vistoolendline.cpp b/src/libs/vtools/visualization/line/vistoolendline.cpp index 654f9275c..88e9e6906 100644 --- a/src/libs/vtools/visualization/line/vistoolendline.cpp +++ b/src/libs/vtools/visualization/line/vistoolendline.cpp @@ -79,7 +79,7 @@ void VisToolEndLine::RefreshGeometry() DrawPoint(point, line.p2(), mainColor); } DrawLine(this, line, mainColor, lineStyle); - static const QString prefix = UnitsToStr(qApp->patternUnit(), true); + static const QString prefix = UnitsToStr(qApp->patternUnits(), true); Visualization::toolTip = tr("Point at distance and angle: angle = %1°, length = %2%3; " "%4 - sticking angle, %5 - finish creation") .arg(this->line().angle()) diff --git a/src/libs/vtools/visualization/visualization.h b/src/libs/vtools/visualization/visualization.h index 1a302820e..8c7014411 100644 --- a/src/libs/vtools/visualization/visualization.h +++ b/src/libs/vtools/visualization/visualization.h @@ -36,7 +36,7 @@ #include #include "../vmisc/def.h" -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "../vwidgets/vmaingraphicsscene.h" #include "../vwidgets/vcurvepathitem.h" #include "../vwidgets/global.h" diff --git a/src/libs/vwidgets/vgraphicssimpletextitem.cpp b/src/libs/vwidgets/vgraphicssimpletextitem.cpp index 370bc876f..3d3762187 100644 --- a/src/libs/vwidgets/vgraphicssimpletextitem.cpp +++ b/src/libs/vwidgets/vgraphicssimpletextitem.cpp @@ -48,7 +48,7 @@ #include "global.h" #include "vscenepoint.h" #include "../vmisc/vmath.h" -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" //--------------------------------------------------------------------------------------------------------------------- /** diff --git a/src/libs/vwidgets/vmaingraphicsview.cpp b/src/libs/vwidgets/vmaingraphicsview.cpp index 8351784c7..1e9a3c65a 100644 --- a/src/libs/vwidgets/vmaingraphicsview.cpp +++ b/src/libs/vwidgets/vmaingraphicsview.cpp @@ -55,7 +55,7 @@ #include "vmaingraphicsscene.h" #include "vsimplecurve.h" #include "vcontrolpointspline.h" -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "../vmisc/vsettings.h" #include "vabstractmainwindow.h" #include "global.h" diff --git a/src/test/ValentinaTest/tst_vpiece.cpp b/src/test/ValentinaTest/tst_vpiece.cpp index 0db6fcee6..26f816a35 100644 --- a/src/test/ValentinaTest/tst_vpiece.cpp +++ b/src/test/ValentinaTest/tst_vpiece.cpp @@ -33,7 +33,7 @@ #include "../vpatterndb/vpiecenode.h" #include "../vpatterndb/vpiecepath.h" #include "../vgeometry/vsplinepath.h" -#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include #include "../vpatterndb/vpiece.h" @@ -51,7 +51,7 @@ void TST_VPiece::Issue620() // Check main path const Unit unit = Unit::Cm; QSharedPointer data(new VContainer(nullptr, &unit, VContainer::UniqueNamespace())); - qApp->setPatternUnit(unit); + qApp->SetPatternUnits(unit); VPiece detail; AbstractTest::PieceFromJson(QStringLiteral("://Issue_620/input.json"), detail, data); From 18e1a4a601b5ddae520db26c6081cfb48732e2c3 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 16 Oct 2020 08:22:43 +0300 Subject: [PATCH 36/44] Remove gradation information from pattern. --- dist/debian/valentina.1 | 10 +- src/app/valentina/core/vcmdexport.cpp | 77 +- src/app/valentina/core/vcmdexport.h | 10 +- .../dialogs/dialogpatternproperties.cpp | 458 +------ .../dialogs/dialogpatternproperties.h | 28 - .../dialogs/dialogpatternproperties.ui | 1011 +--------------- src/app/valentina/mainwindow.cpp | 91 +- src/app/valentina/mainwindow.h | 5 +- src/app/valentina/xml/vpattern.cpp | 158 --- src/app/valentina/xml/vpattern.h | 11 - src/libs/ifc/schema.qrc | 1 + src/libs/ifc/schema/pattern/v0.8.8.xsd | 1071 +++++++++++++++++ src/libs/ifc/xml/vabstractpattern.cpp | 497 +------- src/libs/ifc/xml/vabstractpattern.h | 68 -- src/libs/ifc/xml/vpatternconverter.cpp | 38 +- src/libs/ifc/xml/vpatternconverter.h | 5 +- src/libs/vmisc/commandoptions.cpp | 13 +- src/libs/vmisc/commandoptions.h | 8 +- src/libs/vmisc/def.h | 13 - .../vpatterndb/variables/vmeasurement.cpp | 120 -- src/libs/vpatterndb/variables/vmeasurement.h | 7 - 21 files changed, 1286 insertions(+), 2414 deletions(-) create mode 100644 src/libs/ifc/schema/pattern/v0.8.8.xsd diff --git a/dist/debian/valentina.1 b/dist/debian/valentina.1 index 48c841dd1..44803fad8 100644 --- a/dist/debian/valentina.1 +++ b/dist/debian/valentina.1 @@ -139,10 +139,12 @@ The path to output destination folder. By default the directory at which the app .RB "Export only details. Export details as they positioned in the details mode. Any layout related options will be ignored." .IP "--exportSuchDetails " .RB "Export only details that match a piece name regex." -.IP "-x, --gsize " -.RB "Set size value a pattern file, that was opened with multisize measurements " "(export mode)" ". Valid values: 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56cm." -.IP "-e, --gheight " -.RB "Set height value a pattern file, that was opened with multisize measurements (" "export mode" "). Valid values: 92, 98, 104, 110, 116, 122, 128, 134, 140, 146, 152, 158, 164, 170, 176, 182, 188, 194, 200cm." +.IP "--dimensionA " +.RB "Set base for dimension A in the multisize measurements units " "(export mode)" "." +.IP "--dimensionB " +.RB "Set base for dimension B in the multisize measurements units " "(export mode)" "." +.IP "--dimensionC " +.RB "Set base for dimension C in the multisize measurements units " "(export mode)" "." .IP "--userMaterial " .RB "Use this option to override user material defined in pattern. The value must be in form @. The number should be in range from 1 to 20. For example, 1@Fabric2. The key can be used multiple times. Has no effect in GUI mode." .IP "-p, --pageformat