| 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 QtDocGallery 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 "qgalleryfilter.h" |
| 43 | |
| 44 | #include <QtCore/qdebug.h> |
| 45 | #include <QtCore/qstringlist.h> |
| 46 | #include <QtCore/qurl.h> |
| 47 | |
| 48 | QT_BEGIN_NAMESPACE_DOCGALLERY |
| 49 | |
| 50 | class QGalleryFilterPrivate : public QSharedData |
| 51 | { |
| 52 | public: |
| 53 | QGalleryFilterPrivate(QGalleryFilter::Type type) |
| 54 | : type(type) |
| 55 | { |
| 56 | } |
| 57 | |
| 58 | |
| 59 | virtual ~QGalleryFilterPrivate() {} |
| 60 | |
| 61 | virtual bool isEqual(const QGalleryFilterPrivate &other) const = 0; |
| 62 | |
| 63 | #ifndef QT_NO_DEBUG_STREAM |
| 64 | virtual void printDebug(QDebug &debug) const = 0; |
| 65 | #endif |
| 66 | |
| 67 | const QGalleryFilter::Type type; |
| 68 | |
| 69 | protected: |
| 70 | QGalleryFilterPrivate(const QGalleryFilterPrivate &other) |
| 71 | : QSharedData(other) |
| 72 | , type(other.type) |
| 73 | { |
| 74 | } |
| 75 | }; |
| 76 | |
| 77 | class QGalleryInvalidFilterPrivate : public QGalleryFilterPrivate |
| 78 | { |
| 79 | public: |
| 80 | QGalleryInvalidFilterPrivate() : QGalleryFilterPrivate(QGalleryFilter::Invalid) {} |
| 81 | |
| 82 | bool isEqual(const QGalleryFilterPrivate &other) const { return type == other.type; } |
| 83 | |
| 84 | #ifndef QT_NO_DEBUG_STREAM |
| 85 | void printDebug(QDebug &debug) const { debug << "QGalleryFilter()" ; } |
| 86 | #endif |
| 87 | }; |
| 88 | |
| 89 | class QGalleryIntersectionFilterPrivate : public QGalleryFilterPrivate |
| 90 | { |
| 91 | public: |
| 92 | QGalleryIntersectionFilterPrivate(QGalleryFilter::Type type = QGalleryFilter::Intersection) |
| 93 | : QGalleryFilterPrivate(type) |
| 94 | { |
| 95 | } |
| 96 | |
| 97 | QGalleryIntersectionFilterPrivate(const QGalleryIntersectionFilterPrivate &other) |
| 98 | : QGalleryFilterPrivate(other) |
| 99 | , filters(other.filters) |
| 100 | { |
| 101 | } |
| 102 | |
| 103 | bool isEqual(const QGalleryFilterPrivate &other) const |
| 104 | { |
| 105 | return other.type == type && static_cast<const QGalleryIntersectionFilterPrivate &> |
| 106 | (other).filters == filters; |
| 107 | } |
| 108 | |
| 109 | #ifndef QT_NO_DEBUG_STREAM |
| 110 | void printDebug(QDebug &debug) const |
| 111 | { |
| 112 | debug << "QGalleryIntersectionFilter(" ; |
| 113 | QList<QGalleryFilter>::const_iterator filter = filters.begin(); |
| 114 | if (filter != filters.end()) { |
| 115 | debug << *filter; |
| 116 | |
| 117 | while (++filter != filters.end()) |
| 118 | debug << " ||" << *filter; |
| 119 | } |
| 120 | debug << ")" ; |
| 121 | } |
| 122 | #endif |
| 123 | |
| 124 | QList<QGalleryFilter> filters; |
| 125 | }; |
| 126 | |
| 127 | class QGalleryUnionFilterPrivate : public QGalleryFilterPrivate |
| 128 | { |
| 129 | public: |
| 130 | QGalleryUnionFilterPrivate(QGalleryFilter::Type type = QGalleryFilter::Union) |
| 131 | : QGalleryFilterPrivate(type) {} |
| 132 | |
| 133 | QGalleryUnionFilterPrivate(const QGalleryUnionFilterPrivate &other) |
| 134 | : QGalleryFilterPrivate(other) |
| 135 | , filters(other.filters) |
| 136 | { |
| 137 | } |
| 138 | |
| 139 | bool isEqual(const QGalleryFilterPrivate &other) const |
| 140 | { |
| 141 | return other.type == type && static_cast<const QGalleryUnionFilterPrivate &> |
| 142 | (other).filters == filters; |
| 143 | } |
| 144 | |
| 145 | #ifndef QT_NO_DEBUG_STREAM |
| 146 | void printDebug(QDebug &debug) const |
| 147 | { |
| 148 | debug << "QGalleryUnionFilter(" ; |
| 149 | QList<QGalleryFilter>::const_iterator filter = filters.begin(); |
| 150 | if (filter != filters.end()) { |
| 151 | debug << *filter; |
| 152 | |
| 153 | while (++filter != filters.end()) |
| 154 | debug << " &&" << *filter; |
| 155 | } |
| 156 | debug << ")" ; |
| 157 | } |
| 158 | #endif |
| 159 | QList<QGalleryFilter> filters; |
| 160 | }; |
| 161 | |
| 162 | class QGalleryMetaDataFilterPrivate : public QGalleryFilterPrivate |
| 163 | { |
| 164 | public: |
| 165 | QGalleryMetaDataFilterPrivate(QGalleryFilter::Type type = QGalleryFilter::MetaData) |
| 166 | : QGalleryFilterPrivate(type) |
| 167 | , comparator(QGalleryFilter::Equals) |
| 168 | , negated(false) |
| 169 | { |
| 170 | } |
| 171 | |
| 172 | QGalleryMetaDataFilterPrivate(const QGalleryMetaDataFilterPrivate &other) |
| 173 | : QGalleryFilterPrivate(other) |
| 174 | , comparator(other.comparator) |
| 175 | , negated(other.negated) |
| 176 | , property(other.property) |
| 177 | , value(other.value) |
| 178 | { |
| 179 | } |
| 180 | |
| 181 | bool isEqual(const QGalleryFilterPrivate &other) const |
| 182 | { |
| 183 | if (other.type == type) { |
| 184 | const QGalleryMetaDataFilterPrivate &o |
| 185 | = static_cast<const QGalleryMetaDataFilterPrivate &>(other); |
| 186 | |
| 187 | return o.comparator == comparator |
| 188 | && o.negated == negated |
| 189 | && o.property == property |
| 190 | && o.value == value; |
| 191 | } else { |
| 192 | return false; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | #ifndef QT_NO_DEBUG_STREAM |
| 197 | void printDebug(QDebug &debug) const |
| 198 | { |
| 199 | if (negated) |
| 200 | debug << "!" ; |
| 201 | debug << "QGalleryMetaDataFilter(" ; |
| 202 | if (!property.isNull()) |
| 203 | debug << "propertyName: " << property << " " ; |
| 204 | debug << "comparator: " << comparator; |
| 205 | if (!value.isNull()) |
| 206 | debug << " value: " << value; |
| 207 | debug << ")" ; |
| 208 | } |
| 209 | #endif |
| 210 | |
| 211 | QGalleryFilter::Comparator comparator; |
| 212 | bool negated; |
| 213 | QString property; |
| 214 | QVariant value; |
| 215 | }; |
| 216 | |
| 217 | /*! |
| 218 | \class QGalleryIntersectionFilter |
| 219 | |
| 220 | \ingroup gallery |
| 221 | \ingroup gallery-filters |
| 222 | |
| 223 | \inmodule QtDocGallery |
| 224 | |
| 225 | \brief The QGalleryIntersectionFilter class provides a filter which matches |
| 226 | the intersection of two or more meta-data filters. |
| 227 | |
| 228 | An intersection filter represents the intersection of a list of gallery |
| 229 | filters. Filters can be added to an intersection using either the append(), |
| 230 | prepend(), or insert() functions, or using the |
| 231 | \l {operator<<()}{<< operator}. |
| 232 | |
| 233 | Intersection filters can also combining two gallery filters with the |
| 234 | && operator. |
| 235 | |
| 236 | \sa QGalleryFilter, QGalleryMetaDataFilter |
| 237 | */ |
| 238 | |
| 239 | /*! |
| 240 | Constructs an empty intersection. |
| 241 | */ |
| 242 | |
| 243 | QGalleryIntersectionFilter::QGalleryIntersectionFilter() |
| 244 | : d(new QGalleryIntersectionFilterPrivate) |
| 245 | { |
| 246 | } |
| 247 | |
| 248 | /*! |
| 249 | Constructs an intersection filter from a meta-data \a filter. |
| 250 | */ |
| 251 | |
| 252 | QGalleryIntersectionFilter::QGalleryIntersectionFilter(const QGalleryMetaDataFilter &filter) |
| 253 | : d(new QGalleryIntersectionFilterPrivate) |
| 254 | { |
| 255 | d->filters.append(t: filter); |
| 256 | } |
| 257 | |
| 258 | /*! |
| 259 | Constructs an intersection filter from a union \a filter. |
| 260 | */ |
| 261 | |
| 262 | QGalleryIntersectionFilter::QGalleryIntersectionFilter(const QGalleryUnionFilter &filter) |
| 263 | : d(new QGalleryIntersectionFilterPrivate) |
| 264 | { |
| 265 | d->filters.append(t: filter); |
| 266 | } |
| 267 | |
| 268 | /*! |
| 269 | Constructs a copy of an intersection \a filter. |
| 270 | */ |
| 271 | |
| 272 | QGalleryIntersectionFilter::QGalleryIntersectionFilter(const QGalleryIntersectionFilter &filter) |
| 273 | : d(filter.d) |
| 274 | { |
| 275 | } |
| 276 | |
| 277 | /*! |
| 278 | \internal |
| 279 | */ |
| 280 | |
| 281 | inline QGalleryIntersectionFilter::QGalleryIntersectionFilter(QGalleryFilterPrivate *d) |
| 282 | : d(static_cast<QGalleryIntersectionFilterPrivate *>(d)) |
| 283 | { |
| 284 | } |
| 285 | |
| 286 | /*! |
| 287 | \internal |
| 288 | */ |
| 289 | |
| 290 | inline QGalleryIntersectionFilter::QGalleryIntersectionFilter(QGalleryFilter::Type type) |
| 291 | : d(new QGalleryIntersectionFilterPrivate(type)) |
| 292 | { |
| 293 | } |
| 294 | |
| 295 | /*! |
| 296 | Destroys an intersection filter. |
| 297 | */ |
| 298 | |
| 299 | QGalleryIntersectionFilter::~QGalleryIntersectionFilter() |
| 300 | { |
| 301 | } |
| 302 | |
| 303 | /*! |
| 304 | Assigns the value of \a filter to another intersection filter. |
| 305 | */ |
| 306 | |
| 307 | QGalleryIntersectionFilter &QGalleryIntersectionFilter::operator =( |
| 308 | const QGalleryIntersectionFilter &filter) |
| 309 | { |
| 310 | d = filter.d; |
| 311 | |
| 312 | return *this; |
| 313 | } |
| 314 | |
| 315 | /*! |
| 316 | Returns true if the filter is a valid intersection filter. |
| 317 | |
| 318 | An invalid filter can be obtained by casting a non |
| 319 | QGalleryFilter::Intersection type QGalleryFilter to |
| 320 | QGalleryIntersectionFilter. |
| 321 | */ |
| 322 | |
| 323 | bool QGalleryIntersectionFilter::isValid() const |
| 324 | { |
| 325 | return d->type == QGalleryFilter::Intersection; |
| 326 | } |
| 327 | |
| 328 | /*! |
| 329 | Returns the number of filters in an intersection. |
| 330 | */ |
| 331 | |
| 332 | int QGalleryIntersectionFilter::filterCount() const |
| 333 | { |
| 334 | return d->filters.count(); |
| 335 | } |
| 336 | |
| 337 | /*! |
| 338 | Returns true if an intersection does not contain any filters, and returns |
| 339 | false otherwise. |
| 340 | */ |
| 341 | |
| 342 | bool QGalleryIntersectionFilter::isEmpty() const |
| 343 | { |
| 344 | return d->filters.isEmpty(); |
| 345 | } |
| 346 | |
| 347 | /*! |
| 348 | Return the filters contained in an intersection. |
| 349 | */ |
| 350 | |
| 351 | QList<QGalleryFilter> QGalleryIntersectionFilter::filters() const |
| 352 | { |
| 353 | return d->filters; |
| 354 | } |
| 355 | |
| 356 | /*! |
| 357 | Appends a meta-data \a filter to an intersection. |
| 358 | */ |
| 359 | |
| 360 | void QGalleryIntersectionFilter::append(const QGalleryMetaDataFilter &filter) |
| 361 | { |
| 362 | d->filters.append(t: filter); |
| 363 | } |
| 364 | |
| 365 | /*! |
| 366 | Appens a union \a filter to an intersection. |
| 367 | */ |
| 368 | |
| 369 | void QGalleryIntersectionFilter::append(const QGalleryUnionFilter &filter) |
| 370 | { |
| 371 | d->filters.append(t: filter); |
| 372 | } |
| 373 | |
| 374 | /*! |
| 375 | Appends the contents of an intersection \a filter to an intersection. |
| 376 | */ |
| 377 | |
| 378 | void QGalleryIntersectionFilter::append(const QGalleryIntersectionFilter &filter) |
| 379 | { |
| 380 | d->filters += filter.d->filters; |
| 381 | } |
| 382 | |
| 383 | /*! |
| 384 | Prepends a meta-data \a filter to an intersection. |
| 385 | */ |
| 386 | |
| 387 | void QGalleryIntersectionFilter::prepend(const QGalleryMetaDataFilter &filter) |
| 388 | { |
| 389 | d->filters.prepend(t: filter); |
| 390 | } |
| 391 | |
| 392 | /*! |
| 393 | Prepends a union \a filter to an intersection. |
| 394 | */ |
| 395 | |
| 396 | void QGalleryIntersectionFilter::prepend(const QGalleryUnionFilter &filter) |
| 397 | { |
| 398 | d->filters.prepend(t: filter); |
| 399 | } |
| 400 | |
| 401 | /*! |
| 402 | Prepends the contents of an intersection \a filter to an intersection. |
| 403 | */ |
| 404 | |
| 405 | void QGalleryIntersectionFilter::prepend(const QGalleryIntersectionFilter &filter) |
| 406 | { |
| 407 | d->filters = filter.d->filters + d->filters; |
| 408 | } |
| 409 | |
| 410 | /*! |
| 411 | Inserts a meta-data \a filter into an intersection at \a index. |
| 412 | */ |
| 413 | |
| 414 | void QGalleryIntersectionFilter::insert(int index, const QGalleryMetaDataFilter &filter) |
| 415 | { |
| 416 | d->filters.insert(i: index, t: filter); |
| 417 | } |
| 418 | |
| 419 | /*! |
| 420 | Inserts a union \a filter into an intersection at \a index. |
| 421 | */ |
| 422 | |
| 423 | void QGalleryIntersectionFilter::insert(int index, const QGalleryUnionFilter &filter) |
| 424 | { |
| 425 | d->filters.insert(i: index, t: filter); |
| 426 | } |
| 427 | |
| 428 | /*! |
| 429 | Inserts the contents of an intersection \a filter into an intersection at |
| 430 | \a index. |
| 431 | */ |
| 432 | |
| 433 | void QGalleryIntersectionFilter::insert(int index, const QGalleryIntersectionFilter &filter) |
| 434 | { |
| 435 | QList<QGalleryFilter> start = d->filters.mid(pos: 0, alength: index); |
| 436 | QList<QGalleryFilter> end = d->filters.mid(pos: index); |
| 437 | |
| 438 | d->filters = start + filter.d->filters + end; |
| 439 | } |
| 440 | |
| 441 | /*! |
| 442 | Replaces the filter at \a index in an intersection with a meta-data |
| 443 | \a filter. |
| 444 | */ |
| 445 | |
| 446 | void QGalleryIntersectionFilter::replace(int index, const QGalleryMetaDataFilter &filter) |
| 447 | { |
| 448 | d->filters.replace(i: index, t: filter); |
| 449 | } |
| 450 | |
| 451 | /*! |
| 452 | Replaces the filter at \a index in an intersection with a union |
| 453 | \a filter. |
| 454 | */ |
| 455 | |
| 456 | void QGalleryIntersectionFilter::replace(int index, const QGalleryUnionFilter &filter) |
| 457 | { |
| 458 | d->filters.replace(i: index, t: filter); |
| 459 | } |
| 460 | |
| 461 | /*! |
| 462 | Removes the filter at \a index from an intersection. |
| 463 | */ |
| 464 | |
| 465 | void QGalleryIntersectionFilter::remove(int index) |
| 466 | { |
| 467 | d->filters.removeAt(i: index); |
| 468 | } |
| 469 | |
| 470 | /*! |
| 471 | Clears all the filters from an intersection. |
| 472 | */ |
| 473 | |
| 474 | void QGalleryIntersectionFilter::clear() |
| 475 | { |
| 476 | d->filters.clear(); |
| 477 | } |
| 478 | |
| 479 | /*! |
| 480 | Appends a \a filter to an intersection. |
| 481 | */ |
| 482 | |
| 483 | QGalleryIntersectionFilter &QGalleryIntersectionFilter::operator <<( |
| 484 | const QGalleryIntersectionFilter &filter) |
| 485 | { |
| 486 | d->filters.append(t: filter.d->filters); |
| 487 | |
| 488 | return *this; |
| 489 | } |
| 490 | |
| 491 | /*! |
| 492 | \fn QGalleryIntersectionFilter operator &&(const QGalleryIntersectionFilter &filter1, const QGalleryIntersectionFilter &filter2) |
| 493 | |
| 494 | Returns a gallery filter matches the intersection of \a filter1 and |
| 495 | \a filter2. |
| 496 | |
| 497 | \relates QGalleryIntersectionFilter |
| 498 | */ |
| 499 | |
| 500 | QGalleryIntersectionFilter operator &&( |
| 501 | const QGalleryIntersectionFilter &filter1, const QGalleryIntersectionFilter &filter2) |
| 502 | { |
| 503 | QGalleryIntersectionFilter filter = filter1; |
| 504 | filter.append(filter: filter2); |
| 505 | return filter; |
| 506 | } |
| 507 | |
| 508 | /*! |
| 509 | \class QGalleryUnionFilter |
| 510 | |
| 511 | \ingroup gallery |
| 512 | \ingroup gallery-filters |
| 513 | |
| 514 | \inmodule QtDocGallery |
| 515 | |
| 516 | \brief The QGalleryUnionFilter class provides a filter which matches the |
| 517 | union of two or more meta-data filters. |
| 518 | |
| 519 | A union filter represents the union of a list of gallery filters. |
| 520 | Filters can be added to an union using either the append(), prepend(), or |
| 521 | insert() functions, or using the \l {operator<<()}{<< operator}. |
| 522 | |
| 523 | Union filters can also combining two gallery filters with the |
| 524 | && operator. |
| 525 | |
| 526 | \sa QGalleryFilter, QGalleryMetaDataFilter |
| 527 | */ |
| 528 | |
| 529 | /*! |
| 530 | Constructs an empty union. |
| 531 | */ |
| 532 | |
| 533 | QGalleryUnionFilter::QGalleryUnionFilter() |
| 534 | : d(new QGalleryUnionFilterPrivate) |
| 535 | { |
| 536 | } |
| 537 | |
| 538 | /*! |
| 539 | Constructs a union filter from a meta data \a filter. |
| 540 | */ |
| 541 | |
| 542 | QGalleryUnionFilter::QGalleryUnionFilter(const QGalleryMetaDataFilter &filter) |
| 543 | : d(new QGalleryUnionFilterPrivate) |
| 544 | { |
| 545 | d->filters.append(t: filter); |
| 546 | } |
| 547 | |
| 548 | /*! |
| 549 | Constructs a union filter from an intersection \a filter. |
| 550 | */ |
| 551 | |
| 552 | QGalleryUnionFilter::QGalleryUnionFilter(const QGalleryIntersectionFilter &filter) |
| 553 | : d(new QGalleryUnionFilterPrivate) |
| 554 | { |
| 555 | d->filters.append(t: filter); |
| 556 | } |
| 557 | |
| 558 | /*! |
| 559 | Constructs a copy of a union \a filter. |
| 560 | */ |
| 561 | |
| 562 | QGalleryUnionFilter::QGalleryUnionFilter(const QGalleryUnionFilter &filter) |
| 563 | : d(filter.d) |
| 564 | { |
| 565 | } |
| 566 | |
| 567 | /*! |
| 568 | \internal |
| 569 | */ |
| 570 | |
| 571 | QGalleryUnionFilter::QGalleryUnionFilter(QGalleryFilterPrivate *d) |
| 572 | : d(static_cast<QGalleryUnionFilterPrivate *>(d)) |
| 573 | { |
| 574 | } |
| 575 | |
| 576 | /*! |
| 577 | \internal |
| 578 | */ |
| 579 | |
| 580 | inline QGalleryUnionFilter::QGalleryUnionFilter(QGalleryFilter::Type type) |
| 581 | : d(new QGalleryUnionFilterPrivate(type)) |
| 582 | { |
| 583 | } |
| 584 | |
| 585 | /*! |
| 586 | Destroys a union filter. |
| 587 | */ |
| 588 | |
| 589 | QGalleryUnionFilter::~QGalleryUnionFilter() |
| 590 | { |
| 591 | } |
| 592 | |
| 593 | /*! |
| 594 | Assigns the value of \a filter to another union filter. |
| 595 | */ |
| 596 | |
| 597 | QGalleryUnionFilter &QGalleryUnionFilter::operator =(const QGalleryUnionFilter &filter) |
| 598 | { |
| 599 | d = filter.d; |
| 600 | |
| 601 | return *this; |
| 602 | } |
| 603 | |
| 604 | /*! |
| 605 | Returns true if the filter is a valid union filter. |
| 606 | |
| 607 | An invalid filter can be obtained by casting a non QGalleryFilter::Union |
| 608 | type QGalleryFilter to QGalleryUnionFilter. |
| 609 | */ |
| 610 | |
| 611 | bool QGalleryUnionFilter::isValid() const |
| 612 | { |
| 613 | return d->type == QGalleryFilter::Union; |
| 614 | } |
| 615 | |
| 616 | /*! |
| 617 | Returns the number of filters in a union. |
| 618 | */ |
| 619 | |
| 620 | int QGalleryUnionFilter::filterCount() const |
| 621 | { |
| 622 | return d->filters.count(); |
| 623 | } |
| 624 | |
| 625 | /*! |
| 626 | Returns true if a union contains no filters, and false otherwise. |
| 627 | */ |
| 628 | |
| 629 | bool QGalleryUnionFilter::isEmpty() const |
| 630 | { |
| 631 | return d->filters.isEmpty(); |
| 632 | } |
| 633 | |
| 634 | /*! |
| 635 | Returns the filters contained in a union. |
| 636 | */ |
| 637 | |
| 638 | QList<QGalleryFilter> QGalleryUnionFilter::filters() const |
| 639 | { |
| 640 | return d->filters; |
| 641 | } |
| 642 | |
| 643 | /*! |
| 644 | Appends a meta-data \a filter to a union. |
| 645 | */ |
| 646 | |
| 647 | void QGalleryUnionFilter::append(const QGalleryMetaDataFilter &filter) |
| 648 | { |
| 649 | d->filters.append(t: filter); |
| 650 | } |
| 651 | |
| 652 | /*! |
| 653 | Appends an intersection \a filter to a union. |
| 654 | */ |
| 655 | |
| 656 | void QGalleryUnionFilter::append(const QGalleryIntersectionFilter &filter) |
| 657 | { |
| 658 | d->filters.append(t: filter); |
| 659 | } |
| 660 | |
| 661 | /*! |
| 662 | Appends the contents of a union \a filter to a union. |
| 663 | */ |
| 664 | |
| 665 | void QGalleryUnionFilter::append(const QGalleryUnionFilter &filter) |
| 666 | { |
| 667 | d->filters += filter.d->filters; |
| 668 | } |
| 669 | |
| 670 | /*! |
| 671 | Prepends a meta-data \a filter to a union. |
| 672 | */ |
| 673 | |
| 674 | void QGalleryUnionFilter::prepend(const QGalleryMetaDataFilter &filter) |
| 675 | { |
| 676 | d->filters.prepend(t: filter); |
| 677 | } |
| 678 | |
| 679 | /*! |
| 680 | Prepends an intersection \a filter to a union. |
| 681 | */ |
| 682 | |
| 683 | void QGalleryUnionFilter::prepend(const QGalleryIntersectionFilter &filter) |
| 684 | { |
| 685 | d->filters.prepend(t: filter); |
| 686 | } |
| 687 | |
| 688 | /*! |
| 689 | Prepends the contents of a union \a filter to a union. |
| 690 | */ |
| 691 | |
| 692 | void QGalleryUnionFilter::prepend(const QGalleryUnionFilter &filter) |
| 693 | { |
| 694 | d->filters = filter.d->filters + d->filters; |
| 695 | } |
| 696 | |
| 697 | /*! |
| 698 | Inserts a meta-data \a filter into a union at \a index. |
| 699 | */ |
| 700 | |
| 701 | void QGalleryUnionFilter::insert(int index, const QGalleryMetaDataFilter &filter) |
| 702 | { |
| 703 | d->filters.insert(i: index, t: filter); |
| 704 | } |
| 705 | |
| 706 | /*! |
| 707 | Inserts an intersection \a filter into a union at \a index. |
| 708 | */ |
| 709 | |
| 710 | void QGalleryUnionFilter::insert(int index, const QGalleryIntersectionFilter &filter) |
| 711 | { |
| 712 | d->filters.insert(i: index, t: filter); |
| 713 | } |
| 714 | |
| 715 | /*! |
| 716 | Inserts the contents of a union \a filter into a union at \a index. |
| 717 | */ |
| 718 | |
| 719 | void QGalleryUnionFilter::insert(int index, const QGalleryUnionFilter &filter) |
| 720 | { |
| 721 | QList<QGalleryFilter> start = d->filters.mid(pos: 0, alength: index); |
| 722 | QList<QGalleryFilter> end = d->filters.mid(pos: index); |
| 723 | |
| 724 | d->filters = start + filter.d->filters + end; |
| 725 | } |
| 726 | |
| 727 | /*! |
| 728 | Replaces the filter at \a index in a union with a meta-data \a filter. |
| 729 | */ |
| 730 | |
| 731 | void QGalleryUnionFilter::replace(int index, const QGalleryMetaDataFilter &filter) |
| 732 | { |
| 733 | d->filters.replace(i: index, t: filter); |
| 734 | } |
| 735 | |
| 736 | /*! |
| 737 | Replaces the filter at \a index in a union with an intersetion \a filter. |
| 738 | */ |
| 739 | |
| 740 | void QGalleryUnionFilter::replace(int index, const QGalleryIntersectionFilter &filter) |
| 741 | { |
| 742 | d->filters.replace(i: index, t: filter); |
| 743 | } |
| 744 | |
| 745 | /*! |
| 746 | Removes the filter at \a index from a union. |
| 747 | */ |
| 748 | |
| 749 | void QGalleryUnionFilter::remove(int index) |
| 750 | { |
| 751 | d->filters.removeAt(i: index); |
| 752 | } |
| 753 | |
| 754 | /*! |
| 755 | Clears all the filters from a union. |
| 756 | */ |
| 757 | |
| 758 | void QGalleryUnionFilter::clear() |
| 759 | { |
| 760 | d->filters.clear(); |
| 761 | } |
| 762 | |
| 763 | /*! |
| 764 | Appends a \a filter to a union. |
| 765 | */ |
| 766 | |
| 767 | QGalleryUnionFilter &QGalleryUnionFilter::operator <<(const QGalleryUnionFilter &filter) |
| 768 | { |
| 769 | d->filters.append(t: filter.d->filters); |
| 770 | |
| 771 | return *this; |
| 772 | } |
| 773 | |
| 774 | /*! |
| 775 | \fn QGalleryUnionFilter operator ||(const QGalleryUnionFilter &filter1, const QGalleryUnionFilter &filter2) |
| 776 | |
| 777 | Returns a gallery filter which matches the union of \a filter1 and |
| 778 | \a filter2. |
| 779 | |
| 780 | \relates QGalleryUnionFilter |
| 781 | */ |
| 782 | |
| 783 | QGalleryUnionFilter operator ||( |
| 784 | const QGalleryUnionFilter &filter1, const QGalleryUnionFilter &filter2) |
| 785 | { |
| 786 | QGalleryUnionFilter filter = filter1; |
| 787 | filter.append(filter: filter2); |
| 788 | return filter; |
| 789 | } |
| 790 | |
| 791 | /*! |
| 792 | \class QGalleryMetaDataFilter |
| 793 | |
| 794 | \ingroup gallery |
| 795 | \ingroup gallery-filters |
| 796 | |
| 797 | \inmodule QtDocGallery |
| 798 | |
| 799 | \brief The QGalleryMetaDataFilter class provides a filter which accepts |
| 800 | items with meta-data properties matching a specific value. |
| 801 | |
| 802 | A meta-data filter represents a \l {comparator()}{comparison} between the |
| 803 | value of an item's meta-data property() and a fixed value(). A filter |
| 804 | can be constructed by passing the property name, value, and comparator |
| 805 | to the filter contructor or by using one of the operator overloads or |
| 806 | constructor functions on QGalleryProperty. |
| 807 | |
| 808 | Meta-data filters can also be combined to create \l {QGalleryUnionFilter} |
| 809 | {union} or \l {QGalleryIntersectionFilter}{intersection} filters using the |
| 810 | || and && operators respectively. |
| 811 | |
| 812 | \sa QGalleryFilter, QGalleryProperty |
| 813 | */ |
| 814 | |
| 815 | /*! |
| 816 | Constructs an empty meta-data filter. |
| 817 | */ |
| 818 | |
| 819 | QGalleryMetaDataFilter::QGalleryMetaDataFilter() |
| 820 | : d(new QGalleryMetaDataFilterPrivate) |
| 821 | { |
| 822 | } |
| 823 | |
| 824 | /*! |
| 825 | Constructs a meta-data filter which tests if a meta-data \a property |
| 826 | matches a \a value according to a \a comparison operator. |
| 827 | */ |
| 828 | |
| 829 | QGalleryMetaDataFilter::QGalleryMetaDataFilter( |
| 830 | const QString &property, |
| 831 | const QVariant &value, |
| 832 | QGalleryFilter::Comparator comparison) |
| 833 | : d(new QGalleryMetaDataFilterPrivate) |
| 834 | { |
| 835 | d->property = property; |
| 836 | d->value = value; |
| 837 | d->comparator = comparison; |
| 838 | } |
| 839 | |
| 840 | /*! |
| 841 | Constructs a copy of a meta-data \a filter. |
| 842 | */ |
| 843 | |
| 844 | QGalleryMetaDataFilter::QGalleryMetaDataFilter(const QGalleryMetaDataFilter &filter) |
| 845 | : d(filter.d) |
| 846 | { |
| 847 | } |
| 848 | |
| 849 | /*! |
| 850 | \internal |
| 851 | */ |
| 852 | |
| 853 | QGalleryMetaDataFilter::QGalleryMetaDataFilter(QGalleryFilterPrivate *d) |
| 854 | : d(static_cast<QGalleryMetaDataFilterPrivate *>(d)) |
| 855 | { |
| 856 | } |
| 857 | |
| 858 | /*! |
| 859 | \internal |
| 860 | */ |
| 861 | |
| 862 | inline QGalleryMetaDataFilter::QGalleryMetaDataFilter(QGalleryFilter::Type type) |
| 863 | : d(new QGalleryMetaDataFilterPrivate(type)) |
| 864 | { |
| 865 | } |
| 866 | |
| 867 | /*! |
| 868 | Destroys a meta-data filter. |
| 869 | */ |
| 870 | |
| 871 | QGalleryMetaDataFilter::~QGalleryMetaDataFilter() |
| 872 | { |
| 873 | } |
| 874 | |
| 875 | /*! |
| 876 | Assigns the value of \a filter to another meta-data filter. |
| 877 | */ |
| 878 | |
| 879 | QGalleryMetaDataFilter &QGalleryMetaDataFilter::operator =(const QGalleryMetaDataFilter &filter) |
| 880 | { |
| 881 | d = filter.d; |
| 882 | |
| 883 | return *this; |
| 884 | } |
| 885 | |
| 886 | /*! |
| 887 | Returns true if the filter is a valid meta-data filter. |
| 888 | |
| 889 | An invalid filter can be obtained by casting a non QGalleryFilter::MetaData |
| 890 | type QGalleryFilter to QGalleryMetaDataFilter. |
| 891 | */ |
| 892 | |
| 893 | bool QGalleryMetaDataFilter::isValid() const |
| 894 | { |
| 895 | return d->type == QGalleryFilter::MetaData; |
| 896 | } |
| 897 | |
| 898 | /*! |
| 899 | Returns the name of the property the value of a meta-data filter is |
| 900 | compared against. |
| 901 | */ |
| 902 | |
| 903 | QString QGalleryMetaDataFilter::propertyName() const |
| 904 | { |
| 905 | return d->property; |
| 906 | } |
| 907 | |
| 908 | /*! |
| 909 | Sets the \a name of the property the value of meta-data filter is compared |
| 910 | against. |
| 911 | */ |
| 912 | |
| 913 | void QGalleryMetaDataFilter::setPropertyName(const QString &name) |
| 914 | { |
| 915 | d->property = name; |
| 916 | } |
| 917 | |
| 918 | /*! |
| 919 | Returns the value a property is expected to match for a meta-data filter to |
| 920 | pass. |
| 921 | */ |
| 922 | |
| 923 | QVariant QGalleryMetaDataFilter::value() const |
| 924 | { |
| 925 | return d->value; |
| 926 | } |
| 927 | |
| 928 | /*! |
| 929 | Sets the \a value a property is expected to match for a meta-data filter to |
| 930 | pass. |
| 931 | */ |
| 932 | |
| 933 | void QGalleryMetaDataFilter::setValue(const QVariant &value) |
| 934 | { |
| 935 | d->value = value; |
| 936 | } |
| 937 | |
| 938 | /*! |
| 939 | Returns the comparator used by a meta-data filter. |
| 940 | */ |
| 941 | |
| 942 | QGalleryFilter::Comparator QGalleryMetaDataFilter::comparator() const |
| 943 | { |
| 944 | return d->comparator; |
| 945 | } |
| 946 | |
| 947 | /*! |
| 948 | Sets the \a comparator used by a meta-data filter. |
| 949 | */ |
| 950 | |
| 951 | void QGalleryMetaDataFilter::setComparator(QGalleryFilter::Comparator comparator) |
| 952 | { |
| 953 | d->comparator = comparator; |
| 954 | } |
| 955 | |
| 956 | /*! |
| 957 | Returns whether the result of a meta-data filter should be negated. |
| 958 | */ |
| 959 | |
| 960 | bool QGalleryMetaDataFilter::isNegated() const |
| 961 | { |
| 962 | return d->negated; |
| 963 | } |
| 964 | |
| 965 | /*! |
| 966 | Sets whether the result of a meta-data filter should be \a negated. |
| 967 | */ |
| 968 | |
| 969 | void QGalleryMetaDataFilter::setNegated(bool negated) |
| 970 | { |
| 971 | d->negated = negated; |
| 972 | } |
| 973 | |
| 974 | /*! |
| 975 | Returns a meta-data filter which tests the negation of an existing filter. |
| 976 | */ |
| 977 | |
| 978 | QGalleryMetaDataFilter QGalleryMetaDataFilter::operator !() const |
| 979 | { |
| 980 | QGalleryMetaDataFilter filter(*this); |
| 981 | filter.setNegated(!d->negated); |
| 982 | return filter; |
| 983 | } |
| 984 | |
| 985 | /*! |
| 986 | \class QGalleryFilter |
| 987 | |
| 988 | \ingroup gallery |
| 989 | \ingroup gallery-filters |
| 990 | |
| 991 | \inmodule QtDocGallery |
| 992 | |
| 993 | \brief The QGalleryFilter class provides filtering criteria for gallery |
| 994 | requests. |
| 995 | |
| 996 | A gallery filter may be a {QGalleryMetaData}{meta-data}, |
| 997 | {QGalleryUnionFilter}{union}, or {QGalleryIntersectionFilter}{intersection} |
| 998 | filter. The type of a QGalleryFilter is given by the type() function, and |
| 999 | a filter can be cast to its specific type using one of toMetaFilter(), |
| 1000 | toUnionFilter() or toIntersectionFilter(). Casting to different type of |
| 1001 | filter will always result in an invalid filter. |
| 1002 | |
| 1003 | \sa QGalleryMetaDataFilter, QGalleryUnionFilter, QGalleryIntersectionFilter |
| 1004 | */ |
| 1005 | |
| 1006 | /*! |
| 1007 | \enum QGalleryFilter::Type |
| 1008 | |
| 1009 | Identifies the type of a filter. |
| 1010 | |
| 1011 | \value Invalid The filter is a null QGalleryFilter. |
| 1012 | \value Intersection The filter is a QGalleryIntersectionFilter. |
| 1013 | \value Union The filter is a QGalleryUnionFilter. |
| 1014 | \value MetaData The filter is a QGalleryMetaDataFilter. |
| 1015 | */ |
| 1016 | |
| 1017 | /*! |
| 1018 | \enum QGalleryFilter::Comparator |
| 1019 | |
| 1020 | Identifies the comparison made by a QGalleryMetaDataFilter. |
| 1021 | |
| 1022 | \value Equals The filter tests if a meta-data property is equal to a value. |
| 1023 | \value LessThan The filter tests if a meta-data property is less than a |
| 1024 | value. |
| 1025 | \value GreaterThan The filter tests if a meta-data property is greater |
| 1026 | than a value. |
| 1027 | \value LessThanEquals The filter tests if a meta-data property is less than |
| 1028 | or equal to a value. |
| 1029 | \value GreaterThanEquals The filter tests if a meta-data property is |
| 1030 | greater than or equal to a value. |
| 1031 | \value Contains The filter tests if a meta-data property contains a |
| 1032 | sub-string. |
| 1033 | \value StartsWith The filter tests if a meta-data property starts with a |
| 1034 | string. |
| 1035 | \value EndsWith The filter tests if a meta-data property ends with a |
| 1036 | string. |
| 1037 | \value Wildcard The filter tests if a meta-data property matches a wildcard |
| 1038 | string. |
| 1039 | \value RegExp The filter tests if a meta-data property matches a regular |
| 1040 | expression. |
| 1041 | */ |
| 1042 | |
| 1043 | /*! |
| 1044 | Constructs a gallery filter of type \l Invalid. |
| 1045 | */ |
| 1046 | |
| 1047 | QGalleryFilter::QGalleryFilter() |
| 1048 | : d(new QGalleryInvalidFilterPrivate) |
| 1049 | { |
| 1050 | } |
| 1051 | |
| 1052 | /*! |
| 1053 | Constructs a copy of a gallery \a filter. |
| 1054 | */ |
| 1055 | |
| 1056 | QGalleryFilter::QGalleryFilter(const QGalleryFilter &filter) |
| 1057 | : d(filter.d) |
| 1058 | { |
| 1059 | } |
| 1060 | |
| 1061 | /*! |
| 1062 | Constructs a copy of a gallery intersection \a filter. |
| 1063 | */ |
| 1064 | |
| 1065 | QGalleryFilter::QGalleryFilter(const QGalleryIntersectionFilter &filter) |
| 1066 | : d(const_cast<QGalleryIntersectionFilterPrivate *>(filter.d.constData())) |
| 1067 | { |
| 1068 | } |
| 1069 | |
| 1070 | /*! |
| 1071 | Constructs a copy of a gallery union \a filter. |
| 1072 | */ |
| 1073 | |
| 1074 | QGalleryFilter::QGalleryFilter(const QGalleryUnionFilter &filter) |
| 1075 | : d(const_cast<QGalleryUnionFilterPrivate *>(filter.d.constData())) |
| 1076 | { |
| 1077 | } |
| 1078 | |
| 1079 | /*! |
| 1080 | Constructs a copy of a gallery meta-data \a filter. |
| 1081 | */ |
| 1082 | |
| 1083 | QGalleryFilter::QGalleryFilter(const QGalleryMetaDataFilter &filter) |
| 1084 | : d(const_cast<QGalleryMetaDataFilterPrivate *>(filter.d.constData())) |
| 1085 | { |
| 1086 | } |
| 1087 | |
| 1088 | /*! |
| 1089 | Destroys a gallery filter. |
| 1090 | */ |
| 1091 | |
| 1092 | QGalleryFilter::~QGalleryFilter() |
| 1093 | { |
| 1094 | } |
| 1095 | |
| 1096 | /*! |
| 1097 | Assigns the value of \a filter to another filter. |
| 1098 | */ |
| 1099 | |
| 1100 | QGalleryFilter &QGalleryFilter::operator =(const QGalleryFilter &filter) |
| 1101 | { |
| 1102 | d = filter.d; |
| 1103 | |
| 1104 | return *this; |
| 1105 | } |
| 1106 | |
| 1107 | /*! |
| 1108 | Returns the type of a filter. |
| 1109 | */ |
| 1110 | |
| 1111 | QGalleryFilter::Type QGalleryFilter::type() const |
| 1112 | { |
| 1113 | return d->type; |
| 1114 | } |
| 1115 | |
| 1116 | /*! |
| 1117 | Returns true if the type() of the filter is not equal to Invalid. |
| 1118 | */ |
| 1119 | |
| 1120 | bool QGalleryFilter::isValid() const |
| 1121 | { |
| 1122 | return d->type != QGalleryFilter::Invalid; |
| 1123 | } |
| 1124 | |
| 1125 | /*! |
| 1126 | Casts a filter to an intersection filter. The filter must be of type |
| 1127 | Intersection or this will return an Invalid filter. |
| 1128 | |
| 1129 | Returns a QGalleryIntersectionFilter. |
| 1130 | */ |
| 1131 | |
| 1132 | QGalleryIntersectionFilter QGalleryFilter::toIntersectionFilter() const |
| 1133 | { |
| 1134 | return d->type == Intersection |
| 1135 | ? QGalleryIntersectionFilter(const_cast<QGalleryFilterPrivate *>(d.constData())) |
| 1136 | : QGalleryIntersectionFilter(QGalleryFilter::Invalid); |
| 1137 | } |
| 1138 | |
| 1139 | /*! |
| 1140 | Casts a filter to a union filter. The filter must be of type Union or this |
| 1141 | will return an Invalid filter. |
| 1142 | |
| 1143 | Returns a QGalleryUnionFilter. |
| 1144 | */ |
| 1145 | |
| 1146 | QGalleryUnionFilter QGalleryFilter::toUnionFilter() const |
| 1147 | { |
| 1148 | return d->type == Union |
| 1149 | ? QGalleryUnionFilter(const_cast<QGalleryFilterPrivate *>(d.constData())) |
| 1150 | : QGalleryUnionFilter(QGalleryFilter::Invalid); |
| 1151 | } |
| 1152 | |
| 1153 | /*! |
| 1154 | Casts a filter to a meta-data filter. The filter must be of type MetaData |
| 1155 | or this will return an Invalid filter. |
| 1156 | |
| 1157 | Returns a QGalleryMetaDataFilter. |
| 1158 | */ |
| 1159 | |
| 1160 | QGalleryMetaDataFilter QGalleryFilter::toMetaDataFilter() const |
| 1161 | { |
| 1162 | return d->type == MetaData |
| 1163 | ? QGalleryMetaDataFilter(const_cast<QGalleryFilterPrivate *>(d.constData())) |
| 1164 | : QGalleryMetaDataFilter(QGalleryFilter::Invalid); |
| 1165 | } |
| 1166 | |
| 1167 | #ifndef QT_NO_DEBUG_STREAM |
| 1168 | QDebug operator <<(QDebug debug, const QGalleryFilter &filter) |
| 1169 | { |
| 1170 | filter.d->printDebug(debug&: debug.nospace()); |
| 1171 | |
| 1172 | return debug; |
| 1173 | } |
| 1174 | #endif |
| 1175 | |
| 1176 | /*! |
| 1177 | Compares \a filter1 to filter2. |
| 1178 | |
| 1179 | Returns true if the filters are identical, and false otherwise. |
| 1180 | */ |
| 1181 | |
| 1182 | bool operator ==(const QGalleryFilter &filter1, const QGalleryFilter &filter2) |
| 1183 | { |
| 1184 | return filter1.d == filter2.d || filter1.d->isEqual(other: *filter2.d); |
| 1185 | } |
| 1186 | |
| 1187 | /*! |
| 1188 | Compares \a filter1 to filter2. |
| 1189 | |
| 1190 | Returns true if the filters are not identical, and false otherwise. |
| 1191 | */ |
| 1192 | |
| 1193 | bool operator !=(const QGalleryFilter &filter1, const QGalleryFilter &filter2) |
| 1194 | { |
| 1195 | return filter1.d != filter2.d && !filter1.d->isEqual(other: *filter2.d); |
| 1196 | } |
| 1197 | |
| 1198 | QT_END_NAMESPACE_DOCGALLERY |
| 1199 | |