| Summary: | khexedit statistics columns not sorted correctly | ||
|---|---|---|---|
| Product: | [Unmaintained] khexedit | Reporter: | p92 |
| Component: | general | Assignee: | Espen Sand <espensa> |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | ||
| Priority: | NOR | ||
| Version First Reported In: | 0.8.5 | ||
| Target Milestone: | --- | ||
| Platform: | unspecified | ||
| OS: | Linux | ||
| Latest Commit: | Version Fixed/Implemented In: | ||
| Sentry Crash Report: | |||
| Attachments: | sort order should be numeric on 'occurence' | ||
|
Description
p92
2004-10-28 11:40:11 UTC
still valid in 0.8.5 using KDE 3.3.1 CVS >= 20041110 'occurence' column is the fith one from left. see screenshot Created attachment 8247 [details]
sort order should be numeric on 'occurence'
CVS commit by kossebau:
Backport from HEAD:
QListViewItems are sorted by comparing the text without leading whitespaces
(since when?).
This fails for aligned numbers. Fixed q'n'd by reimplementing the comparison
for the items.
BUG:92249
M +51 -31 fileinfodialog.cc 1.15.4.1
--- kdeutils/khexedit/fileinfodialog.cc #1.15:1.15.4.1
@@ -30,4 +30,45 @@
#include "listview.h"
+// quick'n'dirty hack to have the occurrence column sorted correctly
+class CStatisticListViewItem : public QListViewItem
+{
+ public:
+ CStatisticListViewItem( QListView * parent, QListViewItem * after,
+ QString label1, QString label2, QString label3, QString label4,
+ QString label5, QString label6, QString label7, int i, int o)
+ : QListViewItem( parent, after, label1, label2, label3, label4, label5, label6, label7),
+ item( i ),
+ occurrence( o )
+ {}
+
+ virtual int compare( QListViewItem *i, int col, bool ascending/*Qt doc says: ignore this one*/ ) const
+ {
+ // occurrence column (or the percent one)?
+ if( col == 5 || col == 6 )
+ {
+ const int otherOccurrence = ((CStatisticListViewItem*)i)->occurrence;
+ return occurrence < otherOccurrence ? -1 : occurrence == otherOccurrence ? 0 : 1;
+ }
+ // char column?
+ else if( col == 4 )
+ {
+ const int otherItem = ((CStatisticListViewItem*)i)->item;
+ return item < otherItem ? -1 : item == otherItem ? 0 : 1;
+ }
+ // default
+ else
+ return QListViewItem::compare(i,col,ascending);
+ }
+
+ protected:
+ // no of byte
+ int item;
+ // number of the byte's occurrences
+ int occurrence;
+};
+
+
+
+
CFileInfoDialog::CFileInfoDialog( QWidget *parent,const char *name,bool modal)
:KDialogBase( Plain, i18n("Statistics"), Help|User1|Cancel, User1,
@@ -172,19 +213,11 @@ void CFileInfoDialog::setStatistics( voi
b.sprintf("%s", printBin(i) );
- if( QChar((char)i).isPrint() == true )
- {
- c = QChar((char)i);
- }
- else
- {
- c = QChar('.');
- }
+ const QChar _i((char)i);
+ c = _i.isPrint() ? _i : QChar('.');
- item = new QListViewItem( mFrequencyList, item, h, d, o, b, c, u, u );
+ item = new CStatisticListViewItem( mFrequencyList, item, h, d, o, b, c, u, u, i, -1 );
if( i == 0 )
- {
mFrequencyList->setSelected( item, true );
}
- }
}
@@ -202,13 +235,10 @@ void CFileInfoDialog::setStatistics( SSt
uint size, pre, i;
-
+ // find width of occurrences
for( i=size=0; i<256; i++ )
- {
- if( sc.occurrence[i] > size ) { size = sc.occurrence[i]; }
- }
+ if( sc.occurrence[i] > size )
+ size = sc.occurrence[i];
for( pre = 1; size > 0 ; pre++ )
- {
size /= 10;
- }
for( i=0; i<256; i++ )
@@ -221,7 +251,5 @@ void CFileInfoDialog::setStatistics( SSt
n = QString("%1").arg( sc.occurrence[i], pre );
if( sc.documentSize == 0 )
- {
- p.sprintf("0.00" );
- }
+ p = "0.00";
else
{
@@ -230,19 +258,11 @@ void CFileInfoDialog::setStatistics( SSt
}
- if( QChar((char)i).isPrint() == true )
- {
- c = QChar((char)i);
- }
- else
- {
- c = QChar('.');
- }
+ const QChar _i((char)i);
+ c = _i.isPrint() ? _i : QChar('.');
- item = new QListViewItem( mFrequencyList, item, h, d, o, b, c, n, p );
+ item = new CStatisticListViewItem( mFrequencyList, item, h, d, o, b, c, n, p, i, sc.occurrence[i] );
if( i == 0 )
- {
mFrequencyList->setSelected( item, true );
}
- }
}
|