GtkTreeView with huge amount of rows; dynamic data source?



I'd like to have a list- or treeview-like representation of the contents
(rows) of a database. There can easily be tens of thousands of records
to be browsable in a list. Not only filtered parts of the table should
be listed, but also entire tables, unfiltered, should be browsable.

Preparing a GtkListStore (or even GtkTreeStore) in memory and prefill it
with, say, 100 000 entries doesn't seem to be the right way to me.
Besides the unacceptable memory consumption it would take a significant
amount of time to get the table entirely read in and the list prepared.

So I'm looking for a more dynamic way. My data source (database) is
capable of delivering arbitrary rows, in random access manner. My
concept is to dynamically read and display only small parts of the
database table, as the user scrolls to see them.

I.e. if the user scrolls to a position that corresponds to row 20 000
and the GtkTreeView has room for 50 rows to be displayed, then read just
those 50 records from position 20 000 and display them in the widget. If
the users scrolls, then another small set of rows would be read from the
database and the contents of the GtkTreeView would be changed
accordingly. No more rows than are displayed would need to be read and
prepared or stored in memory any time. This has also the advantage that
changes in the table (from others writing to it at the same time) could
be visible immediately, as the user scrolls to them.

Now, I'm wondering whether this concept is accomplishable using a
standard GtkTreeView widget? Just filling a GtkTreeModel with those 50
entries every time doesn't work. The problem is obviously the scrollbar
of the treeview. Its proportions shouldn't reflect the (limited) amount
of rows in the underlying GtkTreeModel which are displayed any time, but
rather the total number of listable database records and the (possibly
tiny) excerpt of it which is visible.

Another related problem is how to determine the number of rows a
GtkTreeView can display in its given space? No simple method or property
there to query that, if I'm not mistaken?

I'm considering putting a custom, independent scrollbar next to the
GtkTreeView and use that one to navigate the list. However, at least I'd
need to know the number of visible rows in the GtkTreeView for that. The
window containing the GtkTreeView has to be resizable by the user, of
course, so assuming any fixed sizes / numbers of rows isn't feasible.

Any idea how to accomplish this by using existing widgets, or would I
need to write an own sort of list widget? Compatibility to GTK+ 2.0 is
preferred, if existing GTK+ means were to be used.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]