KiCad PCB EDA Suite
WIDGET_SAVE_RESTORE Class Reference

#include <widget_save_restore.h>

Classes

union  CONTROL
 
union  DATA
 
struct  WIDGET_CTRL_T
 Struct that represents a single bound control. More...
 

Public Member Functions

 WIDGET_SAVE_RESTORE (bool &aValidFlag)
 
void Add (wxRadioBox &ctrl, long &dest)
 Bind a radiobox to a choice. More...
 
void Add (wxRadioButton &ctrl, bool &dest)
 Bind a radio button to a binary choice. More...
 
void Add (wxCheckBox &ctrl, bool &dest)
 Bind a check box to a binary choice. More...
 
void Add (wxTextCtrl &ctrl, wxString &dest)
 Bind a text ctrl to a string: the control value is stored directly into the string. More...
 
void Add (wxTextCtrl &ctrl, long &dest)
 Bind a text ctrl to a integer: the control value is converted to and from integer on save/restore. More...
 
void Add (wxTextCtrl &ctrl, double &dest)
 Bind a text ctrl to a double: the control value is converted to and from double on save/restore. More...
 
void Add (UNIT_BINDER &ctrl, long &dest)
 Bind a control managed by a UNIT_BINDER into a integer. More...
 
void Add (UNIT_BINDER &ctrl, EDA_ANGLE &dest)
 Bind a control managed by a UNIT_BINDER into an angle. More...
 
void Add (wxChoice &ctrl, long &dest)
 Bind a choice control into a choice (agnostic to the actual meaning of the choice) More...
 
void Add (wxNotebook &ctrl, long &dest)
 Bind a notebook tab choice to an integer. More...
 
void ReadConfigFromControls ()
 Read values of all bound controls into the internally-stored references to the underlying data. More...
 
void RestoreConfigToControls ()
 Restore the values from the internally-stored references to the underlying data to each bound control. More...
 

Private Types

enum class  WIDGET_CTRL_TYPE_T {
  TEXT , TEXT_INTEGER , TEXT_DOUBLE , UNIT_BINDER ,
  UNIT_BINDER_ANGLE , CHECKBOX , RADIOBUTTON , RADIOBOX ,
  CHOICE , TAB
}
 Recognised parameters types (encodes an implicit widget type, data type and appropriate conversion). More...
 

Private Attributes

std::vector< WIDGET_CTRL_Tm_ctrls
 
bool & m_valid
 

Detailed Description

Definition at line 40 of file widget_save_restore.h.

Member Enumeration Documentation

◆ WIDGET_CTRL_TYPE_T

enum class WIDGET_SAVE_RESTORE::WIDGET_CTRL_TYPE_T
strongprivate

Recognised parameters types (encodes an implicit widget type, data type and appropriate conversion).

Enumerator
TEXT 
TEXT_INTEGER 
TEXT_DOUBLE 
UNIT_BINDER 
UNIT_BINDER_ANGLE 
CHECKBOX 
RADIOBUTTON 
RADIOBOX 
CHOICE 
TAB 

Definition at line 119 of file widget_save_restore.h.

120 {
121 TEXT,
122 TEXT_INTEGER,
123 TEXT_DOUBLE,
125 UNIT_BINDER_ANGLE,
126 CHECKBOX,
127 RADIOBUTTON,
128 RADIOBOX,
129 CHOICE,
130 TAB
131 };

Constructor & Destructor Documentation

◆ WIDGET_SAVE_RESTORE()

WIDGET_SAVE_RESTORE::WIDGET_SAVE_RESTORE ( bool &  aValidFlag)
inline

Definition at line 43 of file widget_save_restore.h.

43 :
44 m_valid( aValidFlag )
45 {
46 }

Member Function Documentation

◆ Add() [1/10]

void WIDGET_SAVE_RESTORE::Add ( UNIT_BINDER ctrl,
EDA_ANGLE dest 
)

Bind a control managed by a UNIT_BINDER into an angle.

Definition at line 78 of file widget_save_restore.cpp.

79{
80 m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::UNIT_BINDER_ANGLE, ctrl, dest );
81}
std::vector< WIDGET_CTRL_T > m_ctrls

References m_ctrls, and UNIT_BINDER_ANGLE.

◆ Add() [2/10]

void WIDGET_SAVE_RESTORE::Add ( UNIT_BINDER ctrl,
long &  dest 
)

Bind a control managed by a UNIT_BINDER into a integer.

Definition at line 72 of file widget_save_restore.cpp.

References m_ctrls, and UNIT_BINDER.

◆ Add() [3/10]

void WIDGET_SAVE_RESTORE::Add ( wxCheckBox &  ctrl,
bool &  dest 
)

Bind a check box to a binary choice.

Definition at line 48 of file widget_save_restore.cpp.

References CHECKBOX, and m_ctrls.

◆ Add() [4/10]

void WIDGET_SAVE_RESTORE::Add ( wxChoice &  ctrl,
long &  dest 
)

Bind a choice control into a choice (agnostic to the actual meaning of the choice)

Definition at line 83 of file widget_save_restore.cpp.

References CHOICE, and m_ctrls.

◆ Add() [5/10]

void WIDGET_SAVE_RESTORE::Add ( wxNotebook &  ctrl,
long &  dest 
)

Bind a notebook tab choice to an integer.

Definition at line 89 of file widget_save_restore.cpp.

References m_ctrls, and TAB.

◆ Add() [6/10]

void WIDGET_SAVE_RESTORE::Add ( wxRadioBox &  ctrl,
long &  dest 
)

Bind a radiobox to a choice.

Definition at line 36 of file widget_save_restore.cpp.

References m_ctrls, and RADIOBOX.

