~chris.gagnon/+junk/qtpim-coverage

« back to all changes in this revision

Viewing changes to src/organizer/qorganizeritemchangeset.cpp

  • Committer: chris.gagnon
  • Date: 2013-12-10 23:09:37 UTC
  • Revision ID: chris.gagnon@canonical.com-20131210230937-2akf1ft1edcttk87
first post

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the QtOrganizer module of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:LGPL$
 
9
** Commercial License Usage
 
10
** Licensees holding valid commercial Qt licenses may use this file in
 
11
** accordance with the commercial license agreement provided with the
 
12
** Software or, alternatively, in accordance with the terms contained in
 
13
** a written agreement between you and Digia.  For licensing terms and
 
14
** conditions see http://qt.digia.com/licensing.  For further information
 
15
** use the contact form at http://qt.digia.com/contact-us.
 
16
**
 
17
** GNU Lesser General Public License Usage
 
18
** Alternatively, this file may be used under the terms of the GNU Lesser
 
19
** General Public License version 2.1 as published by the Free Software
 
20
** Foundation and appearing in the file LICENSE.LGPL included in the
 
21
** packaging of this file.  Please review the following information to
 
22
** ensure the GNU Lesser General Public License version 2.1 requirements
 
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
24
**
 
25
** In addition, as a special exception, Digia gives you certain additional
 
26
** rights.  These rights are described in the Digia Qt LGPL Exception
 
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
28
**
 
29
** GNU General Public License Usage
 
30
** Alternatively, this file may be used under the terms of the GNU
 
31
** General Public License version 3.0 as published by the Free Software
 
32
** Foundation and appearing in the file LICENSE.GPL included in the
 
33
** packaging of this file.  Please review the following information to
 
34
** ensure the GNU General Public License version 3.0 requirements will be
 
35
** met: http://www.gnu.org/copyleft/gpl.html.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#include <qorganizeritemchangeset.h>
 
43
#include <private/qorganizeritemchangeset_p.h>
 
44
#include <qorganizermanagerengine.h>
 
45
 
 
46
QT_BEGIN_NAMESPACE_ORGANIZER
 
47
 
 
48
/*!
 
49
    \class QOrganizerItemChangeSet
 
50
    \brief The QOrganizerItemChangeSet class provides a simple API to simplify the emission of
 
51
           state-change signals for items from QOrganizerManagerEngine implementations.
 
52
    \inmodule QtOrganizer
 
53
    \ingroup organizer-backends
 
54
 
 
55
    This class should only be used by backend developers.
 
56
 */
 
57
 
 
58
/*!
 
59
    Constructs a new change set.
 
60
 */
 
61
QOrganizerItemChangeSet::QOrganizerItemChangeSet()
 
62
    : d(new QOrganizerItemChangeSetData)
 
63
{
 
64
}
 
65
 
 
66
/*!
 
67
    Constructs a copy of the \a other change set.
 
68
 */
 
69
QOrganizerItemChangeSet::QOrganizerItemChangeSet(const QOrganizerItemChangeSet &other)
 
70
    : d(other.d)
 
71
{
 
72
}
 
73
 
 
74
/*!
 
75
    Frees the memory used by this change set.
 
76
 */
 
77
QOrganizerItemChangeSet::~QOrganizerItemChangeSet()
 
78
{
 
79
}
 
80
 
 
81
/*!
 
82
    Assigns this change set to be equal to \a other.
 
83
 */
 
84
QOrganizerItemChangeSet &QOrganizerItemChangeSet::operator=(const QOrganizerItemChangeSet &other)
 
85
{
 
86
    d = other.d;
 
87
    return *this;
 
88
}
 
89
 
 
90
/*!
 
91
    Sets the data changed flag to \a dataChanged.
 
92
 
 
93
    If this is set to true prior to calling emitSignals(), only the QOrganizerManagerEngine::dataChanged()
 
94
    signal will be emitted; otherwise, the appropriate finer-grained signals will be emitted.
 
95
 */
 
