aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlvaluetypeproviders/testtypes.h
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qml/qqmlvaluetypeproviders/testtypes.h')
-rw-r--r--tests/auto/qml/qqmlvaluetypeproviders/testtypes.h426
1 files changed, 395 insertions, 31 deletions
diff --git a/tests/auto/qml/qqmlvaluetypeproviders/testtypes.h b/tests/auto/qml/qqmlvaluetypeproviders/testtypes.h
index 5241381336..8130ea2912 100644
--- a/tests/auto/qml/qqmlvaluetypeproviders/testtypes.h
+++ b/tests/auto/qml/qqmlvaluetypeproviders/testtypes.h
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** 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 General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** 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-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef TESTTYPES_H
#define TESTTYPES_H
@@ -42,8 +17,131 @@
#include <QMatrix4x4>
#include <QFont>
#include <QColor>
+#include <QDateTime>
+#include <QDate>
+#include <QTime>
#include <qqml.h>
+struct ConstructibleValueType
+{
+ Q_GADGET
+ Q_PROPERTY(int foo MEMBER m_foo CONSTANT)
+
+ QML_VALUE_TYPE(constructible)
+ QML_CONSTRUCTIBLE_VALUE
+
+public:
+ ConstructibleValueType() = default;
+ Q_INVOKABLE ConstructibleValueType(int foo) : m_foo(foo) {}
+ Q_INVOKABLE ConstructibleValueType(QObject *) : m_foo(67) {}
+ Q_INVOKABLE ConstructibleValueType(const QUrl &) : m_foo(68) {}
+
+ int foo() const { return m_foo; }
+
+private:
+ friend bool operator==(const ConstructibleValueType &a, const ConstructibleValueType &b)
+ {
+ return a.m_foo == b.m_foo;
+ }
+
+ int m_foo = 0;
+};
+
+struct ConstructibleFromQReal
+{
+ Q_GADGET
+ Q_PROPERTY(qreal foo MEMBER m_foo CONSTANT)
+
+ QML_VALUE_TYPE(constructibleFromQReal)
+ QML_CONSTRUCTIBLE_VALUE
+
+public:
+ ConstructibleFromQReal() = default;
+ Q_INVOKABLE ConstructibleFromQReal(qreal foo) : m_foo(foo) {}
+
+ qreal foo() const { return m_foo; }
+
+private:
+ friend bool operator==(const ConstructibleFromQReal &a, const ConstructibleFromQReal &b)
+ {
+ if (qIsNaN(a.m_foo) && qIsNaN(b.m_foo))
+ return true;
+ if (qIsInf(a.m_foo) && qIsInf(b.m_foo))
+ return (a.m_foo > 0) == (b.m_foo > 0);
+ return qFuzzyCompare(a.m_foo, b.m_foo);
+ }
+
+ qreal m_foo = 0;
+};
+
+struct StructuredValueType
+{
+ Q_GADGET
+ Q_PROPERTY(int i READ i WRITE setI)
+ Q_PROPERTY(ConstructibleValueType c READ c WRITE setC)
+ Q_PROPERTY(QPointF p READ p WRITE setP)
+ Q_PROPERTY(QList<QSizeF> sizes READ sizes WRITE setSizes)
+
+ QML_VALUE_TYPE(structured)
+ QML_STRUCTURED_VALUE
+
+public:
+ int i() const { return m_i; }
+ void setI(int newI) { m_i = newI; }
+
+ const ConstructibleValueType &c() const { return m_c; }
+ void setC(const ConstructibleValueType &newC) { m_c = newC; }
+
+ QPointF p() const { return m_p; }
+ void setP(QPointF newP) { m_p = newP; }
+
+ const QList<QSizeF> &sizes() const { return m_sizes; }
+ void setSizes(const QList<QSizeF> &sizes) { m_sizes = sizes; }
+
+ Q_INVOKABLE QList<QSizeF> sizesDetached() const { return m_sizes; }
+
+private:
+
+ friend bool operator==(const StructuredValueType &a, const StructuredValueType &b)
+ {
+ return a.m_i == b.m_i && a.m_c == b.m_c && a.m_p == b.m_p && a.m_sizes == b.m_sizes;
+ }
+
+ int m_i = 0;
+ ConstructibleValueType m_c;
+ QPointF m_p;
+ QList<QSizeF> m_sizes = { QSizeF(1, 1), QSizeF(2, 2) };
+};
+
+struct BarrenValueType
+{
+ Q_GADGET
+ Q_PROPERTY(int i READ i WRITE setI)
+
+public:
+ BarrenValueType() = default;
+ Q_INVOKABLE BarrenValueType(const QString &) : m_i(25) {}
+
+ int i() const { return m_i; }
+ void setI(int newI) { m_i = newI; }
+
+private:
+ friend bool operator==(const BarrenValueType &a, const BarrenValueType &b)
+ {
+ return a.m_i == b.m_i;
+ }
+
+ int m_i = 0;
+};
+
+struct ForeignAnonymousStructuredValueType
+{
+ Q_GADGET
+ QML_ANONYMOUS
+ QML_FOREIGN(BarrenValueType)
+ QML_STRUCTURED_VALUE
+};
+
class MyTypeObject : public QObject
{
Q_OBJECT
@@ -66,6 +164,14 @@ class MyTypeObject : public QObject
Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY changed)
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY changed)
Q_PROPERTY(QVariant variant READ variant NOTIFY changed)
+ Q_PROPERTY(ConstructibleValueType constructible READ constructible WRITE setConstructible NOTIFY constructibleChanged)
+ Q_PROPERTY(StructuredValueType structured READ structured WRITE setStructured NOTIFY structuredChanged)
+ Q_PROPERTY(BarrenValueType barren READ barren WRITE setBarren NOTIFY barrenChanged)
+
+ Q_PROPERTY(QDateTime aDateTime READ aDateTime WRITE setADateTime NOTIFY aDateTimeChanged)
+ Q_PROPERTY(QDate aDate READ aDate WRITE setADate NOTIFY aDateChanged)
+ Q_PROPERTY(QTime aTime READ aTime WRITE setATime NOTIFY aTimeChanged)
+ Q_PROPERTY(QVariant aVariant READ aVariant WRITE setAVariant NOTIFY aVariantChanged)
public:
MyTypeObject() :
@@ -95,10 +201,10 @@ public:
m_font.setCapitalization(QFont::AllLowercase);
m_font.setLetterSpacing(QFont::AbsoluteSpacing, 10.2);
m_font.setWordSpacing(19.7);
- m_color.setRedF(0.2);
- m_color.setGreenF(0.88);
- m_color.setBlueF(0.6);
- m_color.setAlphaF(0.34);
+ m_color.setRedF(0.2f);
+ m_color.setGreenF(0.88f);
+ m_color.setBlueF(0.6f);
+ m_color.setAlphaF(0.34f);
}
QPoint m_point;
@@ -169,12 +275,270 @@ public:
void emitRunScript() { emit runScript(); }
+ const ConstructibleValueType &constructible() const { return m_constructible; }
+ void setConstructible(const ConstructibleValueType &newConstructible)
+ {
+ if (m_constructible == newConstructible)
+ return;
+ m_constructible = newConstructible;
+ emit constructibleChanged();
+ }
+
+ const StructuredValueType &structured() const { return m_structured; }
+ void setStructured(const StructuredValueType &newStructured)
+ {
+ if (m_structured == newStructured)
+ return;
+ m_structured = newStructured;
+ emit structuredChanged();
+ }
+
+ QDateTime aDateTime() const
+ {
+ return m_aDateTime;
+ }
+ void setADateTime(const QDateTime &newADateTime)
+ {
+ if (m_aDateTime == newADateTime)
+ return;
+ m_aDateTime = newADateTime;
+ emit aDateTimeChanged();
+ }
+
+ QDate aDate() const
+ {
+ return m_aDate;
+ }
+ void setADate(QDate newADate)
+ {
+ if (m_aDate == newADate)
+ return;
+ m_aDate = newADate;
+ emit aDateChanged();
+ }
+
+ QTime aTime() const
+ {
+ return m_aTime;
+ }
+ void setATime(QTime newATime)
+ {
+ if (m_aTime == newATime)
+ return;
+ m_aTime = newATime;
+ emit aTimeChanged();
+ }
+
+ QVariant aVariant() const
+ {
+ return m_aVariant;
+ }
+ void setAVariant(const QVariant &newAVariant)
+ {
+ if (m_aVariant == newAVariant)
+ return;
+ m_aVariant = newAVariant;
+ emit aVariantChanged();
+ }
+
+ BarrenValueType barren() const
+ {
+ return m_barren;
+ }
+
+ void setBarren(const BarrenValueType &newBarren)
+ {
+ if (m_barren == newBarren)
+ return;
+ m_barren = newBarren;
+ emit barrenChanged();
+ }
+
+ Q_INVOKABLE void acceptConstructible(const ConstructibleValueType &a)
+ {
+ setAVariant(QVariant::fromValue(a));
+ }
+
+ Q_INVOKABLE int acceptConstructibles(const QList<ConstructibleValueType> &constructibles)
+ {
+ int result = 0;
+ for (const auto &c: constructibles) {
+ result += c.foo();
+ }
+ return result;
+ }
+
+ Q_INVOKABLE StructuredValueType acceptStructured(const StructuredValueType &a)
+ {
+ return a;
+ }
+
+ Q_INVOKABLE void setEffectPadding(const QRect &r)
+ {
+ m_hasEffectPadding = true;
+ m_effectPadding = r;
+ }
+
+ bool hasEffectPadding() const { return m_hasEffectPadding; }
+ QRectF effectPadding() const { return m_effectPadding; }
+
signals:
void changed();
void runScript();
+ void constructibleChanged();
+ void structuredChanged();
+
+ void aDateTimeChanged();
+ void aDateChanged();
+ void aTimeChanged();
+ void aVariantChanged();
+
+ void barrenChanged();
+
public slots:
QSize method() { return QSize(13, 14); }
+private:
+ ConstructibleValueType m_constructible;
+ StructuredValueType m_structured;
+
+ QDateTime m_aDateTime;
+ QDate m_aDate;
+ QTime m_aTime;
+ QVariant m_aVariant;
+ BarrenValueType m_barren;
+ QRectF m_effectPadding;
+ bool m_hasEffectPadding = false;
+};
+
+class Padding
+{
+ Q_GADGET
+
+ Q_PROPERTY(int left READ left WRITE setLeft)
+ Q_PROPERTY(int right READ right WRITE setRight)
+
+ QML_VALUE_TYPE(padding)
+ QML_STRUCTURED_VALUE
+
+public:
+ enum LogType {
+ DefaultCtor,
+ CopyCtor,
+ MoveCtor,
+ CopyAssign,
+ MoveAssign,
+ InvokableCtor,
+ CustomCtor,
+ Invalid,
+ };
+
+ Q_ENUM(LogType);
+
+ struct LogEntry {
+ LogType type = Invalid;
+ int left = 0;
+ int right = 0;
+
+ friend QDebug operator<<(QDebug &debug, const LogEntry &self)
+ {
+ return debug << self.type << " " << self.left << " " << self.right;
+ }
+ };
+
+ static QList<LogEntry> log;
+
+ void doLog(LogType type) {
+ log.append({
+ type, m_left, m_right
+ });
+ }
+
+ Padding()
+ {
+ doLog(DefaultCtor);
+ }
+
+ Padding(const Padding &other)
+ : m_left(other.m_left)
+ , m_right(other.m_right)
+ {
+ doLog(CopyCtor);
+ }
+
+ Padding(Padding &&other)
+ : m_left(other.m_left)
+ , m_right(other.m_right)
+ {
+ doLog(MoveCtor);
+ }
+
+ Padding(int left, int right)
+ : m_left( left )
+ , m_right( right )
+ {
+ doLog(CustomCtor);
+ }
+
+ Padding &operator=(const Padding &other) {
+ if (this != &other) {
+ m_left = other.m_left;
+ m_right = other.m_right;
+ }
+ doLog(CopyAssign);
+ return *this;
+ }
+
+ Padding &operator=(Padding &&other) {
+ if (this != &other) {
+ m_left = other.m_left;
+ m_right = other.m_right;
+ }
+ doLog(MoveAssign);
+ return *this;
+ }
+
+ Q_INVOKABLE Padding(int padding )
+ : m_left( padding )
+ , m_right( padding )
+ {
+ doLog(InvokableCtor);
+ }
+
+ void setLeft(int padding) { m_left = padding; }
+ int left() const { return m_left; }
+
+ void setRight(int padding) { m_right = padding; }
+ int right() const { return m_right; }
+
+private:
+ int m_left = 0;
+ int m_right = 0;
+};
+
+class MyItem : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(Padding padding READ padding WRITE setPadding NOTIFY paddingChanged)
+ QML_ELEMENT
+
+public:
+ void setPadding(const Padding &padding)
+ {
+ if (padding.left() == m_padding.left() && padding.right() == m_padding.right())
+ return;
+
+ m_padding = padding;
+ emit paddingChanged();
+ }
+
+ const Padding &padding() const{ return m_padding; }
+
+signals:
+ void paddingChanged();
+
+private:
+ Padding m_padding{ 17, 17 };
};
void registerTypes();