Use type safe list for model notifiers, sample corrected
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47722 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -81,10 +81,38 @@ private:
|
||||
|
||||
bool operator == (const wxDataViewItem &left, const wxDataViewItem &right);
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// wxDataViewModelNotifier
|
||||
// ---------------------------------------------------------
|
||||
|
||||
class WXDLLIMPEXP_ADV wxDataViewModelNotifier
|
||||
{
|
||||
public:
|
||||
wxDataViewModelNotifier() { }
|
||||
virtual ~wxDataViewModelNotifier() { m_owner = NULL; }
|
||||
|
||||
virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ) = 0;
|
||||
virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item ) = 0;
|
||||
virtual bool ItemChanged( const wxDataViewItem &item ) = 0;
|
||||
virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col ) = 0;
|
||||
virtual bool Cleared() = 0;
|
||||
|
||||
virtual void Resort() { }
|
||||
|
||||
void SetOwner( wxDataViewModel *owner ) { m_owner = owner; }
|
||||
wxDataViewModel *GetOwner() { return m_owner; }
|
||||
|
||||
private:
|
||||
wxDataViewModel *m_owner;
|
||||
};
|
||||
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// wxDataViewModel
|
||||
// ---------------------------------------------------------
|
||||
|
||||
WX_DECLARE_LIST(wxDataViewModelNotifier, wxDataViewModelNotifiers );
|
||||
|
||||
class WXDLLIMPEXP_ADV wxDataViewModel: public wxObjectRefData
|
||||
{
|
||||
public:
|
||||
@@ -135,7 +163,7 @@ protected:
|
||||
// the user should not delete this class directly: he should use DecRef() instead!
|
||||
virtual ~wxDataViewModel() { }
|
||||
|
||||
wxList m_notifiers;
|
||||
wxDataViewModelNotifiers m_notifiers;
|
||||
unsigned int m_sortingColumn;
|
||||
bool m_ascending;
|
||||
};
|
||||
@@ -193,32 +221,6 @@ private:
|
||||
unsigned int m_lastIndex;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// wxDataViewModelNotifier
|
||||
// ---------------------------------------------------------
|
||||
|
||||
class WXDLLIMPEXP_ADV wxDataViewModelNotifier: public wxObject
|
||||
{
|
||||
public:
|
||||
wxDataViewModelNotifier() { }
|
||||
virtual ~wxDataViewModelNotifier() { m_owner = NULL; }
|
||||
|
||||
virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ) = 0;
|
||||
virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item ) = 0;
|
||||
virtual bool ItemChanged( const wxDataViewItem &item ) = 0;
|
||||
virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col ) = 0;
|
||||
virtual bool Cleared() = 0;
|
||||
|
||||
virtual void Resort() { };
|
||||
|
||||
void SetOwner( wxDataViewModel *owner ) { m_owner = owner; }
|
||||
wxDataViewModel *GetOwner() { return m_owner; }
|
||||
|
||||
private:
|
||||
wxDataViewModel *m_owner;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxDataViewEditorCtrlEvtHandler
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@@ -160,11 +160,12 @@ public:
|
||||
void Delete( const wxDataViewItem &item )
|
||||
{
|
||||
MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
|
||||
wxDataViewItem parent( node->GetParent() );
|
||||
node->GetParent()->GetChildren().Remove( node );
|
||||
delete node;
|
||||
|
||||
// notify control
|
||||
ItemDeleted( item );
|
||||
ItemDeleted( parent, item );
|
||||
}
|
||||
|
||||
// override sorting to always sort branches ascendingly
|
||||
@@ -577,7 +578,7 @@ void MyFrame::OnDeleteMusic(wxCommandEvent& WXUNUSED(event) )
|
||||
{
|
||||
wxDataViewItem item = m_musicCtrl->GetSelection();
|
||||
if (item.IsOk())
|
||||
m_music_model->Delete( m_music_model->GetParent(item), item );
|
||||
m_music_model->Delete( item );
|
||||
}
|
||||
|
||||
void MyFrame::OnPrependList( wxCommandEvent& WXUNUSED(event) )
|
||||
@@ -589,7 +590,7 @@ void MyFrame::OnDeleteList( wxCommandEvent& WXUNUSED(event) )
|
||||
{
|
||||
wxDataViewItem item = m_listCtrl->GetSelection();
|
||||
if (item.IsOk())
|
||||
m_list_model->DeleteItem( m_list_model->GetParent(item), item );
|
||||
m_list_model->DeleteItem( item );
|
||||
}
|
||||
|
||||
void MyFrame::OnItemAdded( wxDataViewEvent &event )
|
||||
|
@@ -36,6 +36,9 @@ bool operator == (const wxDataViewItem &left, const wxDataViewItem &right)
|
||||
// wxDataViewModel
|
||||
// ---------------------------------------------------------
|
||||
|
||||
#include <wx/listimpl.cpp>
|
||||
WX_DEFINE_LIST(wxDataViewModelNotifiers);
|
||||
|
||||
wxDataViewModel::wxDataViewModel()
|
||||
{
|
||||
m_notifiers.DeleteContents( true );
|
||||
@@ -47,13 +50,12 @@ bool wxDataViewModel::ItemAdded( const wxDataViewItem &parent, const wxDataViewI
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
wxList::compatibility_iterator node = m_notifiers.GetFirst();
|
||||
while (node)
|
||||
wxDataViewModelNotifiers::iterator iter;
|
||||
for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
|
||||
{
|
||||
wxDataViewModelNotifier* notifier = (wxDataViewModelNotifier*) node->GetData();
|
||||
wxDataViewModelNotifier* notifier = *iter;
|
||||
if (!notifier->ItemAdded( parent, item ))
|
||||
ret = false;
|
||||
node = node->GetNext();
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -63,13 +65,12 @@ bool wxDataViewModel::ItemDeleted( const wxDataViewItem &parent, const wxDataVie
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
wxList::compatibility_iterator node = m_notifiers.GetFirst();
|
||||
while (node)
|
||||
wxDataViewModelNotifiers::iterator iter;
|
||||
for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
|
||||
{
|
||||
wxDataViewModelNotifier* notifier = (wxDataViewModelNotifier*) node->GetData();
|
||||
wxDataViewModelNotifier* notifier = *iter;
|
||||
if (!notifier->ItemDeleted( parent, item ))
|
||||
ret = false;
|
||||
node = node->GetNext();
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -79,13 +80,12 @@ bool wxDataViewModel::ItemChanged( const wxDataViewItem &item )
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
wxList::compatibility_iterator node = m_notifiers.GetFirst();
|
||||
while (node)
|
||||
wxDataViewModelNotifiers::iterator iter;
|
||||
for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
|
||||
{
|
||||
wxDataViewModelNotifier* notifier = (wxDataViewModelNotifier*) node->GetData();
|
||||
wxDataViewModelNotifier* notifier = *iter;
|
||||
if (!notifier->ItemChanged( item ))
|
||||
ret = false;
|
||||
node = node->GetNext();
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -95,13 +95,12 @@ bool wxDataViewModel::ValueChanged( const wxDataViewItem &item, unsigned int col
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
wxList::compatibility_iterator node = m_notifiers.GetFirst();
|
||||
while (node)
|
||||
wxDataViewModelNotifiers::iterator iter;
|
||||
for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
|
||||
{
|
||||
wxDataViewModelNotifier* notifier = (wxDataViewModelNotifier*) node->GetData();
|
||||
wxDataViewModelNotifier* notifier = *iter;
|
||||
if (!notifier->ValueChanged( item, col ))
|
||||
ret = false;
|
||||
node = node->GetNext();
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -111,13 +110,12 @@ bool wxDataViewModel::Cleared()
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
wxList::compatibility_iterator node = m_notifiers.GetFirst();
|
||||
while (node)
|
||||
wxDataViewModelNotifiers::iterator iter;
|
||||
for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
|
||||
{
|
||||
wxDataViewModelNotifier* notifier = (wxDataViewModelNotifier*) node->GetData();
|
||||
wxDataViewModelNotifier* notifier = *iter;
|
||||
if (!notifier->Cleared())
|
||||
ret = false;
|
||||
node = node->GetNext();
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -125,18 +123,17 @@ bool wxDataViewModel::Cleared()
|
||||
|
||||
void wxDataViewModel::Resort()
|
||||
{
|
||||
wxList::compatibility_iterator node = m_notifiers.GetFirst();
|
||||
while (node)
|
||||
wxDataViewModelNotifiers::iterator iter;
|
||||
for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
|
||||
{
|
||||
wxDataViewModelNotifier* notifier = (wxDataViewModelNotifier*) node->GetData();
|
||||
wxDataViewModelNotifier* notifier = *iter;
|
||||
notifier->Resort();
|
||||
node = node->GetNext();
|
||||
}
|
||||
}
|
||||
|
||||
void wxDataViewModel::AddNotifier( wxDataViewModelNotifier *notifier )
|
||||
{
|
||||
m_notifiers.Append( notifier );
|
||||
m_notifiers.push_back( notifier );
|
||||
notifier->SetOwner( this );
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user