Refactoring.
Unify initialization and translation dimensions base value.
This commit is contained in:
parent
1ffbc0a720
commit
15978bd868
|
@ -563,7 +563,7 @@ void TMainWindow::changeEvent(QEvent *event)
|
|||
{
|
||||
ui->labelMType->setText(tr("Multisize measurements"));
|
||||
|
||||
RetranslateDimensionBaseValues();
|
||||
InitDimensionsBaseValue();
|
||||
|
||||
labelGradationHeights->setText(tr("Height (%1):").arg(UnitsToStr(mUnit)));
|
||||
labelGradationSizes->setText(tr("Size (%1):").arg(UnitsToStr(mUnit)));
|
||||
|
@ -2025,6 +2025,7 @@ void TMainWindow::InitWindow()
|
|||
ui->labelMType->setText(tr("Multisize measurements"));
|
||||
|
||||
InitDimensionsBaseValue();
|
||||
HackDimensionBaseValue();
|
||||
|
||||
// Because Qt Designer doesn't know about our deleting we will create empty objects for correct
|
||||
// working the retranslation UI
|
||||
|
@ -2087,12 +2088,7 @@ void TMainWindow::InitWindow()
|
|||
HackWidget(&ui->labelInHeights);
|
||||
|
||||
// Tab Information
|
||||
HackWidget(&ui->labelDimensionA);
|
||||
HackWidget(&ui->labelDimensionABase);
|
||||
HackWidget(&ui->labelDimensionB);
|
||||
HackWidget(&ui->labelDimensionBBase);
|
||||
HackWidget(&ui->labelDimensionC);
|
||||
HackWidget(&ui->labelDimensionCBase);
|
||||
HackDimensionBaseValue();
|
||||
HackWidget(&ui->frameBaseValue);
|
||||
HackWidget(&ui->labelBaseValues);
|
||||
|
||||
|
@ -2205,11 +2201,6 @@ void TMainWindow::InitDimensionsBaseValue()
|
|||
base->setText(QString::number(dimension->BaseValue()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
HackWidget(&name);
|
||||
HackWidget(&base);
|
||||
}
|
||||
};
|
||||
|
||||
DimensionsBaseValue(0, ui->labelDimensionA, ui->labelDimensionABase);
|
||||
|
@ -3068,6 +3059,28 @@ bool TMainWindow::IgnoreLocking(int error, const QString &path)
|
|||
return true;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TMainWindow::HackDimensionBaseValue()
|
||||
{
|
||||
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
|
||||
|
||||
auto DimensionsBaseValue = [this, dimensions](int index, QLabel *name, QLabel *base)
|
||||
{
|
||||
SCASSERT(name != nullptr)
|
||||
SCASSERT(base != nullptr)
|
||||
|
||||
if (dimensions.size() <= index)
|
||||
{
|
||||
HackWidget(&name);
|
||||
HackWidget(&base);
|
||||
}
|
||||
};
|
||||
|
||||
DimensionsBaseValue(0, ui->labelDimensionA, ui->labelDimensionABase);
|
||||
DimensionsBaseValue(1, ui->labelDimensionB, ui->labelDimensionBBase);
|
||||
DimensionsBaseValue(2, ui->labelDimensionC, ui->labelDimensionCBase);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString TMainWindow::CheckMName(const QString &name, const QSet<QString> &importedNames) const
|
||||
{
|
||||
|
@ -3362,39 +3375,6 @@ QString TMainWindow::DimensionName(MeasurementDimension type)
|
|||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TMainWindow::RetranslateDimensionBaseValues()
|
||||
{
|
||||
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
|
||||
const QString unit = UnitsToStr(m->MUnit(), true);
|
||||
|
||||
auto DimensionsBaseValue = [this, dimensions, unit](int index, QLabel *name, QLabel *base)
|
||||
{
|
||||
SCASSERT(name != nullptr)
|
||||
SCASSERT(base != nullptr)
|
||||
|
||||
if (dimensions.size() > index)
|
||||
{
|
||||
MeasurementDimension_p dimension = dimensions.at(index);
|
||||
name->setText(DimensionName(dimension->Type())+QChar(':'));
|
||||
name->setToolTip(DimensionToolTip(dimension->Type(), dimension->IsCircumference()));
|
||||
|
||||
if (dimension->IsCircumference())
|
||||
{
|
||||
base->setText(QString("%1 %2").arg(dimension->BaseValue()).arg(unit));
|
||||
}
|
||||
else
|
||||
{
|
||||
base->setText(QString::number(dimension->BaseValue()));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
DimensionsBaseValue(0, ui->labelDimensionA, ui->labelDimensionABase);
|
||||
DimensionsBaseValue(1, ui->labelDimensionC, ui->labelDimensionCBase);
|
||||
DimensionsBaseValue(2, ui->labelDimensionB, ui->labelDimensionBBase);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString TMainWindow::DimensionToolTip(MeasurementDimension type, bool circumference)
|
||||
{
|
||||
|
|
|
@ -210,6 +210,7 @@ private:
|
|||
|
||||
template <class T>
|
||||
void HackWidget(T **widget);
|
||||
void HackDimensionBaseValue();
|
||||
|
||||
QString CheckMName(const QString &name, const QSet<QString> &importedNames) const;
|
||||
void ShowError(const QString &text);
|
||||
|
@ -222,8 +223,6 @@ private:
|
|||
|
||||
QString DimensionName(MeasurementDimension type);
|
||||
QString DimensionToolTip(MeasurementDimension type, bool circumference);
|
||||
|
||||
void RetranslateDimensionBaseValues();
|
||||
};
|
||||
|
||||
#endif // TMAINWINDOW_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user