summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qmargins.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools/qmargins.h')
-rw-r--r--src/corelib/tools/qmargins.h71
1 files changed, 23 insertions, 48 deletions
diff --git a/src/corelib/tools/qmargins.h b/src/corelib/tools/qmargins.h
index cf40b89ee0..f8d7150dfd 100644
--- a/src/corelib/tools/qmargins.h
+++ b/src/corelib/tools/qmargins.h
@@ -1,49 +1,20 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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 QMARGINS_H
#define QMARGINS_H
#include <QtCore/qnamespace.h>
+#include <QtCore/q20type_traits.h>
+#include <QtCore/q23utility.h>
+
QT_BEGIN_NAMESPACE
+QT_ENABLE_P0846_SEMANTICS_FOR(get)
+
+class QMarginsF;
+
/*****************************************************************************
QMargins class
*****************************************************************************/
@@ -75,6 +46,8 @@ public:
constexpr QMargins &operator*=(qreal) noexcept;
constexpr QMargins &operator/=(qreal);
+ [[nodiscard]] constexpr inline QMarginsF toMarginsF() const noexcept;
+
private:
int m_left;
int m_top;
@@ -98,17 +71,17 @@ private:
template <std::size_t I,
typename M,
std::enable_if_t<(I < 4), bool> = true,
- std::enable_if_t<std::is_same_v<std::decay_t<M>, QMargins>, bool> = true>
+ std::enable_if_t<std::is_same_v<q20::remove_cvref_t<M>, QMargins>, bool> = true>
friend constexpr decltype(auto) get(M &&m) noexcept
{
if constexpr (I == 0)
- return (std::forward<M>(m).m_left);
+ return q23::forward_like<M>(m.m_left);
else if constexpr (I == 1)
- return (std::forward<M>(m).m_top);
+ return q23::forward_like<M>(m.m_top);
else if constexpr (I == 2)
- return (std::forward<M>(m).m_right);
+ return q23::forward_like<M>(m.m_right);
else if constexpr (I == 3)
- return (std::forward<M>(m).m_bottom);
+ return q23::forward_like<M>(m.m_bottom);
}
};
@@ -347,17 +320,17 @@ private:
template <std::size_t I,
typename M,
std::enable_if_t<(I < 4), bool> = true,
- std::enable_if_t<std::is_same_v<std::decay_t<M>, QMarginsF>, bool> = true>
+ std::enable_if_t<std::is_same_v<q20::remove_cvref_t<M>, QMarginsF>, bool> = true>
friend constexpr decltype(auto) get(M &&m) noexcept
{
if constexpr (I == 0)
- return (std::forward<M>(m).m_left);
+ return q23::forward_like<M>(m.m_left);
else if constexpr (I == 1)
- return (std::forward<M>(m).m_top);
+ return q23::forward_like<M>(m.m_top);
else if constexpr (I == 2)
- return (std::forward<M>(m).m_right);
+ return q23::forward_like<M>(m.m_right);
else if constexpr (I == 3)
- return (std::forward<M>(m).m_bottom);
+ return q23::forward_like<M>(m.m_bottom);
}
};
@@ -516,6 +489,8 @@ constexpr inline QMarginsF operator-(const QMarginsF &margins) noexcept
return QMarginsF(-margins.left(), -margins.top(), -margins.right(), -margins.bottom());
}
+constexpr QMarginsF QMargins::toMarginsF() const noexcept { return *this; }
+
constexpr inline QMargins QMarginsF::toMargins() const noexcept
{
return QMargins(qRound(m_left), qRound(m_top), qRound(m_right), qRound(m_bottom));