Skip to content

Commit f09c415

Browse files
authored
Introducing the ability to define physical objects on the stage using the top-left point (#2063)
* Introducing the ability to define physical objects on the stage using the top-left point * Use begin=x:y instead of leftX,leftY * Feserialize startRotation * Add tests * Lupdate * Fix Clang-Tidy warnings * Add compile_database artifact for linter workflow * Use extra-args option * Add a description for the hotfix
1 parent 4b1f69d commit f09c415

File tree

24 files changed

+354
-219
lines changed

24 files changed

+354
-219
lines changed

.github/workflows/setup_environment.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,14 @@ jobs:
184184
if: ${{ inputs.build == true }}
185185
timeout-minutes: 25
186186

187+
- name: Upload compile_commands.json
188+
uses: actions/upload-artifact@v6
189+
with:
190+
name: compile_commands.json
191+
path: |
192+
build/*.json
193+
if: ${{ inputs.lint_clazy }}
194+
187195
- name: Clazy-standalone
188196
uses: MinyazevR/clazy-standalone-action@v0.3.3
189197
with:
@@ -209,7 +217,9 @@ jobs:
209217
database: 'build'
210218
verbosity: 'info'
211219
files-changed-only: true
212-
ignore-tidy: '^(buildScripts|thirdparty|installer)$'
220+
ignore-tidy: 'thirdparty|buildScripts|installer'
221+
# Despite having the correct isystem path for googletests in compile_commands.json, it throws [clang-dignostic-error] file "gmock/gmock.h" not found. A temporary solution is to explicitly use these options as command-line arguments for clang-tidy
222+
extra-args: '-isystem${{ github.workspace }}/qrtest/thirdparty/googletest/googletest/googlemock/include/ -isystem${{ github.workspace }}/qrtest/thirdparty/googletest/googletest/googletest/include/'
213223

214224
- name: Clang-tidy exit
215225
if: ${{ inputs.lint_clazy && steps.linter.outputs.checks-failed > 0 }}

plugins/robots/common/twoDModel/src/engine/items/ballItem.cpp

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
#include "ballItem.h"
1616

1717
#include <QtGui/QIcon>
18-
#include <QtWidgets/QAction>
18+
#include <QtWidgets/QAction> //clazy:exclude=qt6-header-fixes
1919
#include <QtSvg/QSvgRenderer>
20-
2120
#include <twoDModel/engine/model/constants.h>
2221

2322
using namespace twoDModel::items;
@@ -48,22 +47,19 @@ BallItem::BallItem(graphicsUtils::AbstractCoordinateSystem *metricSystem,
4847
setTransformOriginPoint(boundingRect().center());
4948
}
5049

51-
BallItem::~BallItem()
52-
{
53-
}
50+
BallItem::~BallItem() = default;
5451

5552
QAction *BallItem::ballTool()
5653
{
57-
QAction * const result = new QAction(QIcon(":/icons/2d_ball.svg"), tr("Ball (B)"), nullptr);
54+
auto * const result = new QAction(QIcon(":/icons/2d_ball.svg"), tr("Ball (B)"), nullptr);
5855
result->setShortcuts({QKeySequence(Qt::Key_B), QKeySequence(Qt::Key_4)});
5956
result->setCheckable(true);
6057
return result;
6158
}
6259

6360
QRectF BallItem::boundingRect() const
6461
{
65-
return QRectF({ -mDiameterPx / 2.0, -mDiameterPx / 2.0}
66-
, QSizeF{mDiameterPx, mDiameterPx});
62+
return {{ -mDiameterPx / 2.0, -mDiameterPx / 2.0}, QSizeF{mDiameterPx, mDiameterPx}};
6763
}
6864

6965
void BallItem::drawItem(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
@@ -84,6 +80,26 @@ void BallItem::setPenBrushForExtraction(QPainter *painter, const QStyleOptionGra
8480
}
8581
}
8682

83+
void BallItem::setStartPosition(QPointF startPosition)
84+
{
85+
mStartPosition = startPosition;
86+
}
87+
88+
void BallItem::setStartRotation(qreal startRotation)
89+
{
90+
mStartRotation = startRotation;
91+
}
92+
93+
qreal BallItem::startRotation() const
94+
{
95+
return mStartRotation;
96+
}
97+
98+
QPointF BallItem::startPosition() const
99+
{
100+
return mStartPosition;
101+
}
102+
87103
void BallItem::drawExtractionForItem(QPainter *painter)
88104
{
89105
painter->drawEllipse(boundingRect());
@@ -98,19 +114,11 @@ void BallItem::savePos()
98114
QDomElement BallItem::serialize(QDomElement &element) const
99115
{
100116
QDomElement ballNode = AbstractItem::serialize(element);
117+
Serializer<BallItem>::serialize(ballNode);
118+
SolidItem::serialize(ballNode);
119+
101120
auto *coordSystem = coordinateSystem();
102121
ballNode.setTagName("ball");
103-
ballNode.setAttribute("x",
104-
QString::number(coordSystem->toUnit(x1() + scenePos().x())));
105-
ballNode.setAttribute("y",
106-
QString::number(coordSystem->toUnit(y1() + scenePos().y())));
107-
ballNode.setAttribute("markerX",
108-
QString::number(coordSystem->toUnit(x1() + mStartPosition.x())));
109-
ballNode.setAttribute("markerY",
110-
QString::number(coordSystem->toUnit(y1() + mStartPosition.y())));
111-
ballNode.setAttribute("rotation", QString::number(rotation()));
112-
ballNode.setAttribute("startRotation", QString::number(mStartRotation));
113-
SolidItem::serialize(ballNode);
114122
if (mDiameterPx.wasChanged()) {
115123
ballNode.setAttribute("diameter", QString::number(coordSystem->toUnit(mDiameterPx)));
116124
}
@@ -120,24 +128,14 @@ QDomElement BallItem::serialize(QDomElement &element) const
120128
void BallItem::deserialize(const QDomElement &element)
121129
{
122130
AbstractItem::deserialize(element);
131+
SolidItem::deserialize(element);
123132
auto *coordSystem = coordinateSystem();
124-
qreal x = coordSystem->toPx(element.attribute("x", "0").toDouble());
125-
qreal y = coordSystem->toPx(element.attribute("y", "0").toDouble());
126-
qreal markerX = coordSystem->toPx(element.attribute("markerX", "0").toDouble());
127-
qreal markerY = coordSystem->toPx(element.attribute("markerY", "0").toDouble());
128-
qreal rotation = element.attribute("rotation", "0").toDouble();
129-
mStartRotation = element.attribute("startRotation", "0").toDouble();
130-
131133
if (element.hasAttribute("diameter")) {
132134
setDiameter(coordSystem->toPx(
133135
element.attribute("diameter").toDouble()));
134136
}
135137

136-
SolidItem::deserialize(element);
137-
setPos(QPointF(x, y));
138-
setTransformOriginPoint(boundingRect().center());
139-
mStartPosition = {markerX, markerY};
140-
setRotation(rotation);
138+
Serializer<BallItem>::deserialize(element);
141139
Q_EMIT x1Changed(x1());
142140
}
143141

@@ -166,7 +164,7 @@ void BallItem::returnToStartPosition()
166164

167165
QPolygonF BallItem::collidingPolygon() const
168166
{
169-
return QPolygonF(boundingRect().adjusted(1, 1, -1, -1).translated(scenePos()));
167+
return boundingRect().adjusted(1, 1, -1, -1).translated(scenePos());
170168
}
171169

172170
QPainterPath BallItem::path() const

plugins/robots/common/twoDModel/src/engine/items/ballItem.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,23 @@
1616

1717
#include <qrutils/graphicsUtils/abstractItem.h>
1818
#include "src/engine/items/solidItem.h"
19+
#include "details/serializer.h"
1920
#include <memory>
2021

2122
class QSvgRenderer;
2223

2324
namespace twoDModel {
2425
namespace items {
2526

26-
class BallItem final: public graphicsUtils::AbstractItem, public SolidItem
27+
class BallItem final: public graphicsUtils::AbstractItem, public SolidItem, public Serializer<BallItem>
2728
{
2829
Q_OBJECT
2930
Q_DISABLE_COPY(BallItem)
3031

3132
public:
3233
explicit BallItem(graphicsUtils::AbstractCoordinateSystem *metricSystem,
33-
QPointF position);
34-
~BallItem();
34+
QPointF position);
35+
~BallItem() override;
3536

3637
/// Creates and returns ball item for 2D model palette.
3738
/// Transfers ownership.
@@ -51,6 +52,10 @@ class BallItem final: public graphicsUtils::AbstractItem, public SolidItem
5152

5253
void saveStartPosition();
5354
void returnToStartPosition();
55+
void setStartPosition(QPointF startPosition);
56+
void setStartRotation(qreal startPosition);
57+
qreal startRotation() const;
58+
QPointF startPosition() const;
5459

5560
bool isCircle() const override;
5661
BodyType bodyType() const override;

plugins/robots/common/twoDModel/src/engine/items/cubeItem.cpp

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -100,24 +100,33 @@ void CubeItem::savePos()
100100
RotateItem::savePos();
101101
}
102102

103+
void CubeItem::setStartPosition(QPointF startPosition)
104+
{
105+
mStartPosition = startPosition;
106+
}
107+
108+
void CubeItem::setStartRotation(qreal startRotation)
109+
{
110+
mStartRotation = startRotation;
111+
}
112+
113+
qreal CubeItem::startRotation() const
114+
{
115+
return mStartRotation;
116+
}
117+
118+
QPointF CubeItem::startPosition() const
119+
{
120+
return mStartPosition;
121+
}
122+
103123
QDomElement CubeItem::serialize(QDomElement &element) const
104124
{
105125
QDomElement cubeNode = AbstractItem::serialize(element);
106-
const auto &coordSystem = coordinateSystem();
107-
cubeNode.setTagName("cube");
108-
cubeNode.setAttribute("x",
109-
QString::number(coordSystem->toUnit(scenePos().x())));
110-
cubeNode.setAttribute("y",
111-
QString::number(coordSystem->toUnit(scenePos().y())));
112-
cubeNode.setAttribute("markerX",
113-
QString::number(coordSystem->toUnit(mStartPosition.x())));
114-
cubeNode.setAttribute("markerY",
115-
QString::number(coordSystem->toUnit(mStartPosition.y())));
116-
cubeNode.setAttribute("rotation", QString::number(rotation()));
117-
cubeNode.setAttribute("startRotation", QString::number(mStartRotation));
118-
126+
Serializer<CubeItem>::serialize(cubeNode);
119127
SolidItem::serialize(cubeNode);
120-
128+
cubeNode.setTagName("cube");
129+
auto &&coordSystem = coordinateSystem();
121130
if (mEdgeSizePx.wasChanged()) {
122131
cubeNode.setAttribute("edgeSize", QString::number(coordSystem->toUnit(mEdgeSizePx)));
123132
}
@@ -128,22 +137,18 @@ QDomElement CubeItem::serialize(QDomElement &element) const
128137
void CubeItem::deserialize(const QDomElement &element)
129138
{
130139
AbstractItem::deserialize(element);
131-
const auto &coordSystem = coordinateSystem();
132-
const auto x = coordSystem->toPx(element.attribute("x", "0").toDouble());
133-
const auto y = coordSystem->toPx(element.attribute("y", "0").toDouble());
134-
const auto markerX = coordSystem->toPx(element.attribute("markerX", "0").toDouble());
135-
const auto markerY = coordSystem->toPx(element.attribute("markerY", "0").toDouble());
136-
const auto rotation = element.attribute("rotation", "0").toDouble();
137-
mStartRotation = element.attribute("startRotation", "0").toDouble();
138-
setPos(QPointF(x, y));
139-
setTransformOriginPoint(boundingRect().center());
140-
setRotation(rotation);
140+
SolidItem::deserialize(element);
141+
142+
auto *coordSystem = coordinateSystem();
141143
if (element.hasAttribute("edgeSize")) {
142144
setEdgeSize(coordSystem->toPx(
143145
element.attribute("edgeSize").toDouble()));
144146
}
145-
SolidItem::deserialize(element);
146-
mStartPosition = {markerX, markerY};
147+
148+
Serializer<CubeItem>::deserialize(element);
149+
// Update rotater position
150+
RotateItem::init();
151+
savePos();
147152
Q_EMIT x1Changed(x1());
148153
}
149154

@@ -195,10 +200,6 @@ void CubeItem::setEdgeSize(const qreal edge)
195200
setY1(-mEdgeSizePx / 2.0f);
196201
setX2(x1() + mEdgeSizePx);
197202
setY2(y1() + mEdgeSizePx);
198-
setTransformOriginPoint(boundingRect().center());
199-
// Update rotater position
200-
RotateItem::init();
201-
savePos();
202203
}
203204

204205
SolidItem::BodyType CubeItem::bodyType() const

plugins/robots/common/twoDModel/src/engine/items/cubeItem.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@
1515
#pragma once
1616

1717
#include <qrutils/graphicsUtils/rotateItem.h>
18-
18+
#include "details/serializer.h"
1919
#include "src/engine/items/solidItem.h"
2020

2121
class QSvgRenderer;
2222

2323
namespace twoDModel {
2424
namespace items {
2525

26-
class CubeItem final: public graphicsUtils::RotateItem, public SolidItem
26+
class CubeItem final: public graphicsUtils::RotateItem, public SolidItem, public Serializer<CubeItem>
2727
{
2828
Q_OBJECT
2929
Q_DISABLE_COPY(CubeItem)
3030

3131
public:
3232
explicit CubeItem(graphicsUtils::AbstractCoordinateSystem *metricSystem,
3333
QPointF position);
34-
~CubeItem();
34+
~CubeItem() override;
3535

3636
/// Creates and returns cube item for 2D model palette.
3737
/// Transfers ownership.
@@ -45,6 +45,10 @@ class CubeItem final: public graphicsUtils::RotateItem, public SolidItem
4545
void drawFieldForResizeItem(QPainter* painter) override { Q_UNUSED(painter) }
4646
void resizeItem(QGraphicsSceneMouseEvent *event) override { Q_UNUSED(event) }
4747
void savePos() override;
48+
void setStartPosition(QPointF startPosition);
49+
void setStartRotation(qreal startPosition);
50+
qreal startRotation() const;
51+
QPointF startPosition() const;
4852

4953
QDomElement serialize(QDomElement &element) const override;
5054
void deserialize(const QDomElement &element) override;

plugins/robots/common/twoDModel/src/engine/items/itemProperty.h renamed to plugins/robots/common/twoDModel/src/engine/items/details/itemProperty.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@
1515
#pragma once
1616

1717
#include <QObject>
18+
#include <utility>
1819

1920
template<typename T>
2021
class ItemProperty final
2122
{
2223
Q_DISABLE_COPY_MOVE(ItemProperty)
2324
public:
24-
explicit ItemProperty(const QString& name, const T& value)
25-
: mName(name), mValue(value), mWasChanged(false) {}
25+
explicit ItemProperty(QString name, const T& value)
26+
: mName(std::move(name)), mValue(value), mWasChanged(false) {}
2627

2728
ItemProperty() = default;
28-
operator const T() const & { return mValue; }
29+
operator T() const & { return mValue; } // NOLINT(google-explicit-constructor)
2930

3031
QString name() const { return mName; }
3132

@@ -41,5 +42,5 @@ class ItemProperty final
4142
private:
4243
QString mName;
4344
T mValue;
44-
bool mWasChanged;
45+
bool mWasChanged {};
4546
};

0 commit comments

Comments
 (0)