96
void QOrganizerItemChangeSet::setDataChanged(bool dataChanged)
 
97
{
 
98
    d->m_dataChanged = dataChanged;
 
99
}
 
100
 
 
101
/*!
 
102
    Returns the value of the data changed flag.
 
103
 */
 
104
bool QOrganizerItemChangeSet::dataChanged() const
 
105
{
 
106
    return d->m_dataChanged;
 
107
}
 
108
 
 
109
/*!
 
110
    Returns the set of IDs of organizer items which have been added to the database.
 
111
 */
 
112
QSet<QOrganizerItemId> QOrganizerItemChangeSet::addedItems() const
 
113
{
 
114
    return d->m_addedItems;
 
115
}
 
116
 
 
117
/*!
 
118
    Inserts the given \a itemId into the set of ids of organizer items which have been added to the
 
119
    database.
 
120
 */
 
121
void QOrganizerItemChangeSet::insertAddedItem(const QOrganizerItemId &itemId)
 
122
{
 
123
    d->m_addedItems.insert(itemId);
 
124
    d->m_modifiedItems.append(QPair<QOrganizerItemId, QOrganizerManager::Operation>(itemId, QOrganizerManager::Add));
 
125
}
 
126
 
 
127
/*!
 
128
    Inserts each of the given \a itemIds into the set of IDs of organizer items which have been added
 
129
    to the database.
 
130
 */
 
131
void QOrganizerItemChangeSet::insertAddedItems(const QList<QOrganizerItemId> &itemIds)
 
132
{
 
133
    foreach (const QOrganizerItemId &id, itemIds) {
 
134
        d->m_addedItems.insert(id);
 
135
        d->m_modifiedItems.append(QPair<QOrganizerItemId, QOrganizerManager::Operation>(id, QOrganizerManager::Add));
 
136
    }
 
137
}
 
138
 
 
139
/*!
 
140
    Clears the set of IDs of organizer items which have been added to the database.
 
141
 */
 
142
void QOrganizerItemChangeSet::clearAddedItems()
 
143
{
 
144
    d->m_addedItems.clear();
 
145
}
 
146
 
 
147
/*!
 
148
    Returns the set of IDs of organizer items which have been changed in the database.
 
149
 */
 
150
QSet<QOrganizerItemId> QOrganizerItemChangeSet::changedItems() const
 
151
{
 
152
    return d->m_changedItems;
 
153
}
 
154
 
 
155
/*!
 
156
    Inserts the given \a itemId into the set of IDs of organizer items which have been changed in
 
157
    the database.
 
158
 */
 
159
void QOrganizerItemChangeSet::insertChangedItem(const QOrganizerItemId &itemId)
 
160
{
 
161
    d->m_changedItems.insert(itemId);
 
162
    d->m_modifiedItems.append(QPair<QOrganizerItemId, QOrganizerManager::Operation>(itemId, QOrganizerManager::Change));
 
163
}
 
164
 
 
165
/*!
 
166
    Inserts each of the given \a itemIds into the set of IDs of organizer items which have been
 
167
    changed in the database.
 
168
 */
 
169
void QOrganizerItemChangeSet::insertChangedItems(const QList<QOrganizerItemId> &itemIds)
 
170
{
 
171
    foreach (const QOrganizerItemId &id, itemIds) {
 
172
        d->m_changedItems.insert(id);
 
173
        d->m_modifiedItems.append(QPair<QOrganizerItemId, QOrganizerManager::Operation>(id, QOrganizerManager::Change));
 
174
    }
 
175
}
 
176
 
 
177
/*!
 
178
    Clears the set of IDs of organizer items which have been changed in the database.
 
179
 */
 
180
void QOrganizerItemChangeSet::clearChangedItems()
 
181
{
 
182
    d->m_changedItems.clear();
 
183
}
 
184
 
 
185
/*!
 
186
    Returns the set of IDs of organizer items which have been removed from the database.
 
187
 */
 
