@@ -1,314 +1,309 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 | ** Copyright (C) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Script Generator project on Qt Labs. |
|
7 | ** This file is part of the Qt Script Generator project on Qt Labs. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE:LGPL$ |
|
9 | ** $QT_BEGIN_LICENSE:LGPL$ | |
10 | ** No Commercial Usage |
|
10 | ** No Commercial Usage | |
11 | ** This file contains pre-release code and may not be distributed. |
|
11 | ** This file contains pre-release code and may not be distributed. | |
12 | ** You may use this file in accordance with the terms and conditions |
|
12 | ** You may use this file in accordance with the terms and conditions | |
13 | ** contained in the Technology Preview License Agreement accompanying |
|
13 | ** contained in the Technology Preview License Agreement accompanying | |
14 | ** this package. |
|
14 | ** this package. | |
15 | ** |
|
15 | ** | |
16 | ** GNU Lesser General Public License Usage |
|
16 | ** GNU Lesser General Public License Usage | |
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | |
18 | ** General Public License version 2.1 as published by the Free Software |
|
18 | ** General Public License version 2.1 as published by the Free Software | |
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | |
20 | ** packaging of this file. Please review the following information to |
|
20 | ** packaging of this file. Please review the following information to | |
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | |
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
23 | ** |
|
23 | ** | |
24 | ** In addition, as a special exception, Nokia gives you certain additional |
|
24 | ** In addition, as a special exception, Nokia gives you certain additional | |
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | |
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | |
27 | ** |
|
27 | ** | |
28 | ** If you have questions regarding the use of this file, please contact |
|
28 | ** If you have questions regarding the use of this file, please contact | |
29 | ** Nokia at qt-info@nokia.com. |
|
29 | ** Nokia at qt-info@nokia.com. | |
30 | ** |
|
30 | ** | |
31 | ** |
|
31 | ** | |
32 | ** |
|
32 | ** | |
33 | ** |
|
33 | ** | |
34 | ** |
|
34 | ** | |
35 | ** |
|
35 | ** | |
36 | ** |
|
36 | ** | |
37 | ** |
|
37 | ** | |
38 | ** $QT_END_LICENSE$ |
|
38 | ** $QT_END_LICENSE$ | |
39 | ** |
|
39 | ** | |
40 | ****************************************************************************/ |
|
40 | ****************************************************************************/ | |
41 |
|
41 | |||
42 | #include "shellheadergenerator.h" |
|
42 | #include "shellheadergenerator.h" | |
43 | #include "fileout.h" |
|
43 | #include "fileout.h" | |
44 |
|
44 | |||
45 | #include <QtCore/QDir> |
|
45 | #include <QtCore/QDir> | |
46 |
|
46 | |||
47 | #include <qdebug.h> |
|
47 | #include <qdebug.h> | |
48 |
|
48 | |||
49 | QString ShellHeaderGenerator::fileNameForClass(const AbstractMetaClass *meta_class) const |
|
49 | QString ShellHeaderGenerator::fileNameForClass(const AbstractMetaClass *meta_class) const | |
50 | { |
|
50 | { | |
51 | return QString("PythonQtWrapper_%1.h").arg(meta_class->name()); |
|
51 | return QString("PythonQtWrapper_%1.h").arg(meta_class->name()); | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 |
|
54 | |||
55 | void ShellHeaderGenerator::writeFieldAccessors(QTextStream &s, const AbstractMetaField *field) |
|
55 | void ShellHeaderGenerator::writeFieldAccessors(QTextStream &s, const AbstractMetaField *field) | |
56 | { |
|
56 | { | |
57 | const AbstractMetaFunction *setter = field->setter(); |
|
57 | const AbstractMetaFunction *setter = field->setter(); | |
58 | const AbstractMetaFunction *getter = field->getter(); |
|
58 | const AbstractMetaFunction *getter = field->getter(); | |
59 |
|
59 | |||
60 | // static fields are not supported (yet?) |
|
60 | // static fields are not supported (yet?) | |
61 | if (setter->isStatic()) return; |
|
61 | if (setter->isStatic()) return; | |
62 |
|
62 | |||
63 | // Uuid data4 did not work (TODO: move to typesystem...( |
|
63 | // Uuid data4 did not work (TODO: move to typesystem...( | |
64 | if (field->enclosingClass()->name()=="QUuid" && setter->name()=="data4") return; |
|
64 | if (field->enclosingClass()->name()=="QUuid" && setter->name()=="data4") return; | |
65 | if (field->enclosingClass()->name()=="QIPv6Address") return; |
|
65 | if (field->enclosingClass()->name()=="QIPv6Address") return; | |
66 |
|
66 | |||
67 | if (!field->type()->isConstant()) { |
|
67 | if (!field->type()->isConstant()) { | |
68 | writeFunctionSignature(s, setter, 0, QString(), |
|
68 | writeFunctionSignature(s, setter, 0, QString(), | |
69 | Option(ConvertReferenceToPtr | FirstArgIsWrappedObject| IncludeDefaultExpression | ShowStatic | UnderscoreSpaces)); |
|
69 | Option(ConvertReferenceToPtr | FirstArgIsWrappedObject| IncludeDefaultExpression | ShowStatic | UnderscoreSpaces)); | |
70 | s << "{ theWrappedObject->" << field->name() << " = " << setter->arguments()[0]->argumentName() << "; }\n"; |
|
70 | s << "{ theWrappedObject->" << field->name() << " = " << setter->arguments()[0]->argumentName() << "; }\n"; | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | writeFunctionSignature(s, getter, 0, QString(), |
|
73 | writeFunctionSignature(s, getter, 0, QString(), | |
74 | Option(ConvertReferenceToPtr | FirstArgIsWrappedObject| IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces)); |
|
74 | Option(ConvertReferenceToPtr | FirstArgIsWrappedObject| IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces)); | |
75 | s << "{ return theWrappedObject->" << field->name() << "; }\n"; |
|
75 | s << "{ return theWrappedObject->" << field->name() << "; }\n"; | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | void ShellHeaderGenerator::write(QTextStream &s, const AbstractMetaClass *meta_class) |
|
78 | void ShellHeaderGenerator::write(QTextStream &s, const AbstractMetaClass *meta_class) | |
79 | { |
|
79 | { | |
80 | QString builtIn = ShellGenerator::isBuiltIn(meta_class->name())?"_builtin":""; |
|
80 | QString builtIn = ShellGenerator::isBuiltIn(meta_class->name())?"_builtin":""; | |
81 | QString pro_file_name = meta_class->package().replace(".", "_") + builtIn + "/" + meta_class->package().replace(".", "_") + builtIn + ".pri"; |
|
81 | QString pro_file_name = meta_class->package().replace(".", "_") + builtIn + "/" + meta_class->package().replace(".", "_") + builtIn + ".pri"; | |
82 | priGenerator->addHeader(pro_file_name, fileNameForClass(meta_class)); |
|
82 | priGenerator->addHeader(pro_file_name, fileNameForClass(meta_class)); | |
83 | setupGenerator->addClass(meta_class->package().replace(".", "_") + builtIn, meta_class); |
|
83 | setupGenerator->addClass(meta_class->package().replace(".", "_") + builtIn, meta_class); | |
84 |
|
84 | |||
85 | QString include_block = "PYTHONQTWRAPPER_" + meta_class->name().toUpper() + "_H"; |
|
85 | QString include_block = "PYTHONQTWRAPPER_" + meta_class->name().toUpper() + "_H"; | |
86 |
|
86 | |||
87 | s << "#ifndef " << include_block << endl |
|
87 | s << "#ifndef " << include_block << endl | |
88 | << "#define " << include_block << endl << endl; |
|
88 | << "#define " << include_block << endl << endl; | |
89 |
|
89 | |||
90 | Include inc = meta_class->typeEntry()->include(); |
|
90 | Include inc = meta_class->typeEntry()->include(); | |
91 | ShellGenerator::writeInclude(s, inc); |
|
91 | ShellGenerator::writeInclude(s, inc); | |
92 |
|
92 | |||
93 | s << "#include <QObject>" << endl << endl; |
|
93 | s << "#include <QObject>" << endl << endl; | |
94 | s << "#include <PythonQt.h>" << endl << endl; |
|
94 | s << "#include <PythonQt.h>" << endl << endl; | |
95 |
|
95 | |||
96 | IncludeList list = meta_class->typeEntry()->extraIncludes(); |
|
96 | IncludeList list = meta_class->typeEntry()->extraIncludes(); | |
97 | qSort(list.begin(), list.end()); |
|
97 | qSort(list.begin(), list.end()); | |
98 | foreach (const Include &inc, list) { |
|
98 | foreach (const Include &inc, list) { | |
99 | ShellGenerator::writeInclude(s, inc); |
|
99 | ShellGenerator::writeInclude(s, inc); | |
100 | } |
|
100 | } | |
101 | s << endl; |
|
101 | s << endl; | |
102 |
|
102 | |||
103 | AbstractMetaFunctionList ctors = meta_class->queryFunctions(AbstractMetaClass::Constructors |
|
103 | AbstractMetaFunctionList ctors = meta_class->queryFunctions(AbstractMetaClass::Constructors | |
104 | | AbstractMetaClass::WasVisible |
|
104 | | AbstractMetaClass::WasVisible | |
105 | | AbstractMetaClass::NotRemovedFromTargetLang); |
|
105 | | AbstractMetaClass::NotRemovedFromTargetLang); | |
106 |
|
106 | |||
107 | // Shell------------------------------------------------------------------- |
|
107 | // Shell------------------------------------------------------------------- | |
108 | if (meta_class->generateShellClass()) { |
|
108 | if (meta_class->generateShellClass()) { | |
109 |
|
109 | |||
110 | AbstractMetaFunctionList virtualsForShell = getVirtualFunctionsForShell(meta_class); |
|
110 | AbstractMetaFunctionList virtualsForShell = getVirtualFunctionsForShell(meta_class); | |
111 |
|
111 | |||
112 | s << "class " << shellClassName(meta_class) |
|
112 | s << "class " << shellClassName(meta_class) | |
113 | << " : public " << meta_class->qualifiedCppName() << endl << "{" << endl; |
|
113 | << " : public " << meta_class->qualifiedCppName() << endl << "{" << endl; | |
114 | s << "public:" << endl; |
|
114 | s << "public:" << endl; | |
115 | foreach(AbstractMetaFunction* fun, ctors) { |
|
115 | foreach(AbstractMetaFunction* fun, ctors) { | |
116 | s << " "; |
|
116 | s << " "; | |
117 | writeFunctionSignature(s, fun, 0,"PythonQtShell_", |
|
117 | writeFunctionSignature(s, fun, 0,"PythonQtShell_", | |
118 | Option(IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces)); |
|
118 | Option(IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces)); | |
119 | s << ":" << meta_class->qualifiedCppName() << "("; |
|
119 | s << ":" << meta_class->qualifiedCppName() << "("; | |
120 | QString scriptFunctionName = fun->originalName(); |
|
120 | QString scriptFunctionName = fun->originalName(); | |
121 | AbstractMetaArgumentList args = fun->arguments(); |
|
121 | AbstractMetaArgumentList args = fun->arguments(); | |
122 | for (int i = 0; i < args.size(); ++i) { |
|
122 | for (int i = 0; i < args.size(); ++i) { | |
123 | if (i > 0) |
|
123 | if (i > 0) | |
124 | s << ", "; |
|
124 | s << ", "; | |
125 | s << args.at(i)->argumentName(); |
|
125 | s << args.at(i)->argumentName(); | |
126 | } |
|
126 | } | |
127 | s << "),_wrapper(NULL) {};" << endl; |
|
127 | s << "),_wrapper(NULL) {};" << endl; | |
128 | } |
|
128 | } | |
129 | s << endl; |
|
129 | s << endl; | |
130 | s << " ~" << shellClassName(meta_class) << "();" << endl; |
|
130 | s << " ~" << shellClassName(meta_class) << "();" << endl; | |
131 | s << endl; |
|
131 | s << endl; | |
132 |
|
132 | |||
133 | foreach(AbstractMetaFunction* fun, virtualsForShell) { |
|
133 | foreach(AbstractMetaFunction* fun, virtualsForShell) { | |
134 | s << "virtual "; |
|
134 | s << "virtual "; | |
135 | writeFunctionSignature(s, fun, 0, QString(), |
|
135 | writeFunctionSignature(s, fun, 0, QString(), | |
136 | Option(IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces)); |
|
136 | Option(IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces)); | |
137 | s << ";" << endl; |
|
137 | s << ";" << endl; | |
138 | } |
|
138 | } | |
139 | s << endl; |
|
139 | s << endl; | |
140 | s << " PythonQtInstanceWrapper* _wrapper; " << endl; |
|
140 | s << " PythonQtInstanceWrapper* _wrapper; " << endl; | |
141 |
|
141 | |||
142 | s << "};" << endl << endl; |
|
142 | s << "};" << endl << endl; | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | // Promoter------------------------------------------------------------------- |
|
145 | // Promoter------------------------------------------------------------------- | |
146 | AbstractMetaFunctionList promoteFunctions = getProtectedFunctionsThatNeedPromotion(meta_class); |
|
146 | AbstractMetaFunctionList promoteFunctions = getProtectedFunctionsThatNeedPromotion(meta_class); | |
147 | if (!promoteFunctions.isEmpty()) { |
|
147 | if (!promoteFunctions.isEmpty()) { | |
148 | s << "class " << promoterClassName(meta_class) |
|
148 | s << "class " << promoterClassName(meta_class) | |
149 | << " : public " << meta_class->qualifiedCppName() << endl << "{ public:" << endl; |
|
149 | << " : public " << meta_class->qualifiedCppName() << endl << "{ public:" << endl; | |
150 |
|
150 | |||
151 | foreach(AbstractMetaFunction* fun, promoteFunctions) { |
|
151 | foreach(AbstractMetaFunction* fun, promoteFunctions) { | |
152 | s << "inline "; |
|
152 | s << "inline "; | |
153 | writeFunctionSignature(s, fun, 0, "promoted_", |
|
153 | writeFunctionSignature(s, fun, 0, "promoted_", | |
154 | Option(IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces)); |
|
154 | Option(IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces)); | |
155 | s << " { "; |
|
155 | s << " { "; | |
156 | QString scriptFunctionName = fun->originalName(); |
|
156 | QString scriptFunctionName = fun->originalName(); | |
157 | AbstractMetaArgumentList args = fun->arguments(); |
|
157 | AbstractMetaArgumentList args = fun->arguments(); | |
158 | if (fun->type()) |
|
158 | if (fun->type()) | |
159 | s << "return "; |
|
159 | s << "return "; | |
160 | s << meta_class->qualifiedCppName() << "::"; |
|
160 | s << meta_class->qualifiedCppName() << "::"; | |
161 | s << fun->originalName() << "("; |
|
161 | s << fun->originalName() << "("; | |
162 | for (int i = 0; i < args.size(); ++i) { |
|
162 | for (int i = 0; i < args.size(); ++i) { | |
163 | if (i > 0) |
|
163 | if (i > 0) | |
164 | s << ", "; |
|
164 | s << ", "; | |
165 | s << args.at(i)->argumentName(); |
|
165 | s << args.at(i)->argumentName(); | |
166 | } |
|
166 | } | |
167 | s << "); }" << endl; |
|
167 | s << "); }" << endl; | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | s << "};" << endl << endl; |
|
170 | s << "};" << endl << endl; | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | // Wrapper------------------------------------------------------------------- |
|
173 | // Wrapper------------------------------------------------------------------- | |
174 |
|
174 | |||
175 | s << "class " << wrapperClassName(meta_class) |
|
175 | s << "class " << wrapperClassName(meta_class) | |
176 | << " : public QObject" << endl |
|
176 | << " : public QObject" << endl | |
177 | << "{ Q_OBJECT" << endl; |
|
177 | << "{ Q_OBJECT" << endl; | |
178 |
|
178 | |||
179 | s << "public:" << endl; |
|
179 | s << "public:" << endl; | |
180 |
|
180 | |||
181 | AbstractMetaEnumList enums1 = meta_class->enums(); |
|
181 | AbstractMetaEnumList enums1 = meta_class->enums(); | |
182 | AbstractMetaEnumList enums; |
|
182 | AbstractMetaEnumList enums; | |
183 | QList<FlagsTypeEntry*> flags; |
|
183 | QList<FlagsTypeEntry*> flags; | |
184 | foreach(AbstractMetaEnum* enum1, enums1) { |
|
184 | foreach(AbstractMetaEnum* enum1, enums1) { | |
185 | // catch gadgets and enums that are not exported on QObjects... |
|
185 | // catch gadgets and enums that are not exported on QObjects... | |
186 | if (enum1->wasPublic() && (!meta_class->isQObject() || !enum1->hasQEnumsDeclaration())) { |
|
186 | if (enum1->wasPublic() && (!meta_class->isQObject() || !enum1->hasQEnumsDeclaration())) { | |
187 | enums << enum1; |
|
187 | enums << enum1; | |
188 | if (enum1->typeEntry()->flags()) { |
|
188 | if (enum1->typeEntry()->flags()) { | |
189 | flags << enum1->typeEntry()->flags(); |
|
189 | flags << enum1->typeEntry()->flags(); | |
190 | } |
|
190 | } | |
191 | } |
|
191 | } | |
192 | } |
|
192 | } | |
193 | if (enums.count()) { |
|
193 | if (enums.count()) { | |
194 | s << "Q_ENUMS("; |
|
194 | s << "Q_ENUMS("; | |
195 | foreach(AbstractMetaEnum* enum1, enums) { |
|
195 | foreach(AbstractMetaEnum* enum1, enums) { | |
196 | s << enum1->name() << " "; |
|
196 | s << enum1->name() << " "; | |
197 | } |
|
197 | } | |
198 | s << ")" << endl; |
|
198 | s << ")" << endl; | |
199 |
|
199 | |||
200 | if (flags.count()) { |
|
200 | if (flags.count()) { | |
201 | s << "Q_FLAGS("; |
|
201 | s << "Q_FLAGS("; | |
202 | foreach(FlagsTypeEntry* flag1, flags) { |
|
202 | foreach(FlagsTypeEntry* flag1, flags) { | |
203 | QString origName = flag1->originalName(); |
|
203 | QString origName = flag1->originalName(); | |
204 | int idx = origName.lastIndexOf("::"); |
|
204 | int idx = origName.lastIndexOf("::"); | |
205 | if (idx!= -1) { |
|
205 | if (idx!= -1) { | |
206 | origName = origName.mid(idx+2); |
|
206 | origName = origName.mid(idx+2); | |
207 | } |
|
207 | } | |
208 | s << origName << " "; |
|
208 | s << origName << " "; | |
209 | } |
|
209 | } | |
210 | s << ")" << endl; |
|
210 | s << ")" << endl; | |
211 | } |
|
211 | } | |
212 |
|
212 | |||
213 | foreach(AbstractMetaEnum* enum1, enums) { |
|
213 | foreach(AbstractMetaEnum* enum1, enums) { | |
214 | s << "enum " << enum1->name() << "{" << endl; |
|
214 | s << "enum " << enum1->name() << "{" << endl; | |
215 | bool first = true; |
|
215 | bool first = true; | |
216 | foreach(AbstractMetaEnumValue* value, enum1->values()) { |
|
216 | foreach(AbstractMetaEnumValue* value, enum1->values()) { | |
217 | if (first) { first = false; } |
|
217 | if (first) { first = false; } | |
218 | else { s << ", "; } |
|
218 | else { s << ", "; } | |
219 | s << " " << value->name() << " = " << meta_class->qualifiedCppName() << "::" << value->name(); |
|
219 | s << " " << value->name() << " = " << meta_class->qualifiedCppName() << "::" << value->name(); | |
220 | } |
|
220 | } | |
221 | s << "};" << endl; |
|
221 | s << "};" << endl; | |
222 | } |
|
222 | } | |
223 | if (flags.count()) { |
|
223 | if (flags.count()) { | |
224 | foreach(AbstractMetaEnum* enum1, enums) { |
|
224 | foreach(AbstractMetaEnum* enum1, enums) { | |
225 | if (enum1->typeEntry()->flags()) { |
|
225 | if (enum1->typeEntry()->flags()) { | |
226 | QString origName = enum1->typeEntry()->flags()->originalName(); |
|
226 | QString origName = enum1->typeEntry()->flags()->originalName(); | |
227 | int idx = origName.lastIndexOf("::"); |
|
227 | int idx = origName.lastIndexOf("::"); | |
228 | if (idx!= -1) { |
|
228 | if (idx!= -1) { | |
229 | origName = origName.mid(idx+2); |
|
229 | origName = origName.mid(idx+2); | |
230 | } |
|
230 | } | |
231 | s << "Q_DECLARE_FLAGS("<< origName << ", " << enum1->name() <<")"<<endl; |
|
231 | s << "Q_DECLARE_FLAGS("<< origName << ", " << enum1->name() <<")"<<endl; | |
232 | } |
|
232 | } | |
233 | } |
|
233 | } | |
234 | } |
|
234 | } | |
235 | } |
|
235 | } | |
236 | s << "public slots:" << endl; |
|
236 | s << "public slots:" << endl; | |
237 | if (meta_class->generateShellClass() || !meta_class->isAbstract()) { |
|
237 | if (meta_class->generateShellClass() || !meta_class->isAbstract()) { | |
238 |
|
238 | |||
239 | bool copyConstructorSeen = false; |
|
239 | bool copyConstructorSeen = false; | |
240 | bool defaultConstructorSeen = false; |
|
240 | bool defaultConstructorSeen = false; | |
241 | foreach (const AbstractMetaFunction *fun, ctors) { |
|
241 | foreach (const AbstractMetaFunction *fun, ctors) { | |
242 | if (!fun->isPublic() || fun->isAbstract()) { continue; } |
|
242 | if (!fun->isPublic() || fun->isAbstract()) { continue; } | |
243 | s << meta_class->qualifiedCppName() << "* "; |
|
243 | s << meta_class->qualifiedCppName() << "* "; | |
244 | writeFunctionSignature(s, fun, 0, "new_", |
|
244 | writeFunctionSignature(s, fun, 0, "new_", | |
245 | Option(IncludeDefaultExpression | OriginalName | ShowStatic)); |
|
245 | Option(IncludeDefaultExpression | OriginalName | ShowStatic)); | |
246 | s << ";" << endl; |
|
246 | s << ";" << endl; | |
247 | if (fun->arguments().size()==1 && meta_class->qualifiedCppName() == fun->arguments().at(0)->type()->typeEntry()->qualifiedCppName()) { |
|
247 | if (fun->arguments().size()==1 && meta_class->qualifiedCppName() == fun->arguments().at(0)->type()->typeEntry()->qualifiedCppName()) { | |
248 | copyConstructorSeen = true; |
|
248 | copyConstructorSeen = true; | |
249 | } |
|
249 | } | |
250 | if (fun->arguments().size()==0) { |
|
250 | if (fun->arguments().size()==0) { | |
251 | defaultConstructorSeen = true; |
|
251 | defaultConstructorSeen = true; | |
252 | } |
|
252 | } | |
253 | } |
|
253 | } | |
254 |
|
254 | |||
255 | if (meta_class->typeEntry()->isValue() |
|
255 | if (meta_class->typeEntry()->isValue() | |
256 | && !copyConstructorSeen && defaultConstructorSeen) { |
|
256 | && !copyConstructorSeen && defaultConstructorSeen) { | |
257 | QString className = meta_class->generateShellClass()?shellClassName(meta_class):meta_class->qualifiedCppName(); |
|
257 | QString className = meta_class->generateShellClass()?shellClassName(meta_class):meta_class->qualifiedCppName(); | |
258 | s << meta_class->qualifiedCppName() << "* new_" << meta_class->name() << "(const " << meta_class->qualifiedCppName() << "& other) {" << endl; |
|
258 | s << meta_class->qualifiedCppName() << "* new_" << meta_class->name() << "(const " << meta_class->qualifiedCppName() << "& other) {" << endl; | |
259 | s << className << "* a = new " << className << "();" << endl; |
|
259 | s << className << "* a = new " << className << "();" << endl; | |
260 | s << "*((" << meta_class->qualifiedCppName() << "*)a) = other;" << endl; |
|
260 | s << "*((" << meta_class->qualifiedCppName() << "*)a) = other;" << endl; | |
261 | s << "return a; }" << endl; |
|
261 | s << "return a; }" << endl; | |
262 | } |
|
262 | } | |
263 | } |
|
263 | } | |
264 | if (meta_class->hasPublicDestructor() && !meta_class->isNamespace()) { |
|
264 | if (meta_class->hasPublicDestructor() && !meta_class->isNamespace()) { | |
265 | s << "void delete_" << meta_class->name() << "(" << meta_class->qualifiedCppName() << "* obj) { delete obj; } "; |
|
265 | s << "void delete_" << meta_class->name() << "(" << meta_class->qualifiedCppName() << "* obj) { delete obj; } "; | |
266 | s << endl; |
|
266 | s << endl; | |
267 | } |
|
267 | } | |
268 | if (meta_class->name()=="QTreeWidgetItem") { |
|
|||
269 | s << "bool py_hasOwner(QTreeWidgetItem* theWrappedObject) { return theWrappedObject->treeWidget()!=NULL || theWrappedObject->parent()!=NULL; }" << endl; |
|
|||
270 | } else if (meta_class->name()=="QGraphicsItem") { |
|
|||
271 | s << "bool py_hasOwner(QGraphicsItem* theWrappedObject) { return theWrappedObject->scene()!=NULL || theWrappedObject->parentItem()!=NULL; }" << endl; |
|
|||
272 | } |
|
|||
273 |
|
268 | |||
274 | AbstractMetaFunctionList functions = getFunctionsToWrap(meta_class); |
|
269 | AbstractMetaFunctionList functions = getFunctionsToWrap(meta_class); | |
275 |
|
270 | |||
276 | foreach (const AbstractMetaFunction *function, functions) { |
|
271 | foreach (const AbstractMetaFunction *function, functions) { | |
277 | if (!function->isSlot() || function->isVirtual()) { |
|
272 | if (!function->isSlot() || function->isVirtual()) { | |
278 | s << " "; |
|
273 | s << " "; | |
279 | writeFunctionSignature(s, function, 0, QString(), |
|
274 | writeFunctionSignature(s, function, 0, QString(), | |
280 | Option(ConvertReferenceToPtr | FirstArgIsWrappedObject| IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces)); |
|
275 | Option(ConvertReferenceToPtr | FirstArgIsWrappedObject| IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces)); | |
281 | s << ";" << endl; |
|
276 | s << ";" << endl; | |
282 | } |
|
277 | } | |
283 | } |
|
278 | } | |
284 | if (meta_class->hasDefaultToStringFunction() || meta_class->hasToStringCapability()) { |
|
279 | if (meta_class->hasDefaultToStringFunction() || meta_class->hasToStringCapability()) { | |
285 | s << " QString py_toString(" << meta_class->qualifiedCppName() << "*);" << endl; |
|
280 | s << " QString py_toString(" << meta_class->qualifiedCppName() << "*);" << endl; | |
286 | } |
|
281 | } | |
287 | if (meta_class->hasDefaultIsNull()) { |
|
282 | if (meta_class->hasDefaultIsNull()) { | |
288 | s << " bool __nonzero__(" << meta_class->qualifiedCppName() << "* obj) { return !obj->isNull(); }" << endl; |
|
283 | s << " bool __nonzero__(" << meta_class->qualifiedCppName() << "* obj) { return !obj->isNull(); }" << endl; | |
289 | } |
|
284 | } | |
290 |
|
285 | |||
291 | // Field accessors |
|
286 | // Field accessors | |
292 | foreach (const AbstractMetaField *field, meta_class->fields()) { |
|
287 | foreach (const AbstractMetaField *field, meta_class->fields()) { | |
293 | if (field->isPublic()) { |
|
288 | if (field->isPublic()) { | |
294 | writeFieldAccessors(s, field); |
|
289 | writeFieldAccessors(s, field); | |
295 | } |
|
290 | } | |
296 | } |
|
291 | } | |
297 |
|
292 | |||
298 | writeInjectedCode(s, meta_class); |
|
293 | writeInjectedCode(s, meta_class); | |
299 |
|
294 | |||
300 |
|
295 | |||
301 | s << "};" << endl << endl |
|
296 | s << "};" << endl << endl | |
302 | << "#endif // " << include_block << endl; |
|
297 | << "#endif // " << include_block << endl; | |
303 |
|
298 | |||
304 | } |
|
299 | } | |
305 |
|
300 | |||
306 | void ShellHeaderGenerator::writeInjectedCode(QTextStream &s, const AbstractMetaClass *meta_class) |
|
301 | void ShellHeaderGenerator::writeInjectedCode(QTextStream &s, const AbstractMetaClass *meta_class) | |
307 | { |
|
302 | { | |
308 | CodeSnipList code_snips = meta_class->typeEntry()->codeSnips(); |
|
303 | CodeSnipList code_snips = meta_class->typeEntry()->codeSnips(); | |
309 | foreach (const CodeSnip &cs, code_snips) { |
|
304 | foreach (const CodeSnip &cs, code_snips) { | |
310 | if (cs.language == TypeSystem::PyWrapperDeclaration) { |
|
305 | if (cs.language == TypeSystem::PyWrapperDeclaration) { | |
311 | s << cs.code() << endl; |
|
306 | s << cs.code() << endl; | |
312 | } |
|
307 | } | |
313 | } |
|
308 | } | |
314 | } |
|
309 | } |
General Comments 0
You need to be logged in to leave comments.
Login now