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

Sharan Rao sharanrao at gmail.com
Mon Aug 20 22:41:18 UTC 2007


SVN commit 702619 by sharan:

Fixed a bug caused by porting of lists in the constraints dialog box.
(Redesigned some part of the code to make it more generic, and thus possibly avoid such future bugs :) )



 M  +6 -5      classifierlistpage.cpp  
 M  +15 -1     classifierlistpage.h  
 M  +63 -17    constraintlistpage.cpp  
 M  +22 -1     constraintlistpage.h  


--- trunk/KDE/kdesdk/umbrello/umbrello/dialogs/classifierlistpage.cpp #702618:702619
@@ -242,7 +242,8 @@
         m_pItemListLB->setSelected(0, true);
         listItem = getItemList().at(0);
     } else {
-        listItem = getItemList().at( m_pItemListLB->index(item) );
+        int relativeItemIndex = relativeIndexOf( item );
+        listItem = getItemList().at( relativeItemIndex );
     }
 
     if (listItem) {
@@ -274,7 +275,7 @@
         return;
     }
 
-    int index = calculateNewIndex(listItem);
+    int index = calculateNewIndex(listItem->getBaseType());
 
     m_pItemListLB->insertItem(listItem->toString(Uml::st_SigNoVis), index);
     m_bSigWaiting = false;
@@ -574,8 +575,8 @@
 void ClassifierListPage::saveCurrentItemDocumentation() {
     int currentItemIndex = m_pItemListLB->currentItem();
 
-    // index is -1 . Quit
-    if ( currentItemIndex==-1 )
+    // index is not in range, quit
+    if ( currentItemIndex < 0 || currentItemIndex >= getItemList().count() )
         return;
 
     UMLClassifierListItem* selectedItem = getItemList().at( currentItemIndex );
@@ -655,7 +656,7 @@
 }
 
 
-int ClassifierListPage::calculateNewIndex(UMLClassifierListItem* /*listItem*/){
+int ClassifierListPage::calculateNewIndex(Uml::Object_Type /* ot */){
     return m_pItemListLB->count();
 }
 
--- trunk/KDE/kdesdk/umbrello/umbrello/dialogs/classifierlistpage.h #702618:702619
@@ -135,6 +135,7 @@
 
 protected:
 
+
     /** Loads the Item nList Box
      *
      */
@@ -146,7 +147,20 @@
      */
     void hideArrowButtons(bool hide);
 
-    virtual int calculateNewIndex(UMLClassifierListItem* listItem);
+    /**
+     * Calculates the new index to be assigned when an object of type ot is to
+     * be added to the list box. The default Implementation is to add it to the end of the list
+     * @param ot The Object Type to be added
+     * @return The index
+     */
+    virtual int calculateNewIndex(Uml::Object_Type ot);
+
+    /** 
+     * Returns the index of the Item in the List Box. Default Implementation is same as actual Index of Item
+     */
+    virtual int relativeIndexOf(Q3ListBoxItem* item) {
+	return m_pItemListLB->index( item);
+    }
     
     Uml::Object_Type m_itemType;
     UMLClassifier* m_pClassifier;
--- trunk/KDE/kdesdk/umbrello/umbrello/dialogs/constraintlistpage.cpp #702618:702619
@@ -98,6 +98,7 @@
     if ( m_pLastObjectCreated!=NULL ) {
         m_bSigWaiting = true;
         ent->setAsPrimaryKey( static_cast<UMLUniqueConstraint*>(m_pLastObjectCreated ) );
+        m_itemType = Uml::ot_EntityConstraint;
         reloadItemListBox();
     }
 
@@ -121,7 +122,7 @@
     m_itemType = Uml::ot_EntityConstraint;
 }
 
