diff options
Diffstat (limited to 'src/gui/painting/qregion.cpp')
-rw-r--r-- | src/gui/painting/qregion.cpp | 120 |
1 files changed, 67 insertions, 53 deletions
diff --git a/src/gui/painting/qregion.cpp b/src/gui/painting/qregion.cpp index 6ca87cb416..f9089d7bba 100644 --- a/src/gui/painting/qregion.cpp +++ b/src/gui/painting/qregion.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qregion.h" #include "qpainterpath.h" @@ -48,6 +12,7 @@ #include "qbitmap.h" #include "qtransform.h" +#include <memory> #include <private/qdebug_p.h> #ifdef Q_OS_WIN @@ -86,7 +51,7 @@ QT_BEGIN_NAMESPACE contains() a QPoint or QRect. The bounding rectangle can be found with boundingRect(). - Iteration over the region (with begin(), end(), or C++11 + Iteration over the region (with begin(), end(), or ranged-for loops) gives a decomposition of the region into rectangles. @@ -671,7 +636,7 @@ bool QRegion::intersects(const QRegion ®ion) const */ -#if !defined (Q_OS_UNIX) && !defined (Q_OS_WIN) || defined(Q_CLANG_QDOC) +#if !defined (Q_OS_UNIX) && !defined (Q_OS_WIN) || defined(Q_QDOC) /* \overload \since 4.4 @@ -911,9 +876,15 @@ QRegion QRegion::intersect(const QRect &r) const /*! \fn void QRegion::setRects(const QRect *rects, int number) + \overload + \obsolete Use the QSpan overload instead. +*/ + +/*! + \fn void QRegion::setRects(QSpan<const QRect> rects) + \since 6.8 - Sets the region using the array of rectangles specified by \a rects and - \a number. + Sets the region using the array of rectangles specified by \a rects. The rectangles \e must be optimally Y-X sorted and follow these restrictions: \list @@ -927,6 +898,11 @@ QRegion QRegion::intersect(const QRect &r) const \omit Only some platforms have these restrictions (Qt for Embedded Linux, X11 and \macos). \endomit + + \note For historical reasons, \c{rects.size()} must be less than \c{INT_MAX} + (see rectCount()). + + \sa rects() */ namespace { @@ -3226,8 +3202,7 @@ static void CreateETandAET(int count, const QPoint *pts, int iSLLBlock = 0; int dy; - if (count < 2) - return; + Q_ASSERT(count > 1); /* * initialize the Active Edge Table @@ -3573,7 +3548,7 @@ static QRegionPrivate *PolygonRegion(const QPoint *Pts, int Count, int rule) POINTBLOCK *tmpPtBlock; int numFullPtBlocks = 0; - Q_ASSUME(Count > 1); + Q_ASSERT(Count > 1); region = new QRegionPrivate; @@ -3853,7 +3828,7 @@ QRegion::QRegion(const QRect &r, RegionType t) QRegion::QRegion(const QPolygon &a, Qt::FillRule fillRule) { - if (a.count() > 2) { + if (a.size() > 2) { QRegionPrivate *qt_rgn = PolygonRegion(a.constData(), a.size(), fillRule == Qt::WindingFill ? WindingRule : EvenOddRule); if (qt_rgn) { @@ -3915,7 +3890,7 @@ QRegion &QRegion::operator=(const QRegion &r) QRegion QRegion::copy() const { QRegion r; - QScopedPointer<QRegionData> x(new QRegionData); + auto x = std::make_unique<QRegionData>(); x->ref.initializeOwned(); if (d->qt_rgn) x->qt_rgn = new QRegionPrivate(*d->qt_rgn); @@ -3923,7 +3898,7 @@ QRegion QRegion::copy() const x->qt_rgn = new QRegionPrivate; if (!r.d->ref.deref()) cleanUp(r.d); - r.d = x.take(); + r.d = x.release(); return r; } @@ -4250,18 +4225,39 @@ QRegion::const_iterator QRegion::end() const noexcept return d->qt_rgn ? d->qt_rgn->end() : nullptr; } -void QRegion::setRects(const QRect *rects, int num) +static Q_DECL_COLD_FUNCTION +void set_rects_warn(const char *what) +{ + qWarning("QRegion::setRects(): %s", what); +} + +void QRegion::setRects(const QRect *r, int n) +{ + if (!r && n) { // old setRects() allowed this, but QSpan doesn't + set_rects_warn("passing num != 0 when rects == nullptr is deprecated."); + n = 0; + } + setRects(QSpan<const QRect>(r, n)); +} + +void QRegion::setRects(QSpan<const QRect> rects) { + const auto num = int(rects.size()); + if (num != rects.size()) { + set_rects_warn("span size exceeds INT_MAX, ignoring"); + return; + } + *this = QRegion(); - if (!rects || num == 0 || (num == 1 && rects->isEmpty())) + if (!rects.data() || num == 0 || (num == 1 && rects.front().isEmpty())) return; detach(); d->qt_rgn->numRects = num; if (num == 1) { - d->qt_rgn->extents = *rects; - d->qt_rgn->innerRect = *rects; + d->qt_rgn->extents = rects.front(); + d->qt_rgn->innerRect = rects.front(); } else { d->qt_rgn->rects.resize(num); @@ -4282,12 +4278,30 @@ void QRegion::setRects(const QRect *rects, int num) } } +/*! + \since 6.8 + + Returns a span of non-overlapping rectangles that make up the region. The + span remains valid until the next call of a mutating (non-const) method on + this region. + + The union of all the rectangles is equal to the original region. + + \note This functions existed in Qt 5, too, but returned QVector<QRect> + instead. + + \sa setRects() +*/ +QSpan<const QRect> QRegion::rects() const noexcept +{ + return {begin(), end()}; +}; + int QRegion::rectCount() const noexcept { return (d->qt_rgn ? d->qt_rgn->numRects : 0); } - bool QRegion::operator==(const QRegion &r) const { if (!d->qt_rgn) |