PDA

View Full Version : Sorting issue



Rui Silva
26th February 2016, 16:53
Hi all,

In my project I have a QTableView which displays the information contained in my data model - 40 rows and 20 columns. That information is updated every 100 miliseconds.


Everything works fine however the application performance decreases a lot everytime column sorting is activated. I use a QSortFilterProxyModel to perform column sorting.

i.e:
If I have 2 windows, each one with an instance of the mentioned tableview, if I sort both tables the UI thread goes from less than 20% to 100% CPU usage ... even if I'm only sorting by the row number, which means, no change in row positions

Is this a common issue?
How can I improve the sorting performance?

Regards

anda_skoa
26th February 2016, 17:00
One option is to sort in the model itself.

As it "knows" the data, it can more easily decide if order of items change when data changes or which rows move where.

Cheers,
_

Rui Silva
27th February 2016, 21:23
Thanks for the tip. But, shouldn't QSortFilterProxyModel be optimized to sort decimals and text strings?

By the way, I'm setting setDynamicSortFilter to true.

anda_skoa
28th February 2016, 10:54
A proxy model doesn't have any structural or semantic knowledge about the data to the source model, it can only perform sorting by applying a standard sorting algorithm.

A model that sorts its on data can use that additional information to avoid applying the sorting agorithm on all data.

Example: the data has a numerical field and you sort by that.
Both approaches have to do the same work for the initial sorting.

Now assume that some function increments all values by the same amount.
The proxy only knows that values have change, it has to re-sort the entire model.
The model itself knows that all values are still in the same order, it doesn't have to do anything.

Cheers,
_