~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to parts/classview/classtooldlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2006-05-23 18:39:42 UTC
  • Revision ID: james.westby@ubuntu.com-20060523183942-hucifbvh68k2bwz7
Tags: upstream-3.3.2
Import upstream version 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 1999 by Jonas Nordin                                    *
 
3
 *   jonas.nordin@syncom.se                                                *
 
4
 *   Copyright (C) 2000-2001 by Bernd Gehrmann                             *
 
5
 *   bernd@kdevelop.org                                                    *
 
6
 *                                                                         *
 
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.                                   *
 
11
 *                                                                         *
 
12
 ***************************************************************************/
 
13
 
 
14
#include "classtooldlg.h"
 
15
 
 
16
#include <qlistbox.h>
 
17
#include <qpushbutton.h>
 
18
#include <qtooltip.h>
 
19
#include <kdialog.h>
 
20
#include <kiconloader.h>
 
21
#include <klocale.h>
 
22
 
 
23
#include "kdevlanguagesupport.h"
 
24
#include "classstore.h"
 
25
#include "parsedclass.h"
 
26
#include "classviewpart.h"
 
27
 
 
28
 
 
29
ClassToolDialog::ClassToolDialog( ClassViewPart *part )
 
30
    : QWidget(0, "class tool dialog")
 
31
{
 
32
    currentOperation = ViewNone;
 
33
    comboAccess = (PIAccess)-1;
 
34
    currentClass = 0;
 
35
    m_part = part;
 
36
 
 
37
    class_combo = new QComboBox(false, this);
 
38
 
 
39
    QPushButton *close_button = new KPushButton(KStdGuiItem::close(), this);
 
40
 
 
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"));
 
46
 
 
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"));
 
52
 
 
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"));
 
58
 
 
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"));
 
64
 
 
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"));
 
70
 
 
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"));
 
76
 
 
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"));
 
85
 
 
86
    class_tree = new ClassToolWidget(part, this);
 
87
    //    classTree->setMinimumSize( 500, 400 );
 
88
 
 
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);
 
94
 
 
95
    firstrowLayout->addWidget(class_combo, 1);
 
96
    firstrowLayout->addWidget(close_button, 0);
 
97
 
 
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);
 
106
 
 
107
    layout->addWidget(class_tree, 10);
 
108
 
 
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()));
 
121
 
 
122
    connect( part, SIGNAL(setLanguageSupport(KDevLanguageSupport*)),
 
123
             this, SLOT(setLanguageSupport(KDevLanguageSupport*)) );
 
124
 
 
125
    m_part->registerClassToolDialog(this);
 
126
}
 
127
 
 
128
 
 
129
ClassToolDialog::~ClassToolDialog()
 
130
{
 
131
    m_part->unregisterClassToolDialog(this);
 
132
}
 
133
 
 
134
 
 
135
void ClassToolDialog::setLanguageSupport(KDevLanguageSupport *ls)
 
136
{
 
137
    if (ls) {
 
138
        disconnect(ls, 0, this, 0);
 
139
        connect(ls, SIGNAL(updatedSourceInfo()), this, SLOT(refresh()));
 
140
    } else
 
141
        refresh();
 
142
 
 
143
    currentOperation = ViewNone;
 
144
}
 
145
 
 
146
 
 
147
void ClassToolDialog::setClassName(const QString &name)
 
148
{
 
149
    if ( class_combo->count() == 0 ) refresh();
 
150
 
 
151
    QListBox *lb = class_combo->listBox();
 
152
 
 
153
    for (int i=0; i < (int)lb->count(); ++i)
 
154
        if (lb->text(i) == name) {
 
155
            class_combo->setCurrentItem(i);
 
156
            break;
 
157
        }
 
158
 
 
159
    if (!name.isEmpty())
 
160
        currentClass = m_part->classStore()->getClassByName(name);
 
161
    else
 
162
        currentClass = 0;
 
163
}
 
164
 
 
165
 
 
166
void ClassToolDialog::viewNone()
 
167
{
 
168
    currentOperation = ViewNone;
 
169
    refresh();
 
170
}
 
171
 
 
172
 
 
173
/** View the parents of the current class. */
 
174
void ClassToolDialog::viewParents()
 
175
{
 
176
    currentOperation = ViewParents;
 
177
    refresh();
 
178
}
 
179
 
 
180
 
 
181
/** View the children of the current class. */
 
182
void ClassToolDialog::viewChildren()
 
183
{
 
184
    currentOperation = ViewChildren;
 
185
    refresh();
 
186
}
 
187
 
 
188
 
 
189
/** View all classes that has this class as an attribute. */
 
190
void ClassToolDialog::viewClients()
 
191
{
 
192
    currentOperation = ViewClients;
 
193
    refresh();
 
194
}
 
195
 
 
196
 
 
197
/** View all classes that this class has as attributes. */
 
198
void ClassToolDialog::viewSuppliers()
 
199
{
 
200
    currentOperation = ViewSuppliers;
 
201
    refresh();
 
202
}
 
203
 
 
204
 
 
205
/** View methods in this class and parents. */
 
206
void ClassToolDialog::viewMethods()
 
