KiCad PCB EDA Suite
Loading...
Searching...
No Matches
WX_GRID Class Reference

#include <wx_grid.h>

Inheritance diagram for WX_GRID:

Public Member Functions

 WX_GRID (wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxWANTS_CHARS, const wxString &name=wxGridNameStr)
 
 ~WX_GRID () override
 
void SetColLabelSize (int aHeight)
 Hide wxGrid's SetColLabelSize() method with one which makes sure the size is tall enough for the system GUI font.
 
void SetLabelFont (const wxFont &aFont)
 Hide wxGrid's SetLabelFont() because for some reason on MSW it's a one-shot and subsequent calls to it have no effect.
 
void EnableAlternateRowColors (bool aEnable=true)
 Enable alternate row highlighting, where every odd row has a different background color than the even rows.
 
wxString GetShownColumnsAsString ()
 Get a tokenized string containing the shown column indexes.
 
std::bitset< 64 > GetShownColumns ()
 
void ShowHideColumns (const wxString &shownColumns)
 Show/hide the grid columns based on a tokenized string of shown column indexes.
 
void SetTable (wxGridTableBase *table, bool aTakeOwnership=false)
 Hide wxGrid's SetTable() method with one which doesn't mess up the grid column widths when setting the table.
 
void DestroyTable (wxGridTableBase *aTable)
 Work-around for a bug in wxGrid which crashes when deleting the table if the cell edit control was not closed.
 
bool CommitPendingChanges (bool aQuietMode=false)
 Close any open cell edit controls.
 
bool CancelPendingChanges ()
 
void OnAddRow (const std::function< std::pair< int, int >()> &aAdder)
 
void OnDeleteRows (const std::function< void(int row)> &aDeleter)
 Handles a row deletion event.
 
void OnDeleteRows (const std::function< bool(int row)> &aFilter, const std::function< void(int row)> &aDeleter)
 
void SwapRows (int aRowA, int aRowB)
 These aren't that tricky, but might as well share code.
 
void OnMoveRowUp (const std::function< void(int row)> &aMover)
 
void OnMoveRowDown (const std::function< void(int row)> &aMover)
 
void OnMoveRowUp (const std::function< bool(int row)> &aFilter, const std::function< void(int row)> &aMover)
 
void OnMoveRowDown (const std::function< bool(int row)> &aFilter, const std::function< void(int row)> &aMover)
 
void SetUnitsProvider (UNITS_PROVIDER *aProvider, int aCol=0)
 Set a EUNITS_PROVIDER to enable use of unit- and eval-based Getters.
 
void SetAutoEvalCols (const std::vector< int > &aCols)
 
void SetAutoEvalColUnits (int col, EDA_UNITS aUnit, EDA_DATA_TYPE aUnitType)
 Set the unit and unit data type to use for a given column.
 
void SetAutoEvalColUnits (int col, EDA_UNITS aUnit)
 Set the unit to use for a given column.
 
int GetUnitValue (int aRow, int aCol)
 Apply standard KiCad unit and eval services to a numeric cell.
 
std::optional< int > GetOptionalUnitValue (int aRow, int aCol)
 Apply standard KiCad unit and eval services to a numeric cell.
 
void SetUnitValue (int aRow, int aCol, int aValue)
 Set a unitized cell's value.
 
void SetOptionalUnitValue (int aRow, int aCol, std::optional< int > aValue)
 Set a unitized cell's optional value.
 
int GetVisibleWidth (int aCol, bool aHeader=true, bool aContents=true, bool aKeep=false)
 Calculate the specified column based on the actual size of the text on screen.
 
void EnsureColLabelsVisible ()
 Ensure the height of the row displaying the column labels is enough, even if labels are multiline texts.
 
void ShowEditorOnMouseUp ()
 WxWidgets has a bunch of bugs in its handling of wxGrid mouse events which close cell editors right after opening them.
 
void CancelShowEditorOnMouseUp ()
 
void ClearRows (bool aUpdateLabels=true)
 wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number of rows (even if the delete count is 0).
 
void OverrideMinSize (double aXPct, double aYPct)
 Grids that have column sizes automatically set to fill the available width don't want to shrink afterwards (because wxGrid reports the aggregate column size as the bestSize.
 
wxSize DoGetBestSize () const override
 

Static Public Member Functions

static void CellEditorSetMargins (wxTextEntryBase *aEntry)
 A helper function to set OS-specific margins for text-based cell editors.
 
static void CellEditorTransformSizeRect (wxRect &aRect)
 A helper function to tweak sizes of text-based cell editors depending on OS.
 

