Minor clean up of wxPersistentDataViewCtrl
Add another helper function, make variables const when possible, fix some small style problems. No real changes.
This commit is contained in:
@@ -20,8 +20,6 @@
|
||||
|
||||
#define wxPERSIST_DVC_KIND "DataView"
|
||||
|
||||
#define wxPERSIST_DVC_COLUMNS "Columns"
|
||||
|
||||
#define wxPERSIST_DVC_HIDDEN "Hidden"
|
||||
#define wxPERSIST_DVC_POS "Position"
|
||||
#define wxPERSIST_DVC_TITLE "Title"
|
||||
@@ -30,28 +28,6 @@
|
||||
#define wxPERSIST_DVC_SORT_KEY "Sorting/Column"
|
||||
#define wxPERSIST_DVC_SORT_ASC "Sorting/Asc"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Helper function to search for a column by its title.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
namespace wxPrivate
|
||||
{
|
||||
|
||||
inline
|
||||
wxDataViewColumn*
|
||||
GetColumnByTitle(wxDataViewCtrl* control, const wxString& name)
|
||||
{
|
||||
for ( unsigned int col = 0; col < control->GetColumnCount(); col++)
|
||||
{
|
||||
if ( control->GetColumn(col)->GetTitle() == name )
|
||||
return control->GetColumn(col);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
} // namespace wxPrivate
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxPersistentDataViewCtrl: Saves and restores user modified column widths
|
||||
// and single column sort order.
|
||||
@@ -72,17 +48,14 @@ public:
|
||||
{
|
||||
wxDataViewCtrl* const control = Get();
|
||||
|
||||
wxDataViewColumn* sortColumn = NULL;
|
||||
const wxDataViewColumn* sortColumn = NULL;
|
||||
|
||||
for ( unsigned int col = 0; col < control->GetColumnCount(); col++ )
|
||||
{
|
||||
wxDataViewColumn* column = control->GetColumn(col);
|
||||
wxASSERT(column);
|
||||
const wxDataViewColumn* const column = control->GetColumn(col);
|
||||
|
||||
// Create a prefix string to identify each column.
|
||||
wxString columnPrefix;
|
||||
columnPrefix.Printf("/%s/%s/", wxPERSIST_DVC_COLUMNS,
|
||||
column->GetTitle());
|
||||
const wxString columnPrefix = MakeColumnPrefix(column);
|
||||
|
||||
// Save the column attributes.
|
||||
SaveValue(columnPrefix + wxPERSIST_DVC_HIDDEN, column->IsHidden());
|
||||
@@ -112,19 +85,15 @@ public:
|
||||
virtual bool Restore() wxOVERRIDE
|
||||
{
|
||||
wxDataViewCtrl* const control = Get();
|
||||
wxDataViewColumn* column;
|
||||
|
||||
for ( unsigned int col = 0; col < control->GetColumnCount(); col++ )
|
||||
{
|
||||
column = control->GetColumn(col);
|
||||
wxASSERT(column);
|
||||
wxDataViewColumn* const column = control->GetColumn(col);
|
||||
|
||||
// Create a prefix string to identify each column within the
|
||||
// persistence store (columns are stored by title). The persistence
|
||||
// store benignly handles cases where the title is not found.
|
||||
wxString columnPrefix;
|
||||
columnPrefix.Printf("/%s/%s/", wxPERSIST_DVC_COLUMNS,
|
||||
column->GetTitle());
|
||||
const wxString columnPrefix = MakeColumnPrefix(column);
|
||||
|
||||
// Restore column hidden status.
|
||||
bool hidden;
|
||||
@@ -144,12 +113,10 @@ public:
|
||||
wxString sortColumn;
|
||||
if ( control->GetModel() &&
|
||||
RestoreValue(wxPERSIST_DVC_SORT_KEY, &sortColumn) &&
|
||||
sortColumn != "" )
|
||||
!sortColumn.empty() )
|
||||
{
|
||||
bool sortAsc = true;
|
||||
column = wxPrivate::GetColumnByTitle(control, sortColumn);
|
||||
|
||||
if ( column )
|
||||
if ( wxDataViewColumn* column = GetColumnByTitle(control, sortColumn) )
|
||||
{
|
||||
RestoreValue(wxPERSIST_DVC_SORT_ASC, &sortAsc);
|
||||
column->SetSortOrder(sortAsc);
|
||||
@@ -158,6 +125,7 @@ public:
|
||||
control->GetModel()->Resort();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -165,6 +133,26 @@ public:
|
||||
{
|
||||
return wxPERSIST_DVC_KIND;
|
||||
}
|
||||
|
||||
private:
|
||||
// Return a (slash-terminated) prefix for the column-specific entries.
|
||||
static wxString MakeColumnPrefix(const wxDataViewColumn* column)
|
||||
{
|
||||
return wxString::Format("/Columns/%s/", column->GetTitle());
|
||||
}
|
||||
|
||||
// Return the column with the given title or NULL.
|
||||
static wxDataViewColumn*
|
||||
GetColumnByTitle(wxDataViewCtrl* control, const wxString& title)
|
||||
{
|
||||
for ( unsigned int col = 0; col < control->GetColumnCount(); col++ )
|
||||
{
|
||||
if ( control->GetColumn(col)->GetTitle() == title )
|
||||
return control->GetColumn(col);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
};
|
||||
|
||||
inline wxPersistentObject *wxCreatePersistentObject(wxDataViewCtrl* control)
|
||||
|
Reference in New Issue
Block a user