[Uml-devel] branches/work/soc-umbrello/umbrello

Gopala Krishna A krishna.ggk at gmail.com
Fri Aug 8 16:34:12 UTC 2008


SVN commit 844084 by gopala:

Implemented ExpanderBox item(plus/minus box) which reacts to mouse
click to toggle the expansion state.

The ClassifierWidget now adopts this ExpanderBox to allow user to
hide/show the attributes and operations.

This in my opinion eases user experience but this probably should be
configurable in future.



 M  +1 -0      CMakeLists.txt  
 M  +30 -0     classifierwidget.cpp  
 M  +8 -0      classifierwidget.h  
 A             expanderbox.cpp   [License: GPL (v2+)]
 A             expanderbox.h   [License: GPL (v2+)]


--- branches/work/soc-umbrello/umbrello/CMakeLists.txt #844083:844084
@@ -309,6 +309,7 @@
    enum.cpp
    enumliteral.cpp
    enumwidget.cpp
+   expanderbox.cpp
    floatingdashlinewidget.cpp
    floatingtextwidget.cpp
 #   floatingtextwidgetcontroller.cpp
--- branches/work/soc-umbrello/umbrello/classifierwidget.cpp #844083:844084
@@ -17,6 +17,7 @@
 // app includes
 #include "associationwidget.h"
 #include "classifier.h"
+#include "expanderbox.h"
 #include "listpopupmenu.h"
 #include "object_factory.h"
 #include "operation.h"
@@ -42,6 +43,12 @@
     createTextItemGroup(); // For classifier text items
     createTextItemGroup(); // For template text items'
 
+    m_attributeExpanderBox = new ExpanderBox(false, this);
+    connect(m_attributeExpanderBox, SIGNAL(expansionToggled(bool)), this, SLOT(slotShowAttributes(bool)));
+
+    m_operationExpanderBox = new ExpanderBox(false, this);
+    connect(m_operationExpanderBox, SIGNAL(expansionToggled(bool)), this, SLOT(slotShowOperations(bool)));
+
     // Null initially
     m_dummyAttributeItem = m_dummyOperationItem = 0;
     m_lineItem1Index = m_lineItem2Index = InvalidIndex;
@@ -547,15 +554,20 @@
 
         classifierGroup->setGroupGeometry(m_classifierRect.adjusted(+m, +m, -m, -m));
         const int cnt = classifierGroup->textItemCount();
+        qreal expanderDistance = 4;
         if (cnt > m_lineItem1Index) {
             TextItem *item = classifierGroup->textItemAt(m_lineItem1Index);
             qreal y = item->mapToParent(item->boundingRect().bottomLeft()).y();
             m_classifierLines[0].setLine(m_classifierRect.left(), y, m_classifierRect.right(), y);
+            qreal expanderX = rect().left() - m_attributeExpanderBox->rect().width() - expanderDistance;
+            m_attributeExpanderBox->setPos(expanderX, y);
         }
         if (cnt > m_lineItem1Index) {
             TextItem *item = classifierGroup->textItemAt(m_lineItem2Index);
             qreal y = item->mapToParent(item->boundingRect().bottomLeft()).y();
             m_classifierLines[1].setLine(m_classifierRect.left(), y, m_classifierRect.right(), y);
+            qreal expanderX = rect().left() - m_operationExpanderBox->rect().width() - expanderDistance;
+            m_operationExpanderBox->setPos(expanderX, y);
         }
     }
     classifierGroup->setHoverBrush(QBrush(Qt::blue, Qt::Dense6Pattern));
@@ -637,6 +649,10 @@
 
         item->setVisible(v);
     }
+    // Update expander box to reflect current state and also visibility
+    m_attributeExpanderBox->setExpanded(visualProperty(ShowAttributes));
+    m_attributeExpanderBox->setVisible(!visualProperty(DrawAsCircle) && !umlC->isInterface());
+
     const QString dummyText;
     // Setup line and dummies.
     if (!showNameOnly) {
@@ -668,6 +684,8 @@
 
         item->setVisible(v);
     }
+    m_operationExpanderBox->setExpanded(visualProperty(ShowOperations));
+    m_operationExpanderBox->setVisible(!visualProperty(DrawAsCircle));
 
     if (!showNameOnly && opList.isEmpty()) {
         m_dummyOperationItem = new TextItem(dummyText);
@@ -793,6 +811,18 @@
     }
 }
 
+/// Slot to show/hide attributes based on \a state.
+void ClassifierWidget::slotShowAttributes(bool state)
+{
+    setVisualProperty(ShowAttributes, state);
+}
+
+/// Slot to show/hide operations based on \a state.
+void ClassifierWidget::slotShowOperations(bool state)
+{
+    setVisualProperty(ShowOperations, state);
+}
+
 /**
  * Invalidates all dummies used so that they can be recalculated again.
  */
--- branches/work/soc-umbrello/umbrello/classifierwidget.h #844083:844084
@@ -15,6 +15,7 @@
 #include "newumlrectwidget.h"
 
 class AssociationWidget;
+class ExpanderBox;
 class TextItem;
 class UMLClassifier;
 
@@ -110,6 +111,10 @@
 public Q_SLOTS:
     virtual void slotMenuSelection(QAction* action);
 
+private Q_SLOTS:
+    void slotShowAttributes(bool state);
+    void slotShowOperations(bool state);
+
 private:
     void updateSignatureTypes();
     void calculateTemplateDrawing();
@@ -151,6 +156,9 @@
     TextItem *m_dummyOperationItem;
 
     static const int InvalidIndex;
+
+    ExpanderBox *m_attributeExpanderBox;
+    ExpanderBox *m_operationExpanderBox;
 };
 
 Q_DECLARE_OPERATORS_FOR_FLAGS(ClassifierWidget::VisualProperties)




More information about the umbrello-devel mailing list