[Uml-devel] KDE/kdesdk/umbrello/umbrello/widgets

Ralf Habacker ralf.habacker at gmail.com
Wed Dec 14 14:19:59 UTC 2011


SVN commit 1268730 by habacker:

fixed NoteWidget's method documentation locations and ordering according to class definition

 M  +198 -123  notewidget.cpp  
 M  +12 -78    notewidget.h  


--- trunk/KDE/kdesdk/umbrello/umbrello/widgets/notewidget.cpp #1268729:1268730
@@ -27,6 +27,14 @@
 #include "umlview.h"
 #include "uml.h"
 
+/**
+ * Constructs a NoteWidget.
+ *
+ * @param view              The parent to this widget.
+ * @param noteType          The NoteWidget::NoteType of this NoteWidget
+ * @param id                The unique id of the widget.
+ *                  The default (-1) will prompt a new ID.
+ */
 NoteWidget::NoteWidget(UMLView * view, NoteType noteType , Uml::IDType id)
   : UMLWidget(view, id, new NoteWidgetController(this))
 {
@@ -36,11 +44,75 @@
     setZ(20); //make sure always on top.
 }
 
+/**
+ * destructor
+ */
+NoteWidget::~NoteWidget()
+{
+}
+
+/**
+ * Override default method.
+ */
+void NoteWidget::draw(QPainter & p, int offsetX, int offsetY)
+{
+    const int margin = 10;
+    int w = width()-1;
+    int h = height()-1;
+    const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
+    const int fontHeight  = fm.lineSpacing();
+    QPolygon poly(6);
+    poly.setPoint(0, offsetX, offsetY);
+    poly.setPoint(1, offsetX, offsetY + h);
+    poly.setPoint(2, offsetX + w, offsetY + h);
+    poly.setPoint(3, offsetX + w, offsetY + margin);
+    poly.setPoint(4, offsetX + w - margin, offsetY);
+    poly.setPoint(5, offsetX, offsetY);
+
+    setPenFromSettings(p);
+    if ( UMLWidget::getUseFillColour() ) {
+        QBrush brush( UMLWidget::getFillColor() );
+        p.setBrush(brush);
+        p.drawPolygon(poly);
+    } else
+        p.drawPolyline(poly);
+    p.drawLine(offsetX + w - margin, offsetY, offsetX + w - margin, offsetY + margin);
+    p.drawLine(offsetX + w - margin, offsetY + margin, offsetX + w, offsetY + margin);
+    p.setPen(Qt::black);
+    switch(m_NoteType) {
+    case NoteWidget::PreCondition :
+        p.drawText(offsetX, offsetY + margin, w, fontHeight, Qt::AlignCenter, "<< precondition >>");
+        break;
+    case NoteWidget::PostCondition :
+        p.drawText(offsetX, offsetY + margin, w, fontHeight, Qt::AlignCenter, "<< postcondition >>");
+        break;
+    case NoteWidget::Transformation :
+        p.drawText(offsetX, offsetY + margin, w, fontHeight, Qt::AlignCenter, "<< transformation >>");
+        break;
+    case NoteWidget::Normal :
+    default :
+        break;
+    }
+
+    if (m_selected) {
+        drawSelected(&p, offsetX, offsetY);
+    }
+
+//    drawText(&p, offsetX, offsetY);
+    drawTextWordWrap(&p, offsetX, offsetY);
+}
+
+/**
+ * Returns the type of note.
+ */
 NoteWidget::NoteType NoteWidget::getNoteType() const
 {
     return m_NoteType;
 }
 
+/**
+ * Returns the type of note.
+ */
 NoteWidget::NoteType NoteWidget::getNoteType(const QString& noteType) const
 {
     if (noteType == "Precondition")
@@ -53,20 +125,84 @@
         return NoteWidget::Normal;
 }
 
+/**
+ * Sets the type of note.
+ */
 void NoteWidget::setNoteType( NoteType noteType )
 {
     m_NoteType = noteType;
 }
 
+/**
+ * Sets the type of note.
+ */
 void NoteWidget::setNoteType( const QString& noteType )
 {
     setNoteType(getNoteType(noteType));
 }
 
-NoteWidget::~NoteWidget()
+/**
+ * Override method from UMLWidget.
+ */
+void NoteWidget::setFont(QFont font)
 {
+    UMLWidget::setFont(font);
 }
 
