quickopenclassdialog.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <kdevproject.h>
00022 #include <kdevpartcontroller.h>
00023
00024 #include "doclineedit.h"
00025
00026 #include <klistbox.h>
00027 #include <klocale.h>
00028 #include <kdebug.h>
00029
00030 #include <qregexp.h>
00031 #include <qlabel.h>
00032
00033 #include "quickopenclassdialog.h"
00034 #include "quickopen_part.h"
00035
00036 QuickOpenClassDialog::QuickOpenClassDialog(QuickOpenPart* part, QWidget* parent, const char* name, bool modal, WFlags fl)
00037 : QuickOpenDialog( part, parent, name, modal, fl )
00038 {
00039 nameLabel->setText( i18n("Class &name:") );
00040 itemListLabel->setText( i18n("Class &list:") );
00041
00042 findAllClasses( m_classList );
00043 qHeapSort( m_classList );
00044
00045 m_completion = new KCompletion();
00046 m_completion->insertItems( m_classList );
00047 m_completion->setIgnoreCase( true );
00048
00049 nameEdit->setFocus();
00050
00051 itemList->insertStringList( m_classList );
00052 itemList->setCurrentItem(0);
00053 }
00054
00055 QuickOpenClassDialog::~QuickOpenClassDialog()
00056 {
00057 delete( m_completion );
00058 m_completion = 0;
00059 }
00060
00061 void QuickOpenClassDialog::slotExecuted( QListBoxItem* )
00062 {
00063 accept();
00064 }
00065
00066 void QuickOpenClassDialog::accept()
00067 {
00068 if( QListBoxItem* item = itemList->selectedItem() )
00069 {
00070 ClassDom klass = findClass( item->text() );
00071 if( klass )
00072 {
00073 int startLine, startColumn;
00074 klass->getStartPosition( &startLine, &startColumn );
00075 m_part->partController()->editDocument( KURL( klass->fileName() ), startLine );
00076 }
00077 }
00078
00079 QDialog::accept();
00080 }
00081
00082 void QuickOpenClassDialog::slotReturnPressed( )
00083 {
00084 accept();
00085 }
00086
00087 void QuickOpenClassDialog::findAllClasses( QStringList& lst )
00088 {
00089 findAllClasses( lst, m_part->codeModel()->globalNamespace() );
00090 }
00091
00092 void QuickOpenClassDialog::findAllClasses( QStringList& lst, const ClassDom klass )
00093 {
00094 QStringList fullName = klass->scope();
00095 fullName << klass->name();
00096 lst << fullName.join( "::" );
00097
00098 const ClassList classList = klass->classList();
00099 for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it )
00100 findAllClasses( lst, *it );
00101 }
00102
00103 void QuickOpenClassDialog::findAllClasses( QStringList& lst, const NamespaceDom ns )
00104 {
00105 const NamespaceList namespaceList = ns->namespaceList();
00106 for( NamespaceList::ConstIterator it=namespaceList.begin(); it!=namespaceList.end(); ++it )
00107 findAllClasses( lst, *it );
00108
00109 const ClassList classList = ns->classList();
00110 for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it )
00111 findAllClasses( lst, *it );
00112 }
00113
00114 ClassDom QuickOpenClassDialog::findClass( const QString& name )
00115 {
00116 QStringList path = QStringList::split( "::", name );
00117 return findClass( path, m_part->codeModel()->globalNamespace() );
00118 }
00119
00120 ClassDom QuickOpenClassDialog::findClass( QStringList& path, const NamespaceDom ns )
00121 {
00122 if( path.isEmpty() )
00123 return ClassDom();
00124
00125 QString current = path.front();
00126 if( ns->hasNamespace(current) )
00127 {
00128 path.pop_front();
00129 if( ClassDom klass = findClass( path, ns->namespaceByName(current) ) )
00130 return klass;
00131 path.push_front( current );
00132 }
00133
00134 if( ns->hasClass(current) )
00135 {
00136 path.pop_front();
00137 return findClass( path, ns->classByName(current)[0] );
00138 }
00139
00140 return ClassDom();
00141 }
00142
00143 ClassDom QuickOpenClassDialog::findClass( QStringList& path, const ClassDom klass )
00144 {
00145 if( path.isEmpty() )
00146 return klass;
00147
00148 QString current = path.front();
00149 if( klass->hasClass(current) )
00150 {
00151 path.pop_front();
00152 return findClass( path, klass->classByName(current)[0] );
00153 }
00154
00155 return ClassDom();
00156 }
00157
00158 #include "quickopenclassdialog.moc"
00159
This file is part of the documentation for KDevelop Version 3.1.2.