Extension to QSortFilterProxyModel
|Is adding rows / columns (for auto filtering) needed?|
|addin additional rows in a proxy model is needed||3|
|addin additional columns in a proxy model is needed||3|
|addin additional rows/columns in a proxy model is needed||6|
|it is not needed||5|
|Total Votes: 17||
You must be a logged-in member to vote
it would be nice if the main implementation for sorting and filtering models would enable adding of rows / columsn in the beginning / end. This would be useful to add something like an auto filter row to a model (like in Excel —> auto filter). But this implementation does not enable adding of rows. The only sollution I found (together with the Qt support) was to copy QSortFilterProxyModel and to change the code. But that means, for each new release, I have to check the changes :-(. This would be a helpful feature. Especially, as it is not so easy to write a generic proxy from scartch (QAbstractProxyModel) that does it including filtering (and perhaps sorting). And adding this to the base model is not what I expect. This would be functionality, I would like to be able to add to any model.
What do you think about that?
edit: poll answer #2 fixed / Denis Kormalev
This would mean that the proxy model contains data that is not in the source model? I’m not familiar with Excel (and I intend to keep it that way), so I don’t know the auto filter row thingy you’re talking about. Would it be the same as the effects of the dynamicSortFilter property of the QSortFilterProxyModel?
would be something like that but a bit more.
What is needed for that is the following:
switch ion aut foilter means adding a row on the top. This row is used to enter filters for the different columns. HOw the filters are used, depends on the implementations. some add reg exps via line edits, some display a combo box that contain all values of the cells of the row, and only rows with the selected value are displayed.
This could be implemented in the base model that conatains the real values, but that would mean combinang a base m,odel with a filter proxy by logic. Thats not really good…
One can already insert rows and columns with a proxy model. The default implementation delegates this to the underlying source model.
If I correctly understand what you want, is a kind of fixed row ahead the filtered rows. I think this is nothing that the QSortFilterProxyModel should provide as it’s too specialized. That would better be left to a special purpose proxy model.
But if you want to do that in a specialized proxy modelm, you would have to reimplement nearly complete QSortFilterProxyModel, as you need the filtering for that. and the the model also needs to be sorted, you need the full funtionality. And thats a lot of code. If you only do that for one specific source model it’s easy, but we need it for different types of source models…
The specialozed proxy you are talking about would be nearly the same as QSotrtFilterProxyModel, except it can add some rows in the top…
I don’t see any other solution except writing your own specialized proxy model. A generic proxy model within Qt libs should have expectable behavior. One of this is that each and every data you get out of the proxy model is contained in the source model. If you had rows only existing in the proxy model but not in the source model, this would break expectable behavior. And, what should QAbstractProxyModel::mapToSource() [doc.trolltech.com] return in this case?
Regarding the coding effort: You can grab the sources of QSortFilterProxyModel and modify it for your needs. As long as you just copy and modify it and it works for you (using the index mappings etc.), you need not worry about the Trolls changing the implementation in future versions of Qt because you have all the code in your own files. Althogh a short diff on the two versions might be a good idea, just in case the trolls fixed some bugs :-)
I already did that, and it works. But why not have such a sollution in the base? Perhaps a second proxy for such things. And map to source must of course retunr an invalid model index. But I saw also other, who wanted such features. if it is part od QSortFilterProxyModel or part of a second model, does not matter. And addin additional stuff by a proxy (for grouping, auto filters or whatever) is not that bad as an idea I think.
The interesting thing is, do we want another base class or not. Why not add the possibility, to add rows and columns in the front, to be able to implement such features. The auto filtzering should not be part of the Qt implementation, but the prerequisites could be there. If some people don’t need this feature, they needn’t switch it on :-)
As far as I am aware the whole model view framework is meant to cover what 90% of the people need and to allow for everything the other 10% want to do.
I am not sure that it is a good idea to add functionality that is really important if you want to write a spreadsheet… it just adds lots of functionality that all the people who just need to display some data in a table will never need.
Please note that more advanced table views are available… including some that try hard to behave like excel. Just google:-)
I don’t see a role for this in QSFPM at all. If you want to add filtering capabilities in a top row, why not subclass QHeaderView instead? In my opinion, that would be a logical place to put such a thing.
I am not saying that there is no place for a proxy model implementation that can merge data from more than one data source, but QSFPM is not it IMHO.