[Interest] QSortFilterProxyModel filtering on QFileSystemModel

2024-03-19 Thread Sune Vuorela
Hi

I've hitten a 'fun' corner where I found a surprising but documented
feature of QFileSystemModel and discovered how it interacted with
certain QSortFilterProxyModel configurations and QTreeView interactions

Assume the following:

Create a QSortFilterProxyModel with 
setRecursiveFilteringEnabled(true);


create a folder hierachy under /home/yourusername/somefolder:
folder1
 \-- foo
folder2
 \-- bar



set the the filesystem model as source on the proxy model
set the the root path on the filesystemmodel to
/home/yourusername/somefolder
set the treeview root to the root item mapped to the proxymodel


Try set 'foo' as a filter in the QSFPM and see just 

folder1 
 \-- foo

in the view

Try set 'home' as a filter in the QSFPM and see the full view expanded.

This seems to be because 'home' matches the 'home' in the path (because
setRootPath on QFileSystemModel doesn't change the model root node, but
just where the file gatherer is running; and also why you need to both
set the root path on the QFileSystemModel and the mapped index as the
root on the QTreeView)

Does anyone know a workaround or something else I have missed ?

I guess a SubtreeFilteringProxyModel could be what I'm looking for, but
didn't directly find it.

Any pointers anyone?

/Sune

___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] QSortFilterProxyModel issue

2022-05-31 Thread Laszlo Papp
I managed to trim down this to a small testbed that reproduces the issue in
case anyone could have a look. We ought to find out whether it is a Qt bug
or a bug in my code:

https://github.com/lpapp/examples/blob/main/qt-simple-hotkey-editor/hotkeyEditorWidget.cpp

On Sat, May 28, 2022 at 4:32 PM Laszlo Papp  wrote:

> Hi,
>
> I have authored an example keyboard shortcuts editor application. The
> source code is available on my github repository.
>
> It has this auto-expansion issue for the first group for some reason. When
> I am trying to get to action in e.g. Context1 -> Category1 -> then any
> action to select, the first Context0 group expands. If I remove the
> QSortFilterProxyModel use, it does not do that.
>
> Here is a visual gif representation of the issue:
>
> https://imgur.com/a/rxdYmZp
>
> Can anyone spot the issue with my code? The code is available here:
>
>
> https://github.com/lpapp/examples/blob/main/qt-hotkey-editor/hotkeyEditorWidget.cpp
>
> Thank you in advance.
>
> Kind regards,
> László
>
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


[Interest] QSortFilterProxyModel issue

2022-05-28 Thread Laszlo Papp
Hi,

I have authored an example keyboard shortcuts editor application. The
source code is available on my github repository.

It has this auto-expansion issue for the first group for some reason. When
I am trying to get to action in e.g. Context1 -> Category1 -> then any
action to select, the first Context0 group expands. If I remove the
QSortFilterProxyModel use, it does not do that.

Here is a visual gif representation of the issue:

https://imgur.com/a/rxdYmZp

Can anyone spot the issue with my code? The code is available here:

https://github.com/lpapp/examples/blob/main/qt-hotkey-editor/hotkeyEditorWidget.cpp

Thank you in advance.

Kind regards,
László
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] QSortFilterProxyModel

2019-02-19 Thread Giuseppe D'Angelo via Interest

Il 19/02/19 16:48, Christopher Probst ha scritto:
Thank you Nils. My question may have have been incomplete. I am looking 
to filter the model through a regular expression on data contained in 
the header. I am not sure the method you suggested is the appropriate 
one. But it will certainly help.


Something that would ideally look like void  setFilterKeyColumn(int 
column), where I have a column number that represents the vertical header.


I'm not 100% sure I understood what you need, but here's an idea.



Make your model return the header data you want to filter upon as some 
"hidden" role of come column. Then put a QSFPM on top, filtering on that 
column and that hidden role.


If you can't modify the source model, place a QIdentityProxyModel in the 
middle with a custom data() override.


HTH,
--
Giuseppe D'Angelo | giuseppe.dang...@kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts



smime.p7s
Description: Firma crittografica S/MIME
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] QSortFilterProxyModel

2019-02-19 Thread Christopher Probst
Thank you Nils. My question may have have been incomplete. I am looking to
filter the model through a regular expression on data contained in the
header. I am not sure the method you suggested is the appropriate one. But
it will certainly help.

Something that would ideally look like void  setFilterKeyColumn(int
column), where I have a column number that represents the vertical header.

Thanks,
Christopher

On Tue, 19 Feb 2019 at 01:40, Nils Jeisecke 
wrote:

