File indexing completed on 2023-12-10 04:54:44
0001 /** 0002 * SPDX-FileCopyrightText: 2013 Albert Vaca <albertvaka@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #ifndef QOBJECT_FACTORY_H 0008 #define QOBJECT_FACTORY_H 0009 0010 #include <QObject> 0011 #include <QVariant> 0012 0013 // Wraps a factory function with QObject class to be exposed to qml context as named factory 0014 0015 class ObjectFactory : public QObject 0016 { 0017 Q_OBJECT 0018 0019 typedef QObject *(*Func0)(); 0020 typedef QObject *(*Func1)(const QVariant &); 0021 typedef QObject *(*Func2)(const QVariant &, const QVariant &); 0022 0023 public: 0024 ObjectFactory(QObject *parent, Func0 f0) 0025 : QObject(parent) 0026 , m_f0(f0) 0027 , m_f1(nullptr) 0028 , m_f2(nullptr) 0029 { 0030 } 0031 ObjectFactory(QObject *parent, Func1 f1) 0032 : QObject(parent) 0033 , m_f0(nullptr) 0034 , m_f1(f1) 0035 , m_f2(nullptr) 0036 { 0037 } 0038 ObjectFactory(QObject *parent, Func2 f2) 0039 : QObject(parent) 0040 , m_f0(nullptr) 0041 , m_f1(nullptr) 0042 , m_f2(f2) 0043 { 0044 } 0045 0046 Q_INVOKABLE QObject *create(); 0047 Q_INVOKABLE QObject *create(const QVariant &arg1); 0048 0049 Q_INVOKABLE QObject *create(const QVariant &arg1, const QVariant &arg2); 0050 0051 private: 0052 Func0 m_f0; 0053 Func1 m_f1; 0054 Func2 m_f2; 0055 }; 0056 0057 #endif