Protected Member Functions

void DrawColLabel (wxDC &dc, int col) override
 A re-implementation of wxGrid::DrawColLabel which left-aligns the first column and draws flat borders.
 
void DrawRowLabel (wxDC &dc, int row) override
 A re-implementation of wxGrid::DrawRowLabel which draws flat borders.
 
void DrawCornerLabel (wxDC &dc) override
 A re-implementation of wxGrid::DrawCornerLabel which draws flat borders.
 
void onGridColMove (wxGridEvent &aEvent)
 
void onGridCellSelect (wxGridEvent &aEvent)
 
void onCellEditorShown (wxGridEvent &aEvent)
 
void onCellEditorHidden (wxGridEvent &aEvent)
 
void onDPIChanged (wxDPIChangedEvent &event)
 
UNITS_PROVIDERgetUnitsProvider (int aCol) const
 
std::pair< EDA_UNITS, EDA_DATA_TYPEgetColumnUnits (int aCol) const
 Returns the units and data type associated with a given column.
 

Protected Attributes

bool m_weOwnTable
 
std::map< int, UNITS_PROVIDER * > m_unitsProviders
 
std::unique_ptr< NUMERIC_EVALUATORm_eval
 
std::vector< int > m_autoEvalCols
 
std::unordered_map< int, std::pair< EDA_UNITS, EDA_DATA_TYPE > > m_autoEvalColsUnits
 
std::map< std::pair< int, int >, std::pair< wxString, wxString > > m_evalBeforeAfter
 
std::optional< wxSize > m_minSizeOverride
 

Detailed Description

Definition at line 77 of file wx_grid.h.

Constructor & Destructor Documentation

◆ WX_GRID()

WX_GRID::WX_GRID ( wxWindow * parent,
wxWindowID id,
const wxPoint & pos = wxDefaultPosition,
const wxSize & size = wxDefaultSize,
long style = wxWANTS_CHARS,
const wxString & name = wxGridNameStr )

◆ ~WX_GRID()

WX_GRID::~WX_GRID ( )
override

Member Function Documentation

◆ CancelPendingChanges()

bool WX_GRID::CancelPendingChanges ( )

Definition at line 594 of file wx_grid.cpp.

References editor.

◆ CancelShowEditorOnMouseUp()

void WX_GRID::CancelShowEditorOnMouseUp ( )
inline

Definition at line 240 of file wx_grid.h.

◆ CellEditorSetMargins()

void WX_GRID::CellEditorSetMargins ( wxTextEntryBase * aEntry)
static

A helper function to set OS-specific margins for text-based cell editors.

Definition at line 77 of file wx_grid.cpp.

Referenced by GRID_CELL_FPID_EDITOR::Create(), GRID_CELL_PATH_EDITOR::Create(), GRID_CELL_SYMBOL_ID_EDITOR::Create(), and GRID_CELL_URL_EDITOR::Create().

◆ CellEditorTransformSizeRect()

void WX_GRID::CellEditorTransformSizeRect ( wxRect & aRect)
static

A helper function to tweak sizes of text-based cell editors depending on OS.

Definition at line 84 of file wx_grid.cpp.

Referenced by GRID_CELL_STC_EDITOR::SetSize(), GRID_CELL_TEXT_BUTTON::SetSize(), and GRID_CELL_TEXT_EDITOR::SetSize().

◆ ClearRows()

void WX_GRID::ClearRows ( bool aUpdateLabels = true)
inline

wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number of rows (even if the delete count is 0).

Needless to say, this makes using DeleteRows for clearing a lot more cumbersome so we add a helper here.

Definition at line 247 of file wx_grid.h.

◆ CommitPendingChanges()

bool WX_GRID::CommitPendingChanges ( bool aQuietMode = false)

Close any open cell edit controls.

Parameters
aQuietModeif true don't send events (ie: for row/col delete operations).
Returns
false if validation failed.

Definition at line 622 of file wx_grid.cpp.

References editor.

Referenced by DestroyTable(), OnAddRow(), OnDeleteRows(), onGridColMove(), OnMoveRowDown(), and OnMoveRowUp().

◆ DestroyTable()

void WX_GRID::DestroyTable ( wxGridTableBase * aTable)

Work-around for a bug in wxGrid which crashes when deleting the table if the cell edit control was not closed.

Definition at line 443 of file wx_grid.cpp.

References CommitPendingChanges(), onGridCellSelect(), and onGridColMove().

Referenced by ~WX_GRID().

◆ DoGetBestSize()

wxSize WX_GRID::DoGetBestSize ( ) const
inlineoverride

