Questions about QAbstractTableModel and QSortFilterProxyModel usage
-
Hello!
I'm new to the model/view system and I'm trying to implement a data entity list
using it. I have two list (a local and a global one), which I want to be shown merged
in one list. This list should show a list of all available data entities of
these two list (in particular only the name) and if I double click on it, a new
dialog pops up, where I can edit the entity's data.Because this list can be long, I wanted it sorted and (optional) filtered. So I
used a proxy model.You can find the example source code under:
"http://pastebin.com/Z0YKmc99":http://pastebin.com/Z0YKmc99
Now my questions:
Is it the right way to implement this, as I done it?
Or is there a better way? (Maybe I doing it fundamentally wrong?!)
In my code I cannot select the sorting order. I used
_proxyModel->sort(1, Qt::AscendingOrder);_ on the newly created proxyModel in my code, but it's always ordered descending. Why?
If I add or change an entry, the list is not reordered. If I use
reset(), I will loose the selection. What's wrong here?
If I delete an entry, I call "beginResetModel()" and "endResetModel()".
Is there a better way to force a correct update of the list?
Any answers or hints welcome...
Regards
Sven -
Does nobody have any hints or answers?
-
Hi,
Just a quick look at your code, but for option 4:
There are also "beginRemoveRows(const QModelIndex &, int, int)" and thus with the index you only have the view update the selected rows. The same goes for columns.
When you have an editable model you should not use the dynamicsort option (read the doc!), but rather use the sort function!
Sorry, no more time to go into depth! -
[quote author="Jeroentje@home" date="1404981797"]
JWhen you have an editable model you should not use the dynamicsort option (read the doc!), but rather use the sort function!
Sorry, no more time to go into depth![/quote]Hmmm...
I thought this only applies, if I edit the data in the list/table itself.The documentation states the following:
bq. By default, the model dynamically re-sorts and re-filters data whenever the original model changes. This behavior can be changed by setting the dynamicSortFilter property.
Because I changed the data in the model, I thought this would be propagated upwards. But how should the ListModel (QAbstractTableModel) know about the change? Therefore I tried to use "emit model->dataChanged(...)" but I did not work either.
How do I signal the ListModel (& ProxyModel), that the underlying data has changed?
At this point I think I made something fudamentally wrong...
-
[quote author="Jeroentje@home" date="1404981797"]Hi,
Just a quick look at your code, but for option 4:
There are also "beginRemoveRows(const QModelIndex &, int, int)" and thus with the index you only have the view update the selected rows. The same goes for columns.
[/quote]You'll find that in my code too (line 140 in main.c). I commented it out, because it did not work. If it should work, what I'm doing wrong here?