Tape app. Show variables in order they were added if possible.

Additionally users can sort the list.
This commit is contained in:
Roman Telezhynskyi 2023-10-19 17:59:34 +03:00
parent 2dae3816a6
commit 0c64c55eb2
4 changed files with 47 additions and 32 deletions

View File

@ -49,6 +49,7 @@
- Puzzle app. Fix losing selection by piece. - Puzzle app. Fix losing selection by piece.
- Puzzle app. Fix updating layout when file already opened. - Puzzle app. Fix updating layout when file already opened.
- Tape app. Custom measurement name. - Tape app. Custom measurement name.
- Tape app. Show variables in order they were added.
# Valentina 0.7.52 September 12, 2022 # Valentina 0.7.52 September 12, 2022
- Fix crash when default locale is ru. - Fix crash when default locale is ru.

View File

@ -322,7 +322,13 @@ void DialogEditWrongFormula::PutVal(QTableWidgetItem *item)
void DialogEditWrongFormula::Measurements() void DialogEditWrongFormula::Measurements()
{ {
ui->checkBoxHideEmpty->setEnabled(true); ui->checkBoxHideEmpty->setEnabled(true);
ShowMeasurements(m_data->DataMeasurements());
QList<QSharedPointer<VMeasurement>> vars = m_data->DataMeasurements().values();
std::stable_sort(vars.begin(), vars.end(),
[](const QSharedPointer<VMeasurement> &obj1, const QSharedPointer<VMeasurement> &obj2)
{ return obj1->Index() < obj2->Index(); });
ShowMeasurements(vars);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -332,21 +338,21 @@ void DialogEditWrongFormula::Measurements()
void DialogEditWrongFormula::LengthLines() void DialogEditWrongFormula::LengthLines()
{ {
ui->checkBoxHideEmpty->setEnabled(false); ui->checkBoxHideEmpty->setEnabled(false);
ShowVariable(m_data->DataLengthLines()); ShowVariable(m_data->DataLengthLines().values());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogEditWrongFormula::RadiusArcs() void DialogEditWrongFormula::RadiusArcs()
{ {
ui->checkBoxHideEmpty->setEnabled(false); ui->checkBoxHideEmpty->setEnabled(false);
ShowVariable(m_data->DataRadiusesArcs()); ShowVariable(m_data->DataRadiusesArcs().values());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogEditWrongFormula::AnglesCurves() void DialogEditWrongFormula::AnglesCurves()
{ {
ui->checkBoxHideEmpty->setEnabled(false); ui->checkBoxHideEmpty->setEnabled(false);
ShowVariable(m_data->DataAnglesCurves()); ShowVariable(m_data->DataAnglesCurves().values());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -356,21 +362,21 @@ void DialogEditWrongFormula::AnglesCurves()
void DialogEditWrongFormula::LengthCurves() void DialogEditWrongFormula::LengthCurves()
{ {
ui->checkBoxHideEmpty->setEnabled(false); ui->checkBoxHideEmpty->setEnabled(false);
ShowVariable(m_data->DataLengthCurves()); ShowVariable(m_data->DataLengthCurves().values());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogEditWrongFormula::CurvesCLength() void DialogEditWrongFormula::CurvesCLength()
{ {
ui->checkBoxHideEmpty->setEnabled(false); ui->checkBoxHideEmpty->setEnabled(false);
ShowVariable(m_data->DataCurvesCLength()); ShowVariable(m_data->DataCurvesCLength().values());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogEditWrongFormula::AngleLines() void DialogEditWrongFormula::AngleLines()
{ {
ui->checkBoxHideEmpty->setEnabled(false); ui->checkBoxHideEmpty->setEnabled(false);
ShowVariable(m_data->DataAngleLines()); ShowVariable(m_data->DataAngleLines().values());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -392,7 +398,7 @@ void DialogEditWrongFormula::PreviewCalculations()
void DialogEditWrongFormula::PieceArea() void DialogEditWrongFormula::PieceArea()
{ {
ui->checkBoxHideEmpty->setEnabled(false); 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 * @brief ShowVariable show variables in list
* @param var container with variables * @param vars container with variables
*/ */
template <class key, class val> void DialogEditWrongFormula::ShowVariable(const QMap<key, val> &var) template <class T> void DialogEditWrongFormula::ShowVariable(const QList<T> &vars)
{ {
ui->tableWidget->blockSignals(true); ui->tableWidget->blockSignals(true);
ui->tableWidget->clearContents(); ui->tableWidget->clearContents();
@ -639,24 +645,24 @@ template <class key, class val> void DialogEditWrongFormula::ShowVariable(const
ui->tableWidget->setColumnHidden(ColumnFullName, true); ui->tableWidget->setColumnHidden(ColumnFullName, true);
ui->labelDescription->setText(QString()); ui->labelDescription->setText(QString());
QMapIterator<key, val> iMap(var); for (const auto &var : vars)
while (iMap.hasNext())
{ {
iMap.next(); if (ui->checkBoxHideEmpty->isEnabled() && ui->checkBoxHideEmpty->isChecked() && var->IsNotUsed())
if (ui->checkBoxHideEmpty->isEnabled() && ui->checkBoxHideEmpty->isChecked() && iMap.value()->IsNotUsed())
{ {
continue; // skip this measurement continue; // skip this measurement
} }
if (iMap.value()->Filter(m_toolId) == false)
if (!var->Filter(m_toolId))
{ // If we create this variable don't show { // If we create this variable don't show
ui->tableWidget->setRowCount(ui->tableWidget->rowCount() + 1); ui->tableWidget->setRowCount(ui->tableWidget->rowCount() + 1);
auto *item = new QTableWidgetItem(iMap.key()); auto *item = new QTableWidgetItem(var->GetName());
QFont font = item->font(); QFont font = item->font();
font.setBold(true); font.setBold(true);
item->setFont(font); item->setFont(font);
ui->tableWidget->setItem(ui->tableWidget->rowCount() - 1, ColumnName, item); ui->tableWidget->setItem(ui->tableWidget->rowCount() - 1, ColumnName, item);
} }
} }
ui->tableWidget->blockSignals(false); ui->tableWidget->blockSignals(false);
ui->tableWidget->selectRow(0); ui->tableWidget->selectRow(0);
ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
@ -665,9 +671,9 @@ template <class key, class val> void DialogEditWrongFormula::ShowVariable(const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief ShowMeasurements show measurements in table * @brief ShowMeasurements show measurements in table
* @param var container with measurements * @param vars container with measurements
*/ */
void DialogEditWrongFormula::ShowMeasurements(const QMap<QString, QSharedPointer<VMeasurement>> &var) void DialogEditWrongFormula::ShowMeasurements(const QList<QSharedPointer<VMeasurement>> &vars)
{ {
ui->tableWidget->blockSignals(true); ui->tableWidget->blockSignals(true);
ui->tableWidget->clearContents(); ui->tableWidget->clearContents();
@ -675,18 +681,17 @@ void DialogEditWrongFormula::ShowMeasurements(const QMap<QString, QSharedPointer
ui->tableWidget->setColumnHidden(ColumnFullName, false); ui->tableWidget->setColumnHidden(ColumnFullName, false);
ui->labelDescription->setText(QString()); ui->labelDescription->setText(QString());
QMapIterator<QString, QSharedPointer<VMeasurement>> iMap(var); for (const auto &var : vars)
while (iMap.hasNext())
{ {
iMap.next(); if (ui->checkBoxHideEmpty->isEnabled() && ui->checkBoxHideEmpty->isChecked() && var->IsNotUsed())
if (ui->checkBoxHideEmpty->isEnabled() && ui->checkBoxHideEmpty->isChecked() && iMap.value()->IsNotUsed())
{ {
continue; // skip this measurement 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 { // If we create this variable don't show
ui->tableWidget->setRowCount(ui->tableWidget->rowCount() + 1); ui->tableWidget->setRowCount(ui->tableWidget->rowCount() + 1);
auto *itemName = new QTableWidgetItem(iMap.key()); auto *itemName = new QTableWidgetItem(var->GetName());
QFont fontName = itemName->font(); QFont fontName = itemName->font();
fontName.setBold(true); fontName.setBold(true);
itemName->setFont(fontName); itemName->setFont(fontName);
@ -696,13 +701,13 @@ void DialogEditWrongFormula::ShowMeasurements(const QMap<QString, QSharedPointer
QFont fontFullName = itemName->font(); QFont fontFullName = itemName->font();
fontFullName.setBold(true); fontFullName.setBold(true);
itemFullName->setFont(fontFullName); itemFullName->setFont(fontFullName);
if (iMap.value()->IsCustom()) if (var->IsCustom())
{ {
itemFullName->setText(iMap.value()->GetGuiText()); itemFullName->setText(var->GetGuiText());
} }
else else
{ {
itemFullName->setText(VAbstractApplication::VApp()->TrVars()->GuiText(iMap.value()->GetName())); itemFullName->setText(VAbstractApplication::VApp()->TrVars()->GuiText(var->GetName()));
} }
itemFullName->setToolTip(itemFullName->text()); itemFullName->setToolTip(itemFullName->text());
@ -710,6 +715,7 @@ void DialogEditWrongFormula::ShowMeasurements(const QMap<QString, QSharedPointer
ui->tableWidget->setItem(ui->tableWidget->rowCount() - 1, ColumnFullName, itemFullName); ui->tableWidget->setItem(ui->tableWidget->rowCount() - 1, ColumnFullName, itemFullName);
} }
} }
ui->tableWidget->blockSignals(false); ui->tableWidget->blockSignals(false);
ui->tableWidget->selectRow(0); ui->tableWidget->selectRow(0);
ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
@ -785,7 +791,12 @@ void DialogEditWrongFormula::ShowIncrementsInPreviewCalculation(bool show)
++i; ++i;
} }
ShowVariable(increments); QList<QSharedPointer<VIncrement>> vars = increments.values();
std::stable_sort(vars.begin(), vars.end(),
[](const QSharedPointer<VIncrement> &obj1, const QSharedPointer<VIncrement> &obj2)
{ return obj1->GetIndex() < obj2->GetIndex(); });
ShowVariable(vars);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -148,8 +148,8 @@ private:
void InitVariables(); void InitVariables();
template <class key, class val> void ShowVariable(const QMap<key, val> &var); template <class T> void ShowVariable(const QList<T> &vars);
void ShowMeasurements(const QMap<QString, QSharedPointer<VMeasurement>> &var); void ShowMeasurements(const QList<QSharedPointer<VMeasurement>> &vars);
void ShowFunctions(); void ShowFunctions();
void ShowIncrementsInPreviewCalculation(bool show); void ShowIncrementsInPreviewCalculation(bool show);

View File

@ -10,7 +10,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>542</width> <width>542</width>
<height>483</height> <height>512</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -95,7 +95,7 @@
<string>Insert variable into formula</string> <string>Insert variable into formula</string>
</property> </property>
<property name="text"> <property name="text">
<string notr="true"></string> <string notr="true"/>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../../../vmisc/share/resources/icon.qrc"> <iconset resource="../../../vmisc/share/resources/icon.qrc">
@ -363,6 +363,9 @@
<property name="cursor" stdset="0"> <property name="cursor" stdset="0">
<cursorShape>PointingHandCursor</cursorShape> <cursorShape>PointingHandCursor</cursorShape>
</property> </property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<column> <column>
<property name="text"> <property name="text">
<string>Name</string> <string>Name</string>