|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbWidgets module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 |
|
26 #include <hbdataformmodelitem.h> |
|
27 #include <hbdataformmodel.h> |
|
28 |
|
29 #include "hbdataformmodel_p.h" |
|
30 |
|
31 /* |
|
32 \internal |
|
33 |
|
34 adds the dataformviewitem or page or group depending upon /a itemType |
|
35 and return pointer to newly created form item. |
|
36 \a label : Label for the dataformItem. In case of GroupPage and FormPage, |
|
37 label is added to parents combobox as one of the selectors. |
|
38 \a parent : is parent of item |
|
39 |
|
40 */ |
|
41 HbDataFormModelItem* HbDataFormModelPrivate::addItem( |
|
42 HbDataFormModelItem::DataItemType itemType , const QString& label, HbDataFormModelItem *parent) |
|
43 { |
|
44 if(!parent) { |
|
45 parent = mRoot; |
|
46 } |
|
47 return insertItem( parent->childCount(), itemType , label , parent); |
|
48 } |
|
49 |
|
50 /* |
|
51 \internal |
|
52 |
|
53 insert data form item or page or group depending upon /a itemType |
|
54 and return pointer to newly created form item. |
|
55 \a label : Heading for data group , group tital in case of group page and page tital in case |
|
56 item us data page item. |
|
57 \a parent : is parent of item |
|
58 |
|
59 */ |
|
60 HbDataFormModelItem* HbDataFormModelPrivate::insertItem( |
|
61 int index,HbDataFormModelItem::DataItemType itemType ,const QString& label, HbDataFormModelItem *parent) |
|
62 { |
|
63 if(!parent) { |
|
64 parent = mRoot; |
|
65 } |
|
66 if(itemType == HbDataFormModelItem::GroupPageItem && (parent->type() != HbDataFormModelItem::GroupItem)) { |
|
67 return 0; |
|
68 } |
|
69 HbDataFormModelItem *item = new HbDataFormModelItem(itemType, label); |
|
70 parent->insertChild(index , item); |
|
71 return item; |
|
72 } |
|
73 |
|
74 /* |
|
75 \internal |
|
76 */ |
|
77 void HbDataFormModelPrivate::rowsAboutToBeInserted(HbDataFormModelItem *parent, |
|
78 int start, int end) |
|
79 { |
|
80 Q_Q(HbDataFormModel); |
|
81 QModelIndex index = q->indexFromItem(parent); |
|
82 q->beginInsertRows(index, start, end); |
|
83 } |
|
84 |
|
85 /* |
|
86 \internal |
|
87 */ |
|
88 void HbDataFormModelPrivate::rowsAboutToBeRemoved(HbDataFormModelItem *parent, |
|
89 int start, int end) |
|
90 { |
|
91 Q_Q(HbDataFormModel); |
|
92 QModelIndex index = q->indexFromItem(parent); |
|
93 q->beginRemoveRows(index, start, end); |
|
94 } |
|
95 |
|
96 /* |
|
97 \internal |
|
98 */ |
|
99 void HbDataFormModelPrivate::rowsInserted() |
|
100 { |
|
101 Q_Q(HbDataFormModel); |
|
102 q->endInsertRows(); |
|
103 } |
|
104 |
|
105 /* |
|
106 \internal |
|
107 */ |
|
108 void HbDataFormModelPrivate::rowsRemoved() |
|
109 { |
|
110 Q_Q(HbDataFormModel); |
|
111 q->endRemoveRows(); |
|
112 } |
|
113 |
|
114 |
|
115 /*! |
|
116 @beta |
|
117 @hbwidgets |
|
118 \class HbDataFormModel hbdataformmodel.h |
|
119 \brief The HbDataFormModel class provides data model for HbDataForm. |
|
120 \ingroup model-view |
|
121 |
|
122 HbDataFormModel is derived from QAbstractItemModel. So applications can use, |
|
123 QAbstractItemModel API's to create their datamodel. HbDataFormModel also provides |
|
124 convenience API's specific to HbDataForm. These convinience API's are useful in creating |
|
125 form page, group, group page and data item. |
|
126 |
|
127 A HbDataForm can be used to display the contents of the model. |
|
128 HbDataFormModel also has Apis to return modelindex of the items and vice-versa. |
|
129 So applications can individually modify the items data and set it to the HbDataForm. |
|
130 */ |
|
131 |
|
132 /*! |
|
133 Constructs a new data form model with the given \a parent. |
|
134 |
|
135 */ |
|
136 HbDataFormModel::HbDataFormModel(QObject *parent) |
|
137 :QAbstractItemModel(parent),d_ptr(new HbDataFormModelPrivate ) |
|
138 { |
|
139 Q_D(HbDataFormModel); |
|
140 d->q_ptr = this; |
|
141 d->mRoot->setModel(this); |
|
142 } |
|
143 |
|
144 HbDataFormModel::~HbDataFormModel() |
|
145 { |
|
146 Q_D(HbDataFormModel); |
|
147 removeItem(d->mRoot); |
|
148 delete d_ptr; |
|
149 } |
|
150 |
|
151 /*! |
|
152 @beta |
|
153 |
|
154 Appends FormPageItem and return pointer to newly created HbDataFormModelItem. |
|
155 The parent of FormPageItem is always model's root item. The DataItemType is set |
|
156 as FormPageItem. |
|
157 |
|
158 \a label Label for data page. This label will be added in the top level combo box. |
|
159 |
|
160 \sa insertDataFormPage |
|
161 |
|
162 */ |
|
163 HbDataFormModelItem* HbDataFormModel::appendDataFormPage(const QString &label) |
|
164 { |
|
165 Q_D(HbDataFormModel); |
|
166 return d->addItem(HbDataFormModelItem::FormPageItem,label,0); |
|
167 } |
|
168 |
|
169 /*! |
|
170 @beta |
|
171 |
|
172 Appends GroupItem and returns pointer to newly created HbDataFormModelItem. |
|
173 The DataItemType is set as GroupItem. |
|
174 |
|
175 \a label Label for data group. This label will be set as a group heading. |
|
176 \a parent Parent of item. The parent of GroupItem can be either model's root |
|
177 index or FormPageItem. |
|
178 |
|
179 \sa insertDataFormGroup |
|
180 |
|
181 */ |
|
182 HbDataFormModelItem* HbDataFormModel::appendDataFormGroup(const QString &label, |
|
183 HbDataFormModelItem *parent) |
|
184 { |
|
185 Q_D(HbDataFormModel); |
|
186 return d->addItem(HbDataFormModelItem::GroupItem,label,parent); |
|
187 } |
|
188 |
|
189 /*! |
|
190 @beta |
|
191 |
|
192 Appends GroupPageItem and returns pointer to newly created HbDataFormModelItem. |
|
193 The parent of GroupPageItem can only be GroupItem. If parent passed is other than |
|
194 GroupItem then this item is not appended to model and returns 0. The DataItemType |
|
195 is set as GroupPageItem. |
|
196 |
|
197 \a label Label for data group page. This label will be added in group combo box. |
|
198 |
|
199 \a parent Parent of item which can be only GroupItem. |
|
200 |
|
201 \sa insertDataFormGroupPage |
|
202 |
|
203 */ |
|
204 HbDataFormModelItem* HbDataFormModel::appendDataFormGroupPage(const QString &label, |
|
205 HbDataFormModelItem *parent) |
|
206 { |
|
207 Q_D(HbDataFormModel); |
|
208 return d->addItem(HbDataFormModelItem::GroupPageItem,label,parent); |
|
209 |
|
210 } |
|
211 |
|
212 /*! |
|
213 @beta |
|
214 |
|
215 Appends data item and returns pointer to newly created HbDataFormModelItem. |
|
216 |
|
217 \a itemType Type of data item. It can be anything in |
|
218 HbDataFormModelItem::DataItemType other than FormPageItem, GroupItem and |
|
219 GroupPageItem. |
|
220 \a label Label for data item. |
|
221 \a parent Parent of data item. Parent can be model's root index, FormPageItem, |
|
222 GroupPageItem or GroupItem. |
|
223 |
|
224 \sa insertDataFormItem |
|
225 |
|
226 */ |
|
227 HbDataFormModelItem* HbDataFormModel::appendDataFormItem( |
|
228 HbDataFormModelItem::DataItemType itemType ,const QString &label, |
|
229 HbDataFormModelItem *parent) |
|
230 { |
|
231 Q_D(HbDataFormModel); |
|
232 return d->addItem(itemType,label,parent); |
|
233 } |
|
234 |
|
235 /*! |
|
236 @beta |
|
237 |
|
238 This is a convenience API. If user wants then he can create HbDataFormModelItem |
|
239 individually and then add that item in model using this API. |
|
240 If the \a data is of FormpageItemtype then parent is not considered. FormPage Items are always added |
|
241 to rootItem. Also GroupPage Item has to be inserted in GroupItem. |
|
242 |
|
243 \a data Child item to be inserted. |
|
244 \a parent Parent of DataFormViewItem |
|
245 |
|
246 \sa insertDataFormItem |
|
247 |
|
248 */ |
|
249 void HbDataFormModel::appendDataFormItem(HbDataFormModelItem *data, HbDataFormModelItem *parent) |
|
250 { |
|
251 if(!data) |
|
252 return; |
|
253 |
|
254 HbDataFormModelItem::DataItemType itemType = data->type(); |
|
255 |
|
256 if(!parent || itemType == HbDataFormModelItem::FormPageItem) { |
|
257 parent = invisibleRootItem(); |
|
258 } |
|
259 |
|
260 |
|
261 HbDataFormModelItem::DataItemType parentType = parent->type(); |
|
262 |
|
263 if(itemType == HbDataFormModelItem::GroupPageItem && parentType != HbDataFormModelItem::GroupItem) |
|
264 return; |
|
265 |
|
266 |
|
267 parent->appendChild(data); |
|
268 } |
|
269 |
|
270 /*! |
|
271 @beta |
|
272 |
|
273 Inserts FormPageItem at the specified index and returns pointer to newly created |
|
274 HbDataFormModelItem. The parent can be only model's root index. |
|
275 |
|
276 \a index Index where FormPageItem has to be inserted. |
|
277 \a label Label of FormPageItem. This will be added in top level combo |
|
278 |
|
279 \sa appendDataFormPage |
|
280 |
|
281 */ |
|
282 HbDataFormModelItem* HbDataFormModel::insertDataFormPage(int index,const QString &label) |
|
283 { |
|
284 Q_D(HbDataFormModel); |
|
285 return d->insertItem(index , HbDataFormModelItem::FormPageItem , label); |
|
286 } |
|
287 |
|
288 /*! |
|
289 @beta |
|
290 |
|
291 Inserts GroupItem at the specified index and returns pointer to newly created |
|
292 HbDataFormModelItem. |
|
293 |
|
294 \a index Index where GroupItem has to be inserted. |
|
295 \a label Label for GroupItem. This will be group heading. |
|
296 \a parent Parent of item |
|
297 |
|
298 \sa appendDataFormGroup |
|
299 |
|
300 */ |
|
301 HbDataFormModelItem* HbDataFormModel::insertDataFormGroup(int index, const QString &label, |
|
302 HbDataFormModelItem *parent) |
|
303 { |
|
304 Q_D(HbDataFormModel); |
|
305 return d->insertItem(index , HbDataFormModelItem::GroupItem ,label ,parent); |
|
306 } |
|
307 |
|
308 /*! |
|
309 @beta |
|
310 |
|
311 Inserts GroupPageItem at the specified index and returns pointer to newly created |
|
312 HbDataFormModelItem. Return 0 if parent passed is other than GroupItem. |
|
313 |
|
314 \a index Index where GroupPageItem has to be inserted. |
|
315 \a label Label for GroupPageItem. This will be added in group combo box. |
|
316 \a parent Parent of item |
|
317 |
|
318 \sa appendDataFormGroupPage |
|
319 |
|
320 */ |
|
321 HbDataFormModelItem* HbDataFormModel::insertDataFormGroupPage( |
|
322 int index, const QString &label, HbDataFormModelItem *parent) |
|
323 { |
|
324 Q_D(HbDataFormModel); |
|
325 return d->insertItem(index , HbDataFormModelItem::GroupPageItem, label ,parent); |
|
326 } |
|
327 |
|
328 /*! |
|
329 @beta |
|
330 |
|
331 Inserts data item at the specified index and returns pointer to newly created |
|
332 HbDataFormModelItem. |
|
333 |
|
334 \a index Index where data item has to be inserted. |
|
335 \a label Label for data page. |
|
336 \a parent Parent of item |
|
337 |
|
338 \sa appendDataFormItem |
|
339 |
|
340 */ |
|
341 HbDataFormModelItem* HbDataFormModel::insertDataFormItem(int index, |
|
342 HbDataFormModelItem::DataItemType itemType ,const QString &label, |
|
343 HbDataFormModelItem *parent) |
|
344 { |
|
345 Q_D(HbDataFormModel); |
|
346 return d->insertItem(index ,itemType , label ,parent); |
|
347 } |
|
348 |
|
349 /*! |
|
350 @beta |
|
351 |
|
352 Inserts given HbDataFormModelItem \a data in the \a parent at the specified \a index. |
|
353 |
|
354 \a index Index where data has to be inserted in parent |
|
355 \a data HbDataFormModelItem which has to be inserted |
|
356 \a parent Parent of item |
|
357 |
|
358 \sa appendDataFormItem |
|
359 |
|
360 */ |
|
361 void HbDataFormModel::insertDataFormItem(int index, HbDataFormModelItem *data, |
|
362 HbDataFormModelItem *parent) |
|
363 { |
|
364 if(!parent || (data->data(HbDataFormModelItem::ItemTypeRole) == HbDataFormModelItem::FormPageItem )) { |
|
365 parent = invisibleRootItem(); |
|
366 } |
|
367 parent->insertChild(index,data); |
|
368 } |
|
369 |
|
370 |
|
371 /*! |
|
372 \deprecated HbDataFormModel::insertRows(int row, int count, const QModelIndex &index) |
|
373 is deprecated. Please use other insert and additem API's in HbDataFormModel instead. |
|
374 */ |
|
375 bool HbDataFormModel::insertRows(int row, int count, const QModelIndex &index) |
|
376 { |
|
377 Q_D(HbDataFormModel); |
|
378 HbDataFormModelItem *item = index.isValid() ? itemFromIndex(index) : d->mRoot; |
|
379 if (item == 0) { |
|
380 return false; |
|
381 } |
|
382 |
|
383 QList<HbDataFormModelItem*> items; |
|
384 for(int i =0 ; i < count ; i ++) { |
|
385 items.append(new HbDataFormModelItem()); |
|
386 } |
|
387 item->insertChildren(row,count,items); |
|
388 return true; |
|
389 } |
|
390 |
|
391 |
|
392 /*! |
|
393 @beta |
|
394 |
|
395 Removes and deletes the model item from the model at the given \a index. The visualization |
|
396 corresponding to this \a index is also deleted. Returns true if \a index is removed otherwise |
|
397 returns false. |
|
398 |
|
399 \sa removeItem |
|
400 */ |
|
401 bool HbDataFormModel::removeItem(const QModelIndex &index ) |
|
402 { |
|
403 return removeItem(itemFromIndex(index)); |
|
404 } |
|
405 |
|
406 /*! |
|
407 @beta |
|
408 |
|
409 Removes and deletes given \a item. The visualization corresponding to this \a item |
|
410 is also deleted. If the \a item has childrens, all the children items are removed and deleted. |
|
411 \a item is deleted only if \a item belongs to current model. Returns true if \a item is removed |
|
412 otherwise returns false. |
|
413 |
|
414 \sa removeItem |
|
415 */ |
|
416 bool HbDataFormModel::removeItem(HbDataFormModelItem *item) |
|
417 { |
|
418 if( !item ) { |
|
419 return false; |
|
420 } |
|
421 HbDataFormModelItem* parent = const_cast<HbDataFormModelItem*>(item->parent()); |
|
422 if ( item->model() != this ) { |
|
423 return false; |
|
424 } |
|
425 |
|
426 if( parent ) { |
|
427 int index = parent->indexOf(item); |
|
428 parent->removeChild(index); |
|
429 return true; |
|
430 } else if ( item == invisibleRootItem() ) { |
|
431 delete item; |
|
432 item = 0; |
|
433 return true; |
|
434 } |
|
435 |
|
436 return false; |
|
437 |
|
438 } |
|
439 |
|
440 /*! |
|
441 \reimp |
|
442 */ |
|
443 bool HbDataFormModel::removeRows(int row, int count, const QModelIndex &index) |
|
444 { |
|
445 HbDataFormModelItem *item = itemFromIndex(index); |
|
446 if ((item == 0) || (count < 1) || (row < 0) || ((row + count) > item->childCount())) { |
|
447 return false; |
|
448 } |
|
449 |
|
450 item->removeChildren(row, count); |
|
451 return true; |
|
452 } |
|
453 |
|
454 /*! |
|
455 \reimp |
|
456 Column value should be 0 as DataForm has only one column.If the value is not 0 |
|
457 function returns invalid index. |
|
458 If index is not valid then rootItem's index is considered. |
|
459 */ |
|
460 QModelIndex HbDataFormModel::index(int row, int column, |
|
461 const QModelIndex &index) const |
|
462 { |
|
463 |
|
464 if (!hasIndex(row, column, index) && column > 0) { |
|
465 return QModelIndex(); |
|
466 } |
|
467 HbDataFormModelItem *parentItem = 0; |
|
468 |
|
469 if (!index.isValid()) { |
|
470 parentItem = invisibleRootItem(); |
|
471 } else { |
|
472 parentItem = itemFromIndex(index); |
|
473 } |
|
474 |
|
475 HbDataFormModelItem *childItem = parentItem->childAt(row); |
|
476 if (childItem) { |
|
477 return createIndex(row, column, childItem); |
|
478 } else { |
|
479 return QModelIndex(); |
|
480 } |
|
481 } |
|
482 |
|
483 /*! |
|
484 \reimp |
|
485 */ |
|
486 QModelIndex HbDataFormModel::parent(const QModelIndex &index) const |
|
487 { |
|
488 if (!index.isValid()) { |
|
489 return QModelIndex(); |
|
490 } |
|
491 |
|
492 HbDataFormModelItem *childItem =itemFromIndex(index); |
|
493 HbDataFormModelItem *parentItem = childItem->parent(); |
|
494 |
|
495 if (parentItem == invisibleRootItem()) { |
|
496 return QModelIndex(); |
|
497 } |
|
498 |
|
499 return indexFromItem(parentItem); |
|
500 } |
|
501 |
|
502 /*! |
|
503 \reimp |
|
504 */ |
|
505 int HbDataFormModel::rowCount(const QModelIndex &item ) const |
|
506 { |
|
507 HbDataFormModelItem *parentItem; |
|
508 if (item.column() > 0) { |
|
509 return 0; |
|
510 } |
|
511 |
|
512 if (!item.isValid()) { |
|
513 parentItem = invisibleRootItem(); |
|
514 } else { |
|
515 parentItem = static_cast<HbDataFormModelItem*>(item.internalPointer()); |
|
516 } |
|
517 return parentItem->childCount(); |
|
518 } |
|
519 |
|
520 /*! |
|
521 \reimp |
|
522 */ |
|
523 int HbDataFormModel::columnCount(const QModelIndex & /*parent*/) const |
|
524 { |
|
525 return 1; |
|
526 } |
|
527 |
|
528 /*! |
|
529 \reimp |
|
530 |
|
531 Returns true if given /a index has children, other wise false |
|
532 */ |
|
533 bool HbDataFormModel::hasChildren(const QModelIndex &index) const |
|
534 { |
|
535 HbDataFormModelItem* item = 0; |
|
536 if(index.isValid()) { |
|
537 item = static_cast<HbDataFormModelItem*>(index.internalPointer()); |
|
538 if(item && item->childCount()) { |
|
539 return true; |
|
540 } |
|
541 } |
|
542 return false; |
|
543 } |
|
544 |
|
545 /*! |
|
546 @beta |
|
547 |
|
548 Returns child count for given parent index /a parent |
|
549 */ |
|
550 int HbDataFormModel::childCount(const QModelIndex &index) const |
|
551 { |
|
552 return rowCount(index); |
|
553 } |
|
554 |
|
555 /*! |
|
556 \reimp |
|
557 */ |
|
558 QVariant HbDataFormModel::data(const QModelIndex &index, int role) const |
|
559 { |
|
560 HbDataFormModelItem *item = static_cast<HbDataFormModelItem*>(index.internalPointer()); |
|
561 return item ? item->data(role) : QVariant(); |
|
562 } |
|
563 |
|
564 /*! |
|
565 \reimp |
|
566 */ |
|
567 bool HbDataFormModel::setData(const QModelIndex &index, const QVariant &value, |
|
568 int role) |
|
569 { |
|
570 if (!index.isValid()) { |
|
571 return false; |
|
572 } |
|
573 HbDataFormModelItem *item = itemFromIndex(index); |
|
574 if (item == 0) { |
|
575 return false; |
|
576 } |
|
577 item->setData(role , value); |
|
578 return true; |
|
579 } |
|
580 |
|
581 /*! |
|
582 @beta |
|
583 |
|
584 Removes all items from the model and sets the |
|
585 number of rows and columns to zero. |
|
586 |
|
587 \sa removeColumns(), removeRows() |
|
588 */ |
|
589 void HbDataFormModel::clear() |
|
590 { |
|
591 Q_D(HbDataFormModel); |
|
592 removeItem(invisibleRootItem()); |
|
593 d->mRoot = new HbDataFormModelItem(); |
|
594 d->mRoot->setModel(this); |
|
595 reset(); |
|
596 } |
|
597 |
|
598 /*! |
|
599 \reimp |
|
600 |
|
601 Returns a pointer to the HbDataFormModelItem associated with the given \a index. |
|
602 |
|
603 Calling this function is typically the initial step when processing |
|
604 QModelIndex-based signals from a view, such as |
|
605 HbAbstractItemView::activated(). In your slot, you call itemFromIndex(), |
|
606 with the QModelIndex carried by the signal as argument, to obtain a |
|
607 pointer to the corresponding HbDataFormModelItem. |
|
608 |
|
609 NOTE: index passed should be the one returned from HbDataFromModel Only. |
|
610 |
|
611 If \a index is an invalid index, this function returns 0. |
|
612 |
|
613 \sa indexFromItem() |
|
614 */ |
|
615 HbDataFormModelItem* HbDataFormModel::itemFromIndex(const QModelIndex &index) const |
|
616 { |
|
617 if ((index.row() < 0) || (index.column() < 0) || (index.model() != this)) { |
|
618 return 0; |
|
619 } |
|
620 |
|
621 HbDataFormModelItem *item = static_cast<HbDataFormModelItem*>(index.internalPointer()); |
|
622 if (item) { |
|
623 return item; |
|
624 } |
|
625 return 0; |
|
626 } |
|
627 |
|
628 /*! |
|
629 \reimp |
|
630 |
|
631 Returns the QModelIndex associated with the given \a item. |
|
632 Use this function when you want to perform an operation that requires the |
|
633 QModelIndex of the item, such as HbAbstractItemView::scrollTo(). |
|
634 |
|
635 \sa itemFromIndex() |
|
636 */ |
|
637 QModelIndex HbDataFormModel::indexFromItem(const HbDataFormModelItem* item) const |
|
638 { |
|
639 if(item) { |
|
640 HbDataFormModelItem* parentItem = item->parent(); |
|
641 if (parentItem) { |
|
642 return createIndex(parentItem->indexOf(item), 0, (void*)item); |
|
643 } |
|
644 } |
|
645 return QModelIndex(); |
|
646 } |
|
647 |
|
648 /*! @beta |
|
649 |
|
650 Returns the HbDataFormModelItem at given \a row and with given parent /a index. |
|
651 */ |
|
652 HbDataFormModelItem* HbDataFormModel::item(int row, const QModelIndex &index) const |
|
653 { |
|
654 if(index.isValid()) { |
|
655 return itemFromIndex(index)->childAt(row); |
|
656 } else { |
|
657 return invisibleRootItem()->childAt(row); |
|
658 } |
|
659 } |
|
660 |
|
661 /*! |
|
662 \reimp |
|
663 |
|
664 Returns the model's invisible root item. |
|
665 |
|
666 The invisible root item provides access to the model's top-level items |
|
667 through the HbDataFormModelItem API, making it possible to write functions that |
|
668 can treat top-level items and their children in a uniform way. |
|
669 for example,recursive functions involving a tree model. |
|
670 |
|
671 */ |
|
672 HbDataFormModelItem* HbDataFormModel::invisibleRootItem() const |
|
673 { |
|
674 Q_D(const HbDataFormModel); |
|
675 return d->mRoot; |
|
676 } |
|
677 |
|
678 /* |
|
679 \reimp |
|
680 */ |
|
681 bool HbDataFormModel::canFetchMore ( const QModelIndex & parent ) const |
|
682 { |
|
683 if(parent.isValid()) { |
|
684 if((hasChildren(parent)) || (sibling(parent.row() + 1,0,parent)).isValid()) { |
|
685 return true; |
|
686 } |
|
687 } |
|
688 |
|
689 return false; |
|
690 } |
|
691 |
|
692 /* |
|
693 \reimp |
|
694 */ |
|
695 Qt::ItemFlags HbDataFormModel::flags(const QModelIndex &index) const |
|
696 { |
|
697 if (index.isValid()) { |
|
698 const HbDataFormModelItem *item = itemFromIndex(index); |
|
699 if (item) { |
|
700 return item->flags(); |
|
701 } |
|
702 } |
|
703 return 0; |
|
704 } |
|
705 |
|
706 |