Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions qrgui/editor/labels/label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ using namespace qReal::gui::editor;

Label::Label(models::GraphicalModelAssistApi &graphicalAssistApi
, models::LogicalModelAssistApi &logicalAssistApi
// NOLINTNEXTLINE(modernize-pass-by-value)
, const Id &elementId
, const QSharedPointer<LabelProperties> &properties)
: mIsStretched(false)
Expand All @@ -44,9 +45,7 @@ Label::Label(models::GraphicalModelAssistApi &graphicalAssistApi
setAcceptDrops(true);
}

Label::~Label()
{
}
Label::~Label() = default;

const LabelProperties &Label::info() const
{
Expand Down Expand Up @@ -188,7 +187,7 @@ QString Label::location() const
void Label::updateData(bool withUndoRedo)
{
const QString value = toPlainText();
Element * const parent = dynamic_cast<Element *>(parentItem());
auto * const parent = dynamic_cast<Element *>(parentItem());
if (!mProperties->nameForRoleProperty().isEmpty()) {
if (mEnumValues.isEmpty()) {
parent->setLogicalProperty(mProperties->nameForRoleProperty()
Expand All @@ -197,7 +196,8 @@ void Label::updateData(bool withUndoRedo)
, withUndoRedo
);
} else {
const QString repoValue = mEnumValues.values().contains(value)
const auto &values = mEnumValues.values();
const QString repoValue = values.contains(value)
? mEnumValues.key(value)
: (withUndoRedo ? enumText(value) : value);
parent->setLogicalProperty(mProperties->nameForRoleProperty()
Expand Down Expand Up @@ -234,7 +234,8 @@ void Label::updateData(bool withUndoRedo)

parent->setLogicalProperty(mProperties->binding(), mTextBeforeTextInteraction, value, withUndoRedo);
} else {
const QString repoValue = mEnumValues.values().contains(value)
const auto &values = mEnumValues.values();
const QString repoValue = values.contains(value)
? mEnumValues.key(value)
: (withUndoRedo ? enumText(value) : value);
parent->setLogicalProperty(mProperties->binding(), mTextBeforeTextInteraction, repoValue, withUndoRedo);
Expand Down Expand Up @@ -264,7 +265,8 @@ void Label::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (dynamic_cast<EdgeElement *>(parentItem())) {
// Passing event to edge because users usially want to edit its property when clicking on it.
QGraphicsItem::mousePressEvent(event);
// NOLINTNEXTLINE(bugprone-parent-virtual-call)
QGraphicsItem::mousePressEvent(event); //clazy:exclude=skipped-base-method
return;
}

Expand Down Expand Up @@ -350,6 +352,15 @@ bool Label::isReadOnly() const
return mProperties->isReadOnly();
}

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

void Label::focusOutEvent(QFocusEvent *event)
{
if (event->reason() != Qt::PopupFocusReason) {
Expand Down Expand Up @@ -471,7 +482,7 @@ void Label::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi

// Default dashed frame is drawn arround the whole bounding rect (arround prefix and suffix too). Disabling it.
const_cast<QStyleOptionGraphicsItem *>(option)->state &= ~QStyle::State_Selected & ~QStyle::State_HasFocus;

QGraphicsTextItem::paint(painter, option, widget);
}

Expand Down
6 changes: 4 additions & 2 deletions qrgui/editor/labels/label.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ class Label : public QGraphicsTextItem, public LabelInterface
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;

#if QT_VERSION < QT_VERSION_CHECK(5, 15, 3)
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
#endif
void focusOutEvent(QFocusEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;

void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
void drawText(QPainter *painter, const QRectF &rect, const QString &text);
QRectF prefixRect() const;
QRectF suffixRect() const;
Expand Down