+/**
+ * Override method from UMLWidget.
+ */
+void NoteWidget::setX( int x )
+{
+    UMLWidget::setX(x);
+}
+
+/**
+ * Override method from UMLWidget.
+ */
+void NoteWidget::setY( int y )
+{
+    UMLWidget::setY(y);
+}
+
+/**
+ * Returns the text in the box.
+ *
+ * @return  The text in the box.
+ */
+QString NoteWidget::documentation() const
+{
+    return m_Text;
+}
+
+/**
+ * Sets the note documentation.
+ *
+ * @param newText   The text to set the documentation to.
+ */
+void NoteWidget::setDocumentation(const QString &newText)
+{
+    m_Text = newText;
+    update();
+}
+
+/**
+ * Return the ID of the diagram hyperlinked to this note.
+ *
+ * @return  ID of an UMLView, or Uml::id_None if no
+ *          hyperlink is set.
+ */
+Uml::IDType NoteWidget::getDiagramLink() const
+{
+    return m_DiagramLink;
+}
+
+/**
+ * Set the ID of the diagram hyperlinked to this note.
+ * To switch off the hyperlink, set this to Uml::id_None.
+ *
+ * @param viewID    ID of an UMLView.
+ */
 void NoteWidget::setDiagramLink(Uml::IDType viewID)
 {
     UMLDoc *umldoc = UMLApp::app()->document();
@@ -80,85 +216,87 @@
     m_DiagramLink = viewID;
 }
 
-Uml::IDType NoteWidget::getDiagramLink() const
+/**
+* Display a dialogBox to allow the user to choose the note's type
+*/
+void NoteWidget::askForNoteType(UMLWidget* &targetWidget)
 {
-    return m_DiagramLink;
-}
+    bool pressedOK = false;
+    const QStringList list = QStringList() << "Precondition" << "Postcondition" << "Transformation";
+    QString type = KInputDialog::getItem (i18n("Note Type"), i18n("Select the Note Type"), list, 0, false, &pressedOK, UMLApp::app());
 
