Skip to content

Commit 2d50dfb

Browse files
committed
Improve Code
1 parent f3151dc commit 2d50dfb

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

qrgui/editor/labels/label.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ using namespace qReal::gui::editor;
2525

2626
Label::Label(models::GraphicalModelAssistApi &graphicalAssistApi
2727
, models::LogicalModelAssistApi &logicalAssistApi
28+
// NOLINTNEXTLINE(modernize-pass-by-value)
2829
, const Id &elementId
2930
, const QSharedPointer<LabelProperties> &properties)
3031
: mIsStretched(false)
@@ -44,9 +45,7 @@ Label::Label(models::GraphicalModelAssistApi &graphicalAssistApi
4445
setAcceptDrops(true);
4546
}
4647

47-
Label::~Label()
48-
{
49-
}
48+
Label::~Label() = default;
5049

5150
const LabelProperties &Label::info() const
5251
{
@@ -188,7 +187,7 @@ QString Label::location() const
188187
void Label::updateData(bool withUndoRedo)
189188
{
190189
const QString value = toPlainText();
191-
Element * const parent = dynamic_cast<Element *>(parentItem());
190+
auto * const parent = dynamic_cast<Element *>(parentItem());
192191
if (!mProperties->nameForRoleProperty().isEmpty()) {
193192
if (mEnumValues.isEmpty()) {
194193
parent->setLogicalProperty(mProperties->nameForRoleProperty()
@@ -197,7 +196,8 @@ void Label::updateData(bool withUndoRedo)
197196
, withUndoRedo
198197
);
199198
} else {
200-
const QString repoValue = mEnumValues.values().contains(value)
199+
const auto &values = mEnumValues.values();
200+
const QString repoValue = values.contains(value)
201201
? mEnumValues.key(value)
202202
: (withUndoRedo ? enumText(value) : value);
203203
parent->setLogicalProperty(mProperties->nameForRoleProperty()
@@ -234,7 +234,8 @@ void Label::updateData(bool withUndoRedo)
234234

235235
parent->setLogicalProperty(mProperties->binding(), mTextBeforeTextInteraction, value, withUndoRedo);
236236
} else {
237-
const QString repoValue = mEnumValues.values().contains(value)
237+
const auto &values = mEnumValues.values();
238+
const QString repoValue = values.contains(value)
238239
? mEnumValues.key(value)
239240
: (withUndoRedo ? enumText(value) : value);
240241
parent->setLogicalProperty(mProperties->binding(), mTextBeforeTextInteraction, repoValue, withUndoRedo);
@@ -264,7 +265,8 @@ void Label::mousePressEvent(QGraphicsSceneMouseEvent *event)
264265
{
265266
if (dynamic_cast<EdgeElement *>(parentItem())) {
266267
// Passing event to edge because users usially want to edit its property when clicking on it.
267-
QGraphicsItem::mousePressEvent(event);
268+
// NOLINTNEXTLINE(bugprone-parent-virtual-call)
269+
QGraphicsItem::mousePressEvent(event); //clazy:exclude=skipped-base-method
268270
return;
269271
}
270272

@@ -350,12 +352,14 @@ bool Label::isReadOnly() const
350352
return mProperties->isReadOnly();
351353
}
352354

355+
// https://qt-project.atlassian.net/browse/QTBUG-88309#icft=QTBUG-88309
356+
// TODO: Just remove this Label::contextMenuEvent override when upgrading to Qt >= 5.15.3
357+
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 3)
353358
void Label::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
354359
{
355-
// TODO: https://qt-project.atlassian.net/browse/QTBUG-88309#icft=QTBUG-88309
356-
// Just remove this Label::contextMenuEvent override when upgrading to Qt >= 5.15.3
357360
event->accept();
358361
}
362+
#endif
359363

360364
void Label::focusOutEvent(QFocusEvent *event)
361365
{

qrgui/editor/labels/label.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ class Label : public QGraphicsTextItem, public LabelInterface
7979
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
8080
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
8181
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
82+
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 3)
8283
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
84+
#endif
8385
void focusOutEvent(QFocusEvent *event) override;
8486
void keyPressEvent(QKeyEvent *event) override;
8587

86-
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
88+
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
8789
void drawText(QPainter *painter, const QRectF &rect, const QString &text);
8890
QRectF prefixRect() const;
8991
QRectF suffixRect() const;

0 commit comments

Comments
 (0)