OpenTTD Source  20240917-master-g9ab0a47812
GUIList< T, P, F > Class Template Reference

List template of 'things' T to sort in a GUI. More...

#include <sortlist_type.h>

Inheritance diagram for GUIList< T, P, F >:

Public Types

using SortFunction = std::conditional_t< std::is_same_v< P, std::nullptr_t >, bool(const T &, const T &), bool(const T &, const T &, const P)>
 Signature of sort function.
 
using FilterFunction = bool(const T *, F)
 Signature of filter function.
 

Public Member Functions

template<typename T_ = T, typename P_ = P, typename _F = F, std::enable_if_t<!std::is_same_v< P_, std::nullptr_t >> * = nullptr>
 GUIList (const P &params)
 
uint8_t SortType () const
 Get the sorttype of the list. More...
 
void SetSortType (uint8_t n_type)
 Set the sorttype of the list. More...
 
Listing GetListing () const
 Export current sort conditions. More...
 
void SetListing (Listing l)
 Import sort conditions. More...
 
uint8_t FilterType () const
 Get the filtertype of the list. More...
 
void SetFilterType (uint8_t n_type)
 Set the filtertype of the list. More...
 
Filtering GetFiltering () const
 Export current filter conditions. More...
 
void SetFiltering (Filtering f)
 Import filter conditions. More...
 
bool NeedResort ()
 Check if a resort is needed next loop If used the resort timer will decrease every call till 0. More...
 
void ForceResort ()
 Force a resort next Sort call Reset the resort timer if used too.
 
bool IsDescSortOrder () const
 Check if the sort order is descending. More...
 
void ToggleSortOrder ()
 Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
 
template<typename Comp >
bool Sort (Comp compare)
 Sort the list. More...
 
void SetSortFuncs (std::span< SortFunction *const > n_funcs)
 Hand the sort function pointers to the GUIList. More...
 
bool Sort ()
 Overload of #Sort(SortFunction *compare) Overloaded to reduce external code. More...
 
bool IsFilterEnabled () const
 Check if the filter is enabled. More...
 
void SetFilterState (bool state)
 Enable or disable the filter. More...
 
bool Filter (FilterFunction *decide, F filter_data)
 Filter the list. More...
 
void SetFilterFuncs (std::span< FilterFunction *const > n_funcs)
 Hand the filter function pointers to the GUIList. More...
 
bool Filter (F filter_data)
 Filter the data with the currently selected filter. More...
 
bool NeedRebuild () const
 Check if a rebuild is needed. More...
 
void ForceRebuild ()
 Force that a rebuild is needed.
 
void RebuildDone ()
 Notify the sortlist that the rebuild is done. More...
 

Protected Types

using SortParameterReference = std::conditional_t< std::is_same_v< P, std::nullptr_t >, P, P & >
 

Protected Member Functions

bool IsSortable () const
 Check if the list is sortable. More...
 
void ResetResortTimer ()
 Reset the resort timer.
 

Protected Attributes

std::span< SortFunction *const > sort_func_list
 the sort criteria functions
 
std::span< FilterFunction *const > filter_func_list
 the filter criteria functions
 
SortListFlags flags
 used to control sorting/resorting/etc.
 
uint8_t sort_type
 what criteria to sort on
 
uint8_t filter_type
 what criteria to filter on
 
uint16_t resort_timer
 resort list after a given amount of ticks if set
 
const SortParameterReference params
 

Detailed Description

template<typename T, typename P = std::nullptr_t, typename F = const char*>
class GUIList< T, P, F >

List template of 'things' T to sort in a GUI.

Template Parameters
TType of data stored in the list to represent each item.
PTyoe of data passed as additional parameter to the sort function.
FType of data fed as additional value to the filter function.
See also
FilterFunction

Definition at line 47 of file sortlist_type.h.

Member Function Documentation

◆ Filter() [1/2]

template<typename T , typename P = std::nullptr_t, typename F = const char*>
bool GUIList< T, P, F >::Filter ( filter_data)
inline

Filter the data with the currently selected filter.

Parameters
filter_dataAdditional data passed to the filter function.
Returns
true if the list has been altered by filtering

Definition at line 380 of file sortlist_type.h.

◆ Filter() [2/2]

template<typename T , typename P = std::nullptr_t, typename F = const char*>
bool GUIList< T, P, F >::Filter ( FilterFunction decide,
filter_data 
)
inline

Filter the list.

Parameters
decideThe function to decide about an item
filter_dataAdditional data passed to the filter function
Returns
true if the list has been altered by filtering

Definition at line 346 of file sortlist_type.h.

Referenced by PickerWindow::BuildPickerClassList(), PickerWindow::BuildPickerTypeList(), IndustryDirectoryWindow::BuildSortIndustriesList(), NetworkContentListWindow::FilterContentList(), BuildVehicleWindow::FilterEngineList(), SignList::FilterSignList(), and BaseVehicleListWindow::FilterVehicleList().

◆ FilterType()

template<typename T , typename P = std::nullptr_t, typename F = const char*>
uint8_t GUIList< T, P, F >::FilterType ( ) const
inline

Get the filtertype of the list.

Returns
The current filtertype

Definition at line 167 of file sortlist_type.h.

◆ GetFiltering()

template<typename T , typename P = std::nullptr_t, typename F = const char*>
Filtering GUIList< T, P, F >::GetFiltering ( ) const
inline

Export current filter conditions.

Returns
the current filter conditions

Definition at line 190 of file sortlist_type.h.

Referenced by NetworkContentListWindow::UpdateFilterState().

