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 (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 (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  WIDGET_CTRL_TYPE_T {
  WIDGET_CTRL_TYPE_T::TEXT, WIDGET_CTRL_TYPE_T::TEXT_INTEGER, WIDGET_CTRL_TYPE_T::TEXT_DOUBLE, WIDGET_CTRL_TYPE_T::UNIT_BINDER,
  WIDGET_CTRL_TYPE_T::CHECKBOX, WIDGET_CTRL_TYPE_T::RADIOBOX, WIDGET_CTRL_TYPE_T::CHOICE, WIDGET_CTRL_TYPE_T::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 38 of file widget_save_restore.h.

Member Enumeration Documentation

◆ WIDGET_CTRL_TYPE_T

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

Enumerator
TEXT 
TEXT_INTEGER 
TEXT_DOUBLE 
UNIT_BINDER 
CHECKBOX 
RADIOBOX 
CHOICE 
TAB 

Definition at line 106 of file widget_save_restore.h.

107  {
108  TEXT,
109  TEXT_INTEGER,
110  TEXT_DOUBLE,
111  UNIT_BINDER,
112  CHECKBOX,
113  RADIOBOX,
114  CHOICE,
115  TAB
116  };

Constructor & Destructor Documentation

◆ WIDGET_SAVE_RESTORE()

WIDGET_SAVE_RESTORE::WIDGET_SAVE_RESTORE ( bool &  aValidFlag)
inline

Definition at line 41 of file widget_save_restore.h.

41  : m_valid( aValidFlag )
42  {
43  }

Member Function Documentation

◆ Add() [1/8]

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

Bind a radiobox to a choice.

Definition at line 35 of file widget_save_restore.cpp.

36 {
37  m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::RADIOBOX, ctrl, dest );
38 }
std::vector< WIDGET_CTRL_T > m_ctrls

References m_ctrls, and RADIOBOX.

Referenced by DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY().

◆ Add() [2/8]

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

Bind a check box to a binary choice.

Definition at line 41 of file widget_save_restore.cpp.

42 {
43  m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::CHECKBOX, ctrl, dest );
44 }
std::vector< WIDGET_CTRL_T > m_ctrls

References CHECKBOX, and m_ctrls.

◆ Add() [3/8]

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 47 of file widget_save_restore.cpp.

48 {
49  m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::TEXT, ctrl, dest );
50 }
std::vector< WIDGET_CTRL_T > m_ctrls

References m_ctrls, and TEXT.

◆ Add() [4/8]

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 53 of file widget_save_restore.cpp.

54 {
55  m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::TEXT_INTEGER, ctrl, dest );
56 }
std::vector< WIDGET_CTRL_T > m_ctrls

References m_ctrls, and TEXT_INTEGER.

◆ Add() [5/8]

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 59 of file widget_save_restore.cpp.

60 {
61  m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::TEXT_DOUBLE, ctrl, dest );
62 }
std::vector< WIDGET_CTRL_T > m_ctrls

References m_ctrls, and TEXT_DOUBLE.

◆ Add() [6/8]

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

Bind a control managed by a UNIT_BINDER into a integer.

Definition at line 65 of file widget_save_restore.cpp.

66 {
67  m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::UNIT_BINDER, ctrl, dest );
68 }
std::vector< WIDGET_CTRL_T > m_ctrls

References m_ctrls, and UNIT_BINDER.

◆ Add() [7/8]

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 71 of file widget_save_restore.cpp.

72 {
73  m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::CHOICE, ctrl, dest );
74 }
std::vector< WIDGET_CTRL_T > m_ctrls

References CHOICE, and m_ctrls.

◆ Add() [8/8]

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

Bind a notebook tab choice to an integer.

Definition at line 77 of file widget_save_restore.cpp.

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

References m_ctrls, and TAB.

◆ ReadConfigFromControls()

void WIDGET_SAVE_RESTORE::ReadConfigFromControls ( )

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

Definition at line 83 of file widget_save_restore.cpp.

84 {
85  for( auto& ctrl : m_ctrls )
86  {
87  switch( ctrl.m_type )
88  {
90  *ctrl.m_dest.m_bool = ctrl.m_control.m_checkbox->GetValue();
91  break;
92 
94  *ctrl.m_dest.m_str = ctrl.m_control.m_textctrl->GetValue();
95  break;
96 
98  ctrl.m_control.m_textctrl->GetValue().ToLong( ctrl.m_dest.m_long );
99  break;
100 
102  ctrl.m_control.m_textctrl->GetValue().ToDouble( ctrl.m_dest.m_double );
103  break;
104 
106  *ctrl.m_dest.m_long = ctrl.m_control.m_unit_binder->GetValue();
107  break;
108 
110  *ctrl.m_dest.m_long = ctrl.m_control.m_choice->GetSelection();
111  break;
112 
114  *ctrl.m_dest.m_long = ctrl.m_control.m_radiobox->GetSelection();
115  break;
116 
118  *ctrl.m_dest.m_long = ctrl.m_control.m_notebook->GetSelection();
119  break;
120  }
121  }
122 
123  m_valid = true;
124 }
std::vector< WIDGET_CTRL_T > m_ctrls

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

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 127 of file widget_save_restore.cpp.

128 {
129  if( !m_valid )
130  return;
131 
132  for( auto& ctrl : m_ctrls )
133  {
134  switch( ctrl.m_type )
135  {
137  ctrl.m_control.m_checkbox->SetValue( *ctrl.m_dest.m_bool );
138  break;
139 
141  ctrl.m_control.m_textctrl->SetValue( *ctrl.m_dest.m_str );
142  break;
143 
145  ctrl.m_control.m_textctrl->SetValue( wxString::Format( "%ld", *ctrl.m_dest.m_long ) );
146  break;
147 
149  ctrl.m_control.m_textctrl->SetValue( wxString::Format( "%f", *ctrl.m_dest.m_double ) );
150  break;
151 
153  ctrl.m_control.m_unit_binder->SetValue( *ctrl.m_dest.m_long );
154  break;
155 
157  ctrl.m_control.m_choice->SetSelection( *ctrl.m_dest.m_long );
158  break;
159 
161  ctrl.m_control.m_radiobox->SetSelection( *ctrl.m_dest.m_long );
162  break;
163 
165  ctrl.m_control.m_notebook->SetSelection( *ctrl.m_dest.m_long );
166  break;
167  }
168  }
169 }
std::vector< WIDGET_CTRL_T > m_ctrls
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205

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

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 190 of file widget_save_restore.h.

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

◆ m_valid

bool& WIDGET_SAVE_RESTORE::m_valid
private

Definition at line 191 of file widget_save_restore.h.

Referenced by ReadConfigFromControls(), and RestoreConfigToControls().


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