@@ -471,6 +471,8 public: | |||
|
471 | 471 | FunctionType functionType() const { return m_function_type; } |
|
472 | 472 | void setFunctionType(FunctionType type) { m_function_type = type; } |
|
473 | 473 | |
|
474 | bool isVirtual() { return !(isFinal() || isSignal() || isStatic()); } | |
|
475 | ||
|
474 | 476 | QStringList introspectionCompatibleSignatures(const QStringList &resolvedArguments = QStringList()) const; |
|
475 | 477 | QString signature() const; |
|
476 | 478 | QString targetLangSignature(bool minimal = false) const; |
@@ -68,6 +68,7 QString GeneratorSetQtScript::generate() { | |||
|
68 | 68 | SetupGenerator setupGenerator; |
|
69 | 69 | setupGenerator.setOutputDirectory(outDir); |
|
70 | 70 | setupGenerator.setQtMetaTypeDeclaredTypeNames(declaredTypeNames); |
|
71 | setupGenerator.setClasses(classes); | |
|
71 | 72 | |
|
72 | 73 | /* |
|
73 | 74 | ClassGenerator classGenerator(&priGenerator, &setupGenerator); |
@@ -41,6 +41,20 bool hasDefaultConstructor(const AbstractMetaClass *meta_class); | |||
|
41 | 41 | |
|
42 | 42 | void SetupGenerator::generate() |
|
43 | 43 | { |
|
44 | AbstractMetaClassList classes_with_polymorphic_id; | |
|
45 | { | |
|
46 | QHashIterator<QString, QList<const AbstractMetaClass*> > pack(packHash); | |
|
47 | while (pack.hasNext()) { | |
|
48 | pack.next(); | |
|
49 | QList<const AbstractMetaClass*> list = pack.value(); | |
|
50 | foreach (const AbstractMetaClass *cls, list) { | |
|
51 | if (cls->typeEntry()->isPolymorphicBase()) { | |
|
52 | classes_with_polymorphic_id.append((AbstractMetaClass*)cls); | |
|
53 | } | |
|
54 | } | |
|
55 | } | |
|
56 | } | |
|
57 | ||
|
44 | 58 |
|
|
45 | 59 |
|
|
46 | 60 |
|
@@ -91,6 +105,9 void SetupGenerator::generate() | |||
|
91 | 105 |
|
|
92 | 106 |
|
|
93 | 107 | |
|
108 | QStringList polymorphicHandlers = writePolymorphicHandler(s, list.at(0)->package(), classes_with_polymorphic_id); | |
|
109 | s << endl; | |
|
110 | ||
|
94 | 111 |
|
|
95 | 112 |
|
|
96 | 113 |
|
@@ -115,9 +132,84 void SetupGenerator::generate() | |||
|
115 | 132 |
|
|
116 | 133 |
|
|
117 | 134 |
|
|
135 | foreach (QString handler, polymorphicHandlers) { | |
|
136 | s << "PythonQt::self()->addPolymorphicHandler(\""<< handler << "\", polymorphichandler_" << handler << ");" << endl; | |
|
137 | } | |
|
118 | 138 | |
|
119 | 139 |
|
|
120 | 140 |
|
|
121 | 141 |
|
|
122 | 142 |
|
|
123 | 143 | } |
|
144 | ||
|
145 | QStringList SetupGenerator::writePolymorphicHandler(QTextStream &s, const QString &package, | |
|
146 | const AbstractMetaClassList &classes) | |
|
147 | { | |
|
148 | QStringList handlers; | |
|
149 | foreach (AbstractMetaClass *cls, classes) { | |
|
150 | const ComplexTypeEntry *centry = cls->typeEntry(); | |
|
151 | if (!centry->isPolymorphicBase()) | |
|
152 | continue; | |
|
153 | bool isGraphicsItem = (cls->qualifiedCppName()=="QGraphicsItem"); | |
|
154 | ||
|
155 | AbstractMetaClassList classList = this->classes(); | |
|
156 | bool first = true; | |
|
157 | foreach (AbstractMetaClass *clazz, classList) { | |
|
158 | bool inherits = false; | |
|
159 | if (isGraphicsItem) { | |
|
160 | foreach(AbstractMetaClass* interfaze, clazz->interfaces()) { | |
|
161 | if (interfaze->qualifiedCppName()=="QGraphicsItem") { | |
|
162 | inherits = true; | |
|
163 | break; | |
|
164 | } | |
|
165 | } | |
|
166 | } else { | |
|
167 | inherits = clazz->inheritsFrom(cls); | |
|
168 | } | |
|
169 | if (clazz->package() == package && inherits) { | |
|
170 | if (!clazz->typeEntry()->polymorphicIdValue().isEmpty() || isGraphicsItem) { | |
|
171 | // On first find, open the function | |
|
172 | if (first) { | |
|
173 | first = false; | |
|
174 | ||
|
175 | QString handler = cls->name(); | |
|
176 | handlers.append(handler); | |
|
177 | ||
|
178 | s << "static void* polymorphichandler_" << handler | |
|
179 | << "(const void *ptr, char **class_name)" << endl | |
|
180 | << "{" << endl | |
|
181 | << " Q_ASSERT(ptr != 0);" << endl | |
|
182 | << " " << cls->qualifiedCppName() << " *object = (" | |
|
183 | << cls->qualifiedCppName() << " *)ptr;" << endl; | |
|
184 | } | |
|
185 | ||
|
186 | // For each, add case label | |
|
187 | QString polyId = clazz->typeEntry()->polymorphicIdValue(); | |
|
188 | if (isGraphicsItem) { | |
|
189 | polyId = "%1->type() == " + clazz->qualifiedCppName() + "::Type"; | |
|
190 | } | |
|
191 | s << " if (" | |
|
192 | << polyId.replace("%1", "object") | |
|
193 | << ") {" << endl | |
|
194 | << " *class_name = \"" << clazz->name() << "\";" << endl | |
|
195 | << " return (" << clazz->qualifiedCppName() << "*)object;" << endl | |
|
196 | << " }" << endl; | |
|
197 | } else { | |
|
198 | QString warning = QString("class '%1' inherits from polymorphic class '%2', but has no polymorphic id set") | |
|
199 | .arg(clazz->name()) | |
|
200 | .arg(cls->name()); | |
|
201 | ||
|
202 | ReportHandler::warning(warning); | |
|
203 | } | |
|
204 | } | |
|
205 | } | |
|
206 | ||
|
207 | // Close the function if it has been opened | |
|
208 | if (!first) { | |
|
209 | s << " return NULL;" << endl | |
|
210 | << "}" << endl; | |
|
211 | } | |
|
212 | } | |
|
213 | ||
|
214 | return handlers; | |
|
215 | } |
@@ -37,6 +37,9 class SetupGenerator : public Generator | |||
|
37 | 37 | void addClass(const AbstractMetaClass *cls); |
|
38 | 38 | |
|
39 | 39 | private: |
|
40 | QStringList writePolymorphicHandler(QTextStream &s, const QString &package, | |
|
41 | const AbstractMetaClassList &classes); | |
|
42 | ||
|
40 | 43 |
|
|
41 | 44 | }; |
|
42 | 45 | #endif // SETUPGENERATOR_H |
@@ -269,7 +269,7 AbstractMetaFunctionList ShellGenerator::getProtectedFunctionsThatNeedPromotion( | |||
|
269 | 269 | AbstractMetaFunctionList functions; |
|
270 | 270 | AbstractMetaFunctionList functions1 = getFunctionsToWrap(meta_class); |
|
271 | 271 | foreach(AbstractMetaFunction* func, functions1) { |
|
272 |
if (!func-> |
|
|
272 | if (!func->isPublic() || func->isVirtual()) { | |
|
273 | 273 | functions << func; |
|
274 | 274 | } |
|
275 | 275 | } |
@@ -117,7 +117,7 void ShellHeaderGenerator::write(QTextStream &s, const AbstractMetaClass *meta_c | |||
|
117 | 117 | |
|
118 | 118 | foreach(AbstractMetaFunction* fun, promoteFunctions) { |
|
119 | 119 | s << "inline "; |
|
120 |
writeFunctionSignature(s, fun, 0, |
|
|
120 | writeFunctionSignature(s, fun, 0, "promoted_", | |
|
121 | 121 | Option(IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces)); |
|
122 | 122 | s << " { "; |
|
123 | 123 | QString scriptFunctionName = fun->originalName(); |
@@ -199,6 +199,8 void ShellImplGenerator::write(QTextStream &s, const AbstractMetaClass *meta_cla | |||
|
199 | 199 | } |
|
200 | 200 | } |
|
201 | 201 | |
|
202 | QString wrappedObject = " (*theWrappedObject)"; | |
|
203 | ||
|
202 | 204 | // write member functions |
|
203 | 205 | for (int i = 0; i < functions.size(); ++i) { |
|
204 | 206 | AbstractMetaFunction *fun = functions.at(i); |
@@ -208,12 +210,7 void ShellImplGenerator::write(QTextStream &s, const AbstractMetaClass *meta_cla | |||
|
208 | 210 | Option(FirstArgIsWrappedObject | OriginalName | ShowStatic | UnderscoreSpaces), |
|
209 | 211 | "PythonQtWrapper_"); |
|
210 | 212 | s << endl << "{" << endl; |
|
211 | QString wrappedObject; | |
|
212 | if (fun->wasPublic()) { | |
|
213 | wrappedObject = " (*theWrappedObject)"; | |
|
214 | } else { | |
|
215 | wrappedObject = " (*((" + promoterClassName(meta_class) + "*)theWrappedObject))"; | |
|
216 | } | |
|
213 | s << " "; | |
|
217 | 214 | if (ShellGenerator::isSpecialStreamingOperator(fun)) { |
|
218 | 215 | s << fun->arguments().at(0)->argumentName(); |
|
219 | 216 | if (fun->originalName().startsWith("operator>>")) { |
@@ -241,7 +238,11 void ShellImplGenerator::write(QTextStream &s, const AbstractMetaClass *meta_cla | |||
|
241 | 238 | if (fun->isStatic()) { |
|
242 | 239 | s << meta_class->qualifiedCppName() << "::"; |
|
243 | 240 | } else { |
|
244 | s << wrappedObject << "."; | |
|
241 | if (!fun->isPublic() || fun->isVirtual()) { | |
|
242 | s << " ((" << promoterClassName(meta_class) << "*)theWrappedObject)->promoted_"; | |
|
243 | } else { | |
|
244 | s << " theWrappedObject->"; | |
|
245 | } | |
|
245 | 246 | } |
|
246 | 247 | s << fun->originalName() << "("; |
|
247 | 248 | for (int i = 0; i < args.size(); ++i) { |
@@ -1401,7 +1401,7 | |||
|
1401 | 1401 | <interface-type name="QLayoutItem"/> |
|
1402 | 1402 | <interface-type name="QPaintDevice"/> |
|
1403 | 1403 | |
|
1404 | <interface-type name="QGraphicsItem" delete-in-main-thread="yes"> | |
|
1404 | <interface-type name="QGraphicsItem" delete-in-main-thread="yes" polymorphic-base="yes"> | |
|
1405 | 1405 | <modify-function signature="setMatrix(QMatrix, bool)" remove="all"/> |
|
1406 | 1406 | |
|
1407 | 1407 | <modify-function signature="paint(QPainter*,const QStyleOptionGraphicsItem*,QWidget*)"> |
General Comments 0
You need to be logged in to leave comments.
Login now