src/hbwidgets/dataform/hbdataformmodelitem.cpp
changeset 6 c3690ec91ef8
parent 5 627c4a0fd0e7
child 28 b7da29130b0e
--- a/src/hbwidgets/dataform/hbdataformmodelitem.cpp	Fri Jun 11 13:58:22 2010 +0300
+++ b/src/hbwidgets/dataform/hbdataformmodelitem.cpp	Wed Jun 23 18:33:25 2010 +0300
@@ -23,14 +23,13 @@
 **
 ****************************************************************************/
 
-#include <QAbstractItemModel>
-
 #include "hbdataformmodelitem_p.h"
-#include "hbdataformmodelitem.h"
-#include "hbdataformmodel.h"
 #include "hbdataformmodel_p.h"
 
-class QAbstractItemModel;
+#include <hbdataformmodelitem.h>
+#include <hbdataformmodel.h>
+
+#include <QAbstractItemModel>
 
 
 HbDataFormModelItemPrivate::HbDataFormModelItemPrivate():
@@ -322,8 +321,11 @@
     d_ptr(new HbDataFormModelItemPrivate())
 {
     Q_D(HbDataFormModelItem);
-    d->q_ptr = this ;
-    d->mParentItem = const_cast<HbDataFormModelItem*>(parent);
+    d->q_ptr = this ;  
+    if( parent ) {
+          d->mParentItem = const_cast<HbDataFormModelItem*>(parent);
+          d->mParentItem->appendChild(this);         
+    }
     setData(ItemTypeRole, type);
     setData(LabelRole, label);
 }
@@ -336,7 +338,10 @@
 {
     Q_D(HbDataFormModelItem);
     d->q_ptr = this ;
-    d->mParentItem = const_cast<HbDataFormModelItem*>(parent);
+    if( parent ){
+        d->mParentItem = const_cast<HbDataFormModelItem*>(parent);
+        d->mParentItem->appendChild(this);  
+    }
 }
 
 /*!
@@ -378,7 +383,8 @@
         }
         else {
             d->mChildItems.append(child);
-        }
+        }        
+
     }
 }
 
@@ -450,24 +456,22 @@
     Q_D(HbDataFormModelItem);
     HbDataFormModel* model = static_cast<HbDataFormModel*>(d->mModel);
 
-    if(model)
-        model->d_func()->rowsAboutToBeRemoved(this, index, index);
-
-        HbDataFormModelItem *item = d->mChildItems.at(index);
-        if( item ) {
-            int childCount = item->childCount();
-            for ( int childIndex = 0; childIndex <= childCount ;childIndex++) {
-                item->removeChild(0); 
-            }
-
-            HbDataFormModelItem *item = d->mChildItems.takeAt(index);
-            delete item;
-            item = 0;
-        }        
-        
-    if(model)
-        model->d_func()->rowsRemoved();
-     
+    HbDataFormModelItem *item = d->mChildItems.at(index);
+    if( item ) {
+        int childCount = item->childCount();
+        for ( int childIndex = 0; childIndex < childCount ;childIndex++) {
+            item->removeChild(0); 
+        }
+        if( model ) {
+            model->d_func()->rowsAboutToBeRemoved(this, index, index);
+        }
+        HbDataFormModelItem *item = d->mChildItems.takeAt(index);
+        delete item;
+        item = 0;
+        if( model ) {
+            model->d_func()->rowsRemoved();
+        }
+    }
 }
 
 /*!
@@ -486,26 +490,11 @@
     
     if( startIndex + count > childCount() ) {
         return;
-    }
-
-    Q_D(HbDataFormModelItem);
-
-    HbDataFormModel* model = static_cast<HbDataFormModel*>(d->mModel);
-    if( model ) {
-        model->d_func()->rowsAboutToBeRemoved(this, startIndex, startIndex + count -1); 
-    }
+    }   
 
     for(int index = 0; index < count ;index++) {
-        HbDataFormModelItem *item = d->mChildItems.takeAt(0);
-        if ( item ) {
-            delete item;
-            item = 0;
-        }
-    }
-
-    if( model ) {
-        model->d_func()->rowsRemoved();
-    }
+        removeChild(startIndex);
+    }   
 }
 
 /*!
@@ -673,7 +662,7 @@
    @beta
 
    Sets \a parent as a parent to this item.
-   It only sets the parent pointer. It doesnt put the item in the 
+   It only sets the parent pointer. It does not put the item in the 
    hierarchy.
 */
 void HbDataFormModelItem::setParent(HbDataFormModelItem* parent)