Fix destruction order in Symbol Properties grid table.

wxGrid is VERY cranky about this.  I've only found one recipie that works,
and it must be applied strictly.

Fixes: lp:1831317
* https://bugs.launchpad.net/kicad/+bug/1831317
This commit is contained in:
Jeff Young 2019-06-04 14:32:10 +01:00
parent 1fe848f37c
commit dfcffddbe4
2 changed files with 24 additions and 23 deletions

View File

@ -52,9 +52,14 @@ FIELDS_GRID_TABLE<T>::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* a
m_part( aPart ), m_part( aPart ),
m_fieldNameValidator( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), FIELD_NAME ), m_fieldNameValidator( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), FIELD_NAME ),
m_referenceValidator( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), REFERENCE ), m_referenceValidator( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), REFERENCE ),
m_valueValidator( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), VALUE ) m_valueValidator( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), VALUE ),
m_libIdValidator( LIB_ID::ID_PCB ),
m_urlValidator( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), DATASHEET ),
m_nonUrlValidator( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), DATASHEET )
{ {
// Build the various grid cell attributes. // Build the various grid cell attributes.
// NOTE: validators and cellAttrs are member variables to get the destruction order
// right. wxGrid is VERY cranky about this.
m_readOnlyAttr = new wxGridCellAttr; m_readOnlyAttr = new wxGridCellAttr;
m_readOnlyAttr->SetReadOnly( true ); m_readOnlyAttr->SetReadOnly( true );
@ -76,19 +81,17 @@ FIELDS_GRID_TABLE<T>::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* a
m_footprintAttr = new wxGridCellAttr; m_footprintAttr = new wxGridCellAttr;
GRID_CELL_FOOTPRINT_ID_EDITOR* fpIdEditor = new GRID_CELL_FOOTPRINT_ID_EDITOR( aDialog ); GRID_CELL_FOOTPRINT_ID_EDITOR* fpIdEditor = new GRID_CELL_FOOTPRINT_ID_EDITOR( aDialog );
fpIdEditor->SetValidator( LIB_ID_VALIDATOR( LIB_ID::ID_PCB ) ); fpIdEditor->SetValidator( m_libIdValidator );
m_footprintAttr->SetEditor( fpIdEditor ); m_footprintAttr->SetEditor( fpIdEditor );
m_urlAttr = new wxGridCellAttr; m_urlAttr = new wxGridCellAttr;
GRID_CELL_URL_EDITOR* urlEditor = new GRID_CELL_URL_EDITOR( aDialog ); GRID_CELL_URL_EDITOR* urlEditor = new GRID_CELL_URL_EDITOR( aDialog );
urlEditor->SetValidator( SCH_FIELD_VALIDATOR( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), urlEditor->SetValidator( m_urlValidator );
DATASHEET ) );
m_urlAttr->SetEditor( urlEditor ); m_urlAttr->SetEditor( urlEditor );
m_nonUrlAttr = new wxGridCellAttr; m_nonUrlAttr = new wxGridCellAttr;
wxGridCellTextEditor* nonUrlEditor = new wxGridCellTextEditor(); GRID_CELL_TEXT_EDITOR* nonUrlEditor = new GRID_CELL_TEXT_EDITOR();
nonUrlEditor->SetValidator( SCH_FIELD_VALIDATOR( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), nonUrlEditor->SetValidator( m_nonUrlValidator );
DATASHEET ) );
m_nonUrlAttr->SetEditor( nonUrlEditor ); m_nonUrlAttr->SetEditor( nonUrlEditor );
m_boolAttr = new wxGridCellAttr; m_boolAttr = new wxGridCellAttr;
@ -250,11 +253,13 @@ wxGridCellAttr* FIELDS_GRID_TABLE<T>::GetAttr( int aRow, int aCol, wxGridCellAtt
m_urlAttr->IncRef(); m_urlAttr->IncRef();
return m_urlAttr; return m_urlAttr;
} }
/*
else else
{ {
m_nonUrlAttr->IncRef(); m_nonUrlAttr->IncRef();
return m_nonUrlAttr; return m_nonUrlAttr;
} }
*/
} }
return nullptr; return nullptr;
@ -313,12 +318,9 @@ wxString FIELDS_GRID_TABLE<T>::GetValue( int aRow, int aCol )
case FDC_H_ALIGN: case FDC_H_ALIGN:
switch ( field.GetHorizJustify() ) switch ( field.GetHorizJustify() )
{ {
case GR_TEXT_HJUSTIFY_LEFT: case GR_TEXT_HJUSTIFY_LEFT: return _( "Left" );
return _( "Left" ); case GR_TEXT_HJUSTIFY_CENTER: return _( "Center" );
case GR_TEXT_HJUSTIFY_CENTER: case GR_TEXT_HJUSTIFY_RIGHT: return _( "Right" );
return _( "Center" );
case GR_TEXT_HJUSTIFY_RIGHT:
return _( "Right" );
} }
break; break;
@ -326,12 +328,9 @@ wxString FIELDS_GRID_TABLE<T>::GetValue( int aRow, int aCol )
case FDC_V_ALIGN: case FDC_V_ALIGN:
switch ( field.GetVertJustify() ) switch ( field.GetVertJustify() )
{ {
case GR_TEXT_VJUSTIFY_TOP: case GR_TEXT_VJUSTIFY_TOP: return _( "Top" );
return _( "Top" ); case GR_TEXT_VJUSTIFY_CENTER: return _( "Center" );
case GR_TEXT_VJUSTIFY_CENTER: case GR_TEXT_VJUSTIFY_BOTTOM: return _( "Bottom" );
return _( "Center" );
case GR_TEXT_VJUSTIFY_BOTTOM:
return _( "Bottom" );
} }
break; break;
@ -348,10 +347,8 @@ wxString FIELDS_GRID_TABLE<T>::GetValue( int aRow, int aCol )
case FDC_ORIENTATION: case FDC_ORIENTATION:
switch ( (int) field.GetTextAngle() ) switch ( (int) field.GetTextAngle() )
{ {
case TEXT_ANGLE_HORIZ: case TEXT_ANGLE_HORIZ: return _( "Horizontal" );
return _( "Horizontal" ); case TEXT_ANGLE_VERT: return _( "Vertical" );
case TEXT_ANGLE_VERT:
return _( "Vertical" );
} }
break; break;

View File

@ -29,6 +29,7 @@
#include <wx/grid.h> #include <wx/grid.h>
#include <sch_component.h> #include <sch_component.h>
#include <grid_tricks.h> #include <grid_tricks.h>
#include <validators.h>
class SCH_BASE_FRAME; class SCH_BASE_FRAME;
class DIALOG_SHIM; class DIALOG_SHIM;
@ -105,6 +106,9 @@ private:
SCH_FIELD_VALIDATOR m_fieldNameValidator; SCH_FIELD_VALIDATOR m_fieldNameValidator;
SCH_FIELD_VALIDATOR m_referenceValidator; SCH_FIELD_VALIDATOR m_referenceValidator;
SCH_FIELD_VALIDATOR m_valueValidator; SCH_FIELD_VALIDATOR m_valueValidator;
LIB_ID_VALIDATOR m_libIdValidator;
SCH_FIELD_VALIDATOR m_urlValidator;
SCH_FIELD_VALIDATOR m_nonUrlValidator;
wxGridCellAttr* m_readOnlyAttr; wxGridCellAttr* m_readOnlyAttr;
wxGridCellAttr* m_fieldNameAttr; wxGridCellAttr* m_fieldNameAttr;