Refactoring.

This commit is contained in:
Roman Telezhynskyi 2022-08-20 15:41:00 +03:00
parent 0f78ef8b05
commit b1d7177952
4 changed files with 107 additions and 112 deletions

View File

@ -41,7 +41,6 @@
#include "../../visualization/path/vistoolcutspline.h"
#include "../../visualization/visualization.h"
#include "../ifc/xml/vabstractpattern.h"
#include "../ifc/xml/vdomdocument.h"
#include "../support/dialogeditwrongformula.h"
#include "../vmisc/vabstractapplication.h"
#include "../vmisc/vcommonsettings.h"
@ -58,23 +57,18 @@
DialogCutSpline::DialogCutSpline(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogCutSpline),
formula(),
formulaBaseHeight(0),
pointName(),
timerFormula(new QTimer(this)),
flagFormula(false),
flagName(true)
m_timerFormula(new QTimer(this))
{
ui->setupUi(this);
timerFormula->setSingleShot(true);
connect(timerFormula, &QTimer::timeout, this, &DialogCutSpline::EvalFormula);
m_timerFormula->setSingleShot(true);
connect(m_timerFormula, &QTimer::timeout, this, &DialogCutSpline::EvalFormula);
ui->lineEditNamePoint->setClearButtonEnabled(true);
ui->lineEditNamePoint->setText(
VAbstractValApplication::VApp()->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
this->formulaBaseHeight = ui->plainTextEditFormula->height();
this->m_formulaBaseHeight = ui->plainTextEditFormula->height();
ui->plainTextEditFormula->installEventFilter(this);
InitOkCancelApply(ui);
@ -84,12 +78,12 @@ DialogCutSpline::DialogCutSpline(const VContainer *data, quint32 toolId, QWidget
connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogCutSpline::FXLength);
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();
});
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, [this]()
{
timerFormula->start(formulaTimerTimeout);
m_timerFormula->start(formulaTimerTimeout);
});
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogCutSpline::DeployFormulaTextEdit);
connect(ui->comboBoxSpline, &QComboBox::currentTextChanged, this, &DialogCutSpline::SplineChanged);
@ -110,9 +104,9 @@ DialogCutSpline::~DialogCutSpline()
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogCutSpline::GetPointName() const
auto DialogCutSpline::GetPointName() const -> QString
{
return pointName;
return m_pointName;
}
//---------------------------------------------------------------------------------------------------------------------
@ -122,8 +116,8 @@ QString DialogCutSpline::GetPointName() const
*/
void DialogCutSpline::SetPointName(const QString &value)
{
pointName = value;
ui->lineEditNamePoint->setText(pointName);
m_pointName = value;
ui->lineEditNamePoint->setText(m_pointName);
}
//---------------------------------------------------------------------------------------------------------------------
@ -133,19 +127,19 @@ void DialogCutSpline::SetPointName(const QString &value)
*/
void DialogCutSpline::SetFormula(const QString &value)
{
formula = VAbstractApplication::VApp()->TrVars()
m_formula = VAbstractApplication::VApp()->TrVars()
->FormulaToUser(value, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
// increase height if needed. TODO : see if I can get the max number of caracters in one line
// of this PlainTextEdit to change 80 to this value
if (formula.length() > 80)
if (m_formula.length() > 80)
{
this->DeployFormulaTextEdit();
}
ui->plainTextEditFormula->setPlainText(formula);
ui->plainTextEditFormula->setPlainText(m_formula);
VisToolCutSpline *path = qobject_cast<VisToolCutSpline *>(vis);
auto *path = qobject_cast<VisToolCutSpline *>(vis);
SCASSERT(path != nullptr)
path->setLength(formula);
path->setLength(m_formula);
MoveCursorToEnd(ui->plainTextEditFormula);
}
@ -159,7 +153,7 @@ void DialogCutSpline::setSplineId(quint32 value)
{
setCurrentSplineId(ui->comboBoxSpline, value);
VisToolCutSpline *path = qobject_cast<VisToolCutSpline *>(vis);
auto *path = qobject_cast<VisToolCutSpline *>(vis);
SCASSERT(path != nullptr)
path->setObject1Id(value);
}
@ -172,8 +166,11 @@ void DialogCutSpline::setSplineId(quint32 value)
*/
void DialogCutSpline::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
{
return;
}
if (type == SceneObject::Spline)
{
if (SetObject(id, ui->comboBoxSpline, QString()))
@ -188,19 +185,18 @@ void DialogCutSpline::ChosenObject(quint32 id, const SceneObject &type)
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCutSpline::SaveData()
{
pointName = ui->lineEditNamePoint->text();
formula = ui->plainTextEditFormula->toPlainText();
m_pointName = ui->lineEditNamePoint->text();
m_formula = ui->plainTextEditFormula->toPlainText();
VisToolCutSpline *path = qobject_cast<VisToolCutSpline *>(vis);
auto *path = qobject_cast<VisToolCutSpline *>(vis);
SCASSERT(path != nullptr)
path->setObject1Id(getSplineId());
path->setLength(formula);
path->setLength(m_formula);
path->RefreshGeometry();
}
@ -230,29 +226,29 @@ void DialogCutSpline::ValidateAlias()
if (not GetAliasSuffix1().isEmpty() &&
(not rx.match(spl1.GetAlias()).hasMatch() ||
(originAliasSuffix1 != GetAliasSuffix1() && not data->IsUnique(spl1.GetAlias())) ||
(m_originAliasSuffix1 != GetAliasSuffix1() && not data->IsUnique(spl1.GetAlias())) ||
spl1.GetAlias() == spl2.GetAlias()))
{
flagAlias1 = false;
m_flagAlias1 = false;
ChangeColor(ui->labelAlias1, errorColor);
}
else
{
flagAlias1 = true;
m_flagAlias1 = true;
ChangeColor(ui->labelAlias1, OkColor(this));
}
if (not GetAliasSuffix2().isEmpty() &&
(not rx.match(spl2.GetAlias()).hasMatch() ||
(originAliasSuffix2 != GetAliasSuffix2() && not data->IsUnique(spl2.GetAlias())) ||
(m_originAliasSuffix2 != GetAliasSuffix2() && not data->IsUnique(spl2.GetAlias())) ||
spl1.GetAlias() == spl2.GetAlias()))
{
flagAlias2 = false;
m_flagAlias2 = false;
ChangeColor(ui->labelAlias2, errorColor);
}
else
{
flagAlias2 = true;
m_flagAlias2 = true;
ChangeColor(ui->labelAlias2, OkColor(this));
}
@ -262,13 +258,13 @@ void DialogCutSpline::ValidateAlias()
//---------------------------------------------------------------------------------------------------------------------
void DialogCutSpline::DeployFormulaTextEdit()
{
DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLength, m_formulaBaseHeight);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCutSpline::FXLength()
{
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this);
auto *dialog = new DialogEditWrongFormula(data, toolId, this);
dialog->setWindowTitle(tr("Edit length"));
dialog->SetFormula(GetFormula());
dialog->setPostfix(UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true));
@ -290,7 +286,7 @@ void DialogCutSpline::EvalFormula()
formulaData.postfix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true);
formulaData.checkZero = false;
Eval(formulaData, flagFormula);
Eval(formulaData, m_flagFormula);
}
//---------------------------------------------------------------------------------------------------------------------
@ -304,9 +300,9 @@ void DialogCutSpline::ShowVisualization()
* @brief GetFormula return string of formula
* @return formula
*/
QString DialogCutSpline::GetFormula() const
auto DialogCutSpline::GetFormula() const -> QString
{
return VTranslateVars::TryFormulaFromUser(formula, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
return VTranslateVars::TryFormulaFromUser(m_formula, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
}
//---------------------------------------------------------------------------------------------------------------------
@ -326,7 +322,7 @@ void DialogCutSpline::SetNotes(const QString &notes)
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogCutSpline::GetNotes() const
auto DialogCutSpline::GetNotes() const -> QString
{
return ui->plainTextEditToolNotes->toPlainText();
}
@ -334,13 +330,13 @@ QString DialogCutSpline::GetNotes() const
//---------------------------------------------------------------------------------------------------------------------
void DialogCutSpline::SetAliasSuffix1(const QString &alias)
{
originAliasSuffix1 = alias;
ui->lineEditAlias1->setText(originAliasSuffix1);
m_originAliasSuffix1 = alias;
ui->lineEditAlias1->setText(m_originAliasSuffix1);
ValidateAlias();
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogCutSpline::GetAliasSuffix1() const
auto DialogCutSpline::GetAliasSuffix1() const -> QString
{
return ui->lineEditAlias1->text();
}
@ -348,13 +344,13 @@ QString DialogCutSpline::GetAliasSuffix1() const
//---------------------------------------------------------------------------------------------------------------------
void DialogCutSpline::SetAliasSuffix2(const QString &alias)
{
originAliasSuffix2 = alias;
ui->lineEditAlias2->setText(originAliasSuffix2);
m_originAliasSuffix2 = alias;
ui->lineEditAlias2->setText(m_originAliasSuffix2);
ValidateAlias();
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogCutSpline::GetAliasSuffix2() const
auto DialogCutSpline::GetAliasSuffix2() const -> QString
{
return ui->lineEditAlias2->text();
}

View File

@ -51,27 +51,27 @@ class DialogCutSpline final : public DialogTool
Q_OBJECT // NOLINT
public:
DialogCutSpline(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogCutSpline() override;
~DialogCutSpline() override;
QString GetPointName() const;
auto GetPointName() const -> QString;
void SetPointName(const QString &value);
QString GetFormula() const;
auto GetFormula() const -> QString;
void SetFormula(const QString &value);
quint32 getSplineId() const;
auto getSplineId() const -> quint32;
void setSplineId(quint32 value);
void SetNotes(const QString &notes);
QString GetNotes() const;
auto GetNotes() const -> QString;
void SetAliasSuffix1(const QString &alias);
QString GetAliasSuffix1() const;
auto GetAliasSuffix1() const -> QString;
void SetAliasSuffix2(const QString &alias);
QString GetAliasSuffix2() const;
auto GetAliasSuffix2() const -> QString;
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
*/
@ -79,13 +79,13 @@ public slots:
void FXLength();
void EvalFormula();
protected:
virtual void ShowVisualization() override;
void ShowVisualization() override;
/**
* @brief SaveData Put dialog data in local variables
*/
virtual void SaveData() override;
virtual void closeEvent(QCloseEvent *event) override;
virtual bool IsValid() const final;
void SaveData() override;
void closeEvent(QCloseEvent *event) override;
auto IsValid() const -> bool final;
private slots:
void SplineChanged();
void ValidateAlias();
@ -96,28 +96,28 @@ private:
Ui::DialogCutSpline *ui;
/** @brief formula string with formula */
QString formula;
QString m_formula{};
/** @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 flagName;
bool flagAlias1{true};
bool flagAlias2{true};
bool m_flagFormula{false};
bool m_flagName{true};
bool m_flagAlias1{true};
bool m_flagAlias2{true};
QString originAliasSuffix1{};
QString originAliasSuffix2{};
QString m_originAliasSuffix1{};
QString m_originAliasSuffix2{};
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogCutSpline::IsValid() const
inline auto DialogCutSpline::IsValid() const -> bool
{
return flagFormula && flagName && flagAlias1 && flagAlias2;
return m_flagFormula && m_flagName && m_flagAlias1 && m_flagAlias2;
}
#endif // DIALOGCUTSPLINE_H

View File

@ -36,7 +36,6 @@
#include <Qt>
#include <new>
#include "../ifc/ifcdef.h"
#include "../vgeometry/vabstractcubicbezier.h"
#include "../vgeometry/vabstractcurve.h"
#include "../vgeometry/vpointf.h"
@ -48,16 +47,16 @@
//---------------------------------------------------------------------------------------------------------------------
VisToolCutSpline::VisToolCutSpline(const VContainer *data, QGraphicsItem *parent)
:VisPath(data, parent), point(nullptr), spl1(nullptr), spl2(nullptr), length(0)
:VisPath(data, parent)
{
spl1 = InitItem<VCurvePathItem>(Qt::darkGreen, this);
spl1->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
spl2 = InitItem<VCurvePathItem>(Qt::darkRed, this);
spl2->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
m_spl1 = InitItem<VCurvePathItem>(Qt::darkGreen, this);
m_spl1->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
m_spl2 = InitItem<VCurvePathItem>(Qt::darkRed, this);
m_spl2->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
point = InitPoint(mainColor, this);
point->setZValue(2);
point->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
m_point = InitPoint(mainColor, this);
m_point->setZValue(2);
m_point->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
}
//---------------------------------------------------------------------------------------------------------------------
@ -68,23 +67,23 @@ void VisToolCutSpline::RefreshGeometry()
const auto spl = Visualization::data->GeometricObject<VAbstractCubicBezier>(object1Id);
DrawPath(this, spl->GetPath(), spl->DirectionArrows(), supportColor, lineStyle, Qt::RoundCap);
if (not qFuzzyIsNull(length))
if (not qFuzzyIsNull(m_length))
{
QPointF spl1p2;
QPointF spl1p3;
QPointF spl2p2;
QPointF spl2p3;
const QPointF p = spl->CutSpline(length, spl1p2, spl1p3, spl2p2, spl2p3, QString());
const QPointF p = spl->CutSpline(m_length, spl1p2, spl1p3, spl2p2, spl2p3, QString());
VSpline sp1 = VSpline(spl->GetP1(), spl1p2, spl1p3, VPointF(p));
sp1.SetApproximationScale(spl->GetApproximationScale());
VSpline sp2 = VSpline(VPointF(p), spl2p2, spl2p3, spl->GetP4());
sp2.SetApproximationScale(spl->GetApproximationScale());
DrawPoint(point, p, mainColor);
DrawPoint(m_point, p, mainColor);
DrawPath(spl1, sp1.GetPath(), sp1.DirectionArrows(), Qt::darkGreen, lineStyle, Qt::RoundCap);
DrawPath(spl2, sp2.GetPath(), sp2.DirectionArrows(), Qt::darkRed, lineStyle, Qt::RoundCap);
DrawPath(m_spl1, sp1.GetPath(), sp1.DirectionArrows(), Qt::darkGreen, lineStyle, Qt::RoundCap);
DrawPath(m_spl2, sp2.GetPath(), sp2.DirectionArrows(), Qt::darkRed, lineStyle, Qt::RoundCap);
}
}
}
@ -92,5 +91,5 @@ void VisToolCutSpline::RefreshGeometry()
//---------------------------------------------------------------------------------------------------------------------
void VisToolCutSpline::setLength(const QString &expression)
{
length = FindLengthFromUser(expression, Visualization::data->DataVariables());
m_length = FindLengthFromUser(expression, Visualization::data->DataVariables());
}

View File

@ -44,18 +44,18 @@ class VisToolCutSpline final : public VisPath
Q_OBJECT // NOLINT
public:
explicit VisToolCutSpline(const VContainer *data, QGraphicsItem *parent = nullptr);
virtual ~VisToolCutSpline() Q_DECL_EQ_DEFAULT;
~VisToolCutSpline() override = default;
virtual void RefreshGeometry() override;
void RefreshGeometry() override;
void setLength(const QString &expression);
virtual int type() const override {return Type;}
auto type() const -> int override {return Type;}
enum {Type = UserType + static_cast<int>(Vis::ToolCutSpline)};
protected:
private:
Q_DISABLE_COPY_MOVE(VisToolCutSpline) // NOLINT
VScaledEllipse *point;
VCurvePathItem *spl1;
VCurvePathItem *spl2;
qreal length;
VScaledEllipse *m_point{nullptr};
VCurvePathItem *m_spl1{nullptr};
VCurvePathItem *m_spl2{nullptr};
qreal m_length{0};
};
#endif // VISTOOLCUTSPLINE_H