src/hbwidgets/dataform/hbdataformviewitem_p.cpp
changeset 1 f7ac710697a9
parent 0 16d8024aca5e
child 2 06ff229162e9
--- a/src/hbwidgets/dataform/hbdataformviewitem_p.cpp	Mon Apr 19 14:02:13 2010 +0300
+++ b/src/hbwidgets/dataform/hbdataformviewitem_p.cpp	Mon May 03 12:48:33 2010 +0300
@@ -29,22 +29,29 @@
 #include "hbdataform_p.h"
 #include "hbdataformheadingwidget_p.h"
 #include "hbdatagroup_p.h"
+#include "hbdataformmodelitem_p.h"
 #include "hbdatagroup_p_p.h"
 
 #include <hbslider.h>
 #include <hbcheckbox.h>
+#include <hblistwidget.h>
 #include <hblabel.h>
 #include <hblineedit.h>
 #include <hbradiobuttonlist.h>
 #include <hbcombobox.h>
 #include <hbstyleoptiondataformviewitem.h>
-#include <hblistdialog.h>
+#include <hbselectiondialog.h>
 #include <hbpushbutton.h>
 #include <hbaction.h>
 
 #include <QGraphicsLinearLayout>
 #include <QCoreApplication>
 
+#ifdef HB_GESTURE_FW
+#include <hbtapgesture.h>
+#endif
+#define MAX_INLINE_ITEM_COUNT 3
+
 HbToggleItem::HbToggleItem( QGraphicsItem* parent ): HbWidget( parent )
 {
     // Toggle item uses button as the content widget and toggles the text when item is clicked
@@ -120,53 +127,55 @@
  */
 HbRadioItem::HbRadioItem( QGraphicsItem* parent ):
     HbWidget( parent ),
-    mRadioButton( 0 )
+    mRadioButtonList( 0 ),
+    mButton(0), 
+    mDialog(0),
+    layout(0),
+    mSelected(-1)
 {
-    // Create label by default . RadioButtonList is created created at runtime 
-    // when clicked on the item
-    mViewItem = static_cast<HbDataFormViewItem*>( parent );
 
-    mButton = new HbPushButton();
-    QObject::connect(mButton, SIGNAL(released()), this, SLOT(buttonClicked()));
-    QGraphicsLinearLayout* layout = new QGraphicsLinearLayout( Qt::Vertical );
-    layout->addItem( mButton );
-    setLayout( layout );
-    
-    mButtonVisible = true;
-    mSelected = 0;
+    mViewItem = static_cast<HbDataFormViewItem*>( parent );
     mModel = static_cast<HbDataFormModel*>(
             HbDataFormViewItemPrivate::d_ptr(mViewItem)->mSharedData->mItemView->model());
     mModelItem = static_cast<HbDataFormModelItem*>(
             mModel->itemFromIndex(mViewItem->modelIndex()));
+    QString displayMode = mModelItem->contentWidgetData(QString("displayMode")).toString();
+     
+    // set displayMode to automatic if not already set by application
+    if(displayMode.isEmpty()) {
+        mModelItem->setContentWidgetData(QString("displayMode"), "automatic");
+    }
     QObject::connect(this,SIGNAL(valueChanged(QPersistentModelIndex, QVariant)),mViewItem, 
         SIGNAL(itemModified(QPersistentModelIndex, QVariant)));
+    if(!layout) {
+        layout = new QGraphicsLinearLayout( Qt::Vertical );
+    }
+    setLayout( layout );
 }
 
 HbRadioItem::~HbRadioItem()
 {
-    // delete the widget which is not currently visible. The visible will be deleted by layout hierarchy
-    if( mButtonVisible ) {
-        if( mRadioButton ) {
-            delete mRadioButton;
-        }
-    } else {
-        delete mButton;
-    }
 }
 
-HbWidget* HbRadioItem::contentWidget()
+HbWidget* HbRadioItem::createRadioButton()
 {
     // If not created create and set properties and return the widget
-    if(!mRadioButton) {
-        mRadioButton = new HbRadioButtonList();        
-        mRadioButton->setItems( mItems );        
-        mRadioButton->setVisible(false);
-        mRadioButton->setSelected(mSelected);
-
-        QObject::connect( mRadioButton, SIGNAL(itemSelected(int)), this, SLOT(itemSelected(int)) );
+    if(!mRadioButtonList) {
+        mRadioButtonList = new HbRadioButtonList();      
+        mRadioButtonList->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred));
+        //mRadioButtonList->setClampingStyle(HbScrollArea::StrictClamping);
+        mRadioButtonList->setItems( mItems );
+        if( mSelected != -1 ) {
+            mRadioButtonList->setSelected( mSelected );
+        }
+        // model need to be updated when selection changes
+        // in popup case this connection will be removed since model will be updated 
+        // only when dialog closed
+        QObject::connect( mRadioButtonList, SIGNAL(itemSelected(int)), 
+            this, SLOT(updateModel(int)) );
         
     }
-    return mRadioButton;
+    return mRadioButtonList;
 }
 
 /*  This function is evoked when Dynamic property is set on HbRadioItem , then 
@@ -176,103 +185,304 @@
 {
     switch( e->type() ){
         case QEvent::DynamicPropertyChange: {
-                QDynamicPropertyChangeEvent *changeEvent = static_cast<QDynamicPropertyChangeEvent*>( e );
-                QString name = changeEvent->propertyName().data();
-                if( mRadioButton ) {
-                    mRadioButton->setProperty( 
-                        changeEvent->propertyName().data() ,property( changeEvent->propertyName().data()) );
+                QDynamicPropertyChangeEvent *changeEvent = 
+                    static_cast<QDynamicPropertyChangeEvent*>( e );
+                QString dynamicPropertyName = changeEvent->propertyName().data();
+                if( mRadioButtonList ) {
+                    //Set the property on radiobutton list if already created 
+                    mRadioButtonList->setProperty( 
+                        changeEvent->propertyName().data() ,
+                        property( changeEvent->propertyName().data()) );
                 }
-                if( name == "items" ) {
-                    mItems = property("items").toStringList();
-                } else if( name == "selected" ) {
+                if( dynamicPropertyName == "items" || dynamicPropertyName == "displayMode" ) {
+                    // store the items locally
                     mItems = property("items").toStringList();
+                    // in case of automatic, displayMode (embedded, automatic or popup) will change 
+                    // if new items are populated or mode should be changed if mode is set
+                    //  explicitly by application at runtime
+                    changeMode();
+                } else if(dynamicPropertyName == "selected") {
+                    // store the new selection 
                     mSelected = property("selected").toInt();
-                    mButton->setText(mItems.at(mSelected));
-                    mButton->setTextAlignment(Qt::AlignLeft);
+                    // fine tune the new selection if it goes beyond range. This happens when new
+                    // items are populated or selection index is changed by application in to the model
+                    // which can be out of range
+                    resetSelection();
+                    selectItem();
                 }
                 break;
             }
         default:
             break;
     }
-
     HbWidget::event(e);
     return false;
 }
 
-
-void HbRadioItem::buttonClicked()
+void HbRadioItem::makeEmbedded()
 {
-    // launch popup only if number of items are more than 5
-    if(!mRadioButton) {
-            contentWidget();
-        } 
-    
-    
-        
-        mButton->setVisible( false );  
-        static_cast<QGraphicsLinearLayout*>( layout() )->addItem( mRadioButton );   
-        mRadioButton->setVisible( true );
-        mButtonVisible = false;
-        layout()->removeAt( 0 );
-        
+    // button need to be deleted when mode is changed from popup to embedded
+    if(mButton) {
+        layout->removeItem(mButton);
+        delete mButton;
+        mButton = 0;
+    }
+    createRadioButton();
+    layout->addItem(mRadioButtonList);
+    mRadioButtonList->setScrollDirections(0);
+}
 
+void HbRadioItem::makePopup()
+{
+    if(mRadioButtonList) {
+        layout->removeItem(mRadioButtonList);
+        // RadioButton will not be shown unless button is clicked so delete it
+        delete mRadioButtonList;
+        mRadioButtonList = 0;
+    }
+    initilizeButton();
 }
 
 
-void HbRadioItem::itemSelected( int index )
+void HbRadioItem::resetSelection()
 {
-    //update the label with the selected index text
-    //mLabel->clear( );
-    mButton->setText( mRadioButton->items().at(index) );
-    emit valueChanged(mViewItem->modelIndex(), mRadioButton->items().at(index));
-    
+    if((mItems.count() > 0 && mSelected == -1) || 
+        (mItems.count() > 0 && (mItems.count() <= mSelected ))) {
+        // if selection is beyond range then set it to 0. 
+        // This happens when new items are populated and 
+        // application does not set selection explicitly
+        mSelected = 0;
+    } else if(mItems.count() == 0) {
+        mSelected = -1;
+    }
+}
+
+/*
+changeMode() will change the mode of visualization( embedded, automatic and popup) depending
+on the number of items in case of automatic mode or change it to correspoding if not automatic.
+In popup the selected item will be displayed as the text of the button otherwise RadioButtonList
+is placed inline.
+*/
+void HbRadioItem::changeMode()
+{
+    QString displayMode = mModelItem->contentWidgetData(QString("displayMode")).toString();
     
-    static_cast<QGraphicsLinearLayout*>( layout() )->addItem( mButton );
+    if(displayMode == "embedded") {
+        makeEmbedded();
+    } else if(displayMode == "popup") {
+        makePopup();
+    }
+    else if(displayMode == "automatic") {
+        if(mItems.count() <= MAX_INLINE_ITEM_COUNT  && mItems.count() > 0  ) {
+            makeEmbedded();
+        } else if(mItems.count() >= MAX_INLINE_ITEM_COUNT){
+            makePopup();
+        }
+    }
+    resetSelection();
+    selectItem();
+}
+
+void HbRadioItem::selectItem()
+{
+    //Set Text if button is valid
+    if(mSelected != -1) {
+        if(mButton ) {
+            mButton->setText(mItems.at(mSelected));
+        } 
+        // change selection of radiobutton list
+        if(mRadioButtonList && mRadioButtonList->selected() != mSelected) {
+            mRadioButtonList->setSelected(mSelected);
+        }
+    } else if( mButton ) {
+        // clear the text on the button if items are cleared 
+        mButton->setText(QString(""));
+    }
+}
 
