OpenTTD Source: GUIList< T, F > Class Template Reference

OpenTTD Source 1.11.0-RC1

Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
GUIList< T, F > Class Template Reference

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

`#include <sortlist_type.h>`

Inheritance diagram for GUIList< T, F >:

## Public Types
typedef bool | SortFunction(const T &, const T &)
| Signature of sort function.
typedef bool CDECL | FilterFunction(const T *, F)
| Signature of filter function.

## Public Member Functions
uint8 | SortType () const
| Get the sorttype of the list. More...
void | SetSortType (uint8 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 | FilterType () const
| Get the filtertype of the list. More...
void | SetFilterType (uint8 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 (SortFunction *const *n_funcs)
| Hand the array of sort function pointers to the sort list. 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 (FilterFunction *const *n_funcs)
| Hand the array of filter function pointers to the sort list. 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 Member Functions
bool | IsSortable () const
| Check if the list is sortable. More...
void | ResetResortTimer ()
| Reset the resort timer.

## Protected Attributes
SortFunction *const * | sort_func_list
| the sort criteria functions
FilterFunction *const * | filter_func_list
| the filter criteria functions
SortListFlags | flags
| used to control sorting/resorting/etc.
uint8 | sort_type
| what criteria to sort on
uint8 | filter_type
| what criteria to filter on
uint16 | resort_timer
| resort list after a given amount of ticks if set

## Detailed Description

### template<typename T, typename F = const char*>
class GUIList< T, F >

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

Template Parameters

  T | Type of data stored in the list to represent each item.
  F | Type of data fed as additional value to the filter function.

See also
  FilterFunction

Definition at line 46 of file sortlist_type.h.

## Member Function Documentation

## ◆ Filter() [1/2]

template<typename T , typename F = const char*>

bool GUIList< T, F >::Filter | ( | F | filter_data | ) |
| inline

Filter the data with the currently selected filter.

Parameters

  filter_data | Additional data passed to the filter function.

Returns
  true if the list has been altered by filtering

Definition at line 352 of file sortlist_type.h.

## ◆ Filter() [2/2]

template<typename T , typename F = const char*>

bool GUIList< T, F >::Filter | ( | FilterFunction * | decide,
|  | F | filter_data
| ) |  |
| inline

Filter the list.

Parameters

  decide | The function to decide about an item
  filter_data | Additional data passed to the filter function

Returns
  true if the list has been altered by filtering

Definition at line 318 of file sortlist_type.h.

Referenced by NetworkGameWindow::BuildGUINetworkGameList(), BuildObjectWindow::BuildObjectClassesAvailable(), IndustryDirectoryWindow::BuildSortIndustriesList(), BuildRailStationWindow::BuildStationClassesAvailable(), NetworkContentListWindow::FilterContentList(), BuildVehicleWindow::FilterEngineList(), and SignList::FilterSignList().

## ◆ FilterType()

template<typename T , typename F = const char*>

uint8 GUIList< T, F >::FilterType | ( |  | ) | const
| inline

Get the filtertype of the list.

Returns
  The current filtertype

Definition at line 145 of file sortlist_type.h.

## ◆ GetFiltering()

template<typename T , typename F = const char*>

Filtering GUIList< T, F >::GetFiltering | ( |  | ) | const
| inline

Export current filter conditions.

Returns
  the current filter conditions

Definition at line 167 of file sortlist_type.h.

Referenced by NetworkContentListWindow::UpdateFilterState().

## ◆ GetListing()

template<typename T , typename F = const char*>

Listing GUIList< T, F >::GetListing | ( |  | ) | const
| inline

Export current sort conditions.

Returns
  the current sort conditions

Definition at line 116 of file sortlist_type.h.

Referenced by TownDirectoryWindow::OnClick(), and TownDirectoryWindow::OnDropdownSelect().

## ◆ IsDescSortOrder()

template<typename T , typename F = const char*>

bool GUIList< T, F >::IsDescSortOrder | ( |  | ) | const
| inline

Check if the sort order is descending.

Returns
  true if the sort order is descending

Definition at line 223 of file sortlist_type.h.

Referenced by BuildBridgeWindow::DrawWidget(), CompanyStationsWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), IndustryDirectoryWindow::DrawWidget(), VehicleListWindow::DrawWidget(), and NetworkContentListWindow::OnPaint().

## ◆ IsFilterEnabled()

template<typename T , typename F = const char*>

bool GUIList< T, F >::IsFilterEnabled | ( |  | ) | const
| inline

Check if the filter is enabled.

Returns
  true if the filter is enabled

Definition at line 292 of file sortlist_type.h.

## ◆ IsSortable()

template<typename T , typename F = const char*>

bool GUIList< T, F >::IsSortable | ( |  | ) | const
| inlineprotected

Check if the list is sortable.

Returns
  true if we can sort the list

Definition at line 64 of file sortlist_type.h.

Referenced by GUIList< const Sign *, StringFilter & >::Sort(), and GUIList< const Sign *, StringFilter & >::ToggleSortOrder().

## ◆ NeedRebuild()

template<typename T , typename F = const char*>

bool GUIList< T, F >::NeedRebuild | ( |  | ) | const
| inline

Check if a rebuild is needed.

Returns
  true if a rebuild is needed

Definition at line 362 of file sortlist_type.h.

Referenced by CompanyLeagueWindow::BuildCompanyList(), NetworkContentListWindow::BuildContentList(), VehicleGroupWindow::BuildGroupList(), NetworkGameWindow::BuildGUINetworkGameList(), BuildObjectWindow::BuildObjectClassesAvailable(), IndustryDirectoryWindow::BuildSortIndustriesList(), BuildRailStationWindow::BuildStationClassesAvailable(), CompanyStationsWindow::BuildStationsList(), StoryBookWindow::BuildStoryPageElementList(), StoryBookWindow::BuildStoryPageList(), NetworkContentListWindow::OnInvalidateData(), SignListWindow::OnPaint(), NetworkGameWindow::OnPaint(), NetworkContentListWindow::OnPaint(), TownDirectoryWindow::OnPaint(), and IndustryDirectoryWindow::OnPaint().

## ◆ NeedResort()

template<typename T , typename F = const char*>

bool GUIList< T, 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 199 of file sortlist_type.h.

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

## ◆ RebuildDone()

template<typename T , typename F = const char*>

void GUIList< T, F >::RebuildDone | ( |  | ) |
| inline

Notify the sortlist that the rebuild is done.

Note
  This forces a resort

Definition at line 380 of file sortlist_type.h.

Referenced by CompanyLeagueWindow::BuildCompanyList(), NetworkContentListWindow::BuildContentList(), NetworkGameWindow::BuildGUINetworkGameList(), BuildObjectWindow::BuildObjectClassesAvailable(), IndustryDirectoryWindow::BuildSortIndustriesList(), BuildRailStationWindow::BuildStationClassesAvailable(), CompanyStationsWindow::BuildStationsList(), StoryBookWindow::BuildStoryPageElementList(), StoryBookWindow::BuildStoryPageList(), and ReplaceVehicleWindow::GenerateLists().

## ◆ SetFilterFuncs()

template<typename T , typename F = const char*>

void GUIList< T, F >::SetFilterFuncs | ( | FilterFunction *const * | n_funcs | ) |
| inline

Hand the array of filter function pointers to the sort list.

Parameters

  n_funcs | The pointer to the first filter func

Definition at line 341 of file sortlist_type.h.

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

## ◆ SetFiltering()

template<typename T , typename F = const char*>

void GUIList< T, F >::SetFiltering | ( | Filtering | f | ) |
| inline

Import filter conditions.

Parameters

  f | The filter conditions we want to use

Definition at line 181 of file sortlist_type.h.

## ◆ SetFilterState()

template<typename T , typename F = const char*>

void GUIList< T, F >::SetFilterState | ( | bool | state | ) |
| inline

Enable or disable the filter.

Parameters

  state | If filtering should be enabled or disabled

Definition at line 302 of file sortlist_type.h.

Referenced by NetworkGameWindow::BuildGUINetworkGameList(), BuildVehicleWindow::OnDropdownSelect(), BuildObjectWindow::OnEditboxChanged(), BuildRailStationWindow::OnEditboxChanged(), NewGRFWindow::OnEditboxChanged(), IndustryDirectoryWindow::SetAcceptedCargoFilterIndex(), IndustryDirectoryWindow::SetProducedCargoFilterIndex(), and NetworkContentListWindow::UpdateFilterState().

## ◆ SetFilterType()

template<typename T , typename F = const char*>

void GUIList< T, F >::SetFilterType | ( | uint8 | n_type | ) |
| inline

Set the filtertype of the list.

Parameters

  n_type | the new filter type

Definition at line 155 of file sortlist_type.h.

Referenced by NetworkContentListWindow::FilterContentList(), IndustryDirectoryWindow::SetAcceptedCargoFilterIndex(), and IndustryDirectoryWindow::SetProducedCargoFilterIndex().

## ◆ SetListing()

template<typename T , typename F = const char*>

void GUIList< T, F >::SetListing | ( | Listing | l | ) |
| inline

Import sort conditions.

Parameters

  l | The sort conditions we want to use

Definition at line 130 of file sortlist_type.h.

Referenced by TownDirectoryWindow::OnClick().

## ◆ SetSortFuncs()

template<typename T , typename F = const char*>

void GUIList< T, F >::SetSortFuncs | ( | SortFunction *const * | n_funcs | ) |
| inline

Hand the array of sort function pointers to the sort list.

Parameters

  n_funcs | The pointer to the first sort func

Definition at line 270 of file sortlist_type.h.

## ◆ SetSortType()

template<typename T , typename F = const char*>

void GUIList< T, F >::SetSortType | ( | uint8 | n_type | ) |
| inline

Set the sorttype of the list.

Parameters

  n_type | the new sort type

Definition at line 103 of file sortlist_type.h.

Referenced by BuildBridgeWindow::OnDropdownSelect(), CompanyStationsWindow::OnDropdownSelect(), TownDirectoryWindow::OnDropdownSelect(), VehicleGroupWindow::OnDropdownSelect(), IndustryDirectoryWindow::OnDropdownSelect(), and VehicleListWindow::OnDropdownSelect().

## ◆ Sort() [1/2]

template<typename T , typename F = const char*>

bool GUIList< T, 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 281 of file sortlist_type.h.

Referenced by GUIList< const Sign *, StringFilter & >::Sort().

## ◆ Sort() [2/2]

template<typename T , typename F = const char*>
template<typename Comp >

bool GUIList< T, F >::Sort | ( | Comp | compare | ) |
| inline

Sort the list.

Parameters

  compare | The function to compare two list items

Returns
  true if the list sequence has been altered

Definition at line 247 of file sortlist_type.h.

Referenced by VehicleGroupWindow::BuildGroupList(), NetworkGameWindow::BuildGUINetworkGameList(), BuildObjectWindow::BuildObjectClassesAvailable(), IndustryDirectoryWindow::BuildSortIndustriesList(), BuildRailStationWindow::BuildStationClassesAvailable(), StoryBookWindow::BuildStoryPageElementList(), StoryBookWindow::BuildStoryPageList(), TownDirectoryWindow::OnClick(), CompanyLeagueWindow::OnPaint(), BuildBridgeWindow::SortBridgeList(), NetworkContentListWindow::SortContentList(), NetworkGameWindow::SortNetworkGameList(), and CompanyStationsWindow::SortStationsList().

## ◆ SortType()

template<typename T , typename F = const char*>

uint8 GUIList< T, F >::SortType | ( |  | ) | const
| inline

Get the sorttype of the list.

Returns
  The current sorttype

Definition at line 93 of file sortlist_type.h.

Referenced by BuildBridgeWindow::OnClick(), CompanyStationsWindow::OnClick(), VehicleGroupWindow::OnClick(), NetworkGameWindow::OnClick(), TownDirectoryWindow::OnClick(), IndustryDirectoryWindow::OnClick(), VehicleListWindow::OnClick(), BuildBridgeWindow::OnDropdownSelect(), CompanyStationsWindow::OnDropdownSelect(), TownDirectoryWindow::OnDropdownSelect(), IndustryDirectoryWindow::OnDropdownSelect(), NetworkContentListWindow::OnPaint(), TownDirectoryWindow::SetStringParameters(), IndustryDirectoryWindow::SetStringParameters(), and BuildBridgeWindow::SortBridgeList().

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

- src/sortlist_type.h