locationsystemui/locationsysui/possettings/poslocationservices/src/locationservicescustomviewitem.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 is extended as HbDataFormViewItem to be used to create 
       
    15  *              group items for location services
       
    16  *
       
    17  */
       
    18 
       
    19 
       
    20 #include "locationservicescustomviewitem.h"
       
    21 #include "locationserviceswidget.h"
       
    22 #include <hbdataformmodel.h>
       
    23 #include <hbabstractitemview.h>
       
    24 #include <qmetaobject.h>
       
    25 
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 // LocationServicesCustomViewItem::LocationServicesCustomViewItem
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 LocationServicesCustomViewItem::LocationServicesCustomViewItem(
       
    32         QGraphicsItem *parent) :
       
    33     HbDataFormViewItem(parent)
       
    34     {    	
       
    35     }
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // LocationServicesCustomViewItem::~LocationServicesCustomViewItem
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 LocationServicesCustomViewItem::~LocationServicesCustomViewItem()
       
    42     {
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // LocationServicesCustomViewItem::createItem
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 HbAbstractViewItem* LocationServicesCustomViewItem::createItem()
       
    50 {
       
    51     return new LocationServicesCustomViewItem(*this);
       
    52 }
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // LocationServicesCustomViewItem::canSetModelIndex
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 bool LocationServicesCustomViewItem::canSetModelIndex(const QModelIndex &index) const
       
    59 {
       
    60     int type = index.data(HbDataFormModelItem::ItemTypeRole).toInt();
       
    61     if (type == LocationServicesCustomItem) {
       
    62         return true;
       
    63     }
       
    64     else {
       
    65         return false;
       
    66     }
       
    67 }
       
    68 
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // LocationServicesCustomViewItem::createCustomWidget
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 HbWidget * LocationServicesCustomViewItem::createCustomWidget()
       
    75     {
       
    76     //get the type of the model
       
    77     int type = modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt();
       
    78     if (type == LocationServicesCustomItem)
       
    79         {
       
    80         //create the instance of location widget
       
    81         LocationServicesWidget* locationservicesWidget =
       
    82                 new LocationServicesWidget();
       
    83         mPushWidget = locationservicesWidget;
       
    84         return mPushWidget;
       
    85         }
       
    86     else
       
    87         {
       
    88         //else return 0
       
    89         return 0;
       
    90         }
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // LocationServicesCustomViewItem::restore
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 void LocationServicesCustomViewItem::restore()
       
    98 {
       
    99     HbDataFormViewItem::restore();
       
   100     if (mPushWidget) {
       
   101         HbDataFormModelItem::DataItemType itemType = static_cast<HbDataFormModelItem::DataItemType>(
       
   102             modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt());
       
   103 
       
   104         if(itemType == LocationServicesCustomItem) {
       
   105 
       
   106             QModelIndex itemIndex = modelIndex();
       
   107             HbDataFormModel *model = static_cast<HbDataFormModel*>(itemView()->model());;
       
   108             HbDataFormModelItem *modelItem = static_cast<HbDataFormModelItem*>(
       
   109                 model->itemFromIndex(itemIndex));
       
   110 
       
   111             const QMetaObject *metaObj = mPushWidget->metaObject();
       
   112             int count = metaObj->propertyCount();
       
   113             for (int i = 0; i < count; ++i) {
       
   114                 QMetaProperty metaProperty = metaObj->property(i);
       
   115                 if (metaProperty.isValid() && metaProperty.isWritable()) {
       
   116                     metaProperty.write(mPushWidget,modelItem->contentWidgetData(metaProperty.name()));
       
   117                 }
       
   118 
       
   119             }
       
   120         }
       
   121     }
       
   122 }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // LocationServicesCustomViewItem::save
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 /*void LocationServicesCustomViewItem::save()
       
   129 {
       
   130     HbDataFormViewItem::save();
       
   131     if (mPushWidget) {
       
   132         HbDataFormModelItem::DataItemType itemType = static_cast<HbDataFormModelItem::DataItemType>(
       
   133             modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt());
       
   134 
       
   135         if(itemType == LocationServicesCustomItem) {
       
   136 
       
   137             QModelIndex itemIndex = modelIndex();
       
   138             HbDataFormModel *model = static_cast<HbDataFormModel*>(itemView()->model());;
       
   139             HbDataFormModelItem *modelItem = static_cast<HbDataFormModelItem*>(
       
   140             model->itemFromIndex(itemIndex));
       
   141             if (LocationServicesWidget *locationservicesWidget = qobject_cast<LocationServicesWidget *>(mPushWidget)) {
       
   142                 modelItem->setContentWidgetData("primarytext",locationservicesWidget->primaryText());     
       
   143                 modelItem->setContentWidgetData("sectext",locationservicesWidget->secText());
       
   144                 modelItem->setContentWidgetData("sec2text",locationservicesWidget->sec2Text());
       
   145             }
       
   146         }
       
   147     }
       
   148 }*/
       
   149 
       
   150 //-------------End of File--------------------------