-    mRadioButton->setVisible( false );
-    mButton->setVisible( true );
-    mButtonVisible = true;
-    layout()->removeAt( 0 );
-    
-    //update the model
+void HbRadioItem::initilizeButton()
+{
+    if(!mButton) {
+        mButton = new HbPushButton();
+        mButton->setTextAlignment(Qt::AlignLeft);
+        QObject::connect(mButton, SIGNAL(clicked()), this, SLOT(buttonClicked()));
+        layout->addItem( mButton ); 
+    }
+}
+
+void HbRadioItem::buttonClicked()
+{
+    if(mItems.count() > 0) {
+        if(!mRadioButtonList) {
+            createRadioButton();
+        } 
+        mRadioButtonList->setScrollDirections(Qt::Vertical);
+        QObject::disconnect( mRadioButtonList, SIGNAL(itemSelected(int)), 
+            this, SLOT(updateModel(int)) );
+        selectItem();
+        mDialog = new HbDialog();
+        mDialog->setTimeout(HbPopup::NoTimeout);    
+        mDialog->setAttribute(Qt::WA_DeleteOnClose);
+        mDialog->setContentWidget(mRadioButtonList);    
+        mDialog->addAction(new HbAction(QString("Ok")));
+        mDialog->addAction(new HbAction(QString("Cancel")));
+        mDialog->open(this,SLOT(dialogClosed(HbAction*)));  
+        mRadioButtonList->setSelected(mSelected);
+    }
+}
+
+
+void HbRadioItem::updateModel( int index )
+{
+    mSelected = index;
+    emit valueChanged(mViewItem->modelIndex(), mItems.at(index));
+    // Disconnect modelchanged signal since visualization is already updated by user
+    // so if not disconnected , this will trigger visualization change again
     disconnect( mModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
                   HbDataFormViewItemPrivate::d_ptr(mViewItem)->mSharedData->mItemView, 
                   SLOT( dataChanged(QModelIndex,QModelIndex)) );
-    mModelItem->setContentWidgetData("selected", mRadioButton->property("selected"));
+    //update the model
+    mModelItem->setContentWidgetData("selected", mSelected);
+    // establish the connection back
     connect( mModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
                   HbDataFormViewItemPrivate::d_ptr(mViewItem)->mSharedData->mItemView, 
                   SLOT( dataChanged(QModelIndex,QModelIndex)) );
+    // select the item . The selection is already stored in to the model above
+    selectItem();
+}
+
+
+void HbRadioItem::dialogClosed(HbAction* action)
+{
+    if(action->text() == "Ok") {
+        // store the selected item to model
+        updateModel(mRadioButtonList->selected());        
+    }
+    // dont change selection incase of "Cancel" button click .
+    mRadioButtonList = 0;
+    mDialog = 0;
 }
 
 HbMultiSelectionItem::HbMultiSelectionItem( QGraphicsItem* parent ):
     HbWidget(parent),
