Add wxDataViewModel::ChangeValue() and use it in wxDVC implementation.
ChangeValue() is a trivial wrapper calling both SetValue() and ValueChanged(). It allows to replace many calls to SetValue() immediately followed by ValueChanged() with a single function call which is significantly shorter and less error-prone (e.g. most of the existing code didn't test SetValue() return code at all). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62489 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
8c9833d09e
commit
795dac4c86
@ -186,9 +186,20 @@ public:
|
||||
virtual void GetValue( wxVariant &variant,
|
||||
const wxDataViewItem &item, unsigned int col ) const = 0;
|
||||
|
||||
// set value, call ValueChanged() afterwards!
|
||||
virtual bool SetValue( const wxVariant &variant,
|
||||
const wxDataViewItem &item, unsigned int col ) = 0;
|
||||
// usually ValueChanged() should be called after changing the value in the
|
||||
// model to update the control, ChangeValue() does it on its own while
|
||||
// SetValue() does not -- so while you will override SetValue(), you should
|
||||
// be usually calling ChangeValue()
|
||||
virtual bool SetValue(const wxVariant &variant,
|
||||
const wxDataViewItem &item,
|
||||
unsigned int col) = 0;
|
||||
|
||||
bool ChangeValue(const wxVariant& variant,
|
||||
const wxDataViewItem& item,
|
||||
unsigned int col)
|
||||
{
|
||||
return SetValue(variant, item, col) && ValueChanged(item, col);
|
||||
}
|
||||
|
||||
// Get text attribute, return false of default attributes should be used
|
||||
virtual bool GetAttr( const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col), wxDataViewItemAttr &WXUNUSED(attr) )
|
||||
|
@ -23,7 +23,7 @@
|
||||
Since you will usually also allow the wxDataViewCtrl to change your data
|
||||
through its graphical interface, you will also have to override
|
||||
wxDataViewModel::SetValue which the wxDataViewCtrl will call when a change
|
||||
to some data has been commited.
|
||||
to some data has been committed.
|
||||
|
||||
wxDataViewModel (as indeed the entire wxDataViewCtrl code) is using wxVariant
|
||||
to store data and its type in a generic way. wxVariant can be extended to contain
|
||||
@ -91,6 +91,28 @@ public:
|
||||
*/
|
||||
void AddNotifier(wxDataViewModelNotifier* notifier);
|
||||
|
||||
/**
|
||||
Change the value of the given item and update the control to reflect
|
||||
it.
|
||||
|
||||
This function simply calls SetValue() and, if it succeeded,
|
||||
ValueChanged().
|
||||
|
||||
@since 2.9.1
|
||||
|
||||
@param variable
|
||||
The new value.
|
||||
@param item
|
||||
The item (row) to update.
|
||||
@param col
|
||||
The column to update.
|
||||
@return
|
||||
@true if both SetValue() and ValueChanged() returned @true.
|
||||
*/
|
||||
bool ChangeValue(const wxVariant& variant,
|
||||
const wxDataViewItem& item,
|
||||
unsigned int col);
|
||||
|
||||
/**
|
||||
Called to inform the model that all data has been cleared.
|
||||
The control will reread the data from the model again.
|
||||
@ -229,12 +251,17 @@ public:
|
||||
|
||||
/**
|
||||
This gets called in order to set a value in the data model.
|
||||
|
||||
The most common scenario is that the wxDataViewCtrl calls this method
|
||||
after the user changed some data in the view.
|
||||
|
||||
Afterwards ValueChanged() has to be called!
|
||||
This is the function you need to override in your derived class but if
|
||||
you want to call it, ChangeValue() is usually more convenient as
|
||||
otherwise you need to manually call ValueChanged() to update the
|
||||
control itself.
|
||||
*/
|
||||
virtual bool SetValue(const wxVariant& variant, const wxDataViewItem& item,
|
||||
virtual bool SetValue(const wxVariant& variant,
|
||||
const wxDataViewItem& item,
|
||||
unsigned int col) = 0;
|
||||
|
||||
/**
|
||||
|
@ -751,8 +751,7 @@ bool wxDataViewRendererBase::FinishEditing()
|
||||
return false;
|
||||
|
||||
unsigned int col = GetOwner()->GetModelColumn();
|
||||
dv_ctrl->GetModel()->SetValue( value, m_item, col );
|
||||
dv_ctrl->GetModel()->ValueChanged( m_item, col );
|
||||
dv_ctrl->GetModel()->ChangeValue(value, m_item, col);
|
||||
|
||||
// Now we should send Editing Done event
|
||||
wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, dv_ctrl->GetId() );
|
||||
|
@ -933,10 +933,7 @@ bool wxDataViewToggleRenderer::Activate( wxRect WXUNUSED(cell),
|
||||
wxDataViewModel *model,
|
||||
const wxDataViewItem & item, unsigned int col)
|
||||
{
|
||||
bool value = !m_toggle;
|
||||
wxVariant variant = value;
|
||||
model->SetValue( variant, item, col);
|
||||
model->ValueChanged( item, col );
|
||||
model->ChangeValue(!m_toggle, item, col);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1051,10 +1048,7 @@ END_EVENT_TABLE()
|
||||
|
||||
void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent &event )
|
||||
{
|
||||
wxDateTime date = event.GetDate();
|
||||
wxVariant value = date;
|
||||
m_model->SetValue( value, m_item, m_col );
|
||||
m_model->ValueChanged( m_item, m_col );
|
||||
m_model->ChangeValue( event.GetDate(), m_item, m_col );
|
||||
DismissAndNotify();
|
||||
}
|
||||
|
||||
|
@ -1742,8 +1742,7 @@ wxDataViewRenderer::GtkOnCellChanged(const wxVariant& value,
|
||||
unsigned col)
|
||||
{
|
||||
wxDataViewModel *model = GetOwner()->GetOwner()->GetModel();
|
||||
model->SetValue( value, item, col );
|
||||
model->ValueChanged( item, col );
|
||||
model->ChangeValue( value, item, col );
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
@ -1933,8 +1932,7 @@ static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle *renderer,
|
||||
|
||||
unsigned int model_col = cell->GetOwner()->GetModelColumn();
|
||||
|
||||
model->SetValue( value, item, model_col );
|
||||
model->ValueChanged( item, model_col );
|
||||
model->ChangeValue( value, item, model_col );
|
||||
}
|
||||
|
||||
IMPLEMENT_CLASS(wxDataViewToggleRenderer, wxDataViewRenderer)
|
||||
@ -2371,10 +2369,7 @@ END_EVENT_TABLE()
|
||||
|
||||
void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent &event )
|
||||
{
|
||||
wxDateTime date = event.GetDate();
|
||||
wxVariant value = date;
|
||||
m_model->SetValue( value, m_item, m_col );
|
||||
m_model->ValueChanged( m_item, m_col );
|
||||
m_model->ChangeValue( event.GetDate(), m_item, m_col );
|
||||
DismissAndNotify();
|
||||
}
|
||||
|
||||
|
@ -1318,8 +1318,7 @@ OSStatus wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(
|
||||
// variable definition and initialization:
|
||||
wxVariant modifiedData(true);
|
||||
|
||||
if (dataViewCtrlPtr->GetModel()->SetValue(modifiedData, dvItem, col) &&
|
||||
dataViewCtrlPtr->GetModel()->ValueChanged(dvItem, col))
|
||||
if (dataViewCtrlPtr->GetModel()->ChangeValue(modifiedData, dvItem, col))
|
||||
return noErr;
|
||||
else
|
||||
return errDataBrowserInvalidPropertyData;
|
||||
@ -1329,8 +1328,7 @@ OSStatus wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(
|
||||
// variable definition and initialization:
|
||||
wxVariant modifiedData(false);
|
||||
|
||||
if (dataViewCtrlPtr->GetModel()->SetValue(modifiedData, dvItem, col) &&
|
||||
dataViewCtrlPtr->GetModel()->ValueChanged(dvItem, col))
|
||||
if (dataViewCtrlPtr->GetModel()->ChangeValue(modifiedData, dvItem, col))
|
||||
return noErr;
|
||||
else
|
||||
return errDataBrowserInvalidPropertyData;
|
||||
@ -1357,8 +1355,7 @@ OSStatus wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(
|
||||
#endif
|
||||
wxVariant modifiedData(modifiedString.AsString());
|
||||
|
||||
if (dataViewCtrlPtr->GetModel()->SetValue(modifiedData, dvItem, col) &&
|
||||
dataViewCtrlPtr->GetModel()->ValueChanged(dvItem, col))
|
||||
if (dataViewCtrlPtr->GetModel()->ChangeValue(modifiedData, dvItem, col))
|
||||
return noErr;
|
||||
else
|
||||
return errDataBrowserInvalidPropertyData;
|
||||
|
@ -2236,8 +2236,7 @@ void wxDataViewRenderer::OSXOnCellChanged(const wxVariant& value,
|
||||
unsigned col)
|
||||
{
|
||||
wxDataViewModel *model = GetOwner()->GetOwner()->GetModel();
|
||||
model->SetValue(value, item, col);
|
||||
model->ValueChanged(item, col);
|
||||
model->ChangeValue(value, item, col);
|
||||
}
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer,wxDataViewRendererBase)
|
||||
|
Loading…
Reference in New Issue
Block a user