|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "qcontactsortorder.h" |
|
43 #include "qcontactsortorder_p.h" |
|
44 |
|
45 QTM_BEGIN_NAMESPACE |
|
46 |
|
47 /*! |
|
48 \class QContactSortOrder |
|
49 \brief The QContactSortOrder class defines how a list of contacts should be ordered according to some criteria |
|
50 */ |
|
51 |
|
52 /*! |
|
53 * \enum QContactSortOrder::BlankPolicy |
|
54 * Enumerates the ways in which the sort order interprets blanks when sorting contacts |
|
55 * \value BlanksFirst Considers blank values to evaluate to less than all other values in comparisons |
|
56 * \value BlanksLast Considers blank values to evaluate to greater than all other values in comparisons |
|
57 */ |
|
58 |
|
59 /*! |
|
60 * \fn QContactSortOrder::operator QList<QContactSortOrder>() const |
|
61 * Constructs a new list of sort orders containing only the current sort order |
|
62 */ |
|
63 |
|
64 /*! |
|
65 * \fn QContactSortOrder::operator!=(const QContactSortOrder& other) const |
|
66 * Returns true if this sort order is not identical to the \a other sort order |
|
67 * \sa operator==() |
|
68 */ |
|
69 |
|
70 /*! |
|
71 * Constructs a new sort order |
|
72 */ |
|
73 QContactSortOrder::QContactSortOrder() |
|
74 : d(new QContactSortOrderPrivate()) |
|
75 { |
|
76 } |
|
77 |
|
78 /*! |
|
79 * Frees any memory in use by this sort order |
|
80 */ |
|
81 QContactSortOrder::~QContactSortOrder() |
|
82 { |
|
83 } |
|
84 |
|
85 /*! |
|
86 * Constructs a copy of the \a other sort order |
|
87 */ |
|
88 QContactSortOrder::QContactSortOrder(const QContactSortOrder& other) |
|
89 : d(other.d) |
|
90 { |
|
91 |
|
92 } |
|
93 |
|
94 /*! |
|
95 * Assigns this sort order to be equal to \a other |
|
96 */ |
|
97 QContactSortOrder& QContactSortOrder::operator=(const QContactSortOrder& other) |
|
98 { |
|
99 if (this != &other) { |
|
100 d = other.d; |
|
101 } |
|
102 return *this; |
|
103 } |
|
104 |
|
105 /*! |
|
106 * Returns true if the sort order is able to be used to sort a list of contacts; otherwise, returns false |
|
107 */ |
|
108 bool QContactSortOrder::isValid() const |
|
109 { |
|
110 /* We clear both when one is empty, so we only need to check one */ |
|
111 if (d->m_definitionName.isEmpty()) |
|
112 return false; |
|
113 return true; |
|
114 } |
|
115 |
|
116 /*! |
|
117 * Returns true if this sort order is identical to the \a other sort order |
|
118 * \sa operator!=() |
|
119 */ |
|
120 bool QContactSortOrder::operator ==(const QContactSortOrder& other) const |
|
121 { |
|
122 if (d->m_blankPolicy == other.d->m_blankPolicy && |
|
123 d->m_direction == other.d->m_direction && |
|
124 d->m_sensitivity == other.d->m_sensitivity && |
|
125 d->m_definitionName == other.d->m_definitionName && |
|
126 d->m_fieldName == other.d->m_fieldName) |
|
127 return true; |
|
128 return false; |
|
129 } |
|
130 |
|
131 /*! |
|
132 * Sets the definition name of the details which will be inspected to perform sorting to \a definitionName, |
|
133 * and the name of those details' fields which contains the value which contacts will be sorted by to \a fieldName |
|
134 * \sa detailDefinitionName(), detailFieldName() |
|
135 */ |
|
136 void QContactSortOrder::setDetailDefinitionName(const QString& definitionName, const QString& fieldName) |
|
137 { |
|
138 if (definitionName.isEmpty() || fieldName.isEmpty()) { |
|
139 d->m_definitionName.clear(); |
|
140 d->m_fieldName.clear(); |
|
141 } else { |
|
142 d->m_definitionName = definitionName; |
|
143 d->m_fieldName = fieldName; |
|
144 } |
|
145 } |
|
146 |
|
147 /*! |
|
148 * Sets the sort order's policy on blank values with respect to sorting to \a blankPolicy |
|
149 * \sa blankPolicy() |
|
150 */ |
|
151 void QContactSortOrder::setBlankPolicy(BlankPolicy blankPolicy) |
|
152 { |
|
153 d->m_blankPolicy = blankPolicy; |
|
154 } |
|
155 |
|
156 /*! |
|
157 * Sets the sort order direction to \a direction |
|
158 * \sa direction() |
|
159 */ |
|
160 void QContactSortOrder::setDirection(Qt::SortOrder direction) |
|
161 { |
|
162 d->m_direction = direction; |
|
163 } |
|
164 |
|
165 /*! |
|
166 * Returns the definition name of the details which will be inspected to perform sorting. |
|
167 * Note that if a contact has multiple details of the definition, the result of the sorting |
|
168 * is undefined. |
|
169 * \sa setDetailDefinitionName() |
|
170 */ |
|
171 QString QContactSortOrder::detailDefinitionName() const |
|
172 { |
|
173 return d->m_definitionName; |
|
174 } |
|
175 |
|
176 /*! |
|
177 * Returns the name of the field in the definition which will be inspected to perform sorting |
|
178 * \sa setDetailDefinitionName() |
|
179 */ |
|
180 QString QContactSortOrder::detailFieldName() const |
|
181 { |
|
182 return d->m_fieldName; |
|
183 } |
|
184 |
|
185 /*! |
|
186 * Returns the blank policy of the sort order |
|
187 * \sa setBlankPolicy() |
|
188 */ |
|
189 QContactSortOrder::BlankPolicy QContactSortOrder::blankPolicy() const |
|
190 { |
|
191 return d->m_blankPolicy; |
|
192 } |
|
193 |
|
194 /*! |
|
195 * Returns the direction of the sort order |
|
196 * \sa setDirection() |
|
197 */ |
|
198 Qt::SortOrder QContactSortOrder::direction() const |
|
199 { |
|
200 return d->m_direction; |
|
201 } |
|
202 |
|
203 /*! |
|
204 * Returns the case sensitivity of the sort order |
|
205 * \sa setCaseSensitivity() |
|
206 */ |
|
207 Qt::CaseSensitivity QContactSortOrder::caseSensitivity() const |
|
208 { |
|
209 return d->m_sensitivity; |
|
210 } |
|
211 |
|
212 /*! |
|
213 * Sets the case sensitivity of the sort order to \a sensitivity |
|
214 * \sa caseSensitivity() |
|
215 */ |
|
216 void QContactSortOrder::setCaseSensitivity(Qt::CaseSensitivity sensitivity) |
|
217 { |
|
218 d->m_sensitivity = sensitivity; |
|
219 } |
|
220 |
|
221 QTM_END_NAMESPACE |