-    mQuery(0)
+    mSelectionDialog(0),
+    mButton(0),
+    mMultiListWidget(0)
 {
     // Create label by default . RadioButtonList is created created at runtime 
     // when clicked on the item        
     mViewItem = static_cast<HbDataFormViewItem*>(parent);
-
-    mButton = new HbPushButton();
-    QObject::connect(mButton, SIGNAL(released()), this, SLOT(launchMultiSelectionList()));
-    QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Horizontal);
-    layout->addItem(mButton);
+    layout = new QGraphicsLinearLayout(Qt::Horizontal);
     setLayout(layout);
     
     mModel = static_cast<HbDataFormModel*>(
             HbDataFormViewItemPrivate::d_ptr(mViewItem)->mSharedData->mItemView->model());
     mModelItem = static_cast<HbDataFormModelItem*>(
-            mModel->itemFromIndex(mViewItem->modelIndex()));
-    QObject::connect(this,SIGNAL(valueChanged(QPersistentModelIndex, QVariant)),mViewItem, SIGNAL(itemModified(QPersistentModelIndex, QVariant)));
+            mModel->itemFromIndex(mViewItem->modelIndex()));    
+    // set displayMode to automatic if not already set by application
+    QString displayMode = mModelItem->contentWidgetData(QString("displayMode")).toString();
+    if(displayMode.isEmpty()) {
+        mModelItem->setContentWidgetData(QString("displayMode"), "automatic");
+    }
+    QObject::connect(this,SIGNAL(valueChanged(QPersistentModelIndex, QVariant)),
+        mViewItem, SIGNAL(itemModified(QPersistentModelIndex, QVariant)));
 }
 
 HbMultiSelectionItem::~HbMultiSelectionItem()
 {
 }
 
