@@ -55,6 +55,64 @@ void maybeDeclareMetaType(QTextStream &stream, const QString &typeName,
55
55
QSet<QString> ®isteredTypeNames);
56
56
bool hasDefaultConstructor (const AbstractMetaClass *meta_class);
57
57
58
+ static QStringList getOperatorCodes (const AbstractMetaClass* cls) {
59
+ QSet<QString> operatorCodes;
60
+ AbstractMetaFunctionList returned;
61
+ AbstractMetaFunctionList functions = cls->functions ();
62
+ foreach (AbstractMetaFunction *function, functions) {
63
+ if (function->originalName ().startsWith (" operator" )) {
64
+ QString op = function->originalName ().mid (8 );
65
+ operatorCodes.insert (op);
66
+ }
67
+ }
68
+ QSet<QString> r;
69
+ foreach (QString op, operatorCodes.toList ()) {
70
+ if (op == " >" || op == " <" || op == " >=" || op == " <=" || op == " ==" || op == " !=" ) {
71
+ r.insert (" PythonQt::Type_RichCompare" );
72
+ } else if (op == " +" ) {
73
+ r.insert (" PythonQt::Type_Add" );
74
+ } else if (op == " -" ) {
75
+ r.insert (" PythonQt::Type_Subtract" );
76
+ } else if (op == " /" ) {
77
+ r.insert (" PythonQt::Type_Divide" );
78
+ } else if (op == " *" ) {
79
+ r.insert (" PythonQt::Type_Multiply" );
80
+ } else if (op == " %" ) {
81
+ r.insert (" PythonQt::Type_Mod" );
82
+ } else if (op == " &" ) {
83
+ r.insert (" PythonQt::Type_And" );
84
+ } else if (op == " |" ) {
85
+ r.insert (" PythonQt::Type_Or" );
86
+ } else if (op == " ^" ) {
87
+ r.insert (" PythonQt::Type_Xor" );
88
+ } else if (op == " ~" ) {
89
+ r.insert (" PythonQt::Type_Invert" );
90
+
91
+ } else if (op == " +=" ) {
92
+ r.insert (" PythonQt::Type_InplaceAdd" );
93
+ } else if (op == " -=" ) {
94
+ r.insert (" PythonQt::Type_InplaceSubtract" );
95
+ } else if (op == " /=" ) {
96
+ r.insert (" PythonQt::Type_InplaceDivide" );
97
+ } else if (op == " *=" ) {
98
+ r.insert (" PythonQt::Type_InplaceMultiply" );
99
+ } else if (op == " %=" ) {
100
+ r.insert (" PythonQt::Type_InplaceMod" );
101
+ } else if (op == " &=" ) {
102
+ r.insert (" PythonQt::Type_InplaceAnd" );
103
+ } else if (op == " |=" ) {
104
+ r.insert (" PythonQt::Type_InplaceOr" );
105
+ } else if (op == " ^=" ) {
106
+ r.insert (" PythonQt::Type_InplaceXor" );
107
+ }
108
+ }
109
+ if (cls->hasDefaultIsNull ()) {
110
+ r.insert (" PythonQt::Type_NonZero" );
111
+ }
112
+ QStringList result = r.toList ();
113
+ return result;
114
+ }
115
+
58
116
void SetupGenerator::generate ()
59
117
{
60
118
AbstractMetaClassList classes_with_polymorphic_id;
@@ -138,11 +196,15 @@ void SetupGenerator::generate()
138
196
} else {
139
197
shellCreator = " , NULL" ;
140
198
}
199
+ QString operatorCodes = getOperatorCodes (cls).join (" |" );
200
+ if (operatorCodes.isEmpty ()) {
201
+ operatorCodes = " 0" ;
202
+ }
141
203
if (cls->isQObject ()) {
142
- s << " PythonQt::priv()->registerClass(&" << cls->qualifiedCppName () << " ::staticMetaObject, \" " << shortPackName <<" \" , PythonQtCreateObject<PythonQtWrapper_" << cls->name () << " >" << shellCreator << " , module);" << endl;
204
+ s << " PythonQt::priv()->registerClass(&" << cls->qualifiedCppName () << " ::staticMetaObject, \" " << shortPackName <<" \" , PythonQtCreateObject<PythonQtWrapper_" << cls->name () << " >" << shellCreator << " , module, " << operatorCodes << " );" << endl;
143
205
} else {
144
206
QString baseName = cls->baseClass ()?cls->baseClass ()->qualifiedCppName ():" " ;
145
- s << " PythonQt::priv()->registerCPPClass(\" " << cls->qualifiedCppName () << " \" , \" " << baseName << " \" , \" " << shortPackName <<" \" , PythonQtCreateObject<PythonQtWrapper_" << cls->name () << " >" << shellCreator << " , module);" << endl;
207
+ s << " PythonQt::priv()->registerCPPClass(\" " << cls->qualifiedCppName () << " \" , \" " << baseName << " \" , \" " << shortPackName <<" \" , PythonQtCreateObject<PythonQtWrapper_" << cls->name () << " >" << shellCreator << " , module, " << operatorCodes << " );" << endl;
146
208
}
147
209
foreach (AbstractMetaClass* interface, cls->interfaces ()) {
148
210
// the interface might be our own class... (e.g. QPaintDevice)
0 commit comments