KiCad PCB EDA Suite
|
#include <wx_grid.h>
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_PROVIDER * | getUnitsProvider (int aCol) const |
std::pair< EDA_UNITS, EDA_DATA_TYPE > | getColumnUnits (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_EVALUATOR > | m_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 |
WX_GRID::WX_GRID | ( | wxWindow * | parent, |
wxWindowID | id, | ||
const wxPoint & | pos = wxDefaultPosition, | ||
const wxSize & | size = wxDefaultSize, | ||
long | style = wxWANTS_CHARS, | ||
const wxString & | name = wxGridNameStr ) |
Definition at line 204 of file wx_grid.cpp.
References KIUI::GetControlFont(), m_weOwnTable, name, onCellEditorHidden(), onCellEditorShown(), onDPIChanged(), and SetLabelFont().
|
override |
Definition at line 224 of file wx_grid.cpp.
References DestroyTable(), m_weOwnTable, onCellEditorHidden(), onCellEditorShown(), and onDPIChanged().
bool WX_GRID::CancelPendingChanges | ( | ) |
Definition at line 594 of file wx_grid.cpp.
References editor.
|
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().
|
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().
|
inline |
bool WX_GRID::CommitPendingChanges | ( | bool | aQuietMode = false | ) |
Close any open cell edit controls.
aQuietMode | if true don't send events (ie: for row/col delete operations). |
Definition at line 622 of file wx_grid.cpp.
References editor.
Referenced by DestroyTable(), OnAddRow(), OnDeleteRows(), onGridColMove(), OnMoveRowDown(), and OnMoveRowUp().
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().
|
inlineoverride |
Definition at line 275 of file wx_grid.h.
References m_minSizeOverride.
Referenced by OverrideMinSize().
|
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.
|
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().
|
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.
void WX_GRID::EnableAlternateRowColors | ( | bool | aEnable = true | ) |
Enable alternate row highlighting, where every odd row has a different background color than the even rows.
aEnable | flag to specify to enable alternate row striping in the grid. |
Definition at line 302 of file wx_grid.cpp.
Referenced by SetTable().
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().
|
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().
std::optional< int > WX_GRID::GetOptionalUnitValue | ( | int | aRow, |
int | aCol ) |
Apply standard KiCad unit and eval services to a numeric cell.
aRow | the cell row index to fetch. |
aCol | the cell column index to fetch. |
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().
std::bitset< 64 > WX_GRID::GetShownColumns | ( | ) |
Definition at line 476 of file wx_grid.cpp.
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.
|
inlineprotected |
Definition at line 307 of file wx_grid.h.
References m_unitsProviders.
Referenced by getColumnUnits(), GetOptionalUnitValue(), GetUnitValue(), onCellEditorHidden(), SetOptionalUnitValue(), and SetUnitValue().
int WX_GRID::GetUnitValue | ( | int | aRow, |
int | aCol ) |
Apply standard KiCad unit and eval services to a numeric cell.
aRow | the cell row index to fetch. |
aCol | the cell column index to fetch. |
aIsOptional | if true, indicates to the unit provider the value is optional. |
Definition at line 844 of file wx_grid.cpp.
References alg::contains(), getColumnUnits(), getUnitsProvider(), m_autoEvalCols, m_eval, and UNITS_PROVIDER::ValueFromString().
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.
aCol | is the index of the column to resize. Specify -1 for the row labels. |
aHeader | is the header in the width calculation. |
aContents | is the full contents of the column. |
aKeep | is the current size as a minimum value. |
Definition at line 906 of file wx_grid.cpp.
References EnsureColLabelsVisible().
Referenced by PANEL_SETUP_TRACKS_AND_VIAS::PANEL_SETUP_TRACKS_AND_VIAS().
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().
|
protected |
Definition at line 362 of file wx_grid.cpp.
References alg::contains(), getColumnUnits(), getUnitsProvider(), m_autoEvalCols, m_eval, m_evalBeforeAfter, UNITS_PROVIDER::NullUiString, UNITS_PROVIDER::OptionalValueFromString(), UNITS_PROVIDER::StringFromOptionalValue(), UNITS_PROVIDER::StringFromValue(), and UNITS_PROVIDER::ValueFromString().
Referenced by WX_GRID(), and ~WX_GRID().
|
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().
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().
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().
|
protected |
Definition at line 235 of file wx_grid.cpp.
Referenced by WX_GRID(), and ~WX_GRID().
|
protected |
Definition at line 320 of file wx_grid.cpp.
Referenced by DestroyTable(), and SetTable().
|
protected |
Definition at line 899 of file wx_grid.cpp.
References CommitPendingChanges().
Referenced by DestroyTable(), and SetTable().
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().
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().
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().
void WX_GRID::OnMoveRowUp | ( | const std::function< void(int row)> & | aMover | ) |
|
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.
aSize |
Definition at line 269 of file wx_grid.h.
References DoGetBestSize(), KiROUND(), and m_minSizeOverride.
|
inline |
Definition at line 172 of file wx_grid.h.
References m_autoEvalCols.
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().
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().
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.
height |
Definition at line 246 of file wx_grid.cpp.
References MIN_GRIDCELL_MARGIN.
Referenced by EnsureColLabelsVisible().
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().
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().
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().
void WX_GRID::SetUnitsProvider | ( | UNITS_PROVIDER * | aProvider, |
int | aCol = 0 ) |
Set a EUNITS_PROVIDER to enable use of unit- and eval-based Getters.
aProvider |
Definition at line 822 of file wx_grid.cpp.
References UNITS_PROVIDER::GetUserUnits(), m_eval, and m_unitsProviders.
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.
|
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.
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.
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.
|
protected |
Definition at line 325 of file wx_grid.h.
Referenced by GetOptionalUnitValue(), GetUnitValue(), onCellEditorHidden(), onCellEditorShown(), and SetAutoEvalCols().
|
protected |
Definition at line 326 of file wx_grid.h.
Referenced by getColumnUnits(), SetAutoEvalColUnits(), and SetUnitValue().
|
protected |
Definition at line 324 of file wx_grid.h.
Referenced by GetOptionalUnitValue(), GetUnitValue(), onCellEditorHidden(), and SetUnitsProvider().
|
protected |
Definition at line 327 of file wx_grid.h.
Referenced by onCellEditorHidden(), and onCellEditorShown().
|
protected |
Definition at line 329 of file wx_grid.h.
Referenced by DoGetBestSize(), and OverrideMinSize().
|
protected |
Definition at line 323 of file wx_grid.h.
Referenced by getUnitsProvider(), and SetUnitsProvider().
|
protected |
Definition at line 321 of file wx_grid.h.
Referenced by SetTable(), WX_GRID(), and ~WX_GRID().