locationsystemui/locationsysui/possettings/possettingsengine/src/possettingspushbuttonitem.cpp
branchRCL_3
changeset 44 2b4ea9893b66
equal deleted inserted replaced
42:02ba3f1733c6 44:2b4ea9893b66
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  This class provides custom list item for the
       
    15 * DataForm
       
    16 *
       
    17 */
       
    18 
       
    19 #include <possettingspushbuttonitem.h>
       
    20 #include <hbdataformmodelitem.h>
       
    21 #include <hbpushbutton.h>
       
    22 #include <hbabstractitemview.h>
       
    23 #include <QMetaProperty>
       
    24 #include <hbdataformmodel.h>
       
    25 
       
    26 // ---------------------------------------------------------------------------
       
    27 // PosSettingsPushButtonItem:::PosSettingsPushButtonItem
       
    28 // ---------------------------------------------------------------------------
       
    29 //
       
    30 PosSettingsPushButtonItem::PosSettingsPushButtonItem(QGraphicsItem *parent) :
       
    31 HbDataFormViewItem(parent)
       
    32 {
       
    33 }
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // PosSettingsPushButtonItem:::~PosSettingsPushButtonItem
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 PosSettingsPushButtonItem::~PosSettingsPushButtonItem()
       
    40 {
       
    41 }
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // PosSettingsPushButtonItem:::createItem
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 HbAbstractViewItem* PosSettingsPushButtonItem::createItem()
       
    48 {
       
    49     return new PosSettingsPushButtonItem(*this);
       
    50 }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // PosSettingsPushButtonItem:::canSetModelIndex
       
    54 // ---------------------------------------------------------------------------
       
    55 
       
    56 bool PosSettingsPushButtonItem::canSetModelIndex(const QModelIndex &index) const
       
    57 {
       
    58         int type = index.data(HbDataFormModelItem::ItemTypeRole).toInt();
       
    59         if (type == PushButtonItem ) {
       
    60                 return true;
       
    61         }
       
    62         else {
       
    63                 return false;
       
    64         }
       
    65 }
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // PosSettingsPushButtonItem:::createCustomWidget
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 HbWidget* PosSettingsPushButtonItem::createCustomWidget()
       
    72 {
       
    73     HbDataFormModelItem::DataItemType itemType =
       
    74     static_cast<HbDataFormModelItem::DataItemType> 
       
    75     ( modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt() );
       
    76     
       
    77     switch (itemType) {
       
    78       case PushButtonItem:
       
    79             { 
       
    80             //custom button
       
    81             QString str =
       
    82                     modelIndex().data(HbDataFormModelItem::PropertyRole).toString();
       
    83             HbPushButton *button = new HbPushButton(str);
       
    84             mWidget = button;
       
    85             return mWidget;
       
    86             }
       
    87         default:
       
    88             return 0;
       
    89     }
       
    90 }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // PosSettingsPushButtonItem:::restore
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 void PosSettingsPushButtonItem::restore()
       
    97 {
       
    98     HbDataFormViewItem::restore();
       
    99     if (mWidget) {
       
   100         HbDataFormModelItem::DataItemType itemType = static_cast<HbDataFormModelItem::DataItemType>(
       
   101             modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt());
       
   102 
       
   103         if(itemType == PushButtonItem) {
       
   104 
       
   105             QModelIndex itemIndex = modelIndex();
       
   106             HbDataFormModel *model = static_cast<HbDataFormModel*>(itemView()->model());;
       
   107             HbDataFormModelItem *modelItem = static_cast<HbDataFormModelItem*>(
       
   108                 model->itemFromIndex(itemIndex));
       
   109 
       
   110             const QMetaObject *metaObj = mWidget->metaObject();
       
   111             int count = metaObj->propertyCount();
       
   112             for (int i = 0; i < count; i++) {
       
   113                 QMetaProperty metaProperty = metaObj->property(i);
       
   114                 if (metaProperty.isValid() && metaProperty.isWritable()) {
       
   115                     metaProperty.write(mWidget,modelItem->contentWidgetData(metaProperty.name()));
       
   116                 }
       
   117           }
       
   118       }
       
   119   }
       
   120 }
       
   121    
       
   122 //EOF