-HbWidget* HbMultiSelectionItem::contentWidget() const
+
+void HbMultiSelectionItem::makeSelection()
+{
+    QItemSelectionModel *model = 0;
+    if(mMultiListWidget) {// embedded case
+        // get selection model
+        model = mMultiListWidget->selectionModel();
+        if(model) {
+            // disconnect so that the visualization does not get changed when selction 
+            // model changes
+            QObject::disconnect(model, 
+                SIGNAL(selectionChanged( const QItemSelection , const QItemSelection  )), 
+                this, SLOT(updateModel( const QItemSelection , const QItemSelection  )));
+            model->clearSelection();
+            for( int i = 0; i < mSelectedItems.count() ; i++ ) {
+                model->select( model->model()->index(mSelectedItems.at( i ).toInt(),0),
+                    QItemSelectionModel::Select);
+            }
+            QObject::connect(model, 
+                SIGNAL(selectionChanged( const QItemSelection , const QItemSelection  )), 
+                this, SLOT(updateModel( const QItemSelection , const QItemSelection  )));
+        }
+    } else if(mButton) { // update text on button
+        QString newValue("");
+        // create sting to be set on button
+        for ( int i = 0; i < mSelectedItems.count() ; i++ ) {
+            int selectionindex = mSelectedItems.at( i ).toInt();
+            if( selectionindex< mItems.count()) {
+                if( i > 0) {// dont add ; in the starting of the string
+                    newValue.append( ";" );
+                }
+                newValue.append( mItems.at( mSelectedItems.at( i ).toInt() ) );
+            } 
+        }
+        mButton->setText( newValue );
+    }
+}
+
+void HbMultiSelectionItem::makeEmbedded()
 {
-    return mButton;
+    
+    // delete button if displaymode change has happened at runtime 
+    if(mButton){
+        layout->removeItem(mButton);
+        delete mButton;
+        mButton = 0;
+    }
+    // create ListWidget if not yet created 
+    if(!mMultiListWidget) {
+        mMultiListWidget = new HbListWidget();
+        layout->addItem(mMultiListWidget);
+    }
+    
+    mMultiListWidget->setSelectionMode(HbAbstractItemView::MultiSelection);
+    
+    mMultiListWidget->clear();
+    // update the listwidget with new items
+    for (int index = 0; index < mItems.count(); ++index) {
+        mMultiListWidget->addItem(mItems.at(index));
+    }
+    mMultiListWidget->setScrollDirections(0);
+}
+
+void HbMultiSelectionItem::makePopup()
+{
+    // Delete ListWidget if mode change happened at runtime from embedded to popup
+    if(mMultiListWidget) {
+        layout->removeItem(mMultiListWidget);
+        delete mMultiListWidget;
+        mMultiListWidget = 0;
+    }
+    // create button since we need to display selected item on button
+    // and popup will be launched when button is clicked
+    if(!mButton) {
+        mButton = new HbPushButton();
+        mButton->setTextAlignment(Qt::AlignLeft);
+        layout->addItem(mButton);
+    }
+    QObject::connect(mButton, SIGNAL(released()), this, SLOT(launchMultiSelectionList()));
+}
+
+void HbMultiSelectionItem::changeMode()
+{
+    QString displayMode = mModelItem->contentWidgetData(QString("displayMode")).toString();
+    if((mItems.count() <= MAX_INLINE_ITEM_COUNT && displayMode == "automatic") || 
+        displayMode == "embedded" ) {
+        makeEmbedded();
+    } else{
+        makePopup();
+    }
+    makeSelection();
 }
 
 bool HbMultiSelectionItem::event( QEvent * e )
