~chris.gagnon/+junk/qtpim-coverage

« back to all changes in this revision

Viewing changes to src/contacts/qcontactsortorder.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 QtContacts 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 "qcontactsortorder.h"
 
43
#include "qcontactsortorder_p.h"
 
44
#include "qcontactdetail.h"
 
45
 
 
46
#ifndef QT_NO_DEBUG_STREAM
 
47
#include <QDebug>
 
48
#endif
 
49
 
 
50
QT_BEGIN_NAMESPACE_CONTACTS
 
51
 
 
52
/*!
 
53
  \class QContactSortOrder
 
54
  \brief The QContactSortOrder class defines how a list of contacts should be ordered according to some criteria
 
55
 
 
56
  \inmodule QtContacts
 
57
 
 
58
 */
 
59
 
 
60
/*!
 
61
 * \enum QContactSortOrder::BlankPolicy
 
62
 * Enumerates the ways in which the sort order interprets blanks when sorting contacts
 
63
 * \value BlanksFirst Considers blank values to evaluate to less than all other values in comparisons
 
64
 * \value BlanksLast Considers blank values to evaluate to greater than all other values in comparisons
 
65
 */
 
66
 
 
67
/*!
 
68
 * \fn QContactSortOrder::operator QList<QContactSortOrder>() const
 
69
 * Constructs a new list of sort orders containing only the current sort order
 
70
 */
 
71
 
 
72
/*!
 
73
 * \fn QContactSortOrder::operator!=(const QContactSortOrder& other) const
 
74
 * Returns true if this sort order is not identical to the \a other sort order
 
75
 * \sa operator==()
 
76
 */
 
77
 
 
78
/*!
 
79
 * Constructs a new sort order
 
80
 */
 
81
QContactSortOrder::QContactSortOrder()
 
82
    : d(new QContactSortOrderPrivate())
 
83
{
 
84
}
 
85
 
 
86
/*!
 
87
 * Frees any memory in use by this sort order
 
88
 */
 
89
QContactSortOrder::~QContactSortOrder()
 
90
{
 
91
}
 
92
 
 
93
/*!
 
94
 * Constructs a copy of the \a other sort order
 
95
 */
 
96
QContactSortOrder::QContactSortOrder(const QContactSortOrder& other)
 
97
    : d(other.d)
 
98
{
 
99
 
 
100
}
 
101
 
 
102
/*!
 
103
 * Assigns this sort order to be equal to \a other
 
104
 */
 
105
QContactSortOrder& QContactSortOrder::operator=(const QContactSortOrder& other)
 
106
{
 
107
    if (this != &other) {
 
108
        d = other.d;
 
109
    }
 
110
    return *this;
 
111
}
 
112
 
 
113
/*!
 
114
 * Returns true if the sort order is able to be used to sort a list of contacts; otherwise, returns false
 
115
 */
 
116
bool QContactSortOrder::isValid() const
 
117
{
 
118
    /* We clear both when one is empty, so we only need to check one */
 
119
    if (d.constData()->m_type == QContactDetail::TypeUndefined)
 
120
        return false;
 
121
    return true;
 
122
}
 
123
 
 
124
/*!
 
125
 * Returns true if this sort order is identical to the \a other sort order
 
126
 * \sa operator!=()
 
127
 */
 
128
bool QContactSortOrder::operator ==(const QContactSortOrder& other) const
 
129
{
 
130
    if (d.constData()->m_blankPolicy == other.d.constData()->m_blankPolicy &&
 
131
        d.constData()->m_direction == other.d.constData()->m_direction &&
 
132
        d.constData()->m_sensitivity == other.d.constData()->m_sensitivity &&
 
133
        d.constData()->m_type == other.d.constData()->m_type &&
 
134
        d.constData()->m_field == other.d.constData()->m_field)
 
135
        return true;
 
136
    return false;
 
137
}
 
138
 
 
139
 
 
140
#ifndef QT_NO_DATASTREAM
 
141
/*!
 
142
 * Writes \a sortOrder to the stream \a out.
 
143
 */
 
144
QDataStream& operator<<(QDataStream& out, const QContactSortOrder& sortOrder)
 
145
{
 
146
    quint8 formatVersion = 1; // Version of QDataStream format for QContactSortOrder
 
147
    return out << formatVersion
 
148
               << static_cast<quint32>(sortOrder.detailType())
 
149
               << sortOrder.detailField()
 
150
               << static_cast<quint32>(sortOrder.blankPolicy())
 
151
               << static_cast<quint32>(sortOrder.direction())
 
152
               << static_cast<quint32>(sortOrder.caseSensitivity());
 
153
}
 
154
 
 
155
/*!
 
156
 * Reads a sort order from stream \a in into \a sortOrder.
 
157
 */
 
158
QDataStream& operator>>(QDataStream& in, QContactSortOrder& sortOrder)
 