> Hi,
>
> Am 18.02.2019 um 16:49 hat Christopher Probst geschrieben:
> > Does anybody know if it Is possible to use QSortFilterProxy to filter
> over
> > data that is in vertical the header?
> you mean QSortFilterProxyModel::filterAcceptsColumn?
>
> Nils
>
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] QSortFilterProxyModel

2019-02-18 Thread Nils Jeisecke via Interest
Hi,

Am 18.02.2019 um 16:49 hat Christopher Probst geschrieben:
> Does anybody know if it Is possible to use QSortFilterProxy to filter over
> data that is in vertical the header?
you mean QSortFilterProxyModel::filterAcceptsColumn?

Nils
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


[Interest] QSortFilterProxyModel

2019-02-18 Thread Christopher Probst
Hello Everybody.

Does anybody know if it Is possible to use QSortFilterProxy to filter over
data that is in vertical the header?

Thanks,
Christopher
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] QSortFilterProxyModel and Exceptions

2017-11-14 Thread Nuno Santos
William,

Thanks for your reply and for your tip.

Got it! 

Best regards,

Nuno

> On 14 Nov 2017, at 11:05, william.croc...@analog.com wrote:
> 
> On 11/14/2017 05:46 AM, Nuno Santos wrote:
>> Hi,
>> 
>> I’m using QSortFilterProxyModel to sort a data model ascending and 
>> descending.
>> 
>> I wanted to create an exception to make a single item always appear at the 
>> beginning of the filtered model, bypassing the sort.
>> 
>> Does anyone knows if this is possible?
>> 
> 
> Build that special case into your lessThan() function.
> 
>> Thx!
>> 
>> Regards,
>> 
>> Nuno
>> ___
>> Interest mailing list
>> Interest@qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>> 
> 
> ___
> Interest mailing list
> Interest@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] QSortFilterProxyModel and Exceptions

2017-11-14 Thread william.croc...@analog.com

On 11/14/2017 05:46 AM, Nuno Santos wrote:

Hi,

I’m using QSortFilterProxyModel to sort a data model ascending and descending.

I wanted to create an exception to make a single item always appear at the 
beginning of the filtered model, bypassing the sort.

Does anyone knows if this is possible?



Build that special case into your lessThan() function.


Thx!

Regards,

Nuno
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest



___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


[Interest] QSortFilterProxyModel and Exceptions

2017-11-14 Thread Nuno Santos
Hi,

I’m using QSortFilterProxyModel to sort a data model ascending and descending.

I wanted to create an exception to make a single item always appear at the 
beginning of the filtered model, bypassing the sort.

Does anyone knows if this is possible?

Thx!

Regards,

Nuno
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


[Interest] QSortFilterProxyModel and lazily populated treeviews

2014-09-08 Thread Hemant Kumar
Hello,

I have implemented a lazily populated treeview by subclassing
QAbstractItemModel. The implementation looks something like:

https://gist.github.com/gnufied/db9c4d805e2bb24d8c23

(I am not pasting code inline, so as to mess with messaging)

It is basically a tree representation of hierarchical data stored in table.
 Now, I want users to be able to sort the rows based on columns. Where
columns are, count or reference count. These values are basically
integers.

The implementation on its own works, until I throw in QSortFilterProxyModel
and I start to get lots of empty rows in the view. The hard problem is,
this tends to happen only when I have lots of rows (like thousands or so).

The code for implementing sorting proxy is:

rootItem =
RBKit::SqlConnectionPool::getInstance()-rootOfSnapshot(snapShotVersion);
model = new RBKit::HeapDataModel(rootItem, this);
proxyModel = new SortObjectProxyModel(this);
proxyModel-setSourceModel(model);
ui-treeView-setModel(proxyModel);
ui-treeView-setSortingEnabled(true);

I have subclassed QSortFilterProxyModel class and subclass implementation
is really simple:


https://gist.github.com/gnufied/115f1a4fae3538534511

The documentation does say -

This simple proxying mechanism may need to be overridden for source models
with more complex behavior; for example, if the source model provides a
custom hasChildren
qthelp://org.qt-project.qtcore.531/qtcore/qsortfilterproxymodel.html#hasChildren()
implementation, you should also provide one in the proxy model.

But beyond that, I am not sure - what I am missing.
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] QSortFilterProxyModel::removeRows()

