ipsservices/nmipssettings/src/nmipssettingscustomitem.cpp
changeset 20 ecc8def7944a
parent 18 578830873419
child 23 2dc6caa42ec3
equal deleted inserted replaced
18:578830873419 20:ecc8def7944a
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <QVariant>
    18 #include <QVariant>
       
    19 #include <hbdatetimeedit.h>
       
    20 #include <hbabstractitemview.h>
       
    21 #include <hbdataformmodel.h>
       
    22 #include <hbdataformmodelitem.h>
    19 
    23 
    20 #include "nmipssettingscustomitem.h"
    24 #include "nmipssettingscustomitem.h"
    21 #include "nmipssettingslabeledcombobox.h"
    25 #include "nmipssettingslabeledcombobox.h"
    22 
    26 
    23 /*!
    27 /*!
    24     \class NmIpsSettingsCustomItem
    28     \class NmIpsSettingsCustomItem
    25     \brief The class implements a custom HbDataFormViewItem.
    29     \brief The class implements a custom HbDataFormViewItem.
    26 
       
    27 */
    30 */
    28 
    31 
    29 // ======== MEMBER FUNCTIONS ========
    32 // ======== MEMBER FUNCTIONS ========
    30 
    33 
    31 /*!
    34 /*!
    56     \return true if item type for the index is supported, otherwise false.
    59     \return true if item type for the index is supported, otherwise false.
    57 */
    60 */
    58 bool NmIpsSettingsCustomItem::canSetModelIndex(const QModelIndex &index) const
    61 bool NmIpsSettingsCustomItem::canSetModelIndex(const QModelIndex &index) const
    59 {
    62 {
    60     int type(index.data(HbDataFormModelItem::ItemTypeRole).toInt());
    63     int type(index.data(HbDataFormModelItem::ItemTypeRole).toInt());
    61     return type==LabeledComboBox;
    64     return type==LabeledComboBox || type==TimeEditor;
       
    65 }
       
    66 
       
    67 /*!
       
    68     Sets the custom widget's properties from the model item.
       
    69 */
       
    70 void NmIpsSettingsCustomItem::restore()
       
    71 {
       
    72     HbDataFormModelItem::DataItemType itemType = static_cast<HbDataFormModelItem::DataItemType>(
       
    73         modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt());
       
    74 
       
    75     if (itemType==LabeledComboBox || itemType==TimeEditor) {
       
    76 
       
    77         HbDataFormModel* model = static_cast<HbDataFormModel*>
       
    78             (static_cast<HbAbstractViewItem*>(this)->itemView()->model());
       
    79         HbDataFormModelItem* modelItem = model->itemFromIndex(modelIndex());
       
    80         QHash<QString ,QVariant> properties =
       
    81             modelItem->data(HbDataFormModelItem::PropertyRole).toHash();
       
    82 
       
    83          if (itemType==TimeEditor) {
       
    84              // Set time editor properties. Simply copy all set properties to the widget.
       
    85              QStringList propertyNames = properties.keys();
       
    86 
       
    87              for (int index=0 ; index < propertyNames.count() ; index++) {
       
    88                  QString propName = propertyNames.at(index);
       
    89                  dataItemContentWidget()->setProperty(propName.toAscii().data(),
       
    90                                                       properties.value(propName));
       
    91              }
       
    92          } else {
       
    93              // Set combobox properties in specific order. currentIndex must be set last so that
       
    94              // both the labelTexts and comboItems have been set before. Also, labelTexts must be
       
    95              // set before comboItems.
       
    96              setWidgetProperty("labelTexts", properties);
       
    97              setWidgetProperty("comboItems", properties);
       
    98              setWidgetProperty("currentIndex", properties);
       
    99          }
       
   100     }
    62 }
   101 }
    63 
   102 
    64 /*!
   103 /*!
    65     Creates the custom widget.
   104     Creates the custom widget.
    66 */
   105 */
    69     QVariant data(modelIndex().data(HbDataFormModelItem::ItemTypeRole));
   108     QVariant data(modelIndex().data(HbDataFormModelItem::ItemTypeRole));
    70     int type(data.toInt());
   109     int type(data.toInt());
    71 
   110 
    72     HbWidget *widget = 0;
   111     HbWidget *widget = 0;
    73 
   112 
    74     if (type == LabeledComboBox) {
   113     switch (type) {
    75         widget = new NmIpsSettingsLabeledComboBox();
   114             case LabeledComboBox: {
       
   115                 widget = new NmIpsSettingsLabeledComboBox();
       
   116                 break;
       
   117                 }
       
   118             case TimeEditor: {
       
   119                 HbDateTimeEdit *edit = new HbDateTimeEdit();
       
   120                 widget = edit;
       
   121                 break;
       
   122                 }
       
   123             default: {
       
   124                 break;
       
   125                 }
    76     }
   126     }
    77 
   127 
    78     return widget;
   128     return widget;
    79 }
   129 }
       
   130 
       
   131 /*!
       
   132     Sets \a property to the content widget if found from \a properties.
       
   133     \param property Name of the property to set.
       
   134     \param properties Available properties.
       
   135 */
       
   136 void NmIpsSettingsCustomItem::setWidgetProperty(const QString &property,
       
   137     const QHash<QString, QVariant> &properties)
       
   138 {
       
   139     if (properties.contains(property)) {
       
   140         dataItemContentWidget()->setProperty(property.toAscii().data(), properties.value(property));
       
   141     }
       
   142 }
       
   143