Change GetValue() and SetValue() to GetValueByRow() and SetValueByRow() in row based interface, Add wxDataViewListStore (WIP)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58124 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
#include "wx/icon.h"
|
#include "wx/icon.h"
|
||||||
#include "wx/imaglist.h"
|
#include "wx/imaglist.h"
|
||||||
#include "wx/weakref.h"
|
#include "wx/weakref.h"
|
||||||
|
#include "wx/vector.h"
|
||||||
|
|
||||||
#if !(defined(__WXGTK20__) || defined(__WXMAC__)) || defined(__WXUNIVERSAL__)
|
#if !(defined(__WXGTK20__) || defined(__WXMAC__)) || defined(__WXUNIVERSAL__)
|
||||||
// #if !(defined(__WXMAC__)) || defined(__WXUNIVERSAL__)
|
// #if !(defined(__WXMAC__)) || defined(__WXUNIVERSAL__)
|
||||||
@@ -242,13 +243,13 @@ public:
|
|||||||
wxDataViewIndexListModel( unsigned int initial_size = 0 );
|
wxDataViewIndexListModel( unsigned int initial_size = 0 );
|
||||||
~wxDataViewIndexListModel();
|
~wxDataViewIndexListModel();
|
||||||
|
|
||||||
virtual void GetValue( wxVariant &variant,
|
virtual void GetValueByRow( wxVariant &variant,
|
||||||
unsigned int row, unsigned int col ) const = 0;
|
unsigned int row, unsigned int col ) const = 0;
|
||||||
|
|
||||||
virtual bool SetValue( const wxVariant &variant,
|
virtual bool SetValueByRow( const wxVariant &variant,
|
||||||
unsigned int row, unsigned int col ) = 0;
|
unsigned int row, unsigned int col ) = 0;
|
||||||
|
|
||||||
virtual bool GetAttr( unsigned int WXUNUSED(row), unsigned int WXUNUSED(col), wxDataViewItemAttr &WXUNUSED(attr) )
|
virtual bool GetAttrByRow( unsigned int WXUNUSED(row), unsigned int WXUNUSED(col), wxDataViewItemAttr &WXUNUSED(attr) )
|
||||||
{ return false; }
|
{ return false; }
|
||||||
|
|
||||||
void RowPrepended();
|
void RowPrepended();
|
||||||
@@ -307,13 +308,13 @@ public:
|
|||||||
wxDataViewVirtualListModel( unsigned int initial_size = 0 );
|
wxDataViewVirtualListModel( unsigned int initial_size = 0 );
|
||||||
~wxDataViewVirtualListModel();
|
~wxDataViewVirtualListModel();
|
||||||
|
|
||||||
virtual void GetValue( wxVariant &variant,
|
virtual void GetValueByRow( wxVariant &variant,
|
||||||
unsigned int row, unsigned int col ) const = 0;
|
unsigned int row, unsigned int col ) const = 0;
|
||||||
|
|
||||||
virtual bool SetValue( const wxVariant &variant,
|
virtual bool SetValueByRow( const wxVariant &variant,
|
||||||
unsigned int row, unsigned int col ) = 0;
|
unsigned int row, unsigned int col ) = 0;
|
||||||
|
|
||||||
virtual bool GetAttr( unsigned int WXUNUSED(row), unsigned int WXUNUSED(col), wxDataViewItemAttr &WXUNUSED(attr) )
|
virtual bool GetAttrByRow( unsigned int WXUNUSED(row), unsigned int WXUNUSED(col), wxDataViewItemAttr &WXUNUSED(attr) )
|
||||||
{ return false; }
|
{ return false; }
|
||||||
|
|
||||||
void RowPrepended();
|
void RowPrepended();
|
||||||
@@ -907,6 +908,81 @@ private:
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxDataViewListStore
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class WXDLLIMPEXP_ADV wxDataViewListStoreLine
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxDataViewListStoreLine( wxClientData *data = NULL )
|
||||||
|
{
|
||||||
|
m_data = data;
|
||||||
|
}
|
||||||
|
virtual ~wxDataViewListStoreLine()
|
||||||
|
{
|
||||||
|
delete m_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetData( wxClientData *data )
|
||||||
|
{ if (m_data) delete m_data; m_data = data; }
|
||||||
|
wxClientData *GetData() const
|
||||||
|
{ return m_data; }
|
||||||
|
|
||||||
|
wxVector<wxVariant> m_values;
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxClientData *m_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class WXDLLIMPEXP_ADV wxDataViewListStore: public wxDataViewIndexListModel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxDataViewListStore();
|
||||||
|
~wxDataViewListStore();
|
||||||
|
|
||||||
|
void PrependColumn( const wxString &varianttype );
|
||||||
|
void InsertColumn( unsigned int pos, const wxString &varianttype );
|
||||||
|
void AppendColumn( const wxString &varianttype );
|
||||||
|
|
||||||
|
void PrependStringColumn()
|
||||||
|
{ PrependColumn( wxT("string") ); }
|
||||||
|
void InsertStringColumn( unsigned int pos )
|
||||||
|
{ InsertColumn( pos, wxT("string") ); }
|
||||||
|
void AppendStringColumn()
|
||||||
|
{ AppendColumn( wxT("string") ); }
|
||||||
|
|
||||||
|
void AppendItem( const wxVector<wxVariant> &values, wxClientData *data = NULL );
|
||||||
|
void PrependItem( const wxVector<wxVariant> &values, wxClientData *data = NULL );
|
||||||
|
void InsertItem( unsigned int row, const wxVector<wxVariant> &values, wxClientData *data = NULL );
|
||||||
|
void DeleteItem( unsigned pos );
|
||||||
|
void DeleteAllItems();
|
||||||
|
|
||||||
|
void SetStringValue( const wxString &value, unsigned int row, unsigned int col )
|
||||||
|
{ SetValueByRow( value, row, col ); }
|
||||||
|
wxString GetStringValue( unsigned int row, unsigned int col )
|
||||||
|
{ wxVariant value; GetValueByRow( value, row, col ); return value.GetString(); }
|
||||||
|
|
||||||
|
// override base virtuals
|
||||||
|
|
||||||
|
virtual unsigned int GetColumnCount() const;
|
||||||
|
|
||||||
|
virtual wxString GetColumnType( unsigned int col ) const;
|
||||||
|
|
||||||
|
virtual void GetValueByRow( wxVariant &value,
|
||||||
|
unsigned int row, unsigned int col ) const;
|
||||||
|
|
||||||
|
virtual bool SetValueByRow( const wxVariant &value,
|
||||||
|
unsigned int row, unsigned int col );
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
wxVector<wxDataViewListStoreLine*> m_data;
|
||||||
|
wxArrayString m_cols;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// wxDataViewTreeStore
|
// wxDataViewTreeStore
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@@ -299,7 +299,7 @@ public:
|
|||||||
|
|
||||||
@see wxDataViewItemAttr.
|
@see wxDataViewItemAttr.
|
||||||
*/
|
*/
|
||||||
virtual bool GetAttr(unsigned int row, unsigned int col,
|
virtual bool GetAttrByRow(unsigned int row, unsigned int col,
|
||||||
wxDataViewItemAttr& attr);
|
wxDataViewItemAttr& attr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -315,7 +315,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
Override this to allow getting values from the model.
|
Override this to allow getting values from the model.
|
||||||
*/
|
*/
|
||||||
virtual void GetValue(wxVariant& variant, unsigned int row,
|
virtual void GetValueByRow(wxVariant& variant, unsigned int row,
|
||||||
unsigned int col) const = 0;
|
unsigned int col) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -365,7 +365,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
Called in order to set a value in the model.
|
Called in order to set a value in the model.
|
||||||
*/
|
*/
|
||||||
virtual bool SetValue(const wxVariant& variant, unsigned int row,
|
virtual bool SetValueByRow(const wxVariant& variant, unsigned int row,
|
||||||
unsigned int col) = 0;
|
unsigned int col) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1673,9 +1673,9 @@ public:
|
|||||||
wxDataViewTreeStore is a specialised wxDataViewModel for displaying simple
|
wxDataViewTreeStore is a specialised wxDataViewModel for displaying simple
|
||||||
trees very much like wxTreeCtrl does and it offers a similar API.
|
trees very much like wxTreeCtrl does and it offers a similar API.
|
||||||
|
|
||||||
This class actually stores the entire tree (therefore its name) and implements
|
This class actually stores the entire tree and the values (therefore its name)
|
||||||
all virtual methods from the base class so it can be used directly without
|
and implements all virtual methods from the base class so it can be used directly
|
||||||
having to derive any class from it.
|
without having to derive any class from it.
|
||||||
This comes at the price of much reduced flexibility.
|
This comes at the price of much reduced flexibility.
|
||||||
|
|
||||||
@library{wxadv}
|
@library{wxadv}
|
||||||
|
@@ -530,7 +530,7 @@ public:
|
|||||||
return m_array.GetCount();
|
return m_array.GetCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void GetValue( wxVariant &variant,
|
virtual void GetValueByRow( wxVariant &variant,
|
||||||
unsigned int row, unsigned int col ) const
|
unsigned int row, unsigned int col ) const
|
||||||
{
|
{
|
||||||
if (col==0)
|
if (col==0)
|
||||||
@@ -560,7 +560,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool GetAttr( unsigned int row, unsigned int col, wxDataViewItemAttr &attr )
|
virtual bool GetAttrByRow( unsigned int row, unsigned int col, wxDataViewItemAttr &attr )
|
||||||
{
|
{
|
||||||
if (col != 2)
|
if (col != 2)
|
||||||
return false;
|
return false;
|
||||||
@@ -574,7 +574,7 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool SetValue( const wxVariant &variant,
|
virtual bool SetValueByRow( const wxVariant &variant,
|
||||||
unsigned int row, unsigned int col )
|
unsigned int row, unsigned int col )
|
||||||
{
|
{
|
||||||
if (col == 0)
|
if (col == 0)
|
||||||
|
@@ -456,18 +456,18 @@ int wxDataViewIndexListModel::Compare(const wxDataViewItem& item1,
|
|||||||
void wxDataViewIndexListModel::GetValue( wxVariant &variant,
|
void wxDataViewIndexListModel::GetValue( wxVariant &variant,
|
||||||
const wxDataViewItem &item, unsigned int col ) const
|
const wxDataViewItem &item, unsigned int col ) const
|
||||||
{
|
{
|
||||||
GetValue( variant, GetRow(item), col );
|
GetValueByRow( variant, GetRow(item), col );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxDataViewIndexListModel::SetValue( const wxVariant &variant,
|
bool wxDataViewIndexListModel::SetValue( const wxVariant &variant,
|
||||||
const wxDataViewItem &item, unsigned int col )
|
const wxDataViewItem &item, unsigned int col )
|
||||||
{
|
{
|
||||||
return SetValue( variant, GetRow(item), col );
|
return SetValueByRow( variant, GetRow(item), col );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxDataViewIndexListModel::GetAttr( const wxDataViewItem &item, unsigned int col, wxDataViewItemAttr &attr )
|
bool wxDataViewIndexListModel::GetAttr( const wxDataViewItem &item, unsigned int col, wxDataViewItemAttr &attr )
|
||||||
{
|
{
|
||||||
return GetAttr( GetRow(item), col, attr );
|
return GetAttrByRow( GetRow(item), col, attr );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDataViewItem wxDataViewIndexListModel::GetParent( const wxDataViewItem & WXUNUSED(item) ) const
|
wxDataViewItem wxDataViewIndexListModel::GetParent( const wxDataViewItem & WXUNUSED(item) ) const
|
||||||
@@ -603,18 +603,18 @@ int wxDataViewVirtualListModel::Compare(const wxDataViewItem& item1,
|
|||||||
void wxDataViewVirtualListModel::GetValue( wxVariant &variant,
|
void wxDataViewVirtualListModel::GetValue( wxVariant &variant,
|
||||||
const wxDataViewItem &item, unsigned int col ) const
|
const wxDataViewItem &item, unsigned int col ) const
|
||||||
{
|
{
|
||||||
GetValue( variant, GetRow(item), col );
|
GetValueByRow( variant, GetRow(item), col );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxDataViewVirtualListModel::SetValue( const wxVariant &variant,
|
bool wxDataViewVirtualListModel::SetValue( const wxVariant &variant,
|
||||||
const wxDataViewItem &item, unsigned int col )
|
const wxDataViewItem &item, unsigned int col )
|
||||||
{
|
{
|
||||||
return SetValue( variant, GetRow(item), col );
|
return SetValueByRow( variant, GetRow(item), col );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxDataViewVirtualListModel::GetAttr( const wxDataViewItem &item, unsigned int col, wxDataViewItemAttr &attr )
|
bool wxDataViewVirtualListModel::GetAttr( const wxDataViewItem &item, unsigned int col, wxDataViewItemAttr &attr )
|
||||||
{
|
{
|
||||||
return GetAttr( GetRow(item), col, attr );
|
return GetAttrByRow( GetRow(item), col, attr );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDataViewItem wxDataViewVirtualListModel::GetParent( const wxDataViewItem & WXUNUSED(item) ) const
|
wxDataViewItem wxDataViewVirtualListModel::GetParent( const wxDataViewItem & WXUNUSED(item) ) const
|
||||||
@@ -1354,6 +1354,110 @@ bool wxDataViewChoiceRenderer::GetValue( wxVariant &value ) const
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxDataViewListStore
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxDataViewListStore::wxDataViewListStore()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
wxDataViewListStore::~wxDataViewListStore()
|
||||||
|
{
|
||||||
|
wxVector<wxDataViewListStoreLine*>::iterator it;
|
||||||
|
for (it = m_data.begin(); it != m_data.end(); ++it)
|
||||||
|
{
|
||||||
|
wxDataViewListStoreLine* line = *it;
|
||||||
|
delete line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxDataViewListStore::PrependColumn( const wxString &varianttype )
|
||||||
|
{
|
||||||
|
m_cols.Insert( varianttype, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxDataViewListStore::InsertColumn( unsigned int pos, const wxString &varianttype )
|
||||||
|
{
|
||||||
|
m_cols.Insert( varianttype, pos );
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxDataViewListStore::AppendColumn( const wxString &varianttype )
|
||||||
|
{
|
||||||
|
m_cols.Add( varianttype );
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int wxDataViewListStore::GetColumnCount() const
|
||||||
|
{
|
||||||
|
return m_cols.GetCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString wxDataViewListStore::GetColumnType( unsigned int pos ) const
|
||||||
|
{
|
||||||
|
return m_cols[pos];
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxDataViewListStore::AppendItem( const wxVector<wxVariant> &values, wxClientData *data )
|
||||||
|
{
|
||||||
|
wxDataViewListStoreLine *line = new wxDataViewListStoreLine( data );
|
||||||
|
line->m_values = values;
|
||||||
|
m_data.push_back( line );
|
||||||
|
|
||||||
|
RowAppended();
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxDataViewListStore::PrependItem( const wxVector<wxVariant> &values, wxClientData *data )
|
||||||
|
{
|
||||||
|
wxDataViewListStoreLine *line = new wxDataViewListStoreLine( data );
|
||||||
|
line->m_values = values;
|
||||||
|
m_data.insert( m_data.begin(), line );
|
||||||
|
|
||||||
|
RowPrepended();
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxDataViewListStore::InsertItem( unsigned int row, const wxVector<wxVariant> &values, wxClientData *data )
|
||||||
|
{
|
||||||
|
wxDataViewListStoreLine *line = new wxDataViewListStoreLine( data );
|
||||||
|
line->m_values = values;
|
||||||
|
m_data.insert( m_data.begin()+row, line );
|
||||||
|
|
||||||
|
RowInserted( row );
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxDataViewListStore::DeleteItem( unsigned row )
|
||||||
|
{
|
||||||
|
wxVector<wxDataViewListStoreLine*>::iterator it = m_data.begin() + row;
|
||||||
|
m_data.erase( it );
|
||||||
|
|
||||||
|
RowDeleted( row );
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxDataViewListStore::DeleteAllItems()
|
||||||
|
{
|
||||||
|
wxVector<wxDataViewListStoreLine*>::iterator it;
|
||||||
|
for (it = m_data.begin(); it != m_data.end(); ++it)
|
||||||
|
{
|
||||||
|
wxDataViewListStoreLine* line = *it;
|
||||||
|
delete line;
|
||||||
|
}
|
||||||
|
|
||||||
|
Reset( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxDataViewListStore::GetValueByRow( wxVariant &value, unsigned int row, unsigned int col ) const
|
||||||
|
{
|
||||||
|
wxDataViewListStoreLine *line = m_data[row];
|
||||||
|
value = line->m_values[col];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxDataViewListStore::SetValueByRow( const wxVariant &value, unsigned int row, unsigned int col )
|
||||||
|
{
|
||||||
|
wxDataViewListStoreLine *line = m_data[row];
|
||||||
|
line->m_values[col] = value;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// wxDataViewTreeStore
|
// wxDataViewTreeStore
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user