Refactoring.

Code style.
This commit is contained in:
Roman Telezhynskyi 2023-11-14 15:28:43 +02:00
parent 03a1b53276
commit 6ddefa9d99
11 changed files with 59 additions and 51 deletions

View File

@ -636,7 +636,7 @@ void MainWindowsNoGUI::ExportDetailsAsFlatLayout(const QVector<VLayoutPiece> &li
QList<QGraphicsScene *> scenes = CreateScenes(papers, shadows, details); QList<QGraphicsScene *> scenes = CreateScenes(papers, shadows, details);
const bool ignorePrinterFields = false; const bool ignorePrinterFields = false;
const qreal margin = ToPixel(1, Unit::Cm); Q_RELAXED_CONSTEXPR qreal margin = ToPixel(1, Unit::Cm);
ExportFlatLayout(scenes, papers, shadows, details, ignorePrinterFields, QMarginsF(margin, margin, margin, margin)); ExportFlatLayout(scenes, papers, shadows, details, ignorePrinterFields, QMarginsF(margin, margin, margin, margin));
qDeleteAll(scenes); // Scene will clear all other items qDeleteAll(scenes); // Scene will clear all other items

View File

@ -758,15 +758,14 @@ Q_DECL_RELAXED_CONSTEXPR static inline auto VFuzzyComparePossibleNulls(double p1
{ {
return qFuzzyIsNull(p2); return qFuzzyIsNull(p2);
} }
else if (qFuzzyIsNull(p2))
if (qFuzzyIsNull(p2))
{ {
return false; return false;
} }
else
{
return qFuzzyCompare(p1, p2); return qFuzzyCompare(p1, p2);
} }
}
/** /**
* @brief The CustomSA struct contains record about custom seam allowanse (SA). * @brief The CustomSA struct contains record about custom seam allowanse (SA).

View File

@ -44,9 +44,9 @@
#include "../../visualization/line/vistoolalongline.h" #include "../../visualization/line/vistoolalongline.h"
#include "../../visualization/visualization.h" #include "../../visualization/visualization.h"
#include "../ifc/ifcdef.h"
#include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vabstractpattern.h"
#include "../support/dialogeditwrongformula.h" #include "../support/dialogeditwrongformula.h"
#include "../vgeometry/../ifc/ifcdef.h"
#include "../vgeometry/vpointf.h" #include "../vgeometry/vpointf.h"
#include "../vmisc/theme/vtheme.h" #include "../vmisc/theme/vtheme.h"
#include "../vmisc/vabstractapplication.h" #include "../vmisc/vabstractapplication.h"
@ -57,6 +57,12 @@
#include "../vwidgets/vabstractmainwindow.h" #include "../vwidgets/vabstractmainwindow.h"
#include "ui_dialogalongline.h" #include "ui_dialogalongline.h"
#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
#include "../vmisc/compatibility.h"
#endif
using namespace Qt::Literals::StringLiterals;
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief DialogAlongLine create dialog * @brief DialogAlongLine create dialog
@ -297,7 +303,7 @@ void DialogAlongLine::ChosenSecondPoint(quint32 id, const QString &toolTip)
line->SetPoint2Id(id); line->SetPoint2Id(id);
if (m_buildMidpoint) if (m_buildMidpoint)
{ {
SetFormula(currentLength + QStringLiteral("/2")); SetFormula(currentLength + "/2"_L1);
line->SetMode(Mode::Show); line->SetMode(Mode::Show);
} }
else else

View File

@ -162,7 +162,7 @@ void DialogCurveIntersectAxis::SetAngle(const QString &value)
} }
ui->plainTextEditFormula->setPlainText(formulaAngle); ui->plainTextEditFormula->setPlainText(formulaAngle);
VisToolCurveIntersectAxis *line = qobject_cast<VisToolCurveIntersectAxis *>(vis); auto *line = qobject_cast<VisToolCurveIntersectAxis *>(vis);
SCASSERT(line != nullptr) SCASSERT(line != nullptr)
line->SetAngle(formulaAngle); line->SetAngle(formulaAngle);
@ -180,7 +180,7 @@ void DialogCurveIntersectAxis::SetBasePointId(quint32 value)
{ {
setCurrentPointId(ui->comboBoxAxisPoint, value); setCurrentPointId(ui->comboBoxAxisPoint, value);
VisToolCurveIntersectAxis *line = qobject_cast<VisToolCurveIntersectAxis *>(vis); auto *line = qobject_cast<VisToolCurveIntersectAxis *>(vis);
SCASSERT(line != nullptr) SCASSERT(line != nullptr)
line->setAxisPointId(value); line->setAxisPointId(value);
} }
@ -196,7 +196,7 @@ void DialogCurveIntersectAxis::setCurveId(quint32 value)
{ {
setCurrentCurveId(ui->comboBoxCurve, value); setCurrentCurveId(ui->comboBoxCurve, value);
VisToolCurveIntersectAxis *line = qobject_cast<VisToolCurveIntersectAxis *>(vis); auto *line = qobject_cast<VisToolCurveIntersectAxis *>(vis);
SCASSERT(line != nullptr) SCASSERT(line != nullptr)
line->SetCurveId(value); line->SetCurveId(value);
} }
@ -268,7 +268,7 @@ void DialogCurveIntersectAxis::ChosenObject(quint32 id, const SceneObject &type)
{ {
number++; number++;
line->VisualMode(id); line->VisualMode(id);
VAbstractMainWindow *window = auto *window =
qobject_cast<VAbstractMainWindow *>(VAbstractValApplication::VApp()->getMainWindow()); qobject_cast<VAbstractMainWindow *>(VAbstractValApplication::VApp()->getMainWindow());
SCASSERT(window != nullptr) SCASSERT(window != nullptr)
connect(line, &VisToolCurveIntersectAxis::ToolTip, window, &VAbstractMainWindow::ShowToolTip); connect(line, &VisToolCurveIntersectAxis::ToolTip, window, &VAbstractMainWindow::ShowToolTip);
@ -323,7 +323,7 @@ void DialogCurveIntersectAxis::DeployAngleTextEdit()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogCurveIntersectAxis::FXAngle() void DialogCurveIntersectAxis::FXAngle()
{ {
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); auto *dialog = new DialogEditWrongFormula(data, toolId, this);
dialog->setWindowTitle(tr("Edit angle")); dialog->setWindowTitle(tr("Edit angle"));
dialog->SetFormula(GetAngle()); dialog->SetFormula(GetAngle());
dialog->setPostfix(degreeSymbol); dialog->setPostfix(degreeSymbol);
@ -346,7 +346,7 @@ void DialogCurveIntersectAxis::SaveData()
pointName = ui->lineEditNamePoint->text(); pointName = ui->lineEditNamePoint->text();
formulaAngle = ui->plainTextEditFormula->toPlainText(); formulaAngle = ui->plainTextEditFormula->toPlainText();
VisToolCurveIntersectAxis *line = qobject_cast<VisToolCurveIntersectAxis *>(vis); auto *line = qobject_cast<VisToolCurveIntersectAxis *>(vis);
SCASSERT(line != nullptr) SCASSERT(line != nullptr)
line->SetCurveId(getCurveId()); line->SetCurveId(getCurveId());

View File

@ -175,7 +175,7 @@ void DialogEndLine::DeployAngleTextEdit()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogEndLine::FXAngle() void DialogEndLine::FXAngle()
{ {
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); auto *dialog = new DialogEditWrongFormula(data, toolId, this);
dialog->setWindowTitle(tr("Edit angle")); dialog->setWindowTitle(tr("Edit angle"));
dialog->SetFormula(GetAngle()); dialog->SetFormula(GetAngle());
dialog->setPostfix(degreeSymbol); dialog->setPostfix(degreeSymbol);
@ -189,7 +189,7 @@ void DialogEndLine::FXAngle()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogEndLine::FXLength() void DialogEndLine::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));
@ -381,7 +381,7 @@ void DialogEndLine::SaveData()
formulaLength = ui->plainTextEditFormula->toPlainText(); formulaLength = ui->plainTextEditFormula->toPlainText();
formulaAngle = ui->plainTextEditAngle->toPlainText(); formulaAngle = ui->plainTextEditAngle->toPlainText();
VisToolEndLine *line = qobject_cast<VisToolEndLine *>(vis); auto *line = qobject_cast<VisToolEndLine *>(vis);
SCASSERT(line != nullptr) SCASSERT(line != nullptr)
line->SetBasePointId(GetBasePointId()); line->SetBasePointId(GetBasePointId());

View File

@ -77,7 +77,7 @@ auto GetOriginPoint(const QVector<SourceItem> &objects, const VContainer *data,
{ {
QPolygonF originObjects; QPolygonF originObjects;
for (auto object : objects) for (const auto &object : objects)
{ {
const QSharedPointer<VGObject> obj = data->GetGObject(object.id); const QSharedPointer<VGObject> obj = data->GetGObject(object.id);
@ -193,7 +193,7 @@ auto VToolMove::Create(VToolMoveInitData &initData) -> VToolMove *
initData.id = initData.data->getNextId(); // Just reserve id for tool initData.id = initData.data->getNextId(); // Just reserve id for tool
for (auto object : qAsConst(initData.source)) for (const auto &object : qAsConst(initData.source))
{ {
const QSharedPointer<VGObject> obj = initData.data->GetGObject(object.id); const QSharedPointer<VGObject> obj = initData.data->GetGObject(object.id);
@ -314,7 +314,7 @@ auto VToolMove::Create(VToolMoveInitData &initData) -> VToolMove *
} }
VAbstractTool::AddRecord(initData.id, Tool::Move, initData.doc); VAbstractTool::AddRecord(initData.id, Tool::Move, initData.doc);
VToolMove *tool = new VToolMove(initData); auto *tool = new VToolMove(initData);
initData.scene->addItem(tool); initData.scene->addItem(tool);
InitOperationToolConnections(initData.scene, tool); InitOperationToolConnections(initData.scene, tool);
VAbstractPattern::AddTool(initData.id, tool); VAbstractPattern::AddTool(initData.id, tool);
@ -324,7 +324,7 @@ auto VToolMove::Create(VToolMoveInitData &initData) -> VToolMove *
initData.doc->IncrementReferens(originPoint->getIdTool()); initData.doc->IncrementReferens(originPoint->getIdTool());
} }
for (auto object : qAsConst(initData.source)) for (const auto &object : qAsConst(initData.source))
{ {
initData.doc->IncrementReferens(initData.data->GetGObject(object.id)->getIdTool()); initData.doc->IncrementReferens(initData.data->GetGObject(object.id)->getIdTool());
} }
@ -354,7 +354,7 @@ auto VToolMove::GetFormulaAngle() const -> VFormula
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolMove::SetFormulaAngle(const VFormula &value) void VToolMove::SetFormulaAngle(const VFormula &value)
{ {
if (value.error() == false) if (!value.error())
{ {
formulaAngle = value.GetFormula(FormulaType::FromUser); formulaAngle = value.GetFormula(FormulaType::FromUser);
@ -377,7 +377,7 @@ auto VToolMove::GetFormulaRotationAngle() const -> VFormula
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolMove::SetFormulaRotationAngle(const VFormula &value) void VToolMove::SetFormulaRotationAngle(const VFormula &value)
{ {
if (value.error() == false) if (!value.error())
{ {
formulaRotationAngle = value.GetFormula(FormulaType::FromUser); formulaRotationAngle = value.GetFormula(FormulaType::FromUser);
@ -493,10 +493,10 @@ void VToolMove::ReadToolAttributes(const QDomElement &domElement)
{ {
VAbstractOperation::ReadToolAttributes(domElement); VAbstractOperation::ReadToolAttributes(domElement);
origPointId = doc->GetParametrUInt(domElement, AttrCenter, NULL_ID_STR); origPointId = VDomDocument::GetParametrUInt(domElement, AttrCenter, NULL_ID_STR);
formulaAngle = doc->GetParametrString(domElement, AttrAngle, QChar('0')); formulaAngle = VDomDocument::GetParametrString(domElement, AttrAngle, QChar('0'));
formulaRotationAngle = doc->GetParametrString(domElement, AttrRotationAngle, QChar('0')); formulaRotationAngle = VDomDocument::GetParametrString(domElement, AttrRotationAngle, QChar('0'));
formulaLength = doc->GetParametrString(domElement, AttrLength, QChar('0')); formulaLength = VDomDocument::GetParametrString(domElement, AttrLength, QChar('0'));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -527,8 +527,8 @@ auto VToolMove::MakeToolTip() const -> QString
tr("Rotation angle")) // 6 tr("Rotation angle")) // 6
.arg(GetFormulaRotationAngle().getDoubleValue()) // 7 .arg(GetFormulaRotationAngle().getDoubleValue()) // 7
.arg(tr("Rotation origin point"), // 8 .arg(tr("Rotation origin point"), // 8
OriginPointName()) // 9 OriginPointName(), // 9
.arg(VisibilityGroupToolTip()); // 10 VisibilityGroupToolTip()); // 10
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -216,7 +216,7 @@ auto VToolEllipticalArc::GetFormulaRadius1() const -> VFormula
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolEllipticalArc::SetFormulaRadius1(const VFormula &value) void VToolEllipticalArc::SetFormulaRadius1(const VFormula &value)
{ {
if (value.error() == false) if (!value.error())
{ {
if (value.getDoubleValue() > 0) // Formula don't check this, but radius1 can't be 0 or negative if (value.getDoubleValue() > 0) // Formula don't check this, but radius1 can't be 0 or negative
{ {
@ -245,7 +245,7 @@ auto VToolEllipticalArc::GetFormulaRadius2() const -> VFormula
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolEllipticalArc::SetFormulaRadius2(const VFormula &value) void VToolEllipticalArc::SetFormulaRadius2(const VFormula &value)
{ {
if (value.error() == false) if (!value.error())
{ {
if (value.getDoubleValue() > 0) // Formula don't check this, but radius2 can't be 0 or negative if (value.getDoubleValue() > 0) // Formula don't check this, but radius2 can't be 0 or negative
{ {
@ -274,7 +274,7 @@ auto VToolEllipticalArc::GetFormulaF1() const -> VFormula
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolEllipticalArc::SetFormulaF1(const VFormula &value) void VToolEllipticalArc::SetFormulaF1(const VFormula &value)
{ {
if (value.error() == false) if (!value.error())
{ {
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(m_id); QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(m_id);
QSharedPointer<VEllipticalArc> elArc = qSharedPointerDynamicCast<VEllipticalArc>(obj); QSharedPointer<VEllipticalArc> elArc = qSharedPointerDynamicCast<VEllipticalArc>(obj);
@ -300,7 +300,7 @@ auto VToolEllipticalArc::GetFormulaF2() const -> VFormula
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolEllipticalArc::SetFormulaF2(const VFormula &value) void VToolEllipticalArc::SetFormulaF2(const VFormula &value)
{ {
if (value.error() == false) if (!value.error())
{ {
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(m_id); QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(m_id);
QSharedPointer<VEllipticalArc> elArc = qSharedPointerDynamicCast<VEllipticalArc>(obj); QSharedPointer<VEllipticalArc> elArc = qSharedPointerDynamicCast<VEllipticalArc>(obj);
@ -326,7 +326,7 @@ auto VToolEllipticalArc::GetFormulaRotationAngle() const -> VFormula
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolEllipticalArc::SetFormulaRotationAngle(const VFormula &value) void VToolEllipticalArc::SetFormulaRotationAngle(const VFormula &value)
{ {
if (value.error() == false) if (!value.error())
{ {
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(m_id); QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(m_id);
QSharedPointer<VEllipticalArc> elArc = qSharedPointerDynamicCast<VEllipticalArc>(obj); QSharedPointer<VEllipticalArc> elArc = qSharedPointerDynamicCast<VEllipticalArc>(obj);

View File

@ -29,7 +29,6 @@
#ifndef VISTOOLMOVE_H #ifndef VISTOOLMOVE_H
#define VISTOOLMOVE_H #define VISTOOLMOVE_H
#include <QColor> #include <QColor>
#include <QGraphicsItem> #include <QGraphicsItem>
#include <QMetaObject> #include <QMetaObject>
@ -45,6 +44,7 @@
class VisToolMove : public VisOperation class VisToolMove : public VisOperation
{ {
Q_OBJECT // NOLINT Q_OBJECT // NOLINT
public: public:
explicit VisToolMove(const VContainer *data, QGraphicsItem *parent = nullptr); explicit VisToolMove(const VContainer *data, QGraphicsItem *parent = nullptr);
~VisToolMove() override = default; ~VisToolMove() override = default;
@ -64,7 +64,11 @@ public:
void SetRotationOriginPointId(quint32 value); void SetRotationOriginPointId(quint32 value);
auto type() const -> int override { return Type; } auto type() const -> int override { return Type; }
enum {Type = UserType + static_cast<int>(Vis::ToolMove)}; enum
{
Type = UserType + static_cast<int>(Vis::ToolMove)
};
private: private:
// cppcheck-suppress unknownMacro // cppcheck-suppress unknownMacro
Q_DISABLE_COPY_MOVE(VisToolMove) // NOLINT Q_DISABLE_COPY_MOVE(VisToolMove) // NOLINT
@ -79,8 +83,7 @@ private:
VScaledLine *m_xAxis{nullptr}; VScaledLine *m_xAxis{nullptr};
quint32 m_rotationOriginId{NULL_ID}; quint32 m_rotationOriginId{NULL_ID};
template <class Item> template <class Item> auto AddOriginCurve(quint32 id, int &i) -> QGraphicsPathItem *;
auto AddOriginCurve(quint32 id, int &i) -> QGraphicsPathItem *;
template <class Item> template <class Item>
auto AddMovedRotatedCurve(qreal angle, qreal length, quint32 id, int i, qreal rotationAngle, auto AddMovedRotatedCurve(qreal angle, qreal length, quint32 id, int i, qreal rotationAngle,

View File

@ -288,14 +288,13 @@ auto Visualization::GetCurveItem(QVector<VCurvePathItem *> &curves, quint32 i, V
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto Visualization::LengthToUser(qreal value) -> QString auto Visualization::LengthToUser(qreal value) -> QString
{ {
return VAbstractApplication::VApp()->TrVars()->FormulaToUser( auto *app = VAbstractValApplication::VApp();
QString::number(VAbstractValApplication::VApp()->fromPixel(value)), return app->TrVars()->FormulaToUser(QString::number(app->fromPixel(value)), app->Settings()->GetOsSeparator());
VAbstractApplication::VApp()->Settings()->GetOsSeparator());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto Visualization::AngleToUser(qreal value) -> QString auto Visualization::AngleToUser(qreal value) -> QString
{ {
return VAbstractApplication::VApp()->TrVars()->FormulaToUser( auto *app = VAbstractApplication::VApp();
QString::number(value), VAbstractApplication::VApp()->Settings()->GetOsSeparator()); return app->TrVars()->FormulaToUser(QString::number(value), app->Settings()->GetOsSeparator());
} }

View File

@ -76,7 +76,7 @@ auto main(int argc, char **argv) -> int
int status = 0; int status = 0;
auto ASSERT_TEST = [&status, argc, argv](QObject *obj) auto ASSERT_TEST = [&status, argc, argv](QObject *obj)
{ {
status |= QTest::qExec(obj, argc, argv); status |= QTest::qExec(obj, argc, argv); // NOLINT(hicpp-signed-bitwise)
delete obj; delete obj;
}; };

View File

@ -34,6 +34,7 @@
class TST_VArc : public AbstractTest class TST_VArc : public AbstractTest
{ {
Q_OBJECT // NOLINT Q_OBJECT // NOLINT
public: public:
explicit TST_VArc(QObject *parent = nullptr); explicit TST_VArc(QObject *parent = nullptr);