The Battle for Wesnoth  1.19.7+dev
Public Member Functions | Private Member Functions | Private Attributes | List of all members
gui2::field_base Class Referenceabstract

Abstract base class for the fields. More...

#include <field.hpp>

Inheritance diagram for gui2::field_base:

Public Member Functions

 field_base (const std::string &id, const bool mandatory)
 Constructor. More...
 
virtual ~field_base ()
 
void attach_to_window (window &window)
 Attaches the field to a window. More...
 
void widget_init ()
 Initializes the widget. More...
 
void widget_finalize ()
 Finalizes the widget. More...
 
void detach_from_window ()
 Detaches the field from a window. More...
 
virtual void widget_save ()=0
 Saves a widget. More...
 
virtual void widget_restore ()=0
 Restores a widget. More...
 
void widget_set_enabled (const bool enable, const bool sync)
 Enables a widget. More...
 
const std::string & id () const
 
bool is_mandatory () const
 
styled_widgetget_widget ()
 
const styled_widgetget_widget () const
 

Private Member Functions

virtual void init_generic ()=0
 See widget_init. More...
 
virtual void init_specialized ()
 See widget_init. More...
 
virtual void finalize_generic ()=0
 See widget_finalize. More...
 
virtual void finalize_specialized ()
 See widget_finalize. More...
 

Private Attributes

const std::string id_
 The id field of the widget, should be unique in a window. More...
 
const bool mandatory_
 Is the widget optional or mandatory in this window. More...
 
styled_widgetwidget_
 The widget attached to the field. More...
 

Detailed Description

Abstract base class for the fields.

Note
In this context a widget is a gui2::styled_widget and not a gui2::widget. This name widget is a generic name and fits, however some functions used are first declared in a styled_widget.

Definition at line 42 of file field.hpp.

Constructor & Destructor Documentation

◆ field_base()

gui2::field_base::field_base ( const std::string &  id,
const bool  mandatory 
)
inline

Constructor.

Parameters
idThe id of the widget to connect to the window. A widget can only be connected once.
mandatoryIs the widget mandatory

Definition at line 52 of file field.hpp.

◆ ~field_base()

virtual gui2::field_base::~field_base ( )
inlinevirtual

Definition at line 57 of file field.hpp.

Member Function Documentation

◆ attach_to_window()

void gui2::field_base::attach_to_window ( window window)
inline

Attaches the field to a window.

When attached the widget which we're a wrapper around is stored linked in here.

Warning
After attaching the window must remain a valid. Before the window is destroyed the detach_from_window function must be called.
Precondition
widget_ == nullptr
Parameters
windowThe window to be attached to.

Definition at line 74 of file field.hpp.

References gui2::widget::find_widget(), id(), mandatory_, and widget_.

Referenced by gui2::dialogs::modal_dialog::init_fields().

◆ detach_from_window()

void gui2::field_base::detach_from_window ( )
inline

Detaches the field from a window.

Precondition
widget_ != nullptr || !mandatory_

Definition at line 124 of file field.hpp.

References mandatory_, and widget_.

Referenced by gui2::dialogs::modal_dialog::finalize_fields().

◆ finalize_generic()

virtual void gui2::field_base::finalize_generic ( )
privatepure virtual

◆ finalize_specialized()

virtual void gui2::field_base::finalize_specialized ( )
inlineprivatevirtual

See widget_finalize.

Reimplemented in gui2::field_text.

Definition at line 224 of file field.hpp.

Referenced by widget_finalize().

◆ get_widget() [1/2]

styled_widget* gui2::field_base::get_widget ( )
inline

◆ get_widget() [2/2]

const styled_widget* gui2::field_base::get_widget ( ) const
inline

Definition at line 197 of file field.hpp.

References widget_.

◆ id()

const std::string& gui2::field_base::id ( ) const
inline

Definition at line 182 of file field.hpp.

References id_.

Referenced by attach_to_window(), and gui2::dialogs::mp_create_game::pre_show().

◆ init_generic()

virtual void gui2::field_base::init_generic ( )
privatepure virtual

◆ init_specialized()

virtual void gui2::field_base::init_specialized ( )
inlineprivatevirtual

See widget_init.

Reimplemented in gui2::field_label, and gui2::field_bool.

Definition at line 216 of file field.hpp.

Referenced by widget_init().

◆ is_mandatory()

bool gui2::field_base::is_mandatory ( ) const
inline

Definition at line 187 of file field.hpp.

References mandatory_.

Referenced by gui2::field< T, W, CT >::validate_widget().

◆ widget_finalize()

void gui2::field_base::widget_finalize ( )
inline

Finalizes the widget.

This routine is called after the dialog is closed with OK. It's called before post_show(). This routine does the following:

  • if no active widget available exit.
  • if a setter is defined the widget value is saved in the setter.
  • The widget value is saved in value_.

Like widget_init it calls two functions with the same purpose.

Definition at line 113 of file field.hpp.

References finalize_generic(), and finalize_specialized().

Referenced by gui2::dialogs::modal_dialog::finalize_fields().

◆ widget_init()

void gui2::field_base::widget_init ( )
inline

Initializes the widget.

This routine is called before the dialog is shown and the pre_show() is called. So the user can override the values set. This routine does the following:

  • If no widget available exit gives feedback it the widget must exist.
  • If a getter is defined we use to set value_ and the widget.
  • If no setter is defined we use the widget value to set value_.

The function calls two functions

  • init_generic which is to be used in the template subclass.
  • init_specialized which is to be used in subclasses of the template class. This way they can override this function without to use their signature to inherit.

Definition at line 96 of file field.hpp.

References init_generic(), and init_specialized().

Referenced by gui2::dialogs::modal_dialog::init_fields().

◆ widget_restore()

virtual void gui2::field_base::widget_restore ( )
pure virtual

◆ widget_save()

virtual void gui2::field_base::widget_save ( )
pure virtual

Saves a widget.

It can be a window must be recreated, in that case the state needs to be saved and restored. This routine does the following:

  • if no widget available exit (doesn't look at the active state).
  • The widget value is saved in value_.

Implemented in gui2::field< T, W, CT >, gui2::field< bool, selectable_item >, gui2::field< std::string, styled_widget, const std::string & >, and gui2::field< std::string, text_box_base, const std::string & >.

Referenced by widget_set_enabled().

◆ widget_set_enabled()

void gui2::field_base::widget_set_enabled ( const bool  enable,
const bool  sync 
)
inline

Enables a widget.

Parameters
enableIf true enables the widget, disables otherwise.
syncIf the state is changed do we need to synchronize. Upon disabling, write the value of the widget in the variable value_. Upon enabling write the value of value_ in the widget.

Definition at line 158 of file field.hpp.

References gui2::styled_widget::get_active(), get_widget(), gui2::styled_widget::set_active(), widget_restore(), and widget_save().

Referenced by gui2::dialogs::mp_create_game::pre_show(), and gui2::dialogs::mp_create_game::update_map_settings().

Member Data Documentation

◆ id_

const std::string gui2::field_base::id_
private

The id field of the widget, should be unique in a window.

Definition at line 204 of file field.hpp.

Referenced by id().

◆ mandatory_

const bool gui2::field_base::mandatory_
private

Is the widget optional or mandatory in this window.

Definition at line 207 of file field.hpp.

Referenced by attach_to_window(), detach_from_window(), and is_mandatory().

◆ widget_

styled_widget* gui2::field_base::widget_
private

The widget attached to the field.

Definition at line 210 of file field.hpp.

Referenced by attach_to_window(), detach_from_window(), and get_widget().


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