equal
deleted
inserted
replaced
21 ** If you have questions regarding the use of this file, please contact |
21 ** If you have questions regarding the use of this file, please contact |
22 ** Nokia at developer.feedback@nokia.com. |
22 ** Nokia at developer.feedback@nokia.com. |
23 ** |
23 ** |
24 ****************************************************************************/ |
24 ****************************************************************************/ |
25 |
25 |
|
26 #include "hbdataformmodelitem_p.h" |
|
27 #include "hbdataformmodel_p.h" |
|
28 |
|
29 #include <hbdataformmodelitem.h> |
|
30 #include <hbdataformmodel.h> |
|
31 |
26 #include <QAbstractItemModel> |
32 #include <QAbstractItemModel> |
27 |
|
28 #include "hbdataformmodelitem_p.h" |
|
29 #include "hbdataformmodelitem.h" |
|
30 #include "hbdataformmodel.h" |
|
31 #include "hbdataformmodel_p.h" |
|
32 |
|
33 class QAbstractItemModel; |
|
34 |
33 |
35 |
34 |
36 HbDataFormModelItemPrivate::HbDataFormModelItemPrivate(): |
35 HbDataFormModelItemPrivate::HbDataFormModelItemPrivate(): |
37 mParentItem(0), |
36 mParentItem(0), |
38 mModel(0), |
37 mModel(0), |
320 HbDataFormModelItem::DataItemType type,const QString &label, |
319 HbDataFormModelItem::DataItemType type,const QString &label, |
321 const HbDataFormModelItem* parent): |
320 const HbDataFormModelItem* parent): |
322 d_ptr(new HbDataFormModelItemPrivate()) |
321 d_ptr(new HbDataFormModelItemPrivate()) |
323 { |
322 { |
324 Q_D(HbDataFormModelItem); |
323 Q_D(HbDataFormModelItem); |
325 d->q_ptr = this ; |
324 d->q_ptr = this ; |
326 d->mParentItem = const_cast<HbDataFormModelItem*>(parent); |
325 if( parent ) { |
|
326 d->mParentItem = const_cast<HbDataFormModelItem*>(parent); |
|
327 d->mParentItem->appendChild(this); |
|
328 } |
327 setData(ItemTypeRole, type); |
329 setData(ItemTypeRole, type); |
328 setData(LabelRole, label); |
330 setData(LabelRole, label); |
329 } |
331 } |
330 |
332 |
331 /*! |
333 /*! |
334 HbDataFormModelItem::HbDataFormModelItem(const HbDataFormModelItem* parent): |
336 HbDataFormModelItem::HbDataFormModelItem(const HbDataFormModelItem* parent): |
335 d_ptr(new HbDataFormModelItemPrivate()) |
337 d_ptr(new HbDataFormModelItemPrivate()) |
336 { |
338 { |
337 Q_D(HbDataFormModelItem); |
339 Q_D(HbDataFormModelItem); |
338 d->q_ptr = this ; |
340 d->q_ptr = this ; |
339 d->mParentItem = const_cast<HbDataFormModelItem*>(parent); |
341 if( parent ){ |
|
342 d->mParentItem = const_cast<HbDataFormModelItem*>(parent); |
|
343 d->mParentItem->appendChild(this); |
|
344 } |
340 } |
345 } |
341 |
346 |
342 /*! |
347 /*! |
343 Destructor |
348 Destructor |
344 */ |
349 */ |
376 d->mChildItems.append(child); |
381 d->mChildItems.append(child); |
377 model->d_func()->rowsInserted(); |
382 model->d_func()->rowsInserted(); |
378 } |
383 } |
379 else { |
384 else { |
380 d->mChildItems.append(child); |
385 d->mChildItems.append(child); |
381 } |
386 } |
|
387 |
382 } |
388 } |
383 } |
389 } |
384 |
390 |
385 /*! |
391 /*! |
386 @beta |
392 @beta |
448 return; |
454 return; |
449 } |
455 } |
450 Q_D(HbDataFormModelItem); |
456 Q_D(HbDataFormModelItem); |
451 HbDataFormModel* model = static_cast<HbDataFormModel*>(d->mModel); |
457 HbDataFormModel* model = static_cast<HbDataFormModel*>(d->mModel); |
452 |
458 |
453 if(model) |
459 HbDataFormModelItem *item = d->mChildItems.at(index); |
454 model->d_func()->rowsAboutToBeRemoved(this, index, index); |
460 if( item ) { |
455 |
461 int childCount = item->childCount(); |
456 HbDataFormModelItem *item = d->mChildItems.at(index); |
462 for ( int childIndex = 0; childIndex < childCount ;childIndex++) { |
457 if( item ) { |
463 item->removeChild(0); |
458 int childCount = item->childCount(); |
464 } |
459 for ( int childIndex = 0; childIndex <= childCount ;childIndex++) { |
465 if( model ) { |
460 item->removeChild(0); |
466 model->d_func()->rowsAboutToBeRemoved(this, index, index); |
461 } |
467 } |
462 |
468 HbDataFormModelItem *item = d->mChildItems.takeAt(index); |
463 HbDataFormModelItem *item = d->mChildItems.takeAt(index); |
469 delete item; |
464 delete item; |
470 item = 0; |
465 item = 0; |
471 if( model ) { |
466 } |
472 model->d_func()->rowsRemoved(); |
467 |
473 } |
468 if(model) |
474 } |
469 model->d_func()->rowsRemoved(); |
|
470 |
|
471 } |
475 } |
472 |
476 |
473 /*! |
477 /*! |
474 @beta |
478 @beta |
475 |
479 |
484 return; |
488 return; |
485 } |
489 } |
486 |
490 |
487 if( startIndex + count > childCount() ) { |
491 if( startIndex + count > childCount() ) { |
488 return; |
492 return; |
489 } |
493 } |
490 |
|
491 Q_D(HbDataFormModelItem); |
|
492 |
|
493 HbDataFormModel* model = static_cast<HbDataFormModel*>(d->mModel); |
|
494 if( model ) { |
|
495 model->d_func()->rowsAboutToBeRemoved(this, startIndex, startIndex + count -1); |
|
496 } |
|
497 |
494 |
498 for(int index = 0; index < count ;index++) { |
495 for(int index = 0; index < count ;index++) { |
499 HbDataFormModelItem *item = d->mChildItems.takeAt(0); |
496 removeChild(startIndex); |
500 if ( item ) { |
497 } |
501 delete item; |
|
502 item = 0; |
|
503 } |
|
504 } |
|
505 |
|
506 if( model ) { |
|
507 model->d_func()->rowsRemoved(); |
|
508 } |
|
509 } |
498 } |
510 |
499 |
511 /*! |
500 /*! |
512 @beta |
501 @beta |
513 |
502 |
671 |
660 |
672 /*! |
661 /*! |
673 @beta |
662 @beta |
674 |
663 |
675 Sets \a parent as a parent to this item. |
664 Sets \a parent as a parent to this item. |
676 It only sets the parent pointer. It doesnt put the item in the |
665 It only sets the parent pointer. It does not put the item in the |
677 hierarchy. |
666 hierarchy. |
678 */ |
667 */ |
679 void HbDataFormModelItem::setParent(HbDataFormModelItem* parent) |
668 void HbDataFormModelItem::setParent(HbDataFormModelItem* parent) |
680 { |
669 { |
681 Q_D(HbDataFormModelItem); |
670 Q_D(HbDataFormModelItem); |