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