Add wxDataViewListCtrl::{Set,Get}ItemData() methods.

These methods are convenient when migrating the code that previously used
wxListCtrl to wxDataViewCtrl.

Closes #11088.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71562 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2012-05-25 17:02:35 +00:00
parent 41abc29aa6
commit 518cef0470
4 changed files with 68 additions and 0 deletions

View File

@@ -556,6 +556,7 @@ All (GUI):
- Added custom text and dimension scaling to wxRichTextCtrl. - Added custom text and dimension scaling to wxRichTextCtrl.
- Added pixel font size capability to wxTextAttr and wxRichTextCtrl. - Added pixel font size capability to wxTextAttr and wxRichTextCtrl.
- Fully implement wxStyledTextCtrl::PositionToXY() (troelsk). - Fully implement wxStyledTextCtrl::PositionToXY() (troelsk).
- Added wxDataViewListCtrl::{Set,Get}ItemData().
GTK: GTK:

View File

@@ -972,6 +972,9 @@ public:
void DeleteItem( unsigned int pos ); void DeleteItem( unsigned int pos );
void DeleteAllItems(); void DeleteAllItems();
void SetItemData( const wxDataViewItem& item, wxUIntPtr data );
wxUIntPtr GetItemData( const wxDataViewItem& item ) const;
// override base virtuals // override base virtuals
virtual unsigned int GetColumnCount() const; virtual unsigned int GetColumnCount() const;
@@ -1077,6 +1080,11 @@ public:
bool GetToggleValue( unsigned int row, unsigned int col ) const bool GetToggleValue( unsigned int row, unsigned int col ) const
{ wxVariant value; GetStore()->GetValueByRow( value, row, col ); return value.GetBool(); } { wxVariant value; GetStore()->GetValueByRow( value, row, col ); return value.GetBool(); }
void SetItemData( const wxDataViewItem& item, wxUIntPtr data )
{ GetStore()->SetItemData( item, data ); }
wxUIntPtr GetItemData( const wxDataViewItem& item ) const
{ return GetStore()->GetItemData( item ); }
void OnSize( wxSizeEvent &event ); void OnSize( wxSizeEvent &event );
private: private:

View File

@@ -2337,6 +2337,15 @@ public:
*/ */
void DeleteAllItems(); void DeleteAllItems();
/**
Returns the client data associated with the item.
@see SetItemData()
@since 2.9.4
*/
wxUIntPtr GetItemData(const wxDataViewItem& item) const;
/** /**
Sets the value in the store and update the control. Sets the value in the store and update the control.
*/ */
@@ -2379,6 +2388,19 @@ public:
*/ */
bool GetToggleValue( unsigned int row, unsigned int col ) const; bool GetToggleValue( unsigned int row, unsigned int col ) const;
/**
Associates a client data pointer with the given item.
Notice that the control does @e not take ownership of the pointer for
compatibility with wxListCtrl. I.e. it will @e not delete the pointer
(if it is a pointer and not a number) itself, it is up to you to do it.
@see GetItemData()
@since 2.9.4
*/
void SetItemData(const wxDataViewItem& item, wxUIntPtr data);
//@} //@}
}; };
@@ -2688,6 +2710,15 @@ public:
*/ */
void DeleteAllItems(); void DeleteAllItems();
/**
Returns the client data associated with the item.
@see SetItemData()
@since 2.9.4
*/
wxUIntPtr GetItemData(const wxDataViewItem& item) const;
/** /**
Overridden from wxDataViewModel Overridden from wxDataViewModel
*/ */
@@ -2698,6 +2729,18 @@ public:
*/ */
virtual wxString GetColumnType( unsigned int col ) const; virtual wxString GetColumnType( unsigned int col ) const;
/**
Sets the client data associated with the item.
Notice that this class does @e not take ownership of the passed in
pointer and will not delete it.
@see GetItemData()
@since 2.9.4
*/
void SetItemData(const wxDataViewItem& item, wxUIntPtr data);
/** /**
Overridden from wxDataViewIndexListModel Overridden from wxDataViewIndexListModel
*/ */

View File

@@ -1761,6 +1761,22 @@ void wxDataViewListStore::DeleteAllItems()
Reset( 0 ); Reset( 0 );
} }
void wxDataViewListStore::SetItemData( const wxDataViewItem& item, wxUIntPtr data )
{
wxDataViewListStoreLine* line = m_data[wxPtrToUInt( item.GetID() ) - 1];
if (!line) return;
line->SetData( data );
}
wxUIntPtr wxDataViewListStore::GetItemData( const wxDataViewItem& item ) const
{
wxDataViewListStoreLine* line = m_data[wxPtrToUInt( item.GetID() ) - 1];
if (!line) return NULL;
return line->GetData();
}
void wxDataViewListStore::GetValueByRow( wxVariant &value, unsigned int row, unsigned int col ) const void wxDataViewListStore::GetValueByRow( wxVariant &value, unsigned int row, unsigned int col ) const
{ {
wxDataViewListStoreLine *line = m_data[row]; wxDataViewListStoreLine *line = m_data[row];