444 QVariant CaItemModelPrivate::data(const QModelIndex &modelIndex, |
444 QVariant CaItemModelPrivate::data(const QModelIndex &modelIndex, |
445 int role) const |
445 int role) const |
446 { |
446 { |
447 CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::data"); |
447 CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::data"); |
448 QVariant variant; |
448 QVariant variant; |
449 if (modelIndex.isValid()) { |
449 QSharedPointer<CaEntry> pEntry = entry(modelIndex); |
|
450 if (!pEntry.isNull()) { |
450 switch (role) { |
451 switch (role) { |
451 case Qt::DisplayRole: |
452 case Qt::DisplayRole: |
452 variant = displayRole(modelIndex); |
453 variant = displayRole(pEntry.data()); |
453 break; |
454 break; |
454 case Qt::DecorationRole: |
455 case Qt::DecorationRole: |
455 variant = QVariant(HbIcon(entry(modelIndex)->makeIcon(mSize))); |
456 variant = QVariant(HbIcon(pEntry->makeIcon(mSize))); |
456 break; |
457 break; |
457 case CaItemModel::IdRole: |
458 case CaItemModel::IdRole: |
458 variant = QVariant(entry(modelIndex)->id()); |
459 variant = QVariant(pEntry->id()); |
459 break; |
460 break; |
460 case CaItemModel::TypeRole: |
461 case CaItemModel::TypeRole: |
461 variant = QVariant(entry(modelIndex)->entryTypeName()); |
462 variant = QVariant(pEntry->entryTypeName()); |
462 break; |
463 break; |
463 case CaItemModel::FlagsRole: |
464 case CaItemModel::FlagsRole: |
464 variant = qVariantFromValue(entry(modelIndex)->flags()); |
465 variant = qVariantFromValue(pEntry->flags()); |
465 break; |
466 break; |
466 case CaItemModel::TextRole: |
467 case CaItemModel::TextRole: |
467 variant = QVariant(entry(modelIndex)->text()); |
468 variant = QVariant(pEntry->text()); |
468 break; |
469 break; |
469 case CaItemModel::FullTextRole: |
470 case CaItemModel::FullTextRole: |
470 variant = QVariant(entry(modelIndex)->text() + QString(" ") |
471 variant = QVariant(pEntry->text() + QString(" ") + pEntry->description()); |
471 + entry(modelIndex)->description()); |
|
472 break; |
472 break; |
473 case CaItemModel::UninstalRole: |
473 case CaItemModel::UninstalRole: |
474 variant = QVariant(entry(modelIndex)->attribute(UNINSTALL_PROGRESS_APPLICATION_ATTRIBUTE_NAME).toInt()); |
474 variant = QVariant( |
475 break; |
475 pEntry->attribute(UNINSTALL_PROGRESS_APPLICATION_ATTRIBUTE_NAME).toInt()); |
|
476 break; |
|
477 case CaItemModel::CollectionTitleRole: |
|
478 if (!pEntry->attribute(COLLECTION_TITLE_NAME).isNull()) { |
|
479 variant = QVariant(hbTrId(pEntry-> |
|
480 attribute(COLLECTION_TITLE_NAME).toUtf8())); |
|
481 } |
|
482 else { |
|
483 variant = QVariant(pEntry->text()); |
|
484 } |
|
485 break; |
|
486 |
476 default: |
487 default: |
477 variant = QVariant(QVariant::Invalid); |
488 variant = QVariant(QVariant::Invalid); |
478 } |
489 } |
479 } |
490 } |
480 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::data"); |
491 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::data"); |
557 \param modelIndex index of entry in model |
568 \param modelIndex index of entry in model |
558 \retval pointer to an entry |
569 \retval pointer to an entry |
559 */ |
570 */ |
560 QSharedPointer<CaEntry> CaItemModelPrivate::entry(const QModelIndex &modelIndex) const |
571 QSharedPointer<CaEntry> CaItemModelPrivate::entry(const QModelIndex &modelIndex) const |
561 { |
572 { |
562 if (modelIndex.column() == 1) { |
573 if (modelIndex.isValid()) { |
563 return mParentEntry; |
574 if (modelIndex.column() == 1) { |
564 } else { |
575 return mParentEntry; |
565 return mEntries.at(modelIndex.row()); |
576 } |
566 } |
577 else { |
|
578 int row = modelIndex.row(); |
|
579 if (row >= mEntries.count()) { |
|
580 return QSharedPointer<CaEntry> (); |
|
581 } |
|
582 else { |
|
583 return mEntries.at(row); |
|
584 } |
|
585 } |
|
586 } |
|
587 return QSharedPointer<CaEntry> (); |
567 } |
588 } |
568 |
589 |
569 /*! |
590 /*! |
570 Disables or enables secondline feature of the model |
591 Disables or enables secondline feature of the model |
571 \param secondLine disables or enables second line |
592 \param secondLine disables or enables second line |
591 /*! |
612 /*! |
592 Returns proper display role for item |
613 Returns proper display role for item |
593 \param modelIndex item index |
614 \param modelIndex item index |
594 \retval QVariant containing display role |
615 \retval QVariant containing display role |
595 */ |
616 */ |
596 QVariant CaItemModelPrivate::displayRole(const QModelIndex &modelIndex) const |
617 QVariant CaItemModelPrivate::displayRole(const CaEntry* entry) const |
597 { |
618 { |
598 CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::displayRole") |
619 CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::displayRole") |
599 |
620 |
600 QVariant result; |
621 QVariant result; |
601 if (mSecondLineVisibility) { |
622 if (mSecondLineVisibility) { |
602 if (entry(modelIndex)->description().isEmpty()) { |
623 if (entry->description().isEmpty()) { |
603 result = entry(modelIndex)->text(); |
624 result = entry->text(); |
604 } else { |
625 } else { |
605 QList<QVariant> text; |
626 QList<QVariant> text; |
606 text << entry(modelIndex)->text(); |
627 text << entry->text(); |
607 text << entry(modelIndex)->description(); |
628 text << entry->description(); |
608 result = QVariant(text); |
629 result = QVariant(text); |
609 } |
630 } |
610 } else { |
631 } else { |
611 result = entry(modelIndex)->text(); |
632 result = entry->text(); |
612 } |
633 } |
613 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::displayRole") |
634 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::displayRole") |
614 return result; |
635 return result; |
615 } |
636 } |
616 |
637 |
786 { |
807 { |
787 CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::handleAddItems"); |
808 CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::handleAddItems"); |
788 const int oldItemCount(mEntries.count()); |
809 const int oldItemCount(mEntries.count()); |
789 if (oldItemCount) { |
810 if (oldItemCount) { |
790 const int newItemCount(itemsList.count()); |
811 const int newItemCount(itemsList.count()); |
|
812 int i = 0; |
|
813 QList<int> oldList = mEntries.orderedIdList(); |
|
814 //we loop through items to find first added |
|
815 while (i < oldList.count()) { |
|
816 if (oldList[i] != itemsList[i]) { |
|
817 oldList.takeAt(i); |
|
818 } else { |
|
819 ++i; |
|
820 } |
|
821 } |
791 if (newItemCount == oldItemCount) { |
822 if (newItemCount == oldItemCount) { |
792 // count is the same - check if item order changed |
823 // count is the same - check if item order changed |
793 if (itemsList == mEntries.orderedIdList()) { |
824 if (itemsList == oldList) { |
794 // assume that if the order has not changed |
825 // assume that if the order has not changed |
795 // it had to be the secondary lines |
826 // it had to be the secondary lines |
796 updateModel(); |
827 updateModel(); |
797 } else { |
828 } else { |
798 updateLayout(); |
829 updateLayout(); |
799 } |
830 } |
800 } else { |
831 } else { |
801 int i = 0; |
|
802 QList<int> oldList = mEntries.orderedIdList(); |
|
803 //we loop through items to find first added |
|
804 while (i < oldList.count()) { |
|
805 if (oldList[i] != itemsList[i]) { |
|
806 oldList.takeAt(i); |
|
807 } else { |
|
808 ++i; |
|
809 } |
|
810 } |
|
811 updateModel(); |
832 updateModel(); |
812 //i is the index of first added item |
833 //i is the index of first added item |
813 emit m_q->scrollTo(i, QAbstractItemView::PositionAtTop); |
|
814 } |
834 } |
|
835 emit m_q->scrollTo(i, QAbstractItemView::PositionAtTop); |
815 } else { |
836 } else { |
816 // items added to an empty list - add all as a single block |
837 // items added to an empty list - add all as a single block |
817 addItemBlock(itemsList); |
838 addItemBlock(itemsList); |
818 } |
839 } |
819 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::handleAddItems"); |
840 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::handleAddItems"); |