Refactoring.

This commit is contained in:
Roman Telezhynskyi 2022-07-20 08:29:59 +03:00
parent 672278209d
commit 22d21a867a
2 changed files with 35 additions and 29 deletions

View File

@ -405,6 +405,37 @@ void DialogSetupMultisize::ZDimensionBodyMeasurementChanged()
CheckState();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSetupMultisize::CheckDimension(QGroupBox *group, QGroupBox *nameGroup, QLineEdit *lineEdit,
bool &dimensionValid, int &dimensions,
const MeasurementDimension_p &dimension)
{
SCASSERT(group != nullptr)
SCASSERT(nameGroup != nullptr)
SCASSERT(lineEdit != nullptr)
if (group->isChecked())
{
dimensionValid = dimension->IsValid();
++dimensions;
if (ui->labelError->text().isEmpty() && not dimensionValid)
{
ui->labelError->setText(tr("Please, provide correct data for dimension %1").arg(dimension->Axis()));
return;
}
if (nameGroup->isChecked() && lineEdit->text().isEmpty())
{
if (ui->labelError->text().isEmpty())
{
ui->labelError->setText(tr("Please, provide custom name for dimension %1").arg(dimension->Axis()));
return;
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSetupMultisize::CheckState()
{
@ -417,35 +448,6 @@ void DialogSetupMultisize::CheckState()
int dimensions = 0;
auto CheckDimension = [this](QGroupBox *group, QGroupBox *nameGroup, QLineEdit *lineEdit, bool &dimensionValid,
int &dimensions, const MeasurementDimension_p &dimension)
{
SCASSERT(group != nullptr)
SCASSERT(nameGroup != nullptr)
SCASSERT(lineEdit != nullptr)
if (group->isChecked())
{
dimensionValid = dimension->IsValid();
++dimensions;
if (ui->labelError->text().isEmpty() && not dimensionValid)
{
ui->labelError->setText(tr("Please, provide correct data for dimension %1").arg(dimension->Axis()));
return;
}
if (nameGroup->isChecked() && lineEdit->text().isEmpty())
{
if (ui->labelError->text().isEmpty())
{
ui->labelError->setText(tr("Please, provide custom name for dimension %1").arg(dimension->Axis()));
return;
}
}
}
};
CheckDimension(ui->groupBoxXDimension, ui->groupBoxCustomXDimensionName, ui->lineEditCustomXDimensionName,
xDimensionValid, dimensions, m_xDimension);
CheckDimension(ui->groupBoxYDimension, ui->groupBoxCustomYDimensionName, ui->lineEditCustomYDimensionName,

View File

@ -38,6 +38,8 @@
#endif // QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
class QDoubleSpinBox;
class QGroupBox;
class QLineEdit;
namespace Ui
{
@ -76,6 +78,8 @@ private:
QSharedPointer<VWMeasurementDimension> m_wDimension;
QSharedPointer<VZMeasurementDimension> m_zDimension;
void CheckDimension(QGroupBox *group, QGroupBox *nameGroup, QLineEdit *lineEdit, bool &dimensionValid,
int &dimensions, const MeasurementDimension_p &dimension);
void CheckState();
void InitDimensionMinMax(QDoubleSpinBox *doubleSpinBoxMinValue, QDoubleSpinBox *doubleSpinBoxMaxValue,