Don't put null value in map as a side-effect of using [].

This commit is contained in:
Jeff Young
2025-04-18 13:41:19 -07:00
committed by Seth Hillbrand
parent 24cef6d165
commit 53e509326c
2 changed files with 14 additions and 36 deletions
+6 -36
View File
@@ -375,10 +375,7 @@ void WX_GRID::onCellEditorHidden( wxGridEvent& aEvent )
if( alg::contains( m_autoEvalCols, col ) )
{
UNITS_PROVIDER* unitsProvider = m_unitsProviders[ aEvent.GetCol() ];
if( !unitsProvider )
unitsProvider = m_unitsProviders.begin()->second;
UNITS_PROVIDER* unitsProvider = getUnitsProvider( col );
auto [cellUnits, cellDataType] = getColumnUnits( col );
@@ -723,11 +720,6 @@ void WX_GRID::SetAutoEvalColUnits( const int col, EDA_UNITS aUnit )
int WX_GRID::GetUnitValue( int aRow, int aCol )
{
UNITS_PROVIDER* unitsProvider = m_unitsProviders[ aCol ];
if( !unitsProvider )
unitsProvider = m_unitsProviders.begin()->second;
wxString stringValue = GetCellValue( aRow, aCol );
auto [cellUnits, cellDataType] = getColumnUnits( aCol );
@@ -740,17 +732,12 @@ int WX_GRID::GetUnitValue( int aRow, int aCol )
stringValue = m_eval->Result();
}
return unitsProvider->ValueFromString( stringValue, cellDataType );
return getUnitsProvider( aCol )->ValueFromString( stringValue, cellDataType );
}
std::optional<int> WX_GRID::GetOptionalUnitValue( int aRow, int aCol )
{
UNITS_PROVIDER* unitsProvider = m_unitsProviders[aCol];
if( !unitsProvider )
unitsProvider = m_unitsProviders.begin()->second;
wxString stringValue = GetCellValue( aRow, aCol );
auto [cellUnits, cellDataType] = getColumnUnits( aCol );
@@ -763,17 +750,12 @@ std::optional<int> WX_GRID::GetOptionalUnitValue( int aRow, int aCol )
stringValue = m_eval->Result();
}
return unitsProvider->OptionalValueFromString( stringValue, cellDataType );
return getUnitsProvider( aCol )->OptionalValueFromString( stringValue, cellDataType );
}
void WX_GRID::SetUnitValue( int aRow, int aCol, int aValue )
{
UNITS_PROVIDER* unitsProvider = m_unitsProviders[ aCol ];
if( !unitsProvider )
unitsProvider = m_unitsProviders.begin()->second;
EDA_DATA_TYPE cellDataType;
if( m_autoEvalColsUnits.contains( aCol ) )
@@ -781,18 +763,13 @@ void WX_GRID::SetUnitValue( int aRow, int aCol, int aValue )
else
cellDataType = EDA_DATA_TYPE::DISTANCE;
SetCellValue( aRow, aCol, unitsProvider->StringFromValue( aValue, true, cellDataType ) );
SetCellValue( aRow, aCol, getUnitsProvider( aCol )->StringFromValue( aValue, true, cellDataType ) );
}
void WX_GRID::SetOptionalUnitValue( int aRow, int aCol, std::optional<int> aValue )
{
UNITS_PROVIDER* unitsProvider = m_unitsProviders[aCol];
if( !unitsProvider )
unitsProvider = m_unitsProviders.begin()->second;
SetCellValue( aRow, aCol, unitsProvider->StringFromOptionalValue( aValue, true ) );
SetCellValue( aRow, aCol, getUnitsProvider( aCol )->StringFromOptionalValue( aValue, true ) );
}
@@ -877,13 +854,6 @@ std::pair<EDA_UNITS, EDA_DATA_TYPE> WX_GRID::getColumnUnits( const int aCol ) co
if( m_autoEvalColsUnits.contains( aCol ) )
return { m_autoEvalColsUnits.at( aCol ).first, m_autoEvalColsUnits.at( aCol ).second };
UNITS_PROVIDER* unitsProvider;
if( m_unitsProviders.contains( aCol ) )
unitsProvider = m_unitsProviders.at( aCol );
else
unitsProvider = m_unitsProviders.begin()->second;
// Legacy - default always DISTANCE
return { unitsProvider->GetUserUnits(), EDA_DATA_TYPE::DISTANCE };
return { getUnitsProvider( aCol )->GetUserUnits(), EDA_DATA_TYPE::DISTANCE };
}
+8
View File
@@ -260,6 +260,14 @@ protected:
void onDPIChanged(wxDPIChangedEvent& event);
UNITS_PROVIDER* getUnitsProvider( int aCol ) const
{
if( m_unitsProviders.contains( aCol ) )
return m_unitsProviders.at( aCol );
else
return m_unitsProviders.begin()->second;
}
/**
* Returns the units and data type associated with a given column
*/