Coverage Report

Created: 2026-03-31 07:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/prefix/include/QtGui/qregion.h
Line
Count
Source
1
// Copyright (C) 2016 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
// Qt-Security score:significant reason:default
4
5
#ifndef QREGION_H
6
#define QREGION_H
7
8
#include <QtGui/qtguiglobal.h>
9
#include <QtCore/qatomic.h>
10
#include <QtCore/qrect.h>
11
#include <QtGui/qwindowdefs.h>
12
13
#ifndef QT_NO_DATASTREAM
14
#include <QtCore/qdatastream.h>
15
#endif
16
#include <QtCore/qspan.h>
17
18
QT_BEGIN_NAMESPACE
19
20
21
class QVariant;
22
23
struct QRegionPrivate;
24
25
class QBitmap;
26
27
class Q_GUI_EXPORT QRegion
28
{
29
public:
30
    enum RegionType { Rectangle, Ellipse };
31
32
    QRegion();
33
    QRegion(int x, int y, int w, int h, RegionType t = Rectangle);
34
    QRegion(const QRect &r, RegionType t = Rectangle);
35
    QRegion(const QPolygon &pa, Qt::FillRule fillRule = Qt::OddEvenFill);
36
    QRegion(const QRegion &region);
37
    QRegion(QRegion &&other) noexcept
38
0
        : d(std::exchange(other.d, const_cast<QRegionData*>(&shared_empty))) {}
39
    QRegion(const QBitmap &bitmap);
40
    ~QRegion();
41
    QRegion &operator=(const QRegion &);
42
    QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QRegion)
43
0
    void swap(QRegion &other) noexcept { qt_ptr_swap(d, other.d); }
44
    bool isEmpty() const;
45
    bool isNull() const;
46
47
    typedef const QRect *const_iterator;
48
    typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
49
50
    const_iterator begin()  const noexcept;
51
0
    const_iterator cbegin() const noexcept { return begin(); }
52
    const_iterator end()    const noexcept;
53
0
    const_iterator cend()   const noexcept { return end(); }
54
0
    const_reverse_iterator rbegin()  const noexcept { return const_reverse_iterator(end()); }
55
0
    const_reverse_iterator crbegin() const noexcept { return rbegin(); }
56
0
    const_reverse_iterator rend()    const noexcept { return const_reverse_iterator(begin()); }
57
0
    const_reverse_iterator crend()   const noexcept { return rend(); }
58
59
    bool contains(const QPoint &p) const;
60
    bool contains(const QRect &r) const;
61
62
    void translate(int dx, int dy);
63
0
    inline void translate(const QPoint &p) { translate(p.x(), p.y()); }
64
    [[nodiscard]] QRegion translated(int dx, int dy) const;
65
0
    [[nodiscard]] inline QRegion translated(const QPoint &p) const { return translated(p.x(), p.y()); }
66
67
    [[nodiscard]] QRegion united(const QRegion &r) const;
68
    [[nodiscard]] QRegion united(const QRect &r) const;
69
    [[nodiscard]] QRegion intersected(const QRegion &r) const;
70
    [[nodiscard]] QRegion intersected(const QRect &r) const;
71
    [[nodiscard]] QRegion subtracted(const QRegion &r) const;
72
    [[nodiscard]] QRegion xored(const QRegion &r) const;
73
74
    bool intersects(const QRegion &r) const;
75
    bool intersects(const QRect &r) const;
76
77
    QRect boundingRect() const noexcept;
78
    void setRects(const QRect *rect, int num);
79
    void setRects(QSpan<const QRect> r);
80
    QSpan<const QRect> rects() const noexcept;
81
    int rectCount() const noexcept;
82
83
    QRegion operator|(const QRegion &r) const;
84
    QRegion operator+(const QRegion &r) const;
85
    QRegion operator+(const QRect &r) const;
86
    QRegion operator&(const QRegion &r) const;
87
    QRegion operator&(const QRect &r) const;
88
    QRegion operator-(const QRegion &r) const;
89
    QRegion operator^(const QRegion &r) const;
90
91
    QRegion& operator|=(const QRegion &r);
92
    QRegion& operator+=(const QRegion &r);
93
    QRegion& operator+=(const QRect &r);
94
    QRegion& operator&=(const QRegion &r);
95
    QRegion& operator&=(const QRect &r);
96
    QRegion& operator-=(const QRegion &r);
97
    QRegion& operator^=(const QRegion &r);
98
99
    bool operator==(const QRegion &r) const;
100
0
    inline bool operator!=(const QRegion &r) const { return !(operator==(r)); }
101
    operator QVariant() const;
102
103
    // Platform specific conversion functions
104
#if defined(Q_OS_WIN) || defined(Q_QDOC)
105
    HRGN toHRGN() const;
106
    static QRegion fromHRGN(HRGN hrgn);
107
#endif
108
109
#ifndef QT_NO_DATASTREAM
110
    friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QRegion &);
111
    friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QRegion &);
112
#endif
113
private:
114
    QRegion copy() const;   // helper of detach.
115
    void detach();
116
Q_GUI_EXPORT
117
    friend bool qt_region_strictContains(const QRegion &region,
118
                                         const QRect &rect);
119
    friend struct QRegionPrivate;
120
121
#ifndef QT_NO_DATASTREAM
122
    void exec(const QByteArray &ba, int ver = 0, QDataStream::ByteOrder byteOrder = QDataStream::BigEndian);
123
#endif
124
    struct QRegionData {
125
        QtPrivate::RefCount ref = Q_REFCOUNT_INITIALIZE_OWNED;
126
        QRegionPrivate *qt_rgn;
127
    };
128
    struct QRegionData *d;
129
    static const struct QRegionData shared_empty;
130
    static void cleanUp(QRegionData *x);
131
};
132
Q_DECLARE_SHARED(QRegion)
133
134
/*****************************************************************************
135
  QRegion stream functions
136
 *****************************************************************************/
137
138
#ifndef QT_NO_DATASTREAM
139
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QRegion &);
140
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QRegion &);
141
#endif
142
143
#ifndef QT_NO_DEBUG_STREAM
144
Q_GUI_EXPORT QDebug operator<<(QDebug, const QRegion &);
145
#endif
146
147
QT_END_NAMESPACE
148
149
#endif // QREGION_H