@@ -280,33 +490,19 @@
     switch( e->type() ) {
         case QEvent::DynamicPropertyChange: {
                 QDynamicPropertyChangeEvent *eve = static_cast<QDynamicPropertyChangeEvent*>( e );
-                QString name = eve->propertyName( ).data( );
-                
-                if ( name == "text" ) {
-                    mButton->setProperty(
-                        eve->propertyName().data(), property(eve->propertyName().data()) );
-                }
-                if ( name == "items" ) {
+                QString dynamicPropertyName = eve->propertyName( ).data( );                
+                if ( dynamicPropertyName == "items" || dynamicPropertyName == "displayMode" ) {
+                    int prevCount = mItems.count();
+                    mItems.clear();
                     mItems = property("items").toStringList();
-                } else if ( name == "selectedItems" ) {
-                     mItems = property("items").toStringList();
-                     QList<QVariant> selected = property("selectedItems").toList();
-                     
-                     for( int i = 0; i < selected.count() ; i++ ) {
-                         if ( !mSelectedItems.contains( selected.at( i ).toInt( ) ) ) {
-                            mSelectedItems.append( selected.at( i ).toInt( ) );
-                         }
-                     }
-                }
-                if ( mSelectedItems.count() > 0 && mItems.count() > 0 ) {
-                    QString newValue("");
-                    for ( int i = 0; i < mSelectedItems.count() ; i++ ) {
-                        newValue.append( mItems.at( mSelectedItems.at( i ) ) );
-                        newValue.append( ";" );
+                    if ( mItems.count() != prevCount || dynamicPropertyName == "displayMode") {
+                        changeMode();
                     }
-                    //mButton->clear( );
-                    mButton->setText( newValue );                    
-                    mButton->setTextAlignment(Qt::AlignLeft);
+                    
+                } else if ( dynamicPropertyName == "selectedItems" ) {                    
+                    mItems = property("items").toStringList();
+                    mSelectedItems = property("selectedItems").toList();
+                    makeSelection();
                 }
                 break;
             }
@@ -319,53 +515,86 @@
 }
 
 
+void HbMultiSelectionItem::updateModel( const QItemSelection &selected, 
+    const QItemSelection  &deselected)
+{
+
+    // This function gets called when selection changes in HbListWidget model
+    disconnect( mModel, SIGNAL( dataChanged( QModelIndex, QModelIndex ) ),
+        HbDataFormViewItemPrivate::d_ptr(mViewItem)->mSharedData->mItemView, 
+        SLOT( dataChanged(QModelIndex,QModelIndex)));
+    QModelIndexList selectList = selected.indexes();    
+    QModelIndexList deselectList = deselected.indexes();
+    // Add newly selected item to selected list
+    for(int i = 0;i<selectList.count(); i++) {
+       if(!mSelectedItems.contains(selectList.at(i).row())) {
+            mSelectedItems.append(selectList.at(i).row());
+       }
+    }
+    // remove selection from selection list
+    for(int i = 0;i<deselectList.count(); i++) {
+        mSelectedItems.removeOne(deselectList.at(i).row());
+    }
+    //update the model with the selected items
+    
+    mModelItem->setContentWidgetData("selectedItems", mSelectedItems);
+
+    connect(mModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
+                  HbDataFormViewItemPrivate::d_ptr(mViewItem)->mSharedData->mItemView, 
+                  SLOT( dataChanged(QModelIndex,QModelIndex)));
+}
+
 void HbMultiSelectionItem::launchMultiSelectionList()
 {
-    mQuery = 0;
-    mQuery = new HbListDialog();
-    mQuery->setSelectionMode( HbAbstractItemView::MultiSelection );
-    mQuery->setStringItems( mItems, mItems.count() + 1 );    
-    mQuery->setSelectedItems( mSelectedItems );
-    mQuery->setAttribute(Qt::WA_DeleteOnClose);
-
-    mQuery->open(this,SLOT(dialogClosed(HbAction*)));   
+    if(!mSelectionDialog ) {
+        mSelectionDialog = new HbSelectionDialog();
+        mSelectionDialog->setSelectionMode( HbAbstractItemView::MultiSelection );
+        mSelectionDialog->setStringItems( mItems, -1 ); 
+        mSelectionDialog->setSelectedItems( mSelectedItems );
+        mSelectionDialog->setAttribute(Qt::WA_DeleteOnClose);
+        mSelectionDialog->open(this,SLOT(dialogClosed(HbAction*)));   
+    }
 }
 
 void HbMultiSelectionItem::dialogClosed(HbAction* action)
 {
-    if( action == mQuery->primaryAction( )) {
+    if( action->text() == "Ok") {
         //fetch the selected items
-        mSelectedItems = mQuery->selectedItems();
+        mSelectedItems = mSelectionDialog->selectedItems();
         QString newValue("");
-
-        qSort( mSelectedItems.begin(), mSelectedItems.end( ) );
+        QList<int> selection;
         for( int i = 0; i < mSelectedItems.count(); i++ ) {
-            newValue.append(mQuery->stringItems().at(mSelectedItems.at(i)));
-            if( i != mSelectedItems.count() - 1 ) {
+            selection.append(mSelectedItems.at(i).toInt());
+        }
+        qSort( selection.begin(), selection.end( ) );
+        mSelectedItems.clear();
+        for( int i = 0; i < selection.count(); i++ ) {
+            mSelectedItems.append(selection.at(i));
+            newValue.append(mSelectionDialog->stringItems().at(selection.at(i)));
+            if( i != selection.count() - 1 ) {
                 newValue.append( ";" );
             }
-        }
-        
+        }        
         mButton->setText( newValue );
         emit valueChanged(mViewItem->modelIndex(), newValue);
 
         disconnect( mModel, SIGNAL( dataChanged( QModelIndex, QModelIndex ) ),
                       HbDataFormViewItemPrivate::d_ptr(mViewItem)->mSharedData->mItemView, 
                       SLOT( dataChanged(QModelIndex,QModelIndex)));
+        if(mModelItem) {
+            mModelItem->setContentWidgetData(QString("text"), newValue);
+        }
         
         mModelItem->setContentWidgetData( "items", mItems );
 
         //update the model with the selected items
-        QList<QVariant> items;
-        for( int i = 0; i < mSelectedItems.count(); i++ ) {
-            items.append( mSelectedItems.at( i ) );
-        }
-        mModelItem->setContentWidgetData("selectedItems", items);
+        mModelItem->setContentWidgetData("selectedItems", mSelectedItems);
 
         connect(mModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
                       HbDataFormViewItemPrivate::d_ptr(mViewItem)->mSharedData->mItemView, 
                       SLOT( dataChanged(QModelIndex,QModelIndex)));
     }
+    mSelectionDialog = 0;
 }
 
 
@@ -431,6 +660,13 @@
         if( !mLabelItem ) {
             mLabelItem = q->style()->createPrimitive( HbStyle::P_DataItem_label, q );
         }
+    } else {
+        if( mLabelItem ) {
+            HbStyle::setItemName( mLabelItem, NULL );
+            delete mLabelItem;
+            mLabelItem = 0;
+
+        }
     }
 
     if( !mIcon.isEmpty() ) {
@@ -440,12 +676,24 @@
         }
     } else {
         q->setProperty( "hasIcon", false );
+        if( mIconItem ) {
+            HbStyle::setItemName( mIconItem, NULL );
+            delete mIconItem;
+            mIconItem = 0;
+        }
     }
 
     if(!mDescription.isEmpty()) {
         if(!mDescriptionItem) {
             mDescriptionItem = q->style()->createPrimitive(HbStyle::P_DataItem_description, q);
         }
+    } else {
+        if( mDescriptionItem ) {
+            HbStyle::setItemName( mDescriptionItem, NULL );
+            delete mDescriptionItem;
+            mDescriptionItem = 0;
+
+        }
     }
 }
 
