kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #39046
[PATCH 3/7] Component fields grid: copy/paste boolean values.
NEW: Add ability to copy/paste from/to cells with boolean values
(checkboxes) in grid control of component properties dialog of Eeschema.
---
eeschema/fields_grid_table.cpp | 48 ++++++++++++++++++++++++++++++++++
eeschema/fields_grid_table.h | 3 +++
2 files changed, 51 insertions(+)
diff --git a/eeschema/fields_grid_table.cpp b/eeschema/fields_grid_table.cpp
index 4605ba246..4e005b7d3 100644
--- a/eeschema/fields_grid_table.cpp
+++ b/eeschema/fields_grid_table.cpp
@@ -291,6 +291,9 @@ wxString FIELDS_GRID_TABLE<T>::GetValue( int aRow, int aCol )
case FDC_VALUE:
return field.GetText();
+ case FDC_SHOWN:
+ return StringFromBool( field.IsVisible() );
+
case FDC_H_ALIGN:
switch ( field.GetHorizJustify() )
{
@@ -317,6 +320,12 @@ wxString FIELDS_GRID_TABLE<T>::GetValue( int aRow, int aCol )
break;
+ case FDC_ITALIC:
+ return StringFromBool( field.IsItalic() );
+
+ case FDC_BOLD:
+ return StringFromBool( field.IsBold() );
+
case FDC_TEXT_SIZE:
return StringFromValue( m_userUnits, field.GetTextSize().GetHeight(), true, true );
@@ -382,6 +391,10 @@ void FIELDS_GRID_TABLE<T>::SetValue( int aRow, int aCol, const wxString &aValue
field.SetText( aValue );
break;
+ case FDC_SHOWN:
+ field.SetVisible( BoolFromString( aValue ) );
+ break;
+
case FDC_H_ALIGN:
if( aValue == _( "Left" ) )
field.SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
@@ -404,6 +417,14 @@ void FIELDS_GRID_TABLE<T>::SetValue( int aRow, int aCol, const wxString &aValue
wxFAIL_MSG( wxT( "unknown vertical alignment: " ) + aValue);
break;
+ case FDC_ITALIC:
+ field.SetItalic( BoolFromString( aValue ) );
+ break;
+
+ case FDC_BOLD:
+ field.SetBold( BoolFromString( aValue ) );
+ break;
+
case FDC_TEXT_SIZE:
field.SetTextSize( wxSize( ValueFromString( m_userUnits, aValue ),
ValueFromString( m_userUnits, aValue ) ) );
@@ -508,3 +529,30 @@ void FIELDS_GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
GRID_TRICKS::doPopupSelection( event );
}
}
+
+template <class T>
+wxString FIELDS_GRID_TABLE<T>::StringFromBool( bool aValue )
+{
+ if( aValue )
+ return wxT( "1" );
+ else
+ return wxT( "0" );
+}
+
+template <class T>
+bool FIELDS_GRID_TABLE<T>::BoolFromString( wxString aValue )
+{
+ if( aValue == wxT( "1" ) )
+ {
+ return true;
+ }
+ else if( aValue == wxT( "0" ) )
+ {
+ return false;
+ }
+ else
+ {
+ wxFAIL_MSG( wxString::Format( wxT( "string \"%s\" can't be converted to boolean correctly, it will have been perceived as FALSE" ), aValue ) );
+ return false;
+ }
+}
diff --git a/eeschema/fields_grid_table.h b/eeschema/fields_grid_table.h
index 7c5661504..326bda108 100644
--- a/eeschema/fields_grid_table.h
+++ b/eeschema/fields_grid_table.h
@@ -94,6 +94,9 @@ public:
void SetValue( int aRow, int aCol, const wxString &aValue ) override;
void SetValueAsBool( int aRow, int aCol, bool aValue ) override;
+ wxString StringFromBool( bool aValue );
+ bool BoolFromString( wxString aValue );
+
private:
SCH_BASE_FRAME* m_frame;
EDA_UNITS_T m_userUnits;
--
2.20.1
References