85
|
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"
|
87
|
24 |
#include "caclienttest_global.h"
|
85
|
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 |
{
|
87
|
50 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelList::clear");
|
85
|
51 |
mOrderedList.clear();
|
|
52 |
mEntriesHash.clear();
|
87
|
53 |
CACLIENTTEST_FUNC_EXIT("CaItemModelList::clear");
|
85
|
54 |
}
|
|
55 |
|
|
56 |
/*!
|
|
57 |
List count
|
|
58 |
\retval list count
|
|
59 |
*/
|
|
60 |
int CaItemModelList::count() const
|
|
61 |
{
|
|
62 |
return mOrderedList.count();
|
|
63 |
}
|
|
64 |
|
|
65 |
/*!
|
|
66 |
Returns entry at aRow
|
|
67 |
\param row of model list
|
|
68 |
\retval entry at row
|
|
69 |
*/
|
92
|
70 |
QSharedPointer<CaEntry> CaItemModelList::at(int row) const
|
85
|
71 |
{
|
|
72 |
int id = mOrderedList[row];
|
|
73 |
return mEntriesHash.value(id);
|
|
74 |
}
|
|
75 |
|
|
76 |
/*!
|
|
77 |
Reloads entries
|
|
78 |
\param query needed to reload model list
|
|
79 |
*/
|
|
80 |
void CaItemModelList::reloadEntries(const CaQuery &query)
|
|
81 |
{
|
87
|
82 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelList::reloadEntries");
|
85
|
83 |
clear();
|
86
|
84 |
int id=0;
|
92
|
85 |
QList< QSharedPointer<CaEntry> > eList = mService->getEntries(query);
|
86
|
86 |
for (int i = 0; i < eList.count(); i++) {
|
|
87 |
id = eList[i]->id();
|
|
88 |
mOrderedList << id;
|
|
89 |
mEntriesHash.insert(id, eList[i]);
|
85
|
90 |
}
|
87
|
91 |
CACLIENTTEST_FUNC_EXIT("CaItemModelList::reloadEntries");
|
85
|
92 |
}
|
|
93 |
|
|
94 |
/*!
|
|
95 |
Updates entry with given id
|
|
96 |
\param id of item in the list
|
|
97 |
*/
|
|
98 |
void CaItemModelList::updateEntry(int id)
|
|
99 |
{
|
87
|
100 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelList::updateEntry");
|
85
|
101 |
if (mEntriesHash.contains(id)) {
|
|
102 |
mEntriesHash.insert(id, mService->getEntry(id));
|
|
103 |
}
|
87
|
104 |
CACLIENTTEST_FUNC_EXIT("CaItemModelList::updateEntry");
|
85
|
105 |
}
|
|
106 |
|
|
107 |
/*!
|
|
108 |
Updates entries
|
|
109 |
\param query with sort order
|
|
110 |
*/
|
|
111 |
void CaItemModelList::updateEntries(const CaQuery &query)
|
|
112 |
{
|
87
|
113 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelList::updateEntries");
|
85
|
114 |
mOrderedList = mService->getEntryIds(query);
|
|
115 |
for (int i = 0; i < mOrderedList.count(); i++) {
|
|
116 |
if (!mEntriesHash.contains(mOrderedList[i])) {
|
|
117 |
mEntriesHash.insert(mOrderedList[i], mService->getEntry(
|
87
|
118 |
mOrderedList[i]));
|
85
|
119 |
}
|
|
120 |
}
|
87
|
121 |
CACLIENTTEST_FUNC_EXIT("CaItemModelList::updateEntries");
|
85
|
122 |
}
|
|
123 |
|
|
124 |
/*!
|
|
125 |
Returns index with given id value
|
|
126 |
\param id item id
|
|
127 |
\retval index of item with given aId
|
|
128 |
*/
|
|
129 |
int CaItemModelList::indexOf(const int &id) const
|
|
130 |
{
|
|
131 |
return mOrderedList.indexOf(id);
|
|
132 |
}
|
|
133 |
|
|
134 |
/*!
|
|
135 |
Inserts item with given id at row
|
|
136 |
(entry for given id is created and inserted in list)
|
|
137 |
\param row at which item is to be inserted
|
|
138 |
\param id of item to be inserted
|
|
139 |
*/
|
|
140 |
void CaItemModelList::insert(int row, int id)
|
|
141 |
{
|
87
|
142 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelList::insert");
|
85
|
143 |
mOrderedList.insert(row, id);
|
|
144 |
mEntriesHash.insert(id, mService->getEntry(id));
|
87
|
145 |
CACLIENTTEST_FUNC_EXIT("CaItemModelList::insert");
|
85
|
146 |
}
|
|
147 |
|
|
148 |
/*!
|
|
149 |
Removes item with given id
|
|
150 |
\param id of item to remove
|
|
151 |
*/
|
|
152 |
void CaItemModelList::remove(int id)
|
|
153 |
{
|
87
|
154 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelList::remove");
|
85
|
155 |
if (mEntriesHash.contains(id)) {
|
92
|
156 |
mEntriesHash.remove(id);
|
85
|
157 |
}
|
|
158 |
mOrderedList.removeOne(id);
|
87
|
159 |
CACLIENTTEST_FUNC_EXIT("CaItemModelList::remove");
|
85
|
160 |
}
|
|
161 |
|
|
162 |
/*!
|
|
163 |
Returns the item id at row position - aRow
|
|
164 |
\param row item row
|
|
165 |
\retval id of item at given row
|
|
166 |
*/
|
|
167 |
const int &CaItemModelList::operator[](int row) const
|
|
168 |
{
|
|
169 |
return mOrderedList[row];
|
|
170 |
}
|
89
|
171 |
|
|
172 |
/*!
|
|
173 |
Returns on ordered list of entry IDs
|
|
174 |
\retval Copy of the internal ID list
|
|
175 |
*/
|
|
176 |
QList<int> CaItemModelList::orderedIdList()
|
|
177 |
{
|
|
178 |
return mOrderedList;
|
|
179 |
}
|