Move pipeline access safety check to single function in Label
MODIFY
src/graphics/connection.cpp
src/graphics/connection.cpp
@@ -260,7 +260,10 @@ void Connection::toggleLabel(bool show){
// --------- label ------------
void Label::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*) {
- if (m_signal != nullptr && !Pipeline::getPipeline()->isRunning()) {
+ // Dont draw if we have not attached the label to a signal
+ if(m_signal == nullptr)
+ return;
+
// Draw label (connection value)
const auto text = getText();
QRectF textRect = getTextRect(text);
@@ -276,10 +279,13 @@ void Label::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*)
textPos.ry() += 14;
painter->drawText(textPos, text);
}
-}
QString Label::getText() const {
+ if(m_signal != nullptr && !Pipeline::getPipeline()->isRunning()){
return QString("0x%1").arg(QString().setNum(m_signal->getValue(), 16));
+ } else {
+ return QString();
+ }
}
QRectF Label::getTextRect(const QString& text) const{
@@ -289,15 +295,11 @@ QRectF Label::getTextRect(const QString& text) const{
}
QRectF Label::boundingRect() const {
- if (m_signal != nullptr && !Pipeline::getPipeline()->isRunning()) {
auto boundingRect = getTextRect(getText());
// Adjust for pen width etc.
boundingRect.adjust(-5 - PENWIDTH, - PENWIDTH, 5 + PENWIDTH, 5 + PENWIDTH);
return boundingRect;
- } else {
- return QRectF();
- }
}
} // namespace Graphics

Move pipeline access safety check to single function in Label