Class SortListModel<T extends GObject>
- All Implemented Interfaces:
Iterable<T>, Collection<T>, List<T>, SequencedCollection<T>, ListModel<T>, SectionModel<T>, Proxy, ListModelJavaList<T>
A list model that sorts the elements of another model.
The elements are sorted 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
Nested ClassesModifier and TypeClassDescriptionstatic classSortListModel.Builder<B extends SortListModel.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static classSortListModel.SortListModelClass<T extends GObject>Nested classes/interfaces inherited from class GObject
GObject.NotifyCallback, GObject.ObjectClassNested classes/interfaces inherited from interface ListModel
ListModel.ItemsChangedCallback, ListModel.ListModel$Impl, ListModel.ListModelInterfaceNested classes/interfaces inherited from interface ListModelJavaList
ListModelJavaList.SubList<E,List> Nested classes/interfaces inherited from interface SectionModel
SectionModel.SectionModel$Impl, SectionModel.SectionModelInterface, SectionModel.SectionsChangedCallback -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new SortListModel.SortListModel(MemorySegment address) Create a SortListModel instance for the provided memory address.SortListModel(@Nullable ListModel model, @Nullable Sorter sorter) Creates a new sort list model that uses thesorterto sortmodel. -
Method Summary
Modifier and TypeMethodDescriptionprotected SortListModelasParent()Return this instance as if it were its parent type.static SortListModel.Builder<? extends SortListModel.Builder> builder()ASortListModel.Builderobject constructs aSortListModelwith the specified properties.booleanReturns whether incremental sorting is enabled.static MemoryLayoutThe memory layout of the native struct.@Nullable ListModelgetModel()Gets the model currently sorted ornullif none.intEstimates progress of an ongoing sorting operation.@Nullable SorterGets the section sorter that is used to sort items of this SortListModel into sections.@Nullable SorterGets the sorter that is used to sortself.static @Nullable TypegetType()Get the GType of the SortListModel class.voidsetIncremental(boolean incremental) Sets the sort model to do an incremental sort.voidSets the model to be sorted.voidsetSectionSorter(@Nullable Sorter sorter) Sets a new section sorter onself.voidSets a new sorter onself.Methods inherited from class 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, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, 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, withPropertiesMethods inherited from class TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class ProxyInstance
equals, handle, hashCodeMethods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface List
addFirst, addLast, equals, getFirst, getLast, hashCode, removeFirst, removeLast, replaceAll, reversed, sort, spliteratorMethods inherited from interface ListModel
emitItemsChanged, getItem, getItemType, getNItems, itemsChanged, onItemsChangedMethods inherited from interface ListModelJavaList
add, add, addAll, addAll, clear, contains, containsAll, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, retainAll, set, size, subList, toArray, toArrayMethods inherited from interface SectionModel
emitSectionsChanged, getSection, onSectionsChanged, sectionsChanged
-
Constructor Details
-
SortListModel
Create a SortListModel instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
SortListModel
-
SortListModel
public SortListModel()Create a new SortListModel.
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Return this instance as if it were its parent type. Comparable to the Javasuperkeyword, but ensures the parent typeclass is also used in native code. -
getIncremental
public boolean getIncremental()Returns whether incremental sorting is enabled.
- Returns:
trueif incremental sorting is enabled
-
getModel
Gets the model currently sorted ornullif 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:incrementalisfalse- 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 - Since:
- 4.12
-
getSorter
Gets the sorter that is used to sortself.- 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
GtkSortListModelwill 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-trueto sort incrementally
-
setModel
Sets the model to be sorted.
The
model'sitem type must conform to the item type ofself.- Parameters:
model- The model to be sorted
-
setSectionSorter
Sets a new section sorter onself.- Parameters:
sorter- theGtkSorterto sortmodelwith- Since:
- 4.12
-
setSorter
Sets a new sorter onself.- Parameters:
sorter- theGtkSorterto sortmodelwith
-
builder
ASortListModel.Builderobject constructs aSortListModelwith the specified properties. Use the variousset...()methods to set properties, and finish construction withSortListModel.Builder.build().- Returns:
- the builder object
-