src/hbwidgets/dataform/hbdataformviewitem_p.cpp
changeset 6 c3690ec91ef8
parent 5 627c4a0fd0e7
child 7 923ff622b8b9
equal deleted inserted replaced
5:627c4a0fd0e7 6:c3690ec91ef8
    70             HbDataFormViewItemPrivate::d_ptr( mViewItem )->mSharedData->mItemView->model( ) );
    70             HbDataFormViewItemPrivate::d_ptr( mViewItem )->mSharedData->mItemView->model( ) );
    71     mModelItem = static_cast<HbDataFormModelItem*>(
    71     mModelItem = static_cast<HbDataFormModelItem*>(
    72             mModel->itemFromIndex( mViewItem->modelIndex( ) ) );
    72             mModel->itemFromIndex( mViewItem->modelIndex( ) ) );
    73     QObject::connect(this,SIGNAL(valueChanged(QPersistentModelIndex, QVariant)),mViewItem, 
    73     QObject::connect(this,SIGNAL(valueChanged(QPersistentModelIndex, QVariant)),mViewItem, 
    74         SIGNAL(itemModified(QPersistentModelIndex, QVariant)));
    74         SIGNAL(itemModified(QPersistentModelIndex, QVariant)));
       
    75 
       
    76      // make the connetions added by application
       
    77      HbDataFormPrivate* form_priv = HbDataFormPrivate::d_ptr(
       
    78             static_cast<HbDataForm*>(mViewItem->itemView()));
       
    79      form_priv->makeConnection(mViewItem->modelIndex() , mButton);
    75 }
    80 }
    76 
    81 
    77 HbToggleItem::~HbToggleItem()
    82 HbToggleItem::~HbToggleItem()
    78 {
    83 {
    79 }
    84 }
   115     // as the text of HbPushButton
   120     // as the text of HbPushButton
   116     QString additionalTxt = 
   121     QString additionalTxt = 
   117         mModelItem->contentWidgetData( QString("additionalText") ).toString();
   122         mModelItem->contentWidgetData( QString("additionalText") ).toString();
   118     QString txt = mModelItem->contentWidgetData(QString("text")).toString();
   123     QString txt = mModelItem->contentWidgetData(QString("text")).toString();
   119     HbDataFormModelItemPrivate *modelItem_priv = HbDataFormModelItemPrivate::d_ptr(mModelItem); 
   124     HbDataFormModelItemPrivate *modelItem_priv = HbDataFormModelItemPrivate::d_ptr(mModelItem); 
   120     // Dont want to emit datachanged for this property so calling private function
   125     // Don't want to emit datachanged for this property so calling private function
   121     modelItem_priv->setContentWidgetData( QString("additionalText"), txt );
   126     modelItem_priv->setContentWidgetData( QString("additionalText"), txt );
   122     // will emit datachanged
   127     // will emit datachanged
   123     mModelItem->setContentWidgetData( QString("text"), additionalTxt );
   128     mModelItem->setContentWidgetData( QString("text"), additionalTxt );
   124     emit valueChanged(mViewItem->modelIndex(), additionalTxt);
   129     emit valueChanged(mViewItem->modelIndex(), additionalTxt);
   125 }
   130 }
   165 {
   170 {
   166     // If not created create and set properties and return the widget
   171     // If not created create and set properties and return the widget
   167     if(!mRadioButtonList) {
   172     if(!mRadioButtonList) {
   168         mRadioButtonList = new HbRadioButtonList();      
   173         mRadioButtonList = new HbRadioButtonList();      
   169         mRadioButtonList->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred));
   174         mRadioButtonList->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred));
   170         QObject::connect(mRadioButtonList, SIGNAL(itemSelected(int)), this, SIGNAL(itemSelected(int)));
   175                
   171         QObject::connect(mRadioButtonList, SIGNAL(startPreview(int)), this, SIGNAL(startPreview(int)));
       
   172         //mRadioButtonList->setClampingStyle(HbScrollArea::StrictClamping);
   176         //mRadioButtonList->setClampingStyle(HbScrollArea::StrictClamping);
   173         mRadioButtonList->setItems( mItems );
   177         mRadioButtonList->setItems( mItems );
   174         if( mSelected != -1 ) {
   178         if( mSelected != -1 ) {
   175             mRadioButtonList->setSelected( mSelected );
   179             mRadioButtonList->setSelected( mSelected );
   176         }
   180         }
   177         // model need to be updated when selection changes
   181         // model need to be updated when selection changes
   178         // in popup case this connection will be removed since model will be updated 
   182         // in popup case this connection will be removed since model will be updated 
   179         // only when dialog closed
   183         // only when dialog closed
   180         QObject::connect( mRadioButtonList, SIGNAL(itemSelected(int)), 
   184         QObject::connect( mRadioButtonList, SIGNAL(itemSelected(int)), 
   181             this, SLOT(updateModel(int)) );
   185             this, SLOT(updateModel(int)) );
       
   186 
       
   187         // make the connetions added by application
       
   188         HbDataFormPrivate* form_priv = HbDataFormPrivate::d_ptr(
       
   189             static_cast<HbDataForm*>(mViewItem->itemView()));
       
   190         form_priv->makeConnection(mViewItem->modelIndex() , mRadioButtonList);
   182         
   191         
   183     }
   192     }
   184     return mRadioButtonList;
   193     return mRadioButtonList;
   185 }
   194 }
   186 
   195 
   201                         property( changeEvent->propertyName().data()) );
   210                         property( changeEvent->propertyName().data()) );
   202                 }
   211                 }
   203                 if( dynamicPropertyName == "items" || dynamicPropertyName == "displayMode" ) {
   212                 if( dynamicPropertyName == "items" || dynamicPropertyName == "displayMode" ) {
   204                     // store the items locally
   213                     // store the items locally
   205                     mItems = property("items").toStringList();
   214                     mItems = property("items").toStringList();
       
   215                     if(mItems.count() == 0) {
       
   216                         mItems = mModelItem->contentWidgetData(QString("items")).toStringList();
       
   217                     }
       
   218                     if(mItems.count() == 0) {
       
   219                         //clear the current slection if all items are deleted 
       
   220                         updateModel(-1);
       
   221                     }/* else {
       
   222                         // if new items are populated make the current slection to 0
       
   223                         updateModel(0);
       
   224                     }*/
   206                     // in case of automatic, displayMode (embedded, automatic or popup) will change 
   225                     // in case of automatic, displayMode (embedded, automatic or popup) will change 
   207                     // if new items are populated or mode should be changed if mode is set
   226                     // if new items are populated or mode should be changed if mode is set
   208                     //  explicitly by application at runtime
   227                     //  explicitly by application at runtime
   209                     changeMode();
   228                     changeMode();
   210                 } else if(dynamicPropertyName == "selected") {
   229                 } else if(dynamicPropertyName == "selected") {
   234         mButton = 0;
   253         mButton = 0;
   235     }
   254     }
   236     createRadioButton();
   255     createRadioButton();
   237     layout->addItem(mRadioButtonList);
   256     layout->addItem(mRadioButtonList);
   238     mRadioButtonList->setScrollDirections(0);
   257     mRadioButtonList->setScrollDirections(0);
       
   258     //Ungrab the pan gesture because we do not want radio button list to scroll
       
   259     mRadioButtonList->ungrabGesture(Qt::PanGesture);
   239 }
   260 }
   240 
   261 
   241 void HbRadioItem::makePopup()
   262 void HbRadioItem::makePopup()
   242 {
   263 {
   243     if(mRadioButtonList) {
   264     if(mRadioButtonList) {
   308 
   329 
   309 void HbRadioItem::initilizeButton()
   330 void HbRadioItem::initilizeButton()
   310 {
   331 {
   311     if(!mButton) {
   332     if(!mButton) {
   312         mButton = new HbPushButton();
   333         mButton = new HbPushButton();
   313         mButton->setTextAlignment(Qt::AlignLeft);
       
   314         QObject::connect(mButton, SIGNAL(clicked()), this, SLOT(buttonClicked()));
   334         QObject::connect(mButton, SIGNAL(clicked()), this, SLOT(buttonClicked()));
   315         layout->addItem( mButton ); 
   335         layout->addItem( mButton ); 
   316     }
   336     }
   317 }
   337 }
   318 
   338 
   331         QObject::connect(mDialog, SIGNAL(aboutToShow()), this, SIGNAL(aboutToShow()));
   351         QObject::connect(mDialog, SIGNAL(aboutToShow()), this, SIGNAL(aboutToShow()));
   332         QObject::connect(mDialog, SIGNAL(aboutToHide()), this, SIGNAL(aboutToHide()));
   352         QObject::connect(mDialog, SIGNAL(aboutToHide()), this, SIGNAL(aboutToHide()));
   333         QObject::connect(mDialog, SIGNAL(aboutToClose()), this, SIGNAL(aboutToClose()));
   353         QObject::connect(mDialog, SIGNAL(aboutToClose()), this, SIGNAL(aboutToClose()));
   334         mDialog->setTimeout(HbPopup::NoTimeout);    
   354         mDialog->setTimeout(HbPopup::NoTimeout);    
   335         mDialog->setAttribute(Qt::WA_DeleteOnClose);
   355         mDialog->setAttribute(Qt::WA_DeleteOnClose);
   336         mDialog->setContentWidget(mRadioButtonList);    
   356         mDialog->setDismissPolicy(HbPopup::NoDismiss);
   337         mDialog->addAction(new HbAction(QString("Ok")));
   357         mDialog->setModal(true);
   338         mDialog->addAction(new HbAction(QString("Cancel")));
   358         mDialog->setContentWidget(mRadioButtonList);   
   339         mDialog->open(this,SLOT(dialogClosed(HbAction*)));  
   359         HbAction *ok = new HbAction(QString("Ok"));
   340         mRadioButtonList->setSelected(mSelected);
   360         mDialog->addAction(ok);
       
   361         HbAction *cancel = new HbAction(QString("Cancel"));
       
   362         connect(ok, SIGNAL(triggered()), mDialog,SLOT(accept()));
       
   363         mDialog->addAction(cancel);
       
   364         mDialog->connect(cancel, SIGNAL(triggered()), mDialog, SLOT(reject()));
       
   365         mRadioButtonList->setSelected(mSelected);       
       
   366         mDialog->open(this,SLOT(dialogClosed(int)));
   341     }
   367     }
   342 }
   368 }
   343 
   369 
   344 
   370 
   345 void HbRadioItem::updateModel( int index )
   371 void HbRadioItem::updateModel( int index )
   346 {
   372 {
   347     mSelected = index;
   373     mSelected = index;
   348     emit valueChanged(mViewItem->modelIndex(), mItems.at(index));
   374     if( index > -1 && mItems.count() < index ) {
       
   375     	emit valueChanged(mViewItem->modelIndex(), mItems.at(index));
       
   376     }
   349     // Disconnect modelchanged signal since visualization is already updated by user
   377     // Disconnect modelchanged signal since visualization is already updated by user
   350     // so if not disconnected , this will trigger visualization change again
   378     // so if not disconnected , this will trigger visualization change again
   351     disconnect( mModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
   379     disconnect( mModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
   352                   HbDataFormViewItemPrivate::d_ptr(mViewItem)->mSharedData->mItemView, 
   380                   HbDataFormViewItemPrivate::d_ptr(mViewItem)->mSharedData->mItemView, 
   353                   SLOT( dataChanged(QModelIndex,QModelIndex)) );
   381                   SLOT( dataChanged(QModelIndex,QModelIndex)) );
   360     // select the item . The selection is already stored in to the model above
   388     // select the item . The selection is already stored in to the model above
   361     selectItem();
   389     selectItem();
   362 }
   390 }
   363 
   391 
   364 
   392 
   365 void HbRadioItem::dialogClosed(HbAction* action)
   393 void HbRadioItem::dialogClosed(int code)
   366 {
   394 {
   367     if(( action ) && ( action->text() == "Ok" )) {
   395     if(code == HbDialog::Accepted && mRadioButtonList) {
   368         // store the selected item to model
   396         // store the selected item to model
   369         updateModel(mRadioButtonList->selected());        
   397         updateModel(mRadioButtonList->selected());        
   370     }
   398     }
   371     // dont change selection incase of "Cancel" button click .
   399     // don't change selection incase of "Cancel" button click .
   372     mRadioButtonList = 0;
   400     mRadioButtonList = 0;
   373     mDialog = 0;
   401     mDialog = 0;
   374 }
   402 }
   375 
   403 
   376 HbMultiSelectionItem::HbMultiSelectionItem( QGraphicsItem* parent ):
   404 HbMultiSelectionItem::HbMultiSelectionItem( QGraphicsItem* parent ):
   409     QItemSelectionModel *model = 0;
   437     QItemSelectionModel *model = 0;
   410     if(mMultiListWidget) {// embedded case
   438     if(mMultiListWidget) {// embedded case
   411         // get selection model
   439         // get selection model
   412         model = mMultiListWidget->selectionModel();
   440         model = mMultiListWidget->selectionModel();
   413         if(model) {
   441         if(model) {
   414             // disconnect so that the visualization does not get changed when selction 
   442             // disconnect so that the visualization does not get changed when selection 
   415             // model changes
   443             // model changes
   416             QObject::disconnect(model, 
   444             QObject::disconnect(model, 
   417                 SIGNAL(selectionChanged( const QItemSelection , const QItemSelection  )), 
   445                 SIGNAL(selectionChanged( const QItemSelection , const QItemSelection  )), 
   418                 this, SLOT(updateModel( const QItemSelection , const QItemSelection  )));
   446                 this, SLOT(updateModel( const QItemSelection , const QItemSelection  )));
   419             model->clearSelection();
   447             model->clearSelection();
   429         QString newValue("");
   457         QString newValue("");
   430         // create sting to be set on button
   458         // create sting to be set on button
   431         for ( int i = 0; i < mSelectedItems.count() ; i++ ) {
   459         for ( int i = 0; i < mSelectedItems.count() ; i++ ) {
   432             int selectionindex = mSelectedItems.at( i ).toInt();
   460             int selectionindex = mSelectedItems.at( i ).toInt();
   433             if( selectionindex< mItems.count()) {
   461             if( selectionindex< mItems.count()) {
   434                 if( i > 0) {// dont add ; in the starting of the string
   462                 if( i > 0) {// don't add ; in the starting of the string
   435                     newValue.append( "," );
   463                     newValue.append( "," );
   436                 }
   464                 }
   437                 newValue.append( mItems.at( mSelectedItems.at( i ).toInt() ) );
   465                 newValue.append( mItems.at( mSelectedItems.at( i ).toInt() ) );
   438             } 
   466             } 
   439         }
   467         }
   466     // update the listwidget with new items
   494     // update the listwidget with new items
   467     for (int index = 0; index < mItems.count(); ++index) {
   495     for (int index = 0; index < mItems.count(); ++index) {
   468         mMultiListWidget->addItem(mItems.at(index));
   496         mMultiListWidget->addItem(mItems.at(index));
   469     }
   497     }
   470     mMultiListWidget->setScrollDirections(0);
   498     mMultiListWidget->setScrollDirections(0);
       
   499     //ungrab pan gesture because we do not want embedded multi selection list
       
   500     //to scroll
       
   501     mMultiListWidget->ungrabGesture( Qt::PanGesture );
   471 }
   502 }
   472 
   503 
   473 void HbMultiSelectionItem::makePopup()
   504 void HbMultiSelectionItem::makePopup()
   474 {
   505 {
   475     // Delete ListWidget if mode change happened at runtime from embedded to popup
   506     // Delete ListWidget if mode change happened at runtime from embedded to popup
   480     }
   511     }
   481     // create button since we need to display selected item on button
   512     // create button since we need to display selected item on button
   482     // and popup will be launched when button is clicked
   513     // and popup will be launched when button is clicked
   483     if(!mButton) {
   514     if(!mButton) {
   484         mButton = new HbPushButton();
   515         mButton = new HbPushButton();
   485         mButton->setTextAlignment(Qt::AlignLeft);
       
   486         layout->addItem(mButton);
   516         layout->addItem(mButton);
   487     }
   517     }
   488     QObject::connect(mButton, SIGNAL(clicked()), this, SLOT(launchMultiSelectionList()));
   518     QObject::connect(mButton, SIGNAL(clicked()), this, SLOT(launchMultiSelectionList()));
   489 }
   519 }
   490 
   520 
   569         QObject::connect(mSelectionDialog, SIGNAL(finished(HbAction*)),this ,SIGNAL(finished(HbAction*)));
   599         QObject::connect(mSelectionDialog, SIGNAL(finished(HbAction*)),this ,SIGNAL(finished(HbAction*)));
   570         mSelectionDialog->setSelectionMode( HbAbstractItemView::MultiSelection );
   600         mSelectionDialog->setSelectionMode( HbAbstractItemView::MultiSelection );
   571         mSelectionDialog->setStringItems( mItems, -1 ); 
   601         mSelectionDialog->setStringItems( mItems, -1 ); 
   572         mSelectionDialog->setSelectedItems( mSelectedItems );
   602         mSelectionDialog->setSelectedItems( mSelectedItems );
   573         mSelectionDialog->setAttribute(Qt::WA_DeleteOnClose);
   603         mSelectionDialog->setAttribute(Qt::WA_DeleteOnClose);
   574         mSelectionDialog->open(this,SLOT(dialogClosed(HbAction*)));   
   604         mSelectionDialog->open(this,SLOT(dialogClosed(int)));
   575     }
   605 
   576 }
   606         // make the connetions added by application
   577 
   607      HbDataFormPrivate* form_priv = HbDataFormPrivate::d_ptr(
   578 void HbMultiSelectionItem::dialogClosed(HbAction* action)
   608             static_cast<HbDataForm*>(mViewItem->itemView()));
   579 {
   609      form_priv->makeConnection(mViewItem->modelIndex() , mSelectionDialog);
   580     if(( action ) && ( action->text() == "Ok" )) {
   610     }
       
   611 }
       
   612 
       
   613 void HbMultiSelectionItem::dialogClosed(int code)
       
   614 {
       
   615 
       
   616     if(code == HbDialog::Accepted) {
   581         //fetch the selected items
   617         //fetch the selected items
   582         mSelectedItems = mSelectionDialog->selectedItems();
   618         mSelectedItems = mSelectionDialog->selectedItems();
   583         QString newValue("");
   619         QString newValue("");
   584         QList<int> selection;
   620         QList<int> selection;
   585         for( int i = 0; i < mSelectedItems.count(); i++ ) {
   621         for( int i = 0; i < mSelectedItems.count(); i++ ) {
   844         }
   880         }
   845     } else if ( modelItem_priv->dirtyProperty() == "DescriptionRole" ) {
   881     } else if ( modelItem_priv->dirtyProperty() == "DescriptionRole" ) {
   846         //update description of either data item or data group
   882         //update description of either data item or data group
   847         QString description = model_item->description();
   883         QString description = model_item->description();
   848         if( type == HbDataFormModelItem::GroupItem ) {
   884         if( type == HbDataFormModelItem::GroupItem ) {
   849             HbDataGroupPrivate::d_ptr(static_cast<HbDataGroup*>(q))->setDescription(description);
   885             static_cast<HbDataGroup*>(q)->setDescription(description);
   850         } else if ( type > HbDataFormModelItem::GroupPageItem ) {
   886         } else if ( type > HbDataFormModelItem::GroupPageItem ) {
   851             setDescription(description);
   887             setDescription(description);
   852         }
   888         }
   853     } else if ( modelItem_priv->dirtyProperty() == "DecorationRole" ){
   889     } else if ( modelItem_priv->dirtyProperty() == "DecorationRole" ){
   854         //update data item icon
   890         //update data item icon
   868     if (indexFlags & Qt::ItemIsEnabled) {
   904     if (indexFlags & Qt::ItemIsEnabled) {
   869         if (!(itemFlags & QGraphicsItem::ItemIsFocusable)) {
   905         if (!(itemFlags & QGraphicsItem::ItemIsFocusable)) {
   870             itemFlags |= QGraphicsItem::ItemIsFocusable;
   906             itemFlags |= QGraphicsItem::ItemIsFocusable;
   871             q->setFocusPolicy(q->prototype()->focusPolicy());
   907             q->setFocusPolicy(q->prototype()->focusPolicy());
   872             q->setProperty("state", "normal");
   908             q->setProperty("state", "normal");
       
   909             q->setEnabled(true);
   873             q->grabGesture(Qt::TapGesture);
   910             q->grabGesture(Qt::TapGesture);
   874         }
   911         }
   875     } else {
   912     } else {
   876         if (itemFlags & QGraphicsItem::ItemIsFocusable) {
   913         if (itemFlags & QGraphicsItem::ItemIsFocusable) {
   877             itemFlags &= ~QGraphicsItem::ItemIsFocusable;
   914             itemFlags &= ~QGraphicsItem::ItemIsFocusable;
   878             q->setFocusPolicy(Qt::NoFocus);
   915             q->setFocusPolicy(Qt::NoFocus);
   879             q->setProperty("state", "disabled");
   916             q->setProperty("state", "disabled");
       
   917             q->setEnabled(false);
   880             q->ungrabGesture(Qt::TapGesture);
   918             q->ungrabGesture(Qt::TapGesture);
   881         }
   919         }
   882     }
   920     }
   883 
   921 
   884     if( mContentWidget ) {
   922     if( mContentWidget ) {
   885         mContentWidget->setEnabled(enabled);
   923         mContentWidget->setEnabled(enabled);
       
   924         //If slider is disabled then still panning should be possible.
       
   925         if( ( mType == HbDataFormModelItem::SliderItem ) ||
       
   926             ( mType == HbDataFormModelItem::VolumeSliderItem ) ) {
       
   927                 HbSlider *slider = static_cast<HbSlider*>( mContentWidget );
       
   928                 if( enabled ) {
       
   929                     //grab pan gesture
       
   930                     slider->primitive(HbStyle::P_SliderElement_touchgroove)->toGraphicsObject()->grabGesture(
       
   931                         Qt::PanGesture);
       
   932                 } else {
       
   933                     //ungrab pan gesture
       
   934                     slider->primitive(HbStyle::P_SliderElement_touchgroove)->toGraphicsObject()->ungrabGesture(
       
   935                         Qt::PanGesture);
       
   936                 }
       
   937         }
   886     }
   938     }
   887 }
   939 }
   888 
   940 
   889 /*
   941 /*
   890     Returns the heading / label of the setting item.
   942     Returns the heading / label of the setting item.