I want to get the Min and Max values of QStandardItemModel.
-
appendRow to the value of QStandardItemModel.
I want to get the Min and Max values based on the column line.Do I have to access the index every time to find Min and Max? Please let me know if there is a simpler way
@IknowQT said in I want to get the Min and Max values of QStandardItemModel.:
Do I have to access the index every time to find Min and Max?
Yes
-
appendRow to the value of QStandardItemModel.
I want to get the Min and Max values based on the column line.Do I have to access the index every time to find Min and Max? Please let me know if there is a simpler way
@IknowQT
There are 3 ways you can accomplish this:-
Visit every index to determine the min/max in a column. This is presumably the way databases implement
MIN/MAX(column), unlesscolumnhas a databaseINDEXon it. -
Add a
QSortFilterProxyModelon top of theQStandardItemModel, sorted by the numeric desired column. EnsuredynamicSortFilteris on, so that it retains the correct, updated sort order when you add a row. Then you know you want the first and the last indexes into the sort filter proxy model. -
Maintain your own
min&maxvariables, presumably in a subclass of theQStandardItemModel. Initially calculate them by visiting every index. When you append a row you only need to compare that against your currentmin/maxvariables to see if they need updating. Be careful to clear them out and recalculate if you re-fill the model, change its other rows' values, or similar.
-