don't ignore changes of empty string to 0 or vice versa in float grid cells (#4764)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54410 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1113,7 +1113,7 @@ void wxGridCellFloatEditor::Create(wxWindow* parent,
|
|||||||
void wxGridCellFloatEditor::BeginEdit(int row, int col, wxGrid* grid)
|
void wxGridCellFloatEditor::BeginEdit(int row, int col, wxGrid* grid)
|
||||||
{
|
{
|
||||||
// first get the value
|
// first get the value
|
||||||
wxGridTableBase *table = grid->GetTable();
|
wxGridTableBase * const table = grid->GetTable();
|
||||||
if ( table->CanGetValueAs(row, col, wxGRID_VALUE_FLOAT) )
|
if ( table->CanGetValueAs(row, col, wxGRID_VALUE_FLOAT) )
|
||||||
{
|
{
|
||||||
m_valueOld = table->GetValueAsDouble(row, col);
|
m_valueOld = table->GetValueAsDouble(row, col);
|
||||||
@@ -1121,35 +1121,53 @@ void wxGridCellFloatEditor::BeginEdit(int row, int col, wxGrid* grid)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_valueOld = 0.0;
|
m_valueOld = 0.0;
|
||||||
wxString sValue = table->GetValue(row, col);
|
|
||||||
if (! sValue.ToDouble(&m_valueOld) && ! sValue.empty())
|
const wxString value = table->GetValue(row, col);
|
||||||
|
if ( !value.empty() )
|
||||||
|
{
|
||||||
|
if ( !value.ToDouble(&m_valueOld) )
|
||||||
{
|
{
|
||||||
wxFAIL_MSG( _T("this cell doesn't have float value") );
|
wxFAIL_MSG( _T("this cell doesn't have float value") );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DoBeginEdit(GetString());
|
DoBeginEdit(GetString());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxGridCellFloatEditor::EndEdit(int row, int col,
|
bool wxGridCellFloatEditor::EndEdit(int row, int col, wxGrid* grid)
|
||||||
wxGrid* grid)
|
|
||||||
{
|
{
|
||||||
double value = 0.0;
|
const wxString text(Text()->GetValue()),
|
||||||
wxString text(Text()->GetValue());
|
textOld(grid->GetCellValue(row, col));
|
||||||
|
|
||||||
if ( (text.empty() || text.ToDouble(&value)) &&
|
double value;
|
||||||
!wxIsSameDouble(value, m_valueOld) )
|
if ( !text.empty() )
|
||||||
{
|
{
|
||||||
if (grid->GetTable()->CanSetValueAs(row, col, wxGRID_VALUE_FLOAT))
|
if ( !text.ToDouble(&value) )
|
||||||
grid->GetTable()->SetValueAsDouble(row, col, value);
|
return false;
|
||||||
else
|
}
|
||||||
grid->GetTable()->SetValue(row, col, text);
|
else // new value is empty string
|
||||||
|
{
|
||||||
|
if ( textOld.empty() )
|
||||||
|
return false; // nothing changed
|
||||||
|
|
||||||
return true;
|
value = 0.;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
// the test for empty strings ensures that we don't skip the value setting
|
||||||
|
// when "" is replaced by "0" or vice versa as "" numeric value is also 0.
|
||||||
|
if ( wxIsSameDouble(value, m_valueOld) && !text.empty() && !textOld.empty() )
|
||||||
|
return false; // nothing changed
|
||||||
|
|
||||||
|
wxGridTableBase * const table = grid->GetTable();
|
||||||
|
|
||||||
|
if ( table->CanSetValueAs(row, col, wxGRID_VALUE_FLOAT) )
|
||||||
|
table->SetValueAsDouble(row, col, value);
|
||||||
|
else
|
||||||
|
table->SetValue(row, col, text);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGridCellFloatEditor::Reset()
|
void wxGridCellFloatEditor::Reset()
|
||||||
|
Reference in New Issue
Block a user