Definition at line 275 of file wx_grid.h.

References m_minSizeOverride.

Referenced by OverrideMinSize().

◆ DrawColLabel()

void WX_GRID::DrawColLabel ( wxDC & dc,
int col )
overrideprotected

A re-implementation of wxGrid::DrawColLabel which left-aligns the first column and draws flat borders.

Definition at line 525 of file wx_grid.cpp.

References WX_GRID_COLUMN_HEADER_RENDERER::DrawBorder(), and MIN_GRIDCELL_MARGIN.

◆ DrawCornerLabel()

void WX_GRID::DrawCornerLabel ( wxDC & dc)
overrideprotected

A re-implementation of wxGrid::DrawCornerLabel which draws flat borders.

Definition at line 505 of file wx_grid.cpp.

References WX_GRID_CORNER_HEADER_RENDERER::DrawBorder().

◆ DrawRowLabel()

void WX_GRID::DrawRowLabel ( wxDC & dc,
int row )
overrideprotected

A re-implementation of wxGrid::DrawRowLabel which draws flat borders.

Definition at line 563 of file wx_grid.cpp.

References WX_GRID_ROW_HEADER_RENDERER::DrawBorder(), and MIN_GRIDCELL_MARGIN.

◆ EnableAlternateRowColors()

void WX_GRID::EnableAlternateRowColors ( bool aEnable = true)

Enable alternate row highlighting, where every odd row has a different background color than the even rows.

Parameters
aEnableflag to specify to enable alternate row striping in the grid.

Definition at line 302 of file wx_grid.cpp.

References color, and table.

Referenced by SetTable().

◆ EnsureColLabelsVisible()

void WX_GRID::EnsureColLabelsVisible ( )

Ensure the height of the row displaying the column labels is enough, even if labels are multiline texts.

Definition at line 946 of file wx_grid.cpp.

References SetColLabelSize().

Referenced by GetVisibleWidth().

◆ getColumnUnits()

std::pair< EDA_UNITS, EDA_DATA_TYPE > WX_GRID::getColumnUnits ( int aCol) const
protected

Returns the units and data type associated with a given column.

Definition at line 974 of file wx_grid.cpp.

References DISTANCE, getUnitsProvider(), UNITS_PROVIDER::GetUserUnits(), and m_autoEvalColsUnits.

Referenced by GetOptionalUnitValue(), GetUnitValue(), and onCellEditorHidden().

◆ GetOptionalUnitValue()

std::optional< int > WX_GRID::GetOptionalUnitValue ( int aRow,
int aCol )

Apply standard KiCad unit and eval services to a numeric cell.

Parameters
aRowthe cell row index to fetch.
aColthe cell column index to fetch.
Returns
the value held by the cell in internal units.

Definition at line 862 of file wx_grid.cpp.

References alg::contains(), getColumnUnits(), getUnitsProvider(), m_autoEvalCols, m_eval, UNITS_PROVIDER::NullUiString, and UNITS_PROVIDER::OptionalValueFromString().

◆ GetShownColumns()

std::bitset< 64 > WX_GRID::GetShownColumns ( )

Definition at line 476 of file wx_grid.cpp.

◆ GetShownColumnsAsString()

wxString WX_GRID::GetShownColumnsAsString ( )

Get a tokenized string containing the shown column indexes.

Tokens are separated by spaces.

Definition at line 457 of file wx_grid.cpp.

◆ getUnitsProvider()

UNITS_PROVIDER * WX_GRID::getUnitsProvider ( int aCol) const
inlineprotected

◆ GetUnitValue()

int WX_GRID::GetUnitValue ( int aRow,
int aCol )

Apply standard KiCad unit and eval services to a numeric cell.

Parameters
aRowthe cell row index to fetch.
aColthe cell column index to fetch.
aIsOptionalif true, indicates to the unit provider the value is optional.
Returns
the value held by the cell in internal units.

Definition at line 844 of file wx_grid.cpp.

References alg::contains(), getColumnUnits(), getUnitsProvider(), m_autoEvalCols, m_eval, and UNITS_PROVIDER::ValueFromString().

◆ GetVisibleWidth()

int WX_GRID::GetVisibleWidth ( int aCol,
bool aHeader = true,
bool aContents = true,
bool aKeep = false )

Calculate the specified column based on the actual size of the text on screen.

Parameters
aColis the index of the column to resize. Specify -1 for the row labels.
aHeaderis the header in the width calculation.
aContentsis the full contents of the column.
aKeepis the current size as a minimum value.
Returns
The maximum value of all calculated widths.

