diff options
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/data/variantreturn.h')
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/variantreturn.h | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/data/variantreturn.h b/tests/auto/qml/qmlcppcodegen/data/variantreturn.h new file mode 100644 index 0000000000..87718aaef3 --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/variantreturn.h @@ -0,0 +1,63 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef VARIANTERETURN_H +#define VARIANTERETURN_H + +#include <QtCore/qobject.h> +#include <QtCore/qproperty.h> +#include <QtQml/qqmlregistration.h> + +#include "weathermoduleurl.h" + +class DirectBindable : public QObject +{ + Q_OBJECT + QML_ELEMENT + Q_PROPERTY(WeatherModelUrl x READ x WRITE setX NOTIFY xChanged BINDABLE bindableX) + +public: + explicit DirectBindable(QObject *parent = nullptr) : QObject(parent) {} + + WeatherModelUrl x() const { return m_x.value(); } + void setX(const WeatherModelUrl& newX) { m_x.setValue(newX);} + QBindable<WeatherModelUrl> bindableX() { return QBindable<WeatherModelUrl>(&m_x); } + +Q_SIGNALS: + void xChanged(); + +private: + Q_OBJECT_BINDABLE_PROPERTY(DirectBindable, WeatherModelUrl, m_x, &DirectBindable::xChanged) +}; + +class IndirectBindable : public QObject +{ + Q_OBJECT + QML_ELEMENT + Q_PROPERTY(WeatherModelUrl y READ y WRITE setY NOTIFY yChanged BINDABLE bindableY) + Q_PROPERTY(int z READ z NOTIFY zChanged) + +public: + explicit IndirectBindable(QObject *parent = nullptr) : QObject(parent) { + m_z.setBinding([this]()->int { + return m_y.value().timeIndex() * 2; + }); + } + + WeatherModelUrl y() const { return m_y.value(); } + void setY(const WeatherModelUrl& newY) { m_y.setValue(newY); } + QBindable<WeatherModelUrl> bindableY() { return QBindable<WeatherModelUrl>(&m_y); } + + int z() const { return m_z.value(); } + QBindable<int> bindableZ() const { return QBindable<int>(&m_z); } + +Q_SIGNALS: + void yChanged(); + void zChanged(); + +private: + Q_OBJECT_BINDABLE_PROPERTY(IndirectBindable, WeatherModelUrl, m_y, &IndirectBindable::yChanged) + Q_OBJECT_BINDABLE_PROPERTY(IndirectBindable, int, m_z, &IndirectBindable::zChanged) +}; + +#endif // VARIANTRETURN_H |