+/* at this time we don't sort trees, so this method does nothing */
+void TreeItemFormatter::setSortValue(int /* index */, const QVariant & /* value */)
+{
+}
+
+/***********************************************
+ *
+ * Specialized table widget used for sorting
+ *
+ ***********************************************/
+TableItemFormatter::BatSortingTableItem::BatSortingTableItem():
+QTableWidgetItem(1)
+{
+}
+
+void TableItemFormatter::BatSortingTableItem::setSortData(const QVariant &d)
+{
+ setData(SORTDATA_ROLE, d);
+}
+
+bool TableItemFormatter::BatSortingTableItem::operator< ( const QTableWidgetItem & o ) const
+{
+ QVariant my = data(SORTDATA_ROLE);
+ QVariant other = o.data(SORTDATA_ROLE);
+ if (!my.isValid() || !other.isValid() || my.type() != other.type())
+ return QTableWidgetItem::operator< (o); /* invalid combination, revert to default sorting */
+
+ /* 64bit integers must be handled separately, others can be converted to double */
+ if (QVariant::ULongLong == my.type()) {
+ return my.toULongLong() < other.toULongLong();
+ } else if (QVariant::LongLong == my.type()) {
+ return my.toLongLong() < other.toLongLong();
+ } else if (my.canConvert(QVariant::Double)) {
+ return my.toDouble() < other.toDouble();
+ } else {
+ return QTableWidgetItem::operator< (o); /* invalid combination, revert to default sorting */
+ }
+}