1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QPAGERANGES_H
5#define QPAGERANGES_H
6
7#include <QtGui/qtguiglobal.h>
8#include <QtCore/qstring.h>
9#include <QtCore/qlist.h>
10#include <QtCore/qshareddata.h>
11#include <QtCore/qmetatype.h>
12
13QT_BEGIN_NAMESPACE
14
15class QDebug;
16class QDataStream;
17class QPageRangesPrivate;
18QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QPageRangesPrivate, Q_GUI_EXPORT)
19
20class Q_GUI_EXPORT QPageRanges
21{
22public:
23 QPageRanges();
24 ~QPageRanges();
25
26 QPageRanges(const QPageRanges &other) noexcept;
27 QPageRanges &operator=(const QPageRanges &other) noexcept;
28
29 QPageRanges(QPageRanges &&other) noexcept = default;
30 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QPageRanges)
31 void swap(QPageRanges &other) noexcept
32 { d.swap(other&: other.d); }
33
34 friend bool operator==(const QPageRanges &lhs, const QPageRanges &rhs) noexcept
35 { return lhs.isEqual(other: rhs); }
36 friend bool operator!=(const QPageRanges &lhs, const QPageRanges &rhs) noexcept
37 { return !lhs.isEqual(other: rhs); }
38
39 struct Range {
40 int from = -1;
41 int to = -1;
42 bool contains(int pageNumber) const noexcept
43 { return from <= pageNumber && to >= pageNumber; }
44 friend bool operator==(Range lhs, Range rhs) noexcept
45 { return lhs.from == rhs.from && lhs.to == rhs.to; }
46 friend bool operator!=(Range lhs, Range rhs) noexcept
47 { return !(lhs == rhs); }
48 friend bool operator<(Range lhs, Range rhs) noexcept
49 { return lhs.from < rhs.from || (!(rhs.from < lhs.from) && lhs.to < rhs.to); }
50 };
51
52 void addPage(int pageNumber);
53 void addRange(int from, int to);
54 QList<Range> toRangeList() const;
55 void clear();
56
57 QString toString() const;
58 static QPageRanges fromString(const QString &ranges);
59
60 bool contains(int pageNumber) const;
61 bool isEmpty() const;
62 int firstPage() const;
63 int lastPage() const;
64
65 void detach();
66
67private:
68 bool isEqual(const QPageRanges &other) const noexcept;
69
70 QExplicitlySharedDataPointer<QPageRangesPrivate> d;
71};
72
73#ifndef QT_NO_DATASTREAM
74Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPageRanges &);
75Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPageRanges &);
76#endif
77
78#ifndef QT_NO_DEBUG_STREAM
79Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QPageRanges &pageRanges);
80#endif
81
82Q_DECLARE_SHARED(QPageRanges)
83Q_DECLARE_TYPEINFO(QPageRanges::Range, Q_RELOCATABLE_TYPE);
84
85QT_END_NAMESPACE
86
87QT_DECL_METATYPE_EXTERN(QPageRanges, Q_GUI_EXPORT)
88
89#endif // QPAGERANGES_H
90

source code of qtbase/src/gui/painting/qpageranges.h