[Uml-devel] kdesdk/umbrello/umbrello

Oliver Kellogg okellogg at users.sourceforge.net
Fri Jan 7 07:18:28 UTC 2005


CVS commit by okellogg: 

compare(): Reflect the changed attribute/operation order in the list view
 and restore it upon reload.
CCBUG:96216


  M +34 -4     umllistviewitem.cpp   1.68


--- kdesdk/umbrello/umbrello/umllistviewitem.cpp  #1.67:1.68
@@ -522,10 +522,40 @@ void UMLListViewItem::cancelRename(int c
 int UMLListViewItem::compare(QListViewItem *other, int col, bool ascending) const
 {
+        UMLListViewItem *ulvi = static_cast<UMLListViewItem*>(other);
         Uml::ListView_Type ourType = getType();
-        Uml::ListView_Type otherType = static_cast<UMLListViewItem*>( other )->getType();
+        Uml::ListView_Type otherType = ulvi->getType();
 
-        if ( ourType == otherType )
+        if ( ourType == otherType ) {
+                UMLObject *otherObj = ulvi->getUMLObject();
+                if (m_pObject == NULL || otherObj == NULL)
                 return key( col, ascending ).compare( other->key( col, ascending) );
-
+                if (ourType == Uml::lvt_Attribute) {
+                        UMLClass *ourParent = dynamic_cast<UMLClass*>(m_pObject->parent());
+                        UMLClass *otherParent = dynamic_cast<UMLClass*>(otherObj->parent());
+                        if (ourParent == NULL || otherParent == NULL || ourParent != otherParent) {
+                                kdError() << "UMLListViewItem::compare(UMLAttribute): ourParent="
+                                          << ourParent << ", otherParent=" << otherParent << endl;
+                                return key( col, ascending ).compare( other->key( col, ascending) );
+                        }
+                        UMLAttributeList atts = ourParent->getAttributeList();
+                        int myIndex = atts.findRef( static_cast<UMLAttribute*>(m_pObject) );
+                        int otherIndex = atts.findRef( static_cast<UMLAttribute*>(otherObj) );
+                        return (myIndex < otherIndex ? -1 : myIndex > otherIndex ? 1 : 0);
+                } else if (ourType == Uml::lvt_Operation) {
+                        UMLClassifier *ourParent = dynamic_cast<UMLClassifier*>(m_pObject->parent());
+                        UMLClassifier *otherParent = dynamic_cast<UMLClassifier*>(otherObj->parent());
+                        if (ourParent == NULL || otherParent == NULL || ourParent != otherParent) {
+                                kdError() << "UMLListViewItem::compare(UMLOperation): ourParent="
+                                          << ourParent << ", otherParent=" << otherParent << endl;
+                                return key( col, ascending ).compare( other->key( col, ascending) );
+                        }
+                        UMLOperationList ops = ourParent->getOpList();
+                        int myIndex = ops.findRef( static_cast<UMLOperation*>(m_pObject) );
+                        int otherIndex = ops.findRef( static_cast<UMLOperation*>(otherObj) );
+                        return (myIndex < otherIndex ? -1 : myIndex > otherIndex ? 1 : 0);
+                } else {
+                        return key( col, ascending ).compare( other->key( col, ascending) );
+                }
+        }
         if ( ourType < otherType )
                 return -1;






More information about the umbrello-devel mailing list