| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. |
| 4 | ** Contact: http://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtOrganizer module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ |
| 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 The Qt Company. For licensing terms |
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free |
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and |
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the |
| 22 | ** following information to ensure the GNU Lesser General Public License |
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and |
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 25 | ** |
| 26 | ** As a special exception, The Qt Company gives you certain additional |
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception |
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 29 | ** |
| 30 | ** $QT_END_LICENSE$ |
| 31 | ** |
| 32 | ****************************************************************************/ |
| 33 | |
| 34 | #include "qorganizeritemsortorder.h" |
| 35 | #include "qorganizeritemsortorder_p.h" |
| 36 | |
| 37 | #ifndef QT_NO_DATASTREAM |
| 38 | #include <QtCore/qdatastream.h> |
| 39 | #endif |
| 40 | #ifndef QT_NO_DEBUG_STREAM |
| 41 | #include <QtCore/qdebug.h> |
| 42 | #endif |
| 43 | |
| 44 | QT_BEGIN_NAMESPACE_ORGANIZER |
| 45 | |
| 46 | /*! |
| 47 | \class QOrganizerItemSortOrder |
| 48 | \brief The QOrganizerItemSortOrder class defines how a list of organizer items should be ordered according to some criteria. |
| 49 | \inmodule QtOrganizer |
| 50 | \ingroup organizer-filters |
| 51 | */ |
| 52 | |
| 53 | /*! |
| 54 | \enum QOrganizerItemSortOrder::BlankPolicy |
| 55 | |
| 56 | Enumerates the ways in which the sort order interprets blanks when sorting organizer items. |
| 57 | \value BlanksFirst Considers blank values to evaluate to less than all other values in comparisons. |
| 58 | \value BlanksLast Considers blank values to evaluate to greater than all other values in comparisons. |
| 59 | */ |
| 60 | |
| 61 | /*! |
| 62 | \fn QOrganizerItemSortOrder::operator QList<QOrganizerItemSortOrder>() const |
| 63 | |
| 64 | Constructs a new list of sort orders containing only the current sort order. |
| 65 | */ |
| 66 | |
| 67 | /*! |
| 68 | \fn QOrganizerItemSortOrder::operator!=(const QOrganizerItemSortOrder &other) const |
| 69 | |
| 70 | Returns true if this sort order is not identical to the \a other sort order. |
| 71 | |
| 72 | \sa operator==() |
| 73 | */ |
| 74 | |
| 75 | /*! |
| 76 | Constructs a new sort order |
| 77 | */ |
| 78 | QOrganizerItemSortOrder::QOrganizerItemSortOrder() |
| 79 | : d(new QOrganizerItemSortOrderPrivate()) |
| 80 | { |
| 81 | } |
| 82 | |
| 83 | /*! |
| 84 | Frees any memory in use by this sort order |
| 85 | */ |
| 86 | QOrganizerItemSortOrder::~QOrganizerItemSortOrder() |
| 87 | { |
| 88 | } |
| 89 | |
| 90 | /*! |
| 91 | Constructs a copy of the \a other sort order. |
| 92 | */ |
| 93 | QOrganizerItemSortOrder::QOrganizerItemSortOrder(const QOrganizerItemSortOrder &other) |
| 94 | : d(other.d) |
| 95 | { |
| 96 | } |
| 97 | |
| 98 | /*! |
| 99 | Assigns this sort order to be equal to \a other. |
| 100 | */ |
| 101 | QOrganizerItemSortOrder &QOrganizerItemSortOrder::operator=(const QOrganizerItemSortOrder &other) |
| 102 | { |
| 103 | d = other.d; |
| 104 | return *this; |
| 105 | } |
| 106 | |
| 107 | /*! |
| 108 | Returns true if the sort order is able to be used to sort a list of organizer items; otherwise, returns false. |
| 109 | */ |
| 110 | bool QOrganizerItemSortOrder::isValid() const |
| 111 | { |
| 112 | return d->m_detailType != QOrganizerItemDetail::TypeUndefined; |
| 113 | } |
| 114 | |
| 115 | /*! |
| 116 | Returns true if this sort order is identical to the \a other sort order. |
| 117 | |
| 118 | \sa operator!=() |
| 119 | */ |
| 120 | bool QOrganizerItemSortOrder::operator ==(const QOrganizerItemSortOrder &other) const |
| 121 | { |
| 122 | if (d == other.d) |
| 123 | return true; |
| 124 | |
| 125 | return d->m_blankPolicy == other.d->m_blankPolicy |
| 126 | && d->m_direction == other.d->m_direction |
| 127 | && d->m_sensitivity == other.d->m_sensitivity |
| 128 | && d->m_detailType == other.d->m_detailType |
| 129 | && d->m_detailField == other.d->m_detailField; |
| 130 | } |
| 131 | |
| 132 | #ifndef QT_NO_DATASTREAM |
| 133 | /*! |
| 134 | \relates QOrganizerItemSortOrder |
| 135 | Writes \a sortOrder to the stream \a out. |
| 136 | */ |
| 137 | QDataStream &operator<<(QDataStream &out, const QOrganizerItemSortOrder &sortOrder) |
| 138 | { |
| 139 | quint8 formatVersion = 1; // Version of QDataStream format for QOrganizerItemSortOrder |
| 140 | return out << formatVersion |
| 141 | << sortOrder.detailType() |
| 142 | << sortOrder.detailField() |
| 143 | << static_cast<quint32>(sortOrder.blankPolicy()) |
| 144 | << static_cast<quint32>(sortOrder.direction()) |
| 145 | << static_cast<quint32>(sortOrder.caseSensitivity()); |
| 146 | } |
| 147 | |
| 148 | /*! |
| 149 | \relates QOrganizerItemSortOrder |
| 150 | Reads a sort order from stream \a in into \a sortOrder. |
| 151 | */ |
| 152 | QDataStream &operator>>(QDataStream &in, QOrganizerItemSortOrder &sortOrder) |
| 153 | { |
| 154 | quint8 formatVersion; |
| 155 | in >> formatVersion; |
| 156 | if (formatVersion == 1) { |
| 157 | quint32 detailType; |
| 158 | int fieldName; |
| 159 | quint32 blankPolicy; |
| 160 | quint32 direction; |
| 161 | quint32 caseSensitivity; |
| 162 | in >> detailType >> fieldName >> blankPolicy >> direction >> caseSensitivity; |
| 163 | sortOrder.setDetail(detailType: static_cast<QOrganizerItemDetail::DetailType>(detailType), field: fieldName); |
| 164 | sortOrder.setBlankPolicy(static_cast<QOrganizerItemSortOrder::BlankPolicy>(blankPolicy)); |
| 165 | sortOrder.setDirection(static_cast<Qt::SortOrder>(direction)); |
| 166 | sortOrder.setCaseSensitivity(static_cast<Qt::CaseSensitivity>(caseSensitivity)); |
| 167 | } else { |
| 168 | in.setStatus(QDataStream::ReadCorruptData); |
| 169 | } |
| 170 | return in; |
| 171 | } |
| 172 | #endif // QT_NO_DATASTREAM |
| 173 | |
| 174 | #ifndef QT_NO_DEBUG_STREAM |
| 175 | /*! |
| 176 | \relates QOrganizerItemSortOrder |
| 177 | Outputs \a sortOrder to the debug stream \a dbg. |
| 178 | */ |
| 179 | QDebug operator<<(QDebug dbg, const QOrganizerItemSortOrder &sortOrder) |
| 180 | { |
| 181 | dbg.nospace() << "QOrganizerItemSortOrder(" ; |
| 182 | dbg.nospace() << "detailType=" ; |
| 183 | dbg.nospace() << sortOrder.detailType(); |
| 184 | dbg.nospace() << "," ; |
| 185 | dbg.nospace() << "detailField=" ; |
| 186 | dbg.nospace() << sortOrder.detailField(); |
| 187 | dbg.nospace() << "," ; |
| 188 | dbg.nospace() << "blankPolicy=" ; |
| 189 | dbg.nospace() << static_cast<quint32>(sortOrder.blankPolicy()); |
| 190 | dbg.nospace() << "," ; |
| 191 | dbg.nospace() << "direction=" ; |
| 192 | dbg.nospace() << static_cast<quint32>(sortOrder.direction()); |
| 193 | dbg.nospace() << "," ; |
| 194 | dbg.nospace() << "caseSensitivity=" ; |
| 195 | dbg.nospace() << static_cast<quint32>(sortOrder.caseSensitivity()); |
| 196 | dbg.nospace() << ")" ; |
| 197 | return dbg.maybeSpace(); |
| 198 | } |
| 199 | #endif // QT_NO_DEBUG_STREAM |
| 200 | |
| 201 | /*! |
| 202 | Sets the type of detail which will be inspected for sorting to \a detailType, and the field of |
| 203 | the detail to \a field. |
| 204 | |
| 205 | If \a field is not specified, or equal to -1, the organizer item with a detail of the specified type |
| 206 | would appear before or after the organizer item that lacks a detail of the specified type, |
| 207 | according to blankPolicy(). |
| 208 | |
| 209 | \sa detailType(), detailField() |
| 210 | */ |
| 211 | void QOrganizerItemSortOrder::setDetail(QOrganizerItemDetail::DetailType detailType, int field) |
| 212 | { |
| 213 | d->m_detailType = detailType; |
| 214 | d->m_detailField = field; |
| 215 | } |
| 216 | |
| 217 | /*! |
| 218 | Sets the sort order's policy on blank values with respect to sorting to \a blankPolicy. |
| 219 | |
| 220 | \sa blankPolicy() |
| 221 | */ |
| 222 | void QOrganizerItemSortOrder::setBlankPolicy(BlankPolicy blankPolicy) |
| 223 | { |
| 224 | d->m_blankPolicy = blankPolicy; |
| 225 | } |
| 226 | |
| 227 | /*! |
| 228 | Sets the sort order direction to \a direction. |
| 229 | |
| 230 | \sa direction() |
| 231 | */ |
| 232 | void QOrganizerItemSortOrder::setDirection(Qt::SortOrder direction) |
| 233 | { |
| 234 | d->m_direction = direction; |
| 235 | } |
| 236 | |
| 237 | /*! |
| 238 | Returns the type of the detail which will be inspected to perform sorting. |
| 239 | |
| 240 | \sa setDetail() |
| 241 | */ |
| 242 | QOrganizerItemDetail::DetailType QOrganizerItemSortOrder::detailType() const |
| 243 | { |
| 244 | return d->m_detailType; |
| 245 | } |
| 246 | |
| 247 | /*! |
| 248 | Returns the detail field which will be inspected to perform sorting. |
| 249 | |
| 250 | \sa setDetail() |
| 251 | */ |
| 252 | int QOrganizerItemSortOrder::detailField() const |
| 253 | { |
| 254 | return d->m_detailField; |
| 255 | } |
| 256 | |
| 257 | /*! |
| 258 | Returns the blank policy of the sort order. |
| 259 | |
| 260 | \sa setBlankPolicy() |
| 261 | */ |
| 262 | QOrganizerItemSortOrder::BlankPolicy QOrganizerItemSortOrder::blankPolicy() const |
| 263 | { |
| 264 | return d->m_blankPolicy; |
| 265 | } |
| 266 | |
| 267 | /*! |
| 268 | Returns the direction of the sort order. |
| 269 | |
| 270 | \sa setDirection() |
| 271 | */ |
| 272 | Qt::SortOrder QOrganizerItemSortOrder::direction() const |
| 273 | { |
| 274 | return d->m_direction; |
| 275 | } |
| 276 | |
| 277 | /*! |
| 278 | Returns the case sensitivity of the sort order. |
| 279 | |
| 280 | \sa setCaseSensitivity() |
| 281 | */ |
| 282 | Qt::CaseSensitivity QOrganizerItemSortOrder::caseSensitivity() const |
| 283 | { |
| 284 | return d->m_sensitivity; |
| 285 | } |
| 286 | |
| 287 | /*! |
| 288 | Sets the case sensitivity of the sort order to \a sensitivity. |
| 289 | |
| 290 | \sa caseSensitivity() |
| 291 | */ |
| 292 | void QOrganizerItemSortOrder::setCaseSensitivity(Qt::CaseSensitivity sensitivity) |
| 293 | { |
| 294 | d->m_sensitivity = sensitivity; |
| 295 | } |
| 296 | |
| 297 | QT_END_NAMESPACE_ORGANIZER |
| 298 | |