-void NoteWidget::setFont(QFont font)
-{
-    UMLWidget::setFont(font);
+    if (pressedOK) {
+        dynamic_cast<NoteWidget*>(targetWidget)->setNoteType(type);
+    } else {
+        targetWidget->cleanup();
+        delete targetWidget;
+        targetWidget = NULL;
 }
-
-void NoteWidget::setX( int x )
-{
-    UMLWidget::setX(x);
 }
 
-void NoteWidget::setY( int y )
+/**
+ * Loads a "notewidget" XMI element.
+ */
+bool NoteWidget::loadFromXMI( QDomElement & qElement )
 {
-    UMLWidget::setY(y);
+    if( !UMLWidget::loadFromXMI( qElement ) )
+        return false;
+    setZ( 20 ); //make sure always on top.
+    setDocumentation( qElement.attribute("text", "") );
+    QString diagramlink = qElement.attribute("diagramlink", "");
+    if (!diagramlink.isEmpty())
+        m_DiagramLink = STR2ID(diagramlink);
+    QString type = qElement.attribute("noteType", "");
+    setNoteType( (NoteType)type.toInt() );
+    return true;
 }
 
-QString NoteWidget::documentation() const
+/**
+ * Saves to the "notewidget" XMI element.
+ */
+void NoteWidget::saveToXMI( QDomDocument & qDoc, QDomElement & qElement )
 {
-    return m_Text;
+    QDomElement noteElement = qDoc.createElement( "notewidget" );
+    UMLWidget::saveToXMI( qDoc, noteElement );
+    noteElement.setAttribute( "text", documentation() );
+    if (m_DiagramLink != Uml::id_None)
+        noteElement.setAttribute( "diagramlink", ID2STR(m_DiagramLink) );
+    noteElement.setAttribute( "noteType", m_NoteType);
+    qElement.appendChild( noteElement );
 }
 
-void NoteWidget::setDocumentation(const QString &newText)
+/**
+ * Will be called when a menu selection has been made from the popup
+ * menu.
+ *
+ * @param action       The action that has been selected.
+ */
+void NoteWidget::slotMenuSelection(QAction* action)
 {
-    m_Text = newText;
+    NoteDialog * dlg = 0;
+    UMLDoc *doc = UMLApp::app()->document();
+    ListPopupMenu::MenuType sel = m_pMenu->getMenuType(action);
+    switch(sel) {
+    case ListPopupMenu::mt_Rename:
+        m_pView->updateDocumentation( false );
+        dlg = new NoteDialog( m_pView, this );
+        if( dlg->exec() ) {
+            m_pView->showDocumentation( this, true );
+            doc->setModified(true);
     update();
 }
+        delete dlg;
+        break;
 
-void NoteWidget::draw(QPainter & p, int offsetX, int offsetY)
-{
-    const int margin = 10;
-    int w = width()-1;
-    int h = height()-1;
-    const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
-    const int fontHeight  = fm.lineSpacing();
-    QPolygon poly(6);
-    poly.setPoint(0, offsetX, offsetY);
-    poly.setPoint(1, offsetX, offsetY + h);
-    poly.setPoint(2, offsetX + w, offsetY + h);
-    poly.setPoint(3, offsetX + w, offsetY + margin);
-    poly.setPoint(4, offsetX + w - margin, offsetY);
-    poly.setPoint(5, offsetX, offsetY);
-
-    setPenFromSettings(p);
-    if ( UMLWidget::getUseFillColour() ) {
-        QBrush brush( UMLWidget::getFillColor() );
-        p.setBrush(brush);
-        p.drawPolygon(poly);
-    } else
-        p.drawPolyline(poly);
-    p.drawLine(offsetX + w - margin, offsetY, offsetX + w - margin, offsetY + margin);
-    p.drawLine(offsetX + w - margin, offsetY + margin, offsetX + w, offsetY + margin);
-    p.setPen(Qt::black);
-    switch(m_NoteType) {
-    case NoteWidget::PreCondition :
-        p.drawText(offsetX, offsetY + margin, w, fontHeight, Qt::AlignCenter, "<< precondition >>");
-        break;
-    case NoteWidget::PostCondition :
-        p.drawText(offsetX, offsetY + margin, w, fontHeight, Qt::AlignCenter, "<< postcondition >>");
-        break;
-    case NoteWidget::Transformation :
-        p.drawText(offsetX, offsetY + margin, w, fontHeight, Qt::AlignCenter, "<< transformation >>");
-        break;
-    case NoteWidget::Normal :
     default :
+        UMLWidget::slotMenuSelection(action);
         break;
     }
-
-    if (m_selected) {
-        drawSelected(&p, offsetX, offsetY);
     }
 
-//    drawText(&p, offsetX, offsetY);
-    drawTextWordWrap(&p, offsetX, offsetY);
-}
-
+/**
+ * Overrides method from UMLWidget.
+ */
 QSize NoteWidget::calculateSize()
 {
     int width = 60;
@@ -186,29 +324,6 @@
     return QSize(width, height);
 }
 
-void NoteWidget::slotMenuSelection(QAction* action)
-{
-    NoteDialog * dlg = 0;
-    UMLDoc *doc = UMLApp::app()->document();
-    ListPopupMenu::MenuType sel = m_pMenu->getMenuType(action);
-    switch(sel) {
-    case ListPopupMenu::mt_Rename:
-        m_pView->updateDocumentation( false );
-        dlg = new NoteDialog( m_pView, this );
-        if( dlg->exec() ) {
-            m_pView->showDocumentation( this, true );
-            doc->setModified(true);
-            update();
-        }
-        delete dlg;
-        break;
-
-    default:
-        UMLWidget::slotMenuSelection(action);
-        break;
-    }
-}
-
 /**
  * Draws the text. Auxiliary to draw().
  * Implemented without word wrap.
@@ -371,45 +486,5 @@
     }//end for
 }
 
-void NoteWidget::askForNoteType(UMLWidget* &targetWidget)
-{
-    bool pressedOK = false;
-    const QStringList list = QStringList() << "Precondition" << "Postcondition" << "Transformation";
-    QString type = KInputDialog::getItem (i18n("Note Type"), i18n("Select the Note Type"), list, 0, false, &pressedOK, UMLApp::app());
-
-    if (pressedOK) {
-        dynamic_cast<NoteWidget*>(targetWidget)->setNoteType(type);
-    } else {
-        targetWidget->cleanup();
-        delete targetWidget;
-        targetWidget = NULL;
-    }
-}
-
-void NoteWidget::saveToXMI( QDomDocument & qDoc, QDomElement & qElement )
-{
-    QDomElement noteElement = qDoc.createElement( "notewidget" );
-    UMLWidget::saveToXMI( qDoc, noteElement );
-    noteElement.setAttribute( "text", documentation() );
-    if (m_DiagramLink != Uml::id_None)
-        noteElement.setAttribute( "diagramlink", ID2STR(m_DiagramLink) );
-    noteElement.setAttribute( "noteType", m_NoteType);
-    qElement.appendChild( noteElement );
-}
-
-bool NoteWidget::loadFromXMI( QDomElement & qElement )
-{
-    if( !UMLWidget::loadFromXMI( qElement ) )
-        return false;
-    setZ( 20 ); //make sure always on top.
-    setDocumentation( qElement.attribute("text", "") );
-    QString diagramlink = qElement.attribute("diagramlink", "");
-    if (!diagramlink.isEmpty())
-        m_DiagramLink = STR2ID(diagramlink);
-    QString type = qElement.attribute("noteType", "");
-    setNoteType( (NoteType)type.toInt() );
-    return true;
-}
-
 #include "notewidget.moc"
 
--- trunk/KDE/kdesdk/umbrello/umbrello/widgets/notewidget.h #1268729:1268730
@@ -43,114 +43,48 @@
         PostCondition,
         Transformation
     };
-
-    /**
-     * Constructs a NoteWidget.
-     *
-     * @param view              The parent to this widget.
-     * @param noteType          The NoteWidget::NoteType of this NoteWidget
-     * @param id                The unique id of the widget.
-     *                  The default (-1) will prompt a new ID.
-     */
     explicit NoteWidget(UMLView * view, NoteWidget::NoteType noteType = Normal, Uml::IDType id = Uml::id_None );
-
-    /**
-     * destructor
-     */
     virtual ~NoteWidget();
 
-    /**
-     * Returns the type of note.
-     */
+    void draw(QPainter & p, int offsetX, int offsetY);
+
     NoteType getNoteType() const;
     NoteType getNoteType(const QString& noteType) const;
-
-    /**
-     * Sets the type of note.
-     */
     void setNoteType( NoteType noteType );
     void setNoteType( const QString& noteType );
 
-    /**
-     * Overrides method from UMLWidget.
-     */
-    QSize calculateSize();
-
-    /**
-     * Returns the text in the box.
-     *
-     * @return  The text in the box.
-     */
     QString documentation() const;
-
-    /**
-     * Sets the note documentation.
-     *
-     * @param newText   The text to set the documentation to.
-     */
     void setDocumentation(const QString &newText);
 
-    /**
-     * Set the ID of the diagram hyperlinked to this note.
-     * To switch off the hyperlink, set this to Uml::id_None.
-     *
-     * @param viewID    ID of an UMLView.
-     */
+    Uml::IDType getDiagramLink() const;
     void setDiagramLink(Uml::IDType viewID);
 
-    /**
-     * Return the ID of the diagram hyperlinked to this note.
-     *
-     * @return  ID of an UMLView, or Uml::id_None if no
-     *          hyperlink is set.
-     */
-    Uml::IDType getDiagramLink() const;
-
-    /**
-     * Override default method.
-     */
-    void draw(QPainter & p, int offsetX, int offsetY);
-
-    /**
-     * Override method from UMLWidget.
-     */
+    // this method is obsolate 
     void setFont(QFont font);
 
-    /**
-     * Override method from UMLWidget.
-     */
+    // this method is obsolate 
     void setX(int x);
-
-    /**
-     * Override method from UMLWidget.
-     */
+    // this method is obsolate 
     void setY(int y);
 
-    /**
-    * Display a dialogBox to allow the user to choose the note's type
-    */
     void askForNoteType(UMLWidget* &targetWidget);
 
-    /**
-     * Saves to the "notewidget" XMI element.
-     */
+    bool loadFromXMI( QDomElement & qElement );
     void saveToXMI( QDomDocument & qDoc, QDomElement & qElement );
 
-    /**
-     * Loads a "notewidget" XMI element.
-     */
-    bool loadFromXMI( QDomElement & qElement );
 
-public slots:
+public Q_SLOTS:
     void slotMenuSelection(QAction* action);
 
 protected:
+    QSize calculateSize();
+    void drawText(QPainter * p = NULL, int offsetX = 0, int offsetY = 0);
+    void drawTextWordWrap(QPainter * p = NULL, int offsetX = 0, int offsetY = 0);
+
     Uml::IDType m_DiagramLink;  ///< Data loaded/saved.
     NoteType    m_NoteType;     ///< Type of note.
     QString     l_Type;         ///< Label to see the note's type.
 
-    void drawText(QPainter * p = NULL, int offsetX = 0, int offsetY = 0);
-    void drawTextWordWrap(QPainter * p = NULL, int offsetX = 0, int offsetY = 0);
 
 private:
     QString m_Text;




More information about the umbrello-devel mailing list