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:
@@ -122,6 +122,9 @@ private:
|
|||||||
class MyMusicModel: public wxDataViewModel
|
class MyMusicModel: public wxDataViewModel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
|
||||||
MyMusicModel()
|
MyMusicModel()
|
||||||
{
|
{
|
||||||
m_idCounter = 0;
|
m_idCounter = 0;
|
||||||
@@ -141,6 +144,8 @@ public:
|
|||||||
m_classicalMusicIsKnownToControl = false;
|
m_classicalMusicIsKnownToControl = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// helper methods to change the model
|
||||||
|
|
||||||
void AddToClassical( const wxString &title, const wxString &artist, const wxString &year )
|
void AddToClassical( const wxString &title, const wxString &artist, const wxString &year )
|
||||||
{
|
{
|
||||||
// add to data
|
// add to data
|
||||||
@@ -156,6 +161,18 @@ public:
|
|||||||
ItemAdded( parent, child );
|
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
|
virtual unsigned int GetColumnCount() const
|
||||||
{
|
{
|
||||||
@@ -302,6 +319,7 @@ public:
|
|||||||
void OnQuit(wxCommandEvent& event);
|
void OnQuit(wxCommandEvent& event);
|
||||||
void OnAbout(wxCommandEvent& event);
|
void OnAbout(wxCommandEvent& event);
|
||||||
void OnAdd(wxCommandEvent& event);
|
void OnAdd(wxCommandEvent& event);
|
||||||
|
void OnDelete(wxCommandEvent& event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxDataViewCtrl* m_dataview;
|
wxDataViewCtrl* m_dataview;
|
||||||
@@ -349,12 +367,14 @@ enum
|
|||||||
ID_EXIT = wxID_EXIT,
|
ID_EXIT = wxID_EXIT,
|
||||||
|
|
||||||
ID_ADD = 100,
|
ID_ADD = 100,
|
||||||
|
ID_DELETE = 101,
|
||||||
};
|
};
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||||
EVT_MENU( ID_ABOUT, MyFrame::OnAbout )
|
EVT_MENU( ID_ABOUT, MyFrame::OnAbout )
|
||||||
EVT_MENU( ID_EXIT, MyFrame::OnQuit )
|
EVT_MENU( ID_EXIT, MyFrame::OnQuit )
|
||||||
EVT_BUTTON( ID_ADD, MyFrame::OnAdd )
|
EVT_BUTTON( ID_ADD, MyFrame::OnAdd )
|
||||||
|
EVT_BUTTON( ID_DELETE, MyFrame::OnDelete )
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
MyFrame::MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h):
|
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 );
|
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_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 );
|
main_sizer->Add( button_sizer, 0, 0, 0 );
|
||||||
|
|
||||||
@@ -410,22 +431,15 @@ void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
|
|||||||
Close(true);
|
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();
|
wxDataViewItem item = m_dataview->GetSelection();
|
||||||
if (item.IsOk())
|
if (item.IsOk())
|
||||||
{
|
m_model->Delete( item );
|
||||||
if (m_model->HasChildren(item))
|
}
|
||||||
{
|
|
||||||
}
|
void MyFrame::OnAdd(wxCommandEvent& WXUNUSED(event) )
|
||||||
else
|
{
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
m_model->AddToClassical( "Kleine Nachtmusik", "Wolfgang Mozart", "1787" );
|
m_model->AddToClassical( "Kleine Nachtmusik", "Wolfgang Mozart", "1787" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -118,6 +118,7 @@ public:
|
|||||||
GtkWxTreeModel* GetOwner() { return m_owner; }
|
GtkWxTreeModel* GetOwner() { return m_owner; }
|
||||||
|
|
||||||
bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
|
bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
|
||||||
|
bool ItemDeleted( const wxDataViewItem &item );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void InitTree();
|
void InitTree();
|
||||||
@@ -612,6 +613,16 @@ bool wxGtkTreeModel::ItemAdded( const wxDataViewItem &parent, const wxDataViewIt
|
|||||||
return true;
|
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 )
|
gboolean wxGtkTreeModel::get_iter( GtkTreeIter *iter, GtkTreePath *path )
|
||||||
{
|
{
|
||||||
int depth = gtk_tree_path_get_depth( 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_MODEL(m_wxgtk_model), path );
|
||||||
gtk_tree_path_free (path);
|
gtk_tree_path_free (path);
|
||||||
|
|
||||||
|
m_wxgtk_model->model->ItemDeleted( item );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user