◆ GetListing()

template<typename T , typename P = std::nullptr_t, typename F = const char*>
Listing GUIList< T, P, F >::GetListing ( ) const
inline

Export current sort conditions.

Returns
the current sort conditions

Definition at line 138 of file sortlist_type.h.

◆ IsDescSortOrder()

template<typename T , typename P = std::nullptr_t, typename F = const char*>
bool GUIList< T, P, F >::IsDescSortOrder ( ) const
inline

Check if the sort order is descending.

Returns
true if the sort order is descending

Definition at line 246 of file sortlist_type.h.

Referenced by NetworkContentListWindow::OnPaint().

◆ IsFilterEnabled()

template<typename T , typename P = std::nullptr_t, typename F = const char*>
bool GUIList< T, P, F >::IsFilterEnabled ( ) const
inline

Check if the filter is enabled.

Returns
true if the filter is enabled

Definition at line 320 of file sortlist_type.h.

◆ IsSortable()

template<typename T , typename P = std::nullptr_t, typename F = const char*>
bool GUIList< T, P, F >::IsSortable ( ) const
inlineprotected

Check if the list is sortable.

Returns
true if we can sort the list

Definition at line 70 of file sortlist_type.h.

Referenced by GUIList< BuildBridgeData >::Sort(), and GUIList< BuildBridgeData >::ToggleSortOrder().

◆ NeedRebuild()

◆ NeedResort()

template<typename T , typename P = std::nullptr_t, typename F = const char*>
bool GUIList< T, P, F >::NeedResort ( )
inline

Check if a resort is needed next loop If used the resort timer will decrease every call till 0.

If 0 reached the resort bit will be set and the timer will be reset.

Returns
true if resort bit is set for next loop

Definition at line 222 of file sortlist_type.h.

Referenced by PerformanceLeagueWindow::OnGameTick(), CompanyStationsWindow::OnGameTick(), VehicleGroupWindow::OnGameTick(), VehicleListWindow::OnGameTick(), NetworkGameWindow::OnPaint(), and SignWindow::PrevNextSign().

◆ RebuildDone()

◆ SetFilterFuncs()

template<typename T , typename P = std::nullptr_t, typename F = const char*>
void GUIList< T, P, F >::SetFilterFuncs ( std::span< FilterFunction *const >  n_funcs)
inline

Hand the filter function pointers to the GUIList.

Parameters
n_funcsSpan covering the filter function pointers.

Definition at line 369 of file sortlist_type.h.

Referenced by NetworkContentListWindow::NetworkContentListWindow(), BaseVehicleListWindow::SetCargoFilterArray(), BuildVehicleWindow::SetCargoFilterArray(), and IndustryDirectoryWindow::SetCargoFilterArray().

◆ SetFiltering()

template<typename T , typename P = std::nullptr_t, typename F = const char*>
void GUIList< T, P, F >::SetFiltering ( Filtering  f)
inline

Import filter conditions.

Parameters
fThe filter conditions we want to use

Definition at line 204 of file sortlist_type.h.

Referenced by NetworkContentListWindow::NetworkContentListWindow().

◆ SetFilterState()

template<typename T , typename P = std::nullptr_t, typename F = const char*>
void GUIList< T, P, F >::SetFilterState ( bool  state)
inline

◆ SetFilterType()

template<typename T , typename P = std::nullptr_t, typename F = const char*>
void GUIList< T, P, F >::SetFilterType ( uint8_t  n_type)
inline

◆ SetListing()

template<typename T , typename P = std::nullptr_t, typename F = const char*>
void GUIList< T, P, F >::SetListing ( Listing  l)
inline

Import sort conditions.

Parameters
lThe sort conditions we want to use

Definition at line 152 of file sortlist_type.h.

Referenced by NetworkContentListWindow::NetworkContentListWindow().

◆ SetSortFuncs()

template<typename T , typename P = std::nullptr_t, typename F = const char*>
void GUIList< T, P, F >::SetSortFuncs ( std::span< SortFunction *const >  n_funcs)
inline

Hand the sort function pointers to the GUIList.

Parameters
n_funcsSpan covering the sort function pointers.

Definition at line 297 of file sortlist_type.h.

Referenced by NetworkContentListWindow::NetworkContentListWindow().

◆ SetSortType()

template<typename T , typename P = std::nullptr_t, typename F = const char*>
void GUIList< T, P, F >::SetSortType ( uint8_t  n_type)
inline

Set the sorttype of the list.

Parameters
n_typethe new sort type

Definition at line 124 of file sortlist_type.h.

◆ Sort() [1/2]

template<typename T , typename P = std::nullptr_t, typename F = const char*>
bool GUIList< T, P, F >::Sort ( )
inline

Overload of #Sort(SortFunction *compare) Overloaded to reduce external code.

Returns
true if the list sequence has been altered

Definition at line 308 of file sortlist_type.h.

Referenced by GUIList< BuildBridgeData >::Sort().

◆ Sort() [2/2]

template<typename T , typename P = std::nullptr_t, typename F = const char*>
template<typename Comp >
bool GUIList< T, P, F >::Sort ( Comp  compare)
inline

◆ SortType()

template<typename T , typename P = std::nullptr_t, typename F = const char*>
uint8_t GUIList< T, P, F >::SortType ( ) const
inline

Get the sorttype of the list.

Returns
The current sorttype

Definition at line 114 of file sortlist_type.h.

Referenced by NetworkContentListWindow::OnPaint(), and BuildBridgeWindow::SortBridgeList().


The documentation for this class was generated from the following file: