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

Ralf Habacker ralf.habacker at gmail.com
Tue Dec 13 15:55:22 UTC 2011


SVN commit 1268569 by habacker:

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

 M  +140 -105  artifactwidget.cpp  
 M  +5 -51     artifactwidget.h  


--- trunk/KDE/kdesdk/umbrello/umbrello/widgets/artifactwidget.cpp #1268568:1268569
@@ -11,15 +11,17 @@
 // own header
 #include "artifactwidget.h"
 
-// qt/kde includes
-#include <QtGui/QPainter>
-
 // app includes
 #include "artifact.h"
 #include "debug_utils.h"
 #include "umlview.h"
 
-
+/**
+ * Constructs a ArtifactWidget.
+ *
+ * @param view              The parent of this ArtifactWidget.
+ * @param a         The Artifact this widget will be representing.
+ */
 ArtifactWidget::ArtifactWidget(UMLView *view, UMLArtifact *a)
   : UMLWidget(view, a)
 {
@@ -28,57 +30,124 @@
     updateComponentSize();
 }
 
+/**
+ * Destructor.
+ */
+ArtifactWidget::~ArtifactWidget()
+{
+}
 
+/**
+ * Overrides standard method
+ */
+void ArtifactWidget::draw(QPainter& p, int offsetX, int offsetY)
+{
+    UMLWidget::setPenFromSettings(p);
+    if ( UMLWidget::getUseFillColour() ) {
+        p.setBrush( UMLWidget::getFillColor() );
+    } else {
+        p.setBrush( m_pView->viewport()->palette().color(QPalette::Background) );
+    }
+
+    UMLArtifact *umlart = static_cast<UMLArtifact*>(m_pObject);
+    UMLArtifact::Draw_Type drawType = umlart->getDrawAsType();
+    switch (drawType) {
+    case UMLArtifact::defaultDraw:
+        return drawAsNormal(p, offsetX, offsetY);
+        break;
+    case UMLArtifact::file:
+        return drawAsFile(p, offsetX, offsetY);
+        break;
+    case UMLArtifact::library:
+        return drawAsLibrary(p, offsetX, offsetY);
+        break;
+    case UMLArtifact::table:
+        return drawAsTable(p, offsetX, offsetY);
+        break;
+    default:
+        uWarning() << "Artifact drawn as unknown type";
+        break;
+    }
+}
+
+/**
+ * Reimplemented from WidgetBase::saveToXMI to save the widget to
+ * the "artifactwidget" XMI element.
+ */
+void ArtifactWidget::saveToXMI(QDomDocument& qDoc, QDomElement& qElement)
+{
+    QDomElement conceptElement = qDoc.createElement("artifactwidget");
+    UMLWidget::saveToXMI(qDoc, conceptElement);
+    qElement.appendChild(conceptElement);
+}
+
+/**
+ * Overrides method from UMLWidget.
+ */
+QSize ArtifactWidget::calculateSize()
+{
+    if ( !m_pObject) {
+        return UMLWidget::calculateSize();
+    }
+    UMLArtifact *umlart = static_cast<UMLArtifact*>(m_pObject);
+    if (umlart->getDrawAsType() == UMLArtifact::defaultDraw) {
+        return calculateNormalSize();
+    } else {
+        return calculateIconSize();
+    }
+}
+
+/**
+ * Initializes key variables of the class.
+ */
 void ArtifactWidget::init()
 {
     UMLWidget::setBaseType( WidgetBase::wt_Artifact );
     m_pMenu = 0;
 }
 
-ArtifactWidget::~ArtifactWidget()
+/**
+ * calculates the size when drawing as an icon (it's the same size for all icons)
+ */
+QSize ArtifactWidget::calculateIconSize()
 {
+    const QFontMetrics &fm = getFontMetrics(FT_BOLD_ITALIC);
+    const int fontHeight  = fm.lineSpacing();
+
+    int width = fm.width( m_pObject->name() );
+
+    width = width<50 ? 50 : width;
+
+    int height = 50 + fontHeight;
+
+    return QSize(width, height);
 }
 
