V
Vincent RICHOMME
Hi,
I would like to know what is the best way of doing the following thing.
I am developping a GUI application with a tree and for each item of my
tree I can associate(gui mechanism) a class to store extra information.
So i have this :
ifndef PRJTREE_H
#define PRJTREE_H
#include <wx/treectrl.h>
enum EItemType
{
eRoot = 0,
eReaderGroup,
eReaderItem,
eCardGroup,
eCardItem,
eCardCmdGroup,
eCardCmdItem
};
/*
wxTreeItemData is some (arbitrary) user class associated with some item.
The main advantage of having this class is that wxTreeItemData objects
are destroyed automatically by the tree and, as this class has virtual
destructor
*/
class PrjItemData : public wxTreeItemData
{
public:
PrjItemData(EItemType enuItemType = eRoot) {m_enuItemType =
enuItemType;}
private:
EItemType m_enuItemType;
};
class PrjTree : public wxTreeCtrl
{
public:
PrjTree() { }
PrjTree(wxWindow * parent, wxWindowID id, const wxPoint& pos,
const wxSize& size, long style);
virtual ~PrjTree(){};
void AddItem(EItemType eType, const wxString& strItemName);
DECLARE_DYNAMIC_CLASS(PrjTree)
DECLARE_EVENT_TABLE()
};
And in my AddItem when I add an item to my tree I associate a
PrjItemData with it.
void PrjTree::AddItem(EItemType eParentType, const wxString& strItemName)
{
wxTreeItemId idItem = GetItemCorrespondingTo( eParentType);
AppendItem(idItem, strItemName, -1, -1, new PrjItemData
(eParentType) );
}
#endif
Now my question is should I let enum as global or would it be better to
put it inside one of the two classes?
Should I use namespace ?
I tried to put enum in PrjTree but in this case when I define
PrjItemData I suppose I should write (not even sure if it works) this
class PrjItemData : public wxTreeItemData
{
public:
PrjItemData(PrjTree::EItemType enuItemType = eRoot) {m_enuItemType
= enuItemType;}
private:
EItemType m_enuItemType;
};
I would like to know what is the best way of doing the following thing.
I am developping a GUI application with a tree and for each item of my
tree I can associate(gui mechanism) a class to store extra information.
So i have this :
ifndef PRJTREE_H
#define PRJTREE_H
#include <wx/treectrl.h>
enum EItemType
{
eRoot = 0,
eReaderGroup,
eReaderItem,
eCardGroup,
eCardItem,
eCardCmdGroup,
eCardCmdItem
};
/*
wxTreeItemData is some (arbitrary) user class associated with some item.
The main advantage of having this class is that wxTreeItemData objects
are destroyed automatically by the tree and, as this class has virtual
destructor
*/
class PrjItemData : public wxTreeItemData
{
public:
PrjItemData(EItemType enuItemType = eRoot) {m_enuItemType =
enuItemType;}
private:
EItemType m_enuItemType;
};
class PrjTree : public wxTreeCtrl
{
public:
PrjTree() { }
PrjTree(wxWindow * parent, wxWindowID id, const wxPoint& pos,
const wxSize& size, long style);
virtual ~PrjTree(){};
void AddItem(EItemType eType, const wxString& strItemName);
DECLARE_DYNAMIC_CLASS(PrjTree)
DECLARE_EVENT_TABLE()
};
And in my AddItem when I add an item to my tree I associate a
PrjItemData with it.
void PrjTree::AddItem(EItemType eParentType, const wxString& strItemName)
{
wxTreeItemId idItem = GetItemCorrespondingTo( eParentType);
AppendItem(idItem, strItemName, -1, -1, new PrjItemData
(eParentType) );
}
#endif
Now my question is should I let enum as global or would it be better to
put it inside one of the two classes?
Should I use namespace ?
I tried to put enum in PrjTree but in this case when I define
PrjItemData I suppose I should write (not even sure if it works) this
class PrjItemData : public wxTreeItemData
{
public:
PrjItemData(PrjTree::EItemType enuItemType = eRoot) {m_enuItemType
= enuItemType;}
private:
EItemType m_enuItemType;
};