MythTV  master
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 "libmythbase/mythconfig.h"
32 
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 #if CONFIG_QTSCRIPT
49 #include <QScriptEngine>
50 
51 // --------------------------------------------------------------------------
52 // The following class wrapper is due to a limitation in Qt Script Engine. It
53 // requires all methods that return pointers to user classes that are derived from
54 // QObject actually return QObject* (not the user class *). If the user class pointer
55 // is returned, the script engine treats it as a QVariant and doesn't create a
56 // javascript prototype wrapper for it.
57 //
58 // This class allows us to keep the rich return types in the main API class while
59 // offering the script engine a class it can work with.
60 //
61 // Only API Classes that return custom classes needs to implement these wrappers.
62 //
63 // We should continue to look for a cleaning solution to this problem.
64 // --------------------------------------------------------------------------
65 
66 class ScriptableRtti : public QObject
67 {
68  Q_OBJECT
69 
70  private:
71 
72  Rtti m_obj;
73 
74  public:
75 
76  Q_INVOKABLE explicit ScriptableRtti( QObject *parent = nullptr ) : QObject( parent ) {}
77 
78  public slots:
79 
80  QObject* GetEnum ( const QString &FQN )
81  {
82  return m_obj.GetEnum( FQN );
83  }
84 };
85 
86 // NOLINTNEXTLINE(modernize-use-auto)
87 Q_SCRIPT_DECLARE_QMETAOBJECT( ScriptableRtti, QObject*);
88 #endif
89 
90 #endif
RttiServices
Definition: rttiServices.h:35
Rtti::GetEnum
DTC::Enum * GetEnum(const QString &FQN) override
Definition: rtti.cpp:36
rttiServices.h
Rtti::Rtti
Q_INVOKABLE Rtti(QObject *parent=nullptr)
Definition: rtti.h:40
DTC::Enum
Definition: enum.h:23
Rtti
Definition: rtti.h:34
enum.h