2009-03-05 09:00:46 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: mymodels.h
|
|
|
|
// Purpose: wxDataViewCtrl wxWidgets sample
|
|
|
|
// Author: Robert Roebling
|
|
|
|
// Modified by: Francesco Montorsi, Bo Yang
|
|
|
|
// Created: 06/01/06
|
|
|
|
// Copyright: (c) Robert Roebling
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
2009-03-05 09:00:46 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-11-27 09:43:21 -05:00
|
|
|
#include "wx/hashmap.h"
|
2018-08-14 12:01:50 -04:00
|
|
|
#include <wx/vector.h>
|
2015-11-27 09:43:21 -05:00
|
|
|
|
|
|
|
WX_DECLARE_HASH_MAP(unsigned, wxString, wxIntegerHash, wxIntegerEqual,
|
|
|
|
IntToStringMap);
|
2009-03-05 09:00:46 -05:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyMusicTreeModelNode: a node inside MyMusicTreeModel
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class MyMusicTreeModelNode;
|
|
|
|
WX_DEFINE_ARRAY_PTR( MyMusicTreeModelNode*, MyMusicTreeModelNodePtrArray );
|
|
|
|
|
|
|
|
class MyMusicTreeModelNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyMusicTreeModelNode( MyMusicTreeModelNode* parent,
|
2009-03-06 15:45:04 -05:00
|
|
|
const wxString &title, const wxString &artist,
|
2009-03-05 09:00:46 -05:00
|
|
|
unsigned int year )
|
|
|
|
{
|
|
|
|
m_parent = parent;
|
|
|
|
|
|
|
|
m_title = title;
|
|
|
|
m_artist = artist;
|
|
|
|
m_year = year;
|
|
|
|
m_quality = "good";
|
2009-03-06 15:45:04 -05:00
|
|
|
|
|
|
|
m_container = false;
|
2009-03-05 09:00:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
MyMusicTreeModelNode( MyMusicTreeModelNode* parent,
|
|
|
|
const wxString &branch )
|
|
|
|
{
|
|
|
|
m_parent = parent;
|
|
|
|
|
|
|
|
m_title = branch;
|
|
|
|
m_year = -1;
|
2009-03-06 15:45:04 -05:00
|
|
|
|
|
|
|
m_container = true;
|
2009-03-05 09:00:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
~MyMusicTreeModelNode()
|
|
|
|
{
|
|
|
|
// free all our children nodes
|
|
|
|
size_t count = m_children.GetCount();
|
|
|
|
for (size_t i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
MyMusicTreeModelNode *child = m_children[i];
|
|
|
|
delete child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsContainer() const
|
2009-03-06 15:45:04 -05:00
|
|
|
{ return m_container; }
|
2009-03-05 09:00:46 -05:00
|
|
|
|
|
|
|
MyMusicTreeModelNode* GetParent()
|
|
|
|
{ return m_parent; }
|
|
|
|
MyMusicTreeModelNodePtrArray& GetChildren()
|
|
|
|
{ return m_children; }
|
|
|
|
MyMusicTreeModelNode* GetNthChild( unsigned int n )
|
|
|
|
{ return m_children.Item( n ); }
|
|
|
|
void Insert( MyMusicTreeModelNode* child, unsigned int n)
|
|
|
|
{ m_children.Insert( child, n); }
|
|
|
|
void Append( MyMusicTreeModelNode* child )
|
|
|
|
{ m_children.Add( child ); }
|
|
|
|
unsigned int GetChildCount() const
|
|
|
|
{ return m_children.GetCount(); }
|
|
|
|
|
|
|
|
public: // public to avoid getters/setters
|
|
|
|
wxString m_title;
|
|
|
|
wxString m_artist;
|
|
|
|
int m_year;
|
|
|
|
wxString m_quality;
|
|
|
|
|
2009-03-06 15:45:04 -05:00
|
|
|
// TODO/FIXME:
|
|
|
|
// the GTK version of wxDVC (in particular wxDataViewCtrlInternal::ItemAdded)
|
|
|
|
// needs to know in advance if a node is or _will be_ a container.
|
|
|
|
// Thus implementing:
|
|
|
|
// bool IsContainer() const
|
|
|
|
// { return m_children.GetCount()>0; }
|
|
|
|
// doesn't work with wxGTK when MyMusicTreeModel::AddToClassical is called
|
|
|
|
// AND the classical node was removed (a new node temporary without children
|
|
|
|
// would be added to the control)
|
|
|
|
bool m_container;
|
|
|
|
|
2009-03-05 09:00:46 -05:00
|
|
|
private:
|
|
|
|
MyMusicTreeModelNode *m_parent;
|
|
|
|
MyMusicTreeModelNodePtrArray m_children;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyMusicTreeModel
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/*
|
|
|
|
Implement this data model
|
|
|
|
Title Artist Year Judgement
|
|
|
|
--------------------------------------------------------------------------
|
|
|
|
1: My Music:
|
|
|
|
2: Pop music
|
|
|
|
3: You are not alone Michael Jackson 1995 good
|
|
|
|
4: Take a bow Madonna 1994 good
|
|
|
|
5: Classical music
|
|
|
|
6: Ninth Symphony Ludwig v. Beethoven 1824 good
|
|
|
|
7: German Requiem Johannes Brahms 1868 good
|
|
|
|
*/
|
|
|
|
|
|
|
|
class MyMusicTreeModel: public wxDataViewModel
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyMusicTreeModel();
|
|
|
|
~MyMusicTreeModel()
|
|
|
|
{
|
|
|
|
delete m_root;
|
|
|
|
}
|
|
|
|
|
|
|
|
// helper method for wxLog
|
|
|
|
|
|
|
|
wxString GetTitle( const wxDataViewItem &item ) const;
|
2009-03-09 16:49:22 -04:00
|
|
|
wxString GetArtist( const wxDataViewItem &item ) const;
|
2009-03-05 09:00:46 -05:00
|
|
|
int GetYear( const wxDataViewItem &item ) const;
|
|
|
|
|
|
|
|
// helper methods to change the model
|
|
|
|
|
2009-03-06 15:45:04 -05:00
|
|
|
void AddToClassical( const wxString &title, const wxString &artist,
|
2009-03-05 09:00:46 -05:00
|
|
|
unsigned int year );
|
|
|
|
void Delete( const wxDataViewItem &item );
|
|
|
|
|
|
|
|
wxDataViewItem GetNinthItem() const
|
|
|
|
{
|
|
|
|
return wxDataViewItem( m_ninth );
|
|
|
|
}
|
|
|
|
|
|
|
|
// override sorting to always sort branches ascendingly
|
|
|
|
|
|
|
|
int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
|
2014-03-29 20:02:23 -04:00
|
|
|
unsigned int column, bool ascending ) const wxOVERRIDE;
|
2009-03-05 09:00:46 -05:00
|
|
|
|
|
|
|
// implementation of base class virtuals to define model
|
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual unsigned int GetColumnCount() const wxOVERRIDE
|
2009-03-05 09:00:46 -05:00
|
|
|
{
|
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual wxString GetColumnType( unsigned int col ) const wxOVERRIDE
|
2009-03-05 09:00:46 -05:00
|
|
|
{
|
|
|
|
if (col == 2)
|
2018-09-22 19:15:08 -04:00
|
|
|
return "long";
|
2009-03-05 09:00:46 -05:00
|
|
|
|
2018-09-22 19:15:08 -04:00
|
|
|
return "string";
|
2009-03-05 09:00:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void GetValue( wxVariant &variant,
|
2014-03-29 20:02:23 -04:00
|
|
|
const wxDataViewItem &item, unsigned int col ) const wxOVERRIDE;
|
2009-03-05 09:00:46 -05:00
|
|
|
virtual bool SetValue( const wxVariant &variant,
|
2014-03-29 20:02:23 -04:00
|
|
|
const wxDataViewItem &item, unsigned int col ) wxOVERRIDE;
|
2009-03-05 09:00:46 -05:00
|
|
|
|
2010-12-19 10:02:56 -05:00
|
|
|
virtual bool IsEnabled( const wxDataViewItem &item,
|
2014-03-29 20:02:23 -04:00
|
|
|
unsigned int col ) const wxOVERRIDE;
|
2010-12-19 10:02:56 -05:00
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const wxOVERRIDE;
|
|
|
|
virtual bool IsContainer( const wxDataViewItem &item ) const wxOVERRIDE;
|
2009-03-06 15:45:04 -05:00
|
|
|
virtual unsigned int GetChildren( const wxDataViewItem &parent,
|
2014-03-29 20:02:23 -04:00
|
|
|
wxDataViewItemArray &array ) const wxOVERRIDE;
|
2009-03-05 09:00:46 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
MyMusicTreeModelNode* m_root;
|
|
|
|
|
|
|
|
// pointers to some "special" nodes of the tree:
|
|
|
|
MyMusicTreeModelNode* m_pop;
|
|
|
|
MyMusicTreeModelNode* m_classical;
|
|
|
|
MyMusicTreeModelNode* m_ninth;
|
|
|
|
|
|
|
|
// ??
|
|
|
|
bool m_classicalMusicIsKnownToControl;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-12-21 11:56:01 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyLongMusicTreeModel
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class MyLongMusicTreeModel : public MyMusicTreeModel
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyLongMusicTreeModel();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-03-05 09:00:46 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyListModel
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class MyListModel: public wxDataViewVirtualListModel
|
|
|
|
{
|
|
|
|
public:
|
2009-11-10 12:40:25 -05:00
|
|
|
enum
|
|
|
|
{
|
2018-08-14 12:01:50 -04:00
|
|
|
Col_Toggle,
|
2009-11-10 12:40:25 -05:00
|
|
|
Col_EditableText,
|
|
|
|
Col_IconText,
|
2015-07-17 20:11:27 -04:00
|
|
|
Col_Date,
|
2009-11-10 12:40:25 -05:00
|
|
|
Col_TextWithAttr,
|
2009-11-10 12:40:37 -05:00
|
|
|
Col_Custom,
|
2009-11-10 12:40:25 -05:00
|
|
|
Col_Max
|
|
|
|
};
|
|
|
|
|
2009-03-05 09:00:46 -05:00
|
|
|
MyListModel();
|
|
|
|
|
|
|
|
// helper methods to change the model
|
|
|
|
|
|
|
|
void Prepend( const wxString &text );
|
|
|
|
void DeleteItem( const wxDataViewItem &item );
|
|
|
|
void DeleteItems( const wxDataViewItemArray &items );
|
|
|
|
void AddMany();
|
|
|
|
|
|
|
|
|
|
|
|
// implementation of base class virtuals to define model
|
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual unsigned int GetColumnCount() const wxOVERRIDE
|
2009-03-05 09:00:46 -05:00
|
|
|
{
|
2009-11-10 12:40:25 -05:00
|
|
|
return Col_Max;
|
2009-03-05 09:00:46 -05:00
|
|
|
}
|
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual wxString GetColumnType( unsigned int col ) const wxOVERRIDE
|
2009-03-05 09:00:46 -05:00
|
|
|
{
|
2018-08-14 12:01:50 -04:00
|
|
|
if (col == Col_Toggle)
|
2018-09-28 21:45:15 -04:00
|
|
|
return "bool";
|
2018-08-14 12:01:50 -04:00
|
|
|
|
2009-11-10 12:40:25 -05:00
|
|
|
if (col == Col_IconText)
|
2018-09-22 19:15:08 -04:00
|
|
|
return "wxDataViewIconText";
|
2009-03-05 09:00:46 -05:00
|
|
|
|
2018-09-22 19:15:08 -04:00
|
|
|
return "string";
|
2009-03-05 09:00:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void GetValueByRow( wxVariant &variant,
|
2014-03-29 20:02:23 -04:00
|
|
|
unsigned int row, unsigned int col ) const wxOVERRIDE;
|
2009-10-24 17:42:04 -04:00
|
|
|
virtual bool GetAttrByRow( unsigned int row, unsigned int col,
|
2014-03-29 20:02:23 -04:00
|
|
|
wxDataViewItemAttr &attr ) const wxOVERRIDE;
|
2009-03-05 09:00:46 -05:00
|
|
|
virtual bool SetValueByRow( const wxVariant &variant,
|
2014-03-29 20:02:23 -04:00
|
|
|
unsigned int row, unsigned int col ) wxOVERRIDE;
|
2009-03-05 09:00:46 -05:00
|
|
|
|
|
|
|
private:
|
2018-08-14 12:01:50 -04:00
|
|
|
wxVector<bool> m_toggleColValues;
|
2009-10-15 21:29:06 -04:00
|
|
|
wxArrayString m_textColValues;
|
|
|
|
wxArrayString m_iconColValues;
|
2015-11-27 09:43:21 -05:00
|
|
|
IntToStringMap m_customColValues;
|
2009-03-05 09:00:46 -05:00
|
|
|
wxIcon m_icon[2];
|
|
|
|
};
|
|
|
|
|
2010-12-19 10:02:56 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyListStoreDerivedModel
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class MyListStoreDerivedModel : public wxDataViewListStore
|
|
|
|
{
|
|
|
|
public:
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual bool IsEnabledByRow(unsigned int row, unsigned int col) const wxOVERRIDE;
|
2010-12-19 10:02:56 -05:00
|
|
|
};
|
2019-09-12 12:51:36 -04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyIndexListModel
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class MyIndexListModel : public wxDataViewIndexListModel
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyIndexListModel() { }
|
|
|
|
|
|
|
|
void Fill(const wxArrayString& strings)
|
|
|
|
{
|
|
|
|
m_strings = strings;
|
|
|
|
|
|
|
|
Reset(m_strings.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implement base class pure virtual methods.
|
|
|
|
unsigned GetColumnCount() const wxOVERRIDE { return 1; }
|
|
|
|
wxString GetColumnType(unsigned) const wxOVERRIDE { return "string"; }
|
|
|
|
unsigned GetCount() const wxOVERRIDE { return m_strings.size(); }
|
|
|
|
void GetValueByRow(wxVariant& val, unsigned row, unsigned) const wxOVERRIDE
|
|
|
|
{
|
|
|
|
val = m_strings[row];
|
|
|
|
}
|
|
|
|
bool SetValueByRow(const wxVariant&, unsigned, unsigned) wxOVERRIDE
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
wxArrayString m_strings;
|
|
|
|
|
|
|
|
wxDECLARE_NO_COPY_CLASS(MyIndexListModel);
|
|
|
|
};
|