QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskMetaInvokable.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_META_INVOKABLE_H
7#define QSK_META_INVOKABLE_H
8
9#include "QskGlobal.h"
10
11#include <qmetatype.h>
12#include <qnamespace.h>
13
14class QskMetaFunction;
15struct QMetaObject;
16class QMetaMethod;
17class QMetaProperty;
18class QObject;
19class QByteArray;
20
21class QSK_EXPORT QskMetaInvokable
22{
23 public:
24 enum Type
25 {
26 Invalid = 0,
27
28 // A QMetaMethod
29 MetaMethod,
30
31 // The WRITE accessor of a QMetaProperty
32 MetaProperty,
33
34 // A function pointer, for what Qt calls "functor based" callbacks
35 MetaFunction
36 };
37
39
41
42 QskMetaInvokable( const QMetaMethod& );
43 QskMetaInvokable( const QObject*, const char* methodName );
44 QskMetaInvokable( const QMetaObject*, const char* methodName );
45
46 QskMetaInvokable( const QMetaProperty& );
47
49
51
52 QskMetaInvokable& operator=( const QskMetaInvokable& );
53
54 bool operator==( const QskMetaInvokable& ) const;
55 bool operator!=( const QskMetaInvokable& ) const;
56
57 explicit operator bool() const;
58
59 Type type() const;
60 bool isNull() const;
61
62 int parameterCount() const;
63 int parameterType( int index ) const;
64
65 int returnType() const;
66
67 void invoke( QObject*, void* args[],
68 Qt::ConnectionType = Qt::AutoConnection );
69
70 void reset();
71
72 QByteArray name() const;
73
74 QMetaMethod method() const;
75 QMetaProperty property() const;
76 QskMetaFunction function() const;
77
78 private:
79 struct FunctionData
80 {
81 void* functionCall;
82 };
83
84 struct MetaData
85 {
86 const QMetaObject* metaObject;
87 int index; // method or property index
88 };
89
90 union
91 {
92 FunctionData m_functionData;
93 MetaData m_metaData;
94 };
95
96 int m_type : 3;
97};
98
99inline QskMetaInvokable::QskMetaInvokable()
100 : m_type( Invalid )
101{
102}
103
104inline bool QskMetaInvokable::operator!=( const QskMetaInvokable& other ) const
105{
106 return !( *this == other );
107}
108
109inline QskMetaInvokable::operator bool() const
110{
111 return !isNull();
112}
113
114inline QskMetaInvokable::Type QskMetaInvokable::type() const
115{
116 return static_cast< Type >( m_type );
117}
118
119QSK_EXPORT QMetaMethod qskMetaMethod( const QMetaObject*, const char* methodName );
120QSK_EXPORT QMetaMethod qskMetaMethod( const QObject*, const char* methodName );
121
122QSK_EXPORT void qskInvokeMetaMethod(
123 QObject*, const QMetaObject*, int methodIndex, void* args[],
124 Qt::ConnectionType = Qt::AutoConnection );
125
126QSK_EXPORT void qskInvokeMetaMethod(
127 QObject*, const QMetaMethod&, void* args[],
128 Qt::ConnectionType = Qt::AutoConnection );
129
130QSK_EXPORT void qskInvokeMetaPropertyWrite(
131 QObject*, const QMetaObject*, int propertyIndex,
132 void* args[], Qt::ConnectionType = Qt::AutoConnection );
133
134QSK_EXPORT void qskInvokeMetaPropertyWrite(
135 QObject*, const QMetaProperty&, void* args[],
136 Qt::ConnectionType = Qt::AutoConnection );
137
138QSK_EXPORT QMetaMethod qskNotifySignal( const QMetaObject*, const char* propertyName );
139QSK_EXPORT QMetaMethod qskNotifySignal( const QObject*, const char* propertyName );
140
141Q_DECLARE_METATYPE( QskMetaInvokable )
142
143#endif