|
From: <sv...@va...> - 2010-03-07 21:55:06
|
Author: cerion
Date: 2010-03-07 21:54:57 +0000 (Sun, 07 Mar 2010)
New Revision: 485
Log:
Implemented openclose_all_items for memcheckview.
Both open/close one & all now just triggering actions, not toggling: much simpler, and adequate.
Modified:
branches/valkyrie_qt4port/toolview/memcheckview.cpp
branches/valkyrie_qt4port/toolview/memcheckview.h
Modified: branches/valkyrie_qt4port/toolview/memcheckview.cpp
===================================================================
--- branches/valkyrie_qt4port/toolview/memcheckview.cpp 2010-03-07 16:52:32 UTC (rev 484)
+++ branches/valkyrie_qt4port/toolview/memcheckview.cpp 2010-03-07 21:54:57 UTC (rev 485)
@@ -64,10 +64,10 @@
// enable | disable show*Item buttons
connect( treeView, SIGNAL( itemSelectionChanged() ),
this, SLOT( updateItemActions() ) );
+
+ // on collapsing a branch, reset currentItem to branch head.
connect( treeView, SIGNAL( itemCollapsed( QTreeWidgetItem* ) ),
this, SLOT( itemCollapsed( QTreeWidgetItem* ) ) );
- connect( treeView, SIGNAL( itemExpanded( QTreeWidgetItem* ) ),
- this, SLOT( updateItemActions() ) );
// load items on-demand
connect( treeView, SIGNAL( itemExpanded( QTreeWidgetItem* ) ),
@@ -142,26 +142,21 @@
// Define actions
actMC_OpenClose_item = new QAction( this );
actMC_OpenClose_item->setObjectName( QString::fromUtf8( "actMC_OpenClose_item" ) );
- actMC_OpenClose_item->setCheckable( true );
QIcon icon_opencloseitem;
icon_opencloseitem.addPixmap( QPixmap( QString::fromUtf8( ":/vk_icons/icons/item_open.png" ) ),
QIcon::Normal, QIcon::Off );
- icon_opencloseitem.addPixmap( QPixmap( QString::fromUtf8( ":/vk_icons/icons/item_close.png" ) ),
- QIcon::Normal, QIcon::On );
actMC_OpenClose_item->setIcon( icon_opencloseitem );
- connect( actMC_OpenClose_item, SIGNAL( triggered( bool ) ),
- this, SLOT( openOneItem( bool ) ) );
+ connect( actMC_OpenClose_item, SIGNAL( triggered() ),
+ this, SLOT( opencloseOneItem() ) );
actMC_OpenClose_all = new QAction( this );
actMC_OpenClose_all->setObjectName( QString::fromUtf8( "actMC_OpenClose_all" ) );
- actMC_OpenClose_all->setCheckable( true );
QIcon icon_opencloseall;
icon_opencloseall.addPixmap( QPixmap( QString::fromUtf8( ":/vk_icons/icons/tree_open.png" ) ),
QIcon::Normal, QIcon::Off );
- icon_opencloseall.addPixmap( QPixmap( QString::fromUtf8( ":/vk_icons/icons/tree_close.png" ) ),
- QIcon::Normal, QIcon::On );
actMC_OpenClose_all->setIcon( icon_opencloseall );
- connect( actMC_OpenClose_all, SIGNAL( triggered( bool ) ), this, SLOT( openAllItems( bool ) ) );
+ connect( actMC_OpenClose_all, SIGNAL( triggered() ),
+ this, SLOT( opencloseAllItems() ) );
actMC_ShowSrcPaths = new QAction( this );
actMC_ShowSrcPaths->setObjectName( QString::fromUtf8( "actMC_ShowSrcPaths" ) );
@@ -196,10 +191,10 @@
// ------------------------------------------------------------
// Text
- actMC_OpenClose_item->setText( tr( "Open/Close" ) );
+ actMC_OpenClose_item->setText( tr( "Open/Close item" ) );
actMC_OpenClose_item->setToolTip( tr( "Open/Close currently selected item" ) );
actMC_OpenClose_all->setText( tr( "Open/Close all" ) );
- actMC_OpenClose_all->setToolTip( tr( "Open/Close all items" ) );
+ actMC_OpenClose_all->setToolTip( tr( "Open/Close all Valgrind::ERROR items" ) );
actMC_ShowSrcPaths->setText( tr( "Display simple" ) );
actMC_ShowSrcPaths->setToolTip( tr( "Display complex / simplified view" ) );
@@ -263,9 +258,7 @@
// ... turn on again only if they can be used
bool tree_empty = ( treeView->topLevelItemCount() == 0 );
actMC_OpenClose_item->setEnabled( false ); // can't enable before item clicked
- actMC_OpenClose_item->setChecked( false ); // - and default to 'open'
actMC_OpenClose_all->setEnabled( !tree_empty ); // enable only if sthng in tree
- actMC_OpenClose_all->setChecked( false ); // - and default to 'open'
actMC_ShowSrcPaths->setEnabled( !tree_empty ); // enable only if sthng in tree
actMC_ShowSrcPaths->setChecked( false ); // - and default to 'show src'
actFile_SaveLog->setEnabled( !tree_empty );
@@ -310,13 +303,73 @@
Opens all error items, including their children.
Ignores non-error items (status, preample, etc).
*/
-void MemcheckView::openAllItems( bool open_all )
+void MemcheckView::opencloseAllItems()
{
- cerr << "MemcheckView::openAllItems(): " << open_all << endl;
- cerr << "TODO" << endl;
- //TODO
+// cerr << "MemcheckView::opencloseAllItems()" << endl;
- actMC_OpenClose_all->setChecked( open_all );
+ if ( treeView->topLevelItemCount() == 0 ) {
+ // empty tree.
+ return;
+ }
+
+ VgOutputItem* vgItemTop = (VgOutputItem*)treeView->topLevelItem( 0 );
+ if ( !vgItemTop || vgItemTop->childCount() == 0 ) {
+ cerr << "Error: listview not populated as expected" << endl;
+ return;
+ }
+
+ // iterate over the first-child items
+ // check item->isOpen, start from first error, ignore suppcounts
+ bool anItemIsOpen = false;
+ int idxItemERR = -1;
+ for ( int i=0; i<vgItemTop->childCount(); ++i ) {
+ VgOutputItem* child = (VgOutputItem*)vgItemTop->child( i );
+
+ // find the first ERROR element
+ if ( (idxItemERR == -1) &&
+ child->elemType() == VgElement::ERROR ) {
+ idxItemERR = i;
+ }
+
+ // and check all elements from then on for isExpanded()
+ if ( idxItemERR != -1 ) {
+ // skip suppressions
+ if ( child->elemType() == VgElement::SUPPCOUNTS ) {
+ continue;
+ }
+ if ( child->isExpanded() ) {
+ anItemIsOpen = true;
+ break;
+ }
+ }
+ }
+ if ( idxItemERR == -1 ) {
+ // first ERROR element not found :-(
+ cerr << "Error: listview not populated as expected "
+ << "(no VgElement::ERROR found)" << endl;
+ return;
+ }
+
+ // iterate over the same items, opening or collapsing all.
+ // note: only opening/collapsing first-child level, not all levels.
+ for ( int i=idxItemERR; i<vgItemTop->childCount(); ++i ) {
+ VgOutputItem* child = (VgOutputItem*)vgItemTop->child( i );
+ // skip suppressions
+ if ( child->elemType() == VgElement::SUPPCOUNTS ) {
+ continue;
+ }
+ child->setExpanded( !anItemIsOpen );
+ }
+
+
+ if ( anItemIsOpen ) {
+ // We've collapsed all ERROR branches.
+ // Collapsing a branch sets currentItem to branch head
+ // - giving currentItem == last branch to be collapsed.
+ // Too much work to figure out if we were previously
+ // inside a now collapsed branch. Just reset to top.
+ treeView->setCurrentItem( vgItemTop );
+ }
}
@@ -326,16 +379,12 @@
When opening, all the children of the item are also opened.
When closing, only the selected item is closed.
*/
-void MemcheckView::openOneItem( bool open_item )
+void MemcheckView::opencloseOneItem()
{
QTreeWidgetItem* item = treeView->currentItem();
if ( item == 0 )
return;
- // action and item state should be in sync.
- vk_assert( open_item != item->isExpanded() );
-
- // this should be a slot. grr!
item->setExpanded( !item->isExpanded() );
}
@@ -358,8 +407,7 @@
/*!
- if we collapse a branch, set current item to branch head,
- and update actions for selected item
+ if we collapse a branch, set current item to branch head
*/
void MemcheckView::itemCollapsed( QTreeWidgetItem* item )
{
@@ -368,10 +416,6 @@
if ( item != treeView->currentItem() ) {
// this should be a slot. grr!
treeView->setCurrentItem( item );
- // item now changed: updateItemActions() will be called by signal
- } else {
- // item remained the same: updateItemActions() by hand.
- updateItemActions();
}
}
@@ -389,23 +433,9 @@
}
else {
// item ok: contract / expand it
- actMC_OpenClose_item->setEnabled( true );
+ VgOutputItem* vgItem = (VgOutputItem*)item;
+ actMC_OpenClose_item->setEnabled( vgItem->getIsExpandable() );
- if ( item->isExpanded() ) {
- // set action to 'collapse'
- actMC_OpenClose_item->setChecked( true );
- }
- else {
- // not expanded: is it expandable?
- if ( ((VgOutputItem*)item)->getIsExpandable() ) {
- // set action to 'expand'
- actMC_OpenClose_item->setChecked( false );
- } else {
- // not expanded, and not expandable -> disable action
- actMC_OpenClose_item->setEnabled( false );
-
- //TODO: for leaves, default to closing parent item?
- }
- }
+ //TODO: for leaves, default to closing parent item?
}
}
Modified: branches/valkyrie_qt4port/toolview/memcheckview.h
===================================================================
--- branches/valkyrie_qt4port/toolview/memcheckview.h 2010-03-07 16:52:32 UTC (rev 484)
+++ branches/valkyrie_qt4port/toolview/memcheckview.h 2010-03-07 21:54:57 UTC (rev 485)
@@ -66,8 +66,8 @@
private slots:
void openLogFile();
- void openAllItems( bool open_all );
- void openOneItem( bool open_item );
+ void opencloseAllItems();
+ void opencloseOneItem();
void showSrcPath( bool show_src );
void launchEditor( QTreeWidgetItem* item );
void itemExpanded( QTreeWidgetItem* item );
|