Skip to content

Commit 92c3147

Browse files
Maurizio Ingrassiapaceholder
authored andcommitted
Format code with clang-format similarly to QtCreator (#146)
The file .clang-format has been added. The reference for the configuration is the default used by Qt here: https://raw.githubusercontent.com/qt-creator/qt-creator/master/.clang-format The whole codebase has been formatted following these rules. In linux it's very straightforward, just launch find . \( -name \*.cpp -o -name \*.hpp \) -print0 | xargs -0 -n 1 clang-format-13 -i
1 parent 17641e5 commit 92c3147

File tree

108 files changed

+6167
-9045
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+6167
-9045
lines changed

examples/calculator/AdditionModel.hpp

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

3-
#include "MathOperationDataModel.hpp"
43
#include "DecimalData.hpp"
4+
#include "MathOperationDataModel.hpp"
55

66
#include <QtNodes/NodeDelegateModel>
77

@@ -13,41 +13,27 @@
1313
class AdditionModel : public MathOperationDataModel
1414
{
1515
public:
16-
17-
~AdditionModel() = default;
16+
~AdditionModel() = default;
1817

1918
public:
19+
QString caption() const override { return QStringLiteral("Addition"); }
2020

21-
QString
22-
caption() const override
23-
{ return QStringLiteral("Addition"); }
24-
25-
QString
26-
name() const override
27-
{ return QStringLiteral("Addition"); }
21+
QString name() const override { return QStringLiteral("Addition"); }
2822

2923
private:
30-
31-
void
32-
compute() override
33-
{
34-
PortIndex const outPortIndex = 0;
35-
36-
auto n1 = _number1.lock();
37-
auto n2 = _number2.lock();
38-
39-
if (n1 && n2)
40-
{
41-
_result = std::make_shared<DecimalData>(n1->number() +
42-
n2->number());
43-
}
44-
else
24+
void compute() override
4525
{
46-
_result.reset();
47-
}
26+
PortIndex const outPortIndex = 0;
4827

49-
Q_EMIT dataUpdated(outPortIndex);
50-
}
28+
auto n1 = _number1.lock();
29+
auto n2 = _number2.lock();
5130

31+
if (n1 && n2) {
32+
_result = std::make_shared<DecimalData>(n1->number() + n2->number());
33+
} else {
34+
_result.reset();
35+
}
5236

37+
Q_EMIT dataUpdated(outPortIndex);
38+
}
5339
};

examples/calculator/DecimalData.hpp

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,28 @@
22

33
#include <QtNodes/NodeData>
44

5-
using QtNodes::NodeDataType;
65
using QtNodes::NodeData;
6+
using QtNodes::NodeDataType;
77

88
/// The class can potentially incapsulate any user data which
99
/// need to be transferred within the Node Editor graph
1010
class DecimalData : public NodeData
1111
{
1212
public:
13+
DecimalData()
14+
: _number(0.0)
15+
{}
1316

14-
DecimalData()
15-
: _number(0.0)
16-
{}
17-
18-
DecimalData(double const number)
19-
: _number(number)
20-
{}
17+
DecimalData(double const number)
18+
: _number(number)
19+
{}
2120

22-
NodeDataType
23-
type() const override
24-
{
25-
return NodeDataType {"decimal",
26-
"Decimal"};
27-
}
21+
NodeDataType type() const override { return NodeDataType{"decimal", "Decimal"}; }
2822

23+
double number() const { return _number; }
2924

30-
double
31-
number() const
32-
{ return _number; }
33-
34-
QString
35-
numberAsText() const
36-
{ return QString::number(_number, 'f'); }
25+
QString numberAsText() const { return QString::number(_number, 'f'); }
3726

3827
private:
39-
40-
double _number;
28+
double _number;
4129
};

examples/calculator/DivisionModel.hpp

Lines changed: 48 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

3-
#include "MathOperationDataModel.hpp"
43
#include "DecimalData.hpp"
4+
#include "MathOperationDataModel.hpp"
55

66
#include <QtNodes/NodeDelegateModel>
77

