From 16ce597a3743061731e2e660d5b4acf8e7ba5065 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 3 Oct 2020 18:52:31 +0300 Subject: [PATCH] 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;