November 26, 2010

Gerolf Gerolf
Robot Herder
3252 posts

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 7
it is not needed 5
Total Votes: 18
You must be a logged-in member to vote

Hi,

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

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

13 replies

November 26, 2010

Franzk Franzk
Lab Rat
830 posts

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?

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

November 26, 2010

Gerolf Gerolf
Robot Herder
3252 posts

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…

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

November 27, 2010

Volker Volker
Ant Farmer
5428 posts

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.

November 27, 2010

Gerolf Gerolf
Robot Herder
3252 posts

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…

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

November 27, 2010

Denis Kormalev Denis Kormalev
Lab Rat
1654 posts

hm, why number two and number three are identical? Typo? As I understood number two should be about columns.

November 27, 2010

Gerolf Gerolf
Robot Herder
3252 posts

Hi,

sorry you are right, number 2 should be columns :-) But how can I change the text of a poll?

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

November 27, 2010

Denis Kormalev Denis Kormalev
Lab Rat
1654 posts

Gerolf Reinwardt wrote:
Hi,

sorry you are right, number 2 should be columns :-) But how can I change the text of a poll?

Done.

November 27, 2010

Volker Volker
Ant Farmer
5428 posts

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 :-)

November 27, 2010

Gerolf Gerolf
Robot Herder
3252 posts

Hi,
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 :-)

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

November 27, 2010

Volker Volker
Ant Farmer
5428 posts

IMHO it breaks the contract that was made in QAbstractProxyModel (returning an invalid QModelIndex in the context of the source model for a valid index in the proxa model) and is therefore not subject for a public API resp. the Qt libs. This might be better placed in a Qt solutions site.

November 28, 2010

Tobias Hunger Tobias Hunger
Robot Herder
3386 posts

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:-)

December 1, 2010

Andre Andre
Robot Herder
6393 posts

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.

December 6, 2010

Denis Kormalev Denis Kormalev
Lab Rat
1654 posts

Closed after authors request.

 
  ‹‹ Extension the views (Table / Tree)      Excel API for C/C++ ››

You must log in to post a reply. Not a member yet? Register here!