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 QtContacts 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 "qcontactsortorder.h"
43
#include "qcontactsortorder_p.h"
44
#include "qcontactdetail.h"
46
#ifndef QT_NO_DEBUG_STREAM
50
QT_BEGIN_NAMESPACE_CONTACTS
53
\class QContactSortOrder
54
\brief The QContactSortOrder class defines how a list of contacts should be ordered according to some criteria
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
68
* \fn QContactSortOrder::operator QList<QContactSortOrder>() const
69
* Constructs a new list of sort orders containing only the current sort order
73
* \fn QContactSortOrder::operator!=(const QContactSortOrder& other) const
74
* Returns true if this sort order is not identical to the \a other sort order
79
* Constructs a new sort order
81
QContactSortOrder::QContactSortOrder()
82
: d(new QContactSortOrderPrivate())
87
* Frees any memory in use by this sort order
89
QContactSortOrder::~QContactSortOrder()
94
* Constructs a copy of the \a other sort order
96
QContactSortOrder::QContactSortOrder(const QContactSortOrder& other)
103
* Assigns this sort order to be equal to \a other
105
QContactSortOrder& QContactSortOrder::operator=(const QContactSortOrder& other)
107
if (this != &other) {
114
* Returns true if the sort order is able to be used to sort a list of contacts; otherwise, returns false
116
bool QContactSortOrder::isValid() const
118
/* We clear both when one is empty, so we only need to check one */
119
if (d.constData()->m_type == QContactDetail::TypeUndefined)
125
* Returns true if this sort order is identical to the \a other sort order
128
bool QContactSortOrder::operator ==(const QContactSortOrder& other) const
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)
140
#ifndef QT_NO_DATASTREAM
142
* Writes \a sortOrder to the stream \a out.
144
QDataStream& operator<<(QDataStream& out, const QContactSortOrder& sortOrder)
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());
156
* Reads a sort order from stream \a in into \a sortOrder.
158
QDataStream& operator>>(QDataStream& in, QContactSortOrder& sortOrder)
160
sortOrder = QContactSortOrder();
161
quint8 formatVersion;
163
if (formatVersion == 1) {
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));
175
in.setStatus(QDataStream::ReadCorruptData);
181
#ifndef QT_NO_DEBUG_STREAM
183
Outputs \a sortOrder to the debug stream \a dbg
185
QDebug operator<<(QDebug dbg, const QContactSortOrder& sortOrder)
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())
194
return dbg.maybeSpace();
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()
203
void QContactSortOrder::setDetailType(QContactDetail::DetailType type, int field)
205
if (type == QContactDetail::TypeUndefined || field == -1) {
206
d->m_type = QContactDetail::TypeUndefined;
215
* Sets the sort order's policy on blank values with respect to sorting to \a blankPolicy
218
void QContactSortOrder::setBlankPolicy(BlankPolicy blankPolicy)
220
d->m_blankPolicy = blankPolicy;
224
* Sets the sort order direction to \a direction
227
void QContactSortOrder::setDirection(Qt::SortOrder direction)
229
d->m_direction = direction;
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
236
* \sa setDetailType()
238
QContactDetail::DetailType QContactSortOrder::detailType() const
240
return d.constData()->m_type;
244
* Returns the detail field which the sorting order will be based on.
245
* \sa setDetailType()
247
int QContactSortOrder::detailField() const
249
return d.constData()->m_field;
254
* Returns the blank policy of the sort order
255
* \sa setBlankPolicy()
257
QContactSortOrder::BlankPolicy QContactSortOrder::blankPolicy() const
259
return d.constData()->m_blankPolicy;
263
* Returns the direction of the sort order
266
Qt::SortOrder QContactSortOrder::direction() const
268
return d.constData()->m_direction;
272
* Returns the case sensitivity of the sort order
273
* \sa setCaseSensitivity()
275
Qt::CaseSensitivity QContactSortOrder::caseSensitivity() const
277
return d.constData()->m_sensitivity;
281
* Sets the case sensitivity of the sort order to \a sensitivity
282
* \sa caseSensitivity()
284
void QContactSortOrder::setCaseSensitivity(Qt::CaseSensitivity sensitivity)
286
d->m_sensitivity = sensitivity;
289
QT_END_NAMESPACE_CONTACTS