Sure, here's the whole function:
void JasperView::expandNonDefaultNodes()
{
// If I uncomment this, I don't get the QPainter warnings
// and ALL the nodes are expanded..
//expandAll();
//return;
for (int i=0; i < mdl->rowCount( rootNdx ); ++i)
{
BlockTreeItem *item = getItem( ctrIndex );
// For binds, just expand so the fcalls are visible (for now)
BindBlockItem *bindBlock = dynamic_cast<BindBlockItem*>( item );
if (bindBlock)
{
setExpanded( ctrIndex, true );
}
// For functions, expand out any nodes with non-default values
FuncBlockItem *funcBlock = dynamic_cast<FuncBlockItem*>( item );
if (funcBlock)
{
bool anyExpandedNodes = false;
for (int j=0; j < mdl->rowCount( ctrIndex ); ++j )
{
ParamNodeItem *nodeItem = dynamic_cast<ParamNodeItem*>( getItem( nodeIndex ) );
ParamNode *node = nodeItem->block();
if (node)
{
bool shouldExpand = node->anyChangesFromDefault();
setExpanded( nodeIndex, shouldExpand );
anyExpandedNodes = anyExpandedNodes | shouldExpand;
}
}
// Expand this container if any of it's nodes
// are expanded
setExpanded( ctrIndex, anyExpandedNodes );
}
}
// these don't seem to make any difference
updateGeometries();
viewport()->update();
update();
}
void JasperView::expandNonDefaultNodes()
{
// If I uncomment this, I don't get the QPainter warnings
// and ALL the nodes are expanded..
//expandAll();
//return;
QAbstractItemModel *mdl = model();
QModelIndex rootNdx = rootIndex();
for (int i=0; i < mdl->rowCount( rootNdx ); ++i)
{
QModelIndex ctrIndex = mdl->index( i, 0, rootNdx );
BlockTreeItem *item = getItem( ctrIndex );
// For binds, just expand so the fcalls are visible (for now)
BindBlockItem *bindBlock = dynamic_cast<BindBlockItem*>( item );
if (bindBlock)
{
setExpanded( ctrIndex, true );
}
// For functions, expand out any nodes with non-default values
FuncBlockItem *funcBlock = dynamic_cast<FuncBlockItem*>( item );
if (funcBlock)
{
bool anyExpandedNodes = false;
for (int j=0; j < mdl->rowCount( ctrIndex ); ++j )
{
QModelIndex nodeIndex = mdl->index( j, 0, ctrIndex );
ParamNodeItem *nodeItem = dynamic_cast<ParamNodeItem*>( getItem( nodeIndex ) );
ParamNode *node = nodeItem->block();
if (node)
{
bool shouldExpand = node->anyChangesFromDefault();
setExpanded( nodeIndex, shouldExpand );
anyExpandedNodes = anyExpandedNodes | shouldExpand;
}
}
// Expand this container if any of it's nodes
// are expanded
setExpanded( ctrIndex, anyExpandedNodes );
}
}
// these don't seem to make any difference
updateGeometries();
viewport()->update();
update();
}
To copy to clipboard, switch view to plain text mode
I've tried replacing the setExpanded() calls with expand() but it does the same thing. I have verified that the setExpandeds actually get called.
One other little detail, I was calling this from my openFile, after I loaded the model data and did a setModel. That resulted in nothing expanding (again, expandAll works). I'm now calling it with this:
QTimer::singleShot( 0, ui.
treeView,
SLOT(expandNonDefaultNodes
()) );
QTimer::singleShot( 0, ui.treeView, SLOT(expandNonDefaultNodes()) );
To copy to clipboard, switch view to plain text mode
And it works, but i get the warnings. Same thing if I call it from a QAction.
this is qt 4.5.0, btw.
Bookmarks