|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "emailtrace.h" |
|
19 |
|
20 #include <QModelIndex> |
|
21 #include <HbPushButton> |
|
22 #include <HbAbstractViewItem> |
|
23 #include <HbDataFormModel> |
|
24 #include <HbDataFormModelItem> |
|
25 #include <HbAbstractItemView> |
|
26 |
|
27 #include "nmsettingsformcustomitems.h" |
|
28 |
|
29 |
|
30 /*! |
|
31 \class NmSettingsFormCustomItems |
|
32 \brief Contains definitions for custom setting data form items. |
|
33 */ |
|
34 |
|
35 |
|
36 /*! |
|
37 Class constructor. |
|
38 */ |
|
39 NmSettingsFormCustomItems::NmSettingsFormCustomItems(QGraphicsItem *parent) |
|
40 : HbDataFormViewItem(parent) |
|
41 { |
|
42 NM_FUNCTION; |
|
43 } |
|
44 |
|
45 |
|
46 /*! |
|
47 Class destructor. |
|
48 */ |
|
49 NmSettingsFormCustomItems::~NmSettingsFormCustomItems() |
|
50 { |
|
51 NM_FUNCTION; |
|
52 } |
|
53 |
|
54 |
|
55 /*! |
|
56 From HbDataFormViewItem. |
|
57 */ |
|
58 HbAbstractViewItem *NmSettingsFormCustomItems::createItem() |
|
59 { |
|
60 NM_FUNCTION; |
|
61 |
|
62 return new NmSettingsFormCustomItems(*this); |
|
63 } |
|
64 |
|
65 bool NmSettingsFormCustomItems::canSetModelIndex(const QModelIndex &index) const |
|
66 { |
|
67 NM_FUNCTION; |
|
68 |
|
69 int type(index.data(HbDataFormModelItem::ItemTypeRole).toInt()); |
|
70 return type==NmButtonItem; |
|
71 } |
|
72 |
|
73 /*! |
|
74 Sets the custom widget's properties from the model item. |
|
75 */ |
|
76 void NmSettingsFormCustomItems::restore() |
|
77 { |
|
78 NM_FUNCTION; |
|
79 |
|
80 HbDataFormModelItem::DataItemType itemType = static_cast<HbDataFormModelItem::DataItemType>( |
|
81 modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt()); |
|
82 if (itemType==NmButtonItem) { |
|
83 |
|
84 HbDataFormModel* model = static_cast<HbDataFormModel*> |
|
85 (static_cast<HbAbstractViewItem*>(this)->itemView()->model()); |
|
86 HbDataFormModelItem* modelItem = model->itemFromIndex(modelIndex()); |
|
87 QHash<QString ,QVariant> properties = |
|
88 modelItem->data(HbDataFormModelItem::PropertyRole).toHash(); |
|
89 QList <QString> propertyNames = properties.keys(); |
|
90 |
|
91 for (int index=0; index < propertyNames.count(); index++) { |
|
92 QString propName = propertyNames.at(index); |
|
93 dataItemContentWidget()->setProperty(propName.toAscii().data(), |
|
94 properties.value(propName)); |
|
95 } |
|
96 } |
|
97 } |
|
98 |
|
99 /*! |
|
100 From HbDataFormViewItem. |
|
101 */ |
|
102 HbWidget *NmSettingsFormCustomItems::createCustomWidget() |
|
103 { |
|
104 NM_FUNCTION; |
|
105 |
|
106 HbDataFormModelItem::DataItemType itemType = |
|
107 static_cast<HbDataFormModelItem::DataItemType>( |
|
108 modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt()); |
|
109 |
|
110 HbWidget *widget = 0; |
|
111 |
|
112 switch (itemType) { |
|
113 case NmButtonItem: { |
|
114 // Push button. |
|
115 widget = new HbPushButton(); |
|
116 } |
|
117 default: { |
|
118 break; |
|
119 } |
|
120 } |
|
121 |
|
122 return widget; |
|
123 } |
|
124 |
|
125 |
|
126 // End of file. |