Refactoring.

This commit is contained in:
Roman Telezhynskyi 2022-08-24 11:06:19 +03:00
parent 8a94ed2645
commit cdc291a40f
3 changed files with 125 additions and 129 deletions

View File

@ -61,24 +61,18 @@
DialogPointOfContact::DialogPointOfContact(const VContainer *data, quint32 toolId, QWidget *parent) DialogPointOfContact::DialogPointOfContact(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent), : DialogTool(data, toolId, parent),
ui(new Ui::DialogPointOfContact), ui(new Ui::DialogPointOfContact),
radius(), m_timerFormula(new QTimer(this))
formulaBaseHeight(0),
pointName(),
timerFormula(new QTimer(this)),
flagFormula(false),
flagName(true),
flagError(true)
{ {
ui->setupUi(this); ui->setupUi(this);
timerFormula->setSingleShot(true); m_timerFormula->setSingleShot(true);
connect(timerFormula, &QTimer::timeout, this, &DialogPointOfContact::EvalFormula); connect(m_timerFormula, &QTimer::timeout, this, &DialogPointOfContact::EvalFormula);
ui->lineEditNamePoint->setClearButtonEnabled(true); ui->lineEditNamePoint->setClearButtonEnabled(true);
ui->lineEditNamePoint->setText( ui->lineEditNamePoint->setText(
VAbstractValApplication::VApp()->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); VAbstractValApplication::VApp()->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
this->formulaBaseHeight = ui->plainTextEditFormula->height(); this->m_formulaBaseHeight = ui->plainTextEditFormula->height();
ui->plainTextEditFormula->installEventFilter(this); ui->plainTextEditFormula->installEventFilter(this);
InitOkCancelApply(ui); InitOkCancelApply(ui);
@ -90,12 +84,12 @@ DialogPointOfContact::DialogPointOfContact(const VContainer *data, quint32 toolI
connect(ui->toolButtonExprRadius, &QPushButton::clicked, this, &DialogPointOfContact::FXRadius); connect(ui->toolButtonExprRadius, &QPushButton::clicked, this, &DialogPointOfContact::FXRadius);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, [this]() connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, [this]()
{ {
CheckPointLabel(this, ui->lineEditNamePoint, ui->labelEditNamePoint, pointName, this->data, flagName); CheckPointLabel(this, ui->lineEditNamePoint, ui->labelEditNamePoint, m_pointName, this->data, m_flagName);
CheckState(); CheckState();
}); });
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, [this]() connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, [this]()
{ {
timerFormula->start(formulaTimerTimeout); m_timerFormula->start(formulaTimerTimeout);
}); });
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogPointOfContact::DeployFormulaTextEdit); connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogPointOfContact::DeployFormulaTextEdit);
connect(ui->comboBoxFirstPoint, &QComboBox::currentTextChanged, connect(ui->comboBoxFirstPoint, &QComboBox::currentTextChanged,
@ -118,9 +112,9 @@ DialogPointOfContact::~DialogPointOfContact()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogPointOfContact::GetPointName() const auto DialogPointOfContact::GetPointName() const -> QString
{ {
return pointName; return m_pointName;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -134,12 +128,12 @@ void DialogPointOfContact::PointNameChanged()
QColor color; QColor color;
if (set.size() != 3) if (set.size() != 3)
{ {
flagError = false; m_flagError = false;
color = errorColor; color = errorColor;
} }
else else
{ {
flagError = true; m_flagError = true;
color = OkColor(this); color = OkColor(this);
} }
ChangeColor(ui->labelFirstPoint, color); ChangeColor(ui->labelFirstPoint, color);
@ -151,13 +145,13 @@ void DialogPointOfContact::PointNameChanged()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogPointOfContact::FXRadius() void DialogPointOfContact::FXRadius()
{ {
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); auto *dialog = new DialogEditWrongFormula(data, toolId, this);
dialog->setWindowTitle(tr("Edit radius")); dialog->setWindowTitle(tr("Edit radius"));
dialog->SetFormula(getRadius()); dialog->SetFormula(GetRadius());
dialog->setPostfix(UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true)); dialog->setPostfix(UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true));
if (dialog->exec() == QDialog::Accepted) if (dialog->exec() == QDialog::Accepted)
{ {
setRadius(dialog->GetFormula()); SetRadius(dialog->GetFormula());
} }
delete dialog; delete dialog;
} }
@ -172,7 +166,7 @@ void DialogPointOfContact::EvalFormula()
formulaData.labelResult = ui->labelResultCalculation; formulaData.labelResult = ui->labelResultCalculation;
formulaData.postfix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true); formulaData.postfix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true);
Eval(formulaData, flagFormula); Eval(formulaData, m_flagFormula);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -184,7 +178,7 @@ void DialogPointOfContact::ShowVisualization()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogPointOfContact::DeployFormulaTextEdit() void DialogPointOfContact::DeployFormulaTextEdit()
{ {
DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight); DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLength, m_formulaBaseHeight);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -219,11 +213,11 @@ void DialogPointOfContact::ShowDialog(bool click)
auto *scene = qobject_cast<VMainGraphicsScene *>(VAbstractValApplication::VApp()->getCurrentScene()); auto *scene = qobject_cast<VMainGraphicsScene *>(VAbstractValApplication::VApp()->getCurrentScene());
SCASSERT(scene != nullptr) SCASSERT(scene != nullptr)
const QSharedPointer<VPointF> center = data->GeometricObject<VPointF>(getCenter()); const QSharedPointer<VPointF> center = data->GeometricObject<VPointF>(GetCenter());
QLineF line(static_cast<QPointF>(*center), scene->getScenePos()); QLineF line(static_cast<QPointF>(*center), scene->getScenePos());
setRadius(QString::number(FromPixel(line.length(), *data->GetPatternUnit()))); SetRadius(QString::number(FromPixel(line.length(), *data->GetPatternUnit())));
FinishCreating(); FinishCreating();
} }
@ -244,17 +238,20 @@ void DialogPointOfContact::ChosenObject(quint32 id, const SceneObject &type)
return; return;
} }
if (type == SceneObject::Point) if (type != SceneObject::Point)
{ {
VisToolPointOfContact *line = qobject_cast<VisToolPointOfContact *>(vis); return;
}
auto *line = qobject_cast<VisToolPointOfContact *>(vis);
SCASSERT(line != nullptr) SCASSERT(line != nullptr)
switch (number) switch (m_number)
{ {
case 0: case 0:
if (SetObject(id, ui->comboBoxFirstPoint, tr("Select second point of line"))) if (SetObject(id, ui->comboBoxFirstPoint, tr("Select second point of line")))
{ {
number++; m_number++;
line->VisualMode(id); line->VisualMode(id);
} }
break; break;
@ -263,7 +260,7 @@ void DialogPointOfContact::ChosenObject(quint32 id, const SceneObject &type)
{ {
if (SetObject(id, ui->comboBoxSecondPoint, tr("Select point of center of arc"))) if (SetObject(id, ui->comboBoxSecondPoint, tr("Select point of center of arc")))
{ {
number++; m_number++;
line->SetLineP2Id(id); line->SetLineP2Id(id);
line->RefreshGeometry(); line->RefreshGeometry();
} }
@ -295,22 +292,21 @@ void DialogPointOfContact::ChosenObject(quint32 id, const SceneObject &type)
default: default:
break; break;
} }
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogPointOfContact::SaveData() void DialogPointOfContact::SaveData()
{ {
pointName = ui->lineEditNamePoint->text(); m_pointName = ui->lineEditNamePoint->text();
radius = ui->plainTextEditFormula->toPlainText(); m_radius = ui->plainTextEditFormula->toPlainText();
VisToolPointOfContact *line = qobject_cast<VisToolPointOfContact *>(vis); auto *line = qobject_cast<VisToolPointOfContact *>(vis);
SCASSERT(line != nullptr) SCASSERT(line != nullptr)
line->SetLineP1Id(GetFirstPoint()); line->SetLineP1Id(GetFirstPoint());
line->SetLineP2Id(GetSecondPoint()); line->SetLineP2Id(GetSecondPoint());
line->SetRadiusId(getCenter()); line->SetRadiusId(GetCenter());
line->SetRadius(radius); line->SetRadius(m_radius);
line->RefreshGeometry(); line->RefreshGeometry();
} }
@ -330,7 +326,7 @@ void DialogPointOfContact::SetSecondPoint(quint32 value)
{ {
setCurrentPointId(ui->comboBoxSecondPoint, value); setCurrentPointId(ui->comboBoxSecondPoint, value);
VisToolPointOfContact *line = qobject_cast<VisToolPointOfContact *>(vis); auto *line = qobject_cast<VisToolPointOfContact *>(vis);
SCASSERT(line != nullptr) SCASSERT(line != nullptr)
line->SetLineP2Id(value); line->SetLineP2Id(value);
} }
@ -344,7 +340,7 @@ void DialogPointOfContact::SetFirstPoint(quint32 value)
{ {
setCurrentPointId(ui->comboBoxFirstPoint, value); setCurrentPointId(ui->comboBoxFirstPoint, value);
VisToolPointOfContact *line = qobject_cast<VisToolPointOfContact *>(vis); auto *line = qobject_cast<VisToolPointOfContact *>(vis);
SCASSERT(line != nullptr) SCASSERT(line != nullptr)
line->SetLineP1Id(value); line->SetLineP1Id(value);
} }
@ -354,11 +350,11 @@ void DialogPointOfContact::SetFirstPoint(quint32 value)
* @brief SetCenter set id of center point * @brief SetCenter set id of center point
* @param value id * @param value id
*/ */
void DialogPointOfContact::setCenter(quint32 value) void DialogPointOfContact::SetCenter(quint32 value)
{ {
setCurrentPointId(ui->comboBoxCenter, value); setCurrentPointId(ui->comboBoxCenter, value);
VisToolPointOfContact *line = qobject_cast<VisToolPointOfContact *>(vis); auto *line = qobject_cast<VisToolPointOfContact *>(vis);
SCASSERT(line != nullptr) SCASSERT(line != nullptr)
line->SetRadiusId(value); line->SetRadiusId(value);
} }
@ -368,20 +364,20 @@ void DialogPointOfContact::setCenter(quint32 value)
* @brief setRadius set formula radius of arc * @brief setRadius set formula radius of arc
* @param value formula * @param value formula
*/ */
void DialogPointOfContact::setRadius(const QString &value) void DialogPointOfContact::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->DeployFormulaTextEdit(); this->DeployFormulaTextEdit();
} }
ui->plainTextEditFormula->setPlainText(radius); ui->plainTextEditFormula->setPlainText(m_radius);
VisToolPointOfContact *line = qobject_cast<VisToolPointOfContact *>(vis); auto *line = qobject_cast<VisToolPointOfContact *>(vis);
SCASSERT(line != nullptr) SCASSERT(line != nullptr)
line->SetRadius(radius); line->SetRadius(m_radius);
MoveCursorToEnd(ui->plainTextEditFormula); MoveCursorToEnd(ui->plainTextEditFormula);
} }
@ -393,8 +389,8 @@ void DialogPointOfContact::setRadius(const QString &value)
*/ */
void DialogPointOfContact::SetPointName(const QString &value) void DialogPointOfContact::SetPointName(const QString &value)
{ {
pointName = value; m_pointName = value;
ui->lineEditNamePoint->setText(pointName); ui->lineEditNamePoint->setText(m_pointName);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -402,9 +398,9 @@ void DialogPointOfContact::SetPointName(const QString &value)
* @brief getRadius return formula radius of arc * @brief getRadius return formula radius of arc
* @return formula * @return formula
*/ */
QString DialogPointOfContact::getRadius() const auto DialogPointOfContact::GetRadius() const -> QString
{ {
return VTranslateVars::TryFormulaFromUser(radius, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); return VTranslateVars::TryFormulaFromUser(m_radius, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -412,7 +408,7 @@ QString DialogPointOfContact::getRadius() const
* @brief GetCenter return id of center point * @brief GetCenter return id of center point
* @return id * @return id
*/ */
quint32 DialogPointOfContact::getCenter() const auto DialogPointOfContact::GetCenter() const -> quint32
{ {
return getCurrentObjectId(ui->comboBoxCenter); return getCurrentObjectId(ui->comboBoxCenter);
} }
@ -422,7 +418,7 @@ quint32 DialogPointOfContact::getCenter() const
* @brief GetFirstPoint return id first point * @brief GetFirstPoint return id first point
* @return id * @return id
*/ */
quint32 DialogPointOfContact::GetFirstPoint() const auto DialogPointOfContact::GetFirstPoint() const -> quint32
{ {
return getCurrentObjectId(ui->comboBoxFirstPoint); return getCurrentObjectId(ui->comboBoxFirstPoint);
} }
@ -432,7 +428,7 @@ quint32 DialogPointOfContact::GetFirstPoint() const
* @brief GetSecondPoint return id second point * @brief GetSecondPoint return id second point
* @return id * @return id
*/ */
quint32 DialogPointOfContact::GetSecondPoint() const auto DialogPointOfContact::GetSecondPoint() const -> quint32
{ {
return getCurrentObjectId(ui->comboBoxSecondPoint); return getCurrentObjectId(ui->comboBoxSecondPoint);
} }
@ -444,7 +440,7 @@ void DialogPointOfContact::SetNotes(const QString &notes)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogPointOfContact::GetNotes() const auto DialogPointOfContact::GetNotes() const -> QString
{ {
return ui->plainTextEditToolNotes->toPlainText(); return ui->plainTextEditToolNotes->toPlainText();
} }

View File

@ -52,44 +52,44 @@ class DialogPointOfContact : public DialogTool
Q_OBJECT // NOLINT Q_OBJECT // NOLINT
public: public:
DialogPointOfContact(const VContainer *data, quint32 toolId, QWidget *parent = nullptr); DialogPointOfContact(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogPointOfContact() override; ~DialogPointOfContact() override;
QString GetPointName() const; auto GetPointName() const -> QString;
void SetPointName(const QString &value); void SetPointName(const QString &value);
QString getRadius() const; auto GetRadius() const -> QString;
void setRadius(const QString &value); void SetRadius(const QString &value);
quint32 getCenter() const; auto GetCenter() const -> quint32;
void setCenter(quint32 value); void SetCenter(quint32 value);
quint32 GetFirstPoint() const; auto GetFirstPoint() const -> quint32;
void SetFirstPoint(quint32 value); void SetFirstPoint(quint32 value);
quint32 GetSecondPoint() const; auto GetSecondPoint() const -> quint32;
void SetSecondPoint(quint32 value); void SetSecondPoint(quint32 value);
void SetNotes(const QString &notes); void SetNotes(const QString &notes);
QString GetNotes() const; auto GetNotes() const -> QString;
void ShowDialog(bool click) override; void ShowDialog(bool click) override;
public slots: public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) override; void ChosenObject(quint32 id, const SceneObject &type) override;
/** /**
* @brief DeployFormulaTextEdit grow or shrink formula input * @brief DeployFormulaTextEdit grow or shrink formula input
*/ */
void DeployFormulaTextEdit(); void DeployFormulaTextEdit();
virtual void PointNameChanged() override; void PointNameChanged() override;
void FXRadius(); void FXRadius();
void EvalFormula(); void EvalFormula();
protected: protected:
virtual void ShowVisualization() override; void ShowVisualization() override;
/** /**
* @brief SaveData Put dialog data in local variables * @brief SaveData Put dialog data in local variables
*/ */
virtual void SaveData() override; void SaveData() override;
virtual void closeEvent(QCloseEvent *event) override; void closeEvent(QCloseEvent *event) override;
virtual bool IsValid() const final; auto IsValid() const -> bool final;
private: private:
Q_DISABLE_COPY_MOVE(DialogPointOfContact) // NOLINT Q_DISABLE_COPY_MOVE(DialogPointOfContact) // NOLINT
@ -97,29 +97,29 @@ private:
Ui::DialogPointOfContact *ui; Ui::DialogPointOfContact *ui;
/** @brief radius radius of arc */ /** @brief radius radius of arc */
QString radius; QString m_radius{};
/** @brief formulaBaseHeight base height defined by dialogui */ /** @brief formulaBaseHeight base height defined by dialogui */
int formulaBaseHeight; int m_formulaBaseHeight{0};
QString pointName; QString m_pointName{};
QTimer *timerFormula; QTimer *m_timerFormula;
bool flagFormula; bool m_flagFormula{false};
bool flagName; bool m_flagName{true};
bool flagError; bool m_flagError{true};
/** @brief number number of handled objects */ /** @brief number number of handled objects */
qint32 number{0}; qint32 m_number{0};
bool m_firstRelease{false}; bool m_firstRelease{false};
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
inline bool DialogPointOfContact::IsValid() const inline auto DialogPointOfContact::IsValid() const -> bool
{ {
return flagFormula && flagName && flagError; return m_flagFormula && m_flagName && m_flagError;
} }
#endif // DIALOGPOINTOFCONTACT_H #endif // DIALOGPOINTOFCONTACT_H

View File

@ -87,8 +87,8 @@ void VToolPointOfContact::setDialog()
const QPointer<DialogPointOfContact> dialogTool = qobject_cast<DialogPointOfContact *>(m_dialog); const QPointer<DialogPointOfContact> dialogTool = qobject_cast<DialogPointOfContact *>(m_dialog);
SCASSERT(not dialogTool.isNull()) SCASSERT(not dialogTool.isNull())
const QSharedPointer<VPointF> p = VAbstractTool::data.GeometricObject<VPointF>(m_id); const QSharedPointer<VPointF> p = VAbstractTool::data.GeometricObject<VPointF>(m_id);
dialogTool->setRadius(arcRadius); dialogTool->SetRadius(arcRadius);
dialogTool->setCenter(center); dialogTool->SetCenter(center);
dialogTool->SetFirstPoint(firstPointId); dialogTool->SetFirstPoint(firstPointId);
dialogTool->SetSecondPoint(secondPointId); dialogTool->SetSecondPoint(secondPointId);
dialogTool->SetPointName(p->name()); dialogTool->SetPointName(p->name());
@ -175,8 +175,8 @@ VToolPointOfContact* VToolPointOfContact::Create(const QPointer<DialogTool> &dia
SCASSERT(not dialogTool.isNull()) SCASSERT(not dialogTool.isNull())
VToolPointOfContactInitData initData; VToolPointOfContactInitData initData;
initData.radius = dialogTool->getRadius(); initData.radius = dialogTool->GetRadius();
initData.center = dialogTool->getCenter(); initData.center = dialogTool->GetCenter();
initData.firstPointId = dialogTool->GetFirstPoint(); initData.firstPointId = dialogTool->GetFirstPoint();
initData.secondPointId = dialogTool->GetSecondPoint(); initData.secondPointId = dialogTool->GetSecondPoint();
initData.name = dialogTool->GetPointName(); initData.name = dialogTool->GetPointName();
@ -307,13 +307,13 @@ void VToolPointOfContact::SaveDialog(QDomElement &domElement, QList<quint32> &ol
AddDependence(oldDependencies, center); AddDependence(oldDependencies, center);
AddDependence(oldDependencies, firstPointId); AddDependence(oldDependencies, firstPointId);
AddDependence(oldDependencies, secondPointId); AddDependence(oldDependencies, secondPointId);
AddDependence(newDependencies, dialogTool->getCenter()); AddDependence(newDependencies, dialogTool->GetCenter());
AddDependence(newDependencies, dialogTool->GetFirstPoint()); AddDependence(newDependencies, dialogTool->GetFirstPoint());
AddDependence(newDependencies, dialogTool->GetSecondPoint()); AddDependence(newDependencies, dialogTool->GetSecondPoint());
doc->SetAttribute(domElement, AttrName, dialogTool->GetPointName()); doc->SetAttribute(domElement, AttrName, dialogTool->GetPointName());
doc->SetAttribute(domElement, AttrRadius, dialogTool->getRadius()); doc->SetAttribute(domElement, AttrRadius, dialogTool->GetRadius());
doc->SetAttribute(domElement, AttrCenter, QString().setNum(dialogTool->getCenter())); doc->SetAttribute(domElement, AttrCenter, QString().setNum(dialogTool->GetCenter()));
doc->SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->GetFirstPoint())); doc->SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->GetFirstPoint()));
doc->SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->GetSecondPoint())); doc->SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->GetSecondPoint()));
doc->SetAttributeOrRemoveIf<QString>(domElement, AttrNotes, dialogTool->GetNotes(), doc->SetAttributeOrRemoveIf<QString>(domElement, AttrNotes, dialogTool->GetNotes(),