From kde-commits Sat May 31 21:36:38 2014 From: Oliver Kellogg Date: Sat, 31 May 2014 21:36:38 +0000 To: kde-commits Subject: [umbrello] umbrello/widgets: umbrello/widgets/pinwidget.cpp : Do not assume that m_pName is always n Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=140157220604042 Git commit f1c4192235c813c8113319f781eb9e10d895c99c by Oliver Kellogg. Committed on 31/05/2014 at 18:37. Pushed by okellogg into branch 'master'. umbrello/widgets/pinwidget.cpp : Do not assume that m_pName is always non N= ULL. (It may have been deleted.) M +19 -14 umbrello/widgets/pinwidget.cpp http://commits.kde.org/umbrello/f1c4192235c813c8113319f781eb9e10d895c99c diff --git a/umbrello/widgets/pinwidget.cpp b/umbrello/widgets/pinwidget.cpp index 194d27f..b4e3bac 100644 --- a/umbrello/widgets/pinwidget.cpp +++ b/umbrello/widgets/pinwidget.cpp @@ -74,9 +74,6 @@ PinWidget::~PinWidget() */ void PinWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *o= ption, QWidget *widget) { - Q_UNUSED(option); - Q_UNUSED(widget); - int w =3D 10; int h =3D 10; int widthActivity =3D m_pOw->width(); @@ -88,17 +85,18 @@ void PinWidget::paint(QPainter *painter, const QStyleOp= tionGraphicsItem *option, = const QFontMetrics &fm =3D getFontMetrics(FT_NORMAL); const int fontHeight =3D fm.lineSpacing(); + const bool floTxtNeedsPositioning =3D m_pName && !m_pName->text().isEm= pty() && m_pName->x() =3D=3D 0 && m_pName->y() =3D=3D 0; = if ((offsetY + heightActivity/2) <=3D m_pOw->y() + heightActivity){ - y =3D m_pOw->y()-5; - if (m_pName->x() =3D=3D 0 && m_pName->y() =3D=3D 0) { + y =3D m_pOw->y() - 5; + if (floTxtNeedsPositioning) { //the floating text has not been linked with the signal m_pName->setX(x + 5 - m_Text.length()/2); m_pName->setY(y -fontHeight); } } else if((offsetY + heightActivity/2) > m_pOw->y() + heightActivity){ - y =3D (m_pOw->y() + heightActivity)-5; - if (m_pName->x() =3D=3D 0 && m_pName->y() =3D=3D 0) { + y =3D m_pOw->y() + heightActivity - 5; + if (floTxtNeedsPositioning) { //the floating text has not been linked with the signal m_pName->setX(x + 5 - m_Text.length()/2); m_pName->setY(y + fontHeight); @@ -109,7 +107,7 @@ void PinWidget::paint(QPainter *painter, const QStyleOp= tionGraphicsItem *option, && (offsetY > m_pOw->y() +5 && offsetY < m_pOw->y() + heightActiv= ity - 5)){ x =3D m_pOw->x() -5; y =3D m_pOw->y() + (heightActivity/2) -5; - if (m_pName->x() =3D=3D 0 && m_pName->y() =3D=3D 0) { + if (floTxtNeedsPositioning) { m_pName->setX(x - m_Text.length()); m_pName->setY(y - fontHeight); } @@ -117,7 +115,7 @@ void PinWidget::paint(QPainter *painter, const QStyleOp= tionGraphicsItem *option, && (offsetY > m_pOw->y() +5 && offsetY < m_pOw->y() + heightActiv= ity - 5)){ x =3D m_pOw->x() + widthActivity -5; y =3D m_pOw->y() + (heightActivity/2) -5; - if (m_pName->x() =3D=3D 0 && m_pName->y() =3D=3D 0) { + if (floTxtNeedsPositioning) { //the floating text has not been linked with the signal m_pName->setX(x + 10); m_pName->setY(y - fontHeight); @@ -145,8 +143,10 @@ void PinWidget::paint(QPainter *painter, const QStyleO= ptionGraphicsItem *option, //make sure it's always above the others setZValue(20); setPenFromSettings(painter); - m_pName->setVisible((m_pName->text().length() > 0)); - m_pName->updateGeometry(); + if (m_pName) { + m_pName->setVisible((m_pName->text().length() > 0)); + m_pName->updateGeometry(); + } = UMLWidget::paint(painter, option, widget); } @@ -158,12 +158,17 @@ void PinWidget::setName(const QString &strName) { m_Text =3D strName; updateGeometry(); - m_pName->setText(m_Text); + if (m_pName) { + m_pName->setText(m_Text); + } else { + m_pName =3D new FloatingTextWidget(m_scene, Uml::TextRole::Floatin= g, strName); + m_scene->addFloatingTextWidget(m_pName); + } } = /** * Returns the minimum height this widget should be set at on - * a sequence diagrams. Takes into account the widget positions + * a sequence diagram. Takes into account the widget positions * it is related to. */ int PinWidget::getMinY() @@ -183,7 +188,7 @@ void PinWidget::mouseMoveEvent(QGraphicsSceneMouseEvent= * me) UMLWidget::mouseMoveEvent(me); int diffX =3D m_oldX - x(); int diffY =3D m_oldY - y(); - if (m_pName!=3DNULL && !(m_pName->text()).isEmpty()) { + if (m_pName && !m_pName->text().isEmpty()) { m_pName->setX(m_pName->x() - diffX); m_pName->setY(m_pName->y() - diffY); }