contentstorage/caclient/src/caitemmodel.cpp
changeset 87 9d806967057c
parent 86 e492551a0d54
child 89 1e87eb3b400f
equal deleted inserted replaced
86:e492551a0d54 87:9d806967057c
    19 
    19 
    20 #include "caitemmodel.h"
    20 #include "caitemmodel.h"
    21 #include "caitemmodel_p.h"
    21 #include "caitemmodel_p.h"
    22 #include "canotifier.h"
    22 #include "canotifier.h"
    23 #include "canotifierfilter.h"
    23 #include "canotifierfilter.h"
       
    24 #include "caclienttest_global.h"
    24 
    25 
    25 // Constants
    26 // Constants
    26 const QSize defaultIconSize(30, 30);
    27 const QSize defaultIconSize(30, 30);
    27 
    28 
    28 // ======== MEMBER FUNCTIONS ========
    29 // ======== MEMBER FUNCTIONS ========
    50 /*!
    51 /*!
    51  Constructor.
    52  Constructor.
    52  \param query query describing entries that should be present in a model.
    53  \param query query describing entries that should be present in a model.
    53  \param parent parent of a model
    54  \param parent parent of a model
    54  */
    55  */
    55 CaItemModel::CaItemModel(const CaQuery& query, QObject * parent) :
    56 CaItemModel::CaItemModel(const CaQuery &query, QObject *parent) :
    56     QAbstractItemModel(parent), m_d(new CaItemModelPrivate(query, this))
    57     QAbstractItemModel(parent), m_d(new CaItemModelPrivate(query, this))
    57 {
    58 {
    58 
    59 
    59 }
    60 }
    60 
    61 
   120  ...
   121  ...
   121  \endcode
   122  \endcode
   122 
   123 
   123  */
   124  */
   124 QModelIndex CaItemModel::index(int row, int column,
   125 QModelIndex CaItemModel::index(int row, int column,
   125     const QModelIndex &parent) const
   126                                const QModelIndex &parent) const
   126 {
   127 {
   127     Q_UNUSED(column);
   128     Q_UNUSED(column);
   128     Q_UNUSED(parent);
   129     Q_UNUSED(parent);
   129     return m_d->index(row);
   130     return m_d->index(row);
   130 }
   131 }
   261  ...
   262  ...
   262  \endcode
   263  \endcode
   263 
   264 
   264  */
   265  */
   265 void CaItemModel::setSort(SortAttribute sortAttribute,
   266 void CaItemModel::setSort(SortAttribute sortAttribute,
   266     Qt::SortOrder sortOrder)
   267                           Qt::SortOrder sortOrder)
   267 {
   268 {
   268     m_d->setSort(sortAttribute, sortOrder);
   269     m_d->setSort(sortAttribute, sortOrder);
   269 }
   270 }
   270 
   271 
   271 /*!
   272 /*!
   328 {
   329 {
   329     m_d->setParentId(parentId);
   330     m_d->setParentId(parentId);
   330 }
   331 }
   331 
   332 
   332 /*!
   333 /*!
       
   334  Sets flags to mQuery which should be enabled.
       
   335  This method does not update current model - only mQuery member.
       
   336  Now to do this setParentId have to be invoke.
       
   337  \param onFlags flags.
       
   338 
       
   339  \code
       
   340  ...
       
   341  // to set a flags enabled
       
   342  model->setFlagsOn(RemovableEntryFlag);
       
   343  ...
       
   344  \endcode
       
   345 
       
   346  */
       
   347 void CaItemModel::setFlagsOn(const EntryFlags &onFlags)
       
   348 {
       
   349     m_d->setFlagsOn(onFlags);
       
   350 }
       
   351 
       
   352 /*!
       
   353  Sets flags to mQuery which should be disabled.
       
   354  This method does not update current model - only mQuery member.
       
   355  Now to do this setParentId have to be invoke.
       
   356  \param offFlags flags.
       
   357 
       
   358  \code
       
   359  ...
       
   360  // to set a flags disabled
       
   361  model->setFlagsOff(RemovableEntryFlag);
       
   362  ...
       
   363  \endcode
       
   364 
       
   365  */
       
   366 void CaItemModel::setFlagsOff(const EntryFlags &offFlags)
       
   367 {
       
   368     m_d->setFlagsOff(offFlags);
       
   369 }
       
   370 
       
   371 /*!
   333  Returns an entry from model
   372  Returns an entry from model
   334  \param index of entry in model
   373  \param index of entry in model
   335  \retval pointer to an entry
   374  \retval pointer to an entry
   336 
   375 
   337  \code
   376  \code
   341  ...
   380  ...
   342  delete entry;
   381  delete entry;
   343  \endcode
   382  \endcode
   344 
   383 
   345  */
   384  */
   346 CaEntry* CaItemModel::entry(const QModelIndex &index) const
   385 CaEntry *CaItemModel::entry(const QModelIndex &index) const
   347 {
   386 {
   348     return m_d->entry(index);
   387     return m_d->entry(index);
   349 }
   388 }
   350 
   389 
   351 /*!
   390 /*!
   352  Constructor
   391  Constructor
   353  \param query needed to create model
   392  \param query needed to create model
   354  \param pointer to public implementation object connected
   393  \param pointer to public implementation object connected
   355  */
   394  */
   356 CaItemModelPrivate::CaItemModelPrivate(const CaQuery &query,
   395 CaItemModelPrivate::CaItemModelPrivate(const CaQuery &query,
   357     CaItemModel *itemModelPublic) :
   396                                        CaItemModel *itemModelPublic) :
   358     QObject(), m_q(itemModelPublic), mParentEntry(0), mQuery(query),
   397     QObject(), m_q(itemModelPublic), mParentEntry(0), mQuery(query),
   359     mService(CaService::instance()), mEntries(mService), mNotifier(NULL),
   398     mService(CaService::instance()), mEntries(mService), mNotifier(NULL),
   360     mSize(defaultIconSize), mSecondLineVisibility(true)
   399     mSize(defaultIconSize), mSecondLineVisibility(true)
   361 {
   400 {
   362     updateModel();
   401     updateModel();
   401  \param modelIndex model index
   440  \param modelIndex model index
   402  \param role which data role to return
   441  \param role which data role to return
   403  \retval models data as QVariant
   442  \retval models data as QVariant
   404  */
   443  */
   405 QVariant CaItemModelPrivate::data(const QModelIndex &modelIndex,
   444 QVariant CaItemModelPrivate::data(const QModelIndex &modelIndex,
   406     int role) const
   445                                   int role) const
   407 {
   446 {
   408     if (!modelIndex.isValid())
   447     CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::data");
   409         return QVariant();
   448     QVariant variant;
   410 
   449     if (modelIndex.isValid()) {
   411     switch (role) {
   450         switch (role) {
   412     case Qt::DisplayRole:
   451         case Qt::DisplayRole:
   413         return displayRole(modelIndex);
   452             variant = displayRole(modelIndex);
   414     case Qt::DecorationRole:
   453             break;
   415         return QVariant(HbIcon(entry(modelIndex)->makeIcon(mSize)));
   454         case Qt::DecorationRole:
   416     case CaItemModel::IdRole:
   455             variant = QVariant(HbIcon(entry(modelIndex)->makeIcon(mSize)));
   417         return QVariant(entry(modelIndex)->id());
   456             break;
   418     case CaItemModel::TypeRole:
   457         case CaItemModel::IdRole:
   419         return QVariant(entry(modelIndex)->entryTypeName());
   458             variant = QVariant(entry(modelIndex)->id());
   420     case CaItemModel::FlagsRole:
   459             break;
   421         return qVariantFromValue(entry(modelIndex)->flags());
   460         case CaItemModel::TypeRole:
   422     case CaItemModel::TextRole:
   461             variant = QVariant(entry(modelIndex)->entryTypeName());
   423         return QVariant(entry(modelIndex)->text());
   462             break;
   424     default:
   463         case CaItemModel::FlagsRole:
   425         return QVariant(QVariant::Invalid);
   464             variant = qVariantFromValue(entry(modelIndex)->flags());
   426     }
   465             break;
       
   466         case CaItemModel::TextRole:
       
   467             variant = QVariant(entry(modelIndex)->text());
       
   468             break;
       
   469         default:
       
   470             variant = QVariant(QVariant::Invalid);
       
   471         }
       
   472     }
       
   473     CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::data");
       
   474     return variant;
   427 }
   475 }
   428 
   476 
   429 /*!
   477 /*!
   430  Disables or enables auto-update feature of the model
   478  Disables or enables auto-update feature of the model
   431  \param autoUpdate (HsMenuAutoUpdate)
   479  \param autoUpdate (HsMenuAutoUpdate)
   432  */
   480  */
   433 void CaItemModelPrivate::setAutoUpdate(bool autoUpdate)
   481 void CaItemModelPrivate::setAutoUpdate(bool autoUpdate)
   434 {
   482 {
       
   483     CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::setAutoUpdate");
   435     if (autoUpdate) {
   484     if (autoUpdate) {
   436         if (!mNotifier) {
   485         if (!mNotifier) {
   437             CaNotifierFilter filter(mQuery);
   486             CaNotifierFilter filter(mQuery);
   438             mNotifier = mService->createNotifier(filter);
   487             mNotifier = mService->createNotifier(filter);
   439             connectSlots();
   488             connectSlots();
   441     } else {
   490     } else {
   442         disconnectSlots();
   491         disconnectSlots();
   443         delete mNotifier;
   492         delete mNotifier;
   444         mNotifier = NULL;
   493         mNotifier = NULL;
   445     }
   494     }
       
   495     CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::setAutoUpdate");
   446 }
   496 }
   447 
   497 
   448 /*!
   498 /*!
   449  Method for setting sorting order on model
   499  Method for setting sorting order on model
   450  (probably will be moved to MenuService)
   500  (probably will be moved to MenuService)
   451  \param  sortOrder sorting order (SortAttribute)
   501  \param  sortOrder sorting order (SortAttribute)
   452  */
   502  */
   453 void CaItemModelPrivate::setSort(SortAttribute sortAttribute,
   503 void CaItemModelPrivate::setSort(SortAttribute sortAttribute,
   454     Qt::SortOrder sortOrder)
   504                                  Qt::SortOrder sortOrder)
   455 {
   505 {
       
   506     CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::setSort");
   456     mQuery.setSort(sortAttribute, sortOrder);
   507     mQuery.setSort(sortAttribute, sortOrder);
   457     updateLayout();
   508     updateLayout();
       
   509     CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::setSort");
   458 }
   510 }
   459 
   511 
   460 /*!
   512 /*!
   461  Method for setting icon size
   513  Method for setting icon size
   462  \param size icon size to display
   514  \param size icon size to display
   496 /*!
   548 /*!
   497  Returns an entry from model
   549  Returns an entry from model
   498  \param modelIndex index of entry in model
   550  \param modelIndex index of entry in model
   499  \retval pointer to an entry
   551  \retval pointer to an entry
   500  */
   552  */
   501 CaEntry* CaItemModelPrivate::entry(const QModelIndex &modelIndex) const
   553 CaEntry *CaItemModelPrivate::entry(const QModelIndex &modelIndex) const
   502 {
   554 {
   503     if (modelIndex.column() == 1) {
   555     if (modelIndex.column() == 1) {
   504         return mParentEntry;
   556         return mParentEntry;
   505     } else {
   557     } else {
   506         return mEntries.at(modelIndex.row());
   558         return mEntries.at(modelIndex.row());
   534  \param modelIndex item index
   586  \param modelIndex item index
   535  \retval QVariant containing display role
   587  \retval QVariant containing display role
   536  */
   588  */
   537 QVariant CaItemModelPrivate::displayRole(const QModelIndex &modelIndex) const
   589 QVariant CaItemModelPrivate::displayRole(const QModelIndex &modelIndex) const
   538 {
   590 {
       
   591     CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::displayRole")
       
   592 
   539     QVariant result;
   593     QVariant result;
   540     if (mSecondLineVisibility) {
   594     if (mSecondLineVisibility) {
   541         if (entry(modelIndex)->description().isEmpty()) {
   595         if (entry(modelIndex)->description().isEmpty()) {
   542             result = entry(modelIndex)->text();
   596             result = entry(modelIndex)->text();
   543         } else {
   597         } else {
   547             result = QVariant(text);
   601             result = QVariant(text);
   548         }
   602         }
   549     } else {
   603     } else {
   550         result = entry(modelIndex)->text();
   604         result = entry(modelIndex)->text();
   551     }
   605     }
       
   606     CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::displayRole")
   552     return result;
   607     return result;
   553 }
   608 }
   554 
   609 
   555 /*!
   610 /*!
   556  Sets parent
   611  Sets parent
   557  \param parentId
   612  \param parentId
   558  */
   613  */
   559 void CaItemModelPrivate::setParentId(int parentId)
   614 void CaItemModelPrivate::setParentId(int parentId)
   560 {
   615 {
       
   616     CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::setParentId");
   561     mQuery.setParentId(parentId);
   617     mQuery.setParentId(parentId);
   562     if (mNotifier) {
   618     if (mNotifier) {
   563         delete mNotifier;
   619         delete mNotifier;
   564         mNotifier = mService->createNotifier(CaNotifierFilter(mQuery));
   620         mNotifier = mService->createNotifier(CaNotifierFilter(mQuery));
   565         reconnectSlots();
   621         reconnectSlots();
   566     }
   622     }
   567     updateModel();
   623     updateModel();
   568 }
   624     CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::setParentId");
   569 
   625 
       
   626 }
       
   627 
       
   628 /*!
       
   629  Sets flags to mQuery which should be enabled.
       
   630  \param onFlags flags.
       
   631 
       
   632   */
       
   633 void CaItemModelPrivate::setFlagsOn(const EntryFlags &onFlags)
       
   634 {
       
   635     mQuery.setFlagsOn(onFlags);
       
   636 }
       
   637 
       
   638 /*!
       
   639  Sets flags to mQuery which should be disabled.
       
   640  \param offFlags flags.
       
   641 
       
   642  \code
       
   643  ...
       
   644  // to set a new parent id
       
   645  model->setFlagsOff(RemovableEntryFlag);
       
   646  ...
       
   647  \endcode
       
   648 
       
   649  */
       
   650 void CaItemModelPrivate::setFlagsOff(const EntryFlags &offFlags)
       
   651 {
       
   652     mQuery.setFlagsOff(offFlags);
       
   653 }
   570 
   654 
   571 /*!
   655 /*!
   572  Checks if notifier exists
   656  Checks if notifier exists
   573   \retval true if notifier exists otherwise false
   657   \retval true if notifier exists otherwise false
   574  */
   658  */
   584 /*!
   668 /*!
   585  Updates model with fresh entries and resets model
   669  Updates model with fresh entries and resets model
   586  */
   670  */
   587 void CaItemModelPrivate::updateModel()
   671 void CaItemModelPrivate::updateModel()
   588 {
   672 {
       
   673     CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::updateModel");
       
   674 
   589     mEntries.reloadEntries(mQuery);
   675     mEntries.reloadEntries(mQuery);
   590     updateParentEntry();
   676     updateParentEntry();
   591     m_q->reset();
   677     m_q->reset();
       
   678 
       
   679     CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::updateModel");
   592 }
   680 }
   593 
   681 
   594 /*!
   682 /*!
   595  Updates parent entry
   683  Updates parent entry
   596  */
   684  */
   597 void CaItemModelPrivate::updateParentEntry()
   685 void CaItemModelPrivate::updateParentEntry()
   598 {
   686 {
       
   687     CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::updateParentEntry");
       
   688 
   599     if (mQuery.parentId()) {
   689     if (mQuery.parentId()) {
   600         delete mParentEntry;
   690         delete mParentEntry;
   601         mParentEntry = mService->getEntry(mQuery.parentId());
   691         mParentEntry = mService->getEntry(mQuery.parentId());
   602     }
   692     }
       
   693 
       
   694     CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::updateParentEntry");
       
   695 
   603 }
   696 }
   604 
   697 
   605 /*!
   698 /*!
   606  Updates model item with fresh data
   699  Updates model item with fresh data
   607  \param id id of item to update
   700  \param id id of item to update
   608  */
   701  */
   609 void CaItemModelPrivate::updateItemData(int id)
   702 void CaItemModelPrivate::updateItemData(int id)
   610 {
   703 {
       
   704     CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::updateItemData");
       
   705 
   611     mEntries.updateEntry(id);
   706     mEntries.updateEntry(id);
   612 
   707 
   613     QList<int> ids = mService->getEntryIds(mQuery);
   708     QList<int> ids = mService->getEntryIds(mQuery);
   614     if (mEntries.indexOf(id) >= 0 && ids.indexOf(id)
   709     if (mEntries.indexOf(id) >= 0 && ids.indexOf(id)
   615         == mEntries.indexOf(id)) {
   710             == mEntries.indexOf(id)) {
   616         emit m_q->dataChanged(index(mEntries.indexOf(id)), index(
   711         emit m_q->dataChanged(index(mEntries.indexOf(id)), index(
   617             mEntries.indexOf(id)));
   712                                   mEntries.indexOf(id)));
   618     } else {
   713     } else {
   619         if (mParentEntry && id == mParentEntry->id()) {
   714         if (mParentEntry && id == mParentEntry->id()) {
   620             updateParentEntry();
   715             updateParentEntry();
   621             m_q->reset();
   716             m_q->reset();
   622         } else {
   717         } else {
   623             updateLayout();
   718             updateLayout();
   624         }
   719         }
   625     }
   720     }
       
   721     CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::updateItemData");
   626 }
   722 }
   627 
   723 
   628 /*!
   724 /*!
   629  Adds new item to model
   725  Adds new item to model
   630  \param id id of item to add
   726  \param id id of item to add
   631  */
   727  */
   632 void CaItemModelPrivate::addItem(int id)
   728 void CaItemModelPrivate::addItem(int id)
   633 {
   729 {
       
   730     CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::addItem");
       
   731 
   634     int row = itemRow(id);
   732     int row = itemRow(id);
   635     //we use beginInsertRows and endInsertRows to emit proper signal
   733     //we use beginInsertRows and endInsertRows to emit proper signal
   636     //(see Qt documentation of QAbstractItemModel)
   734     //(see Qt documentation of QAbstractItemModel)
   637     if (mEntries.indexOf(id) < 0 && row >= 0) {
   735     if (mEntries.indexOf(id) < 0 && row >= 0) {
   638         m_q->beginInsertRows(QModelIndex(), row, row);
   736         m_q->beginInsertRows(QModelIndex(), row, row);
   639         mEntries.insert(row, id);
   737         mEntries.insert(row, id);
   640         m_q->endInsertRows();
   738         m_q->endInsertRows();
   641     }
   739     }
       
   740     CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::addItem");
   642 }
   741 }
   643 
   742 
   644 /*!
   743 /*!
   645  Adds new items to model
   744  Adds new items to model
   646  \param itemsList current items list
   745  \param itemsList current items list
   647  */
   746  */
   648 void CaItemModelPrivate::handleAddItems(QList<int> &itemsList)
   747 void CaItemModelPrivate::handleAddItems(QList<int> &itemsList)
   649 {
   748 {
       
   749     CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::handleAddItems");
       
   750 
   650     int entriesCount = mEntries.count();
   751     int entriesCount = mEntries.count();
   651     if (entriesCount) {
   752     if (entriesCount) {
   652         int lastRow = itemsList.indexOf(mEntries[entriesCount - 1]);
   753         int lastRow = itemsList.indexOf(mEntries[entriesCount - 1]);
   653         if (itemsList.count() == entriesCount && lastRow == (entriesCount
   754         if (itemsList.count() == entriesCount && lastRow == (entriesCount
   654             - 1)) {
   755                 - 1)) {
   655             //count is same and last item is in same position
   756             //count is same and last item is in same position
   656             //so we update whole model
   757             //so we update whole model
   657             updateModel();
   758             updateModel();
   658         } else if ((itemsList.count() - entriesCount) == 1 && lastRow
   759         } else if ((itemsList.count() - entriesCount) == 1 && lastRow
   659             == entriesCount) {
   760                    == entriesCount) {
   660             //just one item added - collection
   761             //just one item added - collection
   661             int i = 0;
   762             int i = 0;
   662             for (i = 0; i < entriesCount; i++) {
   763             for (i = 0; i < entriesCount; i++) {
   663                 if (itemsList[i] != mEntries[i]) {
   764                 if (itemsList[i] != mEntries[i]) {
   664                     addItem(itemsList[i]);
   765                     addItem(itemsList[i]);
       
   766                     updateLayout();
       
   767                     emit m_q->scrollTo(i,
       
   768                                        QAbstractItemView::PositionAtTop);
   665                 }
   769                 }
   666             }
   770             }
   667             while (i < itemsList.count()) {
   771             while (i < itemsList.count()) {
   668                 addItem(itemsList[i]);
   772                 addItem(itemsList[i]);
   669                 i++;
   773                 i++;
   674             //of first moved/added item
   778             //of first moved/added item
   675             //signal is needed to scroll a view to proper position after
   779             //signal is needed to scroll a view to proper position after
   676             //some items were added
   780             //some items were added
   677             updateLayout();
   781             updateLayout();
   678             emit m_q->scrollTo(lastRow + 1,
   782             emit m_q->scrollTo(lastRow + 1,
   679                 QAbstractItemView::PositionAtTop);
   783                                QAbstractItemView::PositionAtTop);
   680         }
   784         }
   681     } else {
   785     } else {
   682         updateModel();
   786         updateModel();
   683     }
   787     }
       
   788     CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::handleAddItems");
   684 }
   789 }
   685 
   790 
   686 /*!
   791 /*!
   687  Gets index/row for new item
   792  Gets index/row for new item
   688  \param id of item to add
   793  \param id of item to add
   689  \retval row in model list for new item to insert
   794  \retval row in model list for new item to insert
   690  */
   795  */
   691 int CaItemModelPrivate::itemRow(int id)
   796 int CaItemModelPrivate::itemRow(int id)
   692 {
   797 {
       
   798     CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::itemRow");
   693     QList<int> ids = mService->getEntryIds(mQuery);
   799     QList<int> ids = mService->getEntryIds(mQuery);
       
   800     CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::itemRow");
   694     return ids.indexOf(id);
   801     return ids.indexOf(id);
   695 }
   802 }
   696 
   803 
   697 /*!
   804 /*!
   698  Removes item from model
   805  Removes item from model
   699  \param id of item to remove
   806  \param id of item to remove
   700  */
   807  */
   701 void CaItemModelPrivate::removeItem(int id)
   808 void CaItemModelPrivate::removeItem(int id)
   702 {
   809 {
       
   810     CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::removeItem");
   703     int row = mEntries.indexOf(id);
   811     int row = mEntries.indexOf(id);
   704     if (row >= 0) {
   812     if (row >= 0) {
   705         m_q->beginRemoveRows(QModelIndex(), mEntries.indexOf(id),
   813         m_q->beginRemoveRows(QModelIndex(), mEntries.indexOf(id),
   706             mEntries.indexOf(id));
   814                              mEntries.indexOf(id));
   707         mEntries.remove(id);
   815         mEntries.remove(id);
   708         m_q->endRemoveRows();
   816         m_q->endRemoveRows();
   709     }
   817     } else {
       
   818         updateLayout();
       
   819     }
       
   820     
       
   821     CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::removeItem");
   710 }
   822 }
   711 
   823 
   712 /*!
   824 /*!
   713  Removes missing items from model
   825  Removes missing items from model
   714  \param itemsList current items list
   826  \param itemsList current items list
   715  */
   827  */
   716 void CaItemModelPrivate::removeItems(const QList<int> &itemsList)
   828 void CaItemModelPrivate::removeItems(const QList<int> &itemsList)
   717 {
   829 {
       
   830     CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::removeItems");
   718     int i = 0;
   831     int i = 0;
   719     for (i = 0; i < itemsList.count(); i++) {
   832     for (i = 0; i < itemsList.count(); i++) {
   720         if (itemsList[i] != mEntries[i]) {
   833         if (itemsList[i] != mEntries[i]) {
   721             removeItem(mEntries[i]);
   834             removeItem(mEntries[i]);
   722         }
   835         }
   723     }
   836     }
   724     while (i < mEntries.count()) {
   837     while (i < mEntries.count()) {
   725         removeItem(mEntries[i]);
   838         removeItem(mEntries[i]);
   726         i++;
   839         i++;
   727     }
   840     }
       
   841     CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::removeItems");
   728 }
   842 }
   729 
   843 
   730 /*!
   844 /*!
   731  Layout update
   845  Layout update
   732  */
   846  */
   733 void CaItemModelPrivate::updateLayout()
   847 void CaItemModelPrivate::updateLayout()
   734 {
   848 {
       
   849     CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::updateLayout");
   735     m_q->layoutAboutToBeChanged();
   850     m_q->layoutAboutToBeChanged();
   736     mEntries.updateEntries(mQuery);
   851     mEntries.updateEntries(mQuery);
   737     updateParentEntry();
   852     updateParentEntry();
   738     m_q->layoutChanged();
   853     m_q->layoutChanged();
       
   854     CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::updateLayout");
   739 }
   855 }
   740 
   856 
   741 /*!
   857 /*!
   742  Connects slots
   858  Connects slots
   743  */
   859  */
   744 void CaItemModelPrivate::connectSlots()
   860 void CaItemModelPrivate::connectSlots()
   745 {
   861 {
       
   862     CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::connectSlots");
   746     connect(mNotifier, SIGNAL(entryChanged(int,ChangeType)),
   863     connect(mNotifier, SIGNAL(entryChanged(int,ChangeType)),
   747     this, SLOT(updateModelItem(int,ChangeType)) );
   864             this, SLOT(updateModelItem(int,ChangeType)));
   748 
   865 
   749     if (mQuery.parentId() > 0) {
   866     if (mQuery.parentId() > 0) {
   750         connect(mNotifier, SIGNAL(groupContentChanged(int)),
   867         connect(mNotifier, SIGNAL(groupContentChanged(int)),
   751         this, SLOT(updateModelContent(int)) );
   868                 this, SLOT(updateModelContent(int)));
   752     }
   869     }
       
   870     CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::connectSlots");
   753 }
   871 }
   754 
   872 
   755 /*!
   873 /*!
   756  Disconnects slots
   874  Disconnects slots
   757  */
   875  */
   758 void CaItemModelPrivate::disconnectSlots()
   876 void CaItemModelPrivate::disconnectSlots()
   759 {
   877 {
       
   878     CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::disconnectSlots");
   760     disconnect(mNotifier, SIGNAL(entryChanged(int,ChangeType)),
   879     disconnect(mNotifier, SIGNAL(entryChanged(int,ChangeType)),
   761     this, SLOT(updateModelItem(int,ChangeType)) );
   880                this, SLOT(updateModelItem(int,ChangeType)));
   762     if (mQuery.parentId() > 0) {
   881     if (mQuery.parentId() > 0) {
   763         disconnect(mNotifier, SIGNAL(groupContentChanged(int)),
   882         disconnect(mNotifier, SIGNAL(groupContentChanged(int)),
   764         this, SLOT(updateModelContent(int)) );
   883                    this, SLOT(updateModelContent(int)));
   765     }
   884     }
       
   885     CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::disconnectSlots");
   766 }
   886 }
   767 
   887 
   768 /*!
   888 /*!
   769  Reconnects slots
   889  Reconnects slots
   770  */
   890  */
   771 void CaItemModelPrivate::reconnectSlots()
   891 void CaItemModelPrivate::reconnectSlots()
   772 {
   892 {
       
   893     CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::reconnectSlots");
   773     disconnectSlots();
   894     disconnectSlots();
   774     connectSlots();
   895     connectSlots();
       
   896     CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::reconnectSlots");
   775 }
   897 }
   776 
   898 
   777 /*!
   899 /*!
   778  Updates model with fresh entries
   900  Updates model with fresh entries
   779  \param id of item to handle
   901  \param id of item to handle
   780  \param changeType change type
   902  \param changeType change type
   781  */
   903  */
   782 void CaItemModelPrivate::updateModelItem(int id, ChangeType changeType)
   904 void CaItemModelPrivate::updateModelItem(int id, ChangeType changeType)
   783 {
   905 {
       
   906     CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::updateModelItem");
   784     switch (changeType) {
   907     switch (changeType) {
   785     case AddChangeType:
   908     case AddChangeType:
   786         addItem(id);
   909         addItem(id);
   787         break;
   910         break;
   788     case RemoveChangeType:
   911     case RemoveChangeType:
   790         break;
   913         break;
   791     default:
   914     default:
   792         updateItemData(id);
   915         updateItemData(id);
   793         break;
   916         break;
   794     }
   917     }
       
   918     CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::updateModelItem");
   795 }
   919 }
   796 
   920 
   797 /*!
   921 /*!
   798  Updates model with fresh entries
   922  Updates model with fresh entries
   799  \param id of parent
   923  \param id of parent
   800  */
   924  */
   801 void CaItemModelPrivate::updateModelContent(int id)
   925 void CaItemModelPrivate::updateModelContent(int id)
   802 {
   926 {
   803     Q_UNUSED(id);
   927     Q_UNUSED(id);
   804 
   928     CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::updateModelContent");
   805     QList<int> ids = mService->getEntryIds(mQuery);
   929     QList<int> ids = mService->getEntryIds(mQuery);
   806 
   930 
   807     if (ids.count() >= mEntries.count()) {
   931     if (ids.count() >= mEntries.count()) {
   808         handleAddItems(ids);
   932         handleAddItems(ids);
   809     } else {
   933     } else {
   810         removeItems(ids);
   934         removeItems(ids);
   811     }
   935     }
   812 }
   936     CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::updateModelContent");
       
   937 }