novelWriter
novelWriter copied to clipboard
Writing Statistics: incorrect column sorting
Sorting by the columns "Idle" (percentage) or "Words" produces incorrect sorting. The columns are sorted by the first digit of their respective value, not by the complete value. See the two attached screenshots.
Related: Sorting by Histogram does nothing -- but should conceivably simply do the same as sorting by word count.
Sorting by idle percentage. 5%
is sorted between 54%
and 49%
.
Sorting by word count. It sorts from starting digit 9 down to starting digit 1, also ignoring the negative sign.
This is not a bug. The column sorting is a text sort, and the widget doesn't support any other sorting mechanism. That's why the dates are in ISO format.
In order to fix this, I need to make a custom implementation of the item widgets, which is very slow in Python. I can test it out though and check if it is too slow.
This is actually far easier then re-implementing the whole widget
# Untested Example
class WSTreeWidgetItem( QtGui.QTreeWidgetItem ):
def __init__(self, parent=None):
QtGui.QTreeWidgetItem.__init__(self, parent)
def __lt__(self, otherItem):
column = self.treeWidget().sortColumn()
# sort based on column; ie.
if column == 0: # ISO Date
return self.text(column) > otherItem.text(column)
if column > 0 and column < 3: # Numerical Columns
try:
return float( self.text(column) ) > float( otherItem.text(column) )
except ValueError:
return self.text(column) > otherItem.text(column)
else: # histogram
try:
return float( self.text(3) ) > float( otherItem.text(3) )
except ValueError:
return self.text(column) > otherItem.text(column)
then use something like this WSTreeWidgetItem
in place of QTreeWidgetItem
in the _updateListBox
method
Yes, this solution is what I mean by "a custom item widget". I haven't tested it yet, but thanks for the example. :)