Class SortListModel<T extends GObject>
- All Implemented Interfaces:
Proxy
,ListModelJavaList<T>
,Iterable<T>
,Collection<T>
,List<T>
,SequencedCollection<T>
,ListModel<T>
,SectionModel<T>
GListModel
that sorts the elements of an underlying model
according to a GtkSorter
.
The model is a stable sort. If two items compare equal according
to the sorter, the one that appears first in the original model will
also appear first after sorting.
Note that if you change the sorter, the previous order will have no
influence on the new order. If you want that, consider using a
GtkMultiSorter
and appending the previous sorter to it.
The model can be set up to do incremental sorting, so that
sorting long lists doesn't block the UI. See
setIncremental(boolean)
for details.
GtkSortListModel
is a generic model and because of that it
cannot take advantage of any external knowledge when sorting.
If you run into performance issues with GtkSortListModel
,
it is strongly recommended that you write your own sorting list
model.
GtkSortListModel
allows sorting the items into sections. It
implements GtkSectionModel
and when Gtk.SortListModel:section-sorter
is set, it will sort all items with that sorter and items comparing
equal with it will be put into the same section.
The Gtk.SortListModel:sorter
will then be used to sort items
inside their sections.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
SortListModel.Builder<B extends SortListModel.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static class
SortListModel.SortListModelClass<T extends GObject>
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
Nested classes/interfaces inherited from interface org.gnome.gio.ListModel
ListModel.ItemsChangedCallback, ListModel.ListModelImpl, ListModel.ListModelInterface
Nested classes/interfaces inherited from interface org.gnome.gtk.SectionModel
SectionModel.SectionModelImpl, SectionModel.SectionModelInterface, SectionModel.SectionsChangedCallback
-
Constructor Summary
ConstructorDescriptionSortListModel
(MemorySegment address) Create a SortListModel proxy instance for the provided memory address.SortListModel
(@Nullable ListModel model, @Nullable Sorter sorter) Creates a new sort list model that uses thesorter
to sortmodel
. -
Method Summary
Modifier and TypeMethodDescriptionprotected SortListModel
asParent()
Returns this instance as if it were its parent type.static SortListModel.Builder
<? extends SortListModel.Builder> builder()
ASortListModel.Builder
object constructs aSortListModel
with the specified properties.boolean
Returns whether incremental sorting is enabled.getModel()
Gets the model currently sorted ornull
if none.int
Estimates progress of an ongoing sorting operation.Gets the section sorter that is used to sort items of this SortListModel into sections.Gets the sorter that is used to sort this SortListModel.static Type
getType()
Get the GType of the SortListModel classvoid
setIncremental
(boolean incremental) Sets the sort model to do an incremental sort.void
Sets the model to be sorted.void
setSectionSorter
(@Nullable Sorter sorter) Sets a new section sorter on this SortListModel.void
Sets a new sorter on this SortListModel.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
addFirst, addLast, equals, getFirst, getLast, hashCode, removeFirst, removeLast, replaceAll, reversed, sort, spliterator
Methods inherited from interface org.gnome.gio.ListModel
emitItemsChanged, getItem, getItemType, getNItems, itemsChanged, onItemsChanged
Methods inherited from interface io.github.jwharm.javagi.gio.ListModelJavaList
add, add, addAll, addAll, clear, contains, containsAll, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, retainAll, set, size, subList, toArray, toArray
Methods inherited from interface org.gnome.gtk.SectionModel
emitSectionsChanged, getSection, onSectionsChanged, sectionsChanged
-
Constructor Details
-
SortListModel
Create a SortListModel proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
SortListModel
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
getIncremental
public boolean getIncremental()Returns whether incremental sorting is enabled.- Returns:
true
if incremental sorting is enabled
-
getModel
Gets the model currently sorted ornull
if none.- Returns:
- The model that gets sorted
-
getPending
public int getPending()Estimates progress of an ongoing sorting operation.The estimate is the number of items that would still need to be sorted to finish the sorting operation if this was a linear algorithm. So this number is not related to how many items are already correctly sorted.
If you want to estimate the progress, you can use code like this:
pending = gtk_sort_list_model_get_pending (self); model = gtk_sort_list_model_get_model (self); progress = 1.0 - pending / (double) MAX (1, g_list_model_get_n_items (model));
If no sort operation is ongoing - in particular when
Gtk.SortListModel:incremental
isfalse
- this function returns 0.- Returns:
- a progress estimate of remaining items to sort
-
getSectionSorter
Gets the section sorter that is used to sort items of this SortListModel into sections.- Returns:
- the sorter of
self
-
getSorter
Gets the sorter that is used to sort this SortListModel.- Returns:
- the sorter of
self
-
setIncremental
public void setIncremental(boolean incremental) Sets the sort model to do an incremental sort.When incremental sorting is enabled, the
GtkSortListModel
will not do a complete sort immediately, but will instead queue an idle handler that incrementally sorts the items towards their correct position. This of course means that items do not instantly appear in the right place. It also means that the total sorting time is a lot slower.When your filter blocks the UI while sorting, you might consider turning this on. Depending on your model and sorters, this may become interesting around 10,000 to 100,000 items.
By default, incremental sorting is disabled.
See
getPending()
for progress information about an ongoing incremental sorting operation.- Parameters:
incremental
-true
to sort incrementally
-
setModel
Sets the model to be sorted.The
model
's item type must conform to the item type of this SortListModel.- Parameters:
model
- The model to be sorted
-
setSectionSorter
Sets a new section sorter on this SortListModel.- Parameters:
sorter
- theGtkSorter
to sortmodel
with
-
setSorter
Sets a new sorter on this SortListModel.- Parameters:
sorter
- theGtkSorter
to sortmodel
with
-
builder
ASortListModel.Builder
object constructs aSortListModel
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withSortListModel.Builder.build()
.
-