Skip to content

Commit

Permalink
GUI: Connect Event label change to Diagram
Browse files Browse the repository at this point in the history
The connection is managed manually
since QGraphicsItem doesn't inherit from QObject
for performance reasons.
  • Loading branch information
rakhimov committed Jul 24, 2017
1 parent 41264cb commit 7130d7f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions gui/diagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ const double Event::m_labelBoxHeight = 4;
Event::Event(model::Element *event, QGraphicsItem *parent)
: QGraphicsItem(parent), m_event(event), m_typeGraphics(nullptr)
{
m_labelConnection = QObject::connect(event, &model::Element::labelChanged,
[this] { update(); });
}

Event::~Event() noexcept
{
QObject::disconnect(m_labelConnection);
}

QSize Event::units() const
Expand Down
3 changes: 3 additions & 0 deletions gui/diagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ namespace diagram {
class Event : public QGraphicsItem
{
public:
~Event() noexcept override;

QRectF boundingRect() const final;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget) final;
Expand Down Expand Up @@ -97,6 +99,7 @@ class Event : public QGraphicsItem

private:
QGraphicsItem *m_typeGraphics; ///< The graphics of the derived type.
QMetaObject::Connection m_labelConnection; ///< Tracks the label changes.
};

/**
Expand Down

0 comments on commit 7130d7f

Please sign in to comment.