|
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: caitemmodel_p.cpp |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QIcon> |
|
19 |
|
20 #include "caitemmodellist.h" |
|
21 #include "caitemmodel_p.h" |
|
22 #include "canotifier.h" |
|
23 #include "canotifierfilter.h" |
|
24 #include "caclienttest_global.h" |
|
25 |
|
26 // ======== MEMBER FUNCTIONS ======== |
|
27 |
|
28 /*! |
|
29 Constructor |
|
30 \param aService content arsenall service provider |
|
31 */ |
|
32 CaItemModelList::CaItemModelList(QSharedPointer<CaService> service) : |
|
33 mOrderedList(), mEntriesHash(), mService(service) |
|
34 { |
|
35 } |
|
36 |
|
37 /*! |
|
38 Destructor |
|
39 */ |
|
40 CaItemModelList::~CaItemModelList() |
|
41 { |
|
42 clear(); |
|
43 } |
|
44 |
|
45 /*! |
|
46 Clears list |
|
47 */ |
|
48 void CaItemModelList::clear() |
|
49 { |
|
50 CACLIENTTEST_FUNC_ENTRY("CaItemModelList::clear"); |
|
51 mOrderedList.clear(); |
|
52 qDeleteAll(mEntriesHash); |
|
53 mEntriesHash.clear(); |
|
54 CACLIENTTEST_FUNC_EXIT("CaItemModelList::clear"); |
|
55 } |
|
56 |
|
57 /*! |
|
58 List count |
|
59 \retval list count |
|
60 */ |
|
61 int CaItemModelList::count() const |
|
62 { |
|
63 return mOrderedList.count(); |
|
64 } |
|
65 |
|
66 /*! |
|
67 Returns entry at aRow |
|
68 \param row of model list |
|
69 \retval entry at row |
|
70 */ |
|
71 CaEntry *CaItemModelList::at(int row) const |
|
72 { |
|
73 int id = mOrderedList[row]; |
|
74 return mEntriesHash.value(id); |
|
75 } |
|
76 |
|
77 /*! |
|
78 Reloads entries |
|
79 \param query needed to reload model list |
|
80 */ |
|
81 void CaItemModelList::reloadEntries(const CaQuery &query) |
|
82 { |
|
83 CACLIENTTEST_FUNC_ENTRY("CaItemModelList::reloadEntries"); |
|
84 clear(); |
|
85 int id=0; |
|
86 QList<CaEntry *> eList = mService->getEntries(query); |
|
87 for (int i = 0; i < eList.count(); i++) { |
|
88 id = eList[i]->id(); |
|
89 mOrderedList << id; |
|
90 mEntriesHash.insert(id, eList[i]); |
|
91 } |
|
92 CACLIENTTEST_FUNC_EXIT("CaItemModelList::reloadEntries"); |
|
93 } |
|
94 |
|
95 /*! |
|
96 Updates entry with given id |
|
97 \param id of item in the list |
|
98 */ |
|
99 void CaItemModelList::updateEntry(int id) |
|
100 { |
|
101 CACLIENTTEST_FUNC_ENTRY("CaItemModelList::updateEntry"); |
|
102 if (mEntriesHash.contains(id)) { |
|
103 delete mEntriesHash.take(id); |
|
104 mEntriesHash.insert(id, mService->getEntry(id)); |
|
105 } |
|
106 CACLIENTTEST_FUNC_EXIT("CaItemModelList::updateEntry"); |
|
107 } |
|
108 |
|
109 /*! |
|
110 Updates entries |
|
111 \param query with sort order |
|
112 */ |
|
113 void CaItemModelList::updateEntries(const CaQuery &query) |
|
114 { |
|
115 CACLIENTTEST_FUNC_ENTRY("CaItemModelList::updateEntries"); |
|
116 mOrderedList = mService->getEntryIds(query); |
|
117 for (int i = 0; i < mOrderedList.count(); i++) { |
|
118 if (!mEntriesHash.contains(mOrderedList[i])) { |
|
119 mEntriesHash.insert(mOrderedList[i], mService->getEntry( |
|
120 mOrderedList[i])); |
|
121 } |
|
122 } |
|
123 CACLIENTTEST_FUNC_EXIT("CaItemModelList::updateEntries"); |
|
124 } |
|
125 |
|
126 /*! |
|
127 Returns index with given id value |
|
128 \param id item id |
|
129 \retval index of item with given aId |
|
130 */ |
|
131 int CaItemModelList::indexOf(const int &id) const |
|
132 { |
|
133 return mOrderedList.indexOf(id); |
|
134 } |
|
135 |
|
136 /*! |
|
137 Inserts item with given id at row |
|
138 (entry for given id is created and inserted in list) |
|
139 \param row at which item is to be inserted |
|
140 \param id of item to be inserted |
|
141 */ |
|
142 void CaItemModelList::insert(int row, int id) |
|
143 { |
|
144 CACLIENTTEST_FUNC_ENTRY("CaItemModelList::insert"); |
|
145 mOrderedList.insert(row, id); |
|
146 mEntriesHash.insert(id, mService->getEntry(id)); |
|
147 CACLIENTTEST_FUNC_EXIT("CaItemModelList::insert"); |
|
148 } |
|
149 |
|
150 /*! |
|
151 Removes item with given id |
|
152 \param id of item to remove |
|
153 */ |
|
154 void CaItemModelList::remove(int id) |
|
155 { |
|
156 CACLIENTTEST_FUNC_ENTRY("CaItemModelList::remove"); |
|
157 if (mEntriesHash.contains(id)) { |
|
158 delete mEntriesHash.take(id); |
|
159 } |
|
160 mOrderedList.removeOne(id); |
|
161 CACLIENTTEST_FUNC_EXIT("CaItemModelList::remove"); |
|
162 } |
|
163 |
|
164 /*! |
|
165 Returns the item id at row position - aRow |
|
166 \param row item row |
|
167 \retval id of item at given row |
|
168 */ |
|
169 const int &CaItemModelList::operator[](int row) const |
|
170 { |
|
171 return mOrderedList[row]; |
|
172 } |