summaryrefslogtreecommitdiffstats
path: root/languages/cpp/cppnewclassdlg.h
blob: 30aed9e49058e8b2928598d5a9698234a0c88f0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/***************************************************************************
*   Copyright (C) 1998 by Sandy Meier                                     *
*   [email protected]                                              *
*   Copyright (C) 2002 by Bernd Gehrmann                                  *
*   [email protected]                                                    *
*   Copyright (C) 2003 by Alexander Dymo                                  *
*   [email protected]                                                 *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
***************************************************************************/

#ifndef _CPPNEWCLASSDLG_H_
#define _CPPNEWCLASSDLG_H_

#include <tqlineedit.h>
#include <tqlistview.h>
#include <tqwidgetstack.h>

#include "codemodel.h"
#include "cppnewclassdlgbase.h"

class CppSupportPart;
class TDevProject;
class TQPopupMenu;
class TDECompletion;
class CodeModel;


template <class T>
class PCheckListItem: public TQCheckListItem
{
public:

	PCheckListItem ( T item, TQCheckListItem * parent, const TQString & text, Type tt = Controller ) :
			TQCheckListItem ( parent, text, tt ), m_item( item )
	{}

	PCheckListItem ( T item, TQCheckListItem * parent, TQListViewItem * after, const TQString & text, Type tt = Controller ) :
			TQCheckListItem ( parent, after, text, tt ), m_item( item )
	{}

	PCheckListItem ( T item, TQListViewItem * parent, const TQString & text, Type tt = Controller ) :
			TQCheckListItem ( parent, text, tt ), m_item( item )
	{}

	PCheckListItem ( T item, TQListViewItem * parent, TQListViewItem * after, const TQString & text, Type tt = Controller ) :
			TQCheckListItem ( parent, after, text, tt ), m_item( item )
	{}

	PCheckListItem ( T item, TQListView * parent, const TQString & text, Type tt = Controller ) :
			TQCheckListItem ( parent, text, tt ), m_item( item )
	{}

	PCheckListItem ( T item, TQListView * parent, TQListViewItem * after, const TQString & text, Type tt = Controller ) :
			TQCheckListItem ( parent, after, text, tt ), m_item( item )
	{}

	PCheckListItem ( T item, TQListViewItem * parent, const TQString & text, const TQPixmap & p ) :
			TQCheckListItem ( parent, text, p ), m_item( item )
	{}

	PCheckListItem ( T item, TQListView * parent, const TQString & text, const TQPixmap & p ) :
			TQCheckListItem ( parent, text, p ), m_item( item )
	{}

	T item()
	{
		return m_item;
	}

	TQString templateAddition;

private:
	T m_item;
};

template <class T>
class PListViewItem: public TQListViewItem
{
public:

	PListViewItem ( T item, TQListViewItem * parent, TQListViewItem * after, const TQString & text ) :
			TQListViewItem ( parent, after, text ), m_item( item )
	{}

	PListViewItem ( T item, TQListViewItem * parent, const TQString & text ) :
			TQListViewItem ( parent, text ), m_item( item )
	{}

	PListViewItem ( T item, TQListView * parent, const TQString & text ) :
			TQListViewItem ( parent, text ), m_item( item )
	{}

	PListViewItem ( T item, TQListView * parent, TQListViewItem * after, const TQString & text ) :
			TQListViewItem ( parent, after, text ), m_item( item )
	{}

	T item()
	{
		return m_item;
	}

	TQString templateAddition;
private:
	T m_item;
};


class CppNewClassDialog : public CppNewClassDialogBase
{
	Q_OBJECT
  

public:
	CppNewClassDialog( CppSupportPart *part, TQWidget *parent = 0, const char *name = 0 );
	~CppNewClassDialog();

protected:
	virtual void accept();
	virtual void classNameChanged( const TQString &text );
	virtual void classNamespaceChanged( const TQString &text );
	virtual void headerChanged();
	virtual void implementationChanged();
	virtual void nameHandlerChanged( const TQString &text );
	virtual void baseclassname_changed( const TQString &text );
	virtual void baseIncludeChanged( const TQString &text );

	virtual void addBaseClass();
	virtual void remBaseClass();
	virtual void remBaseClassOnly();
	virtual void currBaseNameChanged( const TQString &text );
	virtual void currBasePrivateSet();
	virtual void currBaseProtectedSet();
	virtual void currBasePublicSet();
	virtual void currBaseVirtualChanged( int val );
	virtual void currBaseSelected( TQListViewItem *it );
	virtual void scopeboxActivated( int value );

	virtual void checkObjCInheritance( int val );
	virtual void checkTQWidgetInheritance( int val );

	virtual void upbaseclass_button_clicked();
	virtual void downbaseclass_button_clicked();
	virtual void baseclasses_view_selectionChanged();

