From kde-devel Sun Oct 16 19:56:22 2005 From: =?iso-8859-15?q?Andr=E9_W=F6bbeking?= Date: Sun, 16 Oct 2005 19:56:22 +0000 To: kde-devel Subject: Re: KListView and sorting items Message-Id: <200510162156.22933.Woebbeking () onlinehome ! de> X-MARC-Message: https://marc.info/?l=kde-devel&m=112949237802065 On Sunday 16 October 2005 20:16, Giovanni Venturi wrote: > > Mmm, I don't understand. I used compare() before your reply because > the sorting was done according the strings and I need according long: > > > int KSnifferViewItem::compare( QListViewItem *i, int col, > bool ascending ) const > { > int result; > > switch (col) > { > case 0: > // frame number... > if (key(col, ascending).toLong() < i->key(col, > ascending).toLong()) result = -1; > else if (key(col, ascending).toLong() > i->key(col, > ascending).toLong()) result = 1; > else > result = 0; > break; Don't use key() or you've two conversions (data -> string -> data). Use the data directly, i.e. if (number < i->number) result = -1; else if (number > i->number) result = 1; else result = 0; this small template template int Compare(Type const& lhs, Type const& rhs) { if (lhs < rhs) return -1; else if (rhs < lhs) return 1; else return 0; } is very helpful. With it you can write result = Compare(number, i->number); > Maybe compare() I wrote has some statement that is not for the system > performance? Can someone reply me? > > Redifine text? In which way? I don't understand. Store your data in your item. With text() you only convert the data on demand. >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<