[Uml-devel] KDE/kdesdk/umbrello/umbrello/widgets
Andi Fischer
andi.fischer at hispeed.ch
Sun May 27 11:26:57 UTC 2012
SVN commit 1296786 by fischer:
Code documentation moved from header to implementation file.
M +77 -16 objectnodewidget.cpp
M +10 -76 objectnodewidget.h
--- trunk/KDE/kdesdk/umbrello/umbrello/widgets/objectnodewidget.cpp #1296785:1296786
@@ -29,6 +29,17 @@
#include <QtCore/QPointer>
#include <QtGui/QPainter>
+#define OBJECTNODE_MARGIN 5
+#define OBJECTNODE_WIDTH 30
+#define OBJECTNODE_HEIGHT 10
+
+/**
+ * Creates a Object Node widget.
+ *
+ * @param scene The parent of the widget.
+ * @param objectNodeType The type of object node
+ * @param id The ID to assign (-1 will prompt a new ID.)
+ */
ObjectNodeWidget::ObjectNodeWidget(UMLScene * scene, ObjectNodeType objectNodeType, Uml::IDType id )
: UMLWidget(scene, WidgetBase::wt_ObjectNode, id)
{
@@ -36,10 +47,16 @@
setState("");
}
+/**
+ * Destructor.
+ */
ObjectNodeWidget::~ObjectNodeWidget()
{
}
+/**
+ * Overrides the standard paint event.
+ */
void ObjectNodeWidget::paint(QPainter & p, int offsetX, int offsetY)
{
int w = width();
@@ -58,7 +75,7 @@
p.drawRect(offsetX, offsetY, w, h);
p.setFont( UMLWidget::font() );
- switch ( m_ObjectNodeType )
+ switch ( m_objectNodeType )
{
case Normal : break;
case Buffer :
@@ -102,10 +119,13 @@
}
+/**
+ * Overrides method from UMLWidget.
+ */
UMLSceneSize ObjectNodeWidget::minimumSize()
{
int widthtmp = 10, height = 10,width=10;
- if ( m_ObjectNodeType == Buffer ) {
+ if ( m_objectNodeType == Buffer ) {
const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
const int fontHeight = fm.lineSpacing();
const int textWidth = fm.width("<< centrelBuffer >>");
@@ -116,7 +136,7 @@
height = height > OBJECTNODE_HEIGHT ? height : OBJECTNODE_HEIGHT;
width += OBJECTNODE_MARGIN * 2;
height += OBJECTNODE_MARGIN * 2 + 5;
- } else if ( m_ObjectNodeType == Data ) {
+ } else if ( m_objectNodeType == Data ) {
const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
const int fontHeight = fm.lineSpacing();
const int textWidth = fm.width("<< datastore >>");
@@ -127,7 +147,7 @@
height = height > OBJECTNODE_HEIGHT ? height : OBJECTNODE_HEIGHT;
width += OBJECTNODE_MARGIN * 2;
height += OBJECTNODE_MARGIN * 2 + 5;
- } else if ( m_ObjectNodeType == Flow ) {
+ } else if ( m_objectNodeType == Flow ) {
const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
const int fontHeight = fm.lineSpacing();
const int textWidth = fm.width('[' + state() + ']');
@@ -143,11 +163,18 @@
return UMLSceneSize(width, height);
}
+/**
+ * Returns the type of object node.
+ */
ObjectNodeWidget::ObjectNodeType ObjectNodeWidget::objectNodeType() const
{
- return m_ObjectNodeType;
+ return m_objectNodeType;
}
+/**
+ * Returns the type of object node.
+ * TODO: static, rename to "toObjectNodeType(...).
+ */
ObjectNodeWidget::ObjectNodeType ObjectNodeWidget::objectNodeType(const QString& type) const
{
if (type == "Central buffer")
@@ -161,39 +188,57 @@
return ObjectNodeWidget::Flow;
}
+/**
+ * Sets the type of object node.
+ */
void ObjectNodeWidget::setObjectNodeType( ObjectNodeType objectNodeType )
{
- m_ObjectNodeType = objectNodeType;
+ m_objectNodeType = objectNodeType;
UMLWidget::m_resizable = true;
}
+/**
+ * Sets the type of object node.
+ */
void ObjectNodeWidget::setObjectNodeType( const QString& type )
{
setObjectNodeType(ObjectNodeWidget::objectNodeType(type) );
}
+/**
+ * Sets the state of an object node when it's an objectflow.
+ */
void ObjectNodeWidget::setState(const QString& state)
{
- m_State = state;
+ m_state = state;
updateComponentSize();
}
-QString ObjectNodeWidget::state()
+/**
+ * Returns the state of object node.
+ */
+QString ObjectNodeWidget::state() const
{
- return m_State;
+ return m_state;
}
+/**
+ * Captures any popup menu signals for menus it created.
+ */
void ObjectNodeWidget::slotMenuSelection(QAction* action)
{
bool ok = false;
- QString name = m_Text;
+ QString text = name();
ListPopupMenu::MenuType sel = m_pMenu->getMenuType(action);
switch( sel ) {
case ListPopupMenu::mt_Rename:
- name = KInputDialog::getText( i18n("Enter Object Node Name"), i18n("Enter the name of the object node :"), m_Text, &ok );
- if( ok && name.length() > 0 )
- m_Text = name;
+ text = KInputDialog::getText( i18n("Enter Object Node Name"),
+ i18n("Enter the name of the object node :"),
+ name(), &ok );
+ if (ok && !text.isEmpty()) {
+ setName(text);
+ }
break;
case ListPopupMenu::mt_Properties:
@@ -205,6 +250,9 @@
}
}
+/**
+ * Show a properties dialog for an ObjectNodeWidget.
+ */
void ObjectNodeWidget::showPropertiesDialog()
{
umlScene()->updateDocumentation(false);
@@ -217,17 +265,23 @@
delete dialog;
}
+/**
+ * Saves the widget to the "objectnodewidget" XMI element.
+ */
void ObjectNodeWidget::saveToXMI( QDomDocument & qDoc, QDomElement & qElement )
{
QDomElement objectNodeElement = qDoc.createElement( "objectnodewidget" );
UMLWidget::saveToXMI( qDoc, objectNodeElement );
objectNodeElement.setAttribute( "objectnodename", m_Text );
objectNodeElement.setAttribute( "documentation", m_Doc );
- objectNodeElement.setAttribute( "objectnodetype", m_ObjectNodeType );
- objectNodeElement.setAttribute( "objectnodestate", m_State );
+ objectNodeElement.setAttribute( "objectnodetype", m_objectNodeType );
+ objectNodeElement.setAttribute( "objectnodestate", m_state );
qElement.appendChild( objectNodeElement );
}
+/**
+ * Loads the widget from the "objectnodewidget" XMI element.
+ */
bool ObjectNodeWidget::loadFromXMI( QDomElement & qElement )
{
if( !UMLWidget::loadFromXMI( qElement ) )
@@ -235,11 +289,14 @@
m_Text = qElement.attribute( "objectnodename", "" );
m_Doc = qElement.attribute( "documentation", "" );
QString type = qElement.attribute( "objectnodetype", "1" );
- m_State = qElement.attribute("objectnodestate","");
+ m_state = qElement.attribute("objectnodestate","");
setObjectNodeType( (ObjectNodeType)type.toInt() );
return true;
}
+/**
+ * Open a dialog box to select the objectNode type (Data, Buffer or Flow).
+ */
void ObjectNodeWidget::askForObjectNodeType(UMLWidget* &targetWidget)
{
bool pressedOK = false;
@@ -266,6 +323,10 @@
}
}
+/**
+ * Open a dialog box to input the state of the widget.
+ * This box is shown only if m_objectNodeType = Flow.
+ */
void ObjectNodeWidget::askStateForWidget()
{
bool pressedOK = false;
--- trunk/KDE/kdesdk/umbrello/umbrello/widgets/objectnodewidget.h #1296785:1296786
@@ -4,7 +4,7 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
- * copyright (C) 2002-2009 *
+ * copyright (C) 2002-2012 *
* Umbrello UML Modeller Authors <uml-devel at uml.sf.net> *
***************************************************************************/
@@ -12,12 +12,7 @@
#define OBJECTNODEWIDGET_H
#include "umlwidget.h"
-#include "worktoolbar.h"
-#define OBJECTNODE_MARGIN 5
-#define OBJECTNODE_WIDTH 30
-#define OBJECTNODE_HEIGHT 10
-
/**
* This class is the graphical version of a UML Object Node. A ObjectNodeWidget is created
* by a @ref UMLView. An ObjectNodeWidget belongs to only one @ref UMLView instance.
@@ -43,100 +38,39 @@
Flow
};
- /**
- * Creates a Object Node widget.
- *
- * @param scene The parent of the widget.
- * @param objectNodeType The type of object node
- * @param id The ID to assign (-1 will prompt a new ID.)
- */
explicit ObjectNodeWidget( UMLScene * scene, ObjectNodeType objectNodeType = Normal, Uml::IDType id = Uml::id_None );
-
-
- /**
- * destructor
- */
virtual ~ObjectNodeWidget();
- /**
- * Overrides the standard paint event.
- */
void paint(QPainter & p, int offsetX, int offsetY);
- /**
- * Returns the type of object node.
- */
ObjectNodeType objectNodeType() const;
ObjectNodeType objectNodeType(const QString& type) const;
- /**
- * Sets the type of object node.
- */
void setObjectNodeType( ObjectNodeType objectNodeType );
void setObjectNodeType( const QString& type ) ;
- /**
- * Sets the state of an object node when it's an objectflow.
- */
void setState(const QString& state);
+ QString state() const;
- /**
- * Returns the state of object node.
- */
- QString state();
-
- /**
- * Show a properties dialog for an ObjectNodeWidget.
- *
- */
virtual void showPropertiesDialog();
-
- /**
- * Saves the widget to the "objectnodewidget" XMI element.
- */
- void saveToXMI( QDomDocument & qDoc, QDomElement & qElement );
-
- /**
- * Loads the widget from the "objectnodewidget" XMI element.
- */
- bool loadFromXMI( QDomElement & qElement );
-
- /**
- * Open a dialog box to select the objectNode type (Data, Buffer or Flow)
- */
+ void askStateForWidget();
void askForObjectNodeType(UMLWidget* &targetWidget);
- /**
- * Open a dialog box to input the state of the widget
- * This box is shown only if m_ObjectNodeType = Flow
- */
- void askStateForWidget();
+ virtual void saveToXMI(QDomDocument& qDoc, QDomElement& qElement);
+ virtual bool loadFromXMI(QDomElement& qElement);
protected:
- /**
- * Overrides method from UMLWidget
- */
UMLSceneSize minimumSize();
- /**
- * Type of object node.
- */
- ObjectNodeType m_ObjectNodeType;
-
- /**
- * State of the object node when it's an objectFlow
- */
- QString m_State;
-
public slots:
-
- /**
- * Captures any popup menu signals for menus it created.
- */
void slotMenuSelection(QAction* action);
-
void slotOk();
+
+private:
+ ObjectNodeType m_objectNodeType; ///< type of object node
+ QString m_state; ///< state of object node when it's an objectFlow
+
};
#endif
More information about the umbrello-devel
mailing list