diff options
Diffstat (limited to 'src/corelib/tools/qline.h')
-rw-r--r-- | src/corelib/tools/qline.h | 91 |
1 files changed, 44 insertions, 47 deletions
diff --git a/src/corelib/tools/qline.h b/src/corelib/tools/qline.h index 426d69cd6d..03dac30e16 100644 --- a/src/corelib/tools/qline.h +++ b/src/corelib/tools/qline.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore 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) 2022 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 #ifndef QLINE_H #define QLINE_H @@ -44,6 +8,7 @@ QT_BEGIN_NAMESPACE +class QLineF; /******************************************************************************* * class QLine @@ -83,13 +48,23 @@ public: inline void setPoints(const QPoint &p1, const QPoint &p2); inline void setLine(int x1, int y1, int x2, int y2); +#if QT_CORE_REMOVED_SINCE(6, 8) constexpr inline bool operator==(const QLine &d) const noexcept; - constexpr inline bool operator!=(const QLine &d) const noexcept { return !(*this == d); } + constexpr inline bool operator!=(const QLine &d) const noexcept { return !operator==(d); } +#endif + + [[nodiscard]] constexpr inline QLineF toLineF() const noexcept; private: + friend constexpr bool comparesEqual(const QLine &lhs, const QLine &rhs) noexcept + { return lhs.pt1 == rhs.pt1 && lhs.pt2 == rhs.pt2; } +#if !QT_CORE_REMOVED_SINCE(6, 8) + Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QLine) +#endif + QPoint pt1, pt2; }; -Q_DECLARE_TYPEINFO(QLine, Q_RELOCATABLE_TYPE); +Q_DECLARE_TYPEINFO(QLine, Q_PRIMITIVE_TYPE); /******************************************************************************* * class QLine inline members @@ -194,10 +169,12 @@ inline void QLine::setLine(int aX1, int aY1, int aX2, int aY2) pt2 = QPoint(aX2, aY2); } +#if QT_CORE_REMOVED_SINCE(6, 8) constexpr inline bool QLine::operator==(const QLine &d) const noexcept { - return pt1 == d.pt1 && pt2 == d.pt2; + return comparesEqual(*this, d); } +#endif #ifndef QT_NO_DEBUG_STREAM Q_CORE_EXPORT QDebug operator<<(QDebug d, const QLine &p); @@ -266,15 +243,33 @@ public: inline void setPoints(const QPointF &p1, const QPointF &p2); inline void setLine(qreal x1, qreal y1, qreal x2, qreal y2); +#if QT_CORE_REMOVED_SINCE(6, 8) constexpr inline bool operator==(const QLineF &d) const; - constexpr inline bool operator!=(const QLineF &d) const { return !(*this == d); } + constexpr inline bool operator!=(const QLineF &d) const { return !operator==(d); } +#endif constexpr QLine toLine() const; private: + friend constexpr bool comparesEqual(const QLineF &lhs, const QLineF &rhs) noexcept + { return lhs.pt1 == rhs.pt1 && lhs.pt2 == rhs.pt2; } +#if !QT_CORE_REMOVED_SINCE(6, 8) + Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QLineF) +#endif + + friend constexpr bool comparesEqual(const QLineF &lhs, const QLine &rhs) noexcept + { return comparesEqual(lhs, rhs.toLineF()); } + Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QLineF, QLine) + + friend constexpr bool qFuzzyCompare(const QLineF &lhs, const QLineF &rhs) noexcept + { return qFuzzyCompare(lhs.pt1, rhs.pt1) && qFuzzyCompare(lhs.pt2, rhs.pt2); } + + friend constexpr bool qFuzzyIsNull(const QLineF &line) noexcept + { return qFuzzyCompare(line.pt1, line.pt2); } + QPointF pt1, pt2; }; -Q_DECLARE_TYPEINFO(QLineF, Q_RELOCATABLE_TYPE); +Q_DECLARE_TYPEINFO(QLineF, Q_PRIMITIVE_TYPE); /******************************************************************************* * class QLineF inline members @@ -316,7 +311,7 @@ constexpr inline qreal QLineF::y2() const constexpr inline bool QLineF::isNull() const { - return qFuzzyCompare(pt1.x(), pt2.x()) && qFuzzyCompare(pt1.y(), pt2.y()); + return qFuzzyCompare(pt1, pt2); } constexpr inline QPointF QLineF::p1() const @@ -386,6 +381,8 @@ constexpr inline QPointF QLineF::pointAt(qreal t) const return QPointF(pt1.x() + (pt2.x() - pt1.x()) * t, pt1.y() + (pt2.y() - pt1.y()) * t); } +constexpr inline QLineF QLine::toLineF() const noexcept { return *this; } + constexpr inline QLine QLineF::toLine() const { return QLine(pt1.toPoint(), pt2.toPoint()); @@ -414,12 +411,12 @@ inline void QLineF::setLine(qreal aX1, qreal aY1, qreal aX2, qreal aY2) pt2 = QPointF(aX2, aY2); } - +#if QT_CORE_REMOVED_SINCE(6, 8) constexpr inline bool QLineF::operator==(const QLineF &d) const { - return pt1 == d.pt1 && pt2 == d.pt2; + return comparesEqual(*this, d); } - +#endif #ifndef QT_NO_DEBUG_STREAM |