@@ -454,9 +702,26 @@
 */
 void HbDataFormViewItemPrivate::setDescription( const QString& description )
 {
-    mDescription = description; 
+    Q_Q( HbDataFormViewItem );
+
+    if ( mDescription == description ) {
+        return;
+    }
+    
+    bool doRepolish = false;
+
+    if ( ( mDescription.isEmpty() && !description.isEmpty() ) || 
+        ( !mDescription.isEmpty() && description.isEmpty() )) {
+            doRepolish = true;
+    }
+
+    mDescription = description;
     createPrimitives();
+    if ( doRepolish ) {
+        q->repolish();
+    }
     updatePrimitives();
+    
 }
 
 /*
@@ -500,53 +765,84 @@
 */
 void HbDataFormViewItemPrivate::setLabel( const QString& label )
 {
+    Q_Q( HbDataFormViewItem );
+
+    if (  mLabel == label ) {
+        return;
+    }
+
+    bool doRepolish = false;
+
+    if ( ( mLabel.isEmpty() && !label.isEmpty() ) || 
+        ( !mLabel.isEmpty() && label.isEmpty() )) {
+            doRepolish = true;
+    }
+
     mLabel = label; 
     createPrimitives();
+    if ( doRepolish ) {
+        q->repolish();
+    }
     updatePrimitives();
 }
