|
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 |
|
18 #include <QIcon> |
|
19 |
|
20 #include "caitemmodel.h" |
|
21 #include "caitemmodel_p.h" |
|
22 #include "canotifier.h" |
|
23 #include "canotifierfilter.h" |
|
24 |
|
25 // Constants |
|
26 const QSize defaultIconSize(30, 30); |
|
27 |
|
28 // ======== MEMBER FUNCTIONS ======== |
|
29 |
|
30 /*! |
|
31 * \class CaItemModel |
|
32 * |
|
33 * \brief This class provides model containing CaEntry class objects. |
|
34 * |
|
35 * To create instance of CaItemModel object, you need to pass CaQuery |
|
36 * object in constructor. CaQuery should describe items that you want |
|
37 * to have in a model. |
|
38 * |
|
39 * \example |
|
40 * \code |
|
41 * |
|
42 * CaQuery query; |
|
43 * query.setFlagsOn(VisibleEntryFlag); |
|
44 * query.setParentId(collectionId); |
|
45 * CaItemModel* model = new CaItemModel(query, this); |
|
46 * |
|
47 * \endcode |
|
48 */ |
|
49 |
|
50 /*! |
|
51 Constructor. |
|
52 \param query query describing entries that should be present in a model. |
|
53 \param parent parent of a model |
|
54 */ |
|
55 CaItemModel::CaItemModel(const CaQuery& query, QObject * parent) : |
|
56 QAbstractItemModel(parent), m_d(new CaItemModelPrivate(query, this)) |
|
57 { |
|
58 |
|
59 } |
|
60 |
|
61 /*! |
|
62 Destructor |
|
63 */ |
|
64 CaItemModel::~CaItemModel() |
|
65 { |
|
66 delete m_d; |
|
67 } |
|
68 |
|
69 /*! |
|
70 Returns number of columns |
|
71 \param parent not used |
|
72 \retval 1 |
|
73 |
|
74 \code |
|
75 ... |
|
76 // to get number of columns in a model |
|
77 int columns = model->columnCount(); |
|
78 ... |
|
79 \endcode |
|
80 |
|
81 */ |
|
82 int CaItemModel::columnCount(const QModelIndex &parent) const |
|
83 { |
|
84 Q_UNUSED(parent); |
|
85 //model keeps entries in a column 0 and a parent entry in a column 1 |
|
86 //parent entry is treated as an invisible root item, |
|
87 //so column count is always 1 |
|
88 return 1; |
|
89 } |
|
90 |
|
91 /*! |
|
92 Returns number of rows |
|
93 \param parent not used |
|
94 \retval number of rows |
|
95 |
|
96 \code |
|
97 ... |
|
98 // to get number of rows in a model |
|
99 int rows = model->rowCount(); |
|
100 ... |
|
101 \endcode |
|
102 */ |
|
103 int CaItemModel::rowCount(const QModelIndex &parent) const |
|
104 { |
|
105 Q_UNUSED(parent); |
|
106 return m_d->rowCount(); |
|
107 } |
|
108 |
|
109 /*! |
|
110 Returns QModelIndex of an item |
|
111 \param row row in which an item is placed |
|
112 \param column not used |
|
113 \param parent not used |
|
114 \retval index of item in model |
|
115 |
|
116 \code |
|
117 ... |
|
118 // to get model index of an item |
|
119 QModelIndex modelIndex = model->index(5); |
|
120 ... |
|
121 \endcode |
|
122 |
|
123 */ |
|
124 QModelIndex CaItemModel::index(int row, int column, |
|
125 const QModelIndex &parent) const |
|
126 { |
|
127 Q_UNUSED(column); |
|
128 Q_UNUSED(parent); |
|
129 return m_d->index(row); |
|
130 } |
|
131 |
|
132 /*! |
|
133 Returns parent item |
|
134 \param child index (ignored) |
|
135 \retval parent index. in case of CaItemModel it is always QModelIndex() |
|
136 |
|
137 \code |
|
138 ... |
|
139 // to get model index of a parent of an item |
|
140 QModelIndex parentModelIndex = model->parent(childModelIndex); |
|
141 ... |
|
142 \endcode |
|
143 */ |
|
144 QModelIndex CaItemModel::parent(const QModelIndex &index) const |
|
145 { |
|
146 Q_UNUSED(index); |
|
147 return QModelIndex(); |
|
148 } |
|
149 |
|
150 /*! |
|
151 Returns root item model index |
|
152 \retval root item model index |
|
153 |
|
154 \code |
|
155 ... |
|
156 // to get model index of a root item |
|
157 QModelIndex rootIndex = model->root(); |
|
158 ... |
|
159 \endcode |
|
160 */ |
|
161 QModelIndex CaItemModel::root() const |
|
162 { |
|
163 return m_d->root(); |
|
164 } |
|
165 |
|
166 /*! |
|
167 Returns appropiate model's data |
|
168 \param index model index |
|
169 \param role which data role to return |
|
170 \retval models data |
|
171 |
|
172 \code |
|
173 ... |
|
174 // to get data for model item |
|
175 QVariant = model->data(itemModelIndex, Qt::DisplayRole); |
|
176 ... |
|
177 \endcode |
|
178 |
|
179 */ |
|
180 QVariant CaItemModel::data(const QModelIndex &index, int role) const |
|
181 { |
|
182 return m_d->data(index, role); |
|
183 } |
|
184 |
|
185 /*! |
|
186 Disables or enables auto-update feature of the model |
|
187 \param autoUpdate true to enable autoupdate, false to disable |
|
188 |
|
189 \code |
|
190 ... |
|
191 // to enable model auto update |
|
192 model->setAutoUpdate(true); |
|
193 ... |
|
194 \endcode |
|
195 |
|
196 */ |
|
197 void CaItemModel::setAutoUpdate(bool autoUpdate) |
|
198 { |
|
199 m_d->setAutoUpdate(autoUpdate); |
|
200 } |
|
201 |
|
202 /*! |
|
203 Disables or enables secondline feature of the model |
|
204 \param secondLine enable or disable second line |
|
205 |
|
206 \code |
|
207 ... |
|
208 // to enable model second line visibility |
|
209 model->setSecondLineVisibility(true); |
|
210 ... |
|
211 \endcode |
|
212 |
|
213 */ |
|
214 void CaItemModel::setSecondLineVisibility(bool secondLineVisible) |
|
215 { |
|
216 m_d->setSecondLineVisibility(secondLineVisible); |
|
217 } |
|
218 |
|
219 /*! |
|
220 Gets second line visibility attribute |
|
221 \retrun second line visibility attribute |
|
222 |
|
223 \code |
|
224 ... |
|
225 // to check second line visibility attribute |
|
226 bool visibility = model->secondLineVisibility(); |
|
227 ... |
|
228 \endcode |
|
229 |
|
230 */ |
|
231 bool CaItemModel::secondLineVisibility() const |
|
232 { |
|
233 return m_d->secondLineVisibility(); |
|
234 } |
|
235 /*! |
|
236 Returns auto update status |
|
237 \retval true if autoupdate is on, false if not |
|
238 |
|
239 \code |
|
240 ... |
|
241 // to check auto update attribute |
|
242 bool autoUpdate = model->isAutoUpdate(); |
|
243 ... |
|
244 \endcode |
|
245 |
|
246 */ |
|
247 bool CaItemModel::isAutoUpdate() const |
|
248 { |
|
249 return m_d->notifierExists(); |
|
250 } |
|
251 |
|
252 /*! |
|
253 Method for setting sorting order on model |
|
254 \param sortAttribute sort attribute (by name, timestamp, ect...) |
|
255 \param sortOrder sort order (ascending, descending) |
|
256 |
|
257 \code |
|
258 ... |
|
259 // to set sort order in a model |
|
260 model->setSort(NameSortAttribute, Qt::Ascending); |
|
261 ... |
|
262 \endcode |
|
263 |
|
264 */ |
|
265 void CaItemModel::setSort(SortAttribute sortAttribute, |
|
266 Qt::SortOrder sortOrder) |
|
267 { |
|
268 m_d->setSort(sortAttribute, sortOrder); |
|
269 } |
|
270 |
|
271 /*! |
|
272 Method for setting icon size |
|
273 \param size icon size to display |
|
274 |
|
275 \code |
|
276 ... |
|
277 // to set an icon size in a model |
|
278 QSize iconSize(50,50); |
|
279 model->setIconSize(iconSize); |
|
280 ... |
|
281 \endcode |
|
282 |
|
283 */ |
|
284 void CaItemModel::setIconSize(const QSize &size) |
|
285 { |
|
286 m_d->setIconSize(size); |
|
287 } |
|
288 |
|
289 /*! |
|
290 Method for getting icon size |
|
291 \param size icon size to display |
|
292 */ |
|
293 QSize CaItemModel::getIconSize() const |
|
294 { |
|
295 return m_d->getIconSize(); |
|
296 } |
|
297 |
|
298 /*! |
|
299 Updates model with fresh entries |
|
300 |
|
301 \code |
|
302 ... |
|
303 // to refresh a model |
|
304 model->updateModel(); |
|
305 ... |
|
306 \endcode |
|
307 |
|
308 */ |
|
309 void CaItemModel::updateModel() |
|
310 { |
|
311 m_d->updateModel(); |
|
312 } |
|
313 |
|
314 /*! |
|
315 Sets parent and fetch children items from a storage |
|
316 \param parentId id of a collection |
|
317 |
|
318 \code |
|
319 ... |
|
320 // to set a new parent id |
|
321 int newParentId = 10; |
|
322 model->setParentId(newParentId); |
|
323 ... |
|
324 \endcode |
|
325 |
|
326 */ |
|
327 void CaItemModel::setParentId(int parentId) |
|
328 { |
|
329 m_d->setParentId(parentId); |
|
330 } |
|
331 |
|
332 /*! |
|
333 Returns an entry from model |
|
334 \param index of entry in model |
|
335 \retval pointer to an entry |
|
336 |
|
337 \code |
|
338 ... |
|
339 // to get an entry from a model |
|
340 CaEntry* entry = model->entry(entryModelIndex); |
|
341 ... |
|
342 delete entry; |
|
343 \endcode |
|
344 |
|
345 */ |
|
346 CaEntry* CaItemModel::entry(const QModelIndex &index) const |
|
347 { |
|
348 return m_d->entry(index); |
|
349 } |
|
350 |
|
351 /*! |
|
352 Constructor |
|
353 \param query needed to create model |
|
354 \param pointer to public implementation object connected |
|
355 */ |
|
356 CaItemModelPrivate::CaItemModelPrivate(const CaQuery &query, |
|
357 CaItemModel *itemModelPublic) : |
|
358 QObject(), m_q(itemModelPublic), mParentEntry(0), mQuery(query), |
|
359 mService(CaService::instance()), mEntries(mService), mNotifier(NULL), |
|
360 mSize(defaultIconSize), mSecondLineVisibility(true) |
|
361 { |
|
362 updateModel(); |
|
363 setAutoUpdate(true); |
|
364 } |
|
365 |
|
366 /*! |
|
367 Destructor |
|
368 */ |
|
369 CaItemModelPrivate::~CaItemModelPrivate() |
|
370 { |
|
371 mEntries.clear(); |
|
372 delete mParentEntry; |
|
373 delete mNotifier; |
|
374 } |
|
375 |
|
376 /*! |
|
377 Returns count of rows in model |
|
378 \retval number of rows |
|
379 */ |
|
380 int CaItemModelPrivate::rowCount() const |
|
381 { |
|
382 return mEntries.count(); |
|
383 } |
|
384 |
|
385 /*! |
|
386 Returns QModelIndex of an item |
|
387 \param row row |
|
388 \retval QModelIndex of item in model |
|
389 */ |
|
390 QModelIndex CaItemModelPrivate::index(int row) |
|
391 { |
|
392 if ((row >= 0) && (row < mEntries.count())) { |
|
393 return m_q->createIndex(row, 0); |
|
394 } else { |
|
395 return QModelIndex(); |
|
396 } |
|
397 } |
|
398 |
|
399 /*! |
|
400 Returns appropiate model's data |
|
401 \param modelIndex model index |
|
402 \param role which data role to return |
|
403 \retval models data as QVariant |
|
404 */ |
|
405 QVariant CaItemModelPrivate::data(const QModelIndex &modelIndex, |
|
406 int role) const |
|
407 { |
|
408 if (!modelIndex.isValid()) |
|
409 return QVariant(); |
|
410 |
|
411 switch (role) { |
|
412 case Qt::DisplayRole: |
|
413 return displayRole(modelIndex); |
|
414 case Qt::DecorationRole: |
|
415 return QVariant(QIcon(entry(modelIndex)->makeIcon(mSize))); |
|
416 case CaItemModel::IdRole: |
|
417 return QVariant(entry(modelIndex)->id()); |
|
418 case CaItemModel::TypeRole: |
|
419 return QVariant(entry(modelIndex)->entryTypeName()); |
|
420 case CaItemModel::FlagsRole: |
|
421 return qVariantFromValue(entry(modelIndex)->flags()); |
|
422 case CaItemModel::TextRole: |
|
423 return QVariant(entry(modelIndex)->text()); |
|
424 default: |
|
425 return QVariant(QVariant::Invalid); |
|
426 } |
|
427 } |
|
428 |
|
429 /*! |
|
430 Disables or enables auto-update feature of the model |
|
431 \param autoUpdate (HsMenuAutoUpdate) |
|
432 */ |
|
433 void CaItemModelPrivate::setAutoUpdate(bool autoUpdate) |
|
434 { |
|
435 if (autoUpdate) { |
|
436 if (!mNotifier) { |
|
437 CaNotifierFilter filter(mQuery); |
|
438 mNotifier = mService->createNotifier(filter); |
|
439 connectSlots(); |
|
440 } |
|
441 } else { |
|
442 disconnectSlots(); |
|
443 delete mNotifier; |
|
444 mNotifier = NULL; |
|
445 } |
|
446 } |
|
447 |
|
448 /*! |
|
449 Method for setting sorting order on model |
|
450 (probably will be moved to MenuService) |
|
451 \param sortOrder sorting order (SortAttribute) |
|
452 */ |
|
453 void CaItemModelPrivate::setSort(SortAttribute sortAttribute, |
|
454 Qt::SortOrder sortOrder) |
|
455 { |
|
456 mQuery.setSort(sortAttribute, sortOrder); |
|
457 updateLayout(); |
|
458 } |
|
459 |
|
460 /*! |
|
461 Method for setting icon size |
|
462 \param size icon size to display |
|
463 */ |
|
464 void CaItemModelPrivate::setIconSize(const QSize &size) |
|
465 { |
|
466 if (mSize == size) |
|
467 return; |
|
468 m_q->layoutAboutToBeChanged(); |
|
469 mSize = size; |
|
470 m_q->layoutChanged(); |
|
471 } |
|
472 |
|
473 /*! |
|
474 Method for getting icon size |
|
475 \retval icon size to display |
|
476 */ |
|
477 QSize CaItemModelPrivate::getIconSize() const |
|
478 { |
|
479 return mSize; |
|
480 } |
|
481 |
|
482 |
|
483 /*! |
|
484 Gets index of the parent item |
|
485 \retval QModelIndex representing root item |
|
486 */ |
|
487 QModelIndex CaItemModelPrivate::root() |
|
488 { |
|
489 if (mQuery.parentId()) { |
|
490 return m_q->createIndex(0, 1); |
|
491 } else { |
|
492 return QModelIndex(); |
|
493 } |
|
494 } |
|
495 |
|
496 /*! |
|
497 Returns an entry from model |
|
498 \param modelIndex index of entry in model |
|
499 \retval pointer to an entry |
|
500 */ |
|
501 CaEntry* CaItemModelPrivate::entry(const QModelIndex &modelIndex) const |
|
502 { |
|
503 if (modelIndex.column() == 1) { |
|
504 return mParentEntry; |
|
505 } else { |
|
506 return mEntries.at(modelIndex.row()); |
|
507 } |
|
508 } |
|
509 |
|
510 /*! |
|
511 Disables or enables secondline feature of the model |
|
512 \param secondLine disables or enables second line |
|
513 */ |
|
514 void CaItemModelPrivate::setSecondLineVisibility(bool secondLineVisibility) |
|
515 { |
|
516 if (mSecondLineVisibility == secondLineVisibility) |
|
517 return; |
|
518 m_q->layoutAboutToBeChanged(); |
|
519 mSecondLineVisibility = secondLineVisibility; |
|
520 m_q->layoutChanged(); |
|
521 } |
|
522 |
|
523 /*! |
|
524 Gets second line visibility attribute |
|
525 \retrun second line visibility attribute |
|
526 */ |
|
527 bool CaItemModelPrivate::secondLineVisibility() const |
|
528 { |
|
529 return mSecondLineVisibility; |
|
530 } |
|
531 |
|
532 /*! |
|
533 Returns proper display role for item |
|
534 \param modelIndex item index |
|
535 \retval QVariant containing display role |
|
536 */ |
|
537 QVariant CaItemModelPrivate::displayRole(const QModelIndex &modelIndex) const |
|
538 { |
|
539 QVariant result; |
|
540 if (mSecondLineVisibility) { |
|
541 if (entry(modelIndex)->description().isEmpty()) { |
|
542 result = entry(modelIndex)->text(); |
|
543 } else { |
|
544 QList<QVariant> text; |
|
545 text << entry(modelIndex)->text(); |
|
546 text << entry(modelIndex)->description(); |
|
547 result = QVariant(text); |
|
548 } |
|
549 } else { |
|
550 result = entry(modelIndex)->text(); |
|
551 } |
|
552 return result; |
|
553 } |
|
554 |
|
555 /*! |
|
556 Sets parent |
|
557 \param parentId |
|
558 */ |
|
559 void CaItemModelPrivate::setParentId(int parentId) |
|
560 { |
|
561 mQuery.setParentId(parentId); |
|
562 if (mNotifier) { |
|
563 delete mNotifier; |
|
564 mNotifier = mService->createNotifier(CaNotifierFilter(mQuery)); |
|
565 reconnectSlots(); |
|
566 } |
|
567 updateModel(); |
|
568 } |
|
569 |
|
570 |
|
571 /*! |
|
572 Checks if notifier exists |
|
573 \retval true if notifier exists otherwise false |
|
574 */ |
|
575 bool CaItemModelPrivate::notifierExists() const |
|
576 { |
|
577 if (mNotifier) { |
|
578 return true; |
|
579 } |
|
580 return false; |
|
581 } |
|
582 |
|
583 |
|
584 /*! |
|
585 Updates model with fresh entries and resets model |
|
586 */ |
|
587 void CaItemModelPrivate::updateModel() |
|
588 { |
|
589 mEntries.reloadEntries(mQuery); |
|
590 updateParentEntry(); |
|
591 m_q->reset(); |
|
592 } |
|
593 |
|
594 /*! |
|
595 Updates parent entry |
|
596 */ |
|
597 void CaItemModelPrivate::updateParentEntry() |
|
598 { |
|
599 if (mQuery.parentId()) { |
|
600 delete mParentEntry; |
|
601 mParentEntry = mService->getEntry(mQuery.parentId()); |
|
602 } |
|
603 } |
|
604 |
|
605 /*! |
|
606 Updates model item with fresh data |
|
607 \param id id of item to update |
|
608 */ |
|
609 void CaItemModelPrivate::updateItemData(int id) |
|
610 { |
|
611 mEntries.updateEntry(id); |
|
612 |
|
613 QList<int> ids = mService->getEntryIds(mQuery); |
|
614 if (mEntries.indexOf(id) >= 0 && ids.indexOf(id) |
|
615 == mEntries.indexOf(id)) { |
|
616 emit m_q->dataChanged(index(mEntries.indexOf(id)), index( |
|
617 mEntries.indexOf(id))); |
|
618 } else { |
|
619 if (mParentEntry && id == mParentEntry->id()) { |
|
620 updateParentEntry(); |
|
621 m_q->reset(); |
|
622 } else { |
|
623 updateLayout(); |
|
624 } |
|
625 } |
|
626 } |
|
627 |
|
628 /*! |
|
629 Adds new item to model |
|
630 \param id id of item to add |
|
631 */ |
|
632 void CaItemModelPrivate::addItem(int id) |
|
633 { |
|
634 int row = itemRow(id); |
|
635 //we use beginInsertRows and endInsertRows to emit proper signal |
|
636 //(see Qt documentation of QAbstractItemModel) |
|
637 if (mEntries.indexOf(id) < 0 && row >= 0) { |
|
638 m_q->beginInsertRows(QModelIndex(), row, row); |
|
639 mEntries.insert(row, id); |
|
640 m_q->endInsertRows(); |
|
641 } |
|
642 } |
|
643 |
|
644 /*! |
|
645 Adds new items to model |
|
646 \param itemsList current items list |
|
647 */ |
|
648 void CaItemModelPrivate::handleAddItems(QList<int> &itemsList) |
|
649 { |
|
650 int entriesCount = mEntries.count(); |
|
651 if (entriesCount) { |
|
652 int lastRow = itemsList.indexOf(mEntries[entriesCount - 1]); |
|
653 if (itemsList.count() == entriesCount && lastRow == (entriesCount |
|
654 - 1)) { |
|
655 //count is same and last item is in same position |
|
656 //so we update whole model |
|
657 updateModel(); |
|
658 } else if ((itemsList.count() - entriesCount) == 1 && lastRow |
|
659 == entriesCount) { |
|
660 //just one item added - collection |
|
661 int i = 0; |
|
662 for (i = 0; i < entriesCount; i++) { |
|
663 if (itemsList[i] != mEntries[i]) { |
|
664 addItem(itemsList[i]); |
|
665 } |
|
666 } |
|
667 while (i < itemsList.count()) { |
|
668 addItem(itemsList[i]); |
|
669 i++; |
|
670 } |
|
671 } else { |
|
672 //some items were inserted or reordered, |
|
673 //so we update layout and emit signal with row number |
|
674 //of first moved/added item |
|
675 //signal is needed to scroll a view to proper position after |
|
676 //some items were added |
|
677 updateLayout(); |
|
678 emit m_q->scrollTo(lastRow + 1, |
|
679 QAbstractItemView::PositionAtTop); |
|
680 } |
|
681 } else { |
|
682 updateModel(); |
|
683 } |
|
684 } |
|
685 |
|
686 /*! |
|
687 Gets index/row for new item |
|
688 \param id of item to add |
|
689 \retval row in model list for new item to insert |
|
690 */ |
|
691 int CaItemModelPrivate::itemRow(int id) |
|
692 { |
|
693 QList<int> ids = mService->getEntryIds(mQuery); |
|
694 return ids.indexOf(id); |
|
695 } |
|
696 |
|
697 /*! |
|
698 Removes item from model |
|
699 \param id of item to remove |
|
700 */ |
|
701 void CaItemModelPrivate::removeItem(int id) |
|
702 { |
|
703 int row = mEntries.indexOf(id); |
|
704 if (row >= 0) { |
|
705 m_q->beginRemoveRows(QModelIndex(), mEntries.indexOf(id), |
|
706 mEntries.indexOf(id)); |
|
707 mEntries.remove(id); |
|
708 m_q->endRemoveRows(); |
|
709 } |
|
710 } |
|
711 |
|
712 /*! |
|
713 Removes missing items from model |
|
714 \param itemsList current items list |
|
715 */ |
|
716 void CaItemModelPrivate::removeItems(const QList<int> &itemsList) |
|
717 { |
|
718 int i = 0; |
|
719 for (i = 0; i < itemsList.count(); i++) { |
|
720 if (itemsList[i] != mEntries[i]) { |
|
721 removeItem(mEntries[i]); |
|
722 } |
|
723 } |
|
724 while (i < mEntries.count()) { |
|
725 removeItem(mEntries[i]); |
|
726 i++; |
|
727 } |
|
728 } |
|
729 |
|
730 /*! |
|
731 Layout update |
|
732 */ |
|
733 void CaItemModelPrivate::updateLayout() |
|
734 { |
|
735 m_q->layoutAboutToBeChanged(); |
|
736 mEntries.updateEntries(mQuery); |
|
737 updateParentEntry(); |
|
738 m_q->layoutChanged(); |
|
739 } |
|
740 |
|
741 /*! |
|
742 Connects slots |
|
743 */ |
|
744 void CaItemModelPrivate::connectSlots() |
|
745 { |
|
746 connect(mNotifier, SIGNAL(entryChanged(int,ChangeType)), |
|
747 this, SLOT(updateModelItem(int,ChangeType)) ); |
|
748 |
|
749 if (mQuery.parentId() > 0) { |
|
750 connect(mNotifier, SIGNAL(groupContentChanged(int)), |
|
751 this, SLOT(updateModelContent(int)) ); |
|
752 } |
|
753 } |
|
754 |
|
755 /*! |
|
756 Disconnects slots |
|
757 */ |
|
758 void CaItemModelPrivate::disconnectSlots() |
|
759 { |
|
760 disconnect(mNotifier, SIGNAL(entryChanged(int,ChangeType)), |
|
761 this, SLOT(updateModelItem(int,ChangeType)) ); |
|
762 if (mQuery.parentId() > 0) { |
|
763 disconnect(mNotifier, SIGNAL(groupContentChanged(int)), |
|
764 this, SLOT(updateModelContent(int)) ); |
|
765 } |
|
766 } |
|
767 |
|
768 /*! |
|
769 Reconnects slots |
|
770 */ |
|
771 void CaItemModelPrivate::reconnectSlots() |
|
772 { |
|
773 disconnectSlots(); |
|
774 connectSlots(); |
|
775 } |
|
776 |
|
777 /*! |
|
778 Updates model with fresh entries |
|
779 \param id of item to handle |
|
780 \param changeType change type |
|
781 */ |
|
782 void CaItemModelPrivate::updateModelItem(int id, ChangeType changeType) |
|
783 { |
|
784 switch (changeType) { |
|
785 case AddChangeType: |
|
786 addItem(id); |
|
787 break; |
|
788 case RemoveChangeType: |
|
789 removeItem(id); |
|
790 break; |
|
791 default: |
|
792 updateItemData(id); |
|
793 break; |
|
794 } |
|
795 } |
|
796 |
|
797 /*! |
|
798 Updates model with fresh entries |
|
799 \param id of parent |
|
800 */ |
|
801 void CaItemModelPrivate::updateModelContent(int id) |
|
802 { |
|
803 Q_UNUSED(id); |
|
804 |
|
805 QList<int> ids = mService->getEntryIds(mQuery); |
|
806 |
|
807 if (ids.count() >= mEntries.count()) { |
|
808 handleAddItems(ids); |
|
809 } else { |
|
810 removeItems(ids); |
|
811 } |
|
812 } |