Sort and filter models

Forum for posting problems using QxOrm library

Sort and filter models

Postby JoanneC » Wed May 11, 2016 3:45 pm

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
JoanneC
 
Posts: 3
Joined: Wed May 11, 2016 1:50 pm

Re: Sort and filter models

Postby qxorm » Wed May 11, 2016 7:09 pm

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.
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: Sort and filter models

Postby qxorm » Thu May 12, 2016 7:42 am

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.
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 16 guests