/* Copyright (C) 2002 by Roberto Raggi This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public version 2, License as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "problemreporter.h" #include "cppsupportpart.h" #include "configproblemreporter.h" #include "backgroundparser.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class ProblemItem: public KListViewItem { public: ProblemItem( TQListView* tqparent, const TQString& problem, const TQString& file, const TQString& line, const TQString& column ) : KListViewItem( tqparent, problem, file, line, column ) {} ProblemItem( TQListViewItem* tqparent, const TQString& problem, const TQString& file, const TQString& line, const TQString& column ) : KListViewItem( tqparent, problem, file, line, column ) {} int compare( TQListViewItem* item, int column, bool ascending ) const { if ( column == 1 || column == 2 ) { int a = text( column ).toInt(); int b = item->text( column ).toInt(); if ( a == b ) return 0; return ( a > b ? 1 : -1 ); } return KListViewItem::compare( item, column, ascending ); } }; ProblemReporter::ProblemReporter( CppSupportPart* part, TQWidget* tqparent, const char* name ) : TQWidget( tqparent, name ? name : "problemreporter" ), m_cppSupport( part ), // m_document( 0 ), m_markIface( 0 ) { TQWhatsThis::add(this, i18n("Problem reporter

This window shows various \"problems\" in your project. " "It displays TODO entries, FIXME's and errors reported by a language parser. " "To add a TODO or FIXME entry, just type
" "//@todo my todo
" "//TODO: my todo
" "//FIXME fix this")); m_initCurrentTimer = new TQTimer( this ); connect( m_initCurrentTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(initCurrentList()) ); m_gridLayout = new TQGridLayout(this,2,3); m_errorList = new KListView(this); m_warningList = new KListView(this); m_fixmeList = new KListView(this); m_todoList = new KListView(this); m_filteredList = new KListView(this); m_currentList = new KListView(this); m_filteredList->addColumn( i18n("Level") ); m_currentList->addColumn( i18n("Level") ); //addColumn( i18n("Level") ); InitListView(m_warningList); InitListView(m_errorList); InitListView(m_fixmeList); InitListView(m_todoList); InitListView(m_filteredList); InitListView(m_currentList); m_currentList->removeColumn(1); m_widgetStack = new TQWidgetStack(this); m_widgetStack->addWidget(m_currentList,0); m_widgetStack->addWidget(m_errorList,1); m_widgetStack->addWidget(m_warningList,2); m_widgetStack->addWidget(m_fixmeList,3); m_widgetStack->addWidget(m_todoList,4); m_widgetStack->addWidget(m_filteredList,5); m_tabBar = new TQTabBar(this); m_tabBar->insertTab(new TQTab(i18n("Current")),0); m_tabBar->insertTab(new TQTab(i18n("Errors")),1); m_tabBar->insertTab(new TQTab(i18n("Warnings")),2); m_tabBar->insertTab(new TQTab(i18n("Fixme")),3); m_tabBar->insertTab(new TQTab(i18n("Todo")),4); m_tabBar->insertTab(new TQTab(i18n("Filtered")),5); m_tabBar->setTabEnabled(0,false); m_tabBar->setTabEnabled(5,false); m_filterEdit = new KLineEdit(this); TQLabel* m_filterLabel = new TQLabel(i18n("Lookup:"),this); m_gridLayout->addWidget(m_tabBar,0,0); m_gridLayout->addMultiCellWidget(m_widgetStack,1,1,0,2); m_gridLayout->addWidget(m_filterLabel,0,1,TQt::AlignRight); m_gridLayout->addWidget(m_filterEdit,0,2,TQt::AlignLeft); connect( m_filterEdit, TQT_SIGNAL(returnPressed()), this, TQT_SLOT(slotFilter()) ); connect( m_filterEdit, TQT_SIGNAL(textChanged( const TQString & )), this, TQT_SLOT(slotFilter()) ); connect( m_tabBar, TQT_SIGNAL(selected(int)), this, TQT_SLOT(slotTabSelected(int)) ); connect( part->partController(), TQT_SIGNAL(activePartChanged(KParts::Part*)), this, TQT_SLOT(slotActivePartChanged(KParts::Part*)) ); connect( part->partController(), TQT_SIGNAL(partAdded(KParts::Part*)), this, TQT_SLOT(slotPartAdded(KParts::Part*)) ); // any editors that were open when we loaded the project needs to have their markType07 icon set too.. TQPtrListIterator it( *m_cppSupport->partController()->parts() ); while( it.current() ) { if ( KTextEditor::MarkInterfaceExtension* iface = dynamic_cast( it.current() ) ) { iface->setPixmap( KTextEditor::MarkInterface::markType07, SmallIcon("stop") ); } ++it; } slotActivePartChanged( part->partController()->activePart() ); } void ProblemReporter::slotFilter() { if(!m_tabBar->isTabEnabled(5)) m_tabBar->setTabEnabled(5,true); m_tabBar->tab(5)->setText(i18n("Filtered: %1").tqarg( m_filterEdit->text() )); m_tabBar->setCurrentTab(5); m_filteredList->clear(); if ( m_filterEdit->text().isEmpty() ) { m_tabBar->setTabEnabled( 5, false ); return; } filterList(m_errorList,i18n("Error")); filterList(m_warningList,i18n("Warning")); filterList(m_fixmeList,i18n("Fixme")); filterList(m_todoList,i18n("Todo")); } void ProblemReporter::filterList(KListView* listview, const TQString& level) { TQListViewItemIterator it( listview ); while ( it.current() ) { if ( it.current()->text(3).tqcontains(m_filterEdit->text(),false)) { new KListViewItem(m_filteredList,level, it.current()->text(0), it.current()->text(1), it.current()->text(2), it.current()->text(3)); } ++it; } } void ProblemReporter::slotTabSelected( int tabindex ) { m_widgetStack->raiseWidget(tabindex); } void ProblemReporter::InitListView(KListView* listview) { listview->addColumn( i18n("File") ); listview->addColumn( i18n("Line") ); listview->addColumn( i18n("Column") ); listview->addColumn( i18n("Problem") ); listview->setAllColumnsShowFocus( TRUE ); connect( listview, TQT_SIGNAL(executed(TQListViewItem*)), this, TQT_SLOT(slotSelected(TQListViewItem*)) ); connect( listview, TQT_SIGNAL(returnPressed(TQListViewItem*)), this, TQT_SLOT(slotSelected(TQListViewItem* )) ); } ProblemReporter::~ProblemReporter() { } void ProblemReporter::slotActivePartChanged( KParts::Part* part ) { m_currentList->clear(); KParts::ReadOnlyPart * ro_part = dynamic_cast( part ); m_markIface = dynamic_cast( part ); if ( !ro_part ) { m_tabBar->setTabEnabled(0,false); return; } m_fileName = ro_part->url().path(); initCurrentList(); } void EfficientKListView::limitSize( int size ) { if( m_map.size() <= size + 50 ) return; TQMap backMap; for( InsertionMap::const_iterator it = m_insertionNumbers.begin(); it != m_insertionNumbers.end(); ++it ) backMap[ (*it).second ] = (*it).first; for( TQMap::const_iterator it = backMap.begin(); it != backMap.end() && m_map.size() > size; ++it ) removeAllItems( (*it).str() ); } void EfficientKListView::removeAllItems( const TQString& str ) { HashedString h(str); m_insertionNumbers.erase( h ) ; std::pair p = m_map.equal_range( h ); for( Map::iterator it = p.first; it != p.second; ++it ) { delete( (*it).second ); } m_map.erase( p.first, p.second ); } void ProblemReporter::removeAllProblems( const TQString& filename ) { TQString relFileName = m_cppSupport->project()->relativeProjectFile(filename); kdDebug(9007) << "ProblemReporter::removeAllProblems()" << relFileName << endl; m_errorList.limitSize( 300 ); m_warningList.limitSize( 300 ); m_fixmeList.limitSize( 300 ); m_todoList.limitSize( 300 ); m_warningList.removeAllItems( relFileName ); m_errorList.removeAllItems( relFileName ); m_fixmeList.removeAllItems( relFileName ); m_todoList.removeAllItems( relFileName ); if( m_markIface ) { TQPtrList marks = m_markIface->marks(); TQPtrListIterator it( marks ); while( it.current() ) { m_markIface->removeMark( it.current()->line, KTextEditor::MarkInterface::markType07 ); ++it; } } m_initCurrentTimer->start(500, true); } void ProblemReporter::initCurrentList() { m_tabBar->setTabEnabled(0,true); TQString relFileName = m_cppSupport->project()->relativeProjectFile(m_fileName); m_currentList->clear(); updateCurrentWith(m_errorList, i18n("Error"),relFileName); updateCurrentWith(m_warningList, i18n("Warning"),relFileName); updateCurrentWith(m_fixmeList,i18n("Fixme"),relFileName); updateCurrentWith(m_todoList,i18n("Todo"),relFileName); // m_tabBar->setCurrentTab(0); } void ProblemReporter::updateCurrentWith(EfficientKListView& listview, const TQString& level, const TQString& filename) { EfficientKListView::Range r = listview.getRange( filename ); for( ; r.first != r.second; ++r.first ) new ProblemItem(m_currentList,level,(*r.first).second->text(1),(*r.first).second->text(2),(*r.first).second->text(3)); } void ProblemReporter::slotSelected( TQListViewItem* item ) { bool is_filtered = false; bool is_current = false; if(item->listView() == m_filteredList) is_filtered = true; else if(item->listView() == m_currentList) is_current = true; //either use current file m_fileName or assemble a new one from current item (relative path) and projectDirectory KURL url( is_current ? m_fileName : m_cppSupport->project()->projectDirectory() + "/" + item->text(0 + is_filtered) ); int line = item->text( 1 + is_filtered).toInt(); // int column = item->text( 3 ).toInt(); m_cppSupport->partController()->editDocument( url, line-1 ); } bool ProblemReporter::hasErrors( const TQString& fileName ) { return m_errorList.hasItem( fileName ); } void ProblemReporter::reportProblem( const TQString& fileName, const Problem& p ) { int markType = levelToMarkType( p.level() ); if( markType != -1 && m_markIface && m_fileName == fileName ) m_markIface->addMark( p.line(), markType ); TQString msg = p.text(); msg = msg.tqreplace( TQRegExp("\n"), "" ); TQString relFileName = m_cppSupport->project()->relativeProjectFile(fileName); EfficientKListView* list; switch( p.level() ) { case Problem::Level_Error: list = &m_errorList; break; case Problem::Level_Warning: list = &m_warningList; break; case Problem::Level_Todo: list = &m_todoList; break; case Problem::Level_Fixme: list = &m_fixmeList; break; default: list = NULL; } if(list) { list->addItem( relFileName, new ProblemItem( *list, relFileName, TQString::number( p.line() + 1 ), TQString::number( p.column() + 1 ), msg ) ); } m_initCurrentTimer->start( 500, true ); } void ProblemReporter::slotPartAdded( KParts::Part* part ) { KTextEditor::MarkInterfaceExtension* iface = dynamic_cast( part ); if( !iface ) return; iface->setPixmap( KTextEditor::MarkInterface::markType07, SmallIcon("stop") ); } TQString ProblemReporter::levelToString( int level ) const { switch( level ) { case Problem::Level_Error: return TQString( i18n("Error") ); case Problem::Level_Warning: return TQString( i18n("Warning") ); case Problem::Level_Todo: return TQString( i18n("Todo") ); case Problem::Level_Fixme: return TQString( i18n("Fixme") ); default: return TQString(); } } int ProblemReporter::levelToMarkType( int level ) const { switch( level ) { case Problem::Level_Error: return KTextEditor::MarkInterface::markType07; case Problem::Level_Warning: return -1; case Problem::Level_Todo: return -1; case Problem::Level_Fixme: return -1; default: return -1; } } #include "problemreporter.moc" //kate: indent-mode csands; tab-width 4; space-indent off;