Hi,
I'm trying to develope a complex Model with different Proxymodels. The Main-Model is a Tree with different Items based on a ItemBaseClass.
The first Proxymodel is a QSortFilterProxyModel for the tree-Navigation-Widget. This works.
Tree:
-Item1
---sub1
---subsub1
---subsub2
---sub2
-Item2
---sub3
Table of sub1:
subsub1-name | subsub1-property
subsub2-name | subsub2-property
Tree:
-Item1
---sub1
---subsub1
---subsub2
---sub2
-Item2
---sub3
Table of sub1:
subsub1-name | subsub1-property
subsub2-name | subsub2-property
To copy to clipboard, switch view to plain text mode
The second Proxymodel is to show and edit a TreeItem with subElements in a table.
This works a bit. The Elements are shown in the table, but I cannot insert or delete rows.
My problem is that I do not know how to implement the MapToSource/MapFromSource methods..
So here are my simple implementations:
return index(source.row(), source.column(), source.parent());
}
if(!proxy.isValid())
{
}
return sourceModel()->index(proxy.row(), proxy.column(), proxy.parent() ) ;
}
QModelIndex TFSEditorItemModel::mapFromSource(const QModelIndex &source) const{
return index(source.row(), source.column(), source.parent());
}
QModelIndex TFSEditorItemModel::mapToSource(const QModelIndex &proxy) const {
if(!proxy.isValid())
{
return QModelIndex();
}
return sourceModel()->index(proxy.row(), proxy.column(), proxy.parent() ) ;
}
To copy to clipboard, switch view to plain text mode
If I try to use mapToSource e.g. to insert a row through the sourceModel, I never get a correct sourceIndex. Especally the proxy.parent-Index is not valid, so the sourceModel cannot create a valid Index in the sourcetree.
How can I get an index of the table-root-item from the sourceModel? I have a Pointer to the Item (the tables root-item) but no Index. I think I cannot remember this Index because it can change..?
I hiope you can help me or give a reference to a good example. I tried to find something, but the results did not help me.
greets
david
Bookmarks