-void HbDataFormViewItemPrivate::updateLabel(const QString& label)
+
+void HbDataFormViewItemPrivate::updateData()
 {
     Q_Q(HbDataFormViewItem);
     
     HbDataFormModelItem::DataItemType type = static_cast< HbDataFormModelItem::DataItemType>(
                 q->modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt());
     HbDataFormModel* data_model = static_cast<HbDataFormModel*>(q->itemView()->model());
-    HbDataFormModelItem *model_item = static_cast<HbDataFormModelItem*>(data_model->itemFromIndex(mIndex));   
-    
-    
-    if(type == HbDataFormModelItem::FormPageItem) {
+    HbDataFormModelItem *model_item = static_cast<HbDataFormModelItem*>(data_model->itemFromIndex(mIndex));
+    HbDataFormModelItemPrivate *modelItem_priv = HbDataFormModelItemPrivate::d_ptr(model_item);    
+
+    //update label
+    if( modelItem_priv->dirtyProperty() == "LabelRole" ) {
+        QString label = model_item->label();
+        if(type == HbDataFormModelItem::FormPageItem) {
 
-        int index = data_model->invisibleRootItem()->indexOf(model_item);
-        HbDataFormPrivate* form_priv = HbDataFormPrivate::d_ptr(
-                                    static_cast<HbDataForm*>(q->itemView()));        
-        if(index >= 0) {
-            form_priv->mHeadingWidget->updatePageName(index ,label);
-        }
+            int index = data_model->invisibleRootItem()->indexOf(model_item);
+            HbDataFormPrivate* form_priv = HbDataFormPrivate::d_ptr(
+                                        static_cast<HbDataForm*>(q->itemView()));        
+            if(index >= 0) {
+                form_priv->mHeadingWidget->updatePageName(index ,label);
+            }
+
+        } else if(type == HbDataFormModelItem::GroupItem) {
+
+            HbDataGroupPrivate::d_ptr(static_cast<HbDataGroup*>(q))->setHeading(label);
 
-    } else if(type == HbDataFormModelItem::GroupItem) {
-        
-        
-        HbDataGroupPrivate::d_ptr(static_cast<HbDataGroup*>(q))->setHeading(label);            
+        } else if(type == HbDataFormModelItem::GroupPageItem) {
+           
+            QModelIndex groupIndex = data_model->parent(mIndex);
+            int index = (data_model->itemFromIndex(groupIndex))->indexOf(model_item);       
+            HbDataGroup* groupItem = static_cast<HbDataGroup*>(
+                            q->itemView()->itemByIndex(groupIndex));
+            groupItem->updateGroupPageName(index,label);
 
-    } else if(type == HbDataFormModelItem::GroupPageItem) {
-       
-        QModelIndex groupIndex = data_model->parent(mIndex);
-        int index = (data_model->itemFromIndex(groupIndex))->indexOf(model_item);       
-        HbDataGroup* groupItem = static_cast<HbDataGroup*>(
-                        q->itemView()->itemByIndex(groupIndex));
-        groupItem->updateGroupPageName(index,label);
-
-    } else if (type > HbDataFormModelItem::GroupPageItem ) {
-        setLabel(label);        
+        } else if (type > HbDataFormModelItem::GroupPageItem ) {
+            setLabel(label);        
+        }
+    } else if ( modelItem_priv->dirtyProperty() == "DescriptionRole" ) {
+        //update description of either data item or data group
+        QString description = model_item->description();
+        if( type == HbDataFormModelItem::GroupItem ) {
+            HbDataGroupPrivate::d_ptr(static_cast<HbDataGroup*>(q))->setDescription(description);
+        } else if ( type > HbDataFormModelItem::GroupPageItem ) {
+            setDescription(description);
+        }
+    } else if ( modelItem_priv->dirtyProperty() == "DecorationRole" ){
+        //update data item icon
+        if ( type > HbDataFormModelItem::GroupPageItem ) {
+            setIcon(model_item->icon());
+        }
     }
-    
 }
 
 void HbDataFormViewItemPrivate::setEnabled(bool enabled)
 {
     Q_Q(HbDataFormViewItem);
 
-
     QGraphicsItem::GraphicsItemFlags itemFlags = q->flags();
     Qt::ItemFlags indexFlags = mIndex.flags();
 
@@ -555,12 +851,14 @@
             itemFlags |= QGraphicsItem::ItemIsFocusable;
             q->setFocusPolicy(q->prototype()->focusPolicy());
             q->setProperty("state", "normal");
+            q->grabGesture(Qt::TapGesture);
         }
     } else {
         if (itemFlags & QGraphicsItem::ItemIsFocusable) {
             itemFlags &= ~QGraphicsItem::ItemIsFocusable;
             q->setFocusPolicy(Qt::NoFocus);
             q->setProperty("state", "disabled");
+            q->ungrabGesture(Qt::TapGesture);
         }
     }
 
