Refactoring.

This commit is contained in:
Roman Telezhynskyi 2022-08-19 16:53:44 +03:00
parent dd2eacd0d5
commit b9dd7d0ee9
4 changed files with 159 additions and 166 deletions

View File

@ -41,15 +41,14 @@
#include <QToolButton>
#include "../vpatterndb/vtranslatevars.h"
#include "../../tools/vabstracttool.h"
#include "../../visualization/visualization.h"
#include "../../visualization/line/vistoolshoulderpoint.h"
#include "../ifc/xml/vabstractpattern.h"
#include "../ifc/xml/vdomdocument.h"
#include "../support/dialogeditwrongformula.h"
#include "../vmisc/vabstractapplication.h"
#include "../vmisc/vcommonsettings.h"
#include "ui_dialogshoulderpoint.h"
#include "../vpatterndb/vcontainer.h"
//---------------------------------------------------------------------------------------------------------------------
/**
@ -60,24 +59,18 @@
DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogShoulderPoint),
formula(),
formulaBaseHeight(0),
timerFormula(new QTimer(this)),
pointName(),
flagFormula(false),
flagName(true),
flagError(true)
m_timerFormula(new QTimer(this))
{
ui->setupUi(this);
timerFormula->setSingleShot(true);
connect(timerFormula, &QTimer::timeout, this, &DialogShoulderPoint::EvalFormula);
m_timerFormula->setSingleShot(true);
connect(m_timerFormula, &QTimer::timeout, this, &DialogShoulderPoint::EvalFormula);
ui->lineEditNamePoint->setClearButtonEnabled(true);
ui->lineEditNamePoint->setText(
VAbstractValApplication::VApp()->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
formulaBaseHeight = ui->plainTextEditFormula->height();
m_formulaBaseHeight = ui->plainTextEditFormula->height();
ui->plainTextEditFormula->installEventFilter(this);
InitOkCancelApply(ui);
@ -91,12 +84,12 @@ DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, quint32 toolId,
connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogShoulderPoint::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, &DialogShoulderPoint::DeployFormulaTextEdit);
connect(ui->comboBoxP1Line, &QComboBox::currentTextChanged,
@ -123,12 +116,12 @@ void DialogShoulderPoint::PointNameChanged()
QColor color;
if (set.size() != 3)
{
flagError = false;
m_flagError = false;
color = errorColor;
}
else
{
flagError = true;
m_flagError = true;
color = OkColor(this);
}
ChangeColor(ui->labelFirstPoint, color);
@ -140,7 +133,7 @@ void DialogShoulderPoint::PointNameChanged()
//---------------------------------------------------------------------------------------------------------------------
void DialogShoulderPoint::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));
@ -161,7 +154,7 @@ void DialogShoulderPoint::EvalFormula()
formulaData.labelResult = ui->labelResultCalculation;
formulaData.postfix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true);
Eval(formulaData, flagFormula);
Eval(formulaData, m_flagFormula);
}
//---------------------------------------------------------------------------------------------------------------------
@ -173,7 +166,7 @@ void DialogShoulderPoint::ShowVisualization()
//---------------------------------------------------------------------------------------------------------------------
void DialogShoulderPoint::DeployFormulaTextEdit()
{
DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLength, m_formulaBaseHeight);
}
//---------------------------------------------------------------------------------------------------------------------
@ -183,9 +176,9 @@ DialogShoulderPoint::~DialogShoulderPoint()
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogShoulderPoint::GetPointName() const
auto DialogShoulderPoint::GetPointName() const -> QString
{
return pointName;
return m_pointName;
}
//---------------------------------------------------------------------------------------------------------------------
@ -196,11 +189,14 @@ QString DialogShoulderPoint::GetPointName() const
*/
void DialogShoulderPoint::ChosenObject(quint32 id, const SceneObject &type)
{
if (prepare == false)
if (prepare)
{
return;
}
if (type == SceneObject::Point)
{
VisToolShoulderPoint *line = qobject_cast<VisToolShoulderPoint *>(vis);
auto *line = qobject_cast<VisToolShoulderPoint *>(vis);
SCASSERT(line != nullptr)
switch (number)
@ -247,22 +243,21 @@ void DialogShoulderPoint::ChosenObject(quint32 id, const SceneObject &type)
break;
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogShoulderPoint::SaveData()
{
pointName = ui->lineEditNamePoint->text();
formula = ui->plainTextEditFormula->toPlainText();
m_pointName = ui->lineEditNamePoint->text();
m_formula = ui->plainTextEditFormula->toPlainText();
VisToolShoulderPoint *line = qobject_cast<VisToolShoulderPoint *>(vis);
auto *line = qobject_cast<VisToolShoulderPoint *>(vis);
SCASSERT(line != nullptr)
line->setObject1Id(GetP3());
line->setLineP1Id(GetP1Line());
line->setLineP2Id(GetP2Line());
line->setLength(formula);
line->setLength(m_formula);
line->setLineStyle(LineStyleToPenStyle(GetTypeLine()));
line->RefreshGeometry();
}
@ -283,13 +278,13 @@ void DialogShoulderPoint::SetP3(const quint32 &value)
{
setCurrentPointId(ui->comboBoxP3, value);
VisToolShoulderPoint *line = qobject_cast<VisToolShoulderPoint *>(vis);
auto *line = qobject_cast<VisToolShoulderPoint *>(vis);
SCASSERT(line != nullptr)
line->setObject1Id(value);
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogShoulderPoint::GetLineColor() const
auto DialogShoulderPoint::GetLineColor() const -> QString
{
return GetComboBoxCurrentData(ui->comboBoxLineColor, ColorBlack);
}
@ -309,7 +304,7 @@ void DialogShoulderPoint::SetP2Line(const quint32 &value)
{
setCurrentPointId(ui->comboBoxP2Line, value);
VisToolShoulderPoint *line = qobject_cast<VisToolShoulderPoint *>(vis);
auto *line = qobject_cast<VisToolShoulderPoint *>(vis);
SCASSERT(line != nullptr)
line->setLineP2Id(value);
}
@ -323,7 +318,7 @@ void DialogShoulderPoint::SetP1Line(const quint32 &value)
{
setCurrentPointId(ui->comboBoxP1Line, value);
VisToolShoulderPoint *line = qobject_cast<VisToolShoulderPoint *>(vis);
auto *line = qobject_cast<VisToolShoulderPoint *>(vis);
SCASSERT(line != nullptr)
line->setLineP1Id(value);
}
@ -335,18 +330,18 @@ void DialogShoulderPoint::SetP1Line(const quint32 &value)
*/
void DialogShoulderPoint::SetFormula(const QString &value)
{
formula = VAbstractApplication::VApp()->TrVars()
m_formula = VAbstractApplication::VApp()->TrVars()
->FormulaToUser(value, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
// increase height if needed.
if (formula.length() > 80)
if (m_formula.length() > 80)
{
this->DeployFormulaTextEdit();
}
ui->plainTextEditFormula->setPlainText(formula);
ui->plainTextEditFormula->setPlainText(m_formula);
VisToolShoulderPoint *line = qobject_cast<VisToolShoulderPoint *>(vis);
auto *line = qobject_cast<VisToolShoulderPoint *>(vis);
SCASSERT(line != nullptr)
line->setLength(formula);
line->setLength(m_formula);
MoveCursorToEnd(ui->plainTextEditFormula);
}
@ -368,8 +363,8 @@ void DialogShoulderPoint::SetTypeLine(const QString &value)
*/
void DialogShoulderPoint::SetPointName(const QString &value)
{
pointName = value;
ui->lineEditNamePoint->setText(pointName);
m_pointName = value;
ui->lineEditNamePoint->setText(m_pointName);
}
//---------------------------------------------------------------------------------------------------------------------
@ -377,7 +372,7 @@ void DialogShoulderPoint::SetPointName(const QString &value)
* @brief GetTypeLine return type of line
* @return type
*/
QString DialogShoulderPoint::GetTypeLine() const
auto DialogShoulderPoint::GetTypeLine() const -> QString
{
return GetComboBoxCurrentData(ui->comboBoxLineType, TypeLineLine);
}
@ -387,9 +382,9 @@ QString DialogShoulderPoint::GetTypeLine() const
* @brief GetFormula return string of formula
* @return formula
*/
QString DialogShoulderPoint::GetFormula() const
auto DialogShoulderPoint::GetFormula() const -> QString
{
return VTranslateVars::TryFormulaFromUser(formula, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
return VTranslateVars::TryFormulaFromUser(m_formula, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
}
//---------------------------------------------------------------------------------------------------------------------
@ -397,7 +392,7 @@ QString DialogShoulderPoint::GetFormula() const
* @brief GetP1Line return id first point of line
* @return id
*/
quint32 DialogShoulderPoint::GetP1Line() const
auto DialogShoulderPoint::GetP1Line() const -> quint32
{
return getCurrentObjectId(ui->comboBoxP1Line);
}
@ -407,7 +402,7 @@ quint32 DialogShoulderPoint::GetP1Line() const
* @brief GetP2Line return id second point of line
* @return id
*/
quint32 DialogShoulderPoint::GetP2Line() const
auto DialogShoulderPoint::GetP2Line() const -> quint32
{
return getCurrentObjectId(ui->comboBoxP2Line);
}
@ -417,7 +412,7 @@ quint32 DialogShoulderPoint::GetP2Line() const
* @brief getPShoulder return id shoulder point
* @return id
*/
quint32 DialogShoulderPoint::GetP3() const
auto DialogShoulderPoint::GetP3() const -> quint32
{
return getCurrentObjectId(ui->comboBoxP3);
}
@ -429,7 +424,7 @@ void DialogShoulderPoint::SetNotes(const QString &notes)
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogShoulderPoint::GetNotes() const
auto DialogShoulderPoint::GetNotes() const -> QString
{
return ui->plainTextEditToolNotes->toPlainText();
}

View File

@ -51,48 +51,48 @@ class DialogShoulderPoint : public DialogTool
Q_OBJECT // NOLINT
public:
DialogShoulderPoint(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogShoulderPoint() override;
~DialogShoulderPoint() override;
QString GetPointName() const;
auto GetPointName() const -> QString;
void SetPointName(const QString &value);
QString GetTypeLine() const;
auto GetTypeLine() const -> QString;
void SetTypeLine(const QString &value);
QString GetFormula() const;
auto GetFormula() const -> QString;
void SetFormula(const QString &value);
quint32 GetP1Line() const;
auto GetP1Line() const -> quint32;
void SetP1Line(const quint32 &value);
quint32 GetP2Line() const;
auto GetP2Line() const -> quint32;
void SetP2Line(const quint32 &value);
quint32 GetP3() const;
auto GetP3() const -> quint32;
void SetP3(const quint32 &value);
QString GetLineColor() const;
auto GetLineColor() const -> QString;
void SetLineColor(const QString &value);
void SetNotes(const QString &notes);
QString GetNotes() const;
auto GetNotes() 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
*/
void DeployFormulaTextEdit();
virtual void PointNameChanged() override;
void PointNameChanged() override;
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:
Q_DISABLE_COPY_MOVE(DialogShoulderPoint) // NOLINT
@ -100,24 +100,24 @@ private:
Ui::DialogShoulderPoint *ui;
/** @brief formula formula */
QString formula;
QString m_formula{};
/** @brief formulaBaseHeight base height defined by dialogui */
int formulaBaseHeight;
int m_formulaBaseHeight{0};
QTimer *timerFormula;
QTimer *m_timerFormula;
QString pointName;
QString m_pointName{};
bool flagFormula;
bool flagName;
bool flagError;
bool m_flagFormula{false};
bool m_flagName{true};
bool m_flagError{true};
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogShoulderPoint::IsValid() const
inline auto DialogShoulderPoint::IsValid() const -> bool
{
return flagFormula && flagName && flagError;
return m_flagFormula && m_flagName && m_flagError;
}
#endif // DIALOGSHOULDERPOINT_H

View File

@ -36,7 +36,6 @@
#include <new>
#include "../../tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.h"
#include "../ifc/ifcdef.h"
#include "../vgeometry/vgobject.h"
#include "../vgeometry/vpointf.h"
#include "../vpatterndb/vcontainer.h"
@ -45,18 +44,17 @@
//---------------------------------------------------------------------------------------------------------------------
VisToolShoulderPoint::VisToolShoulderPoint(const VContainer *data, QGraphicsItem *parent)
:VisLine(data, parent), lineP1Id(NULL_ID), lineP2Id(NULL_ID), point(nullptr), line1P1(nullptr), line1P2(nullptr),
line1(nullptr), line2P2(nullptr), line2(nullptr), line3(nullptr), length(0)
:VisLine(data, parent)
{
line1P1 = InitPoint(supportColor, this);
line1P2 = InitPoint(supportColor, this); //-V656
line1 = InitItem<VScaledLine>(supportColor, this);
m_line1P1 = InitPoint(supportColor, this);
m_line1P2 = InitPoint(supportColor, this); //-V656
m_line1 = InitItem<VScaledLine>(supportColor, this);
line2P2 = InitPoint(supportColor, this);
line2 = InitItem<VScaledLine>(supportColor, this);
line3 = InitItem<VScaledLine>(supportColor, this); //-V656
m_line2P2 = InitPoint(supportColor, this);
m_line2 = InitItem<VScaledLine>(supportColor, this);
m_line3 = InitItem<VScaledLine>(supportColor, this); //-V656
point = InitPoint(mainColor, this);
m_point = InitPoint(mainColor, this);
}
//---------------------------------------------------------------------------------------------------------------------
@ -65,40 +63,40 @@ void VisToolShoulderPoint::RefreshGeometry()
if (object1Id > NULL_ID)
{
const QSharedPointer<VPointF> first = Visualization::data->GeometricObject<VPointF>(object1Id);
DrawPoint(line1P1, static_cast<QPointF>(*first), supportColor);
DrawPoint(m_line1P1, static_cast<QPointF>(*first), supportColor);
if (lineP1Id <= NULL_ID)
if (m_lineP1Id <= NULL_ID)
{
DrawLine(line1, QLineF(static_cast<QPointF>(*first), Visualization::scenePos), supportColor);
DrawLine(m_line1, QLineF(static_cast<QPointF>(*first), Visualization::scenePos), supportColor);
}
else
{
const QSharedPointer<VPointF> second = Visualization::data->GeometricObject<VPointF>(lineP1Id);
DrawPoint(line1P2, static_cast<QPointF>(*second), supportColor);
const QSharedPointer<VPointF> second = Visualization::data->GeometricObject<VPointF>(m_lineP1Id);
DrawPoint(m_line1P2, static_cast<QPointF>(*second), supportColor);
DrawLine(line1, QLineF(static_cast<QPointF>(*first), static_cast<QPointF>(*second)), supportColor);
DrawLine(m_line1, QLineF(static_cast<QPointF>(*first), static_cast<QPointF>(*second)), supportColor);
if (lineP2Id <= NULL_ID)
if (m_lineP2Id <= NULL_ID)
{
DrawLine(line2, QLineF(static_cast<QPointF>(*second), Visualization::scenePos), supportColor);
DrawLine(m_line2, QLineF(static_cast<QPointF>(*second), Visualization::scenePos), supportColor);
}
else
{
const QSharedPointer<VPointF> third = Visualization::data->GeometricObject<VPointF>(lineP2Id);
DrawPoint(line2P2, static_cast<QPointF>(*third), supportColor);
const QSharedPointer<VPointF> third = Visualization::data->GeometricObject<VPointF>(m_lineP2Id);
DrawPoint(m_line2P2, static_cast<QPointF>(*third), supportColor);
DrawLine(line2, QLineF(static_cast<QPointF>(*second), static_cast<QPointF>(*third)), supportColor);
DrawLine(m_line2, QLineF(static_cast<QPointF>(*second), static_cast<QPointF>(*third)), supportColor);
if (not qFuzzyIsNull(length))
if (not qFuzzyIsNull(m_length))
{
QPointF fPoint = VToolShoulderPoint::FindPoint(static_cast<QPointF>(*second),
static_cast<QPointF>(*third),
static_cast<QPointF>(*first), length);
static_cast<QPointF>(*first), m_length);
QLineF mainLine = QLineF(static_cast<QPointF>(*second), fPoint);
DrawLine(this, mainLine, mainColor, lineStyle);
DrawPoint(point, mainLine.p2(), mainColor);
DrawLine(line3, QLineF(static_cast<QPointF>(*first), mainLine.p2()), supportColor, Qt::DashLine);
DrawPoint(m_point, mainLine.p2(), mainColor);
DrawLine(m_line3, QLineF(static_cast<QPointF>(*first), mainLine.p2()), supportColor, Qt::DashLine);
}
else
{
@ -117,17 +115,17 @@ void VisToolShoulderPoint::RefreshGeometry()
//---------------------------------------------------------------------------------------------------------------------
void VisToolShoulderPoint::setLineP1Id(const quint32 &value)
{
lineP1Id = value;
m_lineP1Id = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolShoulderPoint::setLineP2Id(const quint32 &value)
{
lineP2Id = value;
m_lineP2Id = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolShoulderPoint::setLength(const QString &expression)
{
length = FindLengthFromUser(expression, Visualization::data->DataVariables());
m_length = FindLengthFromUser(expression, Visualization::data->DataVariables());
}

View File

@ -44,27 +44,27 @@ class VisToolShoulderPoint : public VisLine
Q_OBJECT // NOLINT
public:
explicit VisToolShoulderPoint(const VContainer *data, QGraphicsItem *parent = nullptr);
virtual ~VisToolShoulderPoint() = default;
~VisToolShoulderPoint() override = default;
virtual void RefreshGeometry() override;
void RefreshGeometry() override;
void setLineP1Id(const quint32 &value);
void setLineP2Id(const quint32 &value);
void setLength(const QString &expression);
virtual int type() const override {return Type;}
enum { Type = UserType + static_cast<int>(Vis::ToolShoulderPoint)};
auto type() const -> int override {return Type;}
enum {Type = UserType + static_cast<int>(Vis::ToolShoulderPoint)};
private:
// cppcheck-suppress unknownMacro
Q_DISABLE_COPY_MOVE(VisToolShoulderPoint) // NOLINT
quint32 lineP1Id;
quint32 lineP2Id;
VScaledEllipse *point;
VScaledEllipse *line1P1;
VScaledEllipse *line1P2;
VScaledLine *line1;
VScaledEllipse *line2P2;
VScaledLine *line2;
VScaledLine *line3;
qreal length;
quint32 m_lineP1Id{NULL_ID};
quint32 m_lineP2Id{NULL_ID};
VScaledEllipse *m_point{nullptr};
VScaledEllipse *m_line1P1{nullptr};
VScaledEllipse *m_line1P2{nullptr};
VScaledLine *m_line1{nullptr};
VScaledEllipse *m_line2P2{nullptr};
VScaledLine *m_line2{nullptr};
VScaledLine *m_line3{nullptr};
qreal m_length{0};
};
#endif // VISTOOLSHOULDERPOINT_H