Add test for deleting item from wxDataViewCtrl
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47481 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
0c8ae72029
commit
e63807a8a4
@ -122,6 +122,9 @@ private:
|
||||
class MyMusicModel: public wxDataViewModel
|
||||
{
|
||||
public:
|
||||
|
||||
// constructor
|
||||
|
||||
MyMusicModel()
|
||||
{
|
||||
m_idCounter = 0;
|
||||
@ -141,6 +144,8 @@ public:
|
||||
m_classicalMusicIsKnownToControl = false;
|
||||
}
|
||||
|
||||
// helper methods to change the model
|
||||
|
||||
void AddToClassical( const wxString &title, const wxString &artist, const wxString &year )
|
||||
{
|
||||
// add to data
|
||||
@ -156,6 +161,18 @@ public:
|
||||
ItemAdded( parent, child );
|
||||
}
|
||||
}
|
||||
|
||||
void Delete( const wxDataViewItem &item )
|
||||
{
|
||||
MyMusicModelNode *node = FindNode( item );
|
||||
node->GetParent()->GetChildren().Remove( node );
|
||||
delete node;
|
||||
|
||||
// notify control
|
||||
ItemDeleted( item );
|
||||
}
|
||||
|
||||
// implementation of base class virtuals to define model
|
||||
|
||||
virtual unsigned int GetColumnCount() const
|
||||
{
|
||||
@ -302,6 +319,7 @@ public:
|
||||
void OnQuit(wxCommandEvent& event);
|
||||
void OnAbout(wxCommandEvent& event);
|
||||
void OnAdd(wxCommandEvent& event);
|
||||
void OnDelete(wxCommandEvent& event);
|
||||
|
||||
private:
|
||||
wxDataViewCtrl* m_dataview;
|
||||
@ -349,12 +367,14 @@ enum
|
||||
ID_EXIT = wxID_EXIT,
|
||||
|
||||
ID_ADD = 100,
|
||||
ID_DELETE = 101,
|
||||
};
|
||||
|
||||
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
EVT_MENU( ID_ABOUT, MyFrame::OnAbout )
|
||||
EVT_MENU( ID_EXIT, MyFrame::OnQuit )
|
||||
EVT_BUTTON( ID_ADD, MyFrame::OnAdd )
|
||||
EVT_BUTTON( ID_DELETE, MyFrame::OnDelete )
|
||||
END_EVENT_TABLE()
|
||||
|
||||
MyFrame::MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h):
|
||||
@ -395,6 +415,7 @@ MyFrame::MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h):
|
||||
wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
|
||||
|
||||
button_sizer->Add( new wxButton( this, ID_ADD, "Add Mozart"), 0, wxALL, 10 );
|
||||
button_sizer->Add( new wxButton( this, ID_DELETE, "Delete selected"), 0, wxALL, 10 );
|
||||
|
||||
main_sizer->Add( button_sizer, 0, 0, 0 );
|
||||
|
||||
@ -410,22 +431,15 @@ void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
|
||||
Close(true);
|
||||
}
|
||||
|
||||
void MyFrame::OnAdd(wxCommandEvent& WXUNUSED(event) )
|
||||
void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event) )
|
||||
{
|
||||
#if 0
|
||||
// ignore selection, do something better later
|
||||
wxDataViewItem item = m_dataview->GetSelection();
|
||||
if (item.IsOk())
|
||||
{
|
||||
if (m_model->HasChildren(item))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
m_model->Delete( item );
|
||||
}
|
||||
|
||||
void MyFrame::OnAdd(wxCommandEvent& WXUNUSED(event) )
|
||||
{
|
||||
m_model->AddToClassical( "Kleine Nachtmusik", "Wolfgang Mozart", "1787" );
|
||||
}
|
||||
|
||||
|
@ -118,6 +118,7 @@ public:
|
||||
GtkWxTreeModel* GetOwner() { return m_owner; }
|
||||
|
||||
bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
|
||||
bool ItemDeleted( const wxDataViewItem &item );
|
||||
|
||||
protected:
|
||||
void InitTree();
|
||||
@ -612,6 +613,16 @@ bool wxGtkTreeModel::ItemAdded( const wxDataViewItem &parent, const wxDataViewIt
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxGtkTreeModel::ItemDeleted( const wxDataViewItem &item )
|
||||
{
|
||||
wxGtkTreeModelNode *node = FindNode( item );
|
||||
wxGtkTreeModelNode *parent = node->GetParent();
|
||||
parent->GetChildren().Remove( node );
|
||||
delete node;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
gboolean wxGtkTreeModel::get_iter( GtkTreeIter *iter, GtkTreePath *path )
|
||||
{
|
||||
int depth = gtk_tree_path_get_depth( path );
|
||||
@ -1228,6 +1239,8 @@ bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem &item )
|
||||
GTK_TREE_MODEL(m_wxgtk_model), path );
|
||||
gtk_tree_path_free (path);
|
||||
|
||||
m_wxgtk_model->model->ItemDeleted( item );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user