KDevelop API Documentation

classviewwidget.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  * Partially based on KDE Studio ClassListView http://www.thekompany.com/projects/kdestudio/
00020  */
00021 
00022 #include "classviewpart.h"
00023 #include "classviewwidget.h"
00024 
00025 #include <kiconloader.h>
00026 #include <kinstance.h>
00027 #include <kurl.h>
00028 #include <kaction.h>
00029 #include <kpopupmenu.h>
00030 #include <kconfig.h>
00031 
00032 #include <urlutil.h>
00033 #include <kdevcore.h>
00034 #include <kdevlanguagesupport.h>
00035 #include <kdevproject.h>
00036 #include <kdevpartcontroller.h>
00037 #include <codemodel.h>
00038 #include <codemodel_utils.h>
00039 
00040 #include <klocale.h>
00041 #include <kdebug.h>
00042 
00043 #include <qheader.h>
00044 #include <qdir.h>
00045 #include <qstylesheet.h>
00046 
00047 // namespace ?!?
00048 
00049 ClassViewWidget::ClassViewWidget( ClassViewPart * part )
00050     : KListView( 0, "ClassViewWidget" ), QToolTip( viewport() ), m_part( part ), m_projectDirectoryLength( 0 )
00051 {
00052     addColumn( "" );
00053     header()->hide();
00054     setSorting( 0 );
00055     setRootIsDecorated( true );
00056 
00057     m_projectItem = 0;
00058 
00059     connect( this, SIGNAL(returnPressed(QListViewItem*)), this, SLOT(slotExecuted(QListViewItem*)) );
00060     connect( this, SIGNAL(executed(QListViewItem*)), this, SLOT(slotExecuted(QListViewItem*)) );
00061     connect( m_part->core(), SIGNAL(projectOpened()), this, SLOT(slotProjectOpened()) );
00062     connect( m_part->core(), SIGNAL(projectClosed()), this, SLOT(slotProjectClosed()) );
00063     connect( m_part->core(), SIGNAL(languageChanged()), this, SLOT(slotProjectOpened()) );
00064 
00065     QStringList lst;
00066     lst << i18n( "Group by Directories" ) << i18n( "Plain List" ) << i18n( "Java Like Mode" );
00067     m_actionViewMode = new KSelectAction( i18n("View Mode"), KShortcut(), m_part->actionCollection(), "classview_mode" );
00068     m_actionViewMode->setItems( lst );
00069     m_actionViewMode->setWhatsThis(i18n("<b>View mode</b><p>Class browser items can be grouped by directories, listed in a plain or java like view."));
00070 
00071     m_actionNewClass = new KAction( i18n("New Class..."), KShortcut(), this, SLOT(slotNewClass()),
00072                     m_part->actionCollection(), "classview_new_class" );
00073     m_actionNewClass->setWhatsThis(i18n("<b>New class</b><p>Calls the <b>New Class</b> wizard."));
00074     m_actionAddMethod = new KAction( i18n("Add Method..."), KShortcut(), this, SLOT(slotAddMethod()),
00075                     m_part->actionCollection(), "classview_add_method" );
00076     m_actionAddMethod->setWhatsThis(i18n("<b>Add method</b><p>Calls the <b>New Method</b> wizard."));
00077     m_actionAddAttribute = new KAction( i18n("Add Attribute..."), KShortcut(), this, SLOT(slotAddAttribute()),
00078                     m_part->actionCollection(), "classview_add_attribute" );
00079     m_actionAddAttribute->setWhatsThis(i18n("<b>Add attribute</b><p>Calls the <b>New Attribute</b> wizard."));
00080 
00081     m_actionOpenDeclaration = new KAction( i18n("Open Declaration"), KShortcut(), this, SLOT(slotOpenDeclaration()),
00082                     m_part->actionCollection(), "classview_open_declaration" );
00083     m_actionOpenDeclaration->setWhatsThis(i18n("<b>Open declaration</b><p>Opens a file where the selected item is declared and jumps to the declaration line."));
00084     m_actionOpenImplementation = new KAction( i18n("Open Implementation"), KShortcut(), this, SLOT(slotOpenImplementation()),
00085                     m_part->actionCollection(), "classview_open_implementation" );
00086     m_actionOpenImplementation->setWhatsThis(i18n("<b>Open implementation</b><p>Opens a file where the selected item is defined (implemented) and jumps to the definition line."));
00087 
00088     KConfig* config = m_part->instance()->config();
00089     config->setGroup( "General" );
00090     setViewMode( config->readNumEntry( "ViewMode", KDevelop3ViewMode ) );
00091 }
00092 
00093 ClassViewWidget::~ ClassViewWidget( )
00094 {
00095     KConfig* config = m_part->instance()->config();
00096     config->setGroup( "General" );
00097     config->writeEntry( "ViewMode", viewMode() );
00098     config->sync();
00099 }
00100 
00101 void ClassViewWidget::slotExecuted( QListViewItem* item )
00102 {
00103     if( ClassViewItem* cbitem = dynamic_cast<ClassViewItem*>( item ) ){
00104     if( cbitem->hasImplementation() )
00105         cbitem->openImplementation();
00106     else
00107         cbitem->openDeclaration();
00108     }
00109 }
00110 
00111 void ClassViewWidget::clear( )
00112 {
00113     KListView::clear();
00114     removedText.clear();
00115     m_projectItem = 0;
00116 }
00117 
00118 void ClassViewWidget::refresh()
00119 {
00120     if( !m_part->project() )
00121     return;
00122 
00123     clear();
00124     m_projectItem = new FolderBrowserItem( this, this, m_part->project()->projectName() );
00125     m_projectItem->setOpen( true );
00126     blockSignals( true );
00127 
00128     FileList fileList = m_part->codeModel()->fileList();
00129     FileList::Iterator it = fileList.begin();
00130     while( it != fileList.end() ){
00131     insertFile( (*it)->name() );
00132     ++it;
00133     }
00134 
00135     blockSignals( false );
00136 }
00137 
00138 void ClassViewWidget::slotProjectOpened( )
00139 {
00140     m_projectItem = new FolderBrowserItem( this, this, m_part->project()->projectName() );
00141     m_projectItem->setOpen( true );
00142 
00143     m_projectDirectory = URLUtil::canonicalPath( m_part->project()->projectDirectory() );
00144     if( m_projectDirectory.isEmpty() )
00145     m_projectDirectory = m_part->project()->projectDirectory();
00146 
00147     m_projectDirectoryLength = m_projectDirectory.length() + 1;
00148 
00149     connect( m_part->languageSupport(), SIGNAL(updatedSourceInfo()),
00150          this, SLOT(refresh()) );
00151     connect( m_part->languageSupport(), SIGNAL(aboutToRemoveSourceInfo(const QString&)),
00152          this, SLOT(removeFile(const QString&)) );
00153     connect( m_part->languageSupport(), SIGNAL(addedSourceInfo(const QString&)),
00154          this, SLOT(insertFile(const QString&)) );
00155 }
00156 
00157 void ClassViewWidget::slotProjectClosed( )
00158 {
00159 }
00160 
00161 void ClassViewWidget::insertFile( const QString& fileName )
00162 {
00163     QString fn = URLUtil::canonicalPath( fileName );
00164     if( !m_part->project()->isProjectFile(fn) )
00165     return;
00166     //kdDebug() << "======================== insertFile(" << fn << ")" << endl;
00167 
00168     FileDom dom = m_part->codeModel()->fileByName( fn );
00169     if( !dom )
00170     return;
00171 
00172     fn = m_part->project()->relativeProjectFile( fn );
00173     QStringList path;
00174 
00175     switch( viewMode() )
00176     {
00177     case KDevelop3ViewMode:
00178     {
00179         path = QStringList::split( "/", fn );
00180         path.pop_back();
00181     }
00182     break;
00183 
00184     case KDevelop2ViewMode:
00185     {
00186     }
00187     break;
00188 
00189     case JavaLikeViewMode:
00190     {
00191         QStringList l = QStringList::split( "/", fn );
00192         l.pop_back();
00193 
00194         QString package = l.join(".");
00195         if( !package.isEmpty() )
00196         path.push_back( package );
00197     }
00198     break;
00199     }
00200 
00201     m_projectItem->processFile( dom, path );
00202 }
00203 
00204 void ClassViewWidget::removeFile( const QString& fileName )
00205 {
00206     QString fn = URLUtil::canonicalPath( fileName );
00207     if( !m_part->project()->isProjectFile(fn) )
00208     return;
00209     //kdDebug() << "======================== removeFile(" << fn << ")" << endl;
00210 
00211     FileDom dom = m_part->codeModel()->fileByName( fn );
00212     if( !dom )
00213     return;
00214 
00215     fn = m_part->project()->relativeProjectFile( fn );
00216     QStringList path;
00217 
00218     switch( viewMode() )
00219     {
00220     case KDevelop3ViewMode:
00221     {
00222         path = QStringList::split( "/", fn );
00223         path.pop_back();
00224     }
00225     break;
00226 
00227     case KDevelop2ViewMode:
00228     {
00229     }
00230     break;
00231 
00232     case JavaLikeViewMode:
00233     {
00234         QStringList l = QStringList::split( "/", fn );
00235         l.pop_back();
00236 
00237         QString package = l.join(".");
00238         if( !package.isEmpty() )
00239         path.push_back( package );
00240     }
00241     break;
00242     }
00243 
00244     m_projectItem->processFile( dom, path, true );
00245 }
00246 
00247 void ClassViewWidget::contentsContextMenuEvent( QContextMenuEvent * ev )
00248 {
00249     KPopupMenu menu( this );
00250 
00251     ClassViewItem* item = dynamic_cast<ClassViewItem*>( selectedItem() );
00252 
00253     m_actionOpenDeclaration->setEnabled( item && item->hasDeclaration() );
00254     m_actionOpenImplementation->setEnabled( item && item->hasImplementation() );
00255 
00256     m_actionOpenDeclaration->plug( &menu );
00257     m_actionOpenImplementation->plug( &menu );
00258     menu.insertSeparator();
00259 
00260     bool sep = false;
00261     if( item && item->isClass() ){
00262         if( m_part->langHasFeature(KDevLanguageSupport::AddMethod) ) {
00263             m_actionAddMethod->plug( &menu );
00264             sep = true;
00265         }
00266     
00267         if( m_part->langHasFeature(KDevLanguageSupport::AddAttribute) ) {
00268         m_actionAddAttribute->plug( &menu );
00269             sep = true;
00270         }   
00271     }
00272 
00273     if( item && item->model() ){
00274     CodeModelItemContext context( item->model() );
00275     m_part->core()->fillContextMenu( &menu, &context );
00276 //        sep = true;
00277     }
00278     if (sep)
00279         menu.insertSeparator();
00280 
00281     int oldViewMode = viewMode();
00282     m_actionViewMode->plug( &menu );
00283 
00284     menu.exec( ev->globalPos() );
00285 
00286     if( viewMode() != oldViewMode )
00287     refresh();
00288 
00289     ev->consume();
00290 }
00291 
00292 void ClassViewWidget::setViewMode( int mode )
00293 {
00294     m_actionViewMode->setCurrentItem( mode );
00295 }
00296 
00297 int ClassViewWidget::viewMode( ) const
00298 {
00299      return m_actionViewMode->currentItem();
00300 }
00301 
00302 void FolderBrowserItem::processFile( FileDom file, QStringList& path, bool remove )
00303 {
00304     if( path.isEmpty() ){
00305     NamespaceList namespaceList = file->namespaceList();
00306     ClassList classList = file->classList();
00307     TypeAliasList typeAliasList = file->typeAliasList();
00308     FunctionList functionList = file->functionList();
00309     VariableList variableList = file->variableList();
00310 
00311     for( NamespaceList::Iterator it=namespaceList.begin(); it!=namespaceList.end(); ++it )
00312         processNamespace( *it, remove );
00313     for( ClassList::Iterator it=classList.begin(); it!=classList.end(); ++it )
00314         processClass( *it, remove );
00315     for( TypeAliasList::Iterator it=typeAliasList.begin(); it!=typeAliasList.end(); ++it )
00316         processTypeAlias( *it, remove );
00317     for( FunctionList::Iterator it=functionList.begin(); it!=functionList.end(); ++it )
00318         processFunction( *it, remove );
00319     for( VariableList::Iterator it=variableList.begin(); it!=variableList.end(); ++it )
00320         processVariable( *it, remove );
00321 
00322     return;
00323     }
00324 
00325     QString current = path.front();
00326     path.pop_front();
00327 
00328     FolderBrowserItem* item = m_folders.contains( current ) ? m_folders[ current ] : 0;
00329     if( !item ){
00330     if( remove )
00331         return;
00332 
00333     item = new FolderBrowserItem( m_widget, this, current );
00334     if( listView()->removedText.contains(current) )
00335         item->setOpen( true );
00336     m_folders.insert( current, item );
00337     }
00338 
00339     item->processFile( file, path, remove );
00340 
00341     if( remove && item->childCount() == 0 ){
00342     m_folders.remove( current );
00343     if( item->isOpen() ){
00344         listView()->removedText << current;
00345     }
00346     delete( item );
00347     item = 0;
00348     }
00349 }
00350 
00351 void FolderBrowserItem::processNamespace( NamespaceDom ns, bool remove )
00352 {
00353     NamespaceDomBrowserItem* item = m_namespaces.contains( ns->name() ) ? m_namespaces[ ns->name() ] : 0;
00354     if( !item ){
00355     if( remove )
00356         return;
00357 
00358     item = new NamespaceDomBrowserItem( this, ns );
00359     if( listView()->removedText.contains(ns->name()) )
00360         item->setOpen( true );
00361     m_namespaces.insert( ns->name(), item );
00362     }
00363 
00364     NamespaceList namespaceList = ns->namespaceList();
00365     ClassList classList = ns->classList();
00366     TypeAliasList typeAliasList = ns->typeAliasList();
00367     FunctionList functionList = ns->functionList();
00368     VariableList variableList = ns->variableList();
00369 
00370     for( NamespaceList::Iterator it=namespaceList.begin(); it!=namespaceList.end(); ++it )
00371     item->processNamespace( *it, remove );
00372     for( ClassList::Iterator it=classList.begin(); it!=classList.end(); ++it )
00373     item->processClass( *it, remove );
00374     for( TypeAliasList::Iterator it=typeAliasList.begin(); it!=typeAliasList.end(); ++it )
00375     item->processTypeAlias( *it, remove );
00376     for( FunctionList::Iterator it=functionList.begin(); it!=functionList.end(); ++it )
00377     item->processFunction( *it, remove );
00378     for( VariableList::Iterator it=variableList.begin(); it!=variableList.end(); ++it )
00379     item->processVariable( *it, remove );
00380 
00381     if( remove && item->childCount() == 0 ){
00382     m_namespaces.remove( ns->name() );
00383     if( item->isOpen() ){
00384         listView()->removedText << ns->name();
00385     }
00386     delete( item );
00387     emit m_widget->removedNamespace(ns->name());
00388     item = 0;
00389     }
00390 }
00391 
00392 void FolderBrowserItem::processClass( ClassDom klass, bool remove )
00393 {
00394     ClassDomBrowserItem* item = m_classes.contains( klass ) ? m_classes[ klass ] : 0;
00395     if( !item ){
00396     if( remove )
00397         return;
00398 
00399     item = new ClassDomBrowserItem( this, klass );
00400     if( listView()->removedText.contains(klass->name()) )
00401         item->setOpen( true );
00402     m_classes.insert( klass, item );
00403     }
00404 
00405     ClassList classList = klass->classList();
00406     TypeAliasList typeAliasList = klass->typeAliasList();
00407     FunctionList functionList = klass->functionList();
00408     VariableList variableList = klass->variableList();
00409 
00410     for( ClassList::Iterator it=classList.begin(); it!=classList.end(); ++it )
00411     item->processClass( *it, remove );
00412     for( TypeAliasList::Iterator it=typeAliasList.begin(); it!=typeAliasList.end(); ++it )
00413     item->processTypeAlias( *it, remove );
00414     for( FunctionList::Iterator it=functionList.begin(); it!=functionList.end(); ++it )
00415     item->processFunction( *it, remove );
00416     for( VariableList::Iterator it=variableList.begin(); it!=variableList.end(); ++it )
00417     item->processVariable( *it, remove );
00418 
00419     if( remove && item->childCount() == 0 ){
00420     m_classes.remove( klass );
00421     if( item->isOpen() ){
00422         listView()->removedText << klass->name();
00423     }
00424     delete( item );
00425     item = 0;
00426     }
00427 }
00428 
00429 void FolderBrowserItem::processTypeAlias( TypeAliasDom typeAlias, bool remove )
00430 {
00431     TypeAliasDomBrowserItem* item = m_typeAliases.contains( typeAlias ) ? m_typeAliases[ typeAlias ] : 0;
00432     if( !item ){
00433     if( remove )
00434         return;
00435 
00436     item = new TypeAliasDomBrowserItem( this, typeAlias );
00437     if( listView()->removedText.contains(typeAlias->name()) )
00438         item->setOpen( true );
00439     m_typeAliases.insert( typeAlias, item );
00440     }
00441 
00442     if( remove && item->childCount() == 0 ){
00443     m_typeAliases.remove( typeAlias );
00444     if( item->isOpen() ){
00445         listView()->removedText << typeAlias->name();
00446     }
00447     delete( item );
00448     item = 0;
00449     }
00450 }
00451 
00452 void FolderBrowserItem::processFunction( FunctionDom fun, bool remove )
00453 {
00454     FunctionDomBrowserItem* item = m_functions.contains( fun ) ? m_functions[ fun ] : 0;
00455     if( !item ){
00456     if( remove )
00457         return;
00458 
00459     item = new FunctionDomBrowserItem( this, fun );
00460     m_functions.insert( fun, item );
00461     }
00462 
00463     if( remove ){
00464     m_functions.remove( fun );
00465     delete( item );
00466     item = 0;
00467     }
00468 }
00469 
00470 void FolderBrowserItem::processVariable( VariableDom var, bool remove )
00471 {
00472     VariableDomBrowserItem* item = m_variables.contains( var ) ? m_variables[ var ] : 0;
00473     if( !item ){
00474     if( remove )
00475         return;
00476 
00477     item = new VariableDomBrowserItem( this, var );
00478     m_variables.insert( var, item );
00479     }
00480 
00481     if( remove ){
00482     m_variables.remove( var );
00483     delete( item );
00484     item = 0;
00485     }
00486 }
00487 
00488 // ------------------------------------------------------------------------
00489 void NamespaceDomBrowserItem::processNamespace( NamespaceDom ns, bool remove )
00490 {
00491     NamespaceDomBrowserItem* item = m_namespaces.contains( ns->name() ) ? m_namespaces[ ns->name() ] : 0;
00492     if( !item ){
00493     if( remove )
00494         return;
00495 
00496     item = new NamespaceDomBrowserItem( this, ns );
00497     if( listView()->removedText.contains(ns->name()) )
00498         item->setOpen( true );
00499     m_namespaces.insert( ns->name(), item );
00500     }
00501 
00502     NamespaceList namespaceList = ns->namespaceList();
00503     ClassList classList = ns->classList();
00504     TypeAliasList typeAliasList = ns->typeAliasList();
00505     FunctionList functionList = ns->functionList();
00506     VariableList variableList = ns->variableList();
00507 
00508     for( NamespaceList::Iterator it=namespaceList.begin(); it!=namespaceList.end(); ++it )
00509     item->processNamespace( *it, remove );
00510     for( ClassList::Iterator it=classList.begin(); it!=classList.end(); ++it )
00511     item->processClass( *it, remove );
00512     for( TypeAliasList::Iterator it=typeAliasList.begin(); it!=typeAliasList.end(); ++it )
00513     item->processTypeAlias( *it, remove );
00514     for( FunctionList::Iterator it=functionList.begin(); it!=functionList.end(); ++it )
00515     item->processFunction( *it, remove );
00516     for( VariableList::Iterator it=variableList.begin(); it!=variableList.end(); ++it )
00517     item->processVariable( *it, remove );
00518 
00519     if( remove && item->childCount() == 0 ){
00520     m_namespaces.remove( ns->name() );
00521     if( item->isOpen() ){
00522         listView()->removedText << ns->name();
00523     }
00524     delete( item );
00525     item = 0;
00526     }
00527 }
00528 
00529 void NamespaceDomBrowserItem::processClass( ClassDom klass, bool remove )
00530 {
00531     ClassDomBrowserItem* item = m_classes.contains( klass ) ? m_classes[ klass ] : 0;
00532     if( !item ){
00533     if( remove )
00534         return;
00535 
00536     item = new ClassDomBrowserItem( this, klass );
00537     if( listView()->removedText.contains(klass->name()) )
00538         item->setOpen( true );
00539     m_classes.insert( klass, item );
00540     }
00541 
00542     ClassList classList = klass->classList();
00543     TypeAliasList typeAliasList = klass->typeAliasList();
00544     FunctionList functionList = klass->functionList();
00545     VariableList variableList = klass->variableList();
00546 
00547     for( ClassList::Iterator it=classList.begin(); it!=classList.end(); ++it )
00548     item->processClass( *it, remove );
00549     for( TypeAliasList::Iterator it=typeAliasList.begin(); it!=typeAliasList.end(); ++it )
00550     item->processTypeAlias( *it, remove );
00551     for( FunctionList::Iterator it=functionList.begin(); it!=functionList.end(); ++it )
00552     item->processFunction( *it, remove );
00553     for( VariableList::Iterator it=variableList.begin(); it!=variableList.end(); ++it )
00554     item->processVariable( *it, remove );
00555 
00556     if( remove && item->childCount() == 0 ){
00557     m_classes.remove( klass );
00558     if( item->isOpen() ){
00559         listView()->removedText << klass->name();
00560     }
00561     delete( item );
00562     item = 0;
00563     }
00564 }
00565 
00566 void NamespaceDomBrowserItem::processTypeAlias( TypeAliasDom typeAlias, bool remove )
00567 {
00568     TypeAliasDomBrowserItem* item = m_typeAliases.contains( typeAlias ) ? m_typeAliases[ typeAlias ] : 0;
00569     if( !item ){
00570     if( remove )
00571         return;
00572 
00573     item = new TypeAliasDomBrowserItem( this, typeAlias );
00574     if( listView()->removedText.contains(typeAlias->name()) )
00575         item->setOpen( true );
00576     m_typeAliases.insert( typeAlias, item );
00577     }
00578 
00579     if( remove && item->childCount() == 0 ){
00580     m_typeAliases.remove( typeAlias );
00581     if( item->isOpen() ){
00582         listView()->removedText << typeAlias->name();
00583     }
00584     delete( item );
00585     item = 0;
00586     }
00587 }
00588 
00589 void NamespaceDomBrowserItem::processFunction( FunctionDom fun, bool remove )
00590 {
00591     FunctionDomBrowserItem* item = m_functions.contains( fun ) ? m_functions[ fun ] : 0;
00592     if( !item ){
00593     if( remove )
00594         return;
00595 
00596     item = new FunctionDomBrowserItem( this, fun );
00597     m_functions.insert( fun, item );
00598     }
00599 
00600     if( remove ){
00601     m_functions.remove( fun );
00602     delete( item );
00603     item = 0;
00604     }
00605 }
00606 
00607 void NamespaceDomBrowserItem::processVariable( VariableDom var, bool remove )
00608 {
00609     VariableDomBrowserItem* item = m_variables.contains( var ) ? m_variables[ var ] : 0;
00610     if( !item ){
00611     if( remove )
00612         return;
00613 
00614     item = new VariableDomBrowserItem( this, var );
00615     m_variables.insert( var, item );
00616     }
00617 
00618     if( remove ){
00619     m_variables.remove( var );
00620     delete( item );
00621     item = 0;
00622     }
00623 }
00624 
00625 // ------------------------------------------------------------------------
00626 void ClassDomBrowserItem::processClass( ClassDom klass, bool remove )
00627 {
00628     ClassDomBrowserItem* item = m_classes.contains( klass ) ? m_classes[ klass ] : 0;
00629     if( !item ){
00630     if( remove )
00631         return;
00632 
00633     item = new ClassDomBrowserItem( this, klass );
00634     if( listView()->removedText.contains(klass->name()) )
00635         item->setOpen( true );
00636     m_classes.insert( klass, item );
00637     }
00638 
00639     ClassList classList = klass->classList();
00640     TypeAliasList typeAliasList = klass->typeAliasList();
00641     FunctionList functionList = klass->functionList();
00642     VariableList variableList = klass->variableList();
00643 
00644     for( ClassList::Iterator it=classList.begin(); it!=classList.end(); ++it )
00645     item->processClass( *it, remove );
00646     for( TypeAliasList::Iterator it=typeAliasList.begin(); it!=typeAliasList.end(); ++it )
00647     item->processTypeAlias( *it, remove );
00648     for( FunctionList::Iterator it=functionList.begin(); it!=functionList.end(); ++it )
00649     item->processFunction( *it, remove );
00650     for( VariableList::Iterator it=variableList.begin(); it!=variableList.end(); ++it )
00651     item->processVariable( *it, remove );
00652 
00653     if( remove && item->childCount() == 0 ){
00654     m_classes.remove( klass );
00655     if( item->isOpen() ){
00656         listView()->removedText << klass->name();
00657     }
00658     delete( item );
00659     item = 0;
00660     }
00661 }
00662 
00663 void ClassDomBrowserItem::processTypeAlias( TypeAliasDom typeAlias, bool remove )
00664 {
00665     TypeAliasDomBrowserItem* item = m_typeAliases.contains( typeAlias ) ? m_typeAliases[ typeAlias ] : 0;
00666     if( !item ){
00667     if( remove )
00668         return;
00669 
00670     item = new TypeAliasDomBrowserItem( this, typeAlias );
00671     if( listView()->removedText.contains(typeAlias->name()) )
00672         item->setOpen( true );
00673     m_typeAliases.insert( typeAlias, item );
00674     }
00675 
00676     if( remove && item->childCount() == 0 ){
00677     m_typeAliases.remove( typeAlias );
00678     if( item->isOpen() ){
00679         listView()->removedText << typeAlias->name();
00680     }
00681     delete( item );
00682     item = 0;
00683     }
00684 }
00685 
00686 void ClassDomBrowserItem::processFunction( FunctionDom fun, bool remove )
00687 {
00688     FunctionDomBrowserItem* item = m_functions.contains( fun ) ? m_functions[ fun ] : 0;
00689     if( !item ){
00690     if( remove )
00691         return;
00692 
00693     item = new FunctionDomBrowserItem( this, fun );
00694     m_functions.insert( fun, item );
00695     }
00696 
00697     if( remove ){
00698     m_functions.remove( fun );
00699     delete( item );
00700     item = 0;
00701     }
00702 }
00703 
00704 void ClassDomBrowserItem::processVariable( VariableDom var, bool remove )
00705 {
00706     VariableDomBrowserItem* item = m_variables.contains( var ) ? m_variables[ var ] : 0;
00707     if( !item ){
00708     if( remove )
00709         return;
00710 
00711     item = new VariableDomBrowserItem( this, var );
00712     m_variables.insert( var, item );
00713     }
00714 
00715     if( remove ){
00716     m_variables.remove( var );
00717     delete( item );
00718     item = 0;
00719     }
00720 }
00721 
00722 void FolderBrowserItem::setup( )
00723 {
00724     ClassViewItem::setup();
00725     setPixmap( 0, SmallIcon("folder") );
00726     setExpandable( true );
00727 }
00728 
00729 void NamespaceDomBrowserItem::setup( )
00730 {
00731     ClassViewItem::setup();
00732     setPixmap( 0, UserIcon("CVnamespace", KIcon::DefaultState, listView()->m_part->instance()) );
00733     setExpandable( true );
00734 
00735     QString txt = listView()->m_part->languageSupport()->formatModelItem(m_dom.data(), true);
00736     setText( 0, txt );
00737 }
00738 
00739 void ClassDomBrowserItem::setup( )
00740 {
00741     ClassViewItem::setup();
00742     setPixmap( 0, UserIcon("CVclass", KIcon::DefaultState, listView()->m_part->instance()) );
00743     setExpandable( true );
00744 
00745     QString txt = listView()->m_part->languageSupport()->formatModelItem(m_dom.data(), true);
00746     setText( 0, txt );
00747 }
00748 
00749 void TypeAliasDomBrowserItem::setup( )
00750 {
00751     ClassViewItem::setup();
00752     setPixmap( 0, UserIcon("CVtypedef", KIcon::DefaultState, listView()->m_part->instance()) );
00753     setExpandable( false );
00754 
00755     QString txt = listView()->m_part->languageSupport()->formatModelItem(m_dom.data(), true);
00756     setText( 0, txt );
00757 }
00758 
00759 void FunctionDomBrowserItem::setup( )
00760 {
00761     ClassViewItem::setup();
00762 
00763     QString iconName;
00764     QString methodType;
00765 
00766     if ( m_dom->isSignal() )
00767         methodType = "signal";
00768     else if (m_dom->isSlot() ) 
00769         methodType = "slot";
00770     else
00771         methodType = "meth";
00772 
00773     if( m_dom->access() == CodeModelItem::Private )
00774         iconName = "CVprivate_" + methodType;
00775     else if( m_dom->access() == CodeModelItem::Protected )
00776         iconName = "CVprotected_" + methodType;
00777     else
00778         iconName = "CVpublic_" + methodType;
00779 
00780     setPixmap( 0, UserIcon(iconName, KIcon::DefaultState, listView()->m_part->instance()) );
00781 
00782     QString txt = listView()->m_part->languageSupport()->formatModelItem(m_dom.data(), true);
00783     setText( 0, txt );
00784 }
00785 
00786 void FunctionDomBrowserItem::openDeclaration()
00787 {
00788     int startLine, startColumn;
00789     m_dom->getStartPosition( &startLine, &startColumn );
00790     listView()->m_part->partController()->editDocument( KURL(m_dom->fileName()), startLine );
00791 }
00792 
00793 void FunctionDomBrowserItem::openImplementation()
00794 {
00795     FunctionDefinitionList lst;
00796     FileList fileList = listView()->m_part->codeModel()->fileList();
00797     CodeModelUtils::findFunctionDefinitions( FindOp(m_dom), fileList, lst );
00798 
00799     if( lst.isEmpty() )
00800         return;
00801 
00802     FunctionDefinitionDom fun;
00803     QFileInfo fileInfo( m_dom->fileName() );
00804     QString path = fileInfo.dirPath( true );
00805 
00806     for( FunctionDefinitionList::Iterator it=lst.begin(); it!=lst.end(); ++it )
00807     {
00808         QFileInfo defFileInfo( (*it)->fileName() );
00809         QString defPath = defFileInfo.dirPath( true );
00810 
00811         if( path != defPath )
00812             continue;
00813 
00814     if( defFileInfo.baseName() == fileInfo.baseName() ) {
00815             fun = *it;
00816         } else if( !fun ) {
00817         fun = *it;
00818         }
00819     }
00820 
00821     if( !fun ) {
00822         fun = lst.front();
00823     }
00824 
00825     int startLine, startColumn;
00826     fun->getStartPosition( &startLine, &startColumn );
00827     listView()->m_part->partController()->editDocument( KURL(fun->fileName()), startLine );
00828 }
00829 
00830 void VariableDomBrowserItem::setup( )
00831 {
00832     ClassViewItem::setup();
00833     QString iconName;
00834     if( m_dom->access() == CodeModelItem::Private )
00835         iconName = "CVprivate_var";
00836     else if( m_dom->access() == CodeModelItem::Protected )
00837         iconName = "CVprotected_var";
00838     else
00839         iconName = "CVpublic_var";
00840 
00841     setPixmap( 0, UserIcon(iconName, KIcon::DefaultState, listView()->m_part->instance()) );
00842 
00843     QString txt = listView()->m_part->languageSupport()->formatModelItem(m_dom.data(), true);
00844     setText( 0, txt );
00845 }
00846 
00847 void VariableDomBrowserItem::openDeclaration()
00848 {
00849     int startLine, startColumn;
00850     m_dom->getStartPosition( &startLine, &startColumn );
00851 
00852     listView()->m_part->partController()->editDocument( KURL(m_dom->fileName()), startLine );
00853 }
00854 
00855 void VariableDomBrowserItem::openImplementation()
00856 {
00857 }
00858 
00859 QString FolderBrowserItem::key( int , bool ) const
00860 {
00861     return "0 " + text( 0 );
00862 }
00863 
00864 QString NamespaceDomBrowserItem::key( int , bool ) const
00865 {
00866     return "1 " + text( 0 );
00867 }
00868 
00869 QString ClassDomBrowserItem::key( int , bool ) const
00870 {
00871     return "2 " + text( 0 );
00872 }
00873 
00874 QString TypeAliasDomBrowserItem::key( int , bool ) const
00875 {
00876     return "3 " + text( 0 );
00877 }
00878 
00879 QString FunctionDomBrowserItem::key( int , bool ) const
00880 {
00881     return "4 " + text( 0 );
00882 }
00883 
00884 QString VariableDomBrowserItem::key( int , bool ) const
00885 {
00886     return "5 " + text( 0 );
00887 }
00888 
00889 void ClassViewWidget::slotNewClass( )
00890 {
00891     if( m_part->languageSupport()->features() & KDevLanguageSupport::NewClass )
00892     m_part->languageSupport()->addClass();
00893 }
00894 
00895 void ClassViewWidget::slotAddMethod( )
00896 {
00897     if ( !selectedItem() ) return;
00898 
00899     if( m_part->languageSupport()->features() & KDevLanguageSupport::AddMethod )
00900         m_part->languageSupport()->addMethod( static_cast<ClassDomBrowserItem*>( selectedItem() )->dom() );
00901 }
00902 
00903 void ClassViewWidget::slotAddAttribute( )
00904 {
00905     if ( !selectedItem() ) return;
00906     
00907     if( m_part->languageSupport()->features() & KDevLanguageSupport::AddAttribute )
00908         m_part->languageSupport()->addAttribute( static_cast<ClassDomBrowserItem*>( selectedItem() )->dom() );
00909 }
00910 
00911 void ClassViewWidget::slotOpenDeclaration( )
00912 {
00913     if ( !selectedItem() ) return;
00914     
00915     static_cast<ClassViewItem*>( selectedItem() )->openDeclaration();
00916 }
00917 
00918 void ClassViewWidget::slotOpenImplementation( )
00919 {
00920     if ( !selectedItem() ) return;
00921     
00922     static_cast<ClassViewItem*>( selectedItem() )->openImplementation();
00923 }
00924 
00925 void ClassDomBrowserItem::openDeclaration( )
00926 {
00927     int startLine, startColumn;
00928     m_dom->getStartPosition( &startLine, &startColumn );
00929     listView()->m_part->partController()->editDocument( KURL(m_dom->fileName()), startLine );
00930 }
00931 
00932 void TypeAliasDomBrowserItem::openDeclaration( )
00933 {
00934     int startLine, startColumn;
00935     m_dom->getStartPosition( &startLine, &startColumn );
00936     listView()->m_part->partController()->editDocument( KURL(m_dom->fileName()), startLine );
00937 }
00938 
00939 bool FunctionDomBrowserItem::hasImplementation() const
00940 {
00941     FunctionDefinitionList lst;
00942     FileList fileList = listView()->m_part->codeModel()->fileList();
00943     CodeModelUtils::findFunctionDefinitions( FindOp(m_dom), fileList, lst );
00944 
00945     return !lst.isEmpty();
00946 }
00947 
00948 void ClassViewWidget::maybeTip( QPoint const & p )
00949 {
00950     ClassViewItem * item = dynamic_cast<ClassViewItem*>( itemAt( p ) );
00951     if ( !item ) return;
00952     
00953     QString tooltip;
00954     
00955     if ( item->isNamespace() )
00956     {
00957         NamespaceDomBrowserItem * nitem = dynamic_cast<NamespaceDomBrowserItem*>( item );
00958         if ( nitem )
00959         {
00960             tooltip = nitem->dom()->scope().join("::") + "::" + nitem->dom()->name();
00961         }
00962     }
00963     else if ( item->isClass() )
00964     {
00965         ClassDomBrowserItem * citem = dynamic_cast<ClassDomBrowserItem*>( item );
00966         if ( citem )
00967         {
00968             tooltip = citem->dom()->scope().join("::") + "::" 
00969                 + citem->dom()->name() + " : " 
00970                 + citem->dom()->baseClassList().join(", ");
00971         }
00972     }
00973     else if ( item->isFunction() )
00974     {
00975         FunctionDomBrowserItem * fitem = dynamic_cast<FunctionDomBrowserItem*>( item );
00976         if ( fitem )
00977         {
00978             QString access;
00979             if ( fitem->dom()->access() == CodeModelItem::Private )
00980                 access = "[private] ";
00981             else if ( fitem->dom()->access() == CodeModelItem::Protected )
00982                 access = "[protected] ";
00983             else if ( fitem->dom()->access() == CodeModelItem::Public )
00984                 access = "[public] ";
00985 
00986             QStringList arguments;
00987             ArgumentList const & list = fitem->dom()->argumentList();
00988             ArgumentList::ConstIterator it( list.begin() );
00989             while ( it != list.end() )
00990             {
00991                 arguments << (*it)->type();
00992                 ++it;
00993             }
00994             
00995             QString strstatic = fitem->dom()->isStatic() ? QString( "[static] " ) : QString::null;
00996             QString strsignal = fitem->dom()->isSignal() ? QString( "[signal] " ) : QString::null;
00997             QString strslot = fitem->dom()->isSlot() ? QString( "[slot] " ) : QString::null;
00998             QString strresult = !fitem->dom()->resultType().isEmpty() ? fitem->dom()->resultType() + " " : QString::null;
00999             
01000             QString strconstant = fitem->dom()->isConstant() ? QString( " [const]" ) : QString::null;
01001             QString strabstract = fitem->dom()->isAbstract() ? QString( " [abstract]" ) : QString::null;
01002             
01003             tooltip = access + strstatic + strsignal + strslot + strresult
01004                 + fitem->dom()->scope().join("::") + "::" + fitem->dom()->name() 
01005                 + "(" + arguments.join(", ") + ")" + strconstant + strabstract;
01006         }
01007     }
01008     else if ( item->isVariable() )
01009     {
01010         VariableDomBrowserItem * vitem = dynamic_cast<VariableDomBrowserItem*>( item );
01011         if ( vitem )
01012         {
01013             QString access;
01014             if ( vitem->dom()->access() == CodeModelItem::Private )
01015                 access = "[private] ";
01016             else if ( vitem->dom()->access() == CodeModelItem::Protected )
01017                 access = "[protected] ";
01018             else if ( vitem->dom()->access() == CodeModelItem::Public )
01019                 access = "[public] ";
01020 
01021             QString strstatic = vitem->dom()->isStatic() ? QString( "[static] " ) : QString::null;
01022             tooltip = access + strstatic + vitem->dom()->type() + " " + vitem->dom()->name();
01023         }   
01024     }
01025     else if ( item->isTypeAlias() )
01026     {
01027         if( TypeAliasDomBrowserItem * titem = dynamic_cast<TypeAliasDomBrowserItem*>( item ) )
01028         {
01029             tooltip = QString( "[Type] " ) + titem->dom()->type() + " " + titem->dom()->name();
01030         }
01031     }
01032     
01033     kdDebug(0) << tooltip << endl;
01034     
01035     QRect r = itemRect( item );
01036 
01037     if ( item && r.isValid() && !tooltip.isEmpty() )
01038     {
01039         tip( r, QString("<qt><pre>") + QStyleSheet::escape( tooltip ) + QString("</pre></qt>") );
01040     }
01041 }
01042 
01043 
01044 #include "classviewwidget.moc"
01045 
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:22:38 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003