Refactoring.

This commit is contained in:
Roman Telezhynskyi 2022-08-23 21:04:23 +03:00
parent be07f701c7
commit 35eedc0a44
2 changed files with 73 additions and 73 deletions

View File

@ -55,28 +55,28 @@
DialogArcWithLength::DialogArcWithLength(const VContainer *data, quint32 toolId, QWidget *parent) DialogArcWithLength::DialogArcWithLength(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent), : DialogTool(data, toolId, parent),
ui(new Ui::DialogArcWithLength), ui(new Ui::DialogArcWithLength),
timerRadius(new QTimer(this)), m_timerRadius(new QTimer(this)),
timerF1(new QTimer(this)), m_timerF1(new QTimer(this)),
timerLength(new QTimer(this)) m_timerLength(new QTimer(this))
{ {
ui->setupUi(this); ui->setupUi(this);
this->formulaBaseHeightRadius = ui->plainTextEditRadius->height(); this->m_formulaBaseHeightRadius = ui->plainTextEditRadius->height();
this->formulaBaseHeightF1 = ui->plainTextEditF1->height(); this->m_formulaBaseHeightF1 = ui->plainTextEditF1->height();
this->formulaBaseHeightLength = ui->plainTextEditLength->height(); this->m_formulaBaseHeightLength = ui->plainTextEditLength->height();
ui->plainTextEditRadius->installEventFilter(this); ui->plainTextEditRadius->installEventFilter(this);
ui->plainTextEditF1->installEventFilter(this); ui->plainTextEditF1->installEventFilter(this);
ui->plainTextEditLength->installEventFilter(this); ui->plainTextEditLength->installEventFilter(this);
timerRadius->setSingleShot(true); m_timerRadius->setSingleShot(true);
connect(timerRadius, &QTimer::timeout, this, &DialogArcWithLength::Radius); connect(m_timerRadius, &QTimer::timeout, this, &DialogArcWithLength::Radius);
timerF1->setSingleShot(true); m_timerF1->setSingleShot(true);
connect(timerF1, &QTimer::timeout, this, &DialogArcWithLength::EvalF); connect(m_timerF1, &QTimer::timeout, this, &DialogArcWithLength::EvalF);
timerLength->setSingleShot(true); m_timerLength->setSingleShot(true);
connect(timerLength, &QTimer::timeout, this, &DialogArcWithLength::Length); connect(m_timerLength, &QTimer::timeout, this, &DialogArcWithLength::Length);
InitOkCancelApply(ui); InitOkCancelApply(ui);
@ -92,17 +92,17 @@ DialogArcWithLength::DialogArcWithLength(const VContainer *data, quint32 toolId,
connect(ui->plainTextEditRadius, &QPlainTextEdit::textChanged, this, [this]() connect(ui->plainTextEditRadius, &QPlainTextEdit::textChanged, this, [this]()
{ {
timerRadius->start(formulaTimerTimeout); m_timerRadius->start(formulaTimerTimeout);
}); });
connect(ui->plainTextEditF1, &QPlainTextEdit::textChanged, this, [this]() connect(ui->plainTextEditF1, &QPlainTextEdit::textChanged, this, [this]()
{ {
timerF1->start(formulaTimerTimeout); m_timerF1->start(formulaTimerTimeout);
}); });
connect(ui->plainTextEditLength, &QPlainTextEdit::textChanged, this, [this]() connect(ui->plainTextEditLength, &QPlainTextEdit::textChanged, this, [this]()
{ {
timerLength->start(formulaTimerTimeout); m_timerLength->start(formulaTimerTimeout);
}); });
connect(ui->pushButtonGrowLengthRadius, &QPushButton::clicked, this, &DialogArcWithLength::DeployRadiusTextEdit); connect(ui->pushButtonGrowLengthRadius, &QPushButton::clicked, this, &DialogArcWithLength::DeployRadiusTextEdit);
@ -141,24 +141,24 @@ void DialogArcWithLength::SetCenter(const quint32 &value)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto DialogArcWithLength::GetRadius() const -> QString auto DialogArcWithLength::GetRadius() const -> QString
{ {
return VTranslateVars::TryFormulaFromUser(radius, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); return VTranslateVars::TryFormulaFromUser(m_radius, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::SetRadius(const QString &value) void DialogArcWithLength::SetRadius(const QString &value)
{ {
radius = VAbstractApplication::VApp()->TrVars() m_radius = VAbstractApplication::VApp()->TrVars()
->FormulaToUser(value, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); ->FormulaToUser(value, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
// increase height if needed. // increase height if needed.
if (radius.length() > 80) if (m_radius.length() > 80)
{ {
this->DeployRadiusTextEdit(); this->DeployRadiusTextEdit();
} }
ui->plainTextEditRadius->setPlainText(radius); ui->plainTextEditRadius->setPlainText(m_radius);
auto *path = qobject_cast<VisToolArcWithLength *>(vis); auto *path = qobject_cast<VisToolArcWithLength *>(vis);
SCASSERT(path != nullptr) SCASSERT(path != nullptr)
path->SetRadius(radius); path->SetRadius(m_radius);
MoveCursorToEnd(ui->plainTextEditRadius); MoveCursorToEnd(ui->plainTextEditRadius);
} }
@ -166,24 +166,24 @@ void DialogArcWithLength::SetRadius(const QString &value)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto DialogArcWithLength::GetF1() const -> QString auto DialogArcWithLength::GetF1() const -> QString
{ {
return VTranslateVars::TryFormulaFromUser(f1, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); return VTranslateVars::TryFormulaFromUser(m_f1, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::SetF1(const QString &value) void DialogArcWithLength::SetF1(const QString &value)
{ {
f1 = VAbstractApplication::VApp()->TrVars() m_f1 = VAbstractApplication::VApp()->TrVars()
->FormulaToUser(value, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); ->FormulaToUser(value, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
// increase height if needed. // increase height if needed.
if (f1.length() > 80) if (m_f1.length() > 80)
{ {
this->DeployF1TextEdit(); this->DeployF1TextEdit();
} }
ui->plainTextEditF1->setPlainText(f1); ui->plainTextEditF1->setPlainText(m_f1);
auto *path = qobject_cast<VisToolArcWithLength *>(vis); auto *path = qobject_cast<VisToolArcWithLength *>(vis);
SCASSERT(path != nullptr) SCASSERT(path != nullptr)
path->SetF1(f1); path->SetF1(m_f1);
MoveCursorToEnd(ui->plainTextEditF1); MoveCursorToEnd(ui->plainTextEditF1);
} }
@ -191,24 +191,24 @@ void DialogArcWithLength::SetF1(const QString &value)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto DialogArcWithLength::GetLength() const -> QString auto DialogArcWithLength::GetLength() const -> QString
{ {
return VTranslateVars::TryFormulaFromUser(length, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); return VTranslateVars::TryFormulaFromUser(m_length, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::SetLength(const QString &value) void DialogArcWithLength::SetLength(const QString &value)
{ {
length = VAbstractApplication::VApp()->TrVars() m_length = VAbstractApplication::VApp()->TrVars()
->FormulaToUser(value, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); ->FormulaToUser(value, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
// increase height if needed. // increase height if needed.
if (length.length() > 80) if (m_length.length() > 80)
{ {
this->DeployLengthTextEdit(); this->DeployLengthTextEdit();
} }
ui->plainTextEditLength->setPlainText(length); ui->plainTextEditLength->setPlainText(m_length);
auto *path = qobject_cast<VisToolArcWithLength *>(vis); auto *path = qobject_cast<VisToolArcWithLength *>(vis);
SCASSERT(path != nullptr) SCASSERT(path != nullptr)
path->SetLength(length); path->SetLength(m_length);
MoveCursorToEnd(ui->plainTextEditLength); MoveCursorToEnd(ui->plainTextEditLength);
} }
@ -250,7 +250,7 @@ void DialogArcWithLength::SetApproximationScale(qreal value)
auto *path = qobject_cast<VisToolArcWithLength *>(vis); auto *path = qobject_cast<VisToolArcWithLength *>(vis);
SCASSERT(path != nullptr) SCASSERT(path != nullptr)
path->SetApproximationScale(value); path->SetApproximationScale(value);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -268,8 +268,8 @@ auto DialogArcWithLength::GetNotes() const -> QString
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::SetAliasSuffix(const QString &alias) void DialogArcWithLength::SetAliasSuffix(const QString &alias)
{ {
originAliasSuffix = alias; m_originAliasSuffix = alias;
ui->lineEditAlias->setText(originAliasSuffix); ui->lineEditAlias->setText(m_originAliasSuffix);
ValidateAlias(); ValidateAlias();
} }
@ -323,7 +323,7 @@ void DialogArcWithLength::ShowDialog(bool click)
return line.angle(); return line.angle();
}; };
if (stageRadius) if (m_stageRadius)
{ {
//Radius of point circle, but little bigger. Need handle with hover sizes. //Radius of point circle, but little bigger. Need handle with hover sizes.
if (line.length() <= ScaledRadius(SceneScale(VAbstractValApplication::VApp()->getCurrentScene()))*1.5) if (line.length() <= ScaledRadius(SceneScale(VAbstractValApplication::VApp()->getCurrentScene()))*1.5)
@ -334,21 +334,21 @@ void DialogArcWithLength::ShowDialog(bool click)
SetRadius(QString::number(VAbstractValApplication::VApp()->fromPixel(line.length()))); SetRadius(QString::number(VAbstractValApplication::VApp()->fromPixel(line.length())));
vis->RefreshGeometry(); vis->RefreshGeometry();
stageRadius = false; m_stageRadius = false;
stageF1 = true; m_stageF1 = true;
} }
else if (stageF1) else if (m_stageF1)
{ {
SetF1(QString::number(Angle())); SetF1(QString::number(Angle()));
vis->RefreshGeometry(); vis->RefreshGeometry();
stageF1 = false; m_stageF1 = false;
} }
else else
{ {
const qreal r = Visualization::FindLengthFromUser(radius, data->DataVariables()); const qreal r = Visualization::FindLengthFromUser(m_radius, data->DataVariables());
const qreal angle1 = Visualization::FindValFromUser(f1, data->DataVariables()); const qreal angle1 = Visualization::FindValFromUser(m_f1, data->DataVariables());
VArc arc(*point, r, angle1, line.angle()); VArc arc(*point, r, angle1, line.angle());
SetLength(QString::number(VAbstractValApplication::VApp()->fromPixel(arc.GetLength()))); SetLength(QString::number(VAbstractValApplication::VApp()->fromPixel(arc.GetLength())));
@ -392,19 +392,19 @@ void DialogArcWithLength::ChosenObject(quint32 id, const SceneObject &type)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::DeployRadiusTextEdit() void DialogArcWithLength::DeployRadiusTextEdit()
{ {
DeployFormula(this, ui->plainTextEditRadius, ui->pushButtonGrowLengthArcLength, formulaBaseHeightRadius); DeployFormula(this, ui->plainTextEditRadius, ui->pushButtonGrowLengthArcLength, m_formulaBaseHeightRadius);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::DeployF1TextEdit() void DialogArcWithLength::DeployF1TextEdit()
{ {
DeployFormula(this, ui->plainTextEditF1, ui->pushButtonGrowLengthF1, formulaBaseHeightF1); DeployFormula(this, ui->plainTextEditF1, ui->pushButtonGrowLengthF1, m_formulaBaseHeightF1);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::DeployLengthTextEdit() void DialogArcWithLength::DeployLengthTextEdit()
{ {
DeployFormula(this, ui->plainTextEditLength, ui->pushButtonGrowLengthArcLength, formulaBaseHeightLength); DeployFormula(this, ui->plainTextEditLength, ui->pushButtonGrowLengthArcLength, m_formulaBaseHeightLength);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -458,17 +458,17 @@ void DialogArcWithLength::ShowVisualization()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::SaveData() void DialogArcWithLength::SaveData()
{ {
radius = ui->plainTextEditRadius->toPlainText(); m_radius = ui->plainTextEditRadius->toPlainText();
f1 = ui->plainTextEditF1->toPlainText(); m_f1 = ui->plainTextEditF1->toPlainText();
length = ui->plainTextEditLength->toPlainText(); m_length = ui->plainTextEditLength->toPlainText();
auto *path = qobject_cast<VisToolArcWithLength *>(vis); auto *path = qobject_cast<VisToolArcWithLength *>(vis);
SCASSERT(path != nullptr) SCASSERT(path != nullptr)
path->SetCenterId(GetCenter()); path->SetCenterId(GetCenter());
path->SetRadius(radius); path->SetRadius(m_radius);
path->SetF1(f1); path->SetF1(m_f1);
path->SetLength(length); path->SetLength(m_length);
path->SetApproximationScale(ui->doubleSpinBoxApproximationScale->value()); path->SetApproximationScale(ui->doubleSpinBoxApproximationScale->value());
path->RefreshGeometry(); path->RefreshGeometry();
} }
@ -490,14 +490,14 @@ void DialogArcWithLength::ValidateAlias()
arc.SetAliasSuffix(GetAliasSuffix()); arc.SetAliasSuffix(GetAliasSuffix());
if (not GetAliasSuffix().isEmpty() && if (not GetAliasSuffix().isEmpty() &&
(not rx.match(arc.GetAlias()).hasMatch() || (not rx.match(arc.GetAlias()).hasMatch() ||
(originAliasSuffix != GetAliasSuffix() && not data->IsUnique(arc.GetAlias())))) (m_originAliasSuffix != GetAliasSuffix() && not data->IsUnique(arc.GetAlias()))))
{ {
flagAlias = false; m_flagAlias = false;
ChangeColor(ui->labelAlias, errorColor); ChangeColor(ui->labelAlias, errorColor);
} }
else else
{ {
flagAlias = true; m_flagAlias = true;
ChangeColor(ui->labelAlias, OkColor(this)); ChangeColor(ui->labelAlias, OkColor(this));
} }
@ -515,7 +515,7 @@ void DialogArcWithLength::Radius()
formulaData.postfix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true); formulaData.postfix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true);
formulaData.checkLessThanZero = true; formulaData.checkLessThanZero = true;
Eval(formulaData, flagRadius); Eval(formulaData, m_flagRadius);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -528,7 +528,7 @@ void DialogArcWithLength::Length()
formulaData.labelResult = ui->labelResultLength; formulaData.labelResult = ui->labelResultLength;
formulaData.postfix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true); formulaData.postfix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true);
Eval(formulaData, flagLength); Eval(formulaData, m_flagLength);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -542,5 +542,5 @@ void DialogArcWithLength::EvalF()
formulaData.postfix = degreeSymbol; formulaData.postfix = degreeSymbol;
formulaData.checkZero = false; formulaData.checkZero = false;
Eval(formulaData, flagF1); Eval(formulaData, m_flagF1);
} }

View File

@ -94,7 +94,7 @@ public slots:
void FXLength(); void FXLength();
protected: protected:
void ShowVisualization() override; void ShowVisualization() override;
/** /**
* @brief SaveData Put dialog data in local variables * @brief SaveData Put dialog data in local variables
*/ */
@ -110,40 +110,40 @@ private:
Ui::DialogArcWithLength *ui; Ui::DialogArcWithLength *ui;
/** @brief flagRadius true if value of radius is correct */ /** @brief flagRadius true if value of radius is correct */
bool flagRadius{false}; bool m_flagRadius{false};
/** @brief flagF1 true if value of first angle is correct */ /** @brief flagF1 true if value of first angle is correct */
bool flagF1{false}; bool m_flagF1{false};
bool flagLength{false}; bool m_flagLength{false};
bool flagAlias{true}; bool m_flagAlias{true};
/** @brief timerRadius timer of check formula of radius */ /** @brief timerRadius timer of check formula of radius */
QTimer *timerRadius; QTimer *m_timerRadius;
/** @brief timerF1 timer of check formula of first angle */ /** @brief timerF1 timer of check formula of first angle */
QTimer *timerF1; QTimer *m_timerF1;
QTimer *timerLength; QTimer *m_timerLength;
/** @brief radius formula of radius */ /** @brief radius formula of radius */
QString radius{}; QString m_radius{};
/** @brief f1 formula of first angle */ /** @brief f1 formula of first angle */
QString f1{}; QString m_f1{};
QString length{}; QString m_length{};
/** @brief formulaBaseHeight base height defined by dialogui */ /** @brief formulaBaseHeight base height defined by dialogui */
int formulaBaseHeightRadius{0}; int m_formulaBaseHeightRadius{0};
int formulaBaseHeightF1{0}; int m_formulaBaseHeightF1{0};
int formulaBaseHeightLength{0}; int m_formulaBaseHeightLength{0};
QString originAliasSuffix{}; QString m_originAliasSuffix{};
bool stageRadius{true}; bool m_stageRadius{true};
bool stageF1{false}; bool m_stageF1{false};
bool m_firstRelease{false}; bool m_firstRelease{false};
@ -155,7 +155,7 @@ private:
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
inline auto DialogArcWithLength::IsValid() const -> bool inline auto DialogArcWithLength::IsValid() const -> bool
{ {
return flagRadius && flagF1 && flagLength && flagAlias; return m_flagRadius && m_flagF1 && m_flagLength && m_flagAlias;
} }
#endif // DIALOGARCWITHLENGTH_H #endif // DIALOGARCWITHLENGTH_H