2012-06-01 Thread Jordi Pujol
El dv 01 de 06 de 2012 a les 14:15 +0900, en/na Paul England va
escriure:
 Hi
 
 I wrote this really long email, and learned a lot about the problem in
 doing so.  So, I guess it was time well spent.  Still frustrated.
 Here's the summed up problem:
 
 I have a QAbstrctTabelModel, QSortFilterProxyModel, QItemDelegate, and
 a QTableView (all subclassed).  As you'd expect, the
 QSortFilterProxyModel filters out what I don't want, the delegate
 paints what I do, and the view displays everything.  Some rows are
 updated, and based on user-defined criteria, need to be removed
 *AFTER* the proxy  has let them in.  Before, I was calling
 invalidate() in the proxy, but that was calling filterAcceptsRow() on
 all rows (visible or not).  Yikes.  So, I'm now doing removeRows() for
 the row(s) that must be removed.
 
 Caveat: my subclassed delegate's paint() is being passed a
 QModelIndex() with the *old* data.
 
 Example, my rows are.
 Harry
 Larry
 Bob
 
 bool my_proxy::removeRows( int row, int count, const QModelIndex )
 {
 
 beginRemoveRows( QModelIndex(), row, count + row - 1 );
 // remove data from model here
 endRemoveRows();
 
 }
 
 if I do:
 removeRows( 2, 1 );
 
 My model will then show it only has two items. 
 Harry and Bob
 
 HOWEVER, for the subsequent call to my_delegeate::paint( QPainter*,
 const QStyledOptionViewItem opt, const QModelIndex index ) will have
 the old index.  paint will be called twice, and
 index.data().toString() will have Harry for the 1st one, and Larry for
 the 2nd.  
 
 Am I missing something?
 Thanks

Perhaps the fact that indexes are 0-based ?

0 - Harry
1 - Larry
2 - Bob

So if you call removeRows( 2, 1 ); you're removing Bob, as expected...

___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] QSortFilterProxyModel::removeRows()

2012-06-01 Thread Paul England


On 06/01/2012 03:01 PM, Jordi Pujol wrote:
 El dv 01 de 06 de 2012 a les 14:15 +0900, en/na Paul England va
 escriure:
 Hi

 I wrote this really long email, and learned a lot about the problem in
 doing so.  So, I guess it was time well spent.  Still frustrated.
 Here's the summed up problem:

 I have a QAbstrctTabelModel, QSortFilterProxyModel, QItemDelegate, and
 a QTableView (all subclassed).  As you'd expect, the
 QSortFilterProxyModel filters out what I don't want, the delegate
 paints what I do, and the view displays everything.  Some rows are
 updated, and based on user-defined criteria, need to be removed
 *AFTER* the proxy  has let them in.  Before, I was calling
 invalidate() in the proxy, but that was calling filterAcceptsRow() on
 all rows (visible or not).  Yikes.  So, I'm now doing removeRows() for
 the row(s) that must be removed.

 Caveat: my subclassed delegate's paint() is being passed a
 QModelIndex() with the *old* data.

 Example, my rows are.
 Harry
 Larry
 Bob

 bool my_proxy::removeRows( int row, int count, const QModelIndex )
 {

 beginRemoveRows( QModelIndex(), row, count + row - 1 );
 // remove data from model here
 endRemoveRows();

 }
 men
 if I do:
 removeRows( 2, 1 );

 My model will then show it only has two items. 
 Harry and Bob

 HOWEVER, for the subsequent call to my_delegeate::paint( QPainter*,
 const QStyledOptionViewItem opt, const QModelIndex index ) will have
 the old index.  paint will be called twice, and
 index.data().toString() will have Harry for the 1st one, and Larry for
 the 2nd.  

 Am I missing something?
 Thanks
 Perhaps the fact that indexes are 0-based ?

 0 - Harry
 1 - Larry
 2 - Bob

 So if you call removeRows( 2, 1 ); you're removing Bob, as expected...

Sorry for not being clear.   I am taking the 0-based index into
account.  removeRows should actually pass 1,1 in that case.

I know that it's not working b/c when paint is called, I grab the
underlying data structure that supposedly changed (indexed by row).  I'm
checking it against QModelIndex::data() within paint() and they do not
match. 
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


[Interest] QSortFilterProxyModel::removeRows()

2012-05-31 Thread Paul England
Hi

I wrote this really long email, and learned a lot about the problem in
doing so.  So, I guess it was time well spent.  Still frustrated. 
Here's the summed up problem:

I have a QAbstrctTabelModel, QSortFilterProxyModel, QItemDelegate, and a
QTableView (all subclassed).  As you'd expect, the QSortFilterProxyModel
filters out what I don't want, the delegate paints what I do, and the
view displays everything.  Some rows are updated, and based on
user-defined criteria, need to be removed *AFTER* the proxy  has let
them in.  Before, I was calling invalidate() in the proxy, but that was
calling filterAcceptsRow() on all rows (visible or not).  Yikes.  So,
I'm now doing removeRows() for the row(s) that must be removed.

Caveat: my subclassed delegate's paint() is being passed a QModelIndex()
with the *old* data.

Example, my rows are.
Harry
Larry
Bob

bool my_proxy::removeRows( int row, int count, const QModelIndex )
{

beginRemoveRows( QModelIndex(), row, count + row - 1 );
// remove data from model here
endRemoveRows();

}

