source: trunk/tools/designer/uic/subclassing.cpp@ 144

Last change on this file since 144 was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 12.8 KB
Line 
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Designer.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
12** licenses may use this file in accordance with the Qt Commercial License
13** Agreement provided with the Software.
14**
15** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17**
18** See http://www.trolltech.com/gpl/ for GPL licensing information.
19** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
20** information about Qt Commercial License Agreements.
21**
22** Contact info@trolltech.com if any conditions of this licensing are
23** not clear to you.
24**
25**********************************************************************/
26
27#include "uic.h"
28#include "parser.h"
29#include "widgetdatabase.h"
30#include "domtool.h"
31#include <qfile.h>
32#include <qstringlist.h>
33#include <qdatetime.h>
34#define NO_STATIC_COLORS
35#include <globaldefs.h>
36#include <qregexp.h>
37#include <stdio.h>
38#include <stdlib.h>
39
40/*!
41 Creates a declaration ( headerfile ) for a subclass \a subClass
42 of the form given in \a e
43
44 \sa createSubImpl()
45 */
46void Uic::createSubDecl( const QDomElement &e, const QString& subClass )
47{
48 QDomElement n;
49 QDomNodeList nl;
50 int i;
51
52 QString objClass = getClassName( e );
53 if ( objClass.isEmpty() )
54 return;
55
56 out << "class " << subClass << " : public " << nameOfClass << endl;
57 out << "{" << endl;
58
59/* tmake ignore Q_OBJECT */
60 out << " Q_OBJECT" << endl;
61 out << endl;
62 out << "public:" << endl;
63
64 // constructor
65 if ( objClass == "QDialog" || objClass == "QWizard" ) {
66 out << " " << subClass << "( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );" << endl;
67 } else { // standard QWidget
68 out << " " << subClass << "( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );" << endl;
69 }
70
71 // destructor
72 out << " ~" << subClass << "();" << endl;
73 out << endl;
74
75 // find additional functions
76 QStringList publicSlots, protectedSlots, privateSlots;
77 QStringList publicSlotTypes, protectedSlotTypes, privateSlotTypes;
78 QStringList publicSlotSpecifier, protectedSlotSpecifier, privateSlotSpecifier;
79 QStringList publicFuncts, protectedFuncts, privateFuncts;
80 QStringList publicFunctRetTyp, protectedFunctRetTyp, privateFunctRetTyp;
81 QStringList publicFunctSpec, protectedFunctSpec, privateFunctSpec;
82
83 nl = e.parentNode().toElement().elementsByTagName( "slot" );
84 for ( i = 0; i < (int) nl.length(); i++ ) {
85 n = nl.item(i).toElement();
86 if ( n.parentNode().toElement().tagName() != "slots"
87 && n.parentNode().toElement().tagName() != "connections" )
88 continue;
89 if ( n.attribute( "language", "C++" ) != "C++" )
90 continue;
91 QString returnType = n.attribute( "returnType", "void" );
92 QString functionName = n.firstChild().toText().data().stripWhiteSpace();
93 if ( functionName.endsWith( ";" ) )
94 functionName = functionName.left( functionName.length() - 1 );
95 QString specifier = n.attribute( "specifier" );
96 QString access = n.attribute( "access" );
97 if ( access == "protected" ) {
98 protectedSlots += functionName;
99 protectedSlotTypes += returnType;
100 protectedSlotSpecifier += specifier;
101 } else if ( access == "private" ) {
102 privateSlots += functionName;
103 privateSlotTypes += returnType;
104 privateSlotSpecifier += specifier;
105 } else {
106 publicSlots += functionName;
107 publicSlotTypes += returnType;
108 publicSlotSpecifier += specifier;
109 }
110 }
111
112 nl = e.parentNode().toElement().elementsByTagName( "function" );
113 for ( i = 0; i < (int) nl.length(); i++ ) {
114 n = nl.item(i).toElement();
115 if ( n.parentNode().toElement().tagName() != "functions" )
116 continue;
117 if ( n.attribute( "language", "C++" ) != "C++" )
118 continue;
119 QString returnType = n.attribute( "returnType", "void" );
120 QString functionName = n.firstChild().toText().data().stripWhiteSpace();
121 if ( functionName.endsWith( ";" ) )
122 functionName = functionName.left( functionName.length() - 1 );
123 QString specifier = n.attribute( "specifier" );
124 QString access = n.attribute( "access" );
125 if ( access == "protected" ) {
126 protectedFuncts += functionName;
127 protectedFunctRetTyp += returnType;
128 protectedFunctSpec += specifier;
129 } else if ( access == "private" ) {
130 privateFuncts += functionName;
131 privateFunctRetTyp += returnType;
132 privateFunctSpec += specifier;
133 } else {
134 publicFuncts += functionName;
135 publicFunctRetTyp += returnType;
136 publicFunctSpec += specifier;
137 }
138 }
139
140 if ( !publicFuncts.isEmpty() )
141 writeFunctionsSubDecl( publicFuncts, publicFunctRetTyp, publicFunctSpec );
142
143 // create public additional slots
144 if ( !publicSlots.isEmpty() ) {
145 out << "public slots:" << endl;
146 writeFunctionsSubDecl( publicSlots, publicSlotTypes, publicSlotSpecifier );
147 }
148
149 if ( !protectedFuncts.isEmpty() ) {
150 out << "protected:" << endl;
151 writeFunctionsSubDecl( protectedFuncts, protectedFunctRetTyp, protectedFunctSpec );
152 }
153
154 // create protected additional slots
155 if ( !protectedSlots.isEmpty() ) {
156 out << "protected slots:" << endl;
157 writeFunctionsSubDecl( protectedSlots, protectedSlotTypes, protectedSlotSpecifier );
158 }
159
160 if ( !privateFuncts.isEmpty() ) {
161 out << "private:" << endl;
162 writeFunctionsSubDecl( privateFuncts, privateFunctRetTyp, privateFunctSpec );
163 }
164
165 // create private additional slots
166 if ( !privateSlots.isEmpty() ) {
167 out << "private slots:" << endl;
168 writeFunctionsSubDecl( privateSlots, privateSlotTypes, privateSlotSpecifier );
169 }
170 out << "};" << endl;
171}
172
173void Uic::writeFunctionsSubDecl( const QStringList &fuLst, const QStringList &typLst, const QStringList &specLst )
174{
175 QValueListConstIterator<QString> it, it2, it3;
176 for ( it = fuLst.begin(), it2 = typLst.begin(), it3 = specLst.begin();
177 it != fuLst.end(); ++it, ++it2, ++it3 ) {
178 QString type = *it2;
179 if ( type.isEmpty() )
180 type = "void";
181 if ( *it3 == "non virtual" )
182 continue;
183 out << " " << type << " " << (*it) << ";" << endl;
184 }
185 out << endl;
186}
187
188/*!
189 Creates an implementation for a subclass \a subClass of the form
190 given in \a e
191
192 \sa createSubDecl()
193 */
194void Uic::createSubImpl( const QDomElement &e, const QString& subClass )
195{
196 QDomElement n;
197 QDomNodeList nl;
198 int i;
199
200 QString objClass = getClassName( e );
201 if ( objClass.isEmpty() )
202 return;
203
204 // constructor
205 if ( objClass == "QDialog" || objClass == "QWizard" ) {
206 out << "/* " << endl;
207 out << " * Constructs a " << subClass << " which is a child of 'parent', with the " << endl;
208 out << " * name 'name' and widget flags set to 'f' " << endl;
209 out << " *" << endl;
210 out << " * The " << objClass.mid(1).lower() << " will by default be modeless, unless you set 'modal' to" << endl;
211 out << " * TRUE to construct a modal " << objClass.mid(1).lower() << "." << endl;
212 out << " */" << endl;
213 out << subClass << "::" << subClass << "( QWidget* parent, const char* name, bool modal, WFlags fl )" << endl;
214 out << " : " << nameOfClass << "( parent, name, modal, fl )" << endl;
215 } else { // standard QWidget
216 out << "/* " << endl;
217 out << " * Constructs a " << subClass << " which is a child of 'parent', with the " << endl;
218 out << " * name 'name' and widget flags set to 'f' " << endl;
219 out << " */" << endl;
220 out << subClass << "::" << subClass << "( QWidget* parent, const char* name, WFlags fl )" << endl;
221 out << " : " << nameOfClass << "( parent, name, fl )" << endl;
222 }
223 out << "{" << endl;
224 out << "}" << endl;
225 out << endl;
226
227 // destructor
228 out << "/* " << endl;
229 out << " * Destroys the object and frees any allocated resources" << endl;
230 out << " */" << endl;
231 out << subClass << "::~" << subClass << "()" << endl;
232 out << "{" << endl;
233 out << " // no need to delete child widgets, Qt does it all for us" << endl;
234 out << "}" << endl;
235 out << endl;
236
237
238 // find additional functions
239 QStringList publicSlots, protectedSlots, privateSlots;
240 QStringList publicSlotTypes, protectedSlotTypes, privateSlotTypes;
241 QStringList publicSlotSpecifier, protectedSlotSpecifier, privateSlotSpecifier;
242 QStringList publicFuncts, protectedFuncts, privateFuncts;
243 QStringList publicFunctRetTyp, protectedFunctRetTyp, privateFunctRetTyp;
244 QStringList publicFunctSpec, protectedFunctSpec, privateFunctSpec;
245
246 nl = e.parentNode().toElement().elementsByTagName( "slot" );
247 for ( i = 0; i < (int) nl.length(); i++ ) {
248 n = nl.item(i).toElement();
249 if ( n.parentNode().toElement().tagName() != "slots"
250 && n.parentNode().toElement().tagName() != "connections" )
251 continue;
252 if ( n.attribute( "language", "C++" ) != "C++" )
253 continue;
254 QString returnType = n.attribute( "returnType", "void" );
255 QString functionName = n.firstChild().toText().data().stripWhiteSpace();
256 if ( functionName.endsWith( ";" ) )
257 functionName = functionName.left( functionName.length() - 1 );
258 QString specifier = n.attribute( "specifier" );
259 QString access = n.attribute( "access" );
260 if ( access == "protected" ) {
261 protectedSlots += functionName;
262 protectedSlotTypes += returnType;
263 protectedSlotSpecifier += specifier;
264 } else if ( access == "private" ) {
265 privateSlots += functionName;
266 privateSlotTypes += returnType;
267 privateSlotSpecifier += specifier;
268 } else {
269 publicSlots += functionName;
270 publicSlotTypes += returnType;
271 publicSlotSpecifier += specifier;
272 }
273 }
274
275 nl = e.parentNode().toElement().elementsByTagName( "function" );
276 for ( i = 0; i < (int) nl.length(); i++ ) {
277 n = nl.item(i).toElement();
278 if ( n.parentNode().toElement().tagName() != "functions" )
279 continue;
280 if ( n.attribute( "language", "C++" ) != "C++" )
281 continue;
282 QString returnType = n.attribute( "returnType", "void" );
283 QString functionName = n.firstChild().toText().data().stripWhiteSpace();
284 if ( functionName.endsWith( ";" ) )
285 functionName = functionName.left( functionName.length() - 1 );
286 QString specifier = n.attribute( "specifier" );
287 QString access = n.attribute( "access" );
288 if ( access == "protected" ) {
289 protectedFuncts += functionName;
290 protectedFunctRetTyp += returnType;
291 protectedFunctSpec += specifier;
292 } else if ( access == "private" ) {
293 privateFuncts += functionName;
294 privateFunctRetTyp += returnType;
295 privateFunctSpec += specifier;
296 } else {
297 publicFuncts += functionName;
298 publicFunctRetTyp += returnType;
299 publicFunctSpec += specifier;
300 }
301 }
302
303 if ( !publicFuncts.isEmpty() )
304 writeFunctionsSubImpl( publicFuncts, publicFunctRetTyp, publicFunctSpec, subClass, "public function" );
305
306 // create stubs for public additional slots
307 if ( !publicSlots.isEmpty() )
308 writeFunctionsSubImpl( publicSlots, publicSlotTypes, publicSlotSpecifier, subClass, "public slot" );
309
310 if ( !protectedFuncts.isEmpty() )
311 writeFunctionsSubImpl( protectedFuncts, protectedFunctRetTyp, protectedFunctSpec, subClass, "protected function" );
312
313 // create stubs for protected additional slots
314 if ( !protectedSlots.isEmpty() )
315 writeFunctionsSubImpl( protectedSlots, protectedSlotTypes, protectedSlotSpecifier, subClass, "protected slot" );
316
317 if ( !privateFuncts.isEmpty() )
318 writeFunctionsSubImpl( privateFuncts, privateFunctRetTyp, privateFunctSpec, subClass, "private function" );
319
320 // create stubs for private additional slots
321 if ( !privateSlots.isEmpty() )
322 writeFunctionsSubImpl( privateSlots, privateSlotTypes, privateSlotSpecifier, subClass, "private slot" );
323}
324
325void Uic::writeFunctionsSubImpl( const QStringList &fuLst, const QStringList &typLst, const QStringList &specLst,
326 const QString &subClass, const QString &descr )
327{
328 QValueListConstIterator<QString> it, it2, it3;
329 for ( it = fuLst.begin(), it2 = typLst.begin(), it3 = specLst.begin();
330 it != fuLst.end(); ++it, ++it2, ++it3 ) {
331 QString type = *it2;
332 if ( type.isEmpty() )
333 type = "void";
334 if ( *it3 == "non virtual" )
335 continue;
336 out << "/*" << endl;
337 out << " * " << descr << endl;
338 out << " */" << endl;
339 out << type << " " << subClass << "::" << (*it) << endl;
340 out << "{" << endl;
341 out << " qWarning( \"" << subClass << "::" << (*it) << " not yet implemented!\" );" << endl;
342 out << "}" << endl << endl;
343 }
344 out << endl;
345}
Note: See TracBrowser for help on using the repository browser.