Backend data not stablized of QAbstractListModel/QListView: increasing performance.
I'm building a qt filebrowser to list entries in a certain directory. For this purpose it connects to a cache of entries I've been working, specially for this purpose. This cache is managed by notifyfs, which also handles the setting of watches.
By combining the cache with the handling of the watches, it's possible to keep the cache up to date in a pretty easy manner
(of course only in these directories where a watch has been set upon). Now I'm also working on making watches work with network (cifs, nfs) and fuse filesystems (sshfs, webdavfs etc).
One reason for me to create notifyfs is to tackle performance problems when loading networkfilesystems in Dolphin, another is to make the watching of fs objects work with network and fuse fs's.
Now I've got the QListView and the QAbstractListModel working, but it only works when the backend is stable, which means that the building of the index only can start AFTER the cache is up to date. For example:
when selecting another directory, which is not yet in the cache, say for example my homedirectory. There are a lot of directories and files there, so the loading this directory in cache (syncing) requires some time. The way to go is to set a watch rightaway on that directory. Now it looks like I cannot make QAbstractListModel process entries (=start creating an index) at the same time, but only AFTER the cache is up to date. This is a big issue. I hoped it was possible to make notifyfs push entries to the model/view. It looks like the current model/view implementation in qt assumes that the backend data is stable, and that is not the case when a direcory which is not yet in cache is selected.
I hoped that in that unstable phase it would be possible that notifyfs can push entries to the QAbstractListModel. Note that after selecting a new directory (like in the example FetchMore) which is not yet in the cache, the rowcount is zero.
Right after that the first "phase" (as I call it) starts:
a. every entry which notifyfs detects in the underlying fs and adds to the cache, is pushed to QAbstractListModel till the view is full (no empty rows anymore). A certain order is maintained (alphabetic on name, directories first, no entries starting with a dot)
When "full" the second phase starts:
b. when there are no empty rows anymore, only entries are pushed to the model when they "fit" into the view and will be displayed when taking the order into account.
So this gives the view/model an unstable phase while it builds the view.
My question is now: is it possible to build a view this way, dynamically?? Required is that the model can determine the number of entries loaded, and when all rows are full, the first entry and the last entry.
Note that webpages are loaded this way. They are also build out of different components, and there is always
a period, starting from an empty page to a fully loaded page, and the loading is ready.
I am not sure I have understood the question fully. But views are dynamic. And you can insert item in your model anytime you want. You just have to make sure that you emit necessary signals while updating your model with new entries. Generally calling begin*() and end*() class of functions from QAbstractItemModel is enough to guarantee right behaviour.
Thanks for reply. I follow the suggestions/idea's I got here:
I first posted there, now here.
I understand that when an entry is added, the way to update the model is by calling
the beginInsertRow/endInsertRow functions.
Now these functions require a row as parameter (first and last row). I want the data in de model/view to be ordered the exact same way as it is ordered in the underlying data source.
So I cannot just add the data at the end, but at a certain row right??
those are first and last rows of the inserted items. They can be same also. The documentation has example also. You can insert anywhere in the model.