From kde-commits Sat May 31 21:36:39 2014 From: Oliver Kellogg Date: Sat, 31 May 2014 21:36:39 +0000 To: kde-commits Subject: [umbrello] umbrello: Integration of PinWidget's floating-text name display in PortWidget Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=140157220704044 Git commit ca646e952dd24c588c16908467df31d442010d7a by Oliver Kellogg. Committed on 31/05/2014 at 21:36. Pushed by okellogg into branch 'master'. Integration of PinWidget's floating-text name display in PortWidget (see "BTW" at https://bugs.kde.org/show_bug.cgi?id=3D335399#c1) umbrello/listpopupmenu.h - At enum MenuType add new value, mt_NameAsTooltip. umbrello/widgets/portwidget.h - Add protected member m_pName of type pointer-to-FloatingTextWidget with corresponding public getter and setter method. The intention is that the FloatingTextWidget may be used as an alternative to the tooltip for displaying the port name on a diagram. - Override UMLWidget::slotMenuSelection() for adding handling of ListPopupMenu::mt_NameAsTooltip. umbrello/listpopupmenu.cpp - In function insertSingleSelectionMenu() case wt_Port, insert mt_NameAsTooltip as checkable. If the PortWidget's floatingTextWidget() is NULL then setChecked(true) on m_actions[mt_NameAsTooltip]. This is the default case as the PortWidget does not automatically construct its FloatingTextWidget. umbrello/widgets/portwidget.cpp - In function updateWidget(), if m_pName is non NULL then update the text in the FloatingTextWidget; else update the text in the ToolTip. - In function slotMenuSelection(), handle ListPopupMenu::mt_NameAsTooltip as follows: If m_pName is non NULL then toggle the name display from FloatingText to ToolTip; else toggle the name display from ToolTip to FloatingText. - In functions loadFromXMI() and saveToXMI(), implement loading/saving of the optional FloatingTextWidget *m_pName. M +8 -0 umbrello/listpopupmenu.cpp M +1 -0 umbrello/listpopupmenu.h M +108 -2 umbrello/widgets/portwidget.cpp M +6 -0 umbrello/widgets/portwidget.h http://commits.kde.org/umbrello/ca646e952dd24c588c16908467df31d442010d7a diff --git a/umbrello/listpopupmenu.cpp b/umbrello/listpopupmenu.cpp index 738247a..a9c20bd 100644 --- a/umbrello/listpopupmenu.cpp +++ b/umbrello/listpopupmenu.cpp @@ -27,6 +27,7 @@ #include "model_utils.h" #include "objectnodewidget.h" #include "objectwidget.h" +#include "portwidget.h" #include "preconditionwidget.h" #include "signalwidget.h" #include "statewidget.h" @@ -386,6 +387,13 @@ void ListPopupMenu::insertSingleSelectionMenu(WidgetBa= se* object) insertSubMenuColor(object->useFillColor()); insertStdItems(false, type); insert(mt_Rename); + insert(mt_NameAsTooltip, "Name as Tooltip", CHECKABLE); + { + PortWidget *portW =3D static_cast(object); + FloatingTextWidget *ft =3D portW->floatingTextWidget(); + if (ft =3D=3D NULL) + m_actions[mt_NameAsTooltip]->setChecked(true); + } insert(mt_Properties); break; = diff --git a/umbrello/listpopupmenu.h b/umbrello/listpopupmenu.h index fcb3cb5..ed11b89 100644 --- a/umbrello/listpopupmenu.h +++ b/umbrello/listpopupmenu.h @@ -168,6 +168,7 @@ public: mt_Anchor, mt_Properties, mt_Rename, + mt_NameAsTooltip, mt_Show, mt_Delete, mt_Export_Image, diff --git a/umbrello/widgets/portwidget.cpp b/umbrello/widgets/portwidget.= cpp index c12eb52..d1fd866 100644 --- a/umbrello/widgets/portwidget.cpp +++ b/umbrello/widgets/portwidget.cpp @@ -19,9 +19,11 @@ #include "umlscene.h" #include "umlview.h" #include "componentwidget.h" +#include "floatingtextwidget.h" = // qt includes #include +#include = // sys includes #include @@ -40,6 +42,7 @@ PortWidget::PortWidget(UMLScene *scene, UMLPort *d) m_ignoreSnapToGrid =3D true; m_ignoreSnapComponentSizeToGrid =3D true; m_resizable =3D false; + m_pName =3D NULL; setMinimumSize(FixedSize); setMaximumSize(FixedSize); setSize(FixedSize); @@ -72,7 +75,11 @@ void PortWidget::updateWidget() { QString strName =3D m_umlObject->name(); uDebug() << " port name is " << strName; - setToolTip(strName); + if (m_pName) { + m_pName->setText(strName); + } else { + setToolTip(strName); + } } = /** @@ -180,11 +187,106 @@ void PortWidget::slotCompMoved(qreal diffX, qreal di= ffY) } = /** + * Captures any popup menu signals for menus it created. + */ +void PortWidget::slotMenuSelection(QAction* action) +{ + ListPopupMenu::MenuType sel =3D ListPopupMenu::typeFromAction(action); + switch(sel) { + case ListPopupMenu::mt_NameAsTooltip: + if (m_pName) { + action->setChecked(true); + m_scene->removeWidget(m_pName); + delete m_pName; + m_pName =3D NULL; + setToolTip(m_umlObject->name()); + } else { + action->setChecked(false); + m_pName =3D new FloatingTextWidget(m_scene, Uml::TextRole::Flo= ating, m_umlObject->name()); + m_pName->activate(); + const Uml::ID::Type compWidgetId =3D m_umlObject->umlPackage()= ->id(); + UMLWidget* owner =3D m_scene->widgetOnDiagram(compWidgetId); + if (owner =3D=3D NULL) { + uError() << "m_scene->widgetOnDiagram(" << Uml::ID::toStri= ng(compWidgetId) << ") returns NULL"; + setX(x()); + setY(y()); + } else { + if (x() < owner->x()) + m_pName->setX(x() - m_pName->width()); + else if (x() >=3D owner->x() + owner->width()) + m_pName->setX(x() + 15); + else + m_pName->setX(x() - m_pName->width() / 2.0 + 7); + if (y() < owner->y()) + m_pName->setY(y() - m_pName->height() - 2); + else if (y() >=3D owner->y() + owner->height()) + m_pName->setY(y() + 15); + else + m_pName->setY(y() - m_pName->height() / 2.0 + 7); + } + m_scene->addFloatingTextWidget(m_pName); + setToolTip(QString()); + QToolTip::hideText(); + } + break; + + default: + UMLWidget::slotMenuSelection(action); + } +} + +FloatingTextWidget *PortWidget::floatingTextWidget() { + return m_pName; +} + +void PortWidget::setFloatingTextWidget(FloatingTextWidget *ft) { + m_pName =3D ft; +} + + +/** * Loads from a "portwidget" XMI element. */ bool PortWidget::loadFromXMI(QDomElement & qElement) { - return UMLWidget::loadFromXMI(qElement); + if (!UMLWidget::loadFromXMI(qElement)) + return false; + + QString textid =3D qElement.attribute("textid", "-1"); + Uml::ID::Type textId =3D Uml::ID::fromString(textid); + if (textId !=3D Uml::ID::None) { + UMLWidget *flotext =3D m_scene -> findWidget(textId); + if (flotext !=3D NULL) { + if (flotext->baseType() =3D=3D WidgetBase::wt_Text) { + uWarning() << "Check XMI file: floatingtext " << textid + << " is already defined"; + m_pName =3D static_cast(flotext); + return true; + } else { + uError() << "floatingtext xmi.id" << textid + << " conflicts with existing " << flotext->baseTy= pe(); + return false; + } + } + } + + // Optional child element: floatingtext + QDomNode node =3D qElement.firstChild(); + QDomElement element =3D node.toElement(); + if (!element.isNull()) { + QString tag =3D element.tagName(); + if (tag =3D=3D "floatingtext") { + m_pName =3D new FloatingTextWidget(m_scene, Uml::TextRole::Flo= ating, m_umlObject->name(), textId); + if (!m_pName->loadFromXMI(element)) { + // Most likely cause: The FloatingTextWidget is empty. + delete m_pName; + m_pName =3D NULL; + } + } else { + uError() << "unknown tag " << tag; + } + } + return true; } = /** @@ -194,6 +296,10 @@ void PortWidget::saveToXMI(QDomDocument & qDoc, QDomEl= ement & qElement) { QDomElement conceptElement =3D qDoc.createElement("portwidget"); UMLWidget::saveToXMI(qDoc, conceptElement); + if (m_pName && !m_pName->text().isEmpty()) { + conceptElement.setAttribute("textid", Uml::ID::toString(m_pName->i= d())); + m_pName -> saveToXMI(qDoc, conceptElement); + } qElement.appendChild(conceptElement); } = diff --git a/umbrello/widgets/portwidget.h b/umbrello/widgets/portwidget.h index 11648e2..ec59b33 100644 --- a/umbrello/widgets/portwidget.h +++ b/umbrello/widgets/portwidget.h @@ -14,6 +14,7 @@ #include "umlwidget.h" = class UMLPort; +class FloatingTextWidget; = /** * Defines a graphical version of the port. Most of the functionality @@ -37,15 +38,20 @@ public: virtual void moveWidgetBy(qreal diffX, qreal diffY); void attachToOwningComponent(); = + FloatingTextWidget *floatingTextWidget(); + void setFloatingTextWidget(FloatingTextWidget *ft); + bool loadFromXMI(QDomElement& qElement); void saveToXMI(QDomDocument& qDoc, QDomElement& qElement); = public slots: void slotCompMoved(qreal diffX, qreal diffY); + void slotMenuSelection(QAction* action); = protected: = static const QSizeF FixedSize; + FloatingTextWidget *m_pName; = }; =20