00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "classtooldlg.h"
00015
00016 #include <qlistbox.h>
00017 #include <qpushbutton.h>
00018 #include <qtooltip.h>
00019 #include <kdialog.h>
00020 #include <kiconloader.h>
00021 #include <klocale.h>
00022
00023 #include "kdevlanguagesupport.h"
00024 #include "classstore.h"
00025 #include "parsedclass.h"
00026 #include "classviewpart.h"
00027
00028
00029 ClassToolDialog::ClassToolDialog( ClassViewPart *part )
00030 : QWidget(0, "class tool dialog")
00031 {
00032 currentOperation = ViewNone;
00033 comboAccess = (PIAccess)-1;
00034 currentClass = 0;
00035 m_part = part;
00036
00037 class_combo = new QComboBox(false, this);
00038
00039 QPushButton *close_button = new KPushButton(KStdGuiItem::close(), this);
00040
00041 parents_button = new QToolButton(this);
00042 parents_button->setPixmap( UserIcon("CTparents", KIcon::DefaultState, ClassViewFactory::instance()) );
00043 parents_button->setToggleButton(true);
00044 parents_button->setFixedSize(parents_button->sizeHint());
00045 QToolTip::add(parents_button, i18n("Show parents"));
00046
00047 children_button = new QToolButton(this);
00048 children_button->setPixmap( UserIcon("CTchildren", KIcon::DefaultState, ClassViewFactory::instance()) );
00049 children_button->setToggleButton(true);
00050 children_button->setFixedSize(children_button->sizeHint());
00051 QToolTip::add(children_button, i18n("Show children"));
00052
00053 clients_button = new QToolButton(this);
00054 clients_button->setPixmap( UserIcon("CTclients", KIcon::DefaultState, ClassViewFactory::instance()) );
00055 clients_button->setToggleButton(true);
00056 clients_button->setFixedSize(clients_button->sizeHint());
00057 QToolTip::add(clients_button, i18n("Show clients"));
00058
00059 suppliers_button = new QToolButton(this);
00060 suppliers_button->setPixmap( UserIcon("CTsuppliers", KIcon::DefaultState, ClassViewFactory::instance()) );
00061 suppliers_button->setToggleButton(true);
00062 suppliers_button->setFixedSize(suppliers_button->sizeHint());
00063 QToolTip::add(suppliers_button, i18n("Show suppliers"));
00064
00065 methods_button = new QToolButton(this);
00066 methods_button->setPixmap( UserIcon("CVpublic_meth", KIcon::DefaultState, ClassViewFactory::instance()) );
00067 methods_button->setToggleButton(true);
00068 methods_button->setFixedSize(methods_button->sizeHint());
00069 QToolTip::add(methods_button, i18n("Show methods"));
00070
00071 attributes_button = new QToolButton(this);
00072 attributes_button->setPixmap( UserIcon("CVpublic_var", KIcon::DefaultState, ClassViewFactory::instance()) );
00073 attributes_button->setToggleButton(true);
00074 attributes_button->setFixedSize(attributes_button->sizeHint());
00075 QToolTip::add(attributes_button, i18n("Show attributes"));
00076
00077 access_combo = new QComboBox(false, this, "access combo");
00078 access_combo->setMinimumWidth(100);
00079 access_combo->setSizeLimit(10);
00080 access_combo->insertItem(i18n("member access","All"));
00081 access_combo->insertItem(i18n("member access","Public"));
00082 access_combo->insertItem(i18n("member access","Protected"));
00083 access_combo->insertItem(i18n("member access","Private"));
00084 access_combo->insertItem(i18n("member access","Package"));
00085
00086 class_tree = new ClassToolWidget(part, this);
00087
00088
00089 QVBoxLayout *layout = new QVBoxLayout(this, KDialog::marginHint(), KDialog::spacingHint());
00090 QHBoxLayout *firstrowLayout = new QHBoxLayout();
00091 QHBoxLayout *secondrowLayout = new QHBoxLayout();
00092 layout->addLayout(firstrowLayout);
00093 layout->addLayout(secondrowLayout);
00094
00095 firstrowLayout->addWidget(class_combo, 1);
00096 firstrowLayout->addWidget(close_button, 0);
00097
00098 secondrowLayout->addWidget(parents_button);
00099 secondrowLayout->addWidget(children_button);
00100 secondrowLayout->addWidget(clients_button);
00101 secondrowLayout->addWidget(suppliers_button);
00102 secondrowLayout->addStretch();
00103 secondrowLayout->addWidget(methods_button);
00104 secondrowLayout->addWidget(attributes_button);
00105 secondrowLayout->addWidget(access_combo);
00106
00107 layout->addWidget(class_tree, 10);
00108
00109 connect( class_combo, SIGNAL(activated(const QString&)),
00110 this, SLOT(slotClassComboChoice(const QString&)) );
00111 connect( close_button, SIGNAL(clicked()),
00112 this, SLOT(slotClose()) );
00113 connect( access_combo, SIGNAL(activated(const QString&)),
00114 this, SLOT(slotAccessComboChoice(const QString&)) );
00115 connect( parents_button, SIGNAL(clicked()), SLOT(viewParents()));
00116 connect( children_button, SIGNAL(clicked()), SLOT(viewChildren()));
00117 connect( clients_button, SIGNAL(clicked()), SLOT(viewClients()));
00118 connect( suppliers_button, SIGNAL(clicked()), SLOT(viewSuppliers()));
00119 connect( methods_button, SIGNAL(clicked()), SLOT(viewMethods()));
00120 connect( attributes_button, SIGNAL(clicked()), SLOT(viewAttributes()));
00121
00122 connect( part, SIGNAL(setLanguageSupport(KDevLanguageSupport*)),
00123 this, SLOT(setLanguageSupport(KDevLanguageSupport*)) );
00124
00125 m_part->registerClassToolDialog(this);
00126 }
00127
00128
00129 ClassToolDialog::~ClassToolDialog()
00130 {
00131 m_part->unregisterClassToolDialog(this);
00132 }
00133
00134
00135 void ClassToolDialog::setLanguageSupport(KDevLanguageSupport *ls)
00136 {
00137 if (ls) {
00138 disconnect(ls, 0, this, 0);
00139 connect(ls, SIGNAL(updatedSourceInfo()), this, SLOT(refresh()));
00140 } else
00141 refresh();
00142
00143 currentOperation = ViewNone;
00144 }
00145
00146
00147 void ClassToolDialog::setClassName(const QString &name)
00148 {
00149 if ( class_combo->count() == 0 ) refresh();
00150
00151 QListBox *lb = class_combo->listBox();
00152
00153 for (int i=0; i < (int)lb->count(); ++i)
00154 if (lb->text(i) == name) {
00155 class_combo->setCurrentItem(i);
00156 break;
00157 }
00158
00159 if (!name.isEmpty())
00160 currentClass = m_part->classStore()->getClassByName(name);
00161 else
00162 currentClass = 0;
00163 }
00164
00165
00166 void ClassToolDialog::viewNone()
00167 {
00168 currentOperation = ViewNone;
00169 refresh();
00170 }
00171
00172
00174 void ClassToolDialog::viewParents()
00175 {
00176 currentOperation = ViewParents;
00177 refresh();
00178 }
00179
00180
00182 void ClassToolDialog::viewChildren()
00183 {
00184 currentOperation = ViewChildren;
00185 refresh();
00186 }
00187
00188
00190 void ClassToolDialog::viewClients()
00191 {
00192 currentOperation = ViewClients;
00193 refresh();
00194 }
00195
00196
00198 void ClassToolDialog::viewSuppliers()
00199 {
00200 currentOperation = ViewSuppliers;
00201 refresh();
00202 }
00203
00204
00206 void ClassToolDialog::viewMethods()
00207 {
00208 currentOperation = ViewMethods;
00209 refresh();
00210 }
00211
00212
00214 void ClassToolDialog::viewAttributes()
00215 {
00216 currentOperation = ViewAttributes;
00217 refresh();
00218 }
00219
00220
00221 void ClassToolDialog::slotAccessComboChoice(const QString &str)
00222 {
00223 if( str == i18n("member access","All") )
00224 comboAccess = (PIAccess)-1;
00225 else if( str == i18n("member access","Public") )
00226 comboAccess = PIE_PUBLIC;
00227 else if( str == i18n("member access","Protected") )
00228 comboAccess = PIE_PROTECTED;
00229 else if( str == i18n("member access","Private") )
00230 comboAccess = PIE_PRIVATE;
00231 else if( str == i18n("member access","Package") )
00232 comboAccess = PIE_PACKAGE;
00233
00234
00235 if (currentOperation == ViewMethods || currentOperation == ViewAttributes)
00236 buildTree();
00237 }
00238
00239
00240 void ClassToolDialog::slotClose()
00241 {
00242 delete this;
00243
00244 }
00245
00246
00247 void ClassToolDialog::delayedClose()
00248 {
00249 delete this;
00250 }
00251
00252
00253 void ClassToolDialog::slotClassComboChoice(const QString &str)
00254 {
00255 setClassName(str);
00256 refresh();
00257 }
00258
00259
00260 void ClassToolDialog::refresh()
00261 {
00262
00263
00264
00265 QString oldName = class_combo->currentText();
00266
00267 class_combo->clear();
00268 QStringList list = m_part->classStore()->getSortedClassNameList();
00269 class_combo->insertStringList(list);
00270 setClassName(oldName);
00271
00272
00273 buildTree();
00274 }
00275
00276
00278 void ClassToolDialog::updateCaptionAndButtons()
00279 {
00280 QString caption;
00281 QToolButton *button;
00282
00283 switch (currentOperation)
00284 {
00285 case ViewParents:
00286 button = parents_button;
00287 caption = i18n("Parents");
00288 break;
00289 case ViewChildren:
00290 button = children_button;
00291 caption = i18n("Children");
00292 break;
00293 case ViewClients:
00294 button = clients_button;
00295 caption = i18n("Clients");
00296 break;
00297 case ViewSuppliers:
00298 button = suppliers_button;
00299 caption = i18n("Suppliers");
00300 break;
00301 case ViewMethods:
00302 button = methods_button;
00303 caption = i18n("%1 Methods").arg(access_combo->currentText());
00304 break;
00305 case ViewAttributes:
00306 button = attributes_button;
00307 caption = i18n("%1 Attributes").arg(access_combo->currentText());
00308 break;
00309 default:
00310 button = 0;
00311 caption = i18n("Class Tool Dialog");
00312 break;
00313 }
00314
00315 parents_button->setOn(false);
00316 children_button->setOn(false);
00317 clients_button->setOn(false);
00318 suppliers_button->setOn(false);
00319 methods_button->setOn(false);
00320 attributes_button->setOn(false);
00321
00322 if (button) {
00323 button->setOn(true);
00324 setCaption(i18n("%1 of Class %2").arg(caption).arg(currentClass->name()));
00325 } else
00326 setCaption(caption);
00327 }
00328
00329
00330 void ClassToolDialog::buildTree()
00331 {
00332 if (!currentClass)
00333 currentOperation = ViewNone;
00334
00335 updateCaptionAndButtons();
00336
00337 class_tree->clear();
00338
00339 switch (currentOperation)
00340 {
00341 case ViewParents:
00342 class_tree->insertClassAndClasses(currentClass, currentClass->parents);
00343 break;
00344 case ViewChildren:
00345 {
00346 QValueList<ParsedClass*> list = m_part->classStore()->getClassesByParent(currentClass->name());
00347 class_tree->insertClassAndClasses(currentClass, list);
00348 }
00349 break;
00350 case ViewClients:
00351 {
00352 QValueList<ParsedClass*> list = m_part->classStore()->getClassClients(currentClass->name());
00353 class_tree->insertClassAndClasses(currentClass, list);
00354 }
00355 break;
00356 case ViewSuppliers:
00357 {
00358 QValueList<ParsedClass*> list = m_part->classStore()->getClassSuppliers(currentClass->name());
00359 class_tree->insertClassAndClasses(currentClass, list);
00360 }
00361 break;
00362 case ViewMethods:
00363 class_tree->insertAllClassMethods(currentClass, comboAccess);
00364 break;
00365 case ViewAttributes:
00366 class_tree->insertAllClassAttributes(currentClass, comboAccess);
00367 break;
00368 default:
00369 break;
00370 }
00371 }
00372
00373 #include "classtooldlg.moc"