1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the QtOrganizer module of the Qt Toolkit.
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.
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.
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.
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.
40
****************************************************************************/
42
#include <qorganizeritemchangeset.h>
43
#include <private/qorganizeritemchangeset_p.h>
44
#include <qorganizermanagerengine.h>
46
QT_BEGIN_NAMESPACE_ORGANIZER
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.
53
\ingroup organizer-backends
55
This class should only be used by backend developers.
59
Constructs a new change set.
61
QOrganizerItemChangeSet::QOrganizerItemChangeSet()
62
: d(new QOrganizerItemChangeSetData)
67
Constructs a copy of the \a other change set.
69
QOrganizerItemChangeSet::QOrganizerItemChangeSet(const QOrganizerItemChangeSet &other)
75
Frees the memory used by this change set.
77
QOrganizerItemChangeSet::~QOrganizerItemChangeSet()
82
Assigns this change set to be equal to \a other.
84
QOrganizerItemChangeSet &QOrganizerItemChangeSet::operator=(const QOrganizerItemChangeSet &other)
91
Sets the data changed flag to \a dataChanged.
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.
96
void QOrganizerItemChangeSet::setDataChanged(bool dataChanged)
98
d->m_dataChanged = dataChanged;
102
Returns the value of the data changed flag.
104
bool QOrganizerItemChangeSet::dataChanged() const
106
return d->m_dataChanged;
110
Returns the set of IDs of organizer items which have been added to the database.
112
QSet<QOrganizerItemId> QOrganizerItemChangeSet::addedItems() const
114
return d->m_addedItems;
118
Inserts the given \a itemId into the set of ids of organizer items which have been added to the
121
void QOrganizerItemChangeSet::insertAddedItem(const QOrganizerItemId &itemId)
123
d->m_addedItems.insert(itemId);
124
d->m_modifiedItems.append(QPair<QOrganizerItemId, QOrganizerManager::Operation>(itemId, QOrganizerManager::Add));
128
Inserts each of the given \a itemIds into the set of IDs of organizer items which have been added
131
void QOrganizerItemChangeSet::insertAddedItems(const QList<QOrganizerItemId> &itemIds)
133
foreach (const QOrganizerItemId &id, itemIds) {
134
d->m_addedItems.insert(id);
135
d->m_modifiedItems.append(QPair<QOrganizerItemId, QOrganizerManager::Operation>(id, QOrganizerManager::Add));
140
Clears the set of IDs of organizer items which have been added to the database.
142
void QOrganizerItemChangeSet::clearAddedItems()
144
d->m_addedItems.clear();
148
Returns the set of IDs of organizer items which have been changed in the database.
150
QSet<QOrganizerItemId> QOrganizerItemChangeSet::changedItems() const
152
return d->m_changedItems;
156
Inserts the given \a itemId into the set of IDs of organizer items which have been changed in
159
void QOrganizerItemChangeSet::insertChangedItem(const QOrganizerItemId &itemId)
161
d->m_changedItems.insert(itemId);
162
d->m_modifiedItems.append(QPair<QOrganizerItemId, QOrganizerManager::Operation>(itemId, QOrganizerManager::Change));
166
Inserts each of the given \a itemIds into the set of IDs of organizer items which have been
167
changed in the database.
169
void QOrganizerItemChangeSet::insertChangedItems(const QList<QOrganizerItemId> &itemIds)
171
foreach (const QOrganizerItemId &id, itemIds) {
172
d->m_changedItems.insert(id);
173
d->m_modifiedItems.append(QPair<QOrganizerItemId, QOrganizerManager::Operation>(id, QOrganizerManager::Change));
178
Clears the set of IDs of organizer items which have been changed in the database.
180
void QOrganizerItemChangeSet::clearChangedItems()
182
d->m_changedItems.clear();
186
Returns the set of IDs of organizer items which have been removed from the database.
188
QSet<QOrganizerItemId> QOrganizerItemChangeSet::removedItems() const
190
return d->m_removedItems;
194
Inserts the given \a itemId into the set of IDs of organizer items which have been removed from
197
void QOrganizerItemChangeSet::insertRemovedItem(const QOrganizerItemId &itemId)
199
d->m_removedItems.insert(itemId);
200
d->m_modifiedItems.append(QPair<QOrganizerItemId, QOrganizerManager::Operation>(itemId, QOrganizerManager::Remove));
204
Inserts each of the given \a itemIds into the set of IDs of organizer items which have been
205
removed from the database.
207
void QOrganizerItemChangeSet::insertRemovedItems(const QList<QOrganizerItemId> &itemIds)
209
foreach (const QOrganizerItemId &id, itemIds) {
210
d->m_removedItems.insert(id);
211
d->m_modifiedItems.append(QPair<QOrganizerItemId, QOrganizerManager::Operation>(id, QOrganizerManager::Remove));
216
Clears the set of IDs of organizer items which have been removed from the database.
218
void QOrganizerItemChangeSet::clearRemovedItems()
220
d->m_removedItems.clear();
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.
228
QList<QPair<QOrganizerItemId, QOrganizerManager::Operation> > QOrganizerItemChangeSet::modifiedItems() const
230
return d->m_modifiedItems;
234
Clears the list of ids of organizer items which have been added, changed or removed from the database
236
void QOrganizerItemChangeSet::clearModifiedItems()
238
d->m_modifiedItems.clear();
242
Clears all flags and sets of IDs in this change set.
244
void QOrganizerItemChangeSet::clearAll()
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();
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.
257
void QOrganizerItemChangeSet::emitSignals(QOrganizerManagerEngine *engine) const
262
if (d->m_dataChanged) {
263
emit engine->dataChanged();
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);
276
QT_END_NAMESPACE_ORGANIZER