phonesettings/cpphonesettingsplugins/divertplugin/src/cpdivertselectionitem.cpp
branchGCC_SURGE
changeset 51 f39ed5e045e0
parent 40 bab96b7ed1a4
parent 46 bc5a64e5bc3c
equal deleted inserted replaced
40:bab96b7ed1a4 51:f39ed5e045e0
     1 /*
       
     2  * Copyright (c) 2009 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:  
       
    15  *
       
    16  */
       
    17 #include "cpdivertselectionitem.h"
       
    18 #include "cpdivertselectioncustomitem.h"
       
    19 #include <HbDataFormModel>
       
    20 #include <HbAbstractItemView>
       
    21 #include <cppluginlogging.h>
       
    22 #include <qmetaobject.h>
       
    23 
       
    24 
       
    25 
       
    26 CpDivertSelectionItem::CpDivertSelectionItem(QGraphicsItem *parent )
       
    27 : HbDataFormViewItem(parent)
       
    28 {
       
    29     DPRINT;
       
    30 }
       
    31 
       
    32 CpDivertSelectionItem::~CpDivertSelectionItem()
       
    33 {
       
    34     DPRINT;
       
    35 }
       
    36 
       
    37 HbAbstractViewItem* CpDivertSelectionItem::createItem()
       
    38 {
       
    39     DPRINT;
       
    40     return new CpDivertSelectionItem(*this);
       
    41 }
       
    42 
       
    43 bool CpDivertSelectionItem::canSetModelIndex(const QModelIndex &index) const
       
    44 {
       
    45     DPRINT << "index:" << index;
       
    46     int type = index.data(HbDataFormModelItem::ItemTypeRole).toInt();
       
    47     return type == CpDivertSelectionItemId;
       
    48 }
       
    49 
       
    50 HbWidget *CpDivertSelectionItem::createCustomWidget()
       
    51 {
       
    52     DPRINT << ": IN";
       
    53 
       
    54     int type = modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt();
       
    55 
       
    56     if (type == CpDivertSelectionItemId) {
       
    57             CpDivertSelectionCustomitem *retWidget =
       
    58                     new CpDivertSelectionCustomitem(this);
       
    59 
       
    60             DPRINT << ": OUT, retWidget";
       
    61             return retWidget;
       
    62     }
       
    63     DPRINT << ": OUT, 0";
       
    64     return 0;
       
    65 }
       
    66 
       
    67 
       
    68 void CpDivertSelectionItem::restore()
       
    69 {
       
    70     HbDataFormViewItem::restore();
       
    71 
       
    72     if (dataItemContentWidget()) {
       
    73         HbDataFormModelItem::DataItemType itemType = static_cast<HbDataFormModelItem::DataItemType>(
       
    74             modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt());
       
    75 
       
    76         if (CpDivertSelectionItemId == itemType) {
       
    77 
       
    78             QModelIndex itemIndex = modelIndex();
       
    79             HbDataFormModel *model = static_cast<HbDataFormModel*>(itemView()->model());
       
    80             HbDataFormModelItem *modelItem = static_cast<HbDataFormModelItem*>(
       
    81                 model->itemFromIndex(itemIndex));
       
    82 
       
    83             const QMetaObject *metaObj = dataItemContentWidget()->metaObject();
       
    84             int count = metaObj->propertyCount();
       
    85             for (int i = 0; i < count; i++) {
       
    86                 QMetaProperty metaProperty = metaObj->property(i);
       
    87                 if (metaProperty.isValid() && metaProperty.isWritable()) {
       
    88                     metaProperty.write(
       
    89                             dataItemContentWidget(),
       
    90                             modelItem->contentWidgetData(metaProperty.name()));
       
    91                 }
       
    92             }
       
    93         }
       
    94     }
       
    95 
       
    96 }