[Uml-devel] KDE/kdesdk/umbrello/umbrello/widgets
Andi Fischer
andi.fischer at hispeed.ch
Fri Oct 8 16:01:15 UTC 2010
SVN commit 1183899 by fischer:
Fix for too small labels of associations.
M +88 -6 floatingtextwidget.cpp
M +8 -115 floatingtextwidget.h
--- trunk/KDE/kdesdk/umbrello/umbrello/widgets/floatingtextwidget.cpp #1183898:1183899
@@ -28,13 +28,14 @@
#include "umldoc.h"
#include "uml.h"
#include "classifier.h"
+#include "linkwidget.h"
#include "listpopupmenu.h"
#include "operation.h"
#include "model_utils.h"
#include "object_factory.h"
#include "messagewidget.h"
-#include "dialogs/assocpropdlg.h"
-#include "dialogs/selectopdlg.h"
+#include "assocpropdlg.h"
+#include "selectopdlg.h"
#include "cmds.h"
/**
@@ -59,6 +60,9 @@
}
}
+/**
+ * Initializes key variables of the class.
+ */
void FloatingTextWidget::init()
{
// initialize loaded/saved (i.e. persistent) data
@@ -79,6 +83,9 @@
{
}
+/**
+ * Overrides default method
+ */
void FloatingTextWidget::draw(QPainter & p, int offsetX, int offsetY)
{
int w = width();
@@ -91,11 +98,17 @@
drawSelected(&p, offsetX, offsetY);
}
+/**
+ * Override default method
+ */
void FloatingTextWidget::resizeEvent(QResizeEvent * re)
{
Q_UNUSED(re);
}
+/**
+ * Overrides method from UMLWidget.
+ */
QSize FloatingTextWidget::calculateSize()
{
const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
@@ -104,6 +117,11 @@
return QSize(w + 8, h + 4); // give a small margin
}
+/**
+ * Called when a menu selection has been made.
+ *
+ * @param action The action that has been selected.
+ */
void FloatingTextWidget::slotMenuSelection(QAction* action)
{
ListPopupMenu::Menu_Type sel = m_pMenu->getMenuType(action);
@@ -173,7 +191,10 @@
}//end switch
}
-/// Handles renaming based on the text role of this widget.
+/**
+ * Handle the ListPopupMenu::mt_Rename case of the slotMenuSelection.
+ * Given an own method because it requires rather lengthy code.
+ */
void FloatingTextWidget::handleRename()
{
QRegExpValidator v(QRegExp(".*"), 0);
@@ -202,7 +223,9 @@
UMLApp::app()->executeCommand(new Uml::CmdHandleRename(this,newText));
}
-/// Changes the text of linked widget.
+/**
+ * Change Name
+ */
void FloatingTextWidget::changeName(const QString& newText)
{
if (m_linkWidget && !isTextValid(newText)) {
@@ -281,8 +304,13 @@
m_Text = seqNum.append(": ").append( op );
} else
m_Text = t;
- } else
+ } else {
m_Text = t;
+ }
+
+ QSize s = calculateSize();
+ setSize(s.width(), s.height());
+
updateComponentSize();
update();
}
@@ -309,6 +337,9 @@
update();
}
+/**
+ * Displays a dialog box to change the text.
+ */
void FloatingTextWidget::showChangeTextDialog()
{
bool ok = false;
@@ -324,6 +355,9 @@
hide();
}
+/**
+ * Shows an operation dialog box.
+ */
void FloatingTextWidget::showOperationDialog()
{
if (m_linkWidget == NULL) {
@@ -436,6 +470,12 @@
return displayText;
}
+/**
+ * Activate the FloatingTextWidget after the saved data has been loaded
+ *
+ * @param ChangeLog Pointer to the IDChangeLog.
+ * @return true for success
+ */
bool FloatingTextWidget::activate( IDChangeLog* ChangeLog /*= 0 */)
{
if (! UMLWidget::activate(ChangeLog))
@@ -444,26 +484,53 @@
return true;
}
+/**
+ * Set the LinkWidget that this FloatingTextWidget is related to.
+ *
+ * @param l The related LinkWidget.
+ */
void FloatingTextWidget::setLink(LinkWidget * l)
{
m_linkWidget = l;
}
-LinkWidget * FloatingTextWidget::link()
+/**
+ * Returns the LinkWidget this floating text is related to.
+ *
+ * @return The LinkWidget this floating text is related to.
+ */
+LinkWidget * FloatingTextWidget::link() const
{
return m_linkWidget;
}
+/**
+ * Sets the role type of this FloatingTextWidget.
+ *
+ * @param role The Text_Role of this FloatingTextWidget.
+ */
void FloatingTextWidget::setRole(Uml::Text_Role role)
{
m_textRole = role;
}
+/**
+ * Return the role of the text widget
+ *
+ * @return The Text_Role of this FloatingTextWidget.
+ */
Uml::Text_Role FloatingTextWidget::textRole() const
{
return m_textRole;
}
+/**
+ * For a text to be valid it must be non-empty, i.e. have a length
+ * larger that zero, and have at least one non whitespace character.
+ *
+ * @param text The string to analyze.
+ * @return True if the given text is valid.
+ */
bool FloatingTextWidget::isTextValid( const QString &text )
{
int length = text.length();
@@ -475,6 +542,12 @@
return false;
}
+/**
+ * Show the properties for a FloatingTextWidget.
+ * Depending on the role of the floating text wiget, the options dialog
+ * for the floating text widget, the rename dialog for floating text or
+ * the options dialog for the link widget are shown.
+ */
void FloatingTextWidget::showProperties()
{
if (m_textRole == Uml::tr_Coll_Message || m_textRole == Uml::tr_Coll_Message_Self ||
@@ -488,6 +561,9 @@
}
}
+/**
+ * Creates the "floatingtext" XMI element.
+ */
void FloatingTextWidget::saveToXMI( QDomDocument & qDoc, QDomElement & qElement )
{
QDomElement textElement = qDoc.createElement( "floatingtext" );
@@ -505,6 +581,9 @@
qElement.appendChild( textElement );
}
+/**
+ * Loads the "floatingtext" XMI element.
+ */
bool FloatingTextWidget::loadFromXMI( QDomElement & qElement )
{
if( !UMLWidget::loadFromXMI( qElement ) )
@@ -534,6 +613,9 @@
{
if (m_linkWidget) {
m_linkWidget->setMessageText(this);
+ QSize s = calculateSize();
+ setSize(s.width(), s.height());
+
}
setVisible(!text().isEmpty());
}
--- trunk/KDE/kdesdk/umbrello/umbrello/widgets/floatingtextwidget.h #1183898:1183899
@@ -12,12 +12,11 @@
#define FLOATINGTEXTWIDGET_H
#include "umlwidget.h"
-#include "linkwidget.h"
+class FloatingTextWidgetController;
+class LinkWidget;
class UMLView;
-class FloatingTextWidgetController;
-
/**
* @short Displays a line of text or an operation.
*
@@ -65,57 +64,20 @@
QString postText() const;
void setPostText(const QString &t);
- /**
- * Set the sequence number to display.
- *
- * @param sn The sequence number to display.
- */
- void setSeqNum(const QString &sn);
+// void setSeqNum(const QString &sn);
+// QString getSeqNum() const;
- /**
- * Return the sequence number.
- *
- * @return The sequence number.
- */
- QString getSeqNum() const;
+// void setOperation(const QString &op);
+// QString getOperation() const;
- /**
- * Set the operation to display.
- *
- * @param op The operation to display.
- */
- void setOperation(const QString &op);
-
- /**
- * Return the operation that is displayed.
- *
- * @return The operation that is displayed.
- *
- QString getOperation() const;
- */
-
QString displayText() const;
- /**
- * Displays a dialog box to change the text.
- */
void showChangeTextDialog();
- /**
- * Set the LinkWidget that this FloatingTextWidget is related to.
- *
- * @param l The related LinkWidget.
- */
void setLink(LinkWidget * l);
+ LinkWidget * link() const;
/**
- * Returns the LinkWidget this floating text is related to.
- *
- * @return The LinkWidget this floating text is related to.
- */
- LinkWidget * link();
-
- /**
* Returns whether this is a line of text.
* Used for transparency in printing.
*
@@ -125,106 +87,37 @@
return true;
}
- /**
- * Activate the FloatingTextWidget after the saved data has been loaded
- *
- * @param ChangeLog Pointer to the IDChangeLog.
- * @return true for success
- */
bool activate( IDChangeLog* ChangeLog = 0 );
- /**
- * Sets the role type of this FloatingTextWidget.
- *
- * @param role The Text_Role of this FloatingTextWidget.
- */
void setRole(Uml::Text_Role role);
-
- /**
- * Return the role of the text widget
- *
- * @return The Text_Role of this FloatingTextWidget.
- */
Uml::Text_Role textRole() const;
- /**
- * For a text to be valid it must be non-empty, i.e. have a length
- * larger that zero, and have at least one non whitespace character.
- *
- * @param text The string to analyze.
- * @return True if the given text is valid.
- */
static bool isTextValid(const QString &text);
- /**
- * Overrides default method
- */
void draw(QPainter & p, int offsetX, int offsetY);
- /**
- * Handle the ListPopupMenu::mt_Rename case of the slotMenuSelection.
- * Given an own method because it requires rather lengthy code.
- */
void handleRename();
- /**
- * Change Name
- */
void changeName(const QString& newText);
- /**
- * Shows an operation dialog box.
- */
void showOperationDialog();
-
- /**
- * Show the properties for a FloatingTextWidget.
- * Depending on the role of the floating text wiget, the options dialog
- * for the floating text widget, the rename dialog for floating text or
- * the options dialog for the link widget are shown.
- */
void showProperties();
- /**
- * Creates the "floatingtext" XMI element.
- */
void saveToXMI( QDomDocument & qDoc, QDomElement & qElement );
-
- /**
- * Loads the "floatingtext" XMI element.
- */
bool loadFromXMI( QDomElement & qElement );
public slots:
- /**
- * Called when a menu selection has been made.
- *
- * @param action The action that has been selected.
- */
void slotMenuSelection(QAction* action);
- /**
- * Sets the text for this label if it is acting as a sequence
- * diagram message or a collaboration diagram message.
- */
void setMessageText();
protected:
- /**
- * Overrides method from UMLWidget.
- */
QSize calculateSize();
private:
- /**
- * Initializes key variables of the class.
- */
void init();
- /**
- * Override default method
- */
- void resizeEvent(QResizeEvent* /*re*/);
+ void resizeEvent(QResizeEvent* re);
/// The association or message widget we may be linked to.
LinkWidget * m_linkWidget;
More information about the umbrello-devel
mailing list