controlpanel/src/cpframework/src/cpdataformlistentryviewitem.cpp
changeset 55 4c15d9aa2384
parent 40 6465d5bb863a
--- a/controlpanel/src/cpframework/src/cpdataformlistentryviewitem.cpp	Thu Aug 05 11:11:52 2010 +0800
+++ b/controlpanel/src/cpframework/src/cpdataformlistentryviewitem.cpp	Thu Sep 02 17:14:05 2010 +0800
@@ -11,7 +11,7 @@
 *
 * Contributors:
 *
-* Description:  
+* Description:  View item implementation for list entry item.
 *
 */
 
@@ -33,24 +33,38 @@
 
 #define CP_DATAFORMLISTENTRYVIEWITEM QLatin1String("cpdataformlistentryviewitem")
 
+/**
+ * Constructor
+ */
 CpDataFormListEntryViewItem::CpDataFormListEntryViewItem(QGraphicsItem *parent) : 
     HbDataFormViewItem(parent)
 {
+    // Add effeect just like item in HbListView
 #ifdef HB_EFFECTS       
     HbEffect::add(CP_DATAFORMLISTENTRYVIEWITEM + "-focus", "listviewitem_press", "pressed");
     HbEffect::add(CP_DATAFORMLISTENTRYVIEWITEM + "-focus", "listviewitem_release", "released");
 #endif
 }
 
+/**
+ * Destructor
+ */
 CpDataFormListEntryViewItem::~CpDataFormListEntryViewItem()
 {
 }
 
+/**
+ * Reimplement by CpDataFormListEntryViewItem, this function return a instance copy.
+ */
 HbAbstractViewItem* CpDataFormListEntryViewItem::createItem()
 {
     return new CpDataFormListEntryViewItem(*this);
 }
 
+/**
+ * Reimplement by CpDataFormListEntryViewItem, return true when the model item type is 
+ * ListEntryItem
+ */
 bool CpDataFormListEntryViewItem::canSetModelIndex(const QModelIndex &index) const
 {
     HbDataFormModelItem::DataItemType itemType = 
@@ -60,24 +74,44 @@
     return ( itemType == CpSettingFormEntryItemData::ListEntryItem );
 }
 
+/**
+ * Reimplement by CpDataFormListEntryViewItem
+ * No content widget in custom list item. So return a null pointer directly
+ */
 HbWidget* CpDataFormListEntryViewItem::createCustomWidget()
 {
+    // Don't need to create any widget
+    return 0;
+}
+/**
+ * Reimplement by CpDataFormListEntryViewItem. Change the description property for 
+ * custom list item.
+ */
+void CpDataFormListEntryViewItem::restore()
+{
     HbDataFormModelItem::DataItemType itemType =
-            static_cast<HbDataFormModelItem::DataItemType> (modelIndex().data(
-                    HbDataFormModelItem::ItemTypeRole).toInt());
-    switch (itemType)
-    {
-        case CpSettingFormEntryItemData::ListEntryItem: {
-            break;
-        }
-        default: {
-            break;
-        }
+        static_cast<HbDataFormModelItem::DataItemType> (modelIndex().data(
+            HbDataFormModelItem::ItemTypeRole).toInt());
+
+    if (itemType == CpSettingFormEntryItemData::ListEntryItem) {
+        QModelIndex itemIndex = modelIndex();
+        HbDataFormModel *model = qobject_cast<HbDataFormModel*> (itemView()->model());
+        if (model) {
+            HbDataFormModelItem *modelItem = model->itemFromIndex(itemIndex);
+            if (modelItem->data(HbDataFormModelItem::DescriptionRole).toString().isEmpty()) {
+                this->setProperty("hasDescription", false);
+            }
+            else {
+                this->setProperty("hasDescription", true);
+            }    
+        }        
     }
-    
-    return 0;
+    HbDataFormViewItem::restore();
 }
 
+/**
+ * Reimplement by CpDataFormListEntryViewItem, provide the effect when pressing list item
+ */
 void CpDataFormListEntryViewItem::pressStateChanged(bool pressed, bool animate)
 {
 #ifdef HB_EFFECTS
@@ -112,6 +146,10 @@
 }
 
 #ifdef HB_GESTURE_FW
+
+/**
+ * Reimplement by CpDataFormListEntryViewItem, set different graphics for list item's gesture
+ */
 void CpDataFormListEntryViewItem::gestureEvent(QGestureEvent *event)
 {
     HbFrameItem *backgroundItem = static_cast<HbFrameItem*> ( primitive("dataItem_Background") );
@@ -120,6 +158,7 @@
     if(backgroundItem && tap) {
         switch(tap->state()) {
         case Qt::GestureStarted: {
+                // Set the pressed state
                 backgroundItem->frameDrawer().setFrameGraphicsName(QLatin1String("qtg_fr_list_pressed"));
             }
             break;
@@ -128,10 +167,12 @@
             }
             break;
         case Qt::GestureCanceled: {
+                // Set the normal state
                 backgroundItem->frameDrawer().setFrameGraphicsName(QLatin1String("qtg_fr_list_normal"));
             }
             break;
         case Qt::GestureFinished: {
+                // Set the normal state
                 backgroundItem->frameDrawer().setFrameGraphicsName(QLatin1String("qtg_fr_list_normal"));
             }
             break;