Change wxVariant GetValue() to GetValue( wxVariant & ).

More cool sorting code.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@37774 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 2006-03-02 10:46:01 +00:00
parent 04e044c4d6
commit 3f3af7e7f8
4 changed files with 49 additions and 26 deletions

View File

@ -106,7 +106,7 @@ public:
// return type as reported by wxVariant
virtual wxString GetColType( size_t col ) = 0;
// get value into a wxVariant
virtual wxVariant GetValue( size_t col, size_t row ) = 0;
virtual void GetValue( wxVariant &variant, size_t col, size_t row ) = 0;
// set value, call ValueChanged() afterwards!
virtual bool SetValue( wxVariant &variant, size_t col, size_t row ) = 0;
@ -154,7 +154,7 @@ public:
// return type as reported by wxVariant
virtual wxString GetColType( size_t col );
// get value into a wxVariant
virtual wxVariant GetValue( size_t col, size_t row );
virtual void GetValue( wxVariant &variant, size_t col, size_t row );
// set value, call ValueChanged() afterwards!
virtual bool SetValue( wxVariant &variant, size_t col, size_t row );

View File

@ -75,33 +75,33 @@ public:
return wxT("string");
}
virtual wxVariant GetValue( size_t col, size_t row )
virtual void GetValue( wxVariant &variant, size_t col, size_t row )
{
if (col == 6)
{
return (wxDateTime) *m_dates[row];
variant = (wxDateTime) *m_dates[row];
} else
if (col == 5)
{
return (long) m_progress[row];
variant = (long) m_progress[row];
} else
if (col == 4)
{
return m_colours[row];
variant = m_colours[row];
} else
if (col == 3)
{
return (bool) m_bools[row];
variant = (bool) m_bools[row];
} else
if (col == 2)
{
return m_list[row];
variant = m_list[row];
}
else
{
wxString tmp;
tmp.Printf( wxT("item(%d;%d)"), (int)row, (int)col );
return tmp;
variant = tmp;
}
}
virtual bool SetValue( wxVariant &value, size_t col, size_t row )
@ -192,13 +192,16 @@ public:
virtual size_t GetNumberOfRows() { return m_list.GetCount(); }
virtual size_t GetNumberOfCols() { return 2; }
virtual wxString GetColType( size_t col ) { return wxT("string"); }
virtual wxVariant GetValue( size_t col, size_t row )
virtual void GetValue( wxVariant &variant, size_t col, size_t row )
{
if (col == 0)
return m_list[row];
{
variant = m_list[row];
return;
}
wxString tmp;
tmp.Printf( wxT("item(%d;%d)"), (int)row, (int)col );
return tmp;
variant = tmp;
}
virtual bool SetValue( wxVariant &variant, size_t col, size_t row )
{

View File

@ -237,8 +237,9 @@ public:
int wxCALLBACK wxDataViewListModelSortedDefaultCompare
(size_t row1, size_t row2, size_t col, wxDataViewListModel* model )
{
wxVariant value1 = model->GetValue( col, row1 );
wxVariant value2 = model->GetValue( col, row2 );
wxVariant value1,value2;
model->GetValue( value1, col, row1 );
model->GetValue( value2, col, row2 );
if (value1.GetType() == wxT("string"))
{
wxString str1 = value1.GetString();
@ -314,6 +315,22 @@ void wxDataViewSortedListModel::Resort()
m_array.Add( i );
}
#if 0
static void Dump( wxDataViewListModel *model, size_t col )
{
size_t n = model->GetNumberOfRows();
size_t i;
for (i = 0; i < n; i++)
{
wxVariant variant;
model->GetValue( variant, col, i );
wxString tmp;
tmp = variant.GetString();
wxPrintf( wxT("%d: %s\n"), (int) i, tmp.c_str() );
}
}
#endif
bool wxDataViewSortedListModel::ChildValueChanged( size_t col, size_t row )
{
size_t i;
@ -328,15 +345,16 @@ bool wxDataViewSortedListModel::ChildValueChanged( size_t col, size_t row )
start_pos = i;
break;
}
m_array.Remove( row );
m_array.RemoveAt( start_pos );
m_array.Add( row );
for (i = 0; i < len; i++)
if (m_array[i] == row)
{
end_pos = i;
break;
}
if (end_pos == start_pos)
return wxDataViewListModel::ValueChanged( col, start_pos );
@ -360,7 +378,7 @@ bool wxDataViewSortedListModel::ChildValueChanged( size_t col, size_t row )
order[start_pos] = end_pos;
}
RowsReordered( order );
wxDataViewListModel::RowsReordered( order );
delete [] order;
@ -369,7 +387,7 @@ bool wxDataViewSortedListModel::ChildValueChanged( size_t col, size_t row )
size_t wxDataViewSortedListModel::GetNumberOfRows()
{
return m_child->GetNumberOfRows();
return m_array.GetCount();
}
size_t wxDataViewSortedListModel::GetNumberOfCols()
@ -382,10 +400,10 @@ wxString wxDataViewSortedListModel::GetColType( size_t col )
return m_child->GetColType( col );
}
wxVariant wxDataViewSortedListModel::GetValue( size_t col, size_t row )
void wxDataViewSortedListModel::GetValue( wxVariant &variant, size_t col, size_t row )
{
size_t child_row = m_array[row];
return m_child->GetValue( col, child_row );
m_child->GetValue( variant, col, child_row );
}
bool wxDataViewSortedListModel::SetValue( wxVariant &variant, size_t col, size_t row )

View File

@ -20,6 +20,7 @@
#include "wx/calctrl.h"
#include "wx/popupwin.h"
#include "wx/sizer.h"
#include "wx/log.h"
#include "wx/gtk/private.h"
#include "wx/gtk/win_gtk.h"
@ -304,8 +305,9 @@ wxgtk_list_store_get_value (GtkTreeModel *tree_model,
wxString mtype = model->GetColType( (size_t) column );
if (mtype == wxT("string"))
{
wxVariant variant;
g_value_init( value, G_TYPE_STRING );
wxVariant variant = model->GetValue( (size_t) column, (size_t) iter->user_data );
model->GetValue( variant, (size_t) column, (size_t) iter->user_data );
g_value_set_string( value, wxGTK_CONV(variant.GetString()) );
}
else
@ -855,7 +857,6 @@ bool wxGtkDataViewListModelNotifier::RowsReordered( size_t *new_order )
node = node->GetNext();
}
return true;
}
@ -1295,7 +1296,8 @@ wxSize wxDataViewDateCell::GetSize()
bool wxDataViewDateCell::Activate( wxRect cell, wxDataViewListModel *model, size_t col, size_t row )
{
wxVariant variant = model->GetValue( col, row );
wxVariant variant;
model->GetValue( variant, col, row );
wxDateTime value = variant.GetDateTime();
wxDataViewDateCellPopupTransient *popup = new wxDataViewDateCellPopupTransient(
@ -1334,11 +1336,11 @@ static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *column,
size_t model_row = (size_t) iter->user_data;
wxVariant value = list_store->model->GetValue(
cell->GetOwner()->GetModelColumn(), model_row );
wxVariant value;
list_store->model->GetValue( value, cell->GetOwner()->GetModelColumn(), model_row );
if (value.GetType() != cell->GetVariantType())
wxPrintf( wxT("Wrong type\n") );
wxLogError( wxT("Wrong type\n") );
cell->SetValue( value );
}