PDA

View Full Version : Mirror nodes in QTreeView - reuse of QStandardItem fail



muenalan
13th January 2011, 14:13
I want to represent a tree which has nodes that are/stay identical, but placed somewhere else:



-+- John
'--+ Company A
'----- Current Stockprice: 10
-+- Jane
'--+ Company A
'----- Current Stockprice: 10

Say i want the "Company A" node with its children to be actually a single node.
Means it is identical also after updates (changes in one instance will affect all others). Its not an option to optimize it by reversing parent child hierarchy.

I tried it with a QStandardItem, but failed:



QStandardItemModel
*simodel = new QStandardItemModel;

QStandardItem
*root1 = new QStandardItem( "John" ),
*root2 = new QStandardItem( "Jane" ),
*leaf = new QStandardItem( "Company A" )
;

root1->appendRow( leaf );
root2->appendRow( leaf );

simodel->invisibleRootItem()->appendRow( root1 );
simodel->invisibleRootItem()->appendRow( root2 );

QTreeView *tview = new QTreeView;
tview->setModel( simodel );
tview->show();

return app.exec();


Gui shows:



-+- John
'--+ Company A
-+- Jane
'--+ ~ <Some dead node which is not rendered>


Terminal output:
QStandardItem::insertRows: Ignoring duplicate insertion of item 0x9170758



Any hints whether this is doable with a QStandarditemModel or a custom QTreeView subclass ? The problem is remiscent of the Interview qtdemo, but I would need whole subtree's duplicated instead of single nodes.