Added wxDataViewListIndexModel::RowsDeleted() and various related corrections
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50764 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
ea3a345f1c
commit
8b6cf9bf10
@ -91,6 +91,14 @@ Call this after a row has been changed.
|
|||||||
|
|
||||||
Call this after a row has been deleted.
|
Call this after a row has been deleted.
|
||||||
|
|
||||||
|
\membersection{wxDataViewIndexListModel::RowsDeleted}\label{wxdataviewindexlistmodelrowdeleted}
|
||||||
|
|
||||||
|
\func{void}{RowsDeleted}{\param{const wxArrayInt &}{rows}}
|
||||||
|
|
||||||
|
Call this after rows have been deleted. The array will internally
|
||||||
|
get copied and sorted in descending order so that the rows with
|
||||||
|
the highest position will be deleted first.
|
||||||
|
|
||||||
\membersection{wxDataViewIndexListModel::RowInserted}\label{wxdataviewindexlistmodelrowinserted}
|
\membersection{wxDataViewIndexListModel::RowInserted}\label{wxdataviewindexlistmodelrowinserted}
|
||||||
|
|
||||||
\func{void}{RowInserted}{\param{unsigned int }{before}}
|
\func{void}{RowInserted}{\param{unsigned int }{before}}
|
||||||
|
@ -245,6 +245,7 @@ public:
|
|||||||
void RowInserted( unsigned int before );
|
void RowInserted( unsigned int before );
|
||||||
void RowAppended();
|
void RowAppended();
|
||||||
void RowDeleted( unsigned int row );
|
void RowDeleted( unsigned int row );
|
||||||
|
void RowsDeleted( const wxArrayInt &rows );
|
||||||
void RowChanged( unsigned int row );
|
void RowChanged( unsigned int row );
|
||||||
void RowValueChanged( unsigned int row, unsigned int col );
|
void RowValueChanged( unsigned int row, unsigned int col );
|
||||||
|
|
||||||
|
@ -353,6 +353,17 @@ private:
|
|||||||
bool m_classicalMusicIsKnownToControl;
|
bool m_classicalMusicIsKnownToControl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static int my_sort_reverse( int *v1, int *v2 )
|
||||||
|
{
|
||||||
|
return *v2-*v1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int my_sort( int *v1, int *v2 )
|
||||||
|
{
|
||||||
|
return *v1-*v2;
|
||||||
|
}
|
||||||
|
|
||||||
class MyListModel: public wxDataViewIndexListModel
|
class MyListModel: public wxDataViewIndexListModel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -389,6 +400,34 @@ public:
|
|||||||
RowDeleted( row );
|
RowDeleted( row );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeleteItems( const wxDataViewItemArray &items )
|
||||||
|
{
|
||||||
|
wxArrayInt rows;
|
||||||
|
unsigned int i;
|
||||||
|
for (i = 0; i < items.GetCount(); i++)
|
||||||
|
{
|
||||||
|
unsigned int row = GetRow( items[i] );
|
||||||
|
rows.Add( row );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort in descending order so that the last
|
||||||
|
// row will be deleted first. Otherwise the
|
||||||
|
// remaining indeces would all be wrong.
|
||||||
|
rows.Sort( my_sort_reverse );
|
||||||
|
for (i = 0; i < rows.GetCount(); i++)
|
||||||
|
m_array.RemoveAt( rows[i] );
|
||||||
|
|
||||||
|
// This is just to test if wxDataViewCtrl can
|
||||||
|
// cope with removing rows not sorted in
|
||||||
|
// descending order
|
||||||
|
rows.Sort( my_sort );
|
||||||
|
RowsDeleted( rows );
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddMany()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// implementation of base class virtuals to define model
|
// implementation of base class virtuals to define model
|
||||||
|
|
||||||
virtual unsigned int GetColumnCount() const
|
virtual unsigned int GetColumnCount() const
|
||||||
@ -522,6 +561,7 @@ public:
|
|||||||
|
|
||||||
void OnRightClick( wxMouseEvent &event );
|
void OnRightClick( wxMouseEvent &event );
|
||||||
void OnGoto( wxCommandEvent &event);
|
void OnGoto( wxCommandEvent &event);
|
||||||
|
void OnAddMany( wxCommandEvent &event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxDataViewCtrl* m_musicCtrl;
|
wxDataViewCtrl* m_musicCtrl;
|
||||||
@ -552,7 +592,7 @@ bool MyApp::OnInit(void)
|
|||||||
|
|
||||||
// build the first frame
|
// build the first frame
|
||||||
MyFrame *frame =
|
MyFrame *frame =
|
||||||
new MyFrame(NULL, wxT("wxDataViewCtrl feature test"), 40, 40, 800, 440);
|
new MyFrame(NULL, wxT("wxDataViewCtrl feature test"), 40, 40, 800, 540);
|
||||||
frame->Show(true);
|
frame->Show(true);
|
||||||
|
|
||||||
SetTopWindow(frame);
|
SetTopWindow(frame);
|
||||||
@ -583,7 +623,8 @@ enum
|
|||||||
|
|
||||||
ID_PREPEND_LIST = 200,
|
ID_PREPEND_LIST = 200,
|
||||||
ID_DELETE_LIST = 201,
|
ID_DELETE_LIST = 201,
|
||||||
ID_GOTO = 202
|
ID_GOTO = 202,
|
||||||
|
ID_ADD_MANY = 203
|
||||||
};
|
};
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||||
@ -595,6 +636,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|||||||
EVT_BUTTON( ID_PREPEND_LIST, MyFrame::OnPrependList )
|
EVT_BUTTON( ID_PREPEND_LIST, MyFrame::OnPrependList )
|
||||||
EVT_BUTTON( ID_DELETE_LIST, MyFrame::OnDeleteList )
|
EVT_BUTTON( ID_DELETE_LIST, MyFrame::OnDeleteList )
|
||||||
EVT_BUTTON( ID_GOTO, MyFrame::OnGoto)
|
EVT_BUTTON( ID_GOTO, MyFrame::OnGoto)
|
||||||
|
EVT_BUTTON( ID_ADD_MANY, MyFrame::OnAddMany)
|
||||||
|
|
||||||
EVT_DATAVIEW_ITEM_VALUE_CHANGED( ID_MUSIC_CTRL, MyFrame::OnValueChanged )
|
EVT_DATAVIEW_ITEM_VALUE_CHANGED( ID_MUSIC_CTRL, MyFrame::OnValueChanged )
|
||||||
|
|
||||||
@ -696,9 +738,12 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
|
|||||||
button_sizer->Add( new wxButton( this, ID_DELETE_MUSIC, "Delete selected"), 0, wxALL, 10 );
|
button_sizer->Add( new wxButton( this, ID_DELETE_MUSIC, "Delete selected"), 0, wxALL, 10 );
|
||||||
button_sizer->Add( new wxButton( this, ID_DELETE_YEAR, "Delete \"Year\" column"), 0, wxALL, 10 );
|
button_sizer->Add( new wxButton( this, ID_DELETE_YEAR, "Delete \"Year\" column"), 0, wxALL, 10 );
|
||||||
button_sizer->Add( 10, 10, 1 );
|
button_sizer->Add( 10, 10, 1 );
|
||||||
button_sizer->Add( new wxButton( this, ID_PREPEND_LIST, "Prepend"), 0, wxALL, 10 );
|
wxFlexGridSizer *grid_sizer = new wxFlexGridSizer( 2, 2 );
|
||||||
button_sizer->Add( new wxButton( this, ID_DELETE_LIST, "Delete selected"), 0, wxALL, 10 );
|
grid_sizer->Add( new wxButton( this, ID_PREPEND_LIST, "Prepend"), 0, wxALL, 2 );
|
||||||
button_sizer->Add( new wxButton( this, ID_GOTO, "Goto 50"), 0, wxALL, 10 );
|
grid_sizer->Add( new wxButton( this, ID_DELETE_LIST, "Delete selected"), 0, wxALL, 2 );
|
||||||
|
grid_sizer->Add( new wxButton( this, ID_GOTO, "Goto 50"), 0, wxALL, 2 );
|
||||||
|
grid_sizer->Add( new wxButton( this, ID_ADD_MANY, "Add 1000"), 0, wxALL, 2 );
|
||||||
|
button_sizer->Add( grid_sizer, 0, wxALL, 10 );
|
||||||
|
|
||||||
main_sizer->Add( button_sizer, 0, wxGROW, 0 );
|
main_sizer->Add( button_sizer, 0, wxGROW, 0 );
|
||||||
|
|
||||||
@ -783,9 +828,8 @@ void MyFrame::OnDeleteList( wxCommandEvent& WXUNUSED(event) )
|
|||||||
{
|
{
|
||||||
wxDataViewItemArray items;
|
wxDataViewItemArray items;
|
||||||
int len = m_listCtrl->GetSelections( items );
|
int len = m_listCtrl->GetSelections( items );
|
||||||
for( int i = 0; i < len; i ++ )
|
if (len > 0)
|
||||||
if (items[i].IsOk())
|
m_list_model->DeleteItems( items );
|
||||||
m_list_model->DeleteItem( items[i] );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyFrame::OnValueChanged( wxDataViewEvent &event )
|
void MyFrame::OnValueChanged( wxDataViewEvent &event )
|
||||||
@ -925,6 +969,12 @@ void MyFrame::OnGoto(wxCommandEvent& WXUNUSED(event))
|
|||||||
m_listCtrl->EnsureVisible(item,m_col);
|
m_listCtrl->EnsureVisible(item,m_col);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnAddMany(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
m_list_model->AddMany();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
|
||||||
{
|
{
|
||||||
wxAboutDialogInfo info;
|
wxAboutDialogInfo info;
|
||||||
|
@ -385,6 +385,8 @@ void wxDataViewIndexListModel::RowDeleted( unsigned int row )
|
|||||||
{
|
{
|
||||||
if (m_useHash)
|
if (m_useHash)
|
||||||
{
|
{
|
||||||
|
m_ordered = false;
|
||||||
|
|
||||||
wxDataViewItem item( m_hash[row] );
|
wxDataViewItem item( m_hash[row] );
|
||||||
wxDataViewModel::ItemDeleted( wxDataViewItem(0), item );
|
wxDataViewModel::ItemDeleted( wxDataViewItem(0), item );
|
||||||
m_hash.RemoveAt( row );
|
m_hash.RemoveAt( row );
|
||||||
@ -397,6 +399,47 @@ void wxDataViewIndexListModel::RowDeleted( unsigned int row )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int my_sort( int *v1, int *v2 )
|
||||||
|
{
|
||||||
|
return *v2-*v1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt &rows )
|
||||||
|
{
|
||||||
|
wxArrayInt sorted = rows;
|
||||||
|
sorted.Sort( my_sort );
|
||||||
|
|
||||||
|
if (m_useHash)
|
||||||
|
{
|
||||||
|
m_ordered = false;
|
||||||
|
|
||||||
|
wxDataViewItemArray array;
|
||||||
|
unsigned int i;
|
||||||
|
for (i = 0; i < rows.GetCount(); i++)
|
||||||
|
{
|
||||||
|
wxDataViewItem item( m_hash[rows[i]] );
|
||||||
|
array.Add( item );
|
||||||
|
}
|
||||||
|
wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array );
|
||||||
|
|
||||||
|
for (i = 0; i < sorted.GetCount(); i++)
|
||||||
|
m_hash.RemoveAt( sorted[i] );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxDataViewItemArray array;
|
||||||
|
unsigned int i;
|
||||||
|
for (i = 0; i < sorted.GetCount(); i++)
|
||||||
|
{
|
||||||
|
wxDataViewItem item( (void*) sorted[i] );
|
||||||
|
array.Add( item );
|
||||||
|
}
|
||||||
|
wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array );
|
||||||
|
|
||||||
|
m_lastIndex -= rows.GetCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void wxDataViewIndexListModel::RowChanged( unsigned int row )
|
void wxDataViewIndexListModel::RowChanged( unsigned int row )
|
||||||
{
|
{
|
||||||
wxDataViewModel::ItemChanged( GetItem(row) );
|
wxDataViewModel::ItemChanged( GetItem(row) );
|
||||||
|
@ -2048,6 +2048,13 @@ bool Walker( wxDataViewTreeNode * node, DoJob & func )
|
|||||||
|
|
||||||
bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxDataViewItem & item)
|
bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxDataViewItem & item)
|
||||||
{
|
{
|
||||||
|
if (!m_root)
|
||||||
|
{
|
||||||
|
m_count++;
|
||||||
|
UpdateDisplay();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
SortPrepare();
|
SortPrepare();
|
||||||
|
|
||||||
wxDataViewTreeNode * node;
|
wxDataViewTreeNode * node;
|
||||||
@ -2081,6 +2088,19 @@ void DestroyTreeHelper( wxDataViewTreeNode * node);
|
|||||||
bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent,
|
bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent,
|
||||||
const wxDataViewItem& item)
|
const wxDataViewItem& item)
|
||||||
{
|
{
|
||||||
|
if (!m_root)
|
||||||
|
{
|
||||||
|
m_count--;
|
||||||
|
if( m_currentRow > GetRowCount() )
|
||||||
|
m_currentRow = m_count - 1;
|
||||||
|
|
||||||
|
m_selection.Empty();
|
||||||
|
|
||||||
|
UpdateDisplay();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
wxDataViewTreeNode * node = FindNode(parent);
|
wxDataViewTreeNode * node = FindNode(parent);
|
||||||
|
|
||||||
wxCHECK_MSG( node != NULL, false, "item not found" );
|
wxCHECK_MSG( node != NULL, false, "item not found" );
|
||||||
|
Loading…
Reference in New Issue
Block a user