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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
|
/**********************************************************************
** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
** This file is part of TQt Designer.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding valid TQt Enterprise Edition or TQt Professional Edition
** licenses may use this file in accordance with the TQt Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
** See http://www.trolltech.com/pricing.html or email [email protected] for
** information about TQt Commercial License Agreements.
**
** Contact [email protected] if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "editfunctionsimpl.h"
#include "formwindow.h"
#include "metadatabase.h"
#include "asciivalidator.h"
#include "mainwindow.h"
#include "hierarchyview.h"
#include "project.h"
#include <kiconloader.h>
#include <klineedit.h>
#include "kdevdesigner_part.h"
#include <tqlistview.h>
#include <tqpushbutton.h>
#include <tqcombobox.h>
#include <tqstrlist.h>
#include <tqmessagebox.h>
#include <tqlayout.h>
#include <tqlabel.h>
#include <tqgroupbox.h>
#include <tqheader.h>
#include <tqcheckbox.h>
#include <klocale.h>
EditFunctions::EditFunctions( TQWidget *tqparent, FormWindow *fw, bool justSlots )
: EditFunctionsBase( tqparent, 0, TRUE ), formWindow( fw )
{
connect( helpButton, TQT_SIGNAL( clicked() ), MainWindow::self, TQT_SLOT( showDialogHelp() ) );
id = 0;
functList.clear();
TQValueList<MetaDataBase::Function> functionList = MetaDataBase::functionList( TQT_TQOBJECT(fw) );
for ( TQValueList<MetaDataBase::Function>::Iterator it = functionList.begin(); it != functionList.end(); ++it ) {
TQListViewItem *i = new TQListViewItem( functionListView );
i->setPixmap( 0, SmallIcon( "designer_editslots.png" , KDevDesignerPartFactory::instance()) );
i->setText( 0, (*it).function );
i->setText( 1, (*it).returnType );
i->setText( 2, (*it).specifier );
i->setText( 3, (*it).access );
i->setText( 4, (*it).type );
FunctItem fui;
fui.id = id;
fui.oldName = (*it).function;
fui.newName = fui.oldName;
fui.oldRetTyp = (*it).returnType;
fui.retTyp = fui.oldRetTyp;
fui.oldSpec = (*it).specifier;
fui.spec = fui.oldSpec;
fui.oldAccess = (*it).access;
fui.access = fui.oldAccess;
fui.oldType = (*it).type;
fui.type = fui.oldType;
functList.append( fui );
functionIds.insert( i, id );
id++;
if ( (*it).type == "slot" ) {
if ( MetaDataBase::isSlotUsed( TQT_TQOBJECT(formWindow), MetaDataBase::normalizeFunction( (*it).function ).latin1() ) )
i->setText( 5, i18n( "Yes" ) );
else
i->setText( 5, i18n( "No" ) );
} else {
i->setText( 5, "---" );
}
}
boxProperties->setEnabled( FALSE );
functionName->setValidator( new AsciiValidator( TRUE, TQT_TQOBJECT(functionName) ) );
if ( functionListView->firstChild() )
functionListView->setCurrentItem( functionListView->firstChild() );
showOnlySlots->setChecked( justSlots );
lastType = "function";
// Enable rename for all TQListViewItems
TQListViewItemIterator lvit = functionListView->firstChild();
for ( ; *lvit; lvit++ )
(*lvit)->setRenameEnabled( 0, TRUE );
// Connect listview signal to signal-relay
TQObject::connect( functionListView,
TQT_SIGNAL( itemRenamed( TQListViewItem*, int, const TQString & ) ),
this,
TQT_SLOT( emitItemRenamed(TQListViewItem*, int, const TQString&) ) );
// Connect signal-relay to TQLineEdit "functionName"
TQObjectList *l = tqparent->queryList( TQLINEEDIT_OBJECT_NAME_STRING, "functionName" );
TQObject *obj;
TQObjectListIt itemsLineEditIt( *l );
while ( (obj = itemsLineEditIt.current()) != 0 ) {
++itemsLineEditIt;
TQObject::connect( this,
TQT_SIGNAL( itemRenamed( const TQString & ) ),
obj,
TQT_SLOT( setText( const TQString & ) ) );
}
delete l;
}
void EditFunctions::okClicked()
{
TQValueList<MetaDataBase::Function> functionList = MetaDataBase::functionList( TQT_TQOBJECT(formWindow) );
TQString n = i18n( "Add/Remove functions of '%1'" ).tqarg( formWindow->name() );
TQPtrList<Command> commands;
TQValueList<MetaDataBase::Function>::Iterator fit;
if ( !functionList.isEmpty() ) {
for ( fit = functionList.begin(); fit != functionList.end(); ++fit ) {
bool functionFound = FALSE;
TQValueList<FunctItem>::Iterator it = functList.begin();
for ( ; it != functList.end(); ++it ) {
if ( MetaDataBase::normalizeFunction( (*it).oldName ) ==
MetaDataBase::normalizeFunction( (*fit).function ) ) {
functionFound = TRUE;
break;
}
}
if ( !functionFound )
commands.append( new RemoveFunctionCommand( i18n( "Remove Function" ),
formWindow, (*fit).function, (*fit).specifier,
(*fit).access,
(*fit).type,
formWindow->project()->language(),
(*fit).returnType ) );
}
}
bool invalidFunctions = FALSE;
TQValueList<FunctItem> invalidItems;
if ( !functList.isEmpty() ) {
TQStrList lst;
TQValueList<FunctItem>::Iterator it = functList.begin();
for ( ; it != functList.end(); ++it ) {
MetaDataBase::Function function;
function.function = (*it).newName;
function.returnType = (*it).retTyp;
function.specifier = (*it).spec;
function.access = (*it).access;
function.type = (*it).type;
function.language = formWindow->project()->language();
if ( function.returnType.isEmpty() )
function.returnType = "void";
TQString s = function.function;
s = s.simplifyWhiteSpace();
bool startNum = s[ 0 ] >= '0' && s[ 0 ] <= '9';
bool noParens = s.tqcontains( '(' ) != 1 || s.tqcontains( ')' ) != 1;
bool illegalSpace = s.tqfind( ' ' ) != -1 && s.tqfind( ' ' ) < s.tqfind( '(' );
if ( startNum || noParens || illegalSpace || lst.tqfind( function.function ) != -1 ) {
invalidFunctions = TRUE;
invalidItems.append( (*it) );
continue;
}
bool functionFound = FALSE;
for ( fit = functionList.begin(); fit != functionList.end(); ++fit ) {
if ( MetaDataBase::normalizeFunction( (*fit).function ) ==
MetaDataBase::normalizeFunction( (*it).oldName ) ) {
functionFound = TRUE;
break;
}
}
if ( !functionFound )
commands.append( new AddFunctionCommand( i18n( "Add Function" ),
formWindow, function.function, function.specifier,
function.access,
function.type, formWindow->project()->language(),
function.returnType ) );
if ( MetaDataBase::normalizeFunction( (*it).newName ) != MetaDataBase::normalizeFunction( (*it).oldName ) ||
(*it).spec != (*it).oldSpec || (*it).access != (*it).oldAccess || (*it).type != (*it).oldType ||
(*it).retTyp != (*it).oldRetTyp ) {
TQString normalizedOldName = MetaDataBase::normalizeFunction( (*it).oldName );
if ((*it).oldName.endsWith("const")) // make sure we get the 'const' when we remove the old name
normalizedOldName += " const";
commands.append( new ChangeFunctionAttribCommand( i18n( "Change Function Attributes" ),
formWindow, function, normalizedOldName,
(*it).oldSpec, (*it).oldAccess, (*it).oldType,
formWindow->project()->language(), (*it).oldRetTyp ) );
}
lst.append( function.function );
}
}
if ( invalidFunctions ) {
if ( TQMessageBox::information( this, i18n( "Edit Functions" ),
i18n( "Some syntactically incorrect functions have been defined.\n"
"Remove these functions?" ), i18n( "&Yes" ), i18n( "&No" ) ) == 0 ) {
TQValueList<FunctItem>::Iterator it = functList.begin();
while ( it != functList.end() ) {
bool found = FALSE;
TQValueList<FunctItem>::Iterator vit = invalidItems.begin();
for ( ; vit != invalidItems.end(); ++vit ) {
if ( (*vit).newName == (*it).newName ) {
invalidItems.remove( vit );
found = TRUE;
break;
}
}
if ( found ) {
int delId = (*it).id;
it = functList.remove( it );
TQMap<TQListViewItem*, int>::Iterator fit = functionIds.begin();
while ( fit != functionIds.end() ) {
if ( *fit == delId ) {
TQListViewItem *litem = fit.key();
functionIds.remove( fit );
delete litem;
if ( functionListView->currentItem() )
functionListView->setSelected( functionListView->currentItem(), TRUE );
currentItemChanged( functionListView->currentItem() );
break;
}
++fit;
}
}
else
++it;
}
if ( functionListView->firstChild() ) {
functionListView->setCurrentItem( functionListView->firstChild() );
functionListView->setSelected( functionListView->firstChild(), TRUE );
}
}
formWindow->mainWindow()->objectHierarchy()->updateFormDefinitionView();
return;
}
if ( !commands.isEmpty() ) {
MacroCommand *cmd = new MacroCommand( n, formWindow, commands );
formWindow->commandHistory()->addCommand( cmd );
cmd->execute();
}
formWindow->mainWindow()->objectHierarchy()->updateFormDefinitionView();
accept();
}
void EditFunctions::functionAdd( const TQString &access, const TQString &type )
{
TQListViewItem *i = new TQListViewItem( functionListView );
i->setPixmap( 0, SmallIcon( "designer_editslots.png" , KDevDesignerPartFactory::instance()) );
i->setRenameEnabled( 0, TRUE );
i->setText( 1, "void" );
i->setText( 2, "virtual" );
if ( access.isEmpty() )
i->setText( 3, "public" );
else
i->setText( 3, access );
if( type.isEmpty() ) {
if ( showOnlySlots->isChecked() )
i->setText( 4, "slot" );
else {
i->setText( 4, lastType );
}
} else {
i->setText( 4, type );
}
if ( i->text( 4 ) == "slot" ) {
i->setText( 0, "newSlot()" );
if ( MetaDataBase::isSlotUsed( TQT_TQOBJECT(formWindow), "newSlot()" ) )
i->setText( 5, i18n( "Yes" ) );
else
i->setText( 5, i18n( "No" ) );
} else {
i->setText( 0, "newFunction()" );
i->setText( 5, "---" );
}
functionListView->setCurrentItem( i );
functionListView->setSelected( i, TRUE );
functionListView->ensureItemVisible( i );
functionName->setFocus();
functionName->selectAll();
FunctItem fui;
fui.id = id;
fui.oldName = i->text( 0 );
fui.newName = fui.oldName;
fui.oldRetTyp = i->text( 1 );
fui.retTyp = fui.oldRetTyp;
fui.oldSpec = i->text ( 2 );
fui.spec = fui.oldSpec;
fui.oldAccess = i->text( 3 );
fui.access = fui.oldAccess;
fui.oldType = i->text( 4 );
fui.type = fui.oldType;
lastType = fui.oldType;
functList.append( fui );
functionIds.insert( i, id );
id++;
}
void EditFunctions::functionRemove()
{
if ( !functionListView->currentItem() )
return;
functionListView->blockSignals( TRUE );
removedFunctions << MetaDataBase::normalizeFunction( functionListView->currentItem()->text( 0 ) );
int delId = functionIds[ functionListView->currentItem() ];
TQValueList<FunctItem>::Iterator it = functList.begin();
while ( it != functList.end() ) {
if ( (*it).id == delId ) {
functList.remove( it );
break;
}
++it;
}
functionIds.remove( functionListView->currentItem() );
delete functionListView->currentItem();
if ( functionListView->currentItem() )
functionListView->setSelected( functionListView->currentItem(), TRUE );
functionListView->blockSignals( FALSE );
currentItemChanged( functionListView->currentItem() );
}
void EditFunctions::currentItemChanged( TQListViewItem *i )
{
functionName->blockSignals( TRUE );
functionName->setText( "" );
functionAccess->setCurrentItem( 0 );
functionName->blockSignals( FALSE );
if ( !i ) {
boxProperties->setEnabled( FALSE );
return;
}
functionName->blockSignals( TRUE );
functionName->setText( i->text( 0 ) );
editType->setText( i->text( 1 ) );
TQString specifier = i->text( 2 );
TQString access = i->text( 3 );
TQString type = i->text( 4 );
if ( specifier == "pure virtual" )
functionSpecifier->setCurrentItem( 2 );
else if ( specifier == "non virtual" )
functionSpecifier->setCurrentItem( 0 );
else if ( specifier == "virtual" )
functionSpecifier->setCurrentItem( 1 );
else
functionSpecifier->setCurrentItem( 3 );
if ( access == "private" )
functionAccess->setCurrentItem( 2 );
else if ( access == "protected" )
functionAccess->setCurrentItem( 1 );
else
functionAccess->setCurrentItem( 0 );
if ( type == "slot" )
functionType->setCurrentItem( 0 );
else
functionType->setCurrentItem( 1 );
functionName->blockSignals( FALSE );
boxProperties->setEnabled( TRUE );
}
void EditFunctions::currentTextChanged( const TQString &txt )
{
if ( !functionListView->currentItem() )
return;
changeItem( functionListView->currentItem(), Name, txt );
functionListView->currentItem()->setText( 0, txt );
if ( functionListView->currentItem()->text( 4 ) == "slot" ) {
if ( MetaDataBase::isSlotUsed( TQT_TQOBJECT(formWindow), MetaDataBase::normalizeFunction( txt.latin1() ).latin1() ) )
functionListView->currentItem()->setText( 5, i18n( "Yes" ) );
else
functionListView->currentItem()->setText( 5, i18n( "No" ) );
} else {
functionListView->currentItem()->setText( 5, "---" );
}
}
void EditFunctions::currentSpecifierChanged( const TQString& s )
{
if ( !functionListView->currentItem() )
return;
changeItem( functionListView->currentItem(), Specifier, s );
functionListView->currentItem()->setText( 2, s );
}
void EditFunctions::currentAccessChanged( const TQString& a )
{
if ( !functionListView->currentItem() )
return;
changeItem( functionListView->currentItem(), Access, a );
functionListView->currentItem()->setText( 3, a );
}
void EditFunctions::currentReturnTypeChanged( const TQString &type )
{
if ( !functionListView->currentItem() )
return;
changeItem( functionListView->currentItem(), ReturnType, type );
functionListView->currentItem()->setText( 1, type );
}
void EditFunctions::currentTypeChanged( const TQString &type )
{
if ( !functionListView->currentItem() )
return;
changeItem( functionListView->currentItem(), Type, type );
lastType = type;
functionListView->currentItem()->setText( 4, type );
if ( type == "slot" ) {
if ( MetaDataBase::isSlotUsed( TQT_TQOBJECT(formWindow),
MetaDataBase::normalizeFunction( functionListView->currentItem()->text( 0 ).latin1() ).latin1() ) )
functionListView->currentItem()->setText( 5, i18n( "Yes" ) );
else
functionListView->currentItem()->setText( 5, i18n( "No" ) );
} else {
functionListView->currentItem()->setText( 5, "---" );
}
}
void EditFunctions::changeItem( TQListViewItem *item, Attribute a, const TQString &nV )
{
int itemId;
TQMap<TQListViewItem*, int>::Iterator fit = functionIds.tqfind( item );
if ( fit != functionIds.end() )
itemId = *fit;
else
return;
TQValueList<FunctItem>::Iterator it = functList.begin();
for ( ; it != functList.end(); ++it ) {
if ( (*it).id == itemId ) {
switch( a ) {
case Name:
(*it).newName = nV;
break;
case Specifier:
(*it).spec = nV;
break;
case Access:
(*it).access = nV;
break;
case ReturnType:
(*it).retTyp = nV;
break;
case Type:
(*it).type = nV;
break;
}
}
}
}
void EditFunctions::setCurrentFunction( const TQString &function )
{
TQListViewItemIterator it( functionListView );
while ( it.current() ) {
if ( MetaDataBase::normalizeFunction( it.current()->text( 0 ) ) == function ) {
functionListView->setCurrentItem( it.current() );
functionListView->setSelected( it.current(), TRUE );
currentItemChanged( it.current() );
return;
}
++it;
}
}
void EditFunctions::displaySlots( bool justSlots )
{
functionIds.clear();
functionListView->clear();
for ( TQValueList<FunctItem>::Iterator it = functList.begin(); it != functList.end(); ++it ) {
if ( (*it).type == "function" && justSlots )
continue;
TQListViewItem *i = new TQListViewItem( functionListView );
functionIds.insert( i, (*it).id );
i->setPixmap( 0, SmallIcon( "designer_editslots.png" , KDevDesignerPartFactory::instance()) );
i->setText( 0, (*it).newName );
i->setText( 1, (*it).retTyp );
i->setText( 2, (*it).spec );
i->setText( 3, (*it).access );
i->setText( 4, (*it).type );
if ( (*it).type == "slot" ) {
if ( MetaDataBase::isSlotUsed( TQT_TQOBJECT(formWindow), MetaDataBase::normalizeFunction( (*it).newName ).latin1() ) )
i->setText( 5, i18n( "Yes" ) );
else
i->setText( 5, i18n( "No" ) );
} else {
i->setText( 5, "---" );
}
}
if ( functionListView->firstChild() )
functionListView->setSelected( functionListView->firstChild(), TRUE );
}
void EditFunctions::emitItemRenamed( TQListViewItem *, int, const TQString & text )
{
emit itemRenamed( text ); // Relay signal ( to TQLineEdit )
}
|