KDevelop API Documentation

parts/quickopen/quickopenclassdialog.cpp

Go to the documentation of this file.
00001 /* 00002 * Copyright (C) 2003 Roberto Raggi (roberto@kdevelop.org) 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2 of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Library General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; see the file COPYING.LIB. If not, write to 00016 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 * Boston, MA 02111-1307, USA. 00018 * 00019 */ 00020 00021 #include "quickopenclassdialog.h" 00022 #include "quickopen_part.h" 00023 00024 #include <kdevproject.h> 00025 #include <kdevpartcontroller.h> 00026 00027 #include "doclineedit.h" 00028 00029 #include <klistbox.h> 00030 #include <klocale.h> 00031 #include <kdebug.h> 00032 00033 #include <qregexp.h> 00034 #include <qlabel.h> 00035 00036 #if QT_VERSION < 0x030100 00037 /* original source from qt-3.2.1/src/widgets/qlistbox.cpp 00038 QListBoxItem* QListBox::selectedItem() const 00039 { 00040 if ( d->selectionMode != Single ) 00041 return 0; 00042 if ( isSelected( currentItem() ) ) 00043 return d->current; 00044 return 0; 00045 } 00046 */ 00047 QListBoxItem* QListBox_selectedItem(QListBox* cpQListBox) 00048 { 00049 if ( cpQListBox->selectionMode() != QListBox::Single ) 00050 return 0; 00051 if ( cpQListBox->isSelected( cpQListBox->currentItem() ) ) 00052 return cpQListBox->item(cpQListBox->currentItem()); 00053 return 0; 00054 } 00055 #endif 00056 00057 00058 QuickOpenClassDialog::QuickOpenClassDialog(QuickOpenPart* part, QWidget* parent, const char* name, bool modal, WFlags fl) 00059 : QuickOpenDialogBase( parent, name, modal, fl ), m_part( part ) 00060 { 00061 nameLabel->setText( i18n("Class &name:") ); 00062 itemListLabel->setText( i18n("Class &list:") ); 00063 00064 findAllClasses( m_classList ); 00065 qHeapSort( m_classList ); 00066 00067 m_completion = new KCompletion(); 00068 m_completion->insertItems( m_classList ); 00069 m_completion->setIgnoreCase( true ); 00070 00071 nameEdit->setFocus(); 00072 00073 itemList->insertStringList( m_classList ); 00074 itemList->setCurrentItem(0); 00075 00076 connect(nameEdit, SIGNAL(upPressed()), this, SLOT(moveUpInList())); 00077 connect(nameEdit, SIGNAL(downPressed()), this, SLOT(moveDownInList())); 00078 connect(nameEdit, SIGNAL(pgupPressed()), this, SLOT(scrollUpInList())); 00079 connect(nameEdit, SIGNAL(pgdownPressed()), this, SLOT(scrollDownInList())); 00080 connect(nameEdit, SIGNAL(homePressed()), this, SLOT(goToBegin())); 00081 connect(nameEdit, SIGNAL(endPressed()), this, SLOT(goToEnd())); 00082 } 00083 00084 QuickOpenClassDialog::~QuickOpenClassDialog() 00085 { 00086 delete( m_completion ); 00087 m_completion = 0; 00088 } 00089 00090 /*$SPECIALIZATION$*/ 00091 void QuickOpenClassDialog::slotExecuted( QListBoxItem* /*item*/ ) 00092 { 00093 accept(); 00094 } 00095 00096 void QuickOpenClassDialog::reject() 00097 { 00098 QDialog::reject(); 00099 } 00100 00101 void QuickOpenClassDialog::accept() 00102 { 00103 #if QT_VERSION >= 0x030100 00104 if( QListBoxItem* item = itemList->selectedItem() ) 00105 #else 00106 if( QListBoxItem* item = QListBox_selectedItem(itemList) ) 00107 #endif 00108 { 00109 ClassDom klass = findClass( item->text() ); 00110 if( klass ) 00111 { 00112 int startLine, startColumn; 00113 klass->getStartPosition( &startLine, &startColumn ); 00114 m_part->partController()->editDocument( klass->fileName(), startLine ); 00115 } 00116 } 00117 00118 QDialog::accept(); 00119 } 00120 00121 void QuickOpenClassDialog::slotReturnPressed( ) 00122 { 00123 accept(); 00124 } 00125 00126 void QuickOpenClassDialog::slotTextChanged( const QString & text ) 00127 { 00128 itemList->clear(); 00129 itemList->insertStringList( m_completion->substringCompletion(text) ); 00130 itemList->setCurrentItem(0); 00131 } 00132 00133 void QuickOpenClassDialog::moveUpInList( ) 00134 { 00135 if (itemList->currentItem() == -1) 00136 itemList->setCurrentItem(itemList->count() - 1); 00137 else 00138 itemList->setCurrentItem(itemList->currentItem() - 1); 00139 itemList->ensureCurrentVisible(); 00140 } 00141 00142 void QuickOpenClassDialog::moveDownInList( ) 00143 { 00144 if (itemList->currentItem() == -1) 00145 itemList->setCurrentItem(0); 00146 else 00147 itemList->setCurrentItem(itemList->currentItem() + 1); 00148 itemList->ensureCurrentVisible(); 00149 } 00150 00151 void QuickOpenClassDialog::scrollUpInList( ) 00152 { 00153 if (itemList->currentItem() == -1) 00154 itemList->setCurrentItem(itemList->count() - 1); 00155 else 00156 itemList->setCurrentItem(itemList->currentItem() - (itemList->numItemsVisible()-1)); 00157 itemList->ensureCurrentVisible(); 00158 } 00159 00160 void QuickOpenClassDialog::scrollDownInList( ) 00161 { 00162 if (itemList->currentItem() == -1) 00163 itemList->setCurrentItem(0); 00164 else 00165 itemList->setCurrentItem(itemList->currentItem() + (itemList->numItemsVisible()-1)); 00166 itemList->ensureCurrentVisible(); 00167 } 00168 00169 void QuickOpenClassDialog::goToBegin( ) 00170 { 00171 itemList->setCurrentItem(0); 00172 } 00173 00174 void QuickOpenClassDialog::goToEnd( ) 00175 { 00176 itemList->setCurrentItem(itemList->count()-1); 00177 } 00178 00179 void QuickOpenClassDialog::findAllClasses( QStringList& lst ) 00180 { 00181 findAllClasses( lst, m_part->codeModel()->globalNamespace() ); 00182 } 00183 00184 void QuickOpenClassDialog::findAllClasses( QStringList& lst, const ClassDom klass ) 00185 { 00186 QStringList fullName = klass->scope(); 00187 fullName << klass->name(); 00188 lst << fullName.join( "::" ); 00189 00190 const ClassList classList = klass->classList(); 00191 for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it ) 00192 findAllClasses( lst, *it ); 00193 } 00194 00195 void QuickOpenClassDialog::findAllClasses( QStringList& lst, const NamespaceDom ns ) 00196 { 00197 const NamespaceList namespaceList = ns->namespaceList(); 00198 for( NamespaceList::ConstIterator it=namespaceList.begin(); it!=namespaceList.end(); ++it ) 00199 findAllClasses( lst, *it ); 00200 00201 const ClassList classList = ns->classList(); 00202 for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it ) 00203 findAllClasses( lst, *it ); 00204 } 00205 00206 ClassDom QuickOpenClassDialog::findClass( const QString& name ) 00207 { 00208 QStringList path = QStringList::split( "::", name ); 00209 return findClass( path, m_part->codeModel()->globalNamespace() ); 00210 } 00211 00212 ClassDom QuickOpenClassDialog::findClass( QStringList& path, const NamespaceDom ns ) 00213 { 00214 if( path.isEmpty() ) 00215 return ClassDom(); 00216 00217 QString current = path.front(); 00218 if( ns->hasNamespace(current) ) 00219 { 00220 path.pop_front(); 00221 if( ClassDom klass = findClass( path, ns->namespaceByName(current) ) ) 00222 return klass; 00223 path.push_front( current ); 00224 } 00225 00226 if( ns->hasClass(current) ) 00227 { 00228 path.pop_front(); 00229 return findClass( path, ns->classByName(current)[0] ); 00230 } 00231 00232 return ClassDom(); 00233 } 00234 00235 ClassDom QuickOpenClassDialog::findClass( QStringList& path, const ClassDom klass ) 00236 { 00237 if( path.isEmpty() ) 00238 return klass; 00239 00240 QString current = path.front(); 00241 if( klass->hasClass(current) ) 00242 { 00243 path.pop_front(); 00244 return findClass( path, klass->classByName(current)[0] ); 00245 } 00246 00247 return ClassDom(); 00248 } 00249 00250 #include "quickopenclassdialog.moc" 00251
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Oct 6 17:39:12 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003