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 » Drag & Drop , Sort, GetValue( x )
Drag & Drop , Sort, GetValue( x ) [message #19586] Sun, 21 December 2008 00:13 Go to next message
sapiency is currently offline  sapiency
Messages: 56
Registered: September 2008
Member
hi,

I'm just playing arount with TreeCtrl to get a solution for my problem.

Attache you find a modified reference example, including the logfile.

in the output you see the value get with
int n = tree.GetItemAtLine(i)
Value a = tree.GetValue(n);

and with the variable I used in the loop
Value b = tree.GetValue(i);

the output is not the same even after
tree.Sort(0);

is this a bug? or is just the way using GetItemAtLine(x) the only way to do this?

and I don't understand how to use the whole features of Sort...().

Do I have to overload the struct to use it?
00222 struct ValueOrder {
00223         virtual bool operator()(const Value& a, const Value& b) const = 0;
00224         virtual ~ValueOrder() {}
00225 };

Maybe you can give me a short example.

regards

reinhard

ps: I'm still working with 2008.1, build in July ...

[Updated on: Mon, 22 December 2008 12:14]

Report message to a moderator

Re: Drag & Drop , Sort, GetValue( x ) [message #19588 is a reply to message #19586] Sun, 21 December 2008 14:04 Go to previous messageGo to next message
sapiency is currently offline  sapiency
Messages: 56
Registered: September 2008
Member
hi,

I modified the example above to show it more clearly what happens

creating the elements and show the content of the tree:
[12/21/2008 13:15:14.3824] Elements: 10
[12/21/2008 13:15:14.3824]  just created ( 1)  get with i: I	 get with n: I
[12/21/2008 13:15:14.3824]  just created ( 2)  get with i: II	 get with n: II
[12/21/2008 13:15:14.3824]  just created ( 3)  get with i: III	 get with n: III
[12/21/2008 13:15:14.3824]  just created ( 4)  get with i: IV	 get with n: IV
[12/21/2008 13:15:14.3824]  just created ( 5)  get with i: V	 get with n: V
[12/21/2008 13:15:14.3824]  just created ( 6)  get with i: VI	 get with n: VI
[12/21/2008 13:15:14.3824]  just created ( 7)  get with i: VII	 get with n: VII
[12/21/2008 13:15:14.3824]  just created ( 8)  get with i: VIII	 get with n: VIII
[12/21/2008 13:15:14.3824]  just created ( 9)  get with i: IX	 get with n: IX


choose element 8 with value "VIII" and drop it to the end of the list.
parent = 0
ii = 9
sel[i] = 8
[12/21/2008 13:15:26.6583] AcceptInternal<TreeCtrl>(d, 'mytreedrag'): parent:  0, ii  9
[12/21/2008 13:15:26.6583] Elements: 10
[12/21/2008 13:15:28.8165]  unsorted ( 1)  get with i: I	 get with n: I
[12/21/2008 13:15:28.8165]  unsorted ( 2)  get with i: II	 get with n: II
[12/21/2008 13:15:28.8165]  unsorted ( 3)  get with i: III	 get with n: III
[12/21/2008 13:15:28.8165]  unsorted ( 4)  get with i: IV	 get with n: IV
[12/21/2008 13:15:28.8165]  unsorted ( 5)  get with i: V	 get with n: V
[12/21/2008 13:15:28.8165]  unsorted ( 6)  get with i: VI	 get with n: VI
[12/21/2008 13:15:28.8165]  unsorted ( 7)  get with i: VII	 get with n: VII
[12/21/2008 13:15:28.8165]  unsorted ( 8)  get with i: 	 get with n: IX
[12/21/2008 13:15:28.8165]  unsorted ( 9)  get with i: IX	 get with n: VIII


take last element with value "VIII" and drop it between "V" and "VI"
parent = 0
ii = 5
sel[i] = 10
[12/21/2008 13:16:12.1737] AcceptInternal<TreeCtrl>(d, 'mytreedrag'): parent:  0, ii  5
[12/21/2008 13:16:12.1737] Elements: 10
[12/21/2008 13:16:15.4792]  unsorted ( 1)  get with i: I	 get with n: I
[12/21/2008 13:16:15.4792]  unsorted ( 2)  get with i: II	 get with n: II
[12/21/2008 13:16:15.4792]  unsorted ( 3)  get with i: III	 get with n: III
[12/21/2008 13:16:15.4792]  unsorted ( 4)  get with i: IV	 get with n: IV
[12/21/2008 13:16:15.4792]  unsorted ( 5)  get with i: V	 get with n: V
[12/21/2008 13:16:15.4792]  unsorted ( 6)  get with i: VI	 get with n: VIII
[12/21/2008 13:16:15.4792]  unsorted ( 7)  get with i: VII	 get with n: VI
[12/21/2008 13:16:15.4792]  unsorted ( 8)  get with i: VIII	 get with n: VII
[12/21/2008 13:16:15.4792]  unsorted ( 9)  get with i: IX	 get with n: IX


after the second step the tree loose the value from Element with ID 8 because it got ID 10 when I put it to the end of the list.

regards

reinhard

[Updated on: Sat, 27 December 2008 23:30]

Report message to a moderator

Re: Drag & Drop , Sort, GetValue( x ) [message #19594 is a reply to message #19588] Mon, 22 December 2008 09:50 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
First small tip:

#define D3(x) RLOG("[" << GetSysTime() << "." << int(GetTickCount() % 10000u) << "] " << x)


In that case, you should be able to

D3(" sorted (" << i << ")  get with i: " << b <<  "\t get with n: " << a);


(BTW, Sprintf is the least safe way how to format things anyway...)

To work with elements, you never should use 'i'. Always navigate elements in the tree using:

	int    GetChildCount(int id);
	int    GetChild(int id, int i);


- that will get you correct node ids.

You should never do it by using 'i' as in your example. GetItemAtLine is quite specific command, you probably would not want to use it either - it gets id of item and given *line* of TreeCtrl - that depends a lot on what nodes are actually open!

You only need to use ValueOrder in case that sorting requiris additional parametrs - e.g. values in TreeCtrl are 'columns' and you want to specify by which column you wish to sort - in that case you need to pass column number to comparison predicate - and ValueOrder allows you to do that (you derive from it, add column number, use it in comparision).

In 90% of cases, simplified methods with "int (*compare)(const Value& v1, const Value& v2)" will be enought.

Mirek
Re: Drag & Drop , Sort, GetValue( x ) [message #19645 is a reply to message #19594] Sat, 27 December 2008 23:30 Go to previous message
sapiency is currently offline  sapiency
Messages: 56
Registered: September 2008
Member
hi Mirek,

I've created an example which work almost as it should.

actually you can create and delete (right button on element / group) elements and groups, move elements to groups, sort them manually.

If you look at line 90 of main.cpp you find
&& _isMovedElement ==false


without this, the callback 'DropInsert' is called twice and two elements are moved to the new place ...

I tried to find out which Method I have to call so that the callback will be called only once. In the example of DND
InsertDrop(parent, ii, d);

moves the Element to the new place in the tree. But I didn't found the reason why the callback is called twice without this line of code ...

regards

reinhard
Previous Topic: Optional highlighting of focused node's control along with value
Next Topic: gui crashes.
Goto Forum:
  


Current Time: Fri Mar 29 00:01:38 CET 2024

Total time taken to generate the page: 0.01440 seconds