1
/***************************************************************************
2
* Copyright (C) 1999 by Jonas Nordin *
3
* jonas.nordin@syncom.se *
4
* Copyright (C) 2000-2001 by Bernd Gehrmann *
7
* This program is free software; you can redistribute it and/or modify *
8
* it under the terms of the GNU General Public License as published by *
9
* the Free Software Foundation; either version 2 of the License, or *
10
* (at your option) any later version. *
12
***************************************************************************/
14
#include "classtooldlg.h"
17
#include <qpushbutton.h>
20
#include <kiconloader.h>
23
#include "kdevlanguagesupport.h"
24
#include "classstore.h"
25
#include "parsedclass.h"
26
#include "classviewpart.h"
29
ClassToolDialog::ClassToolDialog( ClassViewPart *part )
30
: QWidget(0, "class tool dialog")
32
currentOperation = ViewNone;
33
comboAccess = (PIAccess)-1;
37
class_combo = new QComboBox(false, this);
39
QPushButton *close_button = new KPushButton(KStdGuiItem::close(), this);
41
parents_button = new QToolButton(this);
42
parents_button->setPixmap( UserIcon("CTparents", KIcon::DefaultState, ClassViewFactory::instance()) );
43
parents_button->setToggleButton(true);
44
parents_button->setFixedSize(parents_button->sizeHint());
45
QToolTip::add(parents_button, i18n("Show parents"));
47
children_button = new QToolButton(this);
48
children_button->setPixmap( UserIcon("CTchildren", KIcon::DefaultState, ClassViewFactory::instance()) );
49
children_button->setToggleButton(true);
50
children_button->setFixedSize(children_button->sizeHint());
51
QToolTip::add(children_button, i18n("Show children"));
53
clients_button = new QToolButton(this);
54
clients_button->setPixmap( UserIcon("CTclients", KIcon::DefaultState, ClassViewFactory::instance()) );
55
clients_button->setToggleButton(true);
56
clients_button->setFixedSize(clients_button->sizeHint());
57
QToolTip::add(clients_button, i18n("Show clients"));
59
suppliers_button = new QToolButton(this);
60
suppliers_button->setPixmap( UserIcon("CTsuppliers", KIcon::DefaultState, ClassViewFactory::instance()) );
61
suppliers_button->setToggleButton(true);
62
suppliers_button->setFixedSize(suppliers_button->sizeHint());
63
QToolTip::add(suppliers_button, i18n("Show suppliers"));
65
methods_button = new QToolButton(this);
66
methods_button->setPixmap( UserIcon("CVpublic_meth", KIcon::DefaultState, ClassViewFactory::instance()) );
67
methods_button->setToggleButton(true);
68
methods_button->setFixedSize(methods_button->sizeHint());
69
QToolTip::add(methods_button, i18n("Show methods"));
71
attributes_button = new QToolButton(this);
72
attributes_button->setPixmap( UserIcon("CVpublic_var", KIcon::DefaultState, ClassViewFactory::instance()) );
73
attributes_button->setToggleButton(true);
74
attributes_button->setFixedSize(attributes_button->sizeHint());
75
QToolTip::add(attributes_button, i18n("Show attributes"));
77
access_combo = new QComboBox(false, this, "access combo");
78
access_combo->setMinimumWidth(100);
79
access_combo->setSizeLimit(10);
80
access_combo->insertItem(i18n("member access","All"));
81
access_combo->insertItem(i18n("member access","Public"));
82
access_combo->insertItem(i18n("member access","Protected"));
83
access_combo->insertItem(i18n("member access","Private"));
84
access_combo->insertItem(i18n("member access","Package"));
86
class_tree = new ClassToolWidget(part, this);
87
// classTree->setMinimumSize( 500, 400 );
89
QVBoxLayout *layout = new QVBoxLayout(this, KDialog::marginHint(), KDialog::spacingHint());
90
QHBoxLayout *firstrowLayout = new QHBoxLayout();
91
QHBoxLayout *secondrowLayout = new QHBoxLayout();
92
layout->addLayout(firstrowLayout);
93
layout->addLayout(secondrowLayout);
95
firstrowLayout->addWidget(class_combo, 1);
96
firstrowLayout->addWidget(close_button, 0);
98
secondrowLayout->addWidget(parents_button);
99
secondrowLayout->addWidget(children_button);
100
secondrowLayout->addWidget(clients_button);
101
secondrowLayout->addWidget(suppliers_button);
102
secondrowLayout->addStretch();
103
secondrowLayout->addWidget(methods_button);
104
secondrowLayout->addWidget(attributes_button);
105
secondrowLayout->addWidget(access_combo);
107
layout->addWidget(class_tree, 10);
109
connect( class_combo, SIGNAL(activated(const QString&)),
110
this, SLOT(slotClassComboChoice(const QString&)) );
111
connect( close_button, SIGNAL(clicked()),
112
this, SLOT(slotClose()) );
113
connect( access_combo, SIGNAL(activated(const QString&)),
114
this, SLOT(slotAccessComboChoice(const QString&)) );
115
connect( parents_button, SIGNAL(clicked()), SLOT(viewParents()));
116
connect( children_button, SIGNAL(clicked()), SLOT(viewChildren()));
117
connect( clients_button, SIGNAL(clicked()), SLOT(viewClients()));
118
connect( suppliers_button, SIGNAL(clicked()), SLOT(viewSuppliers()));
119
connect( methods_button, SIGNAL(clicked()), SLOT(viewMethods()));
120
connect( attributes_button, SIGNAL(clicked()), SLOT(viewAttributes()));
122
connect( part, SIGNAL(setLanguageSupport(KDevLanguageSupport*)),
123
this, SLOT(setLanguageSupport(KDevLanguageSupport*)) );
125
m_part->registerClassToolDialog(this);
129
ClassToolDialog::~ClassToolDialog()
131
m_part->unregisterClassToolDialog(this);
135
void ClassToolDialog::setLanguageSupport(KDevLanguageSupport *ls)
138
disconnect(ls, 0, this, 0);
139
connect(ls, SIGNAL(updatedSourceInfo()), this, SLOT(refresh()));
143
currentOperation = ViewNone;
147
void ClassToolDialog::setClassName(const QString &name)
149
if ( class_combo->count() == 0 ) refresh();
151
QListBox *lb = class_combo->listBox();
153
for (int i=0; i < (int)lb->count(); ++i)
154
if (lb->text(i) == name) {
155
class_combo->setCurrentItem(i);
160
currentClass = m_part->classStore()->getClassByName(name);
166
void ClassToolDialog::viewNone()
168
currentOperation = ViewNone;
173
/** View the parents of the current class. */
174
void ClassToolDialog::viewParents()
176
currentOperation = ViewParents;
181
/** View the children of the current class. */
182
void ClassToolDialog::viewChildren()
184
currentOperation = ViewChildren;
189
/** View all classes that has this class as an attribute. */
190
void ClassToolDialog::viewClients()
192
currentOperation = ViewClients;
197
/** View all classes that this class has as attributes. */
198
void ClassToolDialog::viewSuppliers()
200
currentOperation = ViewSuppliers;
205
/** View methods in this class and parents. */
206
void ClassToolDialog::viewMethods()
208
currentOperation = ViewMethods;
213
/** View attributes in this class and parents. */
214
void ClassToolDialog::viewAttributes()
216
currentOperation = ViewAttributes;
221
void ClassToolDialog::slotAccessComboChoice(const QString &str)
223
if( str == i18n("member access","All") )
224
comboAccess = (PIAccess)-1;
225
else if( str == i18n("member access","Public") )
226
comboAccess = PIE_PUBLIC;
227
else if( str == i18n("member access","Protected") )
228
comboAccess = PIE_PROTECTED;
229
else if( str == i18n("member access","Private") )
230
comboAccess = PIE_PRIVATE;
231
else if( str == i18n("member access","Package") )
232
comboAccess = PIE_PACKAGE;
234
// Update the view if the choice affected the data.
235
if (currentOperation == ViewMethods || currentOperation == ViewAttributes)
240
void ClassToolDialog::slotClose()
243
// QTimer::singleShot(0, this, SLOT(delayedClose()));
247
void ClassToolDialog::delayedClose()
253
void ClassToolDialog::slotClassComboChoice(const QString &str)
260
void ClassToolDialog::refresh()
262
// Clear the combo box and fill it with the new items.
263
// Try to select the previously selected class
265
QString oldName = class_combo->currentText();
267
class_combo->clear();
268
QStringList list = m_part->classStore()->getSortedClassNameList();
269
class_combo->insertStringList(list);
270
setClassName(oldName);
272
// Rebuild the tree and caption/button state
277
/** Change the caption depending on the current operation. */
278
void ClassToolDialog::updateCaptionAndButtons()
283
switch (currentOperation)
286
button = parents_button;
287
caption = i18n("Parents");
290
button = children_button;
291
caption = i18n("Children");
294
button = clients_button;
295
caption = i18n("Clients");
298
button = suppliers_button;
299
caption = i18n("Suppliers");
302
button = methods_button;
303
caption = i18n("%1 Methods").arg(access_combo->currentText());
306
button = attributes_button;
307
caption = i18n("%1 Attributes").arg(access_combo->currentText());
311
caption = i18n("Class Tool Dialog");
315
parents_button->setOn(false);
316
children_button->setOn(false);
317
clients_button->setOn(false);
318
suppliers_button->setOn(false);
319
methods_button->setOn(false);
320
attributes_button->setOn(false);
324
setCaption(i18n("%1 of Class %2").arg(caption).arg(currentClass->name()));
330
void ClassToolDialog::buildTree()
333
currentOperation = ViewNone;
335
updateCaptionAndButtons();
339
switch (currentOperation)
342
class_tree->insertClassAndClasses(currentClass, currentClass->parents);
346
QValueList<ParsedClass*> list = m_part->classStore()->getClassesByParent(currentClass->name());
347
class_tree->insertClassAndClasses(currentClass, list);
352
QValueList<ParsedClass*> list = m_part->classStore()->getClassClients(currentClass->name());
353
class_tree->insertClassAndClasses(currentClass, list);
358
QValueList<ParsedClass*> list = m_part->classStore()->getClassSuppliers(currentClass->name());
359
class_tree->insertClassAndClasses(currentClass, list);
363
class_tree->insertAllClassMethods(currentClass, comboAccess);
366
class_tree->insertAllClassAttributes(currentClass, comboAccess);
373
#include "classtooldlg.moc"