	virtual void newTabSelected( const TQString &text );
	virtual void newTabSelected( TQWidget *w );
	virtual void access_view_mouseButtonPressed( int button, TQListViewItem * item, const TQPoint &p, int c );
	virtual void changeToPrivate();
	virtual void changeToProtected();
	virtual void changeToPublic();
	virtual void changeToInherited();
	virtual void methods_view_mouseButtonPressed( int button , TQListViewItem * item, const TQPoint&p , int c );
	virtual void extendFunctionality();
	virtual void replaceFunctionality();
	virtual void to_constructors_list_clicked();
	virtual void clear_selection_button_clicked();
	virtual void selectall_button_clicked();
	virtual void gtk_box_stateChanged( int val );
	virtual void qobject_box_stateChanged( int val );
	virtual void headeronly_box_stateChanged(int val);

	void reloadAdvancedInheritance( bool clean = false );
	void parseClass( TQString clName, TQString inheritance );
	void parsePCSClass( TQString clName, TQString inheritance );
	void addToConstructorsList( TQCheckListItem *myClass, FunctionDom method );
	void addToMethodsList( TQListViewItem *parent, FunctionDom method );
	void addToUpgradeList( TQListViewItem *parent, FunctionDom method, TQString modifier );
	void addToUpgradeList( TQListViewItem *parent, VariableDom attr, TQString modifier );
	void clearConstructorsList( bool clean = false );
	void clearMethodsList( bool clean = false );
	void clearUpgradeList( bool clean = false );
	bool isConstructor( TQString className, const FunctionDom &method );
	bool isDestructor( TQString className, const FunctionDom &method );

private:

	bool headerModified;
	bool baseincludeModified;
	bool implementationModified;
	TQString m_parse;
	TQPopupMenu *accessMenu;
	TQPopupMenu *overMenu;
	CppSupportPart *m_part;
	CodeModel *myModel;

	// configuration variables
	TQString interface_url;
	TQString implementation_url;
	TQString interface_suffix;
	TQString implementation_suffix;
	TQStringList currNamespace;
	bool lowercase_filenames;
	TQStringList currBaseClasses;
	TDECompletion * compBasename;
	TDECompletion * compNamespace;

	void setCompletionBasename( CodeModel *model );
	void addCompletionBasenameNamespacesRecursive( const NamespaceDom & namespaceDom, const TQString & namespaceParent = "" );
	void setCompletionNamespaceRecursive( const NamespaceDom & namespaceDom, const TQString & namespaceParent = "" );
	void setStateOfInheritanceEditors( bool state, bool hideList = true );
	void setAccessForBase( TQString baseclass, TQString newAccess );
	void setAccessForItem( TQListViewItem *curr, TQString newAccess, bool isPublic );
	void remClassFromAdv( TQString text );
	void checkUpButtonState();
	void checkDownButtonState();
	void updateConstructorsOrder();

	TQString classNameFormatted();
	TQString templateStrFormatted();
	TQString templateParamsFormatted();
	TQString classNameFormatted( const TQString & );
	TQString templateStrFormatted( const TQString & );
	TQString templateParamsFormatted( const TQString & );
	TQString templateActualParamsFormatted( const TQString & );
	void removeTemplateParams( TQString & );

	friend class ClassGenerator;

	//! The class that translates UI input to a class
	class ClassGenerator
	{

	public:
		ClassGenerator( CppNewClassDialog& _dlg ) : dlg( _dlg )
		{}
		bool generate();

	private:
		bool validateInput();
		void common_text();
		void gen_implementation();
		void gen_interface();
		void genMethodDeclaration( FunctionDom method, TQString className, TQString templateStr,
		                           TQString *adv_h, TQString *adv_cpp, bool extend, TQString baseClassName );

		void beautifyHeader( TQString &templ, TQString &headerGuard,
		                     TQString &includeBaseHeader, TQString &author, TQString &doc, TQString &className, TQString &templateStr,
		                     TQString &baseclass, TQString &inheritance, TQString &qobjectStr, TQString &args,
		                     TQString &header, TQString &namespaceBeg, TQString &constructors, TQString &advH_public,
		                     TQString &advH_public_slots,
		                     TQString &advH_protected, TQString &advH_protected_slots, TQString &advH_private, TQString &advH_private_slots,
		                     TQString &namespaceEnd );
		void beautifySource( TQString &templ, TQString &header, TQString &className, TQString &namespaceBeg,
		                     TQString &constructors, TQString &advCpp, TQString &namespaceEnd, TQString &implementation );

		TQString className;
		TQString templateStr;
		TQString templateParams;
		TQString header;
		TQString implementation;

		TQString advConstructorsHeader;
		TQString advConstructorsSource;

		TDevProject *project;
		TQString subDir, headerPath, implementationPath;
		TQString doc;
		TQString namespaceStr;
		bool childClass;
		bool objc;
		bool qobject;
		bool gtk;
		bool headeronly;
		TQStringList namespaces;
		TQString namespaceBeg, namespaceEnd;
		TQString argsH;
		TQString argsCpp;

		TQString advH_public;
		TQString advH_public_slots;
		TQString advH_protected;
		TQString advH_protected_slots;
		TQString advH_private;
		TQString advH_private_slots;
		TQString advCpp;


		CppNewClassDialog& dlg;
	};


	//! workaround to make gcc 2.95.x happy
	friend class CppNewClassDialog::ClassGenerator;
};

#endif 
// kate: indent-mode csands; tab-width 4;