207
{
 
208
    currentOperation = ViewMethods;
 
209
    refresh();
 
210
}
 
211
 
 
212
 
 
213
/** View attributes in this class and parents. */
 
214
void ClassToolDialog::viewAttributes()
 
215
{
 
216
    currentOperation = ViewAttributes;
 
217
    refresh();
 
218
}
 
219
 
 
220
 
 
221
void ClassToolDialog::slotAccessComboChoice(const QString &str)
 
222
{
 
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;
 
233
 
 
234
    // Update the view if the choice affected the data.
 
235
    if (currentOperation == ViewMethods || currentOperation == ViewAttributes)
 
236
        buildTree();
 
237
}
 
238
 
 
239
 
 
240
void ClassToolDialog::slotClose()
 
241
{
 
242
    delete this;
 
243
    //    QTimer::singleShot(0, this, SLOT(delayedClose()));
 
244
}
 
245
 
 
246
 
 
247
void ClassToolDialog::delayedClose()
 
248
{
 
249
    delete this;
 
250
}
 
251
 
 
252
 
 
253
void ClassToolDialog::slotClassComboChoice(const QString &str)
 
254
{
 
255
    setClassName(str);
 
256
    refresh();
 
257
}
 
258
 
 
259
 
 
260
void ClassToolDialog::refresh()
 
261
{
 
262
    // Clear the combo box and fill it with the new items.
 
263
    // Try to select the previously selected class
 
264
 
 
265
    QString oldName = class_combo->currentText();
 
266
 
 
267
    class_combo->clear();
 
268
    QStringList list = m_part->classStore()->getSortedClassNameList();
 
269
    class_combo->insertStringList(list);
 
270
    setClassName(oldName);
 
271
 
 
272
    // Rebuild the tree and caption/button state
 
273
    buildTree();
 
274
}
 
275
 
 
276
 
 
277
/** Change the caption depending on the current operation. */
 
278
void ClassToolDialog::updateCaptionAndButtons()
 
279
{
 
280
    QString caption;
 
281
    QToolButton *button;
 
282
 
 
283
    switch (currentOperation)
 
284
        {
 
285
        case ViewParents:
 
286
            button = parents_button;
 
287
            caption = i18n("Parents");
 
288
            break;
 
289
        case ViewChildren:
 
290
            button = children_button;
 
291
            caption = i18n("Children");
 
292
            break;
 
293
        case ViewClients:
 
294
            button = clients_button;
 
295
            caption = i18n("Clients");
 
296
            break;
 
297
        case ViewSuppliers:
 
298
            button = suppliers_button;
 
299
            caption = i18n("Suppliers");
 
300
            break;
 
301
        case ViewMethods:
 
302
            button = methods_button;
 
303
            caption = i18n("%1 Methods").arg(access_combo->currentText());
 
304
            break;
 
305
        case ViewAttributes:
 
306
            button = attributes_button;
 
307
            caption = i18n("%1 Attributes").arg(access_combo->currentText());
 
308
            break;
 
309
        default:
 
310
            button = 0;
 
311
            caption = i18n("Class Tool Dialog");
 
312
            break;
 
313
        }
 
314
 
 
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);
 
321
 
 
322
    if (button) {
 
323
        button->setOn(true);
 
324
        setCaption(i18n("%1 of Class %2").arg(caption).arg(currentClass->name()));
 
325
    } else
 
326
        setCaption(caption);
 
327
}
 
328
 
 
329
 
 
330
void ClassToolDialog::buildTree()
 
331
{
 
332
    if (!currentClass)
 
333
        currentOperation = ViewNone;
 
334
 
 
335
    updateCaptionAndButtons();
 
336
 
 
337
    class_tree->clear();
 
338
 
 
339
    switch (currentOperation)
 
340
        {
 
341
        case ViewParents:
 
342
            class_tree->insertClassAndClasses(currentClass, currentClass->parents);
 
343
            break;
 
344
        case ViewChildren:
 
345
            {
 
346
                QValueList<ParsedClass*> list = m_part->classStore()->getClassesByParent(currentClass->name());
 
347
                class_tree->insertClassAndClasses(currentClass, list);
 
348
            }
 
349
            break;
 
350
        case ViewClients:
 
351
            {
 
352
                QValueList<ParsedClass*> list = m_part->classStore()->getClassClients(currentClass->name());
 
353
                class_tree->insertClassAndClasses(currentClass, list);
 
354
            }
 
355
            break;
 
356
        case ViewSuppliers:
 
357
            {
 
358
                QValueList<ParsedClass*> list = m_part->classStore()->getClassSuppliers(currentClass->name());
 
359
                class_tree->insertClassAndClasses(currentClass, list);
 
360
            }
 
361
            break;
 
362
        case ViewMethods:
 
363
            class_tree->insertAllClassMethods(currentClass, comboAccess);
 
364
            break;
 
365
        case ViewAttributes:
 
366
            class_tree->insertAllClassAttributes(currentClass, comboAccess);
 
367
            break;
 
368
        default:
 
369
            break;
 
370
        }
 
371
}
 
372
 
 
373
#include "classtooldlg.moc"