diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index eaa378102..92b7acd2d 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -32,6 +32,7 @@ #include "dialogs/dialogabouttape.h" #include "dialogs/dialognewmeasurements.h" #include "../vpatterndb/calculator.h" +#include "../ifc/ifcdef.h" #include #include @@ -419,7 +420,7 @@ void TMainWindow::AddCustom() QString name; do { - name = QString("@" + tr("M_%1")).arg(num); + name = QString(CustomSign + tr("M_%1")).arg(num); num++; } while (data->IsUnique(name) == false); @@ -519,9 +520,9 @@ void TMainWindow::ShowMData() if (mType == MeasurementsType::Standard) { ui->labelCalculatedValue->setText(QString().setNum(data->GetTableValue(nameField->text(), mType))); - ui->doubleSpinBoxBaseValue->setValue(meash->GetBase()); - ui->doubleSpinBoxInSizes->setValue(meash->GetKsize()); - ui->doubleSpinBoxInHeights->setValue(meash->GetKheight()); + ui->spinBoxBaseValue->setValue(static_cast(meash->GetBase())); + ui->spinBoxInSizes->setValue(static_cast(meash->GetKsize())); + ui->spinBoxInHeights->setValue(static_cast(meash->GetKheight())); } else { @@ -540,6 +541,7 @@ void TMainWindow::ShowMData() if (not meash->IsCustom()) { + ui->plainTextEditDescription->setEnabled(false); ui->lineEditName->setEnabled(false); } } @@ -573,6 +575,157 @@ void TMainWindow::DeployFormula() setUpdatesEnabled(true); } +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::SaveMName() +{ + const int row = ui->tableWidget->currentRow(); + + if (row == -1) + { + return; + } + + QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), 0); + QSharedPointer meash = data->GetVariable(nameField->text()); + + QString newName = ui->lineEditName->text(); + if (meash->IsCustom()) + { + newName = CustomSign + newName; + } + + if (data->IsUnique(newName)) + { + m->SetMName(nameField->text(), newName); + MeasurementsWasSaved(false); + RefreshData(); + + ui->tableWidget->selectRow(row); + ui->tableWidget->resizeColumnsToContents(); + ui->tableWidget->resizeRowsToContents(); + ui->tableWidget->horizontalHeader()->setStretchLastSection(true); + } + else + { + ui->lineEditName->setText(ClearCustomName(nameField->text())); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::SaveMValue() +{ + const int row = ui->tableWidget->currentRow(); + + if (row == -1) + { + return; + } + + QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), 0); + m->SetMValue(nameField->text(), ui->plainTextEditFormula->toPlainText()); + + MeasurementsWasSaved(false); + + RefreshData(); + + ui->tableWidget->selectRow(row); + ui->tableWidget->resizeColumnsToContents(); + ui->tableWidget->resizeRowsToContents(); + ui->tableWidget->horizontalHeader()->setStretchLastSection(true); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::SaveMBaseValue(int value) +{ + const int row = ui->tableWidget->currentRow(); + + if (row == -1) + { + return; + } + + QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), 0); + m->SetMBaseValue(nameField->text(), value); + + MeasurementsWasSaved(false); + + RefreshData(); + + ui->tableWidget->selectRow(row); + ui->tableWidget->resizeColumnsToContents(); + ui->tableWidget->resizeRowsToContents(); + ui->tableWidget->horizontalHeader()->setStretchLastSection(true); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::SaveMSizeIncrease(int value) +{ + const int row = ui->tableWidget->currentRow(); + + if (row == -1) + { + return; + } + + QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), 0); + m->SetMSizeIncrease(nameField->text(), value); + + MeasurementsWasSaved(false); + + RefreshData(); + + ui->tableWidget->selectRow(row); + ui->tableWidget->resizeColumnsToContents(); + ui->tableWidget->resizeRowsToContents(); + ui->tableWidget->horizontalHeader()->setStretchLastSection(true); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::SaveMHeightIncrease(int value) +{ + const int row = ui->tableWidget->currentRow(); + + if (row == -1) + { + return; + } + + QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), 0); + m->SetMHeightIncrease(nameField->text(), value); + + MeasurementsWasSaved(false); + + RefreshData(); + + ui->tableWidget->selectRow(row); + ui->tableWidget->resizeColumnsToContents(); + ui->tableWidget->resizeRowsToContents(); + ui->tableWidget->horizontalHeader()->setStretchLastSection(true); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::SaveMDescription() +{ + const int row = ui->tableWidget->currentRow(); + + if (row == -1) + { + return; + } + + QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), 0); + m->SetMDescription(nameField->text(), ui->plainTextEditDescription->toPlainText()); + + MeasurementsWasSaved(false); + + RefreshData(); + + ui->tableWidget->selectRow(row); + ui->tableWidget->resizeColumnsToContents(); + ui->tableWidget->resizeRowsToContents(); + ui->tableWidget->horizontalHeader()->setStretchLastSection(true); +} + //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::SetupMenu() { @@ -656,6 +809,13 @@ void TMainWindow::InitWindow() SetDefaultSize(static_cast(data->size())); connect(gradationSizes, static_cast(&QComboBox::currentIndexChanged), this, &TMainWindow::ChangedSize); + + connect(ui->spinBoxBaseValue, static_cast(&QSpinBox::valueChanged), this, + &TMainWindow::SaveMBaseValue); + connect(ui->spinBoxInHeights, static_cast(&QSpinBox::valueChanged), this, + &TMainWindow::SaveMSizeIncrease); + connect(ui->spinBoxInHeights, static_cast(&QSpinBox::valueChanged), this, + &TMainWindow::SaveMHeightIncrease); } else { @@ -669,11 +829,11 @@ void TMainWindow::InitWindow() // Tab Measurements delete ui->labelBaseValue; - delete ui->doubleSpinBoxBaseValue; + delete ui->spinBoxBaseValue; delete ui->labelInSizes; - delete ui->doubleSpinBoxInSizes; + delete ui->spinBoxInSizes; delete ui->labelInHeights; - delete ui->doubleSpinBoxInHeights; + delete ui->spinBoxInHeights; // Tab Information delete ui->labelBaseSize; @@ -701,6 +861,8 @@ void TMainWindow::InitWindow() connect(ui->dateEditBirthDate, &QDateEdit::dateChanged, this, &TMainWindow::SaveBirthDate); connect(ui->plainTextEditNotes, &QPlainTextEdit::textChanged, this, &TMainWindow::SaveNotes); connect(ui->pushButtonGrow, &QPushButton::clicked, this, &TMainWindow::DeployFormula); + + connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &TMainWindow::SaveMValue); } ui->actionAddCustom->setEnabled(true); @@ -712,6 +874,9 @@ void TMainWindow::InitWindow() connect(ui->toolButtonUp, &QToolButton::clicked, this, &TMainWindow::MoveUp); connect(ui->toolButtonDown, &QToolButton::clicked, this, &TMainWindow::MoveDown); + connect(ui->lineEditName, &QLineEdit::editingFinished, this, &TMainWindow::SaveMName); + connect(ui->plainTextEditDescription, &QPlainTextEdit::textChanged, this, &TMainWindow::SaveMDescription); + InitTable(); } @@ -939,9 +1104,9 @@ void TMainWindow::MFields(bool enabled) if (mType == MeasurementsType::Standard) { - ui->doubleSpinBoxBaseValue->setEnabled(enabled); - ui->doubleSpinBoxInSizes->setEnabled(enabled); - ui->doubleSpinBoxInHeights->setEnabled(enabled); + ui->spinBoxBaseValue->setEnabled(enabled); + ui->spinBoxInSizes->setEnabled(enabled); + ui->spinBoxInHeights->setEnabled(enabled); } else { @@ -955,7 +1120,7 @@ void TMainWindow::MFields(bool enabled) QString TMainWindow::ClearCustomName(const QString &name) const { QString clear = name; - const int index = clear.indexOf("@"); + const int index = clear.indexOf(CustomSign); if (index == 0) { clear.remove(0, 1); diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index 93bdb327e..75d312432 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -85,6 +85,13 @@ private slots: void DeployFormula(); + void SaveMName(); + void SaveMValue(); + void SaveMBaseValue(int value); + void SaveMSizeIncrease(int value); + void SaveMHeightIncrease(int value); + void SaveMDescription(); + private: Q_DISABLE_COPY(TMainWindow) Ui::TMainWindow *ui; diff --git a/src/app/tape/tmainwindow.ui b/src/app/tape/tmainwindow.ui index c4cf1aaae..d32e6b4b5 100644 --- a/src/app/tape/tmainwindow.ui +++ b/src/app/tape/tmainwindow.ui @@ -219,13 +219,6 @@ - - - - false - - - @@ -233,13 +226,6 @@ - - - - false - - - @@ -247,13 +233,6 @@ - - - - false - - - @@ -347,6 +326,45 @@ + + + + false + + + -1000 + + + 1000 + + + + + + + false + + + -1000 + + + 1000 + + + + + + + false + + + -1000 + + + 1000 + + + diff --git a/src/libs/ifc/ifcdef.cpp b/src/libs/ifc/ifcdef.cpp index cd00687a7..8866567bf 100644 --- a/src/libs/ifc/ifcdef.cpp +++ b/src/libs/ifc/ifcdef.cpp @@ -28,6 +28,8 @@ #include "ifcdef.h" +const QString CustomSign = QStringLiteral("@"); + #define DefWidth 1.2//mm //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/ifc/ifcdef.h b/src/libs/ifc/ifcdef.h index e84290cce..700b72474 100644 --- a/src/libs/ifc/ifcdef.h +++ b/src/libs/ifc/ifcdef.h @@ -32,6 +32,8 @@ #include #include "../vmisc/def.h" +extern const QString CustomSign; + #ifdef Q_OS_WIN32 extern Q_CORE_EXPORT int qt_ntfs_permission_lookup; #include diff --git a/src/libs/vformat/vmeasurements.cpp b/src/libs/vformat/vmeasurements.cpp index 7d0735b8a..fe4dfd311 100644 --- a/src/libs/vformat/vmeasurements.cpp +++ b/src/libs/vformat/vmeasurements.cpp @@ -313,6 +313,66 @@ void VMeasurements::SetReadOnly(bool ro) } } +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurements::SetMName(const QString &name, const QString &text) +{ + QDomElement node = FindM(name); + if (not node.isNull()) + { + SetAttribute(node, AttrName, text); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurements::SetMValue(const QString &name, const QString &text) +{ + QDomElement node = FindM(name); + if (not node.isNull()) + { + SetAttribute(node, AttrValue, text); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurements::SetMBaseValue(const QString &name, int value) +{ + QDomElement node = FindM(name); + if (not node.isNull()) + { + SetAttribute(node, AttrValue, value); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurements::SetMSizeIncrease(const QString &name, int value) +{ + QDomElement node = FindM(name); + if (not node.isNull()) + { + SetAttribute(node, AttrSizeIncrease, value); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurements::SetMHeightIncrease(const QString &name, int value) +{ + QDomElement node = FindM(name); + if (not node.isNull()) + { + SetAttribute(node, AttrHeightIncrease, value); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurements::SetMDescription(const QString &name, const QString &text) +{ + QDomElement node = FindM(name); + if (not node.isNull()) + { + SetAttribute(node, AttrDescription, text); + } +} + //--------------------------------------------------------------------------------------------------------------------- QString VMeasurements::GenderToStr(const SexType &sex) { @@ -453,15 +513,16 @@ QDomElement VMeasurements::MakeEmpty(const QString &name) QDomElement element = createElement(TagMeasurement); SetAttribute(element, AttrName, name); - SetAttribute(element, AttrValue, QString("0")); if (type == MeasurementsType::Standard) { + SetAttribute(element, AttrBase, QString("0")); SetAttribute(element, AttrSizeIncrease, QString("0")); SetAttribute(element, AttrHeightIncrease, QString("0")); } else { + SetAttribute(element, AttrValue, QString("0")); SetAttribute(element, AttrDescription, QString("")); } diff --git a/src/libs/vformat/vmeasurements.h b/src/libs/vformat/vmeasurements.h index 50df498d7..4d036f6c8 100644 --- a/src/libs/vformat/vmeasurements.h +++ b/src/libs/vformat/vmeasurements.h @@ -75,6 +75,13 @@ public: bool ReadOnly() const; void SetReadOnly(bool ro); + void SetMName(const QString &name, const QString &text); + void SetMValue(const QString &name, const QString &text); + void SetMBaseValue(const QString &name, int value); + void SetMSizeIncrease(const QString &name, int value); + void SetMHeightIncrease(const QString &name, int value); + void SetMDescription(const QString &name, const QString &text); + static const QString TagVST; static const QString TagVIT; static const QString TagBodyMeasurements; diff --git a/src/libs/vpatterndb/variables/vmeasurement.cpp b/src/libs/vpatterndb/variables/vmeasurement.cpp index 3205f2be1..cdc015f93 100644 --- a/src/libs/vpatterndb/variables/vmeasurement.cpp +++ b/src/libs/vpatterndb/variables/vmeasurement.cpp @@ -218,7 +218,7 @@ QString VMeasurement::GetFormula() const //--------------------------------------------------------------------------------------------------------------------- bool VMeasurement::IsCustom() const { - if (GetName().indexOf("@") == 0) + if (GetName().indexOf(CustomSign) == 0) { return true; }