Definition at line 906 of file wx_grid.cpp.

References EnsureColLabelsVisible().

Referenced by PANEL_SETUP_TRACKS_AND_VIAS::PANEL_SETUP_TRACKS_AND_VIAS().

◆ OnAddRow()

void WX_GRID::OnAddRow ( const std::function< std::pair< int, int >()> & aAdder)

Definition at line 674 of file wx_grid.cpp.

References CommitPendingChanges().

Referenced by DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::onAddGroup().

◆ onCellEditorHidden()

◆ onCellEditorShown()

void WX_GRID::onCellEditorShown ( wxGridEvent & aEvent)
protected

Definition at line 347 of file wx_grid.cpp.

References alg::contains(), m_autoEvalCols, and m_evalBeforeAfter.

Referenced by WX_GRID(), and ~WX_GRID().

◆ OnDeleteRows() [1/2]

void WX_GRID::OnDeleteRows ( const std::function< bool(int row)> & aFilter,
const std::function< void(int row)> & aDeleter )

Definition at line 705 of file wx_grid.cpp.

References CommitPendingChanges().

◆ OnDeleteRows() [2/2]

void WX_GRID::OnDeleteRows ( const std::function< void(int row)> & aDeleter)

Handles a row deletion event.

This is a bit tricky due to the potential for stale selections, so we code it only once here.

Definition at line 694 of file wx_grid.cpp.

References OnDeleteRows().

Referenced by OnDeleteRows(), and DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::onRemoveGroup().

◆ onDPIChanged()

void WX_GRID::onDPIChanged ( wxDPIChangedEvent & event)
protected

Definition at line 235 of file wx_grid.cpp.

Referenced by WX_GRID(), and ~WX_GRID().

◆ onGridCellSelect()

void WX_GRID::onGridCellSelect ( wxGridEvent & aEvent)
protected

Definition at line 320 of file wx_grid.cpp.

Referenced by DestroyTable(), and SetTable().

◆ onGridColMove()

void WX_GRID::onGridColMove ( wxGridEvent & aEvent)
protected

Definition at line 899 of file wx_grid.cpp.

References CommitPendingChanges().

Referenced by DestroyTable(), and SetTable().

◆ OnMoveRowDown() [1/2]

void WX_GRID::OnMoveRowDown ( const std::function< bool(int row)> & aFilter,
const std::function< void(int row)> & aMover )

Definition at line 800 of file wx_grid.cpp.

References CommitPendingChanges().

◆ OnMoveRowDown() [2/2]

void WX_GRID::OnMoveRowDown ( const std::function< void(int row)> & aMover)

Definition at line 789 of file wx_grid.cpp.

References OnMoveRowDown().

Referenced by OnMoveRowDown().

◆ OnMoveRowUp() [1/2]

void WX_GRID::OnMoveRowUp ( const std::function< bool(int row)> & aFilter,
const std::function< void(int row)> & aMover )

Definition at line 767 of file wx_grid.cpp.

References CommitPendingChanges().

◆ OnMoveRowUp() [2/2]

void WX_GRID::OnMoveRowUp ( const std::function< void(int row)> & aMover)

Definition at line 756 of file wx_grid.cpp.

References OnMoveRowUp().

Referenced by OnMoveRowUp().

◆ OverrideMinSize()

void WX_GRID::OverrideMinSize ( double aXPct,
double aYPct )
inline

Grids that have column sizes automatically set to fill the available width don't want to shrink afterwards (because wxGrid reports the aggregate column size as the bestSize.

Parameters
aSize

Definition at line 269 of file wx_grid.h.

References DoGetBestSize(), KiROUND(), and m_minSizeOverride.

◆ SetAutoEvalCols()

void WX_GRID::SetAutoEvalCols ( const std::vector< int > & aCols)
inline

Definition at line 172 of file wx_grid.h.

References m_autoEvalCols.

◆ SetAutoEvalColUnits() [1/2]

void WX_GRID::SetAutoEvalColUnits ( int col,
EDA_UNITS aUnit )

Set the unit to use for a given column.

The unit data type is inferred from the unit type

Definition at line 837 of file wx_grid.cpp.

References UNITS_PROVIDER::GetTypeFromUnits(), and SetAutoEvalColUnits().

◆ SetAutoEvalColUnits() [2/2]

void WX_GRID::SetAutoEvalColUnits ( int col,
EDA_UNITS aUnit,
EDA_DATA_TYPE aUnitType )

Set the unit and unit data type to use for a given column.

Definition at line 831 of file wx_grid.cpp.

References m_autoEvalColsUnits.