-int ConstraintListPage::calculateNewIndex(UMLClassifierListItem* listItem){
+int ConstraintListPage::calculateNewIndex(Uml::Object_Type ot){
 
     // we want to show all Unique Constraints first , followed by ForeignKey Constraints
     UMLClassifierListItemList ucList, fkcList,  ccList;
@@ -134,28 +135,73 @@
     fkcCount = fkcList.count();
     ccCount = ccList.count();
 
-    QString listItemString = listItem->toString( Uml::st_SigNoVis );
-    int type = listItem->getBaseType();
+    int index = 0;
 
-    int index = 0;
+    if ( greaterThan( Uml::ot_UniqueConstraint, ot ) ) {
+        index += ucCount;
+    }
+
+    if ( greaterThan( Uml::ot_ForeignKeyConstraint, ot ) ) {
+        index += fkcCount;
+    }
+
+    if ( greaterThan( Uml::ot_CheckConstraint, ot ) ) {
+        index += ccCount;
+    }
+
     // we subtract 1 from the count as the new item is already in the list (m_List) and
     // hence contributes to the count we obtained
-    switch( type ) {
-        case Uml::ot_UniqueConstraint:
-            index = ucCount - 1;
-            break;
-        case Uml::ot_ForeignKeyConstraint:
-            index = ucCount + fkcCount - 1;
-            break;
-        case Uml::ot_CheckConstraint:
-            index = ucCount + fkcCount + ccCount - 1;
-            break;
-        default:
-            break;
+    index = index - 1;
 
+    return index;
+}
+
+int ConstraintListPage::relativeIndexOf(Q3ListBoxItem* item) {
+    int actualIndex = ClassifierListPage::relativeIndexOf( item );
+
+    int ucCount = m_pClassifier->getFilteredList( Uml::ot_UniqueConstraint ).count();
+    int fkcCount = m_pClassifier->getFilteredList( Uml::ot_ForeignKeyConstraint ).count();
+    int ccCount = m_pClassifier->getFilteredList( Uml::ot_CheckConstraint ).count();
+
+    //if ( m_itemType == Uml::ot_EntityConstraint )
+    //    return actualIndex;
+
+    int newIndex = actualIndex;
+
+    if ( !greaterThan( m_itemType, Uml::ot_UniqueConstraint ) ) {
+        newIndex -= ucCount;
     }
 
-    return index;
+    if ( !greaterThan( m_itemType, Uml::ot_ForeignKeyConstraint ) ) {
+        newIndex -= fkcCount;
+    }
+
+    return newIndex;
 }
 
+bool ConstraintListPage::greaterThan(Uml::Object_Type ct1,Uml::Object_Type ct2) {
+    // define ordering
+    switch( ct1 ) {
+       case Uml::ot_EntityConstraint:
+       case Uml::ot_UniqueConstraint:
+           // Unique Constraint greater than all others
+            return true;
+            break;
+       case Uml:: ot_ForeignKeyConstraint:
+           if ( ct2 != Uml::ot_UniqueConstraint )
+             return true;
+           else
+               return false;
+           break;
+       case Uml::ot_CheckConstraint:
+           if ( ct2 != Uml::ot_CheckConstraint )
+               return false;
+           else
+               return true;
+           break;
+       default:
+           return false;
+    }
+}
+
 #include "constraintlistpage.moc"
--- trunk/KDE/kdesdk/umbrello/umbrello/dialogs/constraintlistpage.h #702618:702619
@@ -71,8 +71,29 @@
 
 protected:
 
-    int calculateNewIndex(UMLClassifierListItem* listItem);
 
+    /** 
+     * Returns the index of the Item in the List Box
+     */
+    int relativeIndexOf(Q3ListBoxItem* item);
+ 
+    /**
+     * Calculates the new index to be assigned when an object of type ot is to
+     * be added to the list box. The default Implementation is to add it to the end of the list
+     * @param ot The Object Type to be added
+     * @return The index
+     */
+    int calculateNewIndex(Uml::Object_Type ot);
+
+    /**
+     * Will return true if ot1 has a higher (top)  place in the list than ot2
+     *
+     * @param ct1 Contraint Type 1
+     * @param ct2 Constraint Type 2
+     * @return true if ct1 is to be shown above ct2 else false
+     */
+    bool greaterThan(Uml::Object_Type ct1,Uml::Object_Type ct2);
+
     KMenu* buttonMenu;
 
     




More information about the umbrello-devel mailing list