emailuis/nmsettingui/src/nmsettingsformcustomitems.cpp
changeset 20 ecc8def7944a
parent 18 578830873419
child 30 759dc5235cdb
equal deleted inserted replaced
18:578830873419 20:ecc8def7944a
    13 *
    13 *
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 
    17 
       
    18 #include <QModelIndex>
       
    19 #include <HbPushButton>
       
    20 #include <HbAbstractViewItem>
       
    21 #include <HbDataFormModel>
       
    22 #include <HbDataFormModelItem>
       
    23 #include <HbAbstractItemView>
       
    24 
    18 #include "nmsettingsformcustomitems.h"
    25 #include "nmsettingsformcustomitems.h"
    19 
       
    20 #include <hbpushbutton.h>
       
    21 
    26 
    22 
    27 
    23 /*!
    28 /*!
    24     \class NmSettingsFormCustomItems
    29     \class NmSettingsFormCustomItems
    25     \brief Contains definitions for custom setting data form items.
    30     \brief Contains definitions for custom setting data form items.
    55 {
    60 {
    56     int type(index.data(HbDataFormModelItem::ItemTypeRole).toInt());
    61     int type(index.data(HbDataFormModelItem::ItemTypeRole).toInt());
    57     return type==NmButtonItem;
    62     return type==NmButtonItem;
    58 }
    63 }
    59 
    64 
       
    65 /*!
       
    66     Sets the custom widget's properties from the model item.
       
    67 */
       
    68 void NmSettingsFormCustomItems::restore()
       
    69 {
       
    70     HbDataFormModelItem::DataItemType itemType = static_cast<HbDataFormModelItem::DataItemType>(
       
    71         modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt());
       
    72      if (itemType==NmButtonItem) {
       
    73 
       
    74          HbDataFormModel* model = static_cast<HbDataFormModel*>
       
    75              (static_cast<HbAbstractViewItem*>(this)->itemView()->model());
       
    76          HbDataFormModelItem* modelItem = model->itemFromIndex(modelIndex());
       
    77          QHash<QString ,QVariant> properties =
       
    78              modelItem->data(HbDataFormModelItem::PropertyRole).toHash();
       
    79          QList <QString> propertyNames = properties.keys();
       
    80 
       
    81          for (int index=0; index < propertyNames.count(); index++) {
       
    82              QString propName = propertyNames.at(index);
       
    83              dataItemContentWidget()->setProperty(propName.toAscii().data(),
       
    84                                                   properties.value(propName));
       
    85          }
       
    86      }
       
    87 }
    60 
    88 
    61 /*!
    89 /*!
    62     From HbDataFormViewItem.
    90     From HbDataFormViewItem.
    63 */
    91 */
    64 HbWidget *NmSettingsFormCustomItems::createCustomWidget()
    92 HbWidget *NmSettingsFormCustomItems::createCustomWidget()
    70     HbWidget *widget = 0;
    98     HbWidget *widget = 0;
    71 
    99 
    72     switch (itemType) {
   100     switch (itemType) {
    73       case NmButtonItem: {
   101       case NmButtonItem: {
    74             // Push button.
   102             // Push button.
    75             QString text = modelIndex().data(HbDataFormModelItem::KeyRole).toString();
   103             widget = new HbPushButton();
    76             widget = new HbPushButton(text);
       
    77         }
   104         }
    78         default: {
   105         default: {
    79             break;
   106             break;
    80         }
   107         }
    81     }
   108     }