[Tellico-users] two patches for sorting

Andrew Bennett drewbenn at gmail.com
Sun Nov 21 09:08:07 UTC 2010

Hi Robby,

I've noticed two minor issues when sorting numbers.  I've created
patches for both of them, although there are probably better ways of
fixing them.

The first, and less important, is that when a number field has
multiple values, sorting is only performed on the first value.  The
attached file 'sortmult.diff' loops through all the values, so that,
for example, "1; 2" will always come before "1; 3".  There's not a lot
to this patch, although one comment in NumberComparison::compare() had
me a little confused:
  // by default, an empty string would get sorted before "1" because
toFloat() turns it into "0"
  // I want the empty strings to be at the end
This is different from how strings get sorted, where empty strings get
put at the beginning (because it is just a simple string compare); it
seemed odd that numbers and strings are being treated differently.

The second, which I'd really like to see make it into Tellico in some
form, is that numbers are sorted in alphabetic, rather than numeric,
order in the group view.  The attached file 'sortgroups.diff' is a bit
more complex, and when sorting in the group view it checks the field
type and calls the field's custom sort function for certain types
(number, boolean, rating, date, and LCC).  I don't really understand
the data structures inside Tellico, so my method for accessing the
field type is probably not the best or even correct way.

I couldn't make it work with FieldComparison::compare(QString,
QString) as a protected function, so I moved that up to public.  While
I was in the area, I also made EntrySortModel::clear() private since I
don't know of any reason for it to be public, but that's just general
code cleanup, not anything needed by my changes.

The GroupSortModel changes were cribbed from EntrySortModel; there
really isn't anything original there.  I didn't save the sort function
pointers in a member variable, mostly because I had a lot of trouble
getting it to work and eventually gave up, and partly because in a
collection of around 250 books I didn't notice any lag so it didn't
seem important enough to optimize.

I don't like the hack in the new GroupSortModel::getComparison() of
checking that subset of field types, and I'm not positive I picked the
correct set of subtypes, but I couldn't come up with anything better,
and without that hack the other field types not listed there kept
getting sorted incorrectly.

I did my testing against Tellico 2.3, not 2.3.1 or the SVN trunk (but
I don't think any of these files have changed recently).  These
changes haven't been exhaustively tested, either: they seem to work in
my collection for the things I care about, but that's all I checked.

Finally, when I build for the first time, I see a whole lot of
warnings about deprecated functions.  It could be due to my
environment (Ubuntu 10.10, 64-bit, GNOME), and they didn't seem to
affect anything.  I didn't pay any attention to them, but wanted to
mention it in case you care (they disappear on subsequent builds, so
it's pretty easy to forget about them).

I hope these are useful,

Drew Bennett
drewbenn at gmail.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sortmult.diff
Type: text/x-diff
Size: 1054 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/tellico-users/attachments/20101121/6df82822/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sortgroups.diff
Type: text/x-diff
Size: 4009 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/tellico-users/attachments/20101121/6df82822/attachment-0001.bin>

More information about the tellico-users mailing list