-void ArtifactWidget::drawAsNormal(QPainter& p, int offsetX, int offsetY)
+/**
+ * calculates the size for drawing as a box
+ */
+QSize ArtifactWidget::calculateNormalSize()
 {
-    int w = width();
-    int h = height();
-    QFont font = UMLWidget::font();
-    font.setBold(true);
-    const QFontMetrics &fm = getFontMetrics(FT_BOLD);
+    const QFontMetrics &fm = getFontMetrics(FT_BOLD_ITALIC);
     const int fontHeight  = fm.lineSpacing();
-    QString stereotype = m_pObject->stereotype();
 
-    p.drawRect(offsetX, offsetY, w, h);
+    int width = fm.width( m_pObject->name() );
 
-    p.setPen( QPen(Qt::black) );
-    p.setFont(font);
-
-    if (!stereotype.isEmpty()) {
-        p.drawText(offsetX + ARTIFACT_MARGIN, offsetY + (h/2) - fontHeight,
-                   w, fontHeight, Qt::AlignCenter, m_pObject->stereotype(true));
+    int tempWidth = 0;
+    if(!m_pObject->stereotype().isEmpty()) {
+        tempWidth = fm.width( m_pObject->stereotype(true) );
     }
+    width = tempWidth>width ? tempWidth : width;
+    width += ARTIFACT_MARGIN * 2;
 
-    int lines;
-    if (!stereotype.isEmpty()) {
-        lines = 2;
-    } else {
-        lines = 1;
-    }
+    int height = (2*fontHeight) + (ARTIFACT_MARGIN * 2);
 
-    if (lines == 1) {
-        p.drawText(offsetX, offsetY + (h/2) - (fontHeight/2),
-                   w, fontHeight, Qt::AlignCenter, name());
-    } else {
-        p.drawText(offsetX, offsetY + (h/2),
-                   w, fontHeight, Qt::AlignCenter, name());
+    return QSize(width, height);
     }
 
-    if(m_bSelected) {
-        drawSelected(&p, offsetX, offsetY);
-    }
-}
-
+/**
+ * draw as a file icon
+ */
 void ArtifactWidget::drawAsFile(QPainter& p, int offsetX, int offsetY)
 {
     const int w = width();
@@ -112,6 +181,9 @@
     }
 }
 
+/**
+ * draw as a library file icon
+ */
 void ArtifactWidget::drawAsLibrary(QPainter& p, int offsetX, int offsetY)
 {
     //FIXME this should have gears on it
@@ -146,6 +218,9 @@
     }
 }
 
+/**
+ * draw as a database table icon
+ */
 void ArtifactWidget::drawAsTable(QPainter& p, int offsetX, int offsetY)
 {
     const int w = width();
@@ -182,86 +257,46 @@
     }
 }
 
