Page 1 of 1

Sort and filter models

PostPosted: Wed May 11, 2016 3:45 pm
by JoanneC
Hi,

I'm trying to implement a sortable/ filterable list in QML using QxOrm model view generated classes. I'd like to be able to have a solution like that given by QSortFilterProxyModel, which sets sort/ filter roles... and works seamlessly with QML TableView and TreeView.

Is there an 'easy' way to do this in QxOrm without re-querying every time the criteria change?

Thanks

Re: Sort and filter models

PostPosted: Wed May 11, 2016 7:09 pm
by qxorm
Hello,

I see 2 solutions to sort/filter the model :

1- I think the easiest way is to send a SQL query to your SGBD which return sorted/filtered data you need : so instead of qxFetchAll() method, you could use qxFetchByQuery() method with a SQL query.

2- All QxOrm models inherit from qx::IxModel base class/interface, which inherit from QAbstractItemModel Qt class : so all QxOrm models are Qt models.
So the QSortFilterProxyModel Qt class (which is a just wrapper to an existing model) can be a good solution to implement sort/filter feature : http://doc.qt.io/qt-5/qsortfilterproxymodel.html
But you have to create a QSortFilterProxyModel sub-class yourself, QxOrm library doesn't provide any class for that.
You can find 2 examples on Qt web site :
- http://doc.qt.io/qt-5/qtwidgets-itemvie ... ample.html
- http://doc.qt.io/qt-5/qtwidgets-itemvie ... ample.html

If you choose this second solution and need some help, I think a Qt forum is a better place to ask questions about Qt model/view features.

Re: Sort and filter models

PostPosted: Thu May 12, 2016 7:42 am
by qxorm
I found a third solution using DelegateModelGroup in this great article : http://imaginativethinking.ca/use-qt-qu ... odelgroup/

The second part of this article is the most interesting, because it shows how to use DelegateModelGroup with C++ models.
The get() method in this article could be replaced by the qx::IxModel::getModelValue() method.