159
{
 
160
    sortOrder = QContactSortOrder();
 
161
    quint8 formatVersion;
 
162
    in >> formatVersion;
 
163
    if (formatVersion == 1) {
 
164
        quint32 type;
 
165
        int field;
 
166
        quint32 blankPolicy;
 
167
        quint32 direction;
 
168
        quint32 caseSensitivity;
 
169
        in >> type >> field >> blankPolicy >> direction >> caseSensitivity;
 
170
        sortOrder.setDetailType(QContactDetail::DetailType(type), field);
 
171
        sortOrder.setBlankPolicy(QContactSortOrder::BlankPolicy(blankPolicy));
 
172
        sortOrder.setDirection(Qt::SortOrder(direction));
 
173
        sortOrder.setCaseSensitivity(Qt::CaseSensitivity(caseSensitivity));
 
174
    } else {
 
175
        in.setStatus(QDataStream::ReadCorruptData);
 
176
    }
 
177
    return in;
 
178
}
 
179
#endif
 
180
 
 
181
#ifndef QT_NO_DEBUG_STREAM
 
182
/*!
 
183
  Outputs \a sortOrder to the debug stream \a dbg
 
184
 */
 
185
QDebug operator<<(QDebug dbg, const QContactSortOrder& sortOrder)
 
186
{
 
187
    dbg.nospace() << "QContactSortOrder("
 
188
                  << "detailType=" << static_cast<quint32>(sortOrder.detailType()) << ","
 
189
                  << "detailField=" << sortOrder.detailField() << ","
 
190
                  << "blankPolicy=" << static_cast<quint32>(sortOrder.blankPolicy()) << ","
 
191
                  << "direction=" << static_cast<quint32>(sortOrder.direction()) << ","
 
192
                  << "caseSensitivity=" << static_cast<quint32>(sortOrder.caseSensitivity())
 
193
                  << ")";
 
194
    return dbg.maybeSpace();
 
195
}
 
196
#endif
 
197
 
 
198
/*!
 
199
 * Sets the type of the details which will be inspected to perform sorting to \a type
 
200
 * and the name of those details' fields which contains the value which contacts will be sorted by to \a field
 
201
 * \sa detailType(), detailField()
 
202
 */
 
203
void QContactSortOrder::setDetailType(QContactDetail::DetailType type, int field)
 
204
{
 
205
    if (type == QContactDetail::TypeUndefined || field == -1) {
 
206
        d->m_type = QContactDetail::TypeUndefined;
 
207
        d->m_field = -1;
 
208
    } else {
 
209
        d->m_type = type;
 
210
        d->m_field = field;
 
211
    }
 
212
}
 
213
 
 
214
/*!
 
215
 * Sets the sort order's policy on blank values with respect to sorting to \a blankPolicy
 
216
 * \sa blankPolicy()
 
217
 */
 
218
void QContactSortOrder::setBlankPolicy(BlankPolicy blankPolicy)
 
219
{
 
220
    d->m_blankPolicy = blankPolicy;
 
221
}
 
222
 
 
223
/*!
 
224
 * Sets the sort order direction to \a direction
 
225
 * \sa direction()
 
226
 */
 
227
void QContactSortOrder::setDirection(Qt::SortOrder direction)
 
228
{
 
229
    d->m_direction = direction;
 
230
}
 
231
 
 
232
/*!
 
233
 * Returns the type of the details which will be inspected to perform sorting.
 
234
 * Note that if a contact has multiple details of the definition, the result of the sorting
 
235
 * is undefined.
 
236
 * \sa setDetailType()
 
237
 */
 
238
QContactDetail::DetailType QContactSortOrder::detailType() const
 
239
{
 
240
    return d.constData()->m_type;
 
241
}
 
242
 
 
243
/*!
 
244
 * Returns the detail field which the sorting order will be based on.
 
245
 * \sa setDetailType()
 
246
 */
 
247
int QContactSortOrder::detailField() const
 
248
{
 
249
    return d.constData()->m_field;
 
250
}
 
251
 
 
252
 
 
253
/*!
 
254
 * Returns the blank policy of the sort order
 
255
 * \sa setBlankPolicy()
 
256
 */
 
257
QContactSortOrder::BlankPolicy QContactSortOrder::blankPolicy() const
 
258
{
 
259
    return d.constData()->m_blankPolicy;
 
260
}
 
261
 
 
262
/*!
 
263
 * Returns the direction of the sort order
 
264
 * \sa setDirection()
 
265
 */
 
266
Qt::SortOrder QContactSortOrder::direction() const
 
267
{
 
268
    return d.constData()->m_direction;
 
269
}
 
270
 
 
271
/*!
 
272
 * Returns the case sensitivity of the sort order
 
273
 * \sa setCaseSensitivity()
 
274
 */
 
275
Qt::CaseSensitivity QContactSortOrder::caseSensitivity() const
 
276
{
 
277
    return d.constData()->m_sensitivity;
 
278
}
 
279
 
 
280
/*!
 
281
 * Sets the case sensitivity of the sort order to \a sensitivity
 
282
 * \sa caseSensitivity()
 
283
 */
 
284
void QContactSortOrder::setCaseSensitivity(Qt::CaseSensitivity sensitivity)
 
285
{
 
286
    d->m_sensitivity = sensitivity;
 
287
}
 
288
 
 
289
QT_END_NAMESPACE_CONTACTS