-void ArtifactWidget::draw(QPainter& p, int offsetX, int offsetY)
+/**
+ * draw as a box
+ */
+void ArtifactWidget::drawAsNormal(QPainter& p, int offsetX, int offsetY)
 {
-    UMLWidget::setPenFromSettings(p);
-    if ( UMLWidget::getUseFillColour() ) {
-        p.setBrush( UMLWidget::getFillColor() );
-    } else {
-        p.setBrush( m_pView->viewport()->palette().color(QPalette::Background) );
-    }
-
-    UMLArtifact *umlart = static_cast<UMLArtifact*>(m_pObject);
-    UMLArtifact::Draw_Type drawType = umlart->getDrawAsType();
-    switch (drawType) {
-    case UMLArtifact::defaultDraw:
-        return drawAsNormal(p, offsetX, offsetY);
-        break;
-    case UMLArtifact::file:
-        return drawAsFile(p, offsetX, offsetY);
-        break;
-    case UMLArtifact::library:
-        return drawAsLibrary(p, offsetX, offsetY);
-        break;
-    case UMLArtifact::table:
-        return drawAsTable(p, offsetX, offsetY);
-        break;
-    default:
-        uWarning() << "Artifact drawn as unknown type";
-        break;
-    }
-}
-
-QSize ArtifactWidget::calculateIconSize()
-{
-    const QFontMetrics &fm = getFontMetrics(FT_BOLD_ITALIC);
+    int w = width();
+    int h = height();
+    QFont font = UMLWidget::font();
+    font.setBold(true);
+    const QFontMetrics &fm = getFontMetrics(FT_BOLD);
     const int fontHeight  = fm.lineSpacing();
+    QString stereotype = m_pObject->stereotype();
 
-    int width = fm.width( m_pObject->name() );
+    p.drawRect(offsetX, offsetY, w, h);
 
-    width = width<50 ? 50 : width;
+    p.setPen( QPen(Qt::black) );
+    p.setFont(font);
 
-    int height = 50 + fontHeight;
-
-    return QSize(width, height);
+    if (!stereotype.isEmpty()) {
+        p.drawText(offsetX + ARTIFACT_MARGIN, offsetY + (h/2) - fontHeight,
+                   w, fontHeight, Qt::AlignCenter, m_pObject->stereotype(true));
 }
 
-QSize ArtifactWidget::calculateNormalSize()
-{
-    const QFontMetrics &fm = getFontMetrics(FT_BOLD_ITALIC);
-    const int fontHeight  = fm.lineSpacing();
-
-    int width = fm.width( m_pObject->name() );
-
-    int tempWidth = 0;
-    if(!m_pObject->stereotype().isEmpty()) {
-        tempWidth = fm.width( m_pObject->stereotype(true) );
+    int lines;
+    if (!stereotype.isEmpty()) {
+        lines = 2;
+    } else {
+        lines = 1;
     }
-    width = tempWidth>width ? tempWidth : width;
-    width += ARTIFACT_MARGIN * 2;
 
-    int height = (2*fontHeight) + (ARTIFACT_MARGIN * 2);
-
-    return QSize(width, height);
+    if (lines == 1) {
+        p.drawText(offsetX, offsetY + (h/2) - (fontHeight/2),
+                   w, fontHeight, Qt::AlignCenter, name());
+    } else {
+        p.drawText(offsetX, offsetY + (h/2),
+                   w, fontHeight, Qt::AlignCenter, name());
 }
 
-QSize ArtifactWidget::calculateSize()
-{
-    if ( !m_pObject) {
-        return UMLWidget::calculateSize();
+    if(m_bSelected) {
+        drawSelected(&p, offsetX, offsetY);
     }
-    UMLArtifact *umlart = static_cast<UMLArtifact*>(m_pObject);
-    if (umlart->getDrawAsType() == UMLArtifact::defaultDraw) {
-        return calculateNormalSize();
-    } else {
-        return calculateIconSize();
     }
-}
 
-void ArtifactWidget::saveToXMI(QDomDocument& qDoc, QDomElement& qElement)
-{
-    QDomElement conceptElement = qDoc.createElement("artifactwidget");
-    UMLWidget::saveToXMI(qDoc, conceptElement);
-    qElement.appendChild(conceptElement);
-}
-
--- trunk/KDE/kdesdk/umbrello/umbrello/widgets/artifactwidget.h #1268568:1268569
@@ -5,14 +5,13 @@
  *   the Free Software Foundation; either version 2 of the License, or     *
  *   (at your option) any later version.                                   *
  *                                                                         *
- *   copyright (C) 2003-2006                                               *
+ *   copyright (C) 2003-2011                                               *
  *   Umbrello UML Modeller Authors <uml-devel at uml.sf.net>                  *
  ***************************************************************************/
 
 #ifndef ARTIFACTWIDGET_H
 #define ARTIFACTWIDGET_H
 
-
 #include "umlwidget.h"
 
 class UMLView;
@@ -21,81 +20,36 @@
 #define ARTIFACT_MARGIN 5
 
 /**
- * Defines a graphical version of the Artifact.
- * Most of the functionality will come from the @ref UMLArtifact class.
+ * Defines a graphical version of the @ref UMLArtifact.
+ * Most of the functionality will come from the @ref UMLWidget class.
  *
  * @short A graphical version of a Artifact.
  * @author Jonathan Riddell
  * @see UMLWidget
  * Bugs and comments to uml-devel at lists.sf.net or http://bugs.kde.org
  */
-class ArtifactWidget : public UMLWidget {
+class ArtifactWidget : public UMLWidget
+{
 public:
 
-    /**
-     * Constructs a ArtifactWidget.
-     *
-     * @param view              The parent of this ArtifactWidget.
-     * @param a         The Artifact this widget will be representing.
-     */
     ArtifactWidget(UMLView *view, UMLArtifact *a);
-
-    /**
-     * destructor
-     */
     virtual ~ArtifactWidget();
 
-    /**
-     * Overrides standard method
-     */
     void draw(QPainter& p, int offsetX, int offsetY);
 
-    /**
-     * Saves the widget to the "artifactwidget" XMI element.
-     * Note: For loading from XMI, the inherited parent method is used.
-     */
     void saveToXMI(QDomDocument& qDoc, QDomElement& qElement);
 
 protected:
-    /**
-     * Overrides method from UMLWidget.
-     */
     QSize calculateSize();
 
 private:
-    /**
-     * Initializes key variables of the class.
-     */
     void init();
-
-    /**
-     * calculates the size when drawing as an icon (it's the same size for all icons)
-     */
     QSize calculateIconSize();
-
-    /**
-     * calculates the size for drawing as a box
-     */
     QSize calculateNormalSize();
 
-    /**
-     * draw as a file icon
-     */
     void drawAsFile(QPainter& p, int offsetX, int offsetY);
-
-    /**
-     * draw as a library file icon
-     */
     void drawAsLibrary(QPainter& p, int offsetX, int offsetY);
-
-    /**
-     * draw as a database table icon
-     */
     void drawAsTable(QPainter& p, int offsetX, int offsetY);
-
-    /**
-     * draw as a box
-     */
     void drawAsNormal(QPainter& p, int offsetX, int offsetY);
 
     /**




More information about the umbrello-devel mailing list