-
Notifications
You must be signed in to change notification settings - Fork 1
/
phpqtng.h
125 lines (102 loc) · 3.77 KB
/
phpqtng.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#ifndef PHPQTNG_H
#define PHPQTNG_H
#include <iostream>
using namespace std;
#include <phpcpp.h>
#include <QDebug>
#define SLOT_PREFIX "1"
#define SIGNAL_PREFIX "2"
string normalizeSignalOrSlot(string signal_or_slot);
#define CONCAT(x,y) x##y
#define QNAME(x) CONCAT(Qt_,x)
#define PHPQTNG_CONSTRUCT(QtClass) void QNAME(QtClass)::__construct(Php::Parameters ¶ms)
#define PHPQTNG_GET_BEGIN(QtClass) void Php::Value QNAME(QtClass)::__get(const Php::Value &name) {
#define PHPQTNG_GET_END(QtClass) return Php::Base::__get(name); }
// #define PHPQTNG_SET(QtClass) void QNAME(QtClass)::__construct(Php::Parameters ¶ms)
// #define PHPQTNG_CALL(QtClass) void QNAME(QtClass)::__construct(Php::Parameters ¶ms)
// #define PHPQTNG_STATIC_CALL(QtClass) void QNAME(QtClass)::__construct(Php::Parameters ¶ms)
#define PARAM_QOBJECT(param) (QObject *)(((QNAME(QObject) *)param.implementation())->q)
#define PARAM_QWIDGET(param) (QWidget *)(((QNAME(QWidget) *)param.implementation())->q)
#define PARAM_QTYPE(type,param) (type *)(((QNAME(type) *)param.implementation())->q)
#define GET_CLASS(object_param) (Php::call("get_class", object_param))
#define PHPQTNG_CLASS_NODELETE(QtClass) \
class QNAME(QtClass):public PHPQtNgBase \
{ \
public: \
QtClass * q; \
QNAME(QtClass)():q(0){} \
QNAME(QtClass)(QtClass *_q):q(_q) {} \
void __construct(Php::Parameters ¶ms); \
inline Php::Value __get(const Php::Value &name) { \
return QNAME(QtClass)::get(name,q); \
} \
static Php::Value get(const Php::Value &name, QtClass *q); \
inline void __set(const Php::Value &name, const Php::Value &value) { \
return QNAME(QtClass)::set(name,value,q); \
} \
static void set(const Php::Value &name, const Php::Value &value, QtClass *q); \
inline Php::Value __call(const char *_name, Php::Parameters ¶ms) { \
string name=_name; \
return QNAME(QtClass)::call(name,params,q); \
} \
static Php::Value __callStatic(const char *name, Php::Parameters ¶ms); \
static Php::Value call(const string name, Php::Parameters ¶ms, QtClass *q);
// return QNAME(QtClass)::call(string(name),params,this); \
// } \
// static Php::Value call(const string name, Php::Parameters ¶ms, QNAME(QtClass) *obj); \
// Php::Value baseCall(const string name, Php::Parameters ¶ms) { \
// return Php::Base::__call(name.c_str(),params); \
// } \
//
#define PHPQTNG_CLASS_STUB_NODELETE(QtClass) PHPQTNG_CLASS_NODELETE(QtClass) };
#define PHPQTNG_CLASS(QtClass) PHPQTNG_CLASS_NODELETE(QtClass) \
virtual ~QNAME(QtClass)() { \
if (q) \
delete q,q=0; \
} \
void __destruct() { \
if (q) \
delete q,q=0; \
} \
#define PHPQTNG_CLASS_STUB(QtClass) PHPQTNG_CLASS(QtClass) };
// class MethodNotFound: public exception {
// public:
// /**
// * Constructor
// */
// MethodNotFound() : std::exception() {}
// /**
// * Destructor
// */
// virtual ~MethodNotFound() throw() {}
// };
Php::Value dynamicConnect(Php::Parameters ¶ms);
class PHPQtNgBase:public Php::Base
{
public:
static Php::Value call(const string name, Php::Parameters ¶ms, void *q=0)
{
// throw MethodNotFound();
throw Php::Exception("Method '"+name+"()' not found.");
// unreachable code
return nullptr;
}
};
typedef PHPQtNgBase PhpQtNgBase;
#include <QObject>
PHPQTNG_CLASS_STUB_NODELETE(QObject);
#include <QObject>
PHPQTNG_CLASS_STUB_NODELETE(QWidget);
#include <QApplication>
PHPQTNG_CLASS(QApplication)
int argc;
};
#include <QLabel>
PHPQTNG_CLASS_STUB(QLabel);
#include <QPushButton>
PHPQTNG_CLASS_STUB(QPushButton);
#include <QLayout>
PHPQTNG_CLASS_STUB(QLayout);
#include <QVBoxLayout>
PHPQTNG_CLASS_STUB(QVBoxLayout);
#endif