summaryrefslogtreecommitdiffstats
path: root/src/gui/itemviews
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2009-08-14 11:01:37 (GMT)
committerThierry Bastian <thierry.bastian@nokia.com>2009-08-14 11:03:51 (GMT)
commitb770651f19741907cd415ea9ad6e087cb32cc948 (patch)
treeecc163e8b33af66454b84ca7f9159d11d6f0cd91 /src/gui/itemviews
parent51ce8a80acebc67ef09d506d89a2ee1972377877 (diff)
downloadQt-b770651f19741907cd415ea9ad6e087cb32cc948.zip
Qt-b770651f19741907cd415ea9ad6e087cb32cc948.tar.gz
Qt-b770651f19741907cd415ea9ad6e087cb32cc948.tar.bz2
QVariant: added toFloat and toReal
Made better use of qreal all over the place. We were previously using QVariant::toDouble a lot. That is triggering unnecessary conversions between float and double on embedded. Reviewed-by: ogoffart
Diffstat (limited to 'src/gui/itemviews')
-rw-r--r--src/gui/itemviews/qitemdelegate.cpp5
-rw-r--r--src/gui/itemviews/qsortfilterproxymodel.cpp4
-rw-r--r--src/gui/itemviews/qstandarditemmodel.cpp4
-rw-r--r--src/gui/itemviews/qstyleditemdelegate.cpp3
4 files changed, 12 insertions, 4 deletions
diff --git a/src/gui/itemviews/qitemdelegate.cpp b/src/gui/itemviews/qitemdelegate.cpp
index 75d48a4..2cbde51 100644
--- a/src/gui/itemviews/qitemdelegate.cpp
+++ b/src/gui/itemviews/qitemdelegate.cpp
@@ -352,7 +352,10 @@ void QItemDelegate::setClipping(bool clip)
QString QItemDelegatePrivate::valueToText(const QVariant &value, const QStyleOptionViewItemV4 &option)
{
QString text;
- switch (value.type()) {
+ switch (value.userType()) {
+ case QMetaType::Float:
+ text = option.locale.toString(value.toFloat(), 'g');
+ break;
case QVariant::Double:
text = option.locale.toString(value.toDouble(), 'g', DBL_DIG);
break;
diff --git a/src/gui/itemviews/qsortfilterproxymodel.cpp b/src/gui/itemviews/qsortfilterproxymodel.cpp
index d39506d..8444a5b 100644
--- a/src/gui/itemviews/qsortfilterproxymodel.cpp
+++ b/src/gui/itemviews/qsortfilterproxymodel.cpp
@@ -2316,7 +2316,7 @@ bool QSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex
Q_D(const QSortFilterProxyModel);
QVariant l = (left.model() ? left.model()->data(left, d->sort_role) : QVariant());
QVariant r = (right.model() ? right.model()->data(right, d->sort_role) : QVariant());
- switch (l.type()) {
+ switch (l.userType()) {
case QVariant::Invalid:
return (r.type() == QVariant::Invalid);
case QVariant::Int:
@@ -2327,6 +2327,8 @@ bool QSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex
return l.toLongLong() < r.toLongLong();
case QVariant::ULongLong:
return l.toULongLong() < r.toULongLong();
+ case QMetaType::Float:
+ return l.toFloat() < r.toFloat();
case QVariant::Double:
return l.toDouble() < r.toDouble();
case QVariant::Char:
diff --git a/src/gui/itemviews/qstandarditemmodel.cpp b/src/gui/itemviews/qstandarditemmodel.cpp
index 7505ccc..168d423 100644
--- a/src/gui/itemviews/qstandarditemmodel.cpp
+++ b/src/gui/itemviews/qstandarditemmodel.cpp
@@ -1809,7 +1809,7 @@ bool QStandardItem::operator<(const QStandardItem &other) const
const int role = model() ? model()->sortRole() : Qt::DisplayRole;
const QVariant l = data(role), r = other.data(role);
// this code is copied from QSortFilterProxyModel::lessThan()
- switch (l.type()) {
+ switch (l.userType()) {
case QVariant::Invalid:
return (r.type() == QVariant::Invalid);
case QVariant::Int:
@@ -1820,6 +1820,8 @@ bool QStandardItem::operator<(const QStandardItem &other) const
return l.toLongLong() < r.toLongLong();
case QVariant::ULongLong:
return l.toULongLong() < r.toULongLong();
+ case QMetaType::Float:
+ return l.toFloat() < r.toFloat();
case QVariant::Double:
return l.toDouble() < r.toDouble();
case QVariant::Char:
diff --git a/src/gui/itemviews/qstyleditemdelegate.cpp b/src/gui/itemviews/qstyleditemdelegate.cpp
index 0494d4f..f7c7d12 100644
--- a/src/gui/itemviews/qstyleditemdelegate.cpp
+++ b/src/gui/itemviews/qstyleditemdelegate.cpp
@@ -267,7 +267,8 @@ QStyledItemDelegate::~QStyledItemDelegate()
QString QStyledItemDelegate::displayText(const QVariant &value, const QLocale& locale) const
{
QString text;
- switch (value.type()) {
+ switch (value.userType()) {
+ case QMetaType::Float:
case QVariant::Double:
text = locale.toString(value.toDouble());
break;