source: trunk/tools/designer/plugins/cppeditor/languageinterfaceimpl.cpp

Last change on this file was 197, checked in by rudi, 14 years ago

Added QtDesigner

File size: 7.2 KB
Line 
1/**********************************************************************
2**
3** Copyright (C) 2005-2007 Trolltech ASA. All rights reserved.
4**
5** This file is part of Qt Designer.
6**
7** This file may be distributed and/or modified under the terms of the
8** GNU General Public License version 2 as published by the Free Software
9** Foundation and appearing in the file LICENSE.GPL included in the
10** packaging of this file.
11**
12** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
13** licenses may use this file in accordance with the Qt Commercial License
14** Agreement provided with the Software.
15**
16** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
17** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18**
19** See http://www.trolltech.com/gpl/ for GPL licensing information.
20** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
21** information about Qt Commercial License Agreements.
22**
23** Contact info@trolltech.com if any conditions of this licensing are
24** not clear to you.
25**
26**********************************************************************/
27
28#include "languageinterfaceimpl.h"
29#include <qobject.h>
30#include <designerinterface.h>
31#include <qfile.h>
32#include "yyreg.h"
33#include <qmetaobject.h>
34
35LanguageInterfaceImpl::LanguageInterfaceImpl( QUnknownInterface *outer )
36 : parent( outer ), ref( 0 )
37{
38}
39
40ulong LanguageInterfaceImpl::addRef()
41{
42 return parent ? parent->addRef() : ref++;
43}
44
45ulong LanguageInterfaceImpl::release()
46{
47 if ( parent )
48 return parent->release();
49 if ( !--ref ) {
50 delete this;
51 return 0;
52 }
53 return ref;
54}
55
56QRESULT LanguageInterfaceImpl::queryInterface( const QUuid &uuid, QUnknownInterface** iface )
57{
58 if ( parent )
59 return parent->queryInterface( uuid, iface );
60
61 *iface = 0;
62 if ( uuid == IID_QUnknown )
63 *iface = (QUnknownInterface*)this;
64 else if ( uuid == IID_Language )
65 *iface = (LanguageInterface*)this;
66 else
67 return QE_NOINTERFACE;
68
69 (*iface)->addRef();
70 return QS_OK;
71}
72
73
74class NormalizeObject : public QObject
75{
76public:
77 NormalizeObject() : QObject() {}
78 static QCString normalizeSignalSlot( const char *signalSlot ) { return QObject::normalizeSignalSlot( signalSlot ); }
79};
80
81void LanguageInterfaceImpl::functions( const QString &code, QValueList<Function> *functionMap ) const
82{
83 QValueList<CppFunction> l;
84 extractCppFunctions( code, &l );
85 for ( QValueList<CppFunction>::Iterator it = l.begin(); it != l.end(); ++it ) {
86 Function func;
87 func.name = (*it).prototype();
88 func.name.remove( 0, (*it).returnType().length() );
89 if ( func.name.find( "::" ) == -1 )
90 continue;
91 func.name.remove( (uint)0, func.name.find( "::" ) + 2 );
92 func.body = (*it).body();
93 func.returnType = (*it).returnType();
94 func.start = (*it).functionStartLineNum();
95 func.end = (*it).closingBraceLineNum();
96 functionMap->append( func );
97 }
98}
99
100QString LanguageInterfaceImpl::createFunctionStart( const QString &className, const QString &func,
101 const QString &returnType,
102 const QString & )
103{
104 return returnType + " " + className + "::" + func;
105}
106
107QStringList LanguageInterfaceImpl::definitions() const
108{
109 QStringList lst;
110 lst << "Includes (in Implementation)" << "Includes (in Declaration)" << "Forward Declarations" << "Signals";
111 return lst;
112}
113
114QStringList LanguageInterfaceImpl::definitionEntries( const QString &definition, QUnknownInterface *designerIface ) const
115{
116 DesignerInterface *iface = 0;
117 designerIface->queryInterface( IID_Designer, (QUnknownInterface**) &iface );
118 if ( !iface )
119 return QStringList();
120 DesignerFormWindow *fw = iface->currentForm();
121 if ( !fw )
122 return QStringList();
123 QStringList lst;
124 if ( definition == "Includes (in Implementation)" ) {
125 lst = fw->implementationIncludes();
126 } else if ( definition == "Includes (in Declaration)" ) {
127 lst = fw->declarationIncludes();
128 } else if ( definition == "Forward Declarations" ) {
129 lst = fw->forwardDeclarations();
130 } else if ( definition == "Signals" ) {
131 lst = fw->signalList();
132 }
133 iface->release();
134 return lst;
135}
136
137void LanguageInterfaceImpl::setDefinitionEntries( const QString &definition, const QStringList &entries, QUnknownInterface *designerIface )
138{
139 DesignerInterface *iface = 0;
140 designerIface->queryInterface( IID_Designer, (QUnknownInterface**) &iface );
141 if ( !iface )
142 return;
143 DesignerFormWindow *fw = iface->currentForm();
144 if ( !fw )
145 return;
146 if ( definition == "Includes (in Implementation)" ) {
147 fw->setImplementationIncludes( entries );
148 } else if ( definition == "Includes (in Declaration)" ) {
149 fw->setDeclarationIncludes( entries );
150 } else if ( definition == "Forward Declarations" ) {
151 fw->setForwardDeclarations( entries );
152 } else if ( definition == "Signals" ) {
153 fw->setSignalList( entries );
154 }
155 iface->release();
156}
157
158QString LanguageInterfaceImpl::createEmptyFunction()
159{
160 return "{\n\n}\n";
161}
162
163bool LanguageInterfaceImpl::supports( Support s ) const
164{
165 if ( s == ReturnType )
166 return TRUE;
167 if ( s == ConnectionsToCustomSlots )
168 return TRUE;
169 return FALSE;
170}
171
172QStringList LanguageInterfaceImpl::fileFilterList() const
173{
174 QStringList f;
175 f << "C++ Files (*.cpp *.C *.cxx *.c++ *.c *.h *.H *.hpp *.hxx)";
176 return f;
177
178}
179QStringList LanguageInterfaceImpl::fileExtensionList() const
180{
181 QStringList f;
182 f << "cpp" << "C" << "cxx" << "c++" << "c" <<"h" << "H" << "hpp" << "hxx";
183 return f;
184}
185
186QString LanguageInterfaceImpl::projectKeyForExtension( const QString &extension ) const
187{
188 // also handle something like foo.ut.cpp
189 QString ext = extension;
190 int i = ext.findRev('.');
191 if ( i > -1 && i < (int)(ext.length()-1) )
192 ext = ext.mid( i + 1 );
193 if ( ext[ 0 ] == 'c' || ext[ 0 ] == 'C' )
194 return "SOURCES";
195 return "HEADERS";
196}
197
198void LanguageInterfaceImpl::sourceProjectKeys( QStringList &keys ) const
199{
200 keys << "HEADERS" << "SOURCES";
201}
202
203 class CheckObject : public QObject
204{
205public:
206 CheckObject() {}
207 bool checkConnectArgs( const char *signal, const char *member ) { return QObject::checkConnectArgs( signal, 0, member ); }
208
209};
210
211bool LanguageInterfaceImpl::canConnect( const QString &signal, const QString &slot )
212{
213 CheckObject o;
214 return o.checkConnectArgs( signal.latin1(), slot.latin1() );
215}
216
217void LanguageInterfaceImpl::loadFormCode( const QString &, const QString &filename,
218 QValueList<Function> &functions,
219 QStringList &,
220 QValueList<Connection> & )
221{
222 QFile f( filename );
223 if ( !f.open( IO_ReadOnly ) )
224 return;
225 QTextStream ts( &f );
226 QString code( ts.read() );
227 this->functions( code, &functions );
228}
229
230void LanguageInterfaceImpl::preferedExtensions( QMap<QString, QString> &extensionMap ) const
231{
232 extensionMap.insert( "cpp", "C++ Source File" );
233 extensionMap.insert( "h", "C++ Header File" );
234}
235
236QStrList LanguageInterfaceImpl::signalNames( QObject *obj ) const
237{
238 QStrList sigs;
239 sigs = obj->metaObject()->signalNames( TRUE );
240 sigs.remove( "destroyed()" );
241 return sigs;
242}
Note: See TracBrowser for help on using the repository browser.