Commit f8d4dbf7 authored by Oliver Kellogg's avatar Oliver Kellogg
Browse files

Permit creation of ports using toolbar for component diagram:

umbrello/widgets/toolbarstateonewidget.cpp
- In function mouseReleaseWidget() admit
    currentWidget()->baseType() == WidgetBase::wt_Component
  to the call of setWidget(currentWidget())
- In function setWidget() handling of widgetType() == WidgetBase::wt_Pin,
  add handling of m_firstObject->baseType() == WidgetBase::wt_Component:
  - Open a dialog querying the user for a new port name
  - If user confirmed port creation then
    - Let Object_Factory create a UML Port object of given name.
      The object is owned by the UML Component underlying m_firstObject.
    - Let Widget_Factory create a PortWidget representing the UML Port and
      assign this widget to `umlwidget'.

umbrello/worktoolbar.cpp
- In function slotCheckToolBar(Uml::DiagramType::Enum) switch (m_Type) case
  Uml::DiagramType::Component, insertHotBtn(tbb_Pin).
  tbb_Pin is reused for ports.

umbrello/widgets/portwidget.cpp
- In function attachToOwningComponent() prevent the port from being dropped
  underneath its owning component (thus becoming inaccessible).
  This is achieved as follows:
  If scenePos.x() is in the range
    [ owner->x() : owner->x() + owner->width() ]
  and scenePos.y() is in the range
    [ owner->y() : owner->y() + owner->height() ]
  then
    if scenePos.y() is in the top half of owner then
      setY(owner->y() - height())
    else
      setY(owner->y() + owner->height())

CCBUG:115269
parent ed9a487b
......@@ -146,18 +146,29 @@ void PortWidget::attachToOwningComponent() {
setY(scenePos.y());
return;
}
if (scenePos.x() < owner->x() - width())
bool xIsWithinComponent = false;
if (scenePos.x() < owner->x() - width()) {
setX(owner->x() - width());
else if (scenePos.x() <= owner->x() + owner->width())
} else if (scenePos.x() <= owner->x() + owner->width()) {
setX(scenePos.x());
else
xIsWithinComponent = true;
} else {
setX(owner->x() + owner->width());
if (scenePos.y() < owner->y() - height())
}
if (scenePos.y() < owner->y() - height()) {
setY(owner->y() - height());
else if (scenePos.y() <= owner->y() + owner->height())
setY(scenePos.y());
else
} else if (scenePos.y() <= owner->y() + owner->height()) {
if (xIsWithinComponent) {
if (scenePos.y() <= owner->y() + owner->height() / 2.0)
setY(owner->y() - height());
else
setY(owner->y() + owner->height());
} else {
setY(scenePos.y());
}
} else {
setY(owner->y() + owner->height());
}
}
/**
......
......@@ -18,18 +18,23 @@
#include "messagewidget.h"
#include "objectwidget.h"
#include "pinwidget.h"
#include "portwidget.h"
#include "preconditionwidget.h"
#include "regionwidget.h"
#include "uml.h"
#include "umldoc.h"
#include "umlscene.h"
#include "umlwidget.h"
#include "object_factory.h"
#include "package.h"
#include "widget_factory.h"
// kde includes
#include <klocale.h>
#include <kmessagebox.h>
#include <kinputdialog.h>
using namespace Uml;
// using namespace Uml;
/**
* Creates a new ToolBarStateOneWidget.
......@@ -126,9 +131,10 @@ void ToolBarStateOneWidget::mouseReleaseWidget()
m_firstObject = 0;
}
if (m_pMouseEvent->button() != Qt::LeftButton ||(
currentWidget()->baseType() != WidgetBase::wt_Object &&
if (m_pMouseEvent->button() != Qt::LeftButton ||
(currentWidget()->baseType() != WidgetBase::wt_Object &&
currentWidget()->baseType() != WidgetBase::wt_Activity &&
currentWidget()->baseType() != WidgetBase::wt_Component &&
currentWidget()->baseType() != WidgetBase::wt_Region)) {
return;
}
......@@ -178,8 +184,19 @@ void ToolBarStateOneWidget::setWidget(UMLWidget* firstObject)
}
if (widgetType() == WidgetBase::wt_Pin) {
umlwidget = new PinWidget(m_pUMLScene, m_firstObject);
if (m_firstObject->baseType() == WidgetBase::wt_Activity) {
umlwidget = new PinWidget(m_pUMLScene, m_firstObject);
// Create the widget. Some setup functions can remove the widget.
} else if (m_firstObject->baseType() == WidgetBase::wt_Component) {
bool pressedOK = false;
QString name = KInputDialog::getText(i18n("Enter Port Name"), i18n("Enter the port"), i18n("new port"),
&pressedOK, UMLApp::app());
if (pressedOK) {
UMLPackage* component = static_cast<UMLPackage*>(m_firstObject->umlObject());
UMLObject *port = Object_Factory::createUMLObject(UMLObject::ot_Port, name, component);
umlwidget = Widget_Factory::createWidget(m_pUMLScene, port);
}
}
}
if (umlwidget) {
......
......@@ -177,6 +177,7 @@ void WorkToolBar::slotCheckToolBar(Uml::DiagramType::Enum dt)
case Uml::DiagramType::Component:
insertHotBtn(tbb_Interface);
insertHotBtn(tbb_Component);
insertHotBtn(tbb_Pin);
insertHotBtn(tbb_Artifact);
insertBasicAssociations();
break;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment