add bindings for QGraphicsSceneDragDropEvent
[qtscriptgenerator.git] / generator / shellgenerator.cpp
blobceae238674da96314f30b52fad77b043700daa44
1 /****************************************************************************
2 **
3 ** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
4 **
5 ** This file is part of the Qt Script Generator project on Trolltech Labs.
6 **
7 ** This file may be used under the terms of the GNU General Public
8 ** License version 2.0 as published by the Free Software Foundation
9 ** and appearing in the file LICENSE.GPL included in the packaging of
10 ** this file. Please review the following information to ensure GNU
11 ** General Public Licensing requirements will be met:
12 ** http://www.trolltech.com/products/qt/opensource.html
14 ** If you are unsure which license is appropriate for your use, please
15 ** review the following information:
16 ** http://www.trolltech.com/products/qt/licensing.html or contact the
17 ** sales department at sales@trolltech.com.
19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 ****************************************************************************/
24 #include "shellgenerator.h"
25 #include "reporthandler.h"
27 #include "metaqtscript.h"
29 bool ShellGenerator::shouldGenerate(const AbstractMetaClass *meta_class) const
31 uint cg = meta_class->typeEntry()->codeGeneration();
32 return ((cg & TypeEntry::GenerateCode) != 0) && meta_class->generateShellClass();
35 void ShellGenerator::writeTypeInfo(QTextStream &s, const AbstractMetaType *type, Option options)
37 if ((options & OriginalTypeDescription) && !type->originalTypeDescription().isEmpty()) {
38 s << type->originalTypeDescription();
39 return;
42 if (type->isArray()) {
43 writeTypeInfo(s, type->arrayElementType(), options);
44 if (options & ArrayAsPointer) {
45 s << "*";
46 } else {
47 s << "[" << type->arrayElementCount() << "]";
49 return;
52 const TypeEntry *te = type->typeEntry();
54 if (type->isConstant() && !(options & ExcludeConst))
55 s << "const ";
57 if ((options & EnumAsInts) && (te->isEnum() || te->isFlags())) {
58 s << "int";
59 } else if (te->isFlags()) {
60 s << ((FlagsTypeEntry *) te)->originalName();
61 } else {
62 s << fixCppTypeName(te->qualifiedCppName());
65 if (type->instantiations().size() > 0
66 && (!type->isContainer()
67 || (static_cast<const ContainerTypeEntry *>(te))->type() != ContainerTypeEntry::StringListContainer)) {
68 s << '<';
69 QList<AbstractMetaType *> args = type->instantiations();
70 bool nested_template = false;
71 for (int i=0; i<args.size(); ++i) {
72 if (i != 0)
73 s << ", ";
74 nested_template |= args.at(i)->isContainer();
75 writeTypeInfo(s, args.at(i));
77 if (nested_template)
78 s << ' ';
79 s << '>';
82 s << QString(type->indirections(), '*');
84 if (type->isReference() && !(options & ExcludeReference))
85 s << "&";
87 if (!(options & SkipName))
88 s << ' ';
92 void ShellGenerator::writeFunctionArguments(QTextStream &s,
93 const AbstractMetaArgumentList &arguments,
94 Option option,
95 int numArguments)
97 if (numArguments < 0) numArguments = arguments.size();
99 for (int i=0; i<numArguments; ++i) {
100 if (i != 0)
101 s << ", ";
102 AbstractMetaArgument *arg = arguments.at(i);
103 writeTypeInfo(s, arg->type(), option);
104 if (!(option & SkipName))
105 s << " " << arg->argumentName();
106 if ((option & IncludeDefaultExpression) && !arg->originalDefaultValueExpression().isEmpty()) {
107 s << " = ";
109 QString expr = arg->originalDefaultValueExpression();
110 if (arg->type()->typeEntry()->isEnum() && expr.indexOf("::") < 0)
111 s << ((EnumTypeEntry *)arg->type()->typeEntry())->qualifier() << "::";
113 s << expr;
119 * Writes the function \a meta_function signature to the textstream \a s.
121 * The \a name_prefix can be used to give the function name a prefix,
122 * like "__public_" or "__override_" and \a classname_prefix can
123 * be used to give the class name a prefix.
125 * The \a option flags can be used to tweak various parameters, such as
126 * showing static, original vs renamed name, underscores for space etc.
128 * The \a extra_arguments list is a list of extra arguments on the
129 * form "bool static_call".
132 void ShellGenerator::writeFunctionSignature(QTextStream &s,
133 const AbstractMetaFunction *meta_function,
134 const AbstractMetaClass *implementor,
135 const QString &name_prefix,
136 Option option,
137 const QString &classname_prefix,
138 const QStringList &extra_arguments,
139 int numArguments)
141 // ### remove the implementor
142 AbstractMetaType *function_type = meta_function->type();
144 if (meta_function->isStatic() && (option & ShowStatic))
145 s << "static ";
147 if ((option & SkipReturnType) == 0) {
148 if (function_type) {
149 writeTypeInfo(s, function_type, option);
150 s << " ";
151 } else if (!meta_function->isConstructor()) {
152 s << "void ";
156 if (implementor) {
157 if (classname_prefix.isEmpty())
158 s << shellClassName(implementor) << "::";
159 else
160 s << classname_prefix << implementor->name() << "::";
164 QString function_name;
165 if (option & OriginalName)
166 function_name = meta_function->originalName();
167 else
168 function_name = meta_function->name();
170 if (option & UnderscoreSpaces)
171 function_name = function_name.replace(' ', '_');
173 if (meta_function->isConstructor())
174 function_name = shellClassName(meta_function->ownerClass());
176 s << name_prefix << function_name;
178 if (meta_function->attributes() & AbstractMetaAttributes::SetterFunction)
179 s << "_setter";
180 else if (meta_function->attributes() & AbstractMetaAttributes::GetterFunction)
181 s << "_getter";
183 s << "(";
185 writeFunctionArguments(s, meta_function->arguments(), option, numArguments);
187 // The extra arguments...
188 for (int i=0; i<extra_arguments.size(); ++i) {
189 if (i > 0 || meta_function->arguments().size() != 0)
190 s << ", ";
191 s << extra_arguments.at(i);
194 s << ")";
195 if (meta_function->isConstant())
196 s << " const";