summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@gmail.com>2009-06-08 09:05:35 (GMT)
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2009-06-08 09:51:41 (GMT)
commitb5579e01a023800a6fd81193209db00e000a3620 (patch)
tree3e865551146846196e2aaa0f405d868e5900bfa7 /src
parenteb8789ba06949974eb4108b115a30f96e1500a81 (diff)
downloadQt-b5579e01a023800a6fd81193209db00e000a3620.zip
Qt-b5579e01a023800a6fd81193209db00e000a3620.tar.gz
Qt-b5579e01a023800a6fd81193209db00e000a3620.tar.bz2
Made QTreeWidgetItem::operator<() check if the data is numerical when comparing.
More information in task 166873. Merge-request: 514 Reviewed-by: Jan-Arve Sæther <jan-arve.saether@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/gui/itemviews/qtreewidget.cpp33
-rw-r--r--src/gui/itemviews/qtreewidget_p.h1
2 files changed, 31 insertions, 3 deletions
diff --git a/src/gui/itemviews/qtreewidget.cpp b/src/gui/itemviews/qtreewidget.cpp
index a2bfe45..1c87580 100644
--- a/src/gui/itemviews/qtreewidget.cpp
+++ b/src/gui/itemviews/qtreewidget.cpp
@@ -577,7 +577,7 @@ void QTreeModel::sort(int column, Qt::SortOrder order)
if (column < 0 || column >= columnCount())
return;
- //layoutAboutToBeChanged and layoutChanged will be called by sortChildren
+ //layoutAboutToBeChanged and layoutChanged will be called by sortChildren
rootItem->sortChildren(column, order, true);
}
@@ -695,6 +695,29 @@ bool QTreeModel::itemGreaterThan(const QPair<QTreeWidgetItem*,int> &left,
}
/*!
+ \internal
+
+ Returns true if the type of the variant \a value
+ can be casted as double.
+*/
+bool QTreeModel::canConvertToDouble(const QVariant &value)
+{
+ switch (value.type()) {
+ case QVariant::Bool:
+ case QVariant::Int:
+ case QVariant::UInt:
+ case QVariant::LongLong:
+ case QVariant::ULongLong:
+ case QVariant::Double:
+ case QVariant::Char:
+ return true;
+ default:
+ return false;
+ }
+ return false;
+}
+
+/*!
\internal
*/
QList<QTreeWidgetItem*>::iterator QTreeModel::sortedInsertionIterator(
@@ -1787,7 +1810,11 @@ QVariant QTreeWidgetItem::data(int column, int role) const
bool QTreeWidgetItem::operator<(const QTreeWidgetItem &other) const
{
int column = view ? view->sortColumn() : 0;
- return text(column) < other.text(column);
+ const QVariant v1 = data(column, Qt::DisplayRole);
+ const QVariant v2 = other.data(column, Qt::DisplayRole);
+ if (QTreeModel::canConvertToDouble(v1) && QTreeModel::canConvertToDouble(v2))
+ return v1.toDouble() < v2.toDouble();
+ return v1.toString() < v2.toString();
}
#ifndef QT_NO_DATASTREAM
@@ -2074,7 +2101,7 @@ void QTreeWidgetItemPrivate::sortChildren(int column, Qt::SortOrder order, bool
if (climb) {
QList<QTreeWidgetItem*>::iterator it = q->children.begin();
for (; it != q->children.end(); ++it) {
- //here we call the private object's method to avoid emitting
+ //here we call the private object's method to avoid emitting
//the layoutAboutToBeChanged and layoutChanged signals
(*it)->d->sortChildren(column, order, climb);
}
diff --git a/src/gui/itemviews/qtreewidget_p.h b/src/gui/itemviews/qtreewidget_p.h
index a089cf5..96f734d 100644
--- a/src/gui/itemviews/qtreewidget_p.h
+++ b/src/gui/itemviews/qtreewidget_p.h
@@ -116,6 +116,7 @@ public:
const QPair<QTreeWidgetItem*,int> &right);
static bool itemGreaterThan(const QPair<QTreeWidgetItem*,int> &left,
const QPair<QTreeWidgetItem*,int> &right);
+ static bool canConvertToDouble(const QVariant &value);
static QList<QTreeWidgetItem*>::iterator sortedInsertionIterator(
const QList<QTreeWidgetItem*>::iterator &begin,
const QList<QTreeWidgetItem*>::iterator &end,