@@ -583,8 +881,24 @@
 */
 void HbDataFormViewItemPrivate::setIcon( const QString& icon )
 {
+    Q_Q(HbDataFormViewItem);
+    if ( mIcon == icon ) {
+        return;
+    }
+
+    bool doRepolish = false;
+
+    if ( ( mIcon.isEmpty() && !icon.isEmpty() ) || 
+        ( !mIcon.isEmpty() && icon.isEmpty() )) {
+            doRepolish = true;
+    }
+
     mIcon = icon;
     createPrimitives();
+    if ( doRepolish ) {
+        q->repolish();
+    }
+
     updatePrimitives();
 }
 
@@ -610,7 +924,7 @@
         case HbDataFormModelItem::VolumeSliderItem: {
                 mContentWidget = new HbSlider( Qt::Horizontal, q );
                 mProperty.append( "sliderPosition" );            
-                QObject::connect( mContentWidget, SIGNAL(sliderReleased()), q,SLOT(save()) );
+                QObject::connect( mContentWidget, SIGNAL(valueChanged(int)), q,SLOT(save()) );
                 HbStyle::setItemName( mContentWidget, "dataItem_ContentWidget" );                
             }
             break;
@@ -669,6 +983,9 @@
             }
             break;
     }
+    //background primitive should get created.
+    createPrimitives();
+    updatePrimitives();
     if ( mContentWidget ) {
         QEvent polishEvent( QEvent::Polish );
         QCoreApplication::sendEvent( mContentWidget, &polishEvent );