if I do:
removeRows( 2, 1 );

My model will then show it only has two items.
Harry and Bob

HOWEVER, for the subsequent call to my_delegeate::paint( QPainter*,
const QStyledOptionViewItem opt, const QModelIndex index ) will have
the old index.  paint will be called twice, and index.data().toString()
will have Harry for the 1st one, and Larry for the 2nd. 

Am I missing something?
Thanks
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] QSortFilterProxyModel slow updating sql model attached

2012-05-02 Thread Linos
El 02/05/12 01:51, David Boosalis escribió:
 I've not put much stock in the QSqlQueryModel, but instead done my models
 derived from  QStandardModel.  This requires you to write more code for the 
 SQL
 transactions using QT's SQL module (or your own).  Granted you have to write
 more code and you don't get notices from outside changes to the database. But
 with your own mode,l proxy filters are easier to implement.
 
 Taking it a bit further I create my own database class, which does all the sql
 stuff.  For example part of my Database class looks like this:
 
 
 class Database : public QObject {
   Q_OBJECT
 public:
   enum {OK=0,Error=1,SQL_ERROR,TableDoesNotExists,TableFormatBad,EntryExists,
 EntryDoesNotExists};
 
   typedef  enum {Users,Profiles,UssageLog,Models,...NumOfTables} TableType;
  
   enum {NameSize=32,DescriptionSize=256};
   static QString tableNames[NumOfTables];
   static QString arguments[NumOfTables];
   Database(const QString name,const QString user,const QString pass);
   ~Database();
 
   bool createTable(TableType);
   bool isOpen();
   bool open();
   void close();
   bool tableIsValid(TableType);
   QString getLastError();
   QSqlDatabase *getHandle();
   bool  validateUsersTable();
   bool  updateUser(User *);
   bool  updateUsersExpirationDate(int userID,QDate expirationDate);
   bool  addUser(User *);
   bool  deleteUser(qint32 userID);
   UserList  *getUsers();
 .
 
 
 I don't use the database very much. As a result I can read all the records on
 the application startup, cached the records and then be done with the database
 except for seldom inserts, edits, and deletes.  Maybe this approach will work
 for you.
 
 -David
 
 PS
 One error I've seen with this approach is that my Qt database handle can go
 state after a day, (This code ran on a server). Meaning that all SQL Queries
 fail to talk to the MySQL database.  I got around this by restarting the 
 server
 code every day from my cron file
 

Thanks for the advice, I am doing something more like QSqlRelationalTableModel
in my code but much more powerful, it ends using QSqlQueryModel::data for not
changed (in cache) data, but i can edit multiple tables with joins at the same
time and create the correct sql to submit changes taking in account the cache
and such.

Seems that my implementation it is not the best for sort the table on user
action, maybe i could connect the clicks in header to a proper order by change
in the internal model but then unchanged edits would be lost if i don't commit
the changes before and the filter problem remains, would be much better if
QSortFilterProxyModel would be more efficient.

Regards,
Miguel Angel.
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] QSortFilterProxyModel slow updating sql model attached

2012-04-30 Thread Bo Thorsen
Hi,

My advice is to ditch QSortFilterProxyModel completely. It's great for 
models that can be held in memory. But for SQL models, it sucks.

Bo.

Den 30-04-2012 19:02, Linos skrev:
 Hi,
 i have a QTableView with a QSortFilterProxyModel using a QSqlQueryModel as
 source model, i am using Qt 4.8.1 in Linux x86_64.

 if i don't apply sort to any of the columns of the table and execute a new
 .select() on the QSqlQueryModel it does the usual and only call .data method 
 for
 the visible rows after the new data has been populated but if i have the table
 sorted by any column the data method gets called 56000 times for a 1000 row
 table ever using indexes of the sorted col, i can understand that it is 
 sorting
 at the same it is creating indexes and data.

 The problem it is i can't get it to ignore sorting to do manually after the 
 new
 data is populated in the model. i have tried this:

 1) call table.setSortingEnabled(False) (with proxyModel.setDynamicSortFilter()
 using true and false)
 2) call proxyModel.invalidate() before model.select()
 3) call proxyModel.reset() before model.select()

 I can't think other way to make this right now, i could set a fake model as
 source for the proxymodel before call select in model and set the original 
 model
 after that but it seems awkward to me, should be a better way, so any help
 please? :)

 Regards,
 Miguel Angel.
 ___
 Interest mailing list
 Interest@qt-project.org
 http://lists.qt-project.org/mailman/listinfo/interest


Bo Thorsen,
Fionia Software.

-- 

Expert Qt and C++ developer for hire
Contact me if you need expert Qt help
http://www.fioniasoftware.dk
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest