From 484b92a38ef27bba41e63898b109e108dc7457a9 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 28 Sep 2020 16:38:32 +0300 Subject: [PATCH] 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) };