MythTV
master
libs
libmythupnp
services
rtti.h
Go to the documentation of this file.
1
// Program Name: rtti.h
3
// Created : July 25, 2014
4
//
5
// Copyright (c) 2014 David Blain <dblain@mythtv.org>
6
//
7
// This program is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation; either version 2 of the License, or
10
// (at your option) any later version.
11
//
12
// This program is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
16
//
17
// You should have received a copy of the GNU General Public License
18
// along with this program; if not, write to the Free Software
19
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
//
21
// You should have received a copy of the GNU General Public License
22
// along with this program. If not, see <http://www.gnu.org/licenses/>.
23
//
25
26
#ifndef RTTI_H
27
#define RTTI_H
28
29
#include "
services/rttiServices.h
"
30
#include "
datacontracts/enum.h
"
31
32
#include <QScriptEngine>
33
34
class
Rtti
:
public
RttiServices
35
{
36
Q_OBJECT
37
38
public
:
39
40
Q_INVOKABLE
explicit
Rtti
( QObject *parent =
nullptr
) :
RttiServices
( parent ) {}
41
42
public
:
43
44
DTC::Enum
*
GetEnum
(
const
QString &FQN )
override
;
// RttiServices
45
46
};
47
48
// --------------------------------------------------------------------------
49
// The following class wrapper is due to a limitation in Qt Script Engine. It
50
// requires all methods that return pointers to user classes that are derived from
51
// QObject actually return QObject* (not the user class *). If the user class pointer
52
// is returned, the script engine treats it as a QVariant and doesn't create a
53
// javascript prototype wrapper for it.
54
//
55
// This class allows us to keep the rich return types in the main API class while
56
// offering the script engine a class it can work with.
57
//
58
// Only API Classes that return custom classes needs to implement these wrappers.
59
//
60
// We should continue to look for a cleaning solution to this problem.
61
// --------------------------------------------------------------------------
62
63
class
ScriptableRtti
:
public
QObject
64
{
65
Q_OBJECT
66
67
private
:
68
69
Rtti
m_obj
;
70
71
public
:
72
73
Q_INVOKABLE
explicit
ScriptableRtti
( QObject *parent =
nullptr
) : QObject( parent ) {}
74
75
public
slots:
76
77
QObject*
GetEnum
(
const
QString &FQN )
78
{
79
return
m_obj
.
GetEnum
( FQN );
80
}
81
};
82
83
// NOLINTNEXTLINE(modernize-use-auto)
84
Q_SCRIPT_DECLARE_QMETAOBJECT
(
ScriptableRtti
, QObject*);
85
86
#endif
RttiServices
Definition:
rttiServices.h:35
Rtti::GetEnum
DTC::Enum * GetEnum(const QString &FQN) override
Definition:
rtti.cpp:36
rttiServices.h
ScriptableRtti
Definition:
rtti.h:63
ScriptableRtti::GetEnum
QObject * GetEnum(const QString &FQN)
Definition:
rtti.h:77
ScriptableRtti::m_obj
Rtti m_obj
Definition:
rtti.h:69
Rtti::Rtti
Q_INVOKABLE Rtti(QObject *parent=nullptr)
Definition:
rtti.h:40
DTC::Enum
Definition:
enum.h:24
Rtti
Definition:
rtti.h:34
ScriptableRtti::ScriptableRtti
Q_INVOKABLE ScriptableRtti(QObject *parent=nullptr)
Definition:
rtti.h:73
Q_SCRIPT_DECLARE_QMETAOBJECT
Q_SCRIPT_DECLARE_QMETAOBJECT(ScriptableRtti, QObject *)
enum.h
Generated on Mon Mar 8 2021 03:17:36 for MythTV by
1.8.17