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);
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));
qDeleteAll(scenes); // Scene will clear all other items

View File

@ -758,14 +758,13 @@ Q_DECL_RELAXED_CONSTEXPR static inline auto VFuzzyComparePossibleNulls(double p1
{
return qFuzzyIsNull(p2);
}
else if (qFuzzyIsNull(p2))
if (qFuzzyIsNull(p2))
{
return false;
}
else
{
return qFuzzyCompare(p1, p2);
}
return qFuzzyCompare(p1, p2);
}
/**

View File

@ -44,9 +44,9 @@
#include "../../visualization/line/vistoolalongline.h"
#include "../../visualization/visualization.h"
#include "../ifc/ifcdef.h"
#include "../ifc/xml/vabstractpattern.h"
#include "../support/dialogeditwrongformula.h"
#include "../vgeometry/../ifc/ifcdef.h"
#include "../vgeometry/vpointf.h"
#include "../vmisc/theme/vtheme.h"
#include "../vmisc/vabstractapplication.h"
@ -57,6 +57,12 @@
#include "../vwidgets/vabstractmainwindow.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
@ -297,7 +303,7 @@ void DialogAlongLine::ChosenSecondPoint(quint32 id, const QString &toolTip)
line->SetPoint2Id(id);
if (m_buildMidpoint)
{
SetFormula(currentLength + QStringLiteral("/2"));
SetFormula(currentLength + "/2"_L1);
line->SetMode(Mode::Show);
}
else

View File

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

View File

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

View File

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

View File

@ -216,7 +216,7 @@ auto VToolEllipticalArc::GetFormulaRadius1() const -> VFormula
//---------------------------------------------------------------------------------------------------------------------
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
{
@ -245,7 +245,7 @@ auto VToolEllipticalArc::GetFormulaRadius2() const -> VFormula
//---------------------------------------------------------------------------------------------------------------------
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
{
@ -274,7 +274,7 @@ auto VToolEllipticalArc::GetFormulaF1() const -> VFormula
//---------------------------------------------------------------------------------------------------------------------
void VToolEllipticalArc::SetFormulaF1(const VFormula &value)
{
if (value.error() == false)
if (!value.error())
{
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(m_id);
QSharedPointer<VEllipticalArc> elArc = qSharedPointerDynamicCast<VEllipticalArc>(obj);
@ -300,7 +300,7 @@ auto VToolEllipticalArc::GetFormulaF2() const -> VFormula
//---------------------------------------------------------------------------------------------------------------------
void VToolEllipticalArc::SetFormulaF2(const VFormula &value)
{
if (value.error() == false)
if (!value.error())
{
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(m_id);
QSharedPointer<VEllipticalArc> elArc = qSharedPointerDynamicCast<VEllipticalArc>(obj);
@ -326,7 +326,7 @@ auto VToolEllipticalArc::GetFormulaRotationAngle() const -> VFormula
//---------------------------------------------------------------------------------------------------------------------
void VToolEllipticalArc::SetFormulaRotationAngle(const VFormula &value)
{
if (value.error() == false)
if (!value.error())
{
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(m_id);
QSharedPointer<VEllipticalArc> elArc = qSharedPointerDynamicCast<VEllipticalArc>(obj);

View File

@ -29,7 +29,6 @@
#ifndef VISTOOLMOVE_H
#define VISTOOLMOVE_H
#include <QColor>
#include <QGraphicsItem>
#include <QMetaObject>
@ -45,6 +44,7 @@
class VisToolMove : public VisOperation
{
Q_OBJECT // NOLINT
public:
explicit VisToolMove(const VContainer *data, QGraphicsItem *parent = nullptr);
~VisToolMove() override = default;
@ -63,24 +63,27 @@ public:
void SetRotationOriginPointId(quint32 value);
auto type() const -> int override {return Type;}
enum {Type = UserType + static_cast<int>(Vis::ToolMove)};
auto type() const -> int override { return Type; }
enum
{
Type = UserType + static_cast<int>(Vis::ToolMove)
};
private:
// cppcheck-suppress unknownMacro
Q_DISABLE_COPY_MOVE(VisToolMove) // NOLINT
qreal m_angle{0};
qreal m_rotationAngle{INT_MIN};
qreal m_length{0};
qreal m_angle{0};
qreal m_rotationAngle{INT_MIN};
qreal m_length{0};
VScaledEllipse *m_pointOrigin{nullptr};
VScaledEllipse *m_pointRotationOrigin{nullptr};
VScaledEllipse *m_pointFinish{nullptr};
VCurvePathItem *m_angleArc{nullptr};
VScaledLine *m_rotationLine{nullptr};
VScaledLine *m_xAxis{nullptr};
quint32 m_rotationOriginId{NULL_ID};
VScaledLine *m_rotationLine{nullptr};
VScaledLine *m_xAxis{nullptr};
quint32 m_rotationOriginId{NULL_ID};
template <class Item>
auto AddOriginCurve(quint32 id, int &i) -> QGraphicsPathItem *;
template <class Item> auto AddOriginCurve(quint32 id, int &i) -> QGraphicsPathItem *;
template <class Item>
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
{
return VAbstractApplication::VApp()->TrVars()->FormulaToUser(
QString::number(VAbstractValApplication::VApp()->fromPixel(value)),
VAbstractApplication::VApp()->Settings()->GetOsSeparator());
auto *app = VAbstractValApplication::VApp();
return app->TrVars()->FormulaToUser(QString::number(app->fromPixel(value)), app->Settings()->GetOsSeparator());
}
//---------------------------------------------------------------------------------------------------------------------
auto Visualization::AngleToUser(qreal value) -> QString
{
return VAbstractApplication::VApp()->TrVars()->FormulaToUser(
QString::number(value), VAbstractApplication::VApp()->Settings()->GetOsSeparator());
auto *app = VAbstractApplication::VApp();
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;
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;
};

View File

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