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.cpp
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
86
|
18 |
#include <HbIcon>
|
85
|
19 |
|
98
|
20 |
#include "caclient_defines.h"
|
85
|
21 |
#include "caitemmodel.h"
|
|
22 |
#include "caitemmodel_p.h"
|
|
23 |
#include "canotifier.h"
|
|
24 |
#include "canotifierfilter.h"
|
87
|
25 |
#include "caclienttest_global.h"
|
85
|
26 |
|
|
27 |
// Constants
|
112
|
28 |
const QSizeF defaultIconSize(30, 30);
|
85
|
29 |
|
|
30 |
// ======== MEMBER FUNCTIONS ========
|
|
31 |
|
|
32 |
/*!
|
|
33 |
* \class CaItemModel
|
|
34 |
*
|
|
35 |
* \brief This class provides model containing CaEntry class objects.
|
|
36 |
*
|
|
37 |
* To create instance of CaItemModel object, you need to pass CaQuery
|
|
38 |
* object in constructor. CaQuery should describe items that you want
|
|
39 |
* to have in a model.
|
|
40 |
*
|
|
41 |
* \example
|
|
42 |
* \code
|
|
43 |
*
|
|
44 |
* CaQuery query;
|
|
45 |
* query.setFlagsOn(VisibleEntryFlag);
|
|
46 |
* query.setParentId(collectionId);
|
|
47 |
* CaItemModel* model = new CaItemModel(query, this);
|
|
48 |
*
|
|
49 |
* \endcode
|
|
50 |
*/
|
|
51 |
|
|
52 |
/*!
|
|
53 |
Constructor.
|
|
54 |
\param query query describing entries that should be present in a model.
|
|
55 |
\param parent parent of a model
|
|
56 |
*/
|
87
|
57 |
CaItemModel::CaItemModel(const CaQuery &query, QObject *parent) :
|
85
|
58 |
QAbstractItemModel(parent), m_d(new CaItemModelPrivate(query, this))
|
|
59 |
{
|
|
60 |
|
|
61 |
}
|
|
62 |
|
|
63 |
/*!
|
|
64 |
Destructor
|
|
65 |
*/
|
|
66 |
CaItemModel::~CaItemModel()
|
|
67 |
{
|
|
68 |
delete m_d;
|
|
69 |
}
|
|
70 |
|
|
71 |
/*!
|
|
72 |
Returns number of columns
|
|
73 |
\param parent not used
|
|
74 |
\retval 1
|
|
75 |
|
|
76 |
\code
|
|
77 |
...
|
|
78 |
// to get number of columns in a model
|
|
79 |
int columns = model->columnCount();
|
|
80 |
...
|
|
81 |
\endcode
|
|
82 |
|
|
83 |
*/
|
|
84 |
int CaItemModel::columnCount(const QModelIndex &parent) const
|
|
85 |
{
|
|
86 |
Q_UNUSED(parent);
|
|
87 |
//model keeps entries in a column 0 and a parent entry in a column 1
|
|
88 |
//parent entry is treated as an invisible root item,
|
|
89 |
//so column count is always 1
|
|
90 |
return 1;
|
|
91 |
}
|
|
92 |
|
|
93 |
/*!
|
|
94 |
Returns number of rows
|
|
95 |
\param parent not used
|
|
96 |
\retval number of rows
|
|
97 |
|
|
98 |
\code
|
|
99 |
...
|
|
100 |
// to get number of rows in a model
|
|
101 |
int rows = model->rowCount();
|
|
102 |
...
|
|
103 |
\endcode
|
|
104 |
*/
|
|
105 |
int CaItemModel::rowCount(const QModelIndex &parent) const
|
|
106 |
{
|
|
107 |
Q_UNUSED(parent);
|
|
108 |
return m_d->rowCount();
|
|
109 |
}
|
|
110 |
|
|
111 |
/*!
|
|
112 |
Returns QModelIndex of an item
|
|
113 |
\param row row in which an item is placed
|
|
114 |
\param column not used
|
|
115 |
\param parent not used
|
|
116 |
\retval index of item in model
|
|
117 |
|
|
118 |
\code
|
|
119 |
...
|
|
120 |
// to get model index of an item
|
|
121 |
QModelIndex modelIndex = model->index(5);
|
|
122 |
...
|
|
123 |
\endcode
|
|
124 |
|
|
125 |
*/
|
|
126 |
QModelIndex CaItemModel::index(int row, int column,
|
87
|
127 |
const QModelIndex &parent) const
|
85
|
128 |
{
|
|
129 |
Q_UNUSED(column);
|
|
130 |
Q_UNUSED(parent);
|
|
131 |
return m_d->index(row);
|
|
132 |
}
|
|
133 |
|
|
134 |
/*!
|
|
135 |
Returns parent item
|
|
136 |
\param child index (ignored)
|
|
137 |
\retval parent index. in case of CaItemModel it is always QModelIndex()
|
|
138 |
|
|
139 |
\code
|
|
140 |
...
|
|
141 |
// to get model index of a parent of an item
|
|
142 |
QModelIndex parentModelIndex = model->parent(childModelIndex);
|
|
143 |
...
|
|
144 |
\endcode
|
|
145 |
*/
|
|
146 |
QModelIndex CaItemModel::parent(const QModelIndex &index) const
|
|
147 |
{
|
|
148 |
Q_UNUSED(index);
|
|
149 |
return QModelIndex();
|
|
150 |
}
|
|
151 |
|
|
152 |
/*!
|
|
153 |
Returns root item model index
|
|
154 |
\retval root item model index
|
|
155 |
|
|
156 |
\code
|
|
157 |
...
|
|
158 |
// to get model index of a root item
|
|
159 |
QModelIndex rootIndex = model->root();
|
|
160 |
...
|
|
161 |
\endcode
|
|
162 |
*/
|
|
163 |
QModelIndex CaItemModel::root() const
|
|
164 |
{
|
|
165 |
return m_d->root();
|
|
166 |
}
|
|
167 |
|
|
168 |
/*!
|
|
169 |
Returns appropiate model's data
|
|
170 |
\param index model index
|
|
171 |
\param role which data role to return
|
|
172 |
\retval models data
|
|
173 |
|
|
174 |
\code
|
|
175 |
...
|
|
176 |
// to get data for model item
|
|
177 |
QVariant = model->data(itemModelIndex, Qt::DisplayRole);
|
|
178 |
...
|
|
179 |
\endcode
|
|
180 |
|
|
181 |
*/
|
|
182 |
QVariant CaItemModel::data(const QModelIndex &index, int role) const
|
|
183 |
{
|
|
184 |
return m_d->data(index, role);
|
|
185 |
}
|
|
186 |
|
|
187 |
/*!
|
|
188 |
Disables or enables auto-update feature of the model
|
|
189 |
\param autoUpdate true to enable autoupdate, false to disable
|
|
190 |
|
|
191 |
\code
|
|
192 |
...
|
|
193 |
// to enable model auto update
|
|
194 |
model->setAutoUpdate(true);
|
|
195 |
...
|
|
196 |
\endcode
|
|
197 |
|
|
198 |
*/
|
|
199 |
void CaItemModel::setAutoUpdate(bool autoUpdate)
|
|
200 |
{
|
|
201 |
m_d->setAutoUpdate(autoUpdate);
|
|
202 |
}
|
|
203 |
|
|
204 |
/*!
|
|
205 |
Disables or enables secondline feature of the model
|
|
206 |
\param secondLine enable or disable second line
|
|
207 |
|
|
208 |
\code
|
|
209 |
...
|
|
210 |
// to enable model second line visibility
|
|
211 |
model->setSecondLineVisibility(true);
|
|
212 |
...
|
|
213 |
\endcode
|
|
214 |
|
|
215 |
*/
|
|
216 |
void CaItemModel::setSecondLineVisibility(bool secondLineVisible)
|
|
217 |
{
|
|
218 |
m_d->setSecondLineVisibility(secondLineVisible);
|
|
219 |
}
|
|
220 |
|
|
221 |
/*!
|
|
222 |
Gets second line visibility attribute
|
|
223 |
\retrun second line visibility attribute
|
|
224 |
|
|
225 |
\code
|
|
226 |
...
|
|
227 |
// to check second line visibility attribute
|
|
228 |
bool visibility = model->secondLineVisibility();
|
|
229 |
...
|
|
230 |
\endcode
|
|
231 |
|
|
232 |
*/
|
|
233 |
bool CaItemModel::secondLineVisibility() const
|
|
234 |
{
|
|
235 |
return m_d->secondLineVisibility();
|
|
236 |
}
|
|
237 |
/*!
|
|
238 |
Returns auto update status
|
|
239 |
\retval true if autoupdate is on, false if not
|
|
240 |
|
|
241 |
\code
|
|
242 |
...
|
|
243 |
// to check auto update attribute
|
|
244 |
bool autoUpdate = model->isAutoUpdate();
|
|
245 |
...
|
|
246 |
\endcode
|
|
247 |
|
|
248 |
*/
|
|
249 |
bool CaItemModel::isAutoUpdate() const
|
|
250 |
{
|
|
251 |
return m_d->notifierExists();
|
|
252 |
}
|
|
253 |
|
|
254 |
/*!
|
|
255 |
Method for setting sorting order on model
|
|
256 |
\param sortAttribute sort attribute (by name, timestamp, ect...)
|
|
257 |
\param sortOrder sort order (ascending, descending)
|
|
258 |
|
|
259 |
\code
|
|
260 |
...
|
|
261 |
// to set sort order in a model
|
|
262 |
model->setSort(NameSortAttribute, Qt::Ascending);
|
|
263 |
...
|
|
264 |
\endcode
|
|
265 |
|
|
266 |
*/
|
|
267 |
void CaItemModel::setSort(SortAttribute sortAttribute,
|
87
|
268 |
Qt::SortOrder sortOrder)
|
85
|
269 |
{
|
|
270 |
m_d->setSort(sortAttribute, sortOrder);
|
|
271 |
}
|
|
272 |
|
|
273 |
/*!
|
|
274 |
Method for setting icon size
|
|
275 |
\param size icon size to display
|
|
276 |
|
|
277 |
\code
|
|
278 |
...
|
|
279 |
// to set an icon size in a model
|
|
280 |
QSize iconSize(50,50);
|
|
281 |
model->setIconSize(iconSize);
|
|
282 |
...
|
|
283 |
\endcode
|
|
284 |
|
|
285 |
*/
|
112
|
286 |
void CaItemModel::setIconSize(const QSizeF &size)
|
85
|
287 |
{
|
|
288 |
m_d->setIconSize(size);
|
|
289 |
}
|
|
290 |
|
|
291 |
/*!
|
|
292 |
Method for getting icon size
|
|
293 |
\param size icon size to display
|
|
294 |
*/
|
112
|
295 |
QSizeF CaItemModel::getIconSize() const
|
85
|
296 |
{
|
|
297 |
return m_d->getIconSize();
|
|
298 |
}
|
|
299 |
|
|
300 |
/*!
|
|
301 |
Updates model with fresh entries
|
|
302 |
|
|
303 |
\code
|
|
304 |
...
|
|
305 |
// to refresh a model
|
|
306 |
model->updateModel();
|
|
307 |
...
|
|
308 |
\endcode
|
|
309 |
|
|
310 |
*/
|
|
311 |
void CaItemModel::updateModel()
|
|
312 |
{
|
|
313 |
m_d->updateModel();
|
|
314 |
}
|
|
315 |
|
|
316 |
/*!
|
|
317 |
Sets parent and fetch children items from a storage
|
|
318 |
\param parentId id of a collection
|
|
319 |
|
|
320 |
\code
|
|
321 |
...
|
|
322 |
// to set a new parent id
|
|
323 |
int newParentId = 10;
|
|
324 |
model->setParentId(newParentId);
|
|
325 |
...
|
|
326 |
\endcode
|
|
327 |
|
|
328 |
*/
|
|
329 |
void CaItemModel::setParentId(int parentId)
|
|
330 |
{
|
|
331 |
m_d->setParentId(parentId);
|
|
332 |
}
|
|
333 |
|
|
334 |
/*!
|
87
|
335 |
Sets flags to mQuery which should be enabled.
|
|
336 |
This method does not update current model - only mQuery member.
|
|
337 |
Now to do this setParentId have to be invoke.
|
|
338 |
\param onFlags flags.
|
|
339 |
|
|
340 |
\code
|
|
341 |
...
|
|
342 |
// to set a flags enabled
|
|
343 |
model->setFlagsOn(RemovableEntryFlag);
|
|
344 |
...
|
|
345 |
\endcode
|
|
346 |
|
|
347 |
*/
|
|
348 |
void CaItemModel::setFlagsOn(const EntryFlags &onFlags)
|
|
349 |
{
|
|
350 |
m_d->setFlagsOn(onFlags);
|
|
351 |
}
|
|
352 |
|
|
353 |
/*!
|
|
354 |
Sets flags to mQuery which should be disabled.
|
|
355 |
This method does not update current model - only mQuery member.
|
|
356 |
Now to do this setParentId have to be invoke.
|
|
357 |
\param offFlags flags.
|
|
358 |
|
|
359 |
\code
|
|
360 |
...
|
|
361 |
// to set a flags disabled
|
|
362 |
model->setFlagsOff(RemovableEntryFlag);
|
|
363 |
...
|
|
364 |
\endcode
|
|
365 |
|
|
366 |
*/
|
|
367 |
void CaItemModel::setFlagsOff(const EntryFlags &offFlags)
|
|
368 |
{
|
|
369 |
m_d->setFlagsOff(offFlags);
|
|
370 |
}
|
|
371 |
|
|
372 |
/*!
|
85
|
373 |
Returns an entry from model
|
|
374 |
\param index of entry in model
|
|
375 |
\retval pointer to an entry
|
|
376 |
|
|
377 |
\code
|
|
378 |
...
|
|
379 |
// to get an entry from a model
|
|
380 |
CaEntry* entry = model->entry(entryModelIndex);
|
|
381 |
...
|
|
382 |
delete entry;
|
|
383 |
\endcode
|
|
384 |
|
|
385 |
*/
|
92
|
386 |
QSharedPointer<CaEntry> CaItemModel::entry(const QModelIndex &index) const
|
85
|
387 |
{
|
|
388 |
return m_d->entry(index);
|
|
389 |
}
|
|
390 |
|
107
|
391 |
QList<int> CaItemModel::getUninstallingEntriesIds(int componentId)
|
|
392 |
{
|
|
393 |
return m_d->getUninstallingEntriesIds(componentId);
|
|
394 |
}
|
|
395 |
|
|
396 |
void CaItemModel::updateProgress(int id, int valueOfProgress)
|
|
397 |
{
|
|
398 |
m_d->updateProgress(id, valueOfProgress);
|
|
399 |
}
|
|
400 |
|
85
|
401 |
/*!
|
|
402 |
Constructor
|
|
403 |
\param query needed to create model
|
|
404 |
\param pointer to public implementation object connected
|
|
405 |
*/
|
|
406 |
CaItemModelPrivate::CaItemModelPrivate(const CaQuery &query,
|
87
|
407 |
CaItemModel *itemModelPublic) :
|
92
|
408 |
QObject(), m_q(itemModelPublic), mParentEntry(), mQuery(query),
|
85
|
409 |
mService(CaService::instance()), mEntries(mService), mNotifier(NULL),
|
|
410 |
mSize(defaultIconSize), mSecondLineVisibility(true)
|
|
411 |
{
|
|
412 |
updateModel();
|
|
413 |
setAutoUpdate(true);
|
|
414 |
}
|
|
415 |
|
|
416 |
/*!
|
|
417 |
Destructor
|
|
418 |
*/
|
|
419 |
CaItemModelPrivate::~CaItemModelPrivate()
|
|
420 |
{
|
|
421 |
mEntries.clear();
|
|
422 |
delete mNotifier;
|
|
423 |
}
|
|
424 |
|
|
425 |
/*!
|
|
426 |
Returns count of rows in model
|
|
427 |
\retval number of rows
|
|
428 |
*/
|
|
429 |
int CaItemModelPrivate::rowCount() const
|
|
430 |
{
|
|
431 |
return mEntries.count();
|
|
432 |
}
|
|
433 |
|
|
434 |
/*!
|
|
435 |
Returns QModelIndex of an item
|
|
436 |
\param row row
|
|
437 |
\retval QModelIndex of item in model
|
|
438 |
*/
|
|
439 |
QModelIndex CaItemModelPrivate::index(int row)
|
|
440 |
{
|
|
441 |
if ((row >= 0) && (row < mEntries.count())) {
|
|
442 |
return m_q->createIndex(row, 0);
|
|
443 |
} else {
|
|
444 |
return QModelIndex();
|
|
445 |
}
|
|
446 |
}
|
|
447 |
|
|
448 |
/*!
|
|
449 |
Returns appropiate model's data
|
|
450 |
\param modelIndex model index
|
|
451 |
\param role which data role to return
|
|
452 |
\retval models data as QVariant
|
|
453 |
*/
|
|
454 |
QVariant CaItemModelPrivate::data(const QModelIndex &modelIndex,
|
87
|
455 |
int role) const
|
85
|
456 |
{
|
87
|
457 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::data");
|
|
458 |
QVariant variant;
|
106
|
459 |
QSharedPointer<CaEntry> pEntry = entry(modelIndex);
|
|
460 |
if (!pEntry.isNull()) {
|
87
|
461 |
switch (role) {
|
|
462 |
case Qt::DisplayRole:
|
106
|
463 |
variant = displayRole(pEntry.data());
|
87
|
464 |
break;
|
|
465 |
case Qt::DecorationRole:
|
106
|
466 |
variant = QVariant(HbIcon(pEntry->makeIcon(mSize)));
|
87
|
467 |
break;
|
|
468 |
case CaItemModel::IdRole:
|
106
|
469 |
variant = QVariant(pEntry->id());
|
87
|
470 |
break;
|
|
471 |
case CaItemModel::TypeRole:
|
106
|
472 |
variant = QVariant(pEntry->entryTypeName());
|
87
|
473 |
break;
|
|
474 |
case CaItemModel::FlagsRole:
|
106
|
475 |
variant = qVariantFromValue(pEntry->flags());
|
87
|
476 |
break;
|
|
477 |
case CaItemModel::TextRole:
|
106
|
478 |
variant = QVariant(pEntry->text());
|
87
|
479 |
break;
|
92
|
480 |
case CaItemModel::FullTextRole:
|
106
|
481 |
variant = QVariant(pEntry->text() + QString(" ") + pEntry->description());
|
92
|
482 |
break;
|
98
|
483 |
case CaItemModel::UninstalRole:
|
106
|
484 |
variant = QVariant(
|
|
485 |
pEntry->attribute(UNINSTALL_PROGRESS_APPLICATION_ATTRIBUTE_NAME).toInt());
|
98
|
486 |
break;
|
106
|
487 |
case CaItemModel::CollectionTitleRole:
|
|
488 |
if (!pEntry->attribute(COLLECTION_TITLE_NAME).isNull()) {
|
107
|
489 |
variant = QVariant(pEntry->
|
|
490 |
attribute(COLLECTION_TITLE_NAME).toUtf8());
|
106
|
491 |
}
|
|
492 |
else {
|
|
493 |
variant = QVariant(pEntry->text());
|
|
494 |
}
|
|
495 |
break;
|
|
496 |
|
87
|
497 |
default:
|
|
498 |
variant = QVariant(QVariant::Invalid);
|
|
499 |
}
|
85
|
500 |
}
|
87
|
501 |
CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::data");
|
|
502 |
return variant;
|
85
|
503 |
}
|
|
504 |
|
|
505 |
/*!
|
|
506 |
Disables or enables auto-update feature of the model
|
|
507 |
\param autoUpdate (HsMenuAutoUpdate)
|
|
508 |
*/
|
|
509 |
void CaItemModelPrivate::setAutoUpdate(bool autoUpdate)
|
|
510 |
{
|
87
|
511 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::setAutoUpdate");
|
85
|
512 |
if (autoUpdate) {
|
|
513 |
if (!mNotifier) {
|
|
514 |
CaNotifierFilter filter(mQuery);
|
|
515 |
mNotifier = mService->createNotifier(filter);
|
|
516 |
connectSlots();
|
|
517 |
}
|
|
518 |
} else {
|
|
519 |
disconnectSlots();
|
|
520 |
delete mNotifier;
|
|
521 |
mNotifier = NULL;
|
|
522 |
}
|
87
|
523 |
CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::setAutoUpdate");
|
85
|
524 |
}
|
|
525 |
|
|
526 |
/*!
|
|
527 |
Method for setting sorting order on model
|
|
528 |
(probably will be moved to MenuService)
|
|
529 |
\param sortOrder sorting order (SortAttribute)
|
|
530 |
*/
|
|
531 |
void CaItemModelPrivate::setSort(SortAttribute sortAttribute,
|
87
|
532 |
Qt::SortOrder sortOrder)
|
85
|
533 |
{
|
87
|
534 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::setSort");
|
85
|
535 |
mQuery.setSort(sortAttribute, sortOrder);
|
|
536 |
updateLayout();
|
87
|
537 |
CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::setSort");
|
85
|
538 |
}
|
|
539 |
|
|
540 |
/*!
|
|
541 |
Method for setting icon size
|
|
542 |
\param size icon size to display
|
|
543 |
*/
|
112
|
544 |
void CaItemModelPrivate::setIconSize(const QSizeF &size)
|
85
|
545 |
{
|
|
546 |
if (mSize == size)
|
|
547 |
return;
|
|
548 |
m_q->layoutAboutToBeChanged();
|
|
549 |
mSize = size;
|
|
550 |
m_q->layoutChanged();
|
|
551 |
}
|
|
552 |
|
|
553 |
/*!
|
|
554 |
Method for getting icon size
|
|
555 |
\retval icon size to display
|
|
556 |
*/
|
112
|
557 |
QSizeF CaItemModelPrivate::getIconSize() const
|
85
|
558 |
{
|
|
559 |
return mSize;
|
|
560 |
}
|
|
561 |
|
|
562 |
|
|
563 |
/*!
|
|
564 |
Gets index of the parent item
|
|
565 |
\retval QModelIndex representing root item
|
|
566 |
*/
|
|
567 |
QModelIndex CaItemModelPrivate::root()
|
|
568 |
{
|
|
569 |
if (mQuery.parentId()) {
|
|
570 |
return m_q->createIndex(0, 1);
|
|
571 |
} else {
|
|
572 |
return QModelIndex();
|
|
573 |
}
|
|
574 |
}
|
|
575 |
|
|
576 |
/*!
|
|
577 |
Returns an entry from model
|
|
578 |
\param modelIndex index of entry in model
|
|
579 |
\retval pointer to an entry
|
|
580 |
*/
|
92
|
581 |
QSharedPointer<CaEntry> CaItemModelPrivate::entry(const QModelIndex &modelIndex) const
|
85
|
582 |
{
|
106
|
583 |
if (modelIndex.isValid()) {
|
|
584 |
if (modelIndex.column() == 1) {
|
|
585 |
return mParentEntry;
|
|
586 |
}
|
|
587 |
else {
|
|
588 |
int row = modelIndex.row();
|
|
589 |
if (row >= mEntries.count()) {
|
|
590 |
return QSharedPointer<CaEntry> ();
|
|
591 |
}
|
|
592 |
else {
|
|
593 |
return mEntries.at(row);
|
|
594 |
}
|
|
595 |
}
|
85
|
596 |
}
|
106
|
597 |
return QSharedPointer<CaEntry> ();
|
85
|
598 |
}
|
|
599 |
|
|
600 |
/*!
|
|
601 |
Disables or enables secondline feature of the model
|
|
602 |
\param secondLine disables or enables second line
|
|
603 |
*/
|
|
604 |
void CaItemModelPrivate::setSecondLineVisibility(bool secondLineVisibility)
|
|
605 |
{
|
|
606 |
if (mSecondLineVisibility == secondLineVisibility)
|
|
607 |
return;
|
|
608 |
m_q->layoutAboutToBeChanged();
|
|
609 |
mSecondLineVisibility = secondLineVisibility;
|
|
610 |
m_q->layoutChanged();
|
|
611 |
}
|
|
612 |
|
|
613 |
/*!
|
|
614 |
Gets second line visibility attribute
|
|
615 |
\retrun second line visibility attribute
|
|
616 |
*/
|
|
617 |
bool CaItemModelPrivate::secondLineVisibility() const
|
|
618 |
{
|
|
619 |
return mSecondLineVisibility;
|
|
620 |
}
|
|
621 |
|
|
622 |
/*!
|
|
623 |
Returns proper display role for item
|
|
624 |
\param modelIndex item index
|
|
625 |
\retval QVariant containing display role
|
|
626 |
*/
|
106
|
627 |
QVariant CaItemModelPrivate::displayRole(const CaEntry* entry) const
|
85
|
628 |
{
|
87
|
629 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::displayRole")
|
|
630 |
|
85
|
631 |
QVariant result;
|
|
632 |
if (mSecondLineVisibility) {
|
106
|
633 |
if (entry->description().isEmpty()) {
|
|
634 |
result = entry->text();
|
85
|
635 |
} else {
|
|
636 |
QList<QVariant> text;
|
106
|
637 |
text << entry->text();
|
|
638 |
text << entry->description();
|
85
|
639 |
result = QVariant(text);
|
|
640 |
}
|
|
641 |
} else {
|
106
|
642 |
result = entry->text();
|
85
|
643 |
}
|
87
|
644 |
CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::displayRole")
|
85
|
645 |
return result;
|
|
646 |
}
|
|
647 |
|
|
648 |
/*!
|
|
649 |
Sets parent
|
|
650 |
\param parentId
|
|
651 |
*/
|
|
652 |
void CaItemModelPrivate::setParentId(int parentId)
|
|
653 |
{
|
87
|
654 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::setParentId");
|
85
|
655 |
mQuery.setParentId(parentId);
|
|
656 |
if (mNotifier) {
|
|
657 |
delete mNotifier;
|
|
658 |
mNotifier = mService->createNotifier(CaNotifierFilter(mQuery));
|
|
659 |
reconnectSlots();
|
|
660 |
}
|
|
661 |
updateModel();
|
87
|
662 |
CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::setParentId");
|
|
663 |
|
|
664 |
}
|
|
665 |
|
|
666 |
/*!
|
|
667 |
Sets flags to mQuery which should be enabled.
|
|
668 |
\param onFlags flags.
|
|
669 |
|
|
670 |
*/
|
|
671 |
void CaItemModelPrivate::setFlagsOn(const EntryFlags &onFlags)
|
|
672 |
{
|
|
673 |
mQuery.setFlagsOn(onFlags);
|
85
|
674 |
}
|
|
675 |
|
87
|
676 |
/*!
|
|
677 |
Sets flags to mQuery which should be disabled.
|
|
678 |
\param offFlags flags.
|
|
679 |
|
|
680 |
\code
|
|
681 |
...
|
|
682 |
// to set a new parent id
|
|
683 |
model->setFlagsOff(RemovableEntryFlag);
|
|
684 |
...
|
|
685 |
\endcode
|
|
686 |
|
|
687 |
*/
|
|
688 |
void CaItemModelPrivate::setFlagsOff(const EntryFlags &offFlags)
|
|
689 |
{
|
|
690 |
mQuery.setFlagsOff(offFlags);
|
|
691 |
}
|
85
|
692 |
|
|
693 |
/*!
|
|
694 |
Checks if notifier exists
|
|
695 |
\retval true if notifier exists otherwise false
|
|
696 |
*/
|
|
697 |
bool CaItemModelPrivate::notifierExists() const
|
|
698 |
{
|
|
699 |
if (mNotifier) {
|
|
700 |
return true;
|
|
701 |
}
|
|
702 |
return false;
|
|
703 |
}
|
|
704 |
|
|
705 |
|
107
|
706 |
QList<int> CaItemModelPrivate::getUninstallingEntriesIds(int componentId)
|
|
707 |
{
|
|
708 |
CaQuery* query = new CaQuery(mQuery);
|
|
709 |
QString compId(QString().setNum(componentId));
|
|
710 |
query->setAttribute(QString("component_id"), compId);
|
112
|
711 |
query->setFlagsOn(RemovableEntryFlag | VisibleEntryFlag);
|
107
|
712 |
QList<int> ids = mService->getEntryIds(*query);
|
|
713 |
delete query;
|
|
714 |
return ids;
|
|
715 |
}
|
|
716 |
|
|
717 |
void CaItemModelPrivate::updateProgress(int id, int valueOfProgress)
|
|
718 |
{
|
|
719 |
int updateIndex = mEntries.updateProgress(id, valueOfProgress);
|
|
720 |
if (updateIndex >= 0) {
|
|
721 |
emit m_q->dataChanged(
|
|
722 |
index(updateIndex), index(updateIndex));
|
|
723 |
}
|
|
724 |
}
|
85
|
725 |
/*!
|
|
726 |
Updates model with fresh entries and resets model
|
|
727 |
*/
|
|
728 |
void CaItemModelPrivate::updateModel()
|
|
729 |
{
|
87
|
730 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::updateModel");
|
|
731 |
|
85
|
732 |
mEntries.reloadEntries(mQuery);
|
|
733 |
updateParentEntry();
|
|
734 |
m_q->reset();
|
87
|
735 |
|
|
736 |
CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::updateModel");
|
85
|
737 |
}
|
|
738 |
|
|
739 |
/*!
|
|
740 |
Updates parent entry
|
|
741 |
*/
|
|
742 |
void CaItemModelPrivate::updateParentEntry()
|
|
743 |
{
|
87
|
744 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::updateParentEntry");
|
|
745 |
|
85
|
746 |
if (mQuery.parentId()) {
|
|
747 |
mParentEntry = mService->getEntry(mQuery.parentId());
|
|
748 |
}
|
87
|
749 |
|
|
750 |
CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::updateParentEntry");
|
|
751 |
|
85
|
752 |
}
|
|
753 |
|
|
754 |
/*!
|
|
755 |
Updates model item with fresh data
|
98
|
756 |
\param entry item to update
|
85
|
757 |
*/
|
98
|
758 |
void CaItemModelPrivate::updateItemData(const QSharedPointer<CaEntry> &entry)
|
85
|
759 |
{
|
87
|
760 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::updateItemData");
|
|
761 |
|
85
|
762 |
|
98
|
763 |
int id = entry->id();
|
85
|
764 |
QList<int> ids = mService->getEntryIds(mQuery);
|
92
|
765 |
if (mEntries.indexOf(id) >= 0
|
89
|
766 |
&& ids.indexOf(id) == mEntries.indexOf(id)) {
|
98
|
767 |
mEntries.updateEntry(entry);
|
|
768 |
emit m_q->dataChanged(
|
|
769 |
index(mEntries.indexOf(id)), index(mEntries.indexOf(id)));
|
89
|
770 |
} else if (mParentEntry && id == mParentEntry->id()) {
|
|
771 |
updateParentEntry();
|
|
772 |
m_q->reset();
|
98
|
773 |
} else if (ids.indexOf(id) < 0) {
|
|
774 |
removeItem(id);
|
|
775 |
} else if (mEntries.indexOf(id) < 0) {
|
|
776 |
addItem(id);
|
85
|
777 |
} else {
|
89
|
778 |
updateModel();
|
85
|
779 |
}
|
87
|
780 |
CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::updateItemData");
|
85
|
781 |
}
|
|
782 |
|
|
783 |
/*!
|
|
784 |
Adds new item to model
|
|
785 |
\param id id of item to add
|
|
786 |
*/
|
|
787 |
void CaItemModelPrivate::addItem(int id)
|
|
788 |
{
|
87
|
789 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::addItem");
|
|
790 |
|
85
|
791 |
int row = itemRow(id);
|
|
792 |
//we use beginInsertRows and endInsertRows to emit proper signal
|
|
793 |
//(see Qt documentation of QAbstractItemModel)
|
|
794 |
if (mEntries.indexOf(id) < 0 && row >= 0) {
|
94
|
795 |
if (row > mEntries.count()) {
|
|
796 |
m_q->beginInsertRows(QModelIndex(), mEntries.count(), mEntries.count());
|
|
797 |
mEntries.insert(mEntries.count(), id);
|
|
798 |
} else {
|
|
799 |
m_q->beginInsertRows(QModelIndex(), row , row);
|
|
800 |
mEntries.insert(row, id);
|
|
801 |
}
|
85
|
802 |
m_q->endInsertRows();
|
94
|
803 |
} else if (row == -1) {
|
|
804 |
//we udpade whole model because we do not know parent collecion for given item
|
|
805 |
updateModel();
|
85
|
806 |
}
|
87
|
807 |
CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::addItem");
|
85
|
808 |
}
|
|
809 |
|
|
810 |
/*!
|
92
|
811 |
Adds new item block to model
|
|
812 |
Use in cases when inserting / appending an adjacent block of items
|
|
813 |
\param itemsList list of adjacent items
|
|
814 |
*/
|
|
815 |
void CaItemModelPrivate::addItemBlock(const QList<int> &itemsList)
|
|
816 |
{
|
|
817 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::addItemBlock");
|
|
818 |
if (!itemsList.isEmpty()) {
|
|
819 |
int firstRow = itemRow(itemsList.first());
|
|
820 |
int lastRow = itemRow(itemsList.last());
|
|
821 |
m_q->beginInsertRows(QModelIndex(), firstRow, lastRow);
|
|
822 |
for (int i = 0; i < itemsList.count(); ++i) {
|
|
823 |
mEntries.insert(firstRow + i, itemsList.at(i));
|
|
824 |
}
|
|
825 |
m_q->endInsertRows();
|
|
826 |
emit m_q->scrollTo(firstRow, QAbstractItemView::PositionAtTop);
|
|
827 |
}
|
|
828 |
CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::addItemBlock");
|
|
829 |
}
|
|
830 |
|
|
831 |
/*!
|
85
|
832 |
Adds new items to model
|
|
833 |
\param itemsList current items list
|
|
834 |
*/
|
92
|
835 |
void CaItemModelPrivate::handleAddItems(const QList<int> &itemsList)
|
85
|
836 |
{
|
87
|
837 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::handleAddItems");
|
92
|
838 |
const int oldItemCount(mEntries.count());
|
|
839 |
if (oldItemCount) {
|
|
840 |
const int newItemCount(itemsList.count());
|
106
|
841 |
int i = 0;
|
|
842 |
QList<int> oldList = mEntries.orderedIdList();
|
|
843 |
//we loop through items to find first added
|
|
844 |
while (i < oldList.count()) {
|
|
845 |
if (oldList[i] != itemsList[i]) {
|
|
846 |
oldList.takeAt(i);
|
|
847 |
} else {
|
|
848 |
++i;
|
|
849 |
}
|
|
850 |
}
|
92
|
851 |
if (newItemCount == oldItemCount) {
|
|
852 |
// count is the same - check if item order changed
|
106
|
853 |
if (itemsList == oldList) {
|
92
|
854 |
// assume that if the order has not changed
|
|
855 |
// it had to be the secondary lines
|
107
|
856 |
emit m_q->dataChanged(index(0), index(m_q->rowCount()-1));
|
92
|
857 |
} else {
|
89
|
858 |
updateLayout();
|
|
859 |
}
|
92
|
860 |
} else {
|
89
|
861 |
updateModel();
|
92
|
862 |
//i is the index of first added item
|
|
863 |
}
|
106
|
864 |
emit m_q->scrollTo(i, QAbstractItemView::PositionAtTop);
|
85
|
865 |
} else {
|
92
|
866 |
// items added to an empty list - add all as a single block
|
|
867 |
addItemBlock(itemsList);
|
85
|
868 |
}
|
87
|
869 |
CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::handleAddItems");
|
85
|
870 |
}
|
|
871 |
|
|
872 |
/*!
|
|
873 |
Gets index/row for new item
|
|
874 |
\param id of item to add
|
|
875 |
\retval row in model list for new item to insert
|
|
876 |
*/
|
|
877 |
int CaItemModelPrivate::itemRow(int id)
|
|
878 |
{
|
87
|
879 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::itemRow");
|
85
|
880 |
QList<int> ids = mService->getEntryIds(mQuery);
|
87
|
881 |
CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::itemRow");
|
85
|
882 |
return ids.indexOf(id);
|
|
883 |
}
|
|
884 |
|
|
885 |
/*!
|
|
886 |
Removes item from model
|
|
887 |
\param id of item to remove
|
|
888 |
*/
|
|
889 |
void CaItemModelPrivate::removeItem(int id)
|
|
890 |
{
|
87
|
891 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::removeItem");
|
85
|
892 |
int row = mEntries.indexOf(id);
|
|
893 |
if (row >= 0) {
|
|
894 |
m_q->beginRemoveRows(QModelIndex(), mEntries.indexOf(id),
|
87
|
895 |
mEntries.indexOf(id));
|
85
|
896 |
mEntries.remove(id);
|
|
897 |
m_q->endRemoveRows();
|
87
|
898 |
} else {
|
89
|
899 |
updateModel();
|
85
|
900 |
}
|
87
|
901 |
CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::removeItem");
|
85
|
902 |
}
|
|
903 |
|
|
904 |
/*!
|
|
905 |
Removes missing items from model
|
|
906 |
\param itemsList current items list
|
|
907 |
*/
|
|
908 |
void CaItemModelPrivate::removeItems(const QList<int> &itemsList)
|
|
909 |
{
|
87
|
910 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::removeItems");
|
85
|
911 |
int i = 0;
|
|
912 |
for (i = 0; i < itemsList.count(); i++) {
|
|
913 |
if (itemsList[i] != mEntries[i]) {
|
|
914 |
removeItem(mEntries[i]);
|
|
915 |
}
|
|
916 |
}
|
|
917 |
while (i < mEntries.count()) {
|
|
918 |
removeItem(mEntries[i]);
|
|
919 |
i++;
|
|
920 |
}
|
87
|
921 |
CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::removeItems");
|
85
|
922 |
}
|
|
923 |
|
|
924 |
/*!
|
|
925 |
Layout update
|
89
|
926 |
NOTE: this method should be called only if the entries get rearranged
|
|
927 |
and do not change their contents!
|
85
|
928 |
*/
|
|
929 |
void CaItemModelPrivate::updateLayout()
|
|
930 |
{
|
87
|
931 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::updateLayout");
|
85
|
932 |
m_q->layoutAboutToBeChanged();
|
89
|
933 |
|
|
934 |
// get the ID list from before the update
|
|
935 |
QList<int> oldOrderedIdList = mEntries.orderedIdList();
|
|
936 |
|
|
937 |
// do the update, the entries should only get rearranged
|
85
|
938 |
mEntries.updateEntries(mQuery);
|
89
|
939 |
|
|
940 |
// get the new ID list after the entries got rearranged
|
|
941 |
QList<int> newOrderedIdList = mEntries.orderedIdList();
|
|
942 |
// this list will contain the new position indices
|
|
943 |
QList<int> newPositionsList;
|
|
944 |
int entry;
|
|
945 |
foreach (entry, oldOrderedIdList) {
|
|
946 |
newPositionsList << newOrderedIdList.indexOf(entry);
|
|
947 |
}
|
|
948 |
|
|
949 |
// now check which items in the previous persistent index list changed
|
|
950 |
// their positions, make new indices for them and store in the new
|
|
951 |
// persistent index list
|
|
952 |
QModelIndexList oldPersistentIndexList = m_q->persistentIndexList();
|
|
953 |
QModelIndexList newPersistentIndexList;
|
|
954 |
QModelIndex index;
|
|
955 |
foreach (index, oldPersistentIndexList) {
|
|
956 |
newPersistentIndexList <<
|
|
957 |
m_q->createIndex(
|
92
|
958 |
newPositionsList.at(index.row()), 0, index.internalPointer());
|
89
|
959 |
}
|
92
|
960 |
m_q->changePersistentIndexList(
|
|
961 |
oldPersistentIndexList, newPersistentIndexList);
|
89
|
962 |
|
85
|
963 |
m_q->layoutChanged();
|
87
|
964 |
CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::updateLayout");
|
85
|
965 |
}
|
|
966 |
|
|
967 |
/*!
|
|
968 |
Connects slots
|
|
969 |
*/
|
|
970 |
void CaItemModelPrivate::connectSlots()
|
|
971 |
{
|
87
|
972 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::connectSlots");
|
98
|
973 |
connect(mNotifier, SIGNAL(entryChanged(CaEntry ,ChangeType)),
|
|
974 |
this, SLOT(updateModelItem(CaEntry, ChangeType)));
|
85
|
975 |
|
|
976 |
if (mQuery.parentId() > 0) {
|
|
977 |
connect(mNotifier, SIGNAL(groupContentChanged(int)),
|
87
|
978 |
this, SLOT(updateModelContent(int)));
|
85
|
979 |
}
|
87
|
980 |
CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::connectSlots");
|
85
|
981 |
}
|
|
982 |
|
|
983 |
/*!
|
|
984 |
Disconnects slots
|
|
985 |
*/
|
|
986 |
void CaItemModelPrivate::disconnectSlots()
|
|
987 |
{
|
87
|
988 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::disconnectSlots");
|
98
|
989 |
disconnect(mNotifier, SIGNAL(entryChanged(CaEntry ,ChangeType)),
|
|
990 |
this, SLOT(updateModelItem(CaEntry, ChangeType)));
|
85
|
991 |
if (mQuery.parentId() > 0) {
|
|
992 |
disconnect(mNotifier, SIGNAL(groupContentChanged(int)),
|
87
|
993 |
this, SLOT(updateModelContent(int)));
|
85
|
994 |
}
|
87
|
995 |
CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::disconnectSlots");
|
85
|
996 |
}
|
|
997 |
|
|
998 |
/*!
|
|
999 |
Reconnects slots
|
|
1000 |
*/
|
|
1001 |
void CaItemModelPrivate::reconnectSlots()
|
|
1002 |
{
|
87
|
1003 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::reconnectSlots");
|
85
|
1004 |
disconnectSlots();
|
|
1005 |
connectSlots();
|
87
|
1006 |
CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::reconnectSlots");
|
85
|
1007 |
}
|
|
1008 |
|
|
1009 |
/*!
|
|
1010 |
Updates model with fresh entries
|
|
1011 |
\param id of item to handle
|
|
1012 |
\param changeType change type
|
|
1013 |
*/
|
98
|
1014 |
void CaItemModelPrivate::updateModelItem(
|
|
1015 |
const CaEntry &entry, ChangeType changeType)
|
85
|
1016 |
{
|
87
|
1017 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::updateModelItem");
|
98
|
1018 |
QSharedPointer<CaEntry> sharedEntry(new CaEntry(entry));
|
96
|
1019 |
int previousCount = rowCount();
|
85
|
1020 |
switch (changeType) {
|
98
|
1021 |
case AddChangeType:
|
|
1022 |
addItem(sharedEntry->id());
|
|
1023 |
break;
|
|
1024 |
case RemoveChangeType:
|
|
1025 |
removeItem(sharedEntry->id());
|
|
1026 |
break;
|
|
1027 |
default:
|
|
1028 |
updateItemData(sharedEntry);
|
|
1029 |
break;
|
85
|
1030 |
}
|
96
|
1031 |
emitEmpty(previousCount);
|
87
|
1032 |
CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::updateModelItem");
|
85
|
1033 |
}
|
|
1034 |
|
|
1035 |
/*!
|
|
1036 |
Updates model with fresh entries
|
|
1037 |
\param id of parent
|
|
1038 |
*/
|
|
1039 |
void CaItemModelPrivate::updateModelContent(int id)
|
|
1040 |
{
|
|
1041 |
Q_UNUSED(id);
|
96
|
1042 |
int previousCount = rowCount();
|
|
1043 |
|
87
|
1044 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::updateModelContent");
|
85
|
1045 |
QList<int> ids = mService->getEntryIds(mQuery);
|
|
1046 |
|
|
1047 |
if (ids.count() >= mEntries.count()) {
|
|
1048 |
handleAddItems(ids);
|
|
1049 |
} else {
|
|
1050 |
removeItems(ids);
|
|
1051 |
}
|
96
|
1052 |
emitEmpty(previousCount);
|
106
|
1053 |
emitCountChange(previousCount);
|
87
|
1054 |
CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::updateModelContent");
|
85
|
1055 |
}
|
96
|
1056 |
|
|
1057 |
/*!
|
|
1058 |
Emits empty signal if model state was changed
|
|
1059 |
\param id of parent
|
|
1060 |
*/
|
|
1061 |
void CaItemModelPrivate::emitEmpty(int previousCount)
|
|
1062 |
{
|
|
1063 |
if ( previousCount && !rowCount()) {
|
|
1064 |
emit m_q->empty(true);
|
|
1065 |
}
|
|
1066 |
if ( !previousCount && rowCount()) {
|
|
1067 |
emit m_q->empty(false);
|
|
1068 |
}
|
|
1069 |
}
|
106
|
1070 |
|
|
1071 |
/*!
|
|
1072 |
Emits empty signal if count of item in model was change
|
|
1073 |
\param previousCount
|
|
1074 |
*/
|
|
1075 |
void CaItemModelPrivate::emitCountChange(int previousCount)
|
|
1076 |
{
|
|
1077 |
if (previousCount != rowCount()) {
|
|
1078 |
emit m_q->countChange();
|
|
1079 |
}
|
|
1080 |
}
|
107
|
1081 |
|