Refactoring.

This commit is contained in:
Roman Telezhynskyi 2022-08-19 14:59:36 +03:00
parent 3d186c2a37
commit 48b7c387a8
10 changed files with 279 additions and 294 deletions

View File

@ -265,7 +265,7 @@ void DialogAlongLine::SetCurrentLength()
}
//---------------------------------------------------------------------------------------------------------------------
void DialogAlongLine::ChosenSecondPoint(quint32 id, const QString toolTip)
void DialogAlongLine::ChosenSecondPoint(quint32 id, const QString &toolTip)
{
if (SetObject(id, ui->comboBoxSecondPoint, QString()))
{

View File

@ -120,7 +120,7 @@ private:
void SetCurrentLength();
void ChosenSecondPoint(quint32 id, const QString toolTip);
void ChosenSecondPoint(quint32 id, const QString &toolTip);
};
//---------------------------------------------------------------------------------------------------------------------

View File

@ -46,7 +46,6 @@
#include "../ifc/xml/vabstractpattern.h"
#include "../vgeometry/vgobject.h"
#include "../vgeometry/vpointf.h"
#include "../vmisc/vabstractapplication.h"
#include "../vpatterndb/vcontainer.h"
#include "dialogtool.h"
#include "ui_dialogheight.h"
@ -59,10 +58,7 @@
*/
DialogHeight::DialogHeight(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogHeight),
pointName(),
flagError(true),
flagName(true)
ui(new Ui::DialogHeight)
{
ui->setupUi(this);
@ -80,7 +76,7 @@ DialogHeight::DialogHeight(const VContainer *data, quint32 toolId, QWidget *pare
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->comboBoxBasePoint, &QComboBox::currentTextChanged,
@ -103,9 +99,9 @@ DialogHeight::~DialogHeight()
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogHeight::GetPointName() const
auto DialogHeight::GetPointName() const -> QString
{
return pointName;
return m_pointName;
}
//---------------------------------------------------------------------------------------------------------------------
@ -115,8 +111,8 @@ QString DialogHeight::GetPointName() const
*/
void DialogHeight::SetPointName(const QString &value)
{
pointName = value;
ui->lineEditNamePoint->setText(pointName);
m_pointName = value;
ui->lineEditNamePoint->setText(m_pointName);
}
//---------------------------------------------------------------------------------------------------------------------
@ -139,7 +135,7 @@ void DialogHeight::SetBasePointId(const quint32 &value)
{
setCurrentPointId(ui->comboBoxBasePoint, value);
VisToolHeight *line = qobject_cast<VisToolHeight *>(vis);
auto *line = qobject_cast<VisToolHeight *>(vis);
SCASSERT(line != nullptr)
line->setObject1Id(value);
}
@ -153,7 +149,7 @@ void DialogHeight::SetP1LineId(const quint32 &value)
{
setCurrentPointId(ui->comboBoxP1Line, value);
VisToolHeight *line = qobject_cast<VisToolHeight *>(vis);
auto *line = qobject_cast<VisToolHeight *>(vis);
SCASSERT(line != nullptr)
line->setLineP1Id(value);
}
@ -167,13 +163,13 @@ void DialogHeight::SetP2LineId(const quint32 &value)
{
setCurrentPointId(ui->comboBoxP2Line, value);
VisToolHeight *line = qobject_cast<VisToolHeight *>(vis);
auto *line = qobject_cast<VisToolHeight *>(vis);
SCASSERT(line != nullptr)
line->setLineP2Id(value);
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogHeight::GetLineColor() const
auto DialogHeight::GetLineColor() const -> QString
{
return GetComboBoxCurrentData(ui->comboBoxLineColor, ColorBlack);
}
@ -192,11 +188,14 @@ void DialogHeight::SetLineColor(const QString &value)
*/
void DialogHeight::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::Point)
{
VisToolHeight *line = qobject_cast<VisToolHeight *>(vis);
auto *line = qobject_cast<VisToolHeight *>(vis);
SCASSERT(line != nullptr)
switch (number)
@ -242,15 +241,14 @@ void DialogHeight::ChosenObject(quint32 id, const SceneObject &type)
break;
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogHeight::SaveData()
{
pointName = ui->lineEditNamePoint->text();
m_pointName = ui->lineEditNamePoint->text();
VisToolHeight *line = qobject_cast<VisToolHeight *>(vis);
auto *line = qobject_cast<VisToolHeight *>(vis);
SCASSERT(line != nullptr)
line->setObject1Id(GetBasePointId());
@ -282,18 +280,18 @@ void DialogHeight::PointNameChanged()
if (set.size() != 3 || VGObject::ClosestPoint(QLineF(p1Line, p2Line), basePoint) == QPointF())
{
flagError = false;
m_flagError = false;
color = errorColor;
}
else
{
flagError = true;
m_flagError = true;
color = OkColor(this);
}
}
catch (const VExceptionBadId &)
{
flagError = false;
m_flagError = false;
color = errorColor;
}
@ -314,7 +312,7 @@ void DialogHeight::ShowVisualization()
* @brief GetTypeLine return type of line
* @return type
*/
QString DialogHeight::GetTypeLine() const
auto DialogHeight::GetTypeLine() const -> QString
{
return GetComboBoxCurrentData(ui->comboBoxLineType, TypeLineLine);
}
@ -324,7 +322,7 @@ QString DialogHeight::GetTypeLine() const
* @brief GetBasePointId return id base point of height
* @return id
*/
quint32 DialogHeight::GetBasePointId() const
auto DialogHeight::GetBasePointId() const -> quint32
{
return getCurrentObjectId(ui->comboBoxBasePoint);
}
@ -334,7 +332,7 @@ quint32 DialogHeight::GetBasePointId() const
* @brief GetP1LineId return id first point of line
* @return id id
*/
quint32 DialogHeight::GetP1LineId() const
auto DialogHeight::GetP1LineId() const -> quint32
{
return getCurrentObjectId(ui->comboBoxP1Line);
}
@ -344,7 +342,7 @@ quint32 DialogHeight::GetP1LineId() const
* @brief GetP2LineId return id second point of line
* @return id
*/
quint32 DialogHeight::GetP2LineId() const
auto DialogHeight::GetP2LineId() const -> quint32
{
return getCurrentObjectId(ui->comboBoxP2Line);
}
@ -356,7 +354,7 @@ void DialogHeight::SetNotes(const QString &notes)
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogHeight::GetNotes() const
auto DialogHeight::GetNotes() const -> QString
{
return ui->plainTextEditToolNotes->toPlainText();
}

View File

@ -51,54 +51,54 @@ class DialogHeight final : public DialogTool
Q_OBJECT // NOLINT
public:
DialogHeight(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogHeight() override;
~DialogHeight() 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);
quint32 GetBasePointId() const;
auto GetBasePointId() const -> quint32;
void SetBasePointId(const quint32 &value);
quint32 GetP1LineId() const;
auto GetP1LineId() const -> quint32;
void SetP1LineId(const quint32 &value);
quint32 GetP2LineId() const;
auto GetP2LineId() const -> quint32;
void SetP2LineId(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;
virtual void PointNameChanged() override;
void ChosenObject(quint32 id, const SceneObject &type) override;
void PointNameChanged() override;
protected:
virtual void ShowVisualization() override;
void ShowVisualization() override;
/**
* @brief SaveData Put dialog data in local variables
*/
virtual void SaveData() override;
virtual bool IsValid() const final;
void SaveData() override;
auto IsValid() const -> bool final;
private:
Q_DISABLE_COPY_MOVE(DialogHeight) // NOLINT
/** @brief ui keeps information about user interface */
Ui::DialogHeight *ui;
QString pointName;
QString m_pointName{};
bool flagError;
bool flagName;
bool m_flagError{true};
bool m_flagName{true};
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogHeight::IsValid() const
inline auto DialogHeight::IsValid() const -> bool
{
return flagError && flagName;
return m_flagError && m_flagName;
}
#endif // DIALOGHEIGHT_H

View File

@ -60,25 +60,18 @@
DialogNormal::DialogNormal(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogNormal),
formula(),
angle(0),
formulaBaseHeight(0),
pointName(),
timerFormula(new QTimer(this)),
flagFormula(false),
flagName(true),
flagError(true)
m_timerFormula(new QTimer(this))
{
ui->setupUi(this);
timerFormula->setSingleShot(true);
connect(timerFormula, &QTimer::timeout, this, &DialogNormal::EvalFormula);
m_timerFormula->setSingleShot(true);
connect(m_timerFormula, &QTimer::timeout, this, &DialogNormal::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);
@ -101,12 +94,12 @@ DialogNormal::DialogNormal(const VContainer *data, quint32 toolId, QWidget *pare
connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogNormal::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, &DialogNormal::DeployFormulaTextEdit);
connect(ui->comboBoxFirstPoint, &QComboBox::currentTextChanged,
@ -126,12 +119,12 @@ void DialogNormal::PointNameChanged()
QColor color;
if (getCurrentObjectId(ui->comboBoxFirstPoint) == getCurrentObjectId(ui->comboBoxSecondPoint))
{
flagError = false;
m_flagError = false;
color = errorColor;
}
else
{
flagError = true;
m_flagError = true;
color = OkColor(this);
}
ChangeColor(ui->labelFirstPoint, color);
@ -142,7 +135,7 @@ void DialogNormal::PointNameChanged()
//---------------------------------------------------------------------------------------------------------------------
void DialogNormal::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));
@ -163,7 +156,7 @@ void DialogNormal::EvalFormula()
formulaData.labelResult = ui->labelResultCalculation;
formulaData.postfix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true);
Eval(formulaData, flagFormula);
Eval(formulaData, m_flagFormula);
}
//---------------------------------------------------------------------------------------------------------------------
@ -175,7 +168,7 @@ void DialogNormal::ShowVisualization()
//---------------------------------------------------------------------------------------------------------------------
void DialogNormal::DeployFormulaTextEdit()
{
DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLength, m_formulaBaseHeight);
}
//---------------------------------------------------------------------------------------------------------------------
@ -185,9 +178,9 @@ DialogNormal::~DialogNormal()
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogNormal::GetPointName() const
auto DialogNormal::GetPointName() const -> QString
{
return pointName;
return m_pointName;
}
//---------------------------------------------------------------------------------------------------------------------
@ -198,11 +191,14 @@ QString DialogNormal::GetPointName() const
*/
void DialogNormal::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::Point)
{
VisToolNormal *line = qobject_cast<VisToolNormal *>(vis);
auto *line = qobject_cast<VisToolNormal *>(vis);
SCASSERT(line != nullptr)
switch (number)
@ -231,23 +227,22 @@ void DialogNormal::ChosenObject(quint32 id, const SceneObject &type)
break;
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogNormal::SaveData()
{
pointName = ui->lineEditNamePoint->text();
formula = ui->plainTextEditFormula->toPlainText();
angle = ui->doubleSpinBoxAngle->value();
m_pointName = ui->lineEditNamePoint->text();
m_formula = ui->plainTextEditFormula->toPlainText();
m_angle = ui->doubleSpinBoxAngle->value();
VisToolNormal *line = qobject_cast<VisToolNormal *>(vis);
auto *line = qobject_cast<VisToolNormal *>(vis);
SCASSERT(line != nullptr)
line->setObject1Id(GetFirstPointId());
line->setObject2Id(GetSecondPointId());
line->setLength(formula);
line->SetAngle(angle);
line->setLength(m_formula);
line->SetAngle(m_angle);
line->setLineStyle(LineStyleToPenStyle(GetTypeLine()));
line->RefreshGeometry();
}
@ -268,13 +263,13 @@ void DialogNormal::SetSecondPointId(quint32 value)
{
setCurrentPointId(ui->comboBoxSecondPoint, value);
VisToolNormal *line = qobject_cast<VisToolNormal *>(vis);
auto *line = qobject_cast<VisToolNormal *>(vis);
SCASSERT(line != nullptr)
line->setObject2Id(value);
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogNormal::GetLineColor() const
auto DialogNormal::GetLineColor() const -> QString
{
return GetComboBoxCurrentData(ui->comboBoxLineColor, ColorBlack);
}
@ -294,7 +289,7 @@ void DialogNormal::SetFirstPointId(quint32 value)
{
setCurrentPointId(ui->comboBoxFirstPoint, value);
VisToolNormal *line = qobject_cast<VisToolNormal *>(vis);
auto *line = qobject_cast<VisToolNormal *>(vis);
SCASSERT(line != nullptr)
line->setObject1Id(value);
}
@ -306,12 +301,12 @@ void DialogNormal::SetFirstPointId(quint32 value)
*/
void DialogNormal::SetAngle(qreal value)
{
angle = value;
ui->doubleSpinBoxAngle->setValue(angle);
m_angle = value;
ui->doubleSpinBoxAngle->setValue(m_angle);
VisToolNormal *line = qobject_cast<VisToolNormal *>(vis);
auto *line = qobject_cast<VisToolNormal *>(vis);
SCASSERT(line != nullptr)
line->SetAngle(angle);
line->SetAngle(m_angle);
}
//---------------------------------------------------------------------------------------------------------------------
@ -321,18 +316,18 @@ void DialogNormal::SetAngle(qreal value)
*/
void DialogNormal::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);
VisToolNormal *line = qobject_cast<VisToolNormal *>(vis);
auto *line = qobject_cast<VisToolNormal *>(vis);
SCASSERT(line != nullptr)
line->setLength(formula);
line->setLength(m_formula);
MoveCursorToEnd(ui->plainTextEditFormula);
}
@ -355,8 +350,8 @@ void DialogNormal::SetTypeLine(const QString &value)
*/
void DialogNormal::SetPointName(const QString &value)
{
pointName = value;
ui->lineEditNamePoint->setText(pointName);
m_pointName = value;
ui->lineEditNamePoint->setText(m_pointName);
}
//---------------------------------------------------------------------------------------------------------------------
@ -364,7 +359,7 @@ void DialogNormal::SetPointName(const QString &value)
* @brief GetTypeLine return type of line
* @return type
*/
QString DialogNormal::GetTypeLine() const
auto DialogNormal::GetTypeLine() const -> QString
{
return GetComboBoxCurrentData(ui->comboBoxLineType, TypeLineLine);
}
@ -374,9 +369,9 @@ QString DialogNormal::GetTypeLine() const
* @brief GetFormula return string of formula
* @return formula
*/
QString DialogNormal::GetFormula() const
auto DialogNormal::GetFormula() const -> QString
{
return VTranslateVars::TryFormulaFromUser(formula, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
return VTranslateVars::TryFormulaFromUser(m_formula, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
}
//---------------------------------------------------------------------------------------------------------------------
@ -384,9 +379,9 @@ QString DialogNormal::GetFormula() const
* @brief GetAngle return aditional angle of normal
* @return angle in degree
*/
qreal DialogNormal::GetAngle() const
auto DialogNormal::GetAngle() const -> qreal
{
return angle;
return m_angle;
}
//---------------------------------------------------------------------------------------------------------------------
@ -394,7 +389,7 @@ qreal DialogNormal::GetAngle() const
* @brief GetFirstPointId return id of first point
* @return id
*/
quint32 DialogNormal::GetFirstPointId() const
auto DialogNormal::GetFirstPointId() const -> quint32
{
return getCurrentObjectId(ui->comboBoxFirstPoint);
}
@ -404,7 +399,7 @@ quint32 DialogNormal::GetFirstPointId() const
* @brief GetSecondPointId return id of second point
* @return id
*/
quint32 DialogNormal::GetSecondPointId() const
auto DialogNormal::GetSecondPointId() const -> quint32
{
return getCurrentObjectId(ui->comboBoxSecondPoint);
}
@ -416,7 +411,7 @@ void DialogNormal::SetNotes(const QString &notes)
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogNormal::GetNotes() const
auto DialogNormal::GetNotes() const -> QString
{
return ui->plainTextEditToolNotes->toPlainText();
}

View File

@ -51,48 +51,48 @@ class DialogNormal : public DialogTool
Q_OBJECT // NOLINT
public:
DialogNormal(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogNormal() override;
~DialogNormal() 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);
qreal GetAngle() const;
auto GetAngle() const -> qreal;
void SetAngle(qreal value);
quint32 GetFirstPointId() const;
auto GetFirstPointId() const -> quint32;
void SetFirstPointId(quint32 value);
quint32 GetSecondPointId() const;
auto GetSecondPointId() const -> quint32;
void SetSecondPointId(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(DialogNormal) // NOLINT
@ -100,27 +100,29 @@ private:
Ui::DialogNormal *ui;
/** @brief formula formula */
QString formula;
QString m_formula{};
/** @brief angle aditional angle of normal */
qreal angle;
qreal m_angle{0};
/** @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 flagError;
bool m_flagFormula{false};
bool m_flagName{true};
bool m_flagError{true};
bool m_firstRelease{false};
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogNormal::IsValid() const
inline auto DialogNormal::IsValid() const -> bool
{
return flagFormula && flagName && flagError;
return m_flagFormula && m_flagName && m_flagError;
}
#endif // DIALOGNORMAL_H

View File

@ -56,7 +56,7 @@
template <class T> class QSharedPointer;
const QString VToolAlongLine::ToolType = QStringLiteral("alongLine");
const QString VToolAlongLine::ToolType = QStringLiteral("alongLine"); // NOLINT(cert-err58-cpp)
//---------------------------------------------------------------------------------------------------------------------
/**
@ -67,7 +67,7 @@ const QString VToolAlongLine::ToolType = QStringLiteral("alongLine");
VToolAlongLine::VToolAlongLine(const VToolAlongLineInitData &initData, QGraphicsItem *parent)
:VToolLinePoint(initData.doc, initData.data, initData.id, initData.typeLine, initData.lineColor, initData.formula,
initData.firstPointId, 0, initData.notes, parent),
secondPointId(initData.secondPointId)
m_secondPointId(initData.secondPointId)
{
ToolCreation(initData.typeCreation);
}
@ -78,7 +78,7 @@ VToolAlongLine::VToolAlongLine(const VToolAlongLineInitData &initData, QGraphics
*/
void VToolAlongLine::RemoveReferens()
{
const auto secondPoint = VAbstractTool::data.GetGObject(secondPointId);
const auto secondPoint = VAbstractTool::data.GetGObject(m_secondPointId);
doc->DecrementReferens(secondPoint->getIdTool());
VToolLinePoint::RemoveReferens();
}
@ -95,7 +95,7 @@ void VToolAlongLine::SaveDialog(QDomElement &domElement, QList<quint32> &oldDepe
SCASSERT(not dialogTool.isNull())
AddDependence(oldDependencies, basePointId);
AddDependence(oldDependencies, secondPointId);
AddDependence(oldDependencies, m_secondPointId);
AddDependence(newDependencies, dialogTool->GetFirstPointId());
AddDependence(newDependencies, dialogTool->GetSecondPointId());
@ -119,7 +119,7 @@ void VToolAlongLine::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj
doc->SetAttribute(tag, AttrType, ToolType);
doc->SetAttribute(tag, AttrLength, formulaLength);
doc->SetAttribute(tag, AttrFirstPoint, basePointId);
doc->SetAttribute(tag, AttrSecondPoint, secondPointId);
doc->SetAttribute(tag, AttrSecondPoint, m_secondPointId);
}
//---------------------------------------------------------------------------------------------------------------------
@ -127,11 +127,11 @@ void VToolAlongLine::ReadToolAttributes(const QDomElement &domElement)
{
VToolLinePoint::ReadToolAttributes(domElement);
m_lineType = doc->GetParametrString(domElement, AttrTypeLine, TypeLineLine);
lineColor = doc->GetParametrString(domElement, AttrLineColor, ColorBlack);
formulaLength = doc->GetParametrString(domElement, AttrLength, QString());
basePointId = doc->GetParametrUInt(domElement, AttrFirstPoint, NULL_ID_STR);
secondPointId = doc->GetParametrUInt(domElement, AttrSecondPoint, NULL_ID_STR);
m_lineType = VDomDocument::GetParametrString(domElement, AttrTypeLine, TypeLineLine);
lineColor = VDomDocument::GetParametrString(domElement, AttrLineColor, ColorBlack);
formulaLength = VDomDocument::GetParametrString(domElement, AttrLength, QString());
basePointId = VDomDocument::GetParametrUInt(domElement, AttrFirstPoint, NULL_ID_STR);
m_secondPointId = VDomDocument::GetParametrUInt(domElement, AttrSecondPoint, NULL_ID_STR);
}
//---------------------------------------------------------------------------------------------------------------------
@ -139,10 +139,10 @@ void VToolAlongLine::SetVisualization()
{
if (not vis.isNull())
{
VisToolAlongLine *visual = qobject_cast<VisToolAlongLine *>(vis);
auto *visual = qobject_cast<VisToolAlongLine *>(vis);
SCASSERT(visual != nullptr)
visual->setObject1Id(basePointId);
visual->setObject2Id(secondPointId);
visual->setObject2Id(m_secondPointId);
visual->setLength(VAbstractApplication::VApp()->TrVars()
->FormulaToUser(formulaLength, VAbstractApplication::VApp()->Settings()->GetOsSeparator()));
visual->setLineStyle(LineStyleToPenStyle(m_lineType));
@ -151,10 +151,10 @@ void VToolAlongLine::SetVisualization()
}
//---------------------------------------------------------------------------------------------------------------------
QString VToolAlongLine::MakeToolTip() const
auto VToolAlongLine::MakeToolTip() const -> QString
{
const QSharedPointer<VPointF> basePoint = VAbstractTool::data.GeometricObject<VPointF>(basePointId);
const QSharedPointer<VPointF> secondPoint = VAbstractTool::data.GeometricObject<VPointF>(secondPointId);
const QSharedPointer<VPointF> secondPoint = VAbstractTool::data.GeometricObject<VPointF>(m_secondPointId);
const QSharedPointer<VPointF> current = VAbstractTool::data.GeometricObject<VPointF>(m_id);
const QLineF curLine(static_cast<QPointF>(*basePoint), static_cast<QPointF>(*current));
@ -212,7 +212,7 @@ void VToolAlongLine::setDialog()
dialogTool->SetLineColor(lineColor);
dialogTool->SetFormula(formulaLength);
dialogTool->SetFirstPointId(basePointId);
dialogTool->SetSecondPointId(secondPointId);
dialogTool->SetSecondPointId(m_secondPointId);
dialogTool->SetPointName(p->name());
dialogTool->SetNotes(m_notes);
}
@ -225,8 +225,8 @@ void VToolAlongLine::setDialog()
* @param doc dom document container.
* @param data container with variables.
*/
VToolAlongLine* VToolAlongLine::Create(const QPointer<DialogTool> &dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data)
auto VToolAlongLine::Create(const QPointer<DialogTool> &dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data) -> VToolAlongLine*
{
SCASSERT(not dialog.isNull())
const QPointer<DialogAlongLine> dialogTool = qobject_cast<DialogAlongLine *>(dialog);
@ -259,14 +259,14 @@ VToolAlongLine* VToolAlongLine::Create(const QPointer<DialogTool> &dialog, VMain
* @brief Create help create tool.
* @param initData init data.
*/
VToolAlongLine* VToolAlongLine::Create(VToolAlongLineInitData &initData)
auto VToolAlongLine::Create(VToolAlongLineInitData &initData) -> VToolAlongLine*
{
const QSharedPointer<VPointF> firstPoint = initData.data->GeometricObject<VPointF>(initData.firstPointId);
const QSharedPointer<VPointF> secondPoint = initData.data->GeometricObject<VPointF>(initData.secondPointId);
QLineF line = QLineF(static_cast<QPointF>(*firstPoint), static_cast<QPointF>(*secondPoint));
//Declare special variable "CurrentLength"
VLengthLine *length = new VLengthLine(firstPoint.data(), initData.firstPointId, secondPoint.data(),
auto *length = new VLengthLine(firstPoint.data(), initData.firstPointId, secondPoint.data(),
initData.secondPointId, *initData.data->GetPatternUnit());
length->SetName(currentLength);
initData.data->AddVariable(length);
@ -274,7 +274,7 @@ VToolAlongLine* VToolAlongLine::Create(VToolAlongLineInitData &initData)
line.setLength(VAbstractValApplication::VApp()->toPixel(
CheckFormula(initData.id, initData.formula, initData.data)));
VPointF *p = new VPointF(line.p2(), initData.name, initData.mx, initData.my);
auto *p = new VPointF(line.p2(), initData.name, initData.mx, initData.my);
p->SetShowLabel(initData.showLabel);
if (initData.typeCreation == Source::FromGui)
@ -311,7 +311,7 @@ VToolAlongLine* VToolAlongLine::Create(VToolAlongLineInitData &initData)
}
//---------------------------------------------------------------------------------------------------------------------
QString VToolAlongLine::SecondPointName() const
auto VToolAlongLine::SecondPointName() const -> QString
{
return VAbstractTool::data.GetGObject(secondPointId)->name();
return VAbstractTool::data.GetGObject(m_secondPointId)->name();
}

View File

@ -45,16 +45,11 @@ template <class T> class QSharedPointer;
struct VToolAlongLineInitData : VToolLinePointInitData
{
VToolAlongLineInitData()
: VToolLinePointInitData(),
formula("100.0"),
firstPointId(NULL_ID),
secondPointId(NULL_ID)
{}
VToolAlongLineInitData() = default;
QString formula;
quint32 firstPointId;
quint32 secondPointId;
QString formula{QStringLiteral("100.0")}; // NOLINT(misc-non-private-member-variables-in-classes)
quint32 firstPointId{NULL_ID}; // NOLINT(misc-non-private-member-variables-in-classes)
quint32 secondPointId{NULL_ID}; // NOLINT(misc-non-private-member-variables-in-classes)
};
/**
@ -64,34 +59,35 @@ class VToolAlongLine : public VToolLinePoint
{
Q_OBJECT // NOLINT
public:
virtual void setDialog() override;
static VToolAlongLine* Create(const QPointer<DialogTool> &dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data);
static VToolAlongLine* Create(VToolAlongLineInitData &initData);
~VToolAlongLine() override = default;
void setDialog() override;
static auto Create(const QPointer<DialogTool> &dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data) -> VToolAlongLine*;
static auto Create(VToolAlongLineInitData &initData) -> VToolAlongLine*;
static const QString ToolType;
virtual int type() const override {return Type;}
auto type() const -> int override {return Type;}
enum { Type = UserType + static_cast<int>(Tool::AlongLine)};
QString SecondPointName() const;
auto SecondPointName() const -> QString;
virtual void ShowVisualization(bool show) override;
void ShowVisualization(bool show) override;
protected slots:
virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 id=NULL_ID) override;
void ShowContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 id=NULL_ID) override;
protected:
virtual void RemoveReferens() override;
virtual void SaveDialog(QDomElement &domElement, QList<quint32> &oldDependencies,
QList<quint32> &newDependencies) override;
virtual void SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj) override;
virtual void ReadToolAttributes(const QDomElement &domElement) override;
virtual void SetVisualization() override;
virtual QString MakeToolTip() const override;
void RemoveReferens() override;
void SaveDialog(QDomElement &domElement, QList<quint32> &oldDependencies, QList<quint32> &newDependencies) override;
void SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj) override;
void ReadToolAttributes(const QDomElement &domElement) override;
void SetVisualization() override;
auto MakeToolTip() const -> QString override;
private:
Q_DISABLE_COPY_MOVE(VToolAlongLine) // NOLINT
/** @brief secondPointId id second point of line. */
quint32 secondPointId;
quint32 m_secondPointId;
VToolAlongLine(const VToolAlongLineInitData &initData, QGraphicsItem *parent = nullptr);
explicit VToolAlongLine(const VToolAlongLineInitData &initData, QGraphicsItem *parent = nullptr);
};
#endif // VTOOLALONGLINE_H

View File

@ -45,34 +45,27 @@
//---------------------------------------------------------------------------------------------------------------------
VisToolAlongLine::VisToolAlongLine(const VContainer *data, QGraphicsItem *parent)
: VisLine(data, parent),
object2Id(NULL_ID),
point(nullptr),
lineP1(nullptr),
lineP2(nullptr),
line(nullptr),
length(0),
m_midPointMode(false)
: VisLine(data, parent)
{
this->mainColor = Qt::red;
this->setZValue(2);// Show on top real tool
lineP1 = InitPoint(supportColor, this);
lineP2 = InitPoint(supportColor, this); //-V656
line = InitItem<VScaledLine>(supportColor, this);
point = InitPoint(mainColor, this);
m_lineP1 = InitPoint(supportColor, this);
m_lineP2 = InitPoint(supportColor, this); //-V656
m_line = InitItem<VScaledLine>(supportColor, this);
m_point = InitPoint(mainColor, this);
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolAlongLine::setObject2Id(const quint32 &value)
{
object2Id = value;
m_object2Id = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolAlongLine::setLength(const QString &expression)
{
length = FindLengthFromUser(expression, Visualization::data->DataVariables());
m_length = FindLengthFromUser(expression, Visualization::data->DataVariables());
}
//---------------------------------------------------------------------------------------------------------------------
@ -87,33 +80,33 @@ void VisToolAlongLine::RefreshGeometry()
if (object1Id > NULL_ID)
{
const QSharedPointer<VPointF> first = Visualization::data->GeometricObject<VPointF>(object1Id);
DrawPoint(lineP1, static_cast<QPointF>(*first), supportColor);
DrawPoint(m_lineP1, static_cast<QPointF>(*first), supportColor);
if (object2Id <= NULL_ID)
if (m_object2Id <= NULL_ID)
{
QLineF cursorLine (static_cast<QPointF>(*first), Visualization::scenePos);
DrawLine(line, cursorLine, supportColor);
DrawLine(m_line, cursorLine, supportColor);
if (m_midPointMode)
{
cursorLine.setLength(cursorLine.length()/2.0);
DrawPoint(point, cursorLine.p2(), mainColor);
DrawPoint(m_point, cursorLine.p2(), mainColor);
}
}
else
{
const QSharedPointer<VPointF> second = Visualization::data->GeometricObject<VPointF>(object2Id);
DrawPoint(lineP2, static_cast<QPointF>(*second), supportColor);
const QSharedPointer<VPointF> second = Visualization::data->GeometricObject<VPointF>(m_object2Id);
DrawPoint(m_lineP2, static_cast<QPointF>(*second), supportColor);
QLineF baseLine(static_cast<QPointF>(*first), static_cast<QPointF>(*second));
DrawLine(line, baseLine, supportColor);
DrawLine(m_line, baseLine, supportColor);
if (not qFuzzyIsNull(length))
if (not qFuzzyIsNull(m_length))
{
QLineF mainLine = VGObject::BuildLine(static_cast<QPointF>(*first), length, line->line().angle());
QLineF mainLine = VGObject::BuildLine(static_cast<QPointF>(*first), m_length, m_line->line().angle());
DrawLine(this, mainLine, mainColor, lineStyle);
DrawPoint(point, mainLine.p2(), mainColor);
DrawPoint(m_point, mainLine.p2(), mainColor);
}
else if (mode == Mode::Creation)
{
@ -126,10 +119,10 @@ void VisToolAlongLine::RefreshGeometry()
len *= -1;
}
QLineF mainLine = VGObject::BuildLine(static_cast<QPointF>(*first), len, line->line().angle());
QLineF mainLine = VGObject::BuildLine(static_cast<QPointF>(*first), len, m_line->line().angle());
DrawLine(this, mainLine, mainColor, lineStyle);
DrawPoint(point, mainLine.p2(), mainColor);
DrawPoint(m_point, mainLine.p2(), mainColor);
const QString prefix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true);
Visualization::toolTip = tr("Length = %1%2; "

View File

@ -44,24 +44,25 @@ class VisToolAlongLine final :public VisLine
Q_OBJECT // NOLINT
public:
explicit VisToolAlongLine(const VContainer *data, QGraphicsItem *parent = nullptr);
virtual ~VisToolAlongLine() = default;
~VisToolAlongLine() override = default;
virtual void RefreshGeometry() override;
void RefreshGeometry() override;
void setObject2Id(const quint32 &value);
void setLength(const QString &expression);
void setMidPointMode(bool midPointMode);
virtual int type() const override {return Type;}
enum { Type = UserType + static_cast<int>(Vis::ToolAlongLine)};
auto type() const -> int override {return Type;}
enum {Type = UserType + static_cast<int>(Vis::ToolAlongLine)};
private:
// cppcheck-suppress unknownMacro
Q_DISABLE_COPY_MOVE(VisToolAlongLine) // NOLINT
quint32 object2Id;
VScaledEllipse *point;
VScaledEllipse *lineP1;
VScaledEllipse *lineP2;
VScaledLine *line;
qreal length;
bool m_midPointMode;
quint32 m_object2Id{NULL_ID};
VScaledEllipse *m_point{nullptr};
VScaledEllipse *m_lineP1{nullptr};
VScaledEllipse *m_lineP2{nullptr};
VScaledLine *m_line{nullptr};
qreal m_length{0};
bool m_midPointMode{false};
};
#endif // VISTOOLALONGLINE_H