Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » TreeCtrl » PROPOSAL : allow inserting and retrieving of classes DERIVED from TreeCtrl::Node
PROPOSAL : allow inserting and retrieving of classes DERIVED from TreeCtrl::Node [message #34085] Sun, 16 October 2011 11:36 Go to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
It would be useful to allow TreeCtrl to manage user data too; that one would be easy if it could store and retrieve classes derived
from TreeCtrl::Node.

I don't know the internals of TreeCtrl, but adding a couple of :

TreeCtrl::Node *GetNodePtr(int id);
void SetNodePtr(int id, TreeCtrl::Node *node);


could do the trick from the interface side.
This would allow code like that one :

class MyNode : public TreeCtrl::Node
{
    MyData myData;
    MyNode(myData &data) { myData = data; }
};

TreeCtrl tree;
tree.Add(new MyNode(someData)); // takes ownership of node, similar to Array
......
MyNode *node = dynamic_cast<MyNode *>tree.GetNodePtr(id);
MyData data = node->myData;



This would greatly extend the usefulness of TreeCtrl, imho, using it to manage/reorder and so on custom data.

Max
Re: PROPOSAL : allow inserting and retrieving of classes DERIVED from TreeCtrl::Node [message #34168 is a reply to message #34085] Wed, 26 October 2011 08:28 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
mdelfede wrote on Sun, 16 October 2011 05:36

It would be useful to allow TreeCtrl to manage user data too; that one would be easy if it could store and retrieve classes derived
from TreeCtrl::Node.

I don't know the internals of TreeCtrl, but adding a couple of :

TreeCtrl::Node *GetNodePtr(int id);
void SetNodePtr(int id, TreeCtrl::Node *node);


could do the trick from the interface side.
This would allow code like that one :

class MyNode : public TreeCtrl::Node
{
    MyData myData;
    MyNode(myData &data) { myData = data; }
};

TreeCtrl tree;
tree.Add(new MyNode(someData)); // takes ownership of node, similar to Array
......
MyNode *node = dynamic_cast<MyNode *>tree.GetNodePtr(id);
MyData data = node->myData;



This would greatly extend the usefulness of TreeCtrl, imho, using it to manage/reorder and so on custom data.

Max



Sorry, at this moment, rejected. Use custom Value instead. Or embedded widgets.

Mirek
Re: PROPOSAL : allow inserting and retrieving of classes DERIVED from TreeCtrl::Node [message #34169 is a reply to message #34168] Wed, 26 October 2011 09:25 Go to previous message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
I did it with Value, but it's quite less comfortable/intuitive.... Anyways it works Smile

Max
Previous Topic: PROPOSAL: TreeCtrl optionally owns Ctrl's in Node
Next Topic: Editing TreeCtrl Node Value
Goto Forum:
  


Current Time: Sat Apr 20 14:05:21 CEST 2024

Total time taken to generate the page: 0.02099 seconds