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
-+- John
'--+ Company A
'----- Current Stockprice: 10
-+- Jane
'--+ Company A
'----- Current Stockprice: 10
To copy to clipboard, switch view to plain text mode
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:
;
root1->appendRow( leaf );
root2->appendRow( leaf );
simodel->invisibleRootItem()->appendRow( root1 );
simodel->invisibleRootItem()->appendRow( root2 );
tview->setModel( simodel );
tview->show();
return app.exec();
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();
To copy to clipboard, switch view to plain text mode
Gui shows:
-+- John
'--+ Company A
-+- Jane
'--+ ~ <Some dead node which is not rendered>
-+- John
'--+ Company A
-+- Jane
'--+ ~ <Some dead node which is not rendered>
To copy to clipboard, switch view to plain text mode
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.
Bookmarks