Refactoring.

This commit is contained in:
Roman Telezhynskyi 2023-11-07 11:28:47 +02:00
parent 32c10a4b39
commit 84cc3a1393
2 changed files with 55 additions and 40 deletions

View File

@ -202,27 +202,7 @@ void DialogEditWrongFormula::ValChanged(int row)
{ {
if (ui->radioButtonStandardTable->isChecked()) if (ui->radioButtonStandardTable->isChecked())
{ {
const QSharedPointer<VMeasurement> stable = m_data->GetVariable<VMeasurement>(name); SetMeasurementDescription(item, name);
QString description;
if (!stable->IsCustom())
{
if (VKnownMeasurementsDatabase *db = VAbstractApplication::VApp()->KnownMeasurementsDatabase())
{
VKnownMeasurements known = db->KnownMeasurements(stable->GetKnownMeasurementsId());
if (known.IsValid())
{
description = known.Measurement(stable->GetName()).description;
}
}
}
else
{
description = stable->GetDescription();
}
SetDescription(item->text(), *stable->GetValue(), stable->IsSpecialUnits(), description);
} }
else if (ui->radioButtonIncrements->isChecked() || ui->radioButtonPC->isChecked()) else if (ui->radioButtonIncrements->isChecked() || ui->radioButtonPC->isChecked())
{ {
@ -267,25 +247,7 @@ void DialogEditWrongFormula::ValChanged(int row)
} }
else if (ui->radioButtonPieceArea->isChecked()) else if (ui->radioButtonPieceArea->isChecked())
{ {
const bool specialUnits = false; SetPieceAreaDescription(item, name);
const QSharedPointer<VPieceArea> var = m_data->GetVariable<VPieceArea>(name);
QString description = tr("Area of piece");
try
{
VPiece piece = m_data->GetPiece(var->GetPieceId());
QString name = piece.GetName();
if (not name.isEmpty())
{
description += QStringLiteral(" '%1'").arg(piece.GetName());
}
}
catch (const VExceptionBadId &)
{
// do nothing
}
SetDescription(item->text(), *var->GetValue(), specialUnits, description, true);
} }
else if (ui->radioButtonFunctions->isChecked()) else if (ui->radioButtonFunctions->isChecked())
{ {
@ -829,6 +791,56 @@ void DialogEditWrongFormula::ShowIncrementsInPreviewCalculation(bool show)
ShowVariable(vars); ShowVariable(vars);
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogEditWrongFormula::SetMeasurementDescription(QTableWidgetItem *item, const QString &name)
{
const QSharedPointer<VMeasurement> stable = m_data->GetVariable<VMeasurement>(name);
QString description;
if (!stable->IsCustom())
{
if (VKnownMeasurementsDatabase *db = VAbstractApplication::VApp()->KnownMeasurementsDatabase())
{
VKnownMeasurements known = db->KnownMeasurements(stable->GetKnownMeasurementsId());
if (known.IsValid())
{
description = known.Measurement(stable->GetName()).description;
}
}
}
else
{
description = stable->GetDescription();
}
SetDescription(item->text(), *stable->GetValue(), stable->IsSpecialUnits(), description);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEditWrongFormula::SetPieceAreaDescription(QTableWidgetItem *item, const QString &name)
{
const bool specialUnits = false;
const QSharedPointer<VPieceArea> var = m_data->GetVariable<VPieceArea>(name);
QString description = tr("Area of piece");
try
{
VPiece piece = m_data->GetPiece(var->GetPieceId());
QString name = piece.GetName();
if (not name.isEmpty())
{
description += QStringLiteral(" '%1'").arg(piece.GetName());
}
}
catch (const VExceptionBadId &)
{
// do nothing
}
SetDescription(item->text(), *var->GetValue(), specialUnits, description, true);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogEditWrongFormula::FilterVariablesEdited(const QString &filter) void DialogEditWrongFormula::FilterVariablesEdited(const QString &filter)
{ {

View File

@ -153,6 +153,9 @@ private:
void ShowFunctions(); void ShowFunctions();
void ShowIncrementsInPreviewCalculation(bool show); void ShowIncrementsInPreviewCalculation(bool show);
void SetMeasurementDescription(QTableWidgetItem *item, const QString &name);
void SetPieceAreaDescription(QTableWidgetItem *item, const QString &name);
void SetDescription(const QString &name, qreal value, bool specialUnits, const QString &description, void SetDescription(const QString &name, qreal value, bool specialUnits, const QString &description,
bool square = false); bool square = false);