From 15978bd8681fb6e60a4627a3de1a0231ba9b7953 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 1 Oct 2020 19:06:20 +0300 Subject: [PATCH] Refactoring. Unify initialization and translation dimensions base value. --- src/app/tape/tmainwindow.cpp | 70 +++++++++++++----------------------- src/app/tape/tmainwindow.h | 3 +- 2 files changed, 26 insertions(+), 47 deletions(-) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index b596ba0ba..b3106a4f6 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -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 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 &importedNames) const { @@ -3362,39 +3375,6 @@ QString TMainWindow::DimensionName(MeasurementDimension type) } } -//--------------------------------------------------------------------------------------------------------------------- -void TMainWindow::RetranslateDimensionBaseValues() -{ - const QList 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) { diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index 316ad399c..de44cd2d3 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -210,6 +210,7 @@ private: template void HackWidget(T **widget); + void HackDimensionBaseValue(); QString CheckMName(const QString &name, const QSet &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