summaryrefslogtreecommitdiffstats
path: root/src/gui/painting/qregion.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-02-27 12:40:36 +0100
committerMarc Mutz <marc.mutz@kdab.com>2016-02-28 19:06:44 +0000
commit77164e4cc05373de1147128058754d6511145afb (patch)
tree872ea60536608b0f67184d8b35d5aef455907ee1 /src/gui/painting/qregion.h
parent12705f70c9a380a5a4e8ba4027a835259aebb78f (diff)
QRegion: make iterable
Virtually all code in Qt that inspects a QRegion does so by calling rects(), which returns a QVector<QRect>. But rects() has a problem: A QRegion that contains just one rectangle internally is not represented by a QVector, and the mere act of calling rects() makes QRegion create one. So, expose the fact that QRegion is a container of QRects to users by providing iterators and begin()/end(), which can be nothrow, since for the one-rectangle case, instead of vectorize()ing the region, we just return pointers to (and one past) the 'extent' rectangle. As a consequence, the iterator type is just const QRect*, but I think that whatever containers QRegion may use under the hood in the future, it will be certainly one that is layout-compatible with a C array. No mutable iterators are provided, since QRegion maintains a running bounding-rect, so a mutable iterator would have to call into QRegion for every change, which doesn't make sense. [ChangeLog][QtGui][QRegion] Is now iterable as a container of QRects: added {c,}{r,}{begin,end}(). Change-Id: I2fa565fac0c1d26e2c0937604b23763cd4e23604 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/gui/painting/qregion.h')
-rw-r--r--src/gui/painting/qregion.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/gui/painting/qregion.h b/src/gui/painting/qregion.h
index d66f80fcde..f00b1fd284 100644
--- a/src/gui/painting/qregion.h
+++ b/src/gui/painting/qregion.h
@@ -81,6 +81,18 @@ public:
bool isEmpty() const;
bool isNull() const;
+ typedef const QRect *const_iterator;
+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+
+ const_iterator begin() const Q_DECL_NOTHROW;
+ const_iterator cbegin() const Q_DECL_NOTHROW { return begin(); }
+ const_iterator end() const Q_DECL_NOTHROW;
+ const_iterator cend() const Q_DECL_NOTHROW { return end(); }
+ const_reverse_iterator rbegin() const Q_DECL_NOTHROW { return const_reverse_iterator(end()); }
+ const_reverse_iterator crbegin() const Q_DECL_NOTHROW { return rbegin(); }
+ const_reverse_iterator rend() const Q_DECL_NOTHROW { return const_reverse_iterator(begin()); }
+ const_reverse_iterator crend() const Q_DECL_NOTHROW { return rend(); }
+
bool contains(const QPoint &p) const;
bool contains(const QRect &r) const;