Refactoring.

This commit is contained in:
Roman Telezhynskyi 2022-08-19 11:19:55 +03:00
parent 714a4e1715
commit 9a28166539
2 changed files with 109 additions and 115 deletions

View File

@ -45,7 +45,6 @@
#include "../../visualization/line/vistoolalongline.h" #include "../../visualization/line/vistoolalongline.h"
#include "../../visualization/visualization.h" #include "../../visualization/visualization.h"
#include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vabstractpattern.h"
#include "../ifc/xml/vdomdocument.h"
#include "../support/dialogeditwrongformula.h" #include "../support/dialogeditwrongformula.h"
#include "../vgeometry/../ifc/ifcdef.h" #include "../vgeometry/../ifc/ifcdef.h"
#include "../vgeometry/vpointf.h" #include "../vgeometry/vpointf.h"
@ -65,26 +64,19 @@
DialogAlongLine::DialogAlongLine(const VContainer *data, quint32 toolId, QWidget *parent) DialogAlongLine::DialogAlongLine(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent), : DialogTool(data, toolId, parent),
ui(new Ui::DialogAlongLine), ui(new Ui::DialogAlongLine),
formula(), m_timerFormula(new QTimer(this))
pointName(),
formulaBaseHeight(0),
buildMidpoint(false),
timerFormula(new QTimer(this)),
flagFormula(false),
flagError(true),
flagName(true)
{ {
ui->setupUi(this); ui->setupUi(this);
timerFormula->setSingleShot(true); m_timerFormula->setSingleShot(true);
connect(timerFormula, &QTimer::timeout, this, &DialogAlongLine::EvalFormula); connect(m_timerFormula, &QTimer::timeout, this, &DialogAlongLine::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);
@ -97,12 +89,12 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, quint32 toolId, QWidget
connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogAlongLine::FXLength); connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogAlongLine::FXLength);
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, &DialogAlongLine::DeployFormulaTextEdit); connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogAlongLine::DeployFormulaTextEdit);
connect(ui->comboBoxFirstPoint, &QComboBox::currentTextChanged, connect(ui->comboBoxFirstPoint, &QComboBox::currentTextChanged,
@ -125,12 +117,12 @@ void DialogAlongLine::PointChanged()
QColor color; QColor color;
if (GetFirstPointId() == GetSecondPointId()) if (GetFirstPointId() == GetSecondPointId())
{ {
flagError = false; m_flagError = false;
color = errorColor; color = errorColor;
} }
else else
{ {
flagError = true; m_flagError = true;
color = OkColor(this); color = OkColor(this);
} }
SetCurrentLength(); SetCurrentLength();
@ -142,7 +134,7 @@ void DialogAlongLine::PointChanged()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogAlongLine::FXLength() void DialogAlongLine::FXLength()
{ {
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); auto *dialog = new DialogEditWrongFormula(data, toolId, this);
dialog->setWindowTitle(tr("Edit length")); dialog->setWindowTitle(tr("Edit length"));
dialog->SetFormula(GetFormula()); dialog->SetFormula(GetFormula());
dialog->setPostfix(UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true)); dialog->setPostfix(UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true));
@ -164,7 +156,7 @@ void DialogAlongLine::EvalFormula()
formulaData.postfix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true); formulaData.postfix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true);
formulaData.checkZero = false; formulaData.checkZero = false;
Eval(formulaData, flagFormula); Eval(formulaData, m_flagFormula);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -176,7 +168,7 @@ void DialogAlongLine::ShowVisualization()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogAlongLine::DeployFormulaTextEdit() void DialogAlongLine::DeployFormulaTextEdit()
{ {
DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight); DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLength, m_formulaBaseHeight);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -196,47 +188,49 @@ DialogAlongLine::~DialogAlongLine()
*/ */
void DialogAlongLine::ChosenObject(quint32 id, const SceneObject &type) void DialogAlongLine::ChosenObject(quint32 id, const SceneObject &type)
{ {
if (prepare == false)// After first choose we ignore all objects if (prepare)// After first choose we ignore all objects
{ {
if (type == SceneObject::Point) return;
{ }
VisToolAlongLine *line = qobject_cast<VisToolAlongLine *>(vis);
SCASSERT(line != nullptr)
const QString toolTip = tr("Select second point of line"); if (type == SceneObject::Point)
switch (number) {
{ auto *line = qobject_cast<VisToolAlongLine *>(vis);
case 0: SCASSERT(line != nullptr)
if (SetObject(id, ui->comboBoxFirstPoint, toolTip))
const QString toolTip = tr("Select second point of line");
switch (number)
{
case 0:
if (SetObject(id, ui->comboBoxFirstPoint, toolTip))
{
number++;
line->VisualMode(id);
}
break;
case 1:
if (SetObject(id, ui->comboBoxSecondPoint, QString()))
{
if (m_flagError)
{ {
number++; line->setObject2Id(id);
line->VisualMode(id); if (m_buildMidpoint)
{
SetFormula(currentLength + QStringLiteral("/2"));
}
line->RefreshGeometry();
prepare = true;
this->setModal(true);
this->show();
} }
break; else
case 1:
if (SetObject(id, ui->comboBoxSecondPoint, QString()))
{ {
if (flagError) emit ToolTip(toolTip);
{
line->setObject2Id(id);
if (buildMidpoint)
{
SetFormula(currentLength + QStringLiteral("/2"));
}
line->RefreshGeometry();
prepare = true;
this->setModal(true);
this->show();
}
else
{
emit ToolTip(toolTip);
}
} }
break; }
default: break;
break; default:
} break;
} }
} }
} }
@ -244,16 +238,16 @@ void DialogAlongLine::ChosenObject(quint32 id, const SceneObject &type)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogAlongLine::SaveData() void DialogAlongLine::SaveData()
{ {
pointName = ui->lineEditNamePoint->text(); m_pointName = ui->lineEditNamePoint->text();
formula = ui->plainTextEditFormula->toPlainText(); m_formula = ui->plainTextEditFormula->toPlainText();
VisToolAlongLine *line = qobject_cast<VisToolAlongLine *>(vis); auto *line = qobject_cast<VisToolAlongLine *>(vis);
SCASSERT(line != nullptr) SCASSERT(line != nullptr)
line->setObject1Id(GetFirstPointId()); line->setObject1Id(GetFirstPointId());
line->setObject2Id(GetSecondPointId()); line->setObject2Id(GetSecondPointId());
line->setLength(formula); line->setLength(m_formula);
line->setLineStyle(LineStyleToPenStyle(GetTypeLine())); line->setLineStyle(LineStyleToPenStyle(GetTypeLine()));
line->RefreshGeometry(); line->RefreshGeometry();
} }
@ -299,9 +293,9 @@ void DialogAlongLine::SetSecondPointId(quint32 value)
{ {
setCurrentPointId(ui->comboBoxSecondPoint, value); setCurrentPointId(ui->comboBoxSecondPoint, value);
VisToolAlongLine *line = qobject_cast<VisToolAlongLine *>(vis); auto *line = qobject_cast<VisToolAlongLine *>(vis);
SCASSERT(line != nullptr) SCASSERT(line != nullptr)
line->setObject2Id(value); line->setObject2Id(value);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -311,7 +305,7 @@ void DialogAlongLine::SetNotes(const QString &notes)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogAlongLine::GetNotes() const auto DialogAlongLine::GetNotes() const -> QString
{ {
return ui->plainTextEditToolNotes->toPlainText(); return ui->plainTextEditToolNotes->toPlainText();
} }
@ -321,10 +315,10 @@ void DialogAlongLine::Build(const Tool &type)
{ {
if (type == Tool::Midpoint) if (type == Tool::Midpoint)
{ {
buildMidpoint = true; m_buildMidpoint = true;
VisToolAlongLine *line = qobject_cast<VisToolAlongLine *>(vis); auto *line = qobject_cast<VisToolAlongLine *>(vis);
SCASSERT(line != nullptr) SCASSERT(line != nullptr)
line->setMidPointMode(buildMidpoint); line->setMidPointMode(m_buildMidpoint);
} }
} }
@ -337,7 +331,7 @@ void DialogAlongLine::SetFirstPointId(quint32 value)
{ {
setCurrentPointId(ui->comboBoxFirstPoint, value); setCurrentPointId(ui->comboBoxFirstPoint, value);
VisToolAlongLine *line = qobject_cast<VisToolAlongLine *>(vis); auto *line = qobject_cast<VisToolAlongLine *>(vis);
SCASSERT(line != nullptr) SCASSERT(line != nullptr)
line->setObject1Id(value); line->setObject1Id(value);
} }
@ -349,18 +343,18 @@ void DialogAlongLine::SetFirstPointId(quint32 value)
*/ */
void DialogAlongLine::SetFormula(const QString &value) void DialogAlongLine::SetFormula(const QString &value)
{ {
formula = VAbstractApplication::VApp()->TrVars() m_formula = VAbstractApplication::VApp()->TrVars()
->FormulaToUser(value, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); ->FormulaToUser(value, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
// increase height if needed. // increase height if needed.
if (formula.length() > 80) if (m_formula.length() > 80)
{ {
this->DeployFormulaTextEdit(); this->DeployFormulaTextEdit();
} }
ui->plainTextEditFormula->setPlainText(formula); ui->plainTextEditFormula->setPlainText(m_formula);
VisToolAlongLine *line = qobject_cast<VisToolAlongLine *>(vis); auto *line = qobject_cast<VisToolAlongLine *>(vis);
SCASSERT(line != nullptr) SCASSERT(line != nullptr)
line->setLength(formula); line->setLength(m_formula);
MoveCursorToEnd(ui->plainTextEditFormula); MoveCursorToEnd(ui->plainTextEditFormula);
} }
@ -377,7 +371,7 @@ void DialogAlongLine::SetTypeLine(const QString &value)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogAlongLine::GetLineColor() const auto DialogAlongLine::GetLineColor() const -> QString
{ {
return GetComboBoxCurrentData(ui->comboBoxLineColor, ColorBlack); return GetComboBoxCurrentData(ui->comboBoxLineColor, ColorBlack);
} }
@ -389,9 +383,9 @@ void DialogAlongLine::SetLineColor(const QString &value)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogAlongLine::GetPointName() const auto DialogAlongLine::GetPointName() const -> QString
{ {
return pointName; return m_pointName;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -401,8 +395,8 @@ QString DialogAlongLine::GetPointName() const
*/ */
void DialogAlongLine::SetPointName(const QString &value) void DialogAlongLine::SetPointName(const QString &value)
{ {
pointName = value; m_pointName = value;
ui->lineEditNamePoint->setText(pointName); ui->lineEditNamePoint->setText(m_pointName);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -410,7 +404,7 @@ void DialogAlongLine::SetPointName(const QString &value)
* @brief GetTypeLine return type of line * @brief GetTypeLine return type of line
* @return type * @return type
*/ */
QString DialogAlongLine::GetTypeLine() const auto DialogAlongLine::GetTypeLine() const -> QString
{ {
return GetComboBoxCurrentData(ui->comboBoxLineType, TypeLineLine); return GetComboBoxCurrentData(ui->comboBoxLineType, TypeLineLine);
} }
@ -420,9 +414,9 @@ QString DialogAlongLine::GetTypeLine() const
* @brief GetFormula return string of formula * @brief GetFormula return string of formula
* @return formula * @return formula
*/ */
QString DialogAlongLine::GetFormula() const auto DialogAlongLine::GetFormula() const -> QString
{ {
return VTranslateVars::TryFormulaFromUser(formula, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); return VTranslateVars::TryFormulaFromUser(m_formula, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -430,7 +424,7 @@ QString DialogAlongLine::GetFormula() const
* @brief GetFirstPointId return id first point of line * @brief GetFirstPointId return id first point of line
* @return id * @return id
*/ */
quint32 DialogAlongLine::GetFirstPointId() const auto DialogAlongLine::GetFirstPointId() const -> quint32
{ {
return getCurrentObjectId(ui->comboBoxFirstPoint); return getCurrentObjectId(ui->comboBoxFirstPoint);
} }
@ -440,7 +434,7 @@ quint32 DialogAlongLine::GetFirstPointId() const
* @brief GetSecondPointId return id second point of line * @brief GetSecondPointId return id second point of line
* @return id * @return id
*/ */
quint32 DialogAlongLine::GetSecondPointId() const auto DialogAlongLine::GetSecondPointId() const -> quint32
{ {
return getCurrentObjectId(ui->comboBoxSecondPoint); return getCurrentObjectId(ui->comboBoxSecondPoint);
} }

View File

@ -51,48 +51,48 @@ class DialogAlongLine final : public DialogTool
Q_OBJECT // NOLINT Q_OBJECT // NOLINT
public: public:
DialogAlongLine(const VContainer *data, quint32 toolId, QWidget *parent = nullptr); DialogAlongLine(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogAlongLine() override; ~DialogAlongLine() override;
QString GetPointName() const; auto GetPointName() const -> QString;
void SetPointName(const QString &value); void SetPointName(const QString &value);
QString GetTypeLine() const; auto GetTypeLine() const -> QString;
void SetTypeLine(const QString &value); void SetTypeLine(const QString &value);
QString GetLineColor() const; auto GetLineColor() const -> QString;
void SetLineColor(const QString &value); void SetLineColor(const QString &value);
QString GetFormula() const; auto GetFormula() const -> QString;
void SetFormula(const QString &value); void SetFormula(const QString &value);
quint32 GetFirstPointId() const; auto GetFirstPointId() const -> quint32;
void SetFirstPointId(quint32 value); void SetFirstPointId(quint32 value);
quint32 GetSecondPointId() const; auto GetSecondPointId() const -> quint32;
void SetSecondPointId(quint32 value); void SetSecondPointId(quint32 value);
void SetNotes(const QString &notes); void SetNotes(const QString &notes);
QString GetNotes() const; auto GetNotes() const -> QString;
virtual void Build(const Tool &type) override; void Build(const Tool &type) 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();
void PointChanged(); void PointChanged();
void FXLength(); void FXLength();
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(DialogAlongLine) // NOLINT Q_DISABLE_COPY_MOVE(DialogAlongLine) // NOLINT
@ -100,28 +100,28 @@ private:
Ui::DialogAlongLine *ui; Ui::DialogAlongLine *ui;
/** @brief formula formula */ /** @brief formula formula */
QString formula; QString m_formula{};
QString pointName; QString m_pointName{};
/** @brief formulaBaseHeight base height defined by dialogui */ /** @brief formulaBaseHeight base height defined by dialogui */
int formulaBaseHeight; int m_formulaBaseHeight{0};
bool buildMidpoint; bool m_buildMidpoint{false};
QTimer *timerFormula; QTimer *m_timerFormula;
bool flagFormula; bool m_flagFormula{false};
bool flagError; bool m_flagError{true};
bool flagName; bool m_flagName{true};
void SetCurrentLength(); void SetCurrentLength();
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
inline bool DialogAlongLine::IsValid() const inline auto DialogAlongLine::IsValid() const -> bool
{ {
return flagName &&flagFormula && flagError; return m_flagName &&m_flagFormula && m_flagError;
} }
#endif // DIALOGALONGLINE_H #endif // DIALOGALONGLINE_H