@@ -13,79 +13,62 @@
1313
class DivisionModel : public MathOperationDataModel
1414
{
1515
public:
16-
17-
virtual
18-
~DivisionModel() {}
16+
virtual ~DivisionModel() {}
1917

2018
public:
21-
QString
22-
caption() const override
23-
{ return QStringLiteral("Division"); }
19+
QString caption() const override { return QStringLiteral("Division"); }
2420

25-
bool
26-
portCaptionVisible(PortType portType, PortIndex portIndex) const override
27-
{
28-
Q_UNUSED(portType); Q_UNUSED(portIndex);
29-
return true;
30-
}
31-
32-
QString
33-
portCaption(PortType portType, PortIndex portIndex) const override
34-
{
35-
switch (portType)
21+
bool portCaptionVisible(PortType portType, PortIndex portIndex) const override
3622
{
37-
case PortType::In:
38-
if (portIndex == 0)
39-
return QStringLiteral("Dividend");
40-
else if (portIndex == 1)
41-
return QStringLiteral("Divisor");
42-
43-
break;
44-
45-
case PortType::Out:
46-
return QStringLiteral("Result");
23+
Q_UNUSED(portType);
24+
Q_UNUSED(portIndex);
25+
return true;
26+
}
4727

48-
default:
49-
break;
28+
QString portCaption(PortType portType, PortIndex portIndex) const override
29+
{
30+
switch (portType) {
31+
case PortType::In:
32+
if (portIndex == 0)
33+
return QStringLiteral("Dividend");
34+
else if (portIndex == 1)
35+
return QStringLiteral("Divisor");
36+
37+
break;
38+
39+
case PortType::Out:
40+
return QStringLiteral("Result");
41+
42+
default:
43+
break;
44+
}
45+
return QString();
5046
}
51-
return QString();
52-
}
5347

54-
QString
55-
name() const override
56-
{ return QStringLiteral("Division"); }
48+
QString name() const override { return QStringLiteral("Division"); }
5749

5850
private:
59-
60-
void
61-
compute() override
62-
{
63-
PortIndex const outPortIndex = 0;
64-
65-
auto n1 = _number1.lock();
66-
auto n2 = _number2.lock();
67-
68-
if (n2 && (n2->number() == 0.0))
69-
{
70-
//modelValidationState = NodeValidationState::Error;
71-
//modelValidationError = QStringLiteral("Division by zero error");
72-
_result.reset();
73-
}
74-
else if (n1 && n2)
51+
void compute() override
7552
{
76-
//modelValidationState = NodeValidationState::Valid;
77-
//modelValidationError = QString();
78-
_result = std::make_shared<DecimalData>(n1->number() /
79-
n2->number());
53+
PortIndex const outPortIndex = 0;
54+
55+
auto n1 = _number1.lock();
56+
auto n2 = _number2.lock();
57+
58+
if (n2 && (n2->number() == 0.0)) {
59+
//modelValidationState = NodeValidationState::Error;
60+
//modelValidationError = QStringLiteral("Division by zero error");
61+
_result.reset();
62+
} else if (n1 && n2) {
63+
//modelValidationState = NodeValidationState::Valid;
64+
//modelValidationError = QString();
65+
_result = std::make_shared<DecimalData>(n1->number() / n2->number());
66+
} else {
67+
//modelValidationState = NodeValidationState::Warning;
68+
//modelValidationError = QStringLiteral("Missing or incorrect inputs");
69+
_result.reset();
70+
}
71+
72+
Q_EMIT dataUpdated(outPortIndex);
8073
}
81-
else
82-
{
83-
//modelValidationState = NodeValidationState::Warning;
84-
//modelValidationError = QStringLiteral("Missing or incorrect inputs");
85-
_result.reset();
86-
}
87-
88-
Q_EMIT dataUpdated(outPortIndex);
89-
}
90-
9174
};

examples/calculator/MathOperationDataModel.cpp

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,41 @@
22

33
#include "DecimalData.hpp"
44

5-
unsigned int
6-
MathOperationDataModel::
7-
nPorts(PortType portType) const
5+
unsigned int MathOperationDataModel::nPorts(PortType portType) const
86
{
9-
unsigned int result;
7+
unsigned int result;
108

11-
if (portType == PortType::In)
12-
result = 2;
13-
else
14-
result = 1;
9+
if (portType == PortType::In)
10+
result = 2;
11+
else
12+
result = 1;
1513

16-
return result;
14+
return result;
1715
}
1816

19-
20-
NodeDataType
21-
MathOperationDataModel::
22-
dataType(PortType, PortIndex) const
17+
NodeDataType MathOperationDataModel::dataType(PortType, PortIndex) const
2318
{
24-
return DecimalData().type();
19+
return DecimalData().type();
2520
}
2621

27-
28-
std::shared_ptr<NodeData>
29-
MathOperationDataModel::
30-
outData(PortIndex)
22+
std::shared_ptr<NodeData> MathOperationDataModel::outData(PortIndex)
3123
{
32-
return std::static_pointer_cast<NodeData>(_result);
24+
return std::static_pointer_cast<NodeData>(_result);
3325
}
3426

35-
36-
void
37-
MathOperationDataModel::
38-
setInData(std::shared_ptr<NodeData> data, PortIndex portIndex)
27+
void MathOperationDataModel::setInData(std::shared_ptr<NodeData> data, PortIndex portIndex)
3928
{
40-
auto numberData =
41-
std::dynamic_pointer_cast<DecimalData>(data);
42-
43-
if (!data)
44-
{
45-
Q_EMIT dataInvalidated(0);
46-
}
47-
48-
if (portIndex == 0)
49-
{
50-
_number1 = numberData;
51-
}
52-
else
53-
{
54-
_number2 = numberData;
55-
}
56-
57-
compute();
58-
}
29+
auto numberData = std::dynamic_pointer_cast<DecimalData>(data);
5930

31+
if (!data) {
32+
Q_EMIT dataInvalidated(0);
33+
}
34+
35+
if (portIndex == 0) {
36+
_number1 = numberData;
37+
} else {
38+
_number2 = numberData;
39+
}
40+
41+
compute();
42+
}

0 commit comments

Comments
 (0)