15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include <HbIcon> |
18 #include <HbIcon> |
19 |
19 |
|
20 #include "caclient_defines.h" |
20 #include "caitemmodel.h" |
21 #include "caitemmodel.h" |
21 #include "caitemmodel_p.h" |
22 #include "caitemmodel_p.h" |
22 #include "canotifier.h" |
23 #include "canotifier.h" |
23 #include "canotifierfilter.h" |
24 #include "canotifierfilter.h" |
24 #include "caclienttest_global.h" |
25 #include "caclienttest_global.h" |
467 break; |
468 break; |
468 case CaItemModel::FullTextRole: |
469 case CaItemModel::FullTextRole: |
469 variant = QVariant(entry(modelIndex)->text() + QString(" ") |
470 variant = QVariant(entry(modelIndex)->text() + QString(" ") |
470 + entry(modelIndex)->description()); |
471 + entry(modelIndex)->description()); |
471 break; |
472 break; |
|
473 case CaItemModel::UninstalRole: |
|
474 variant = QVariant(entry(modelIndex)->attribute(UNINSTALL_PROGRESS_APPLICATION_ATTRIBUTE_NAME).toInt()); |
|
475 break; |
472 default: |
476 default: |
473 variant = QVariant(QVariant::Invalid); |
477 variant = QVariant(QVariant::Invalid); |
474 } |
478 } |
475 } |
479 } |
476 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::data"); |
480 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::data"); |
697 |
701 |
698 } |
702 } |
699 |
703 |
700 /*! |
704 /*! |
701 Updates model item with fresh data |
705 Updates model item with fresh data |
702 \param id id of item to update |
706 \param entry item to update |
703 */ |
707 */ |
704 void CaItemModelPrivate::updateItemData(int id) |
708 void CaItemModelPrivate::updateItemData(const QSharedPointer<CaEntry> &entry) |
705 { |
709 { |
706 CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::updateItemData"); |
710 CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::updateItemData"); |
707 |
711 |
708 mEntries.updateEntry(id); |
712 |
709 |
713 int id = entry->id(); |
710 QList<int> ids = mService->getEntryIds(mQuery); |
714 QList<int> ids = mService->getEntryIds(mQuery); |
711 if (mEntries.indexOf(id) >= 0 |
715 if (mEntries.indexOf(id) >= 0 |
712 && ids.indexOf(id) == mEntries.indexOf(id)) { |
716 && ids.indexOf(id) == mEntries.indexOf(id)) { |
713 emit m_q->dataChanged(index(mEntries.indexOf(id)), index( |
717 mEntries.updateEntry(entry); |
714 mEntries.indexOf(id))); |
718 emit m_q->dataChanged( |
715 } else if (ids.indexOf(id) < 0){ |
719 index(mEntries.indexOf(id)), index(mEntries.indexOf(id))); |
716 removeItem(id); |
|
717 } else if (mEntries.indexOf(id) < 0){ |
|
718 addItem(id); |
|
719 } else if (mParentEntry && id == mParentEntry->id()) { |
720 } else if (mParentEntry && id == mParentEntry->id()) { |
720 updateParentEntry(); |
721 updateParentEntry(); |
721 m_q->reset(); |
722 m_q->reset(); |
|
723 } else if (ids.indexOf(id) < 0) { |
|
724 removeItem(id); |
|
725 } else if (mEntries.indexOf(id) < 0) { |
|
726 addItem(id); |
722 } else { |
727 } else { |
723 updateModel(); |
728 updateModel(); |
724 } |
729 } |
725 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::updateItemData"); |
730 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::updateItemData"); |
726 } |
731 } |
735 |
740 |
736 int row = itemRow(id); |
741 int row = itemRow(id); |
737 //we use beginInsertRows and endInsertRows to emit proper signal |
742 //we use beginInsertRows and endInsertRows to emit proper signal |
738 //(see Qt documentation of QAbstractItemModel) |
743 //(see Qt documentation of QAbstractItemModel) |
739 if (mEntries.indexOf(id) < 0 && row >= 0) { |
744 if (mEntries.indexOf(id) < 0 && row >= 0) { |
740 m_q->beginInsertRows(QModelIndex(), row, row); |
745 if (row > mEntries.count()) { |
741 mEntries.insert(row, id); |
746 m_q->beginInsertRows(QModelIndex(), mEntries.count(), mEntries.count()); |
|
747 mEntries.insert(mEntries.count(), id); |
|
748 } else { |
|
749 m_q->beginInsertRows(QModelIndex(), row , row); |
|
750 mEntries.insert(row, id); |
|
751 } |
742 m_q->endInsertRows(); |
752 m_q->endInsertRows(); |
|
753 } else if (row == -1) { |
|
754 //we udpade whole model because we do not know parent collecion for given item |
|
755 updateModel(); |
743 } |
756 } |
744 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::addItem"); |
757 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::addItem"); |
745 } |
758 } |
746 |
759 |
747 /*! |
760 /*! |
905 Connects slots |
918 Connects slots |
906 */ |
919 */ |
907 void CaItemModelPrivate::connectSlots() |
920 void CaItemModelPrivate::connectSlots() |
908 { |
921 { |
909 CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::connectSlots"); |
922 CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::connectSlots"); |
910 connect(mNotifier, SIGNAL(entryChanged(int,ChangeType)), |
923 connect(mNotifier, SIGNAL(entryChanged(CaEntry ,ChangeType)), |
911 this, SLOT(updateModelItem(int,ChangeType))); |
924 this, SLOT(updateModelItem(CaEntry, ChangeType))); |
912 |
925 |
913 if (mQuery.parentId() > 0) { |
926 if (mQuery.parentId() > 0) { |
914 connect(mNotifier, SIGNAL(groupContentChanged(int)), |
927 connect(mNotifier, SIGNAL(groupContentChanged(int)), |
915 this, SLOT(updateModelContent(int))); |
928 this, SLOT(updateModelContent(int))); |
916 } |
929 } |
921 Disconnects slots |
934 Disconnects slots |
922 */ |
935 */ |
923 void CaItemModelPrivate::disconnectSlots() |
936 void CaItemModelPrivate::disconnectSlots() |
924 { |
937 { |
925 CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::disconnectSlots"); |
938 CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::disconnectSlots"); |
926 disconnect(mNotifier, SIGNAL(entryChanged(int,ChangeType)), |
939 disconnect(mNotifier, SIGNAL(entryChanged(CaEntry ,ChangeType)), |
927 this, SLOT(updateModelItem(int,ChangeType))); |
940 this, SLOT(updateModelItem(CaEntry, ChangeType))); |
928 if (mQuery.parentId() > 0) { |
941 if (mQuery.parentId() > 0) { |
929 disconnect(mNotifier, SIGNAL(groupContentChanged(int)), |
942 disconnect(mNotifier, SIGNAL(groupContentChanged(int)), |
930 this, SLOT(updateModelContent(int))); |
943 this, SLOT(updateModelContent(int))); |
931 } |
944 } |
932 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::disconnectSlots"); |
945 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::disconnectSlots"); |
946 /*! |
959 /*! |
947 Updates model with fresh entries |
960 Updates model with fresh entries |
948 \param id of item to handle |
961 \param id of item to handle |
949 \param changeType change type |
962 \param changeType change type |
950 */ |
963 */ |
951 void CaItemModelPrivate::updateModelItem(int id, ChangeType changeType) |
964 void CaItemModelPrivate::updateModelItem( |
|
965 const CaEntry &entry, ChangeType changeType) |
952 { |
966 { |
953 CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::updateModelItem"); |
967 CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::updateModelItem"); |
|
968 QSharedPointer<CaEntry> sharedEntry(new CaEntry(entry)); |
|
969 int previousCount = rowCount(); |
954 switch (changeType) { |
970 switch (changeType) { |
955 case AddChangeType: |
971 case AddChangeType: |
956 addItem(id); |
972 addItem(sharedEntry->id()); |
957 break; |
973 break; |
958 case RemoveChangeType: |
974 case RemoveChangeType: |
959 removeItem(id); |
975 removeItem(sharedEntry->id()); |
960 break; |
976 break; |
961 default: |
977 default: |
962 updateItemData(id); |
978 updateItemData(sharedEntry); |
963 break; |
979 break; |
964 } |
980 } |
|
981 emitEmpty(previousCount); |
965 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::updateModelItem"); |
982 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::updateModelItem"); |
966 } |
983 } |
967 |
984 |
968 /*! |
985 /*! |
969 Updates model with fresh entries |
986 Updates model with fresh entries |
970 \param id of parent |
987 \param id of parent |
971 */ |
988 */ |
972 void CaItemModelPrivate::updateModelContent(int id) |
989 void CaItemModelPrivate::updateModelContent(int id) |
973 { |
990 { |
974 Q_UNUSED(id); |
991 Q_UNUSED(id); |
|
992 int previousCount = rowCount(); |
|
993 |
975 CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::updateModelContent"); |
994 CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::updateModelContent"); |
976 QList<int> ids = mService->getEntryIds(mQuery); |
995 QList<int> ids = mService->getEntryIds(mQuery); |
977 |
996 |
978 if (ids.count() >= mEntries.count()) { |
997 if (ids.count() >= mEntries.count()) { |
979 handleAddItems(ids); |
998 handleAddItems(ids); |
980 } else { |
999 } else { |
981 removeItems(ids); |
1000 removeItems(ids); |
982 } |
1001 } |
|
1002 emitEmpty(previousCount); |
983 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::updateModelContent"); |
1003 CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::updateModelContent"); |
984 } |
1004 } |
|
1005 |
|
1006 /*! |
|
1007 Emits empty signal if model state was changed |
|
1008 \param id of parent |
|
1009 */ |
|
1010 void CaItemModelPrivate::emitEmpty(int previousCount) |
|
1011 { |
|
1012 if ( previousCount && !rowCount()) { |
|
1013 emit m_q->empty(true); |
|
1014 } |
|
1015 if ( !previousCount && rowCount()) { |
|
1016 emit m_q->empty(false); |
|
1017 } |
|
1018 } |