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 "cpdataformbuttonentryviewitem.h" |
|
18 #include <hbdataformmodelitem.h> |
|
19 #include <hbpushbutton.h> |
|
20 #include <hbdataformmodel.h> |
|
21 #include <hbabstractitemview.h> |
|
22 #include <QMetaProperty> |
|
23 #include <cpsettingformentryitemdata.h> |
|
24 /*! |
|
25 \class CpDataFormButtonEntryViewItem |
|
26 \brief The CpDataFormButtonEntryViewItem is a item proto type of HbDataForm which is supplied by control panel. |
|
27 When you want use setting items which are come from control panel, you should append this class to the proto type list of your data form's instance. |
|
28 Code example: |
|
29 \code |
|
30 HbDataForm *form = new HbDataForm(); |
|
31 QList<HbAbstractViewItem *> protoType = form->itemProtoTypetypes(); |
|
32 protoType.append(CpDataFormButtonEntryViewItem::createCpItemProtoType()); |
|
33 form->setItemPrototypes(); |
|
34 \endcode |
|
35 */ |
|
36 class CpDataFormButtonEntryViewItemPrivate |
|
37 { |
|
38 public: |
|
39 CpDataFormButtonEntryViewItemPrivate() : mWidget(0) |
|
40 { |
|
41 } |
|
42 ~CpDataFormButtonEntryViewItemPrivate() |
|
43 { |
|
44 } |
|
45 HbWidget *mWidget; |
|
46 }; |
|
47 |
|
48 /*! |
|
49 Constructor |
|
50 */ |
|
51 CpDataFormButtonEntryViewItem::CpDataFormButtonEntryViewItem(QGraphicsItem *parent) |
|
52 : HbDataFormViewItem(parent),d_ptr(new CpDataFormButtonEntryViewItemPrivate()) |
|
53 { |
|
54 } |
|
55 |
|
56 /*! |
|
57 Destructor of CpDataFormButtonEntryViewItem |
|
58 */ |
|
59 CpDataFormButtonEntryViewItem::~CpDataFormButtonEntryViewItem() |
|
60 { |
|
61 delete d_ptr; |
|
62 } |
|
63 |
|
64 /*! |
|
65 Creates CpDataFormButtonEntryViewItem. This function is called form HbAbstractItemContainer when model is getting parsed for creating items. |
|
66 */ |
|
67 HbAbstractViewItem *CpDataFormButtonEntryViewItem::createItem() |
|
68 { |
|
69 return new CpDataFormButtonEntryViewItem(*this); |
|
70 } |
|
71 |
|
72 /*! |
|
73 Copy constructor of CpDataFormButtonEntryViewItem |
|
74 */ |
|
75 CpDataFormButtonEntryViewItem::CpDataFormButtonEntryViewItem(const CpDataFormButtonEntryViewItem &other) |
|
76 : HbDataFormViewItem(other), d_ptr(new CpDataFormButtonEntryViewItemPrivate(*other.d_ptr)) |
|
77 { |
|
78 |
|
79 } |
|
80 |
|
81 /*! |
|
82 Assignment operator |
|
83 */ |
|
84 CpDataFormButtonEntryViewItem &CpDataFormButtonEntryViewItem::operator=(const CpDataFormButtonEntryViewItem &other) |
|
85 { |
|
86 if (&other == this) { |
|
87 return *this; |
|
88 } |
|
89 |
|
90 *d_ptr = *(other.d_ptr); |
|
91 |
|
92 return *this; |
|
93 } |
|
94 |
|
95 /*! |
|
96 Inherit from HbAbstractViewItem, return true if the model item can be supported by CpDataFormButtonEntryViewItem. |
|
97 */ |
|
98 bool CpDataFormButtonEntryViewItem::canSetModelIndex(const QModelIndex &index) const |
|
99 { |
|
100 int itemTypeId = index.data(HbDataFormModelItem::ItemTypeRole).toInt(); |
|
101 |
|
102 return (itemTypeId == CpSettingFormEntryItemData::ButtonEntryItem); |
|
103 } |
|
104 |
|
105 /*! |
|
106 Inherit from HbDataFormViewItem, return the setting item's widget of control panel |
|
107 */ |
|
108 HbWidget *CpDataFormButtonEntryViewItem::createCustomWidget() |
|
109 { |
|
110 HbDataFormModelItem::DataItemType itemType = static_cast<HbDataFormModelItem::DataItemType>( |
|
111 modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt()); |
|
112 |
|
113 if (itemType == CpSettingFormEntryItemData::ButtonEntryItem) { |
|
114 HbPushButton *button = new HbPushButton(QString("Push button")); |
|
115 d_ptr->mWidget = button; |
|
116 button->setTextAlignment( Qt::AlignLeft ); |
|
117 return button; |
|
118 } |
|
119 |
|
120 return 0; |
|
121 } |
|
122 |
|
123 /*! |
|
124 Deprecated. Be instead of HbDataFormViewItem::restore() |
|
125 Inherit from HbDataForm. This function is called by hbdataform's framework, |
|
126 for supporting to load entry item's text, icon and additional text dynamically. |
|
127 It is not recommended to call this function manually. |
|
128 */ |
|
129 void CpDataFormButtonEntryViewItem::load() |
|
130 { |
|
131 //HbDataFormViewItem::load(); |
|
132 |
|
133 if (d_ptr->mWidget) { |
|
134 HbDataFormModelItem::DataItemType itemType = static_cast<HbDataFormModelItem::DataItemType>( |
|
135 modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt()); |
|
136 |
|
137 if(itemType == CpSettingFormEntryItemData::ButtonEntryItem) { |
|
138 |
|
139 QModelIndex itemIndex = modelIndex(); |
|
140 HbDataFormModel *model = static_cast<HbDataFormModel*>(itemView()->model());; |
|
141 HbDataFormModelItem *modelItem = static_cast<HbDataFormModelItem*>( |
|
142 model->itemFromIndex(itemIndex)); |
|
143 |
|
144 const QMetaObject *metaObj = d_ptr->mWidget->metaObject(); |
|
145 int count = metaObj->propertyCount(); |
|
146 for (int i = 0; i < count; i++) { |
|
147 QMetaProperty metaProperty = metaObj->property(i); |
|
148 if (metaProperty.isValid() && metaProperty.isWritable()) { |
|
149 metaProperty.write(d_ptr->mWidget,modelItem->contentWidgetData(metaProperty.name())); |
|
150 } |
|
151 |
|
152 } |
|
153 } |
|
154 } |
|
155 } |
|
156 /*! |
|
157 Inherit from HbDataForm. This function is called by hbdataform's framework, |
|
158 for supporting to load entry item's text, icon and additional text dynamically. |
|
159 It is not recommended to call this function manually. |
|
160 */ |
|
161 void CpDataFormButtonEntryViewItem::restore() |
|
162 { |
|
163 HbDataFormViewItem::restore(); |
|
164 |
|
165 if (d_ptr->mWidget) { |
|
166 HbDataFormModelItem::DataItemType itemType = static_cast<HbDataFormModelItem::DataItemType>( |
|
167 modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt()); |
|
168 |
|
169 if(itemType == CpSettingFormEntryItemData::ButtonEntryItem) { |
|
170 |
|
171 QModelIndex itemIndex = modelIndex(); |
|
172 HbDataFormModel *model = static_cast<HbDataFormModel*>(itemView()->model());; |
|
173 HbDataFormModelItem *modelItem = static_cast<HbDataFormModelItem*>( |
|
174 model->itemFromIndex(itemIndex)); |
|
175 |
|
176 const QMetaObject *metaObj = d_ptr->mWidget->metaObject(); |
|
177 int count = metaObj->propertyCount(); |
|
178 for (int i = 0; i < count; i++) { |
|
179 QMetaProperty metaProperty = metaObj->property(i); |
|
180 if (metaProperty.isValid() && metaProperty.isWritable()) { |
|
181 metaProperty.write(d_ptr->mWidget,modelItem->contentWidgetData(metaProperty.name())); |
|
182 } |
|
183 |
|
184 } |
|
185 } |
|
186 } |
|
187 } |
|
188 |
|
189 //End of File |
|