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 "qorganizeritemfilter.h"
35#include "qorganizeritemfilter_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#include "qorganizeritemfilters.h"
45
46/*!
47 \class QOrganizerItemFilter
48 \brief The QOrganizerItemFilter class is used to filter items made available through a backend.
49 \inmodule QtOrganizer
50 \ingroup organizer-main
51
52 This class is used as a parameter to various functions offered by QOrganizerManager and QOrganizerAbstractRequest,
53 to allow filtering of items which have certain details or properties.
54 */
55
56/*!
57 \enum QOrganizerItemFilter::FilterType
58
59 This enumeration describes the type of the filter.
60 \value InvalidFilter An invalid filter which matches nothing.
61 \value DetailFilter A filter which matches items containing a detail identical to that
62 used by the filter for matching.
63 \value DetailFieldFilter A filter which matches items containing a detail of a particular type,
64 having a given value for a particular field.
65 \value DetailRangeFilter A filter which matches items containing a detail of a particular type,
66 whose values are within a particular range.
67 \value IntersectionFilter A filter which matches all items that are matched by all filters it includes.
68 \value UnionFilter A filter which matches any organizer item that is matched by any of the
69 filters it includes.
70 \value IdFilter A filter which matches any organizer item whose ID is contained in a
71 particular list of organizer item IDs.
72 \value CollectionFilter A filter which matches any items whose collection ID is contained in
73 a particular list of collection IDs.
74 \value DefaultFilter A filter which matches everything.
75 */
76
77/*!
78 \enum QOrganizerItemFilter::MatchFlag
79
80 This enumeration describes the semantics of matching followed by the filter.
81 \value MatchExactly Performs QVariant-based matching.
82 \value MatchContains The search term is contained in the item.
83 \value MatchStartsWith The search term matches the start of the item.
84 \value MatchEndsWith The search term matches the end of the item.
85 \value MatchFixedString Performs string-based matching. String-based comparisons are case-insensitive
86 unless the \c MatchCaseSensitive flag is also specified.
87 \value MatchCaseSensitive The search is case sensitive.
88 */
89
90/*!
91 \fn QOrganizerItemFilter::operator!=(const QOrganizerItemFilter &other) const
92
93 Returns true if this filter is not identical to the \a other filter.
94
95 \sa operator==()
96 */
97
98#if !defined(Q_CC_MWERKS)
99template<> QTORGANIZER_PREPEND_NAMESPACE(QOrganizerItemFilterPrivate) *QSharedDataPointer<QTORGANIZER_PREPEND_NAMESPACE(QOrganizerItemFilterPrivate)>::clone()
100{
101 return d->clone();
102}
103#endif // Q_CC_MWERKS
104
105QT_BEGIN_NAMESPACE_ORGANIZER
106
107/*!
108 Constructs an empty filter of type DefaultFilter.
109 */
110QOrganizerItemFilter::QOrganizerItemFilter()
111 : d_ptr(0)
112{
113}
114
115/*!
116 Constructs a new copy of \a other.
117 */
118QOrganizerItemFilter::QOrganizerItemFilter(const QOrganizerItemFilter &other)
119 : d_ptr(other.d_ptr)
120{
121}
122
123/*!
124 Assigns this filter to be \a other.
125 */
126QOrganizerItemFilter &QOrganizerItemFilter::operator=(const QOrganizerItemFilter &other)
127{
128 d_ptr = other.d_ptr;
129 return *this;
130}
131
132/*!
133 Cleans up the memory used by this filter.
134 */
135QOrganizerItemFilter::~QOrganizerItemFilter()
136{
137}
138
139/*!
140 Returns the type of the filter.
141 */
142QOrganizerItemFilter::FilterType QOrganizerItemFilter::type() const
143{
144 if (!d_ptr)
145 return QOrganizerItemFilter::DefaultFilter;
146 return d_ptr->type();
147}
148
149/*!
150 Returns true if this filter is identical to the \a other filter.
151
152 \sa operator!=()
153 */
154bool QOrganizerItemFilter::operator==(const QOrganizerItemFilter &other) const
155{
156 if (d_ptr == other.d_ptr)
157 return true;
158
159 if (d_ptr && other.d_ptr)
160 return d_ptr->type() == other.d_ptr->type() && d_ptr->compare(other: other.d_ptr);
161
162 return false;
163}
164
165#ifndef QT_NO_DATASTREAM
166/*!
167 \relates QOrganizerItemFilter
168 Writes \a filter to the stream \a out.
169
170 A QOrganizerItemIdFilter will not be preserved if streamed to a QDataStream.
171 */
172QDataStream &operator<<(QDataStream &out, const QOrganizerItemFilter &filter)
173{
174 quint8 formatVersion = 1;
175 out << formatVersion << static_cast<quint32>(filter.type());
176 if (filter.d_ptr)
177 filter.d_ptr->outputToStream(stream&: out, formatVersion);
178 return out;
179}
180
181/*!
182 \relates QOrganizerItemFilter
183 Reads an organizer item filter from stream \a in into \a filter.
184
185 A QOrganizerItemIdFilter will not be preserved if streamed from a QDataStream.
186 */
187QDataStream &operator>>(QDataStream &in, QOrganizerItemFilter &filter)
188{
189 quint8 formatVersion;
190 in >> formatVersion;
191 if (formatVersion == 1) {
192 quint32 type;
193 in >> type;
194 switch (type) {
195 case QOrganizerItemFilter::InvalidFilter:
196 filter = QOrganizerItemInvalidFilter();
197 break;
198 case QOrganizerItemFilter::DetailFilter:
199 filter = QOrganizerItemDetailFilter();
200 case QOrganizerItemFilter::DetailFieldFilter:
201 filter = QOrganizerItemDetailFieldFilter();
202 break;
203 case QOrganizerItemFilter::DetailRangeFilter:
204 filter = QOrganizerItemDetailRangeFilter();
205 break;
206 case QOrganizerItemFilter::IntersectionFilter:
207 filter = QOrganizerItemIntersectionFilter();
208 break;
209 case QOrganizerItemFilter::UnionFilter:
210 filter = QOrganizerItemUnionFilter();
211 break;
212 case QOrganizerItemFilter::IdFilter:
213 filter = QOrganizerItemIdFilter();
214 break;
215 case QOrganizerItemFilter::DefaultFilter:
216 filter = QOrganizerItemFilter();
217 break;
218 }
219
220 if (filter.d_ptr)
221 filter.d_ptr->inputFromStream(stream&: in, formatVersion);
222 } else {
223 in.setStatus(QDataStream::ReadCorruptData);
224 }
225 return in;
226}
227#endif // QT_NO_DATASTREAM
228
229#ifndef QT_NO_DEBUG_STREAM
230/*!
231 \relates QOrganizerItemFilter
232 Outputs \a filter to the debug stream \a dbg.
233 */
234QDebug operator<<(QDebug dbg, const QOrganizerItemFilter &filter)
235{
236 dbg.nospace() << "QOrganizerItemFilter(";
237 if (filter.d_ptr)
238 filter.d_ptr->debugStreamOut(dbg);
239 else
240 dbg.nospace() << "(null)";
241 dbg.nospace() << ")";
242 return dbg.maybeSpace();
243}
244#endif // QT_NO_DEBUG_STREAM
245
246/*!
247 \internal
248
249 Constructs a new filter from the given data pointer \a d.
250 */
251QOrganizerItemFilter::QOrganizerItemFilter(QOrganizerItemFilterPrivate *d)
252 : d_ptr(d)
253{
254}
255
256/*!
257 \relates QOrganizerItemFilter
258 Returns a filter which is the intersection of the \a left and \a right filters.
259
260 \sa QOrganizerItemIntersectionFilter
261 */
262const QOrganizerItemFilter operator&(const QOrganizerItemFilter &left, const QOrganizerItemFilter &right)
263{
264 // XXX TODO: empty intersection/union operations are not well defined yet.
265 //if (left.type() == QOrganizerItemFilter::Intersection) {
266 // QOrganizerItemIntersectionFilter bf(left);
267 // /* we can just add the right to this one */
268 // bf.append(right);
269 // return bf;
270 //}
271
272 //if (right.type() == QOrganizerItemFilter::Intersection) {
273 // QOrganizerItemIntersectionFilter bf(right);
274 // /* we can prepend the left to this one */
275 // bf.prepend(left);
276 // return bf;
277 //}
278
279 /* usual fallback case */
280 QOrganizerItemIntersectionFilter nif;
281 nif << left << right;
282 return nif;
283}
284
285/*!
286 \relates QOrganizerItemFilter
287 Returns a filter which is the union of the \a left and \a right filters.
288
289 \sa QOrganizerItemUnionFilter
290 */
291const QOrganizerItemFilter operator|(const QOrganizerItemFilter &left, const QOrganizerItemFilter &right)
292{
293 if (left.type() == QOrganizerItemFilter::UnionFilter) {
294 QOrganizerItemUnionFilter bf(left);
295 /* we can just add the right to this one */
296 bf.append(filter: right);
297 return bf;
298 }
299
300 if (right.type() == QOrganizerItemFilter::UnionFilter) {
301 QOrganizerItemUnionFilter bf(right);
302 /* we can prepend the left to this one */
303 bf.prepend(filter: left);
304 return bf;
305 }
306
307 /* usual fallback case */
308 QOrganizerItemUnionFilter nif;
309 nif << left << right;
310 return nif;
311}
312
313QT_END_NAMESPACE_ORGANIZER
314

source code of qtpim/src/organizer/qorganizeritemfilter.cpp