File indexing completed on 2024-04-28 15:35:52

0001 // SPDX-FileCopyrightText: 2012 Dan Leinir Turthra Jensen <admin@leinir.dk>
0002 // SPDX-License-Identifier: LGPL-2.1-only or LGPL-3.0-only or LicenseRef-KDE-Accepted-LGPL
0003 
0004 #pragma once
0005 
0006 #include <QObject>
0007 #include <QVariant>
0008 
0009 /**
0010  * The only purpose of this class is to expose the dynamic property
0011  * system of Qt to QML, so we can set and get properties on a generic
0012  * object. It is a little bit of a hack, but QML deliberately does
0013  * not have access to this (according to the developers).
0014  */
0015 class PropertyContainer : public QObject
0016 {
0017     Q_OBJECT
0018 public:
0019     explicit PropertyContainer(QObject *parent = nullptr);
0020     explicit PropertyContainer(const QString &name, QObject *parent = nullptr);
0021     ~PropertyContainer() override;
0022 
0023     // As QObject already as setProperty and property() functions, we must
0024     // name ours differently
0025     Q_INVOKABLE void writeProperty(const QString &name, const QVariant &value);
0026     Q_INVOKABLE QVariant readProperty(const QString &name);
0027 
0028     Q_INVOKABLE QString name() const;
0029 
0030 private:
0031     QString m_name;
0032 };