188
QSet<QOrganizerItemId> QOrganizerItemChangeSet::removedItems() const
 
189
{
 
190
    return d->m_removedItems;
 
191
}
 
192
 
 
193
/*!
 
194
    Inserts the given \a itemId into the set of IDs of organizer items which have been removed from
 
195
    the database.
 
196
 */
 
197
void QOrganizerItemChangeSet::insertRemovedItem(const QOrganizerItemId &itemId)
 
198
{
 
199
    d->m_removedItems.insert(itemId);
 
200
    d->m_modifiedItems.append(QPair<QOrganizerItemId, QOrganizerManager::Operation>(itemId, QOrganizerManager::Remove));
 
201
}
 
202
 
 
203
/*!
 
204
    Inserts each of the given \a itemIds into the set of IDs of organizer items which have been
 
205
    removed from the database.
 
206
 */
 
207
void QOrganizerItemChangeSet::insertRemovedItems(const QList<QOrganizerItemId> &itemIds)
 
208
{
 
209
    foreach (const QOrganizerItemId &id, itemIds) {
 
210
        d->m_removedItems.insert(id);
 
211
        d->m_modifiedItems.append(QPair<QOrganizerItemId, QOrganizerManager::Operation>(id, QOrganizerManager::Remove));
 
212
    }
 
213
}
 
214
 
 
215
/*!
 
216
    Clears the set of IDs of organizer items which have been removed from the database.
 
217
 */
 
218
void QOrganizerItemChangeSet::clearRemovedItems()
 
219
{
 
220
    d->m_removedItems.clear();
 
221
}
 
222
 
 
223
/*!
 
224
   Returns the list of ids of organizer items which have been added, changed or removed from
 
225
   the database. The list includes information about which database operation was done. The ids and
 
226
   operations are ordered so that the first operation is first in the list.
 
227
 */
 
228
QList<QPair<QOrganizerItemId, QOrganizerManager::Operation> > QOrganizerItemChangeSet::modifiedItems() const
 
229
{
 
230
    return d->m_modifiedItems;
 
231
}
 
232
 
 
233
/*!
 
234
  Clears the list of ids of organizer items which have been added, changed or removed from the database
 
235
 */
 
236
void QOrganizerItemChangeSet::clearModifiedItems()
 
237
{
 
238
    d->m_modifiedItems.clear();
 
239
}
 
240
 
 
241
/*!
 
242
    Clears all flags and sets of IDs in this change set.
 
243
 */
 
244
void QOrganizerItemChangeSet::clearAll()
 
245
{
 
246
    d->m_dataChanged = false;
 
247
    d->m_addedItems.clear();
 
248
    d->m_changedItems.clear();
 
249
    d->m_removedItems.clear();
 
250
    d->m_modifiedItems.clear();
 
251
}
 
252
 
 
253
/*!
 
254
    Emits the appropriate signals from the given \a engine given the state of the change set. Note
 
255
    that the flags and sets of IDs are not cleared after signals are emitted.
 
256
 */
 
257
void QOrganizerItemChangeSet::emitSignals(QOrganizerManagerEngine *engine) const
 
258
{
 
259
    if (!engine)
 
260
        return;
 
261
 
 
262
    if (d->m_dataChanged) {
 
263
        emit engine->dataChanged();
 
264
    } else {
 
265
        if (!d->m_addedItems.isEmpty())
 
266
            emit engine->itemsAdded(d->m_addedItems.toList());
 
267
        if (!d->m_changedItems.isEmpty())
 
268
            emit engine->itemsChanged(d->m_changedItems.toList());
 
269
        if (!d->m_removedItems.isEmpty())
 
270
            emit engine->itemsRemoved(d->m_removedItems.toList());
 
271
        if (!d->m_modifiedItems.isEmpty())
 
272
            emit engine->itemsModified(d->m_modifiedItems);
 
273
    }
 
274
}
 
275
 
 
276
QT_END_NAMESPACE_ORGANIZER