Bug 119929

Summary: sort variables list alphabetically
Product: [Applications] kdevelop Reporter: Rob L <robert.leathley>
Component: CPP DebuggerAssignee: kdevelop-bugs-null
Status: RESOLVED FIXED    
Severity: wishlist CC: daviddoria, kbugger, niko.sams, peje66, piotr.mierzwinski, rishabh9511, savoiu
Priority: NOR    
Version: 3.3.0   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: view of variables list
comparision between kdevelop 4.7 & 4.90.90

Description Rob L 2006-01-11 16:51:36 UTC
Version:           3.3.0 (using KDE KDE 3.5.0)
Installed from:    Compiled From Sources
Compiler:          gcc 3.3.3 
OS:                Linux

Currently variables are listed in the order they are defined in the source code (I think).  If there is a long list of variables it can be hard to find the required name, but would be much easier if they were sorted alphabetically.

Could we either have an option to, or always sort this way?
Comment 1 kbugger 2007-07-01 18:00:43 UTC
Please can we have CONFIRMED and a resolution here. This tool is basically very good but this defect alone increases the time needed to scan a variable value by at least a factor of ten.

I may well be better using printf and scanning the console output , this feature is so close but sadly near useless as it is.

Comment 2 Andreas Pakulat 2007-07-01 19:18:57 UTC
Open Source Developers work on things they want to work on. As far as KDevelop Developers are concerned: We don't work on KDevelop3 anymore, except for important bugfixes. So you have to wait til KDevelop4 to see this.
Comment 3 kbugger 2007-07-01 19:46:21 UTC
OK, this bug is rather old but at least if you're agreed this would be an improvement I'm sure there are more pressing issues , although this would probably be about NO.1 usability flaw for my usage.

I guess we'll have to be patient. 

Thanks for the quick response.
Comment 4 Niko Sams 2009-07-26 22:24:11 UTC
Sort by the order in code also makes sense.
IMHO if you look for a specfic variable you add a watch.
Opinions on this?
Comment 5 kbugger 2009-07-26 23:12:18 UTC
could you explain in what way "sort by order in code" is useful? Unless I have photographic recall of all the relevant source, I don't see how this is much help.

saying you would use a different tool is irrelevant. 

assuming that the variable list has a use (part of which is to display current value) it should be organised in a way that make the information accessible. The current format is a bit like a telephone directory that lists people in the order that they took out the subscription.
Comment 6 Rob L 2009-07-27 12:33:02 UTC
Assuming your variables are defined in the smallest possible scope, then those of interest may be near the bottom of the list.  For those that aren't they can be very hard to find, particularly if it is unfamiliar code you are working on.

