|
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 <possettingsgroupboxitem.h> |
|
20 #include <hbdataformmodelitem.h> |
|
21 #include <hbgroupbox.h> |
|
22 #include <hbabstractitemview.h> |
|
23 #include <QMetaProperty> |
|
24 #include <hbdataformmodel.h> |
|
25 |
|
26 // --------------------------------------------------------------------------- |
|
27 // PosSettingsGroupboxItem:::PosSettingsGroupboxItem |
|
28 // --------------------------------------------------------------------------- |
|
29 // |
|
30 PosSettingsGroupboxItem::PosSettingsGroupboxItem(QGraphicsItem *parent) : |
|
31 HbDataFormViewItem(parent) |
|
32 { |
|
33 } |
|
34 |
|
35 // --------------------------------------------------------------------------- |
|
36 // PosSettingsGroupboxItem:::~PosSettingsGroupboxItem |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 PosSettingsGroupboxItem::~PosSettingsGroupboxItem() |
|
40 { |
|
41 } |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // PosSettingsGroupboxItem:::createItem |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 HbAbstractViewItem* PosSettingsGroupboxItem::createItem() |
|
48 { |
|
49 return new PosSettingsGroupboxItem(*this); |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // PosSettingsGroupboxItem:::canSetModelIndex |
|
54 // --------------------------------------------------------------------------- |
|
55 |
|
56 bool PosSettingsGroupboxItem::canSetModelIndex(const QModelIndex &index) const |
|
57 { |
|
58 int type = index.data(HbDataFormModelItem::ItemTypeRole).toInt(); |
|
59 if (type == GroupboxItem ) { |
|
60 return true; |
|
61 } |
|
62 else { |
|
63 return false; |
|
64 } |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // PosSettingsGroupboxItem:::createCustomWidget |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 HbWidget* PosSettingsGroupboxItem::createCustomWidget() |
|
72 { |
|
73 HbDataFormModelItem::DataItemType itemType = |
|
74 static_cast<HbDataFormModelItem::DataItemType> |
|
75 ( modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt() ); |
|
76 |
|
77 switch (itemType) { |
|
78 case GroupboxItem: |
|
79 { |
|
80 //custom button |
|
81 QString str = |
|
82 modelIndex().data(HbDataFormModelItem::PropertyRole).toString(); |
|
83 HbGroupBox* groupbox = new HbGroupBox(this); |
|
84 // Use the Groupbox widget for heading |
|
85 groupbox->setHeading(str); |
|
86 mWidget = groupbox; |
|
87 return mWidget; |
|
88 } |
|
89 default: |
|
90 return 0; |
|
91 } |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // PosSettingsGroupboxItem:::restore |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 void PosSettingsGroupboxItem::restore() |
|
99 { |
|
100 HbDataFormViewItem::restore(); |
|
101 if (mWidget) { |
|
102 HbDataFormModelItem::DataItemType itemType = static_cast<HbDataFormModelItem::DataItemType>( |
|
103 modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt()); |
|
104 |
|
105 if(itemType == GroupboxItem) { |
|
106 |
|
107 QModelIndex itemIndex = modelIndex(); |
|
108 HbDataFormModel *model = static_cast<HbDataFormModel*>(itemView()->model());; |
|
109 HbDataFormModelItem *modelItem = static_cast<HbDataFormModelItem*>( |
|
110 model->itemFromIndex(itemIndex)); |
|
111 |
|
112 const QMetaObject *metaObj = mWidget->metaObject(); |
|
113 int count = metaObj->propertyCount(); |
|
114 for (int i = 0; i < count; ++i) { |
|
115 QMetaProperty metaProperty = metaObj->property(i); |
|
116 if (metaProperty.isValid() && metaProperty.isWritable()) { |
|
117 metaProperty.write(mWidget,modelItem->contentWidgetData(metaProperty.name())); |
|
118 } |
|
119 } |
|
120 } |
|
121 } |
|
122 } |
|
123 |
|
124 //EOF |