]> git.saurik.com Git - wxWidgets.git/commitdiff
Change GetValue() and SetValue() to GetValueByRow() and SetValueByRow() in row based...
authorRobert Roebling <robert@roebling.de>
Fri, 16 Jan 2009 11:23:37 +0000 (11:23 +0000)
committerRobert Roebling <robert@roebling.de>
Fri, 16 Jan 2009 11:23:37 +0000 (11:23 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58124 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/dataview.h
interface/wx/dataview.h
samples/dataview/dataview.cpp
src/common/datavcmn.cpp

index fee4defdf75585fc38bf47780346bb4872e59913..63a565efc4d744ceb74c29bef657fec7818fee79 100644 (file)
@@ -24,6 +24,7 @@
 #include "wx/icon.h"
 #include "wx/imaglist.h"
 #include "wx/weakref.h"
+#include "wx/vector.h"
 
 #if !(defined(__WXGTK20__) || defined(__WXMAC__)) || defined(__WXUNIVERSAL__)
 // #if !(defined(__WXMAC__)) || defined(__WXUNIVERSAL__)
@@ -242,13 +243,13 @@ public:
     wxDataViewIndexListModel( unsigned int initial_size = 0 );
     ~wxDataViewIndexListModel();
 
-    virtual void GetValue( wxVariant &variant,
+    virtual void GetValueByRow( wxVariant &variant,
                            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;
 
-    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; }
 
     void RowPrepended();
@@ -307,13 +308,13 @@ public:
     wxDataViewVirtualListModel( unsigned int initial_size = 0 );
     ~wxDataViewVirtualListModel();
 
-    virtual void GetValue( wxVariant &variant,
+    virtual void GetValueByRow( wxVariant &variant,
                            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;
 
-    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; }
 
     void RowPrepended();
@@ -907,6 +908,81 @@ private:
 
 #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
 //-----------------------------------------------------------------------------
index aa54468bcf36a662523c703c9a430a50fdf4f529..91af033806b46ccc86a9bbd13529d9a99137c800 100644 (file)
@@ -299,7 +299,7 @@ public:
 
         @see wxDataViewItemAttr.
     */
-    virtual bool GetAttr(unsigned int row, unsigned int col,
+    virtual bool GetAttrByRow(unsigned int row, unsigned int col,
                          wxDataViewItemAttr& attr);
 
     /**
@@ -315,7 +315,7 @@ public:
     /**
         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;
 
     /**
@@ -365,7 +365,7 @@ public:
     /**
         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;
 };
 
@@ -1673,9 +1673,9 @@ public:
     wxDataViewTreeStore is a specialised wxDataViewModel for displaying simple
     trees very much like wxTreeCtrl does and it offers a similar API.
 
-    This class actually stores the entire tree (therefore its name) and implements
-    all virtual methods from the base class so it can be used directly without
-    having to derive any class from it.
+    This class actually stores the entire tree and the values (therefore its name) 
+    and implements all virtual methods from the base class so it can be used directly
+    without having to derive any class from it.
     This comes at the price of much reduced flexibility.
 
     @library{wxadv}
index 239ca116fbedce8c6d3e1979cd214983b8dc0edb..37e754170893c98b73127290eae5ab1263d7905f 100644 (file)
@@ -530,7 +530,7 @@ public:
         return m_array.GetCount();
     }
 
-    virtual void GetValue( wxVariant &variant,
+    virtual void GetValueByRow( wxVariant &variant,
                            unsigned int row, unsigned int col ) const
     {
         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)
             return false;
@@ -574,7 +574,7 @@ public:
         return true;
     }
 
-    virtual bool SetValue( const wxVariant &variant,
+    virtual bool SetValueByRow( const wxVariant &variant,
                            unsigned int row, unsigned int col )
     {
         if (col == 0)
index 79f5b89c45a226d58b7ff2a632cb4e7bb543b8c7..6e84094301b9c711b68c00673110947af2c032d9 100644 (file)
@@ -456,18 +456,18 @@ int wxDataViewIndexListModel::Compare(const wxDataViewItem& item1,
 void wxDataViewIndexListModel::GetValue( wxVariant &variant,
                            const wxDataViewItem &item, unsigned int col ) const
 {
-    GetValue( variant, GetRow(item), col );
+    GetValueByRow( variant, GetRow(item), col );
 }
 
 bool wxDataViewIndexListModel::SetValue( const wxVariant &variant,
                            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 )
 {
-    return GetAttr( GetRow(item), col, attr );
+    return GetAttrByRow( GetRow(item), col, attr );
 }
 
 wxDataViewItem wxDataViewIndexListModel::GetParent( const wxDataViewItem & WXUNUSED(item) ) const
@@ -603,18 +603,18 @@ int wxDataViewVirtualListModel::Compare(const wxDataViewItem& item1,
 void wxDataViewVirtualListModel::GetValue( wxVariant &variant,
                            const wxDataViewItem &item, unsigned int col ) const
 {
-    GetValue( variant, GetRow(item), col );
+    GetValueByRow( variant, GetRow(item), col );
 }
 
 bool wxDataViewVirtualListModel::SetValue( const wxVariant &variant,
                            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 )
 {
-    return GetAttr( GetRow(item), col, attr );
+    return GetAttrByRow( GetRow(item), col, attr );
 }
 
 wxDataViewItem wxDataViewVirtualListModel::GetParent( const wxDataViewItem & WXUNUSED(item) ) const
@@ -1354,6 +1354,110 @@ bool wxDataViewChoiceRenderer::GetValue( wxVariant &value ) const
 
 #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
 //-----------------------------------------------------------------------------