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 "sourcetemplateinterfaceimpl.h"
|
---|
29 | #include <designerinterface.h>
|
---|
30 | #include "mainfilesettings.h"
|
---|
31 | #include <qlineedit.h>
|
---|
32 | #include <qlistbox.h>
|
---|
33 |
|
---|
34 | SourceTemplateInterfaceImpl::SourceTemplateInterfaceImpl()
|
---|
35 | {
|
---|
36 | }
|
---|
37 |
|
---|
38 | QRESULT SourceTemplateInterfaceImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
|
---|
39 | {
|
---|
40 | *iface = 0;
|
---|
41 | if ( uuid == IID_QUnknown )
|
---|
42 | *iface = (QUnknownInterface*)this;
|
---|
43 | else if ( uuid == IID_QFeatureList )
|
---|
44 | *iface = (QFeatureListInterface*)this;
|
---|
45 | else if ( uuid == IID_SourceTemplate )
|
---|
46 | *iface = (SourceTemplateInterface*)this;
|
---|
47 | else
|
---|
48 | return QE_NOINTERFACE;
|
---|
49 |
|
---|
50 | (*iface)->addRef();
|
---|
51 | return QS_OK;
|
---|
52 | }
|
---|
53 |
|
---|
54 | QStringList SourceTemplateInterfaceImpl::featureList() const
|
---|
55 | {
|
---|
56 | QStringList l;
|
---|
57 | l << "C++ Main-File (main.cpp)";
|
---|
58 | return l;
|
---|
59 | }
|
---|
60 |
|
---|
61 | static QString generateMainCppCode( const QString &formname, const QString &include )
|
---|
62 | {
|
---|
63 | QString code;
|
---|
64 | code += "#include <qapplication.h>\n";
|
---|
65 | code += "#include \"" + include + "\"\n";
|
---|
66 | code += "\n";
|
---|
67 | code += "int main( int argc, char ** argv )\n";
|
---|
68 | code += "{\n";
|
---|
69 | code += " QApplication a( argc, argv );\n";
|
---|
70 | code += " " + formname + " w;\n";
|
---|
71 | code += " w.show();\n";
|
---|
72 | code += " a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );\n";
|
---|
73 | code += " return a.exec();\n";
|
---|
74 | code += "}\n";
|
---|
75 | return code;
|
---|
76 | }
|
---|
77 |
|
---|
78 | SourceTemplateInterface::Source SourceTemplateInterfaceImpl::create( const QString &templ,
|
---|
79 | QUnknownInterface *appIface )
|
---|
80 | {
|
---|
81 | SourceTemplateInterface::Source src;
|
---|
82 | src.type = SourceTemplateInterface::Source::Invalid;
|
---|
83 | if ( templ == "C++ Main-File (main.cpp)" ) {
|
---|
84 | CppMainFile dia( 0, 0, TRUE );
|
---|
85 | dia.setup( appIface );
|
---|
86 | if ( dia.exec() == QDialog::Accepted ) {
|
---|
87 | DesignerInterface *dIface = 0;
|
---|
88 | appIface->queryInterface( IID_Designer, (QUnknownInterface**)&dIface );
|
---|
89 | if ( dIface ) {
|
---|
90 | src.type = SourceTemplateInterface::Source::FileName;
|
---|
91 | src.filename = dia.editFileName->text();
|
---|
92 | QString include = dIface->currentProject()->
|
---|
93 | formFileName( dia.listForms->text( dia.listForms->currentItem() ) );
|
---|
94 | include.remove( include.length() - 2, 2 );
|
---|
95 | include += "h";
|
---|
96 | int slashFind = include.findRev('/');
|
---|
97 | if (slashFind != -1)
|
---|
98 | include = include.mid(slashFind+1);
|
---|
99 | src.code = generateMainCppCode( dia.listForms->text( dia.listForms->currentItem() ),
|
---|
100 | include );
|
---|
101 | }
|
---|
102 | }
|
---|
103 | }
|
---|
104 | return src;
|
---|
105 | }
|
---|
106 |
|
---|
107 | QString SourceTemplateInterfaceImpl::language( const QString & ) const
|
---|
108 | {
|
---|
109 | return "C++";
|
---|
110 | }
|
---|