forked from supercollider/supercollider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metatype.cpp
166 lines (149 loc) · 4.81 KB
/
metatype.cpp
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/************************************************************************
*
* Copyright 2010 - 2012 Jakob Leben ([email protected])
*
* This file is part of SuperCollider Qt GUI.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
************************************************************************/
#include "metatype.hpp"
#include "type_codec.hpp"
#include "Common.h" // Make sure PyrObject* is declared to QMetaType
#include <PyrKernel.h>
namespace QtCollider {
static QVector<MetaType*> gMetaTypes;
template<typename T> MetaTypeImpl<T> * MetaTypeImpl<T>::instance = 0;
template <typename T> void qc_init_metatype()
{
MetaTypeImpl<T>::instance = new MetaTypeImpl<T>();
gMetaTypes.append( MetaTypeImpl<T>::instance );
}
void MetaType::initAll()
{
qRegisterMetaType<PyrObject*>();
qRegisterMetaType<QObjectProxy*>();
qRegisterMetaType<QcTreeWidget::ItemPtr>();
qRegisterMetaType< QVector<double> >();
qRegisterMetaType< QVector<int> >();
qRegisterMetaType<SharedImage>();
gMetaTypes.reserve(20);
qc_init_metatype<bool>();
qc_init_metatype<int>();
qc_init_metatype<float>();
qc_init_metatype<double>();
qc_init_metatype<QChar>();
qc_init_metatype<QString>();
qc_init_metatype<QPointF>();
qc_init_metatype<QPoint>();
qc_init_metatype<QSizeF>();
qc_init_metatype<QSize>();
qc_init_metatype<QRectF>();
qc_init_metatype<QRect>();
qc_init_metatype<QColor>();
qc_init_metatype<QFont>();
qc_init_metatype<QPalette>();
qc_init_metatype<QObjectProxy*>();
qc_init_metatype<QObject*>();
qc_init_metatype<QWidget*>();
qc_init_metatype<PyrObject*>();
qc_init_metatype<QcTreeWidget::ItemPtr>();
qc_init_metatype<SharedImage>();
qc_init_metatype< QVector<double> >();
qc_init_metatype< QVector<int> >();
qc_init_metatype< QVariantList >();
}
MetaType *MetaType::find( PyrSlot *slot )
{
switch (GetTag(slot)) {
case tagNil :
return 0;
case tagInt :
return metaType<int>();
case tagSym :
return metaType<QString>();
case tagChar :
return metaType<QChar>();
case tagFalse :
case tagTrue :
return metaType<bool>();
case tagObj :
{
PyrObject *obj = slotRawObject(slot);
PyrClass *klass = obj->classptr;
unsigned char format = obj->obj_format;
if( format == obj_double || format == obj_float )
return metaType< QVector<double> >();
else if( format == obj_int32 || format == obj_int16 || format == obj_int8 )
return metaType< QVector<int> >();
else if( isKindOfSlot( slot, class_string ) ) {
return metaType<QString>();
}
else if( isKindOfSlot( slot, SC_CLASS(Point) ) ) {
return metaType<QPointF>();
}
else if( isKindOfSlot( slot, SC_CLASS(Rect) ) ) {
return metaType<QRectF>();
}
else if( isKindOfSlot( slot, SC_CLASS(Size) ) ) {
return metaType<QSizeF>();
}
else if( klass == SC_CLASS(Color) ||
klass == SC_CLASS(Gradient) ||
klass == SC_CLASS(HiliteGradient) )
{
return metaType<QColor>();
}
else if( isKindOfSlot( slot, SC_CLASS(Font) ) ) {
return metaType<QFont>();
}
else if( isKindOfSlot( slot, SC_CLASS(QPalette) ) ) {
return metaType<QPalette>();
}
else if( isKindOfSlot( slot, SC_CLASS(QObject) ) ) {
return metaType<QObjectProxy*>();
}
else if( isKindOfSlot( slot, class_array ) || isKindOfSlot( slot, class_symbolarray ) ) {
return metaType<QVariantList>();
}
else if( isKindOfSlot( slot, SC_CLASS(TreeViewItem) ) ) {
return metaType<QcTreeWidget::ItemPtr>();
}
else if( isKindOfSlot( slot, SC_CLASS(Image) ) ) {
return metaType<SharedImage>();
}
else {
QString className = TypeCodec<QString>::read( &slotRawObject(slot)->classptr->name );
qcWarningMsg(QStringLiteral("WARNING: Do not know how to use an instance of class '%1'").arg(className));
return 0;
}
}
default:
return metaType<double>();
}
}
MetaType * MetaType::find( int id )
{
int n = gMetaTypes.count();
MetaType * const * d = gMetaTypes.constData();
int i;
for(i = 0; i < n; ++i)
{
if((*d)->mId == id)
return *d;
++d;
}
return 0;
}
} // namespace QtCollider