[Qt-interest] incremental model and lazy data population
André Somers
andre at familiesomers.nl
Sun Oct 4 18:24:46 CEST 2009
Hi,
What might be happing is that the view is requesting the data to calculate
the height and width for each item and thus the total list. If you can live
with each item in your list having the same size, you could use
setUniformItemSizes(true) on your view. That *might* stop the listview from
scanning all your items.
André
-----Oorspronkelijk bericht-----
Van: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] Namens Marcos Dione
Verzonden: zondag 4 oktober 2009 15:32
Aan: qt-interest at trolltech.com
Onderwerp: [Qt-interest] incremental model and lazy data population
I'm trying to make a model of a PlayList for a QListView[1], which
should
have two interesting features: it should be able to add items as long as
they're found in the filesystem[2] and to lazily read the metadata in the
audio
files. so what I have is:
* PlayListModel, a QAbstractListModel subclass whichs is a list of
SongModel.
* a CollectionIndexer which scans the collection and emits signals when it
finds sound files.
* a SongModel which reads the metadata only when some attributes are read.
the way it works is: the collection indexer finds new audio files and
adds
them to the playlist, and its data() method reads the SongModel attributes
that
fire the metadata reading. currently I'm trying it with a collection of 5k+
audio files.
what's happening right now is: PLM.data() is being called for every file
found. now, this might be related to the first feature, because I'm
modifying
the model and emiting dataChanged(), but I tried doing it at the end of the
scan and it happens anyways. I tried to read QListView's code and according
to
paintEvent() it calculates the songs shown and calss data() for those items.
i also read http://doc.trolltech.com/4.5/qabstractitemmodel.html which
says: «You can also reimplement hasChildren() to provide special behavior
for
models where the implementation of rowCount() is expensive. This makes it
possible for models to restrict the amount of data requested by views, and
can
be used as a way to implement lazy population of model data», but in my
model
no item has any children. I also read
http://doc.trolltech.com/4.5/model-view-model-subclassing.html#lazy-populati
on-of-model-data,
but again it refers to hasChildren().
in any case, I would like any suggestions on how do all this properly. I
could show you some code, but I have to admint that I'm actually using
PyQt4,
which is a wrapper for pythin, and that all the code is in python. if this
is
not a problem, I can post it here.
--
[1] future implementations would be a QTableView or probably a QTreeView,
but
for now I prefer to keep it as simple as possible. I'm totally new to Qt's
View/Model implementation.
[2] ok, maybe this feature is a little bit too much.
--
(Not so) Random fortune:
10:33 < m4rgin4l> descubri una forma de hacer que me vengan ganas de venir
al laburo
10:33 < m4rgin4l> lastima que solo funciona en invierno
10:33 < m4rgin4l> cuando me bajo del bondi me saco la campera y me cago de
frio
10:33 < m4rgin4l> asi que me dan ganas de entrar a la oficina donde esta un
poco menos frio
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list