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