@d_stranz: can you give me an example how you implemented the mapping foe your problem by subclassing the QAbstractProxyModel. It would help me alot to understand how to reimplement the required methods. Thanks
Added after 1 41 minutes:
But the QSortFilterProxyModel is subclassed from QAbstractProxyModel and it also works with a generic three model. If you dont filter anything, you get the original data from your source model, isn't it ? Can you explain your statement further? I really want to understand, especially whyThe only way to make generic tree models work through a proxy is to subclass either QIdentityProxyModel or QSortFilterProxyModel. In a general case going by subclassing QAbstractProxyModel will not work because there is no way to reliably reimplement parent().
As you stated in the previous replies, I cannot use QSortFilterProxyModel to do the mapping because it uses its own I cannot reimplement the maptoSource and mapFromSource methods, so for a non-generic tree model I have to subclass QAbstractProxyModel to do the mapping.
My problem in the following is rather simple for experienced Qt persons I think. But I do not really know how to start, especially the parent() & index() method
A tree model subclassed by QStandardItemModel.
Name--------------|Value-----|--SpecialValue
A --------------------------------------
|- B------------------------------------
---|-par1----------|---111----|
-------|par1.1-----|---1.1-----|
----|-par2---------|---222-----|
----|-parSpe-------|---XXX----|
----|-par3---------|---333-----|
-|-C---------------|------------
---|-D-------------|------------
----|--E-----------|-----------
-------|-par4 -----|--444-----|
-------|-par5 -----|--555-----|
----------|-par5.1-|--555.111-|
-------|-par6 -----|-----------|
-------|-parSpe---|--ZZZ-----|
-------|-par7 -----|--777-----|
I want to map the value XYZ of the "parSpe" item to the column "SpecialValue" of its parent, e.g of item "B" or "E" in this case. The item "parSpe" itself will not be displayed.
Name--------------|Value-----|--SpecialValue
A --------------------------------------
|- B---------------|----------|----XXX---
---|-par1----------|---111----|-------------
-------|par1.1-----|---1.1-----|--------------
----|-par2---------|---222-----|--------------
----|-par3---------|---333-----|--------------
-|-C---------------|-------------------------
---|-D-------------|-------------------------
----|--E-----------|-----------|-----ZZZ
-------|-par4 -----|--444-----|--------------
-------|-par5 -----|--555-----|--------------
----------|-par5.1-|--555.111-|--------------
-------|-par6 -----|-----------|--------------
-------|-par7 -----|--777-----|--------------
The upper level item A B C D E dont have any further items on column "Value" and "SpecialValue" per default. The column "SpecialValue" is thus a vitual column.
The hierahchy level of the items "parSpe" is not fix but the item "parSpe" itself can be detected by data(QtUserRole +x).
The row number of item "parSpe" is not fix, so I intend to code its row number during mapFromSource() (or after building the source tree) with setData(), so that I have a chance to map it back. Is it ok?
Is it a correct approach to subclass QAbstractProxyModel to solve this problem?
Can someone give me an example how to proceed? especially the parent() & index() method
Thanks in advance
Bookmarks