Referenced by SetAutoEvalColUnits().

◆ SetColLabelSize()

void WX_GRID::SetColLabelSize ( int aHeight)

Hide wxGrid's SetColLabelSize() method with one which makes sure the size is tall enough for the system GUI font.

Parameters
height

Definition at line 246 of file wx_grid.cpp.

References MIN_GRIDCELL_MARGIN.

Referenced by EnsureColLabelsVisible().

◆ SetLabelFont()

void WX_GRID::SetLabelFont ( const wxFont & aFont)

Hide wxGrid's SetLabelFont() because for some reason on MSW it's a one-shot and subsequent calls to it have no effect.

Definition at line 261 of file wx_grid.cpp.

References KIUI::GetControlFont().

Referenced by WX_GRID().

◆ SetOptionalUnitValue()

void WX_GRID::SetOptionalUnitValue ( int aRow,
int aCol,
std::optional< int > aValue )

Set a unitized cell's optional value.

Definition at line 893 of file wx_grid.cpp.

References getUnitsProvider().

◆ SetTable()

void WX_GRID::SetTable ( wxGridTableBase * table,
bool aTakeOwnership = false )

Hide wxGrid's SetTable() method with one which doesn't mess up the grid column widths when setting the table.

Definition at line 267 of file wx_grid.cpp.

References EnableAlternateRowColors(), m_weOwnTable, MIN_GRIDCELL_MARGIN, onGridCellSelect(), onGridColMove(), and Pgm().

◆ SetUnitsProvider()

void WX_GRID::SetUnitsProvider ( UNITS_PROVIDER * aProvider,
int aCol = 0 )

Set a EUNITS_PROVIDER to enable use of unit- and eval-based Getters.

Parameters
aProvider

Definition at line 822 of file wx_grid.cpp.

References UNITS_PROVIDER::GetUserUnits(), m_eval, and m_unitsProviders.

◆ SetUnitValue()

void WX_GRID::SetUnitValue ( int aRow,
int aCol,
int aValue )

Set a unitized cell's value.

Definition at line 880 of file wx_grid.cpp.

References DISTANCE, getUnitsProvider(), and m_autoEvalColsUnits.

◆ ShowEditorOnMouseUp()

void WX_GRID::ShowEditorOnMouseUp ( )
inline

WxWidgets has a bunch of bugs in its handling of wxGrid mouse events which close cell editors right after opening them.

Helpfully, it already has a bunch of work-arounds in place (such as the SetInSetFocus() hack), including one to make slow clicks work. We re-purpose this hack to work-around the bugs when we want to open an editor.

Definition at line 239 of file wx_grid.h.

◆ ShowHideColumns()

void WX_GRID::ShowHideColumns ( const wxString & shownColumns)

Show/hide the grid columns based on a tokenized string of shown column indexes.

Definition at line 487 of file wx_grid.cpp.

◆ SwapRows()

void WX_GRID::SwapRows ( int aRowA,
int aRowB )

These aren't that tricky, but might as well share code.

Definition at line 745 of file wx_grid.cpp.

Member Data Documentation

◆ m_autoEvalCols

std::vector<int> WX_GRID::m_autoEvalCols
protected

◆ m_autoEvalColsUnits

std::unordered_map<int, std::pair<EDA_UNITS, EDA_DATA_TYPE> > WX_GRID::m_autoEvalColsUnits
protected

Definition at line 326 of file wx_grid.h.

Referenced by getColumnUnits(), SetAutoEvalColUnits(), and SetUnitValue().

◆ m_eval

std::unique_ptr<NUMERIC_EVALUATOR> WX_GRID::m_eval
protected

◆ m_evalBeforeAfter

std::map< std::pair<int, int>, std::pair<wxString, wxString> > WX_GRID::m_evalBeforeAfter
protected

Definition at line 327 of file wx_grid.h.

Referenced by onCellEditorHidden(), and onCellEditorShown().

◆ m_minSizeOverride

std::optional<wxSize> WX_GRID::m_minSizeOverride
protected

Definition at line 329 of file wx_grid.h.

Referenced by DoGetBestSize(), and OverrideMinSize().

◆ m_unitsProviders

std::map<int, UNITS_PROVIDER*> WX_GRID::m_unitsProviders
protected

Definition at line 323 of file wx_grid.h.

Referenced by getUnitsProvider(), and SetUnitsProvider().

◆ m_weOwnTable

bool WX_GRID::m_weOwnTable
protected

Definition at line 321 of file wx_grid.h.

Referenced by SetTable(), WX_GRID(), and ~WX_GRID().


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