From 0c64c55eb2152188a3deb9b3ed618a57ff3c5133 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 19 Oct 2023 17:59:34 +0300 Subject: [PATCH] Tape app. Show variables in order they were added if possible. Additionally users can sort the list. --- ChangeLog.txt | 1 + .../support/dialogeditwrongformula.cpp | 67 +++++++++++-------- .../dialogs/support/dialogeditwrongformula.h | 4 +- .../dialogs/support/dialogeditwrongformula.ui | 7 +- 4 files changed, 47 insertions(+), 32 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index dcbf19197..6bf156df9 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -49,6 +49,7 @@ - Puzzle app. Fix losing selection by piece. - Puzzle app. Fix updating layout when file already opened. - Tape app. Custom measurement name. +- Tape app. Show variables in order they were added. # Valentina 0.7.52 September 12, 2022 - Fix crash when default locale is ru. diff --git a/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp b/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp index efc335a4a..a2a3684fa 100644 --- a/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp +++ b/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp @@ -322,7 +322,13 @@ void DialogEditWrongFormula::PutVal(QTableWidgetItem *item) void DialogEditWrongFormula::Measurements() { ui->checkBoxHideEmpty->setEnabled(true); - ShowMeasurements(m_data->DataMeasurements()); + + QList> vars = m_data->DataMeasurements().values(); + std::stable_sort(vars.begin(), vars.end(), + [](const QSharedPointer &obj1, const QSharedPointer &obj2) + { return obj1->Index() < obj2->Index(); }); + + ShowMeasurements(vars); } //--------------------------------------------------------------------------------------------------------------------- @@ -332,21 +338,21 @@ void DialogEditWrongFormula::Measurements() void DialogEditWrongFormula::LengthLines() { ui->checkBoxHideEmpty->setEnabled(false); - ShowVariable(m_data->DataLengthLines()); + ShowVariable(m_data->DataLengthLines().values()); } //--------------------------------------------------------------------------------------------------------------------- void DialogEditWrongFormula::RadiusArcs() { ui->checkBoxHideEmpty->setEnabled(false); - ShowVariable(m_data->DataRadiusesArcs()); + ShowVariable(m_data->DataRadiusesArcs().values()); } //--------------------------------------------------------------------------------------------------------------------- void DialogEditWrongFormula::AnglesCurves() { ui->checkBoxHideEmpty->setEnabled(false); - ShowVariable(m_data->DataAnglesCurves()); + ShowVariable(m_data->DataAnglesCurves().values()); } //--------------------------------------------------------------------------------------------------------------------- @@ -356,21 +362,21 @@ void DialogEditWrongFormula::AnglesCurves() void DialogEditWrongFormula::LengthCurves() { ui->checkBoxHideEmpty->setEnabled(false); - ShowVariable(m_data->DataLengthCurves()); + ShowVariable(m_data->DataLengthCurves().values()); } //--------------------------------------------------------------------------------------------------------------------- void DialogEditWrongFormula::CurvesCLength() { ui->checkBoxHideEmpty->setEnabled(false); - ShowVariable(m_data->DataCurvesCLength()); + ShowVariable(m_data->DataCurvesCLength().values()); } //--------------------------------------------------------------------------------------------------------------------- void DialogEditWrongFormula::AngleLines() { ui->checkBoxHideEmpty->setEnabled(false); - ShowVariable(m_data->DataAngleLines()); + ShowVariable(m_data->DataAngleLines().values()); } //--------------------------------------------------------------------------------------------------------------------- @@ -392,7 +398,7 @@ void DialogEditWrongFormula::PreviewCalculations() void DialogEditWrongFormula::PieceArea() { ui->checkBoxHideEmpty->setEnabled(false); - ShowVariable(m_data->DataPieceArea()); + ShowVariable(m_data->DataPieceArea().values()); } //--------------------------------------------------------------------------------------------------------------------- @@ -629,9 +635,9 @@ void DialogEditWrongFormula::InitIcons() //--------------------------------------------------------------------------------------------------------------------- /** * @brief ShowVariable show variables in list - * @param var container with variables + * @param vars container with variables */ -template void DialogEditWrongFormula::ShowVariable(const QMap &var) +template void DialogEditWrongFormula::ShowVariable(const QList &vars) { ui->tableWidget->blockSignals(true); ui->tableWidget->clearContents(); @@ -639,24 +645,24 @@ template void DialogEditWrongFormula::ShowVariable(const ui->tableWidget->setColumnHidden(ColumnFullName, true); ui->labelDescription->setText(QString()); - QMapIterator iMap(var); - while (iMap.hasNext()) + for (const auto &var : vars) { - iMap.next(); - if (ui->checkBoxHideEmpty->isEnabled() && ui->checkBoxHideEmpty->isChecked() && iMap.value()->IsNotUsed()) + if (ui->checkBoxHideEmpty->isEnabled() && ui->checkBoxHideEmpty->isChecked() && var->IsNotUsed()) { continue; // skip this measurement } - if (iMap.value()->Filter(m_toolId) == false) + + if (!var->Filter(m_toolId)) { // If we create this variable don't show ui->tableWidget->setRowCount(ui->tableWidget->rowCount() + 1); - auto *item = new QTableWidgetItem(iMap.key()); + auto *item = new QTableWidgetItem(var->GetName()); QFont font = item->font(); font.setBold(true); item->setFont(font); ui->tableWidget->setItem(ui->tableWidget->rowCount() - 1, ColumnName, item); } } + ui->tableWidget->blockSignals(false); ui->tableWidget->selectRow(0); ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); @@ -665,9 +671,9 @@ template void DialogEditWrongFormula::ShowVariable(const //--------------------------------------------------------------------------------------------------------------------- /** * @brief ShowMeasurements show measurements in table - * @param var container with measurements + * @param vars container with measurements */ -void DialogEditWrongFormula::ShowMeasurements(const QMap> &var) +void DialogEditWrongFormula::ShowMeasurements(const QList> &vars) { ui->tableWidget->blockSignals(true); ui->tableWidget->clearContents(); @@ -675,18 +681,17 @@ void DialogEditWrongFormula::ShowMeasurements(const QMaptableWidget->setColumnHidden(ColumnFullName, false); ui->labelDescription->setText(QString()); - QMapIterator> iMap(var); - while (iMap.hasNext()) + for (const auto &var : vars) { - iMap.next(); - if (ui->checkBoxHideEmpty->isEnabled() && ui->checkBoxHideEmpty->isChecked() && iMap.value()->IsNotUsed()) + if (ui->checkBoxHideEmpty->isEnabled() && ui->checkBoxHideEmpty->isChecked() && var->IsNotUsed()) { continue; // skip this measurement } - if (not iMap.value()->Filter(m_toolId)) + + if (not var->Filter(m_toolId)) { // If we create this variable don't show ui->tableWidget->setRowCount(ui->tableWidget->rowCount() + 1); - auto *itemName = new QTableWidgetItem(iMap.key()); + auto *itemName = new QTableWidgetItem(var->GetName()); QFont fontName = itemName->font(); fontName.setBold(true); itemName->setFont(fontName); @@ -696,13 +701,13 @@ void DialogEditWrongFormula::ShowMeasurements(const QMapfont(); fontFullName.setBold(true); itemFullName->setFont(fontFullName); - if (iMap.value()->IsCustom()) + if (var->IsCustom()) { - itemFullName->setText(iMap.value()->GetGuiText()); + itemFullName->setText(var->GetGuiText()); } else { - itemFullName->setText(VAbstractApplication::VApp()->TrVars()->GuiText(iMap.value()->GetName())); + itemFullName->setText(VAbstractApplication::VApp()->TrVars()->GuiText(var->GetName())); } itemFullName->setToolTip(itemFullName->text()); @@ -710,6 +715,7 @@ void DialogEditWrongFormula::ShowMeasurements(const QMaptableWidget->setItem(ui->tableWidget->rowCount() - 1, ColumnFullName, itemFullName); } } + ui->tableWidget->blockSignals(false); ui->tableWidget->selectRow(0); ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); @@ -785,7 +791,12 @@ void DialogEditWrongFormula::ShowIncrementsInPreviewCalculation(bool show) ++i; } - ShowVariable(increments); + QList> vars = increments.values(); + std::stable_sort(vars.begin(), vars.end(), + [](const QSharedPointer &obj1, const QSharedPointer &obj2) + { return obj1->GetIndex() < obj2->GetIndex(); }); + + ShowVariable(vars); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/support/dialogeditwrongformula.h b/src/libs/vtools/dialogs/support/dialogeditwrongformula.h index a06458902..882720ba1 100644 --- a/src/libs/vtools/dialogs/support/dialogeditwrongformula.h +++ b/src/libs/vtools/dialogs/support/dialogeditwrongformula.h @@ -148,8 +148,8 @@ private: void InitVariables(); - template void ShowVariable(const QMap &var); - void ShowMeasurements(const QMap> &var); + template void ShowVariable(const QList &vars); + void ShowMeasurements(const QList> &vars); void ShowFunctions(); void ShowIncrementsInPreviewCalculation(bool show); diff --git a/src/libs/vtools/dialogs/support/dialogeditwrongformula.ui b/src/libs/vtools/dialogs/support/dialogeditwrongformula.ui index 2d19e614a..493c6d3d1 100644 --- a/src/libs/vtools/dialogs/support/dialogeditwrongformula.ui +++ b/src/libs/vtools/dialogs/support/dialogeditwrongformula.ui @@ -10,7 +10,7 @@ 0 0 542 - 483 + 512 @@ -95,7 +95,7 @@ Insert variable into formula - + @@ -363,6 +363,9 @@ PointingHandCursor + + true + Name