Referenced by DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY().

◆ Add() [7/10]

void WIDGET_SAVE_RESTORE::Add ( wxRadioButton &  ctrl,
bool &  dest 
)

Bind a radio button to a binary choice.

Definition at line 42 of file widget_save_restore.cpp.

References m_ctrls, and RADIOBUTTON.

◆ Add() [8/10]

void WIDGET_SAVE_RESTORE::Add ( wxTextCtrl &  ctrl,
double &  dest 
)

Bind a text ctrl to a double: the control value is converted to and from double on save/restore.

Definition at line 66 of file widget_save_restore.cpp.

References m_ctrls, and TEXT_DOUBLE.

◆ Add() [9/10]

void WIDGET_SAVE_RESTORE::Add ( wxTextCtrl &  ctrl,
long &  dest 
)

Bind a text ctrl to a integer: the control value is converted to and from integer on save/restore.

Definition at line 60 of file widget_save_restore.cpp.

References m_ctrls, and TEXT_INTEGER.

◆ Add() [10/10]

void WIDGET_SAVE_RESTORE::Add ( wxTextCtrl &  ctrl,
wxString &  dest 
)

Bind a text ctrl to a string: the control value is stored directly into the string.

Definition at line 54 of file widget_save_restore.cpp.

References m_ctrls, and TEXT.

◆ ReadConfigFromControls()

void WIDGET_SAVE_RESTORE::ReadConfigFromControls ( )

Read values of all bound controls into the internally-stored references to the underlying data.

Definition at line 95 of file widget_save_restore.cpp.

96{
98 {
99 switch( ctrl.m_type )
100 {
102 *ctrl.m_dest.m_bool = ctrl.m_control.m_checkbox->GetValue();
103 break;
104
106 *ctrl.m_dest.m_bool = ctrl.m_control.m_radiobutton->GetValue();
107 break;
108
110 *ctrl.m_dest.m_str = ctrl.m_control.m_textctrl->GetValue();
111 break;
112
114 ctrl.m_control.m_textctrl->GetValue().ToLong( ctrl.m_dest.m_long );
115 break;
116
118 ctrl.m_control.m_textctrl->GetValue().ToDouble( ctrl.m_dest.m_double );
119 break;
120
122 *ctrl.m_dest.m_long = ctrl.m_control.m_unit_binder->GetValue();
123 break;
124
126 *ctrl.m_dest.m_angle = ctrl.m_control.m_unit_binder->GetAngleValue();
127 break;
128
130 *ctrl.m_dest.m_long = ctrl.m_control.m_choice->GetSelection();
131 break;
132
134 *ctrl.m_dest.m_long = ctrl.m_control.m_radiobox->GetSelection();
135 break;
136
138 *ctrl.m_dest.m_long = ctrl.m_control.m_notebook->GetSelection();
139 break;
140 }
141 }
142
143 m_valid = true;
144}
Struct that represents a single bound control.

References CHECKBOX, CHOICE, m_ctrls, m_valid, RADIOBOX, RADIOBUTTON, TAB, TEXT, TEXT_DOUBLE, TEXT_INTEGER, UNIT_BINDER, and UNIT_BINDER_ANGLE.

Referenced by DIALOG_CREATE_ARRAY::TransferDataFromWindow().

◆ RestoreConfigToControls()

void WIDGET_SAVE_RESTORE::RestoreConfigToControls ( )

Restore the values from the internally-stored references to the underlying data to each bound control.

Definition at line 147 of file widget_save_restore.cpp.

148{
149 if( !m_valid )
150 return;
151
153 {
154 switch( ctrl.m_type )
155 {
157 ctrl.m_control.m_checkbox->SetValue( *ctrl.m_dest.m_bool );
158 break;
159
161 ctrl.m_control.m_radiobutton->SetValue( *ctrl.m_dest.m_bool );
162 break;
163
165 ctrl.m_control.m_textctrl->SetValue( *ctrl.m_dest.m_str );
166 break;
167
169 ctrl.m_control.m_textctrl->SetValue( wxString::Format( "%ld", *ctrl.m_dest.m_long ) );
170 break;
171
173 ctrl.m_control.m_textctrl->SetValue( wxString::Format( "%f", *ctrl.m_dest.m_double ) );
174 break;
175
177 ctrl.m_control.m_unit_binder->SetValue( *ctrl.m_dest.m_long );
178 break;
179
181 ctrl.m_control.m_unit_binder->SetAngleValue( *ctrl.m_dest.m_angle );
182 break;
183
185 ctrl.m_control.m_choice->SetSelection( *ctrl.m_dest.m_long );
186 break;
187
189 ctrl.m_control.m_radiobox->SetSelection( *ctrl.m_dest.m_long );
190 break;
191
193 ctrl.m_control.m_notebook->SetSelection( *ctrl.m_dest.m_long );
194 break;
195 }
196 }
197}
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References CHECKBOX, CHOICE, Format(), m_ctrls, m_valid, RADIOBOX, RADIOBUTTON, TAB, TEXT, TEXT_DOUBLE, TEXT_INTEGER, UNIT_BINDER, and UNIT_BINDER_ANGLE.

Referenced by DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY().

Member Data Documentation

◆ m_ctrls

std::vector<WIDGET_CTRL_T> WIDGET_SAVE_RESTORE::m_ctrls
private

Definition at line 229 of file widget_save_restore.h.

Referenced by Add(), ReadConfigFromControls(), and RestoreConfigToControls().

◆ m_valid

bool& WIDGET_SAVE_RESTORE::m_valid
private

Definition at line 230 of file widget_save_restore.h.

Referenced by ReadConfigFromControls(), and RestoreConfigToControls().


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