Generally there are too many variables of interest to make watches practical.  You would have to build your own list in alphabetical order.  Tool tip values in the code editor would be an alternative, in which case I would rarely use the variables tree.  But if the tree is to exist, it should be as usable as possible - a user preference can't be that hard to code?
Comment 7 Andreas Pakulat 2009-07-27 12:57:31 UTC
(In reply to comment #6)
> Assuming your variables are defined in the smallest possible scope, then those
> of interest may be near the bottom of the list.  For those that aren't they can
> be very hard to find, particularly if it is unfamiliar code you are working on.

Well, in properly structured code there's not that many variables inside a function or on the global stack. Anyway, I agree a sorting option would be useful, however...

> Generally there are too many variables of interest to make watches practical. 
> You would have to build your own list in alphabetical order.  Tool tip values
> in the code editor would be an alternative,

That works in KDevelop4.

> in which case I would rarely use
> the variables tree.  But if the tree is to exist, it should be as usable as
> possible - a user preference can't be that hard to code?

You'd be surprised how hard it can be. While Qt4 MVC does make some things easier, some other things are getting a bit harder, in particular adding sort/filtering (or rather need more amount of code and possibly adjustments at a few places).
Comment 8 Rob L 2009-07-27 13:20:54 UTC
ok, so this will be most useful to those who have to work with code that isn't properly structured.

I look forward to getting SLES11 and kdev 4 installed.

QSortFilterProxyModel?
Comment 9 Andreas Pakulat 2009-07-27 13:51:08 UTC
(In reply to comment #8)
> ok, so this will be most useful to those who have to work with code that isn't
> properly structured.

That part was actually meant as a joke, I just forgot the ;)

> QSortFilterProxyModel?

Yes, but doing that means adjusting all places that use the view's model or the selection model as you have to convert all the item indices...
Comment 10 Niko Sams 2012-08-24 14:41:10 UTC
*** Bug 304819 has been marked as a duplicate of this bug. ***
Comment 11 Rishabh gupta 2015-09-20 15:48:10 UTC
Can i take this ?doesn't seem that it requires much work
Comment 12 Rishabh gupta 2015-09-20 16:44:14 UTC
Created attachment 94659 [details]
view of variables list

if i have understood correctly ,then the variables (please refer to the image) on the left side should be sorted in alphabetical order ?
Comment 13 Milian Wolff 2015-11-09 15:14:12 UTC
Git commit fa956301ecf0de5dc533f1c90cf21372476297c8 by Milian Wolff, on behalf of rishabh gupta.
Committed on 09/11/2015 at 15:10.
Pushed by mwolff into branch '5.0'.

Sort variables alphabetically in debugger variables view.

REVIEW: 125549

M  +3    -0    debugger/util/treemodel.cpp
M  +4    -0    debugger/util/treemodel.h
M  +7    -6    debugger/util/treeview.cpp
M  +5    -1    debugger/util/treeview.h
M  +6    -1    debugger/variable/variabletooltip.cpp
M  +2    -0    debugger/variable/variabletooltip.h
M  +15   -5    debugger/variable/variablewidget.cpp
M  +6    -3    debugger/variable/variablewidget.h

http://commits.kde.org/kdevplatform/fa956301ecf0de5dc533f1c90cf21372476297c8
Comment 14 peje66 2015-11-20 09:32:00 UTC
Created attachment 95614 [details]
comparision between kdevelop 4.7 & 4.90.90

The sorting of variables when debugging is good but with one bad side effect.

When expanding a vector with more than 10 elements the order becomes:
0, 1, 10, 11, 2, 3, 4, 5, 6, 7, 8, 9

It becomes very hard to follow for example a vector fill.

See attached comparision between kdevelop 4.7 and 5.0
Comment 15 Piotr Mierzwinski 2016-01-09 01:04:03 UTC
The same happen when we unfold QStringList contains more than 10 items. I aware that QStringList is vector variation contains strings instead of numbers. It was only next example.
This issue probably happens because there are sorting strings (presenting indexes) and not numbers.

Some solution for this could be adding 0 to the left side of indexes, making that them length (as string) would be equal. I mean left padding every indexes shortest than one longest (counting number of digits). I think, example will show the best what I mean.
There is QStringList contains 12 strings. This vector/list would be presented in Variable view like this.

myStrList
 |-[00] aa
 |-[01] bb
 |-[02] cc
 |-[03] dd
 |-[04] ee
 |-[05] ff
 |-[06] gg
 |-[07] hh
 |-[08] ii
 |-[09] jj
 |-[10] kk
  \-[11] ll

Thanks leading "0", change of sorting would not broke the order of items.
Comment 16 Milian Wolff 2016-01-09 15:42:41 UTC
needs to be fixed, I agree. it should use natural sorting.
Comment 17 Kevin Funk 2016-01-10 20:34:50 UTC
Git commit fa0d28c15edd81f1613483607d677f9aca2b820c by Kevin Funk, on behalf of Mikhail Ivchenko.
Committed on 10/01/2016 at 20:32.
Pushed by kfunk into branch '5.0'.

[GCI] Use natural sorting in variable list

Test Plan: Tests passed and works as expected.

Reviewers: kfunk

Reviewed By: kfunk

Subscribers: kdevelop-devel, #kdevelop

Projects: #kdevelop

Differential Revision: https://phabricator.kde.org/D777

M  +1    -0    debugger/CMakeLists.txt
A  +46   -0    debugger/variable/variablesortmodel.cpp     [License: GPL (v2+)]
A  +45   -0    debugger/variable/variablesortmodel.h     [License: GPL (v2+)]
M  +2    -1    debugger/variable/variablewidget.cpp

http://commits.kde.org/kdevplatform/fa0d28c15edd81f1613483607d677f9aca2b820c
Comment 18 Milian Wolff 2016-01-23 18:22:45 UTC
*** Bug 355852 has been marked as a duplicate of this bug. ***