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) )
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
*/
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.
/**
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;
/**
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() );
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;
}
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();
}
unsigned col)
{
wxDataViewModel *model = GetOwner()->GetOwner()->GetModel();
- model->SetValue( value, item, col );
- model->ValueChanged( item, col );
+ model->ChangeValue( value, item, col );
}
// ---------------------------------------------------------
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)
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();
}
// 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;
// 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;
#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;
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)