PDA

View Full Version : Proxymodel Sort , After Filter



RameshNani
18th December 2014, 13:17
Hi ,

I am using QSortfilterProxyModel , And when i filter on any column in QTableView , I am calling setFilterRegExp(QString) .

The Filter working fine , But when i try to sort other column after filter the data dissappear, My thougt the sort working on other column with given filter text .
But i want to sort filtered data in all columns .Help Me anyone .

RameshNani
18th December 2014, 13:50
Hi ,

I need multi column filter functionality , Means , I am using QSortFilterProxyModel, Suppose I have 50 rows of data , And When I filter on 1st column I got 20 rows of data , and When I filter on other column The data will filter from 20 rows data . Is it possible , If possible , can any one post the sample code .

Thanks

anda_skoa
18th December 2014, 15:19
You can always try to derive from QSortFilterProxyModel and implement filterAcceptsRow()

Cheers,
_

RameshNani
19th December 2014, 07:41
You mean , can I customize QSortfilterproxymodel .

anda_skoa
19th December 2014, 08:38
Exactly.

Cheers,
_

RameshNani
19th December 2014, 09:29
This is for MultiColumnFilter Right ?

But , After Filter on any column , Can i sort on any other column on filtered data , is it possible , with out Customise QSortfilterProxyModel .
Could you send any sample code for implement filterAcceptrows() function .

Added after 16 minutes:

I would like to do simple functionality using QSortFilterProxymodel , After filter on one column , i would like to sort on other column , but filtered text applied on sorting column .

Means The data like below after filter i am filter with "xx" on A column
Columns A B C

XXA 100 SS
XXB 120 QQ
XXC 90 RR

I applied filter on A Column , Now i would like to sort B ,column by clicking on B column ,

I want data like

A B
XXC 90
XXA 100

But the XX filter also applied on B column when i sort , but i want only sort on B column . Could any one Help us .
XXB 120

anda_skoa
19th December 2014, 10:07
Show us your filterAcceptsRow() implementation.
Maybe you are not checking the column of the index correctly.

Cheers,
_

RameshNani
26th December 2014, 10:09
Hi , Am facing the problem with how to start implementation of filterAcceptsRow() , means with out customize qsortfilterproxymodel , is it not possible to implement what ever we have to implement in filter accepts row ?
My question is what code i would do in filteracceptrow() function , I would like to apply different filter on different columns , is it possible , if possible , could you please guide me with sample code , how to implement filteracceptsrow() , looks like the filteracceptsrow returns which ever rows satisfy current regular exp , but my point of view i would like to apply filter on one column , and i would like to apply different filter on different column with filtered data .

anda_skoa
26th December 2014, 10:56
It is a function that gets a row index and returns a boolean.
When it returns true the row of the given index is part of the result set, if it returns false the row will not show up.

Your implementation can make that decision on whatever criteria you like.



bool MySortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex & source_parent) const
{
return source_row % 2 == 1; // accept every second row
}


Cheers,
_

RameshNani
2nd January 2015, 11:39
I want to apply filter on some rows which are comes up from first Filter .
So can I send all indexes to this filteracceptsrow function ?
But , How can I identify which rows are having Previous filter ?

anda_skoa
2nd January 2015, 12:48
The function is already called for all rows, no need to do any calling yourself.

In side that function you can decide if you want to accept the given row.
How you determine that is of no concern to the proxy's base implementation.
If you decide to use values from multiple columns then that is what you need to do.

Alternatively, if your current level of C++ does not allow you to come up with code that compares multiple values in order, you could use a chain of proxies, each filtering on one criteria.

Cheers,
_

RameshNani
28th January 2015, 06:05
Hi All,

Thanks for your replies , My issue solved now. am implemented filteracceptsrow . thanking you for all .