summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews/qitemdelegate.cpp
diff options
context:
space:
mode:
authorAlexander Volkov <a.volkov@rusbitech.ru>2015-04-06 13:47:16 +0300
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2016-07-28 23:42:56 +0000
commit695d85363e537b51b5d0ae6ab08a9a1e7d9e8354 (patch)
tree51f07befe3d10846a3b6bcfbf0cbf769e79ae1c2 /src/widgets/itemviews/qitemdelegate.cpp
parent444ba31a0a68421ee9ff7de788f6026599202455 (diff)
Item delegates: show localized detailed tooltips and "What's this?" texts
Extract the common part from QItemDelegate and QStyledItemDelegate which uses QLocale to convert a value for Qt::DisplayRole to a string. Use this code to get the text for tooltips and "What's this?". [ChangeLog][QtWidgets][QAbstractItemDelegate] Show localized detailed tooltips and "What's this?" texts. Task-number: QTBUG-16469 Change-Id: I8618763d45b8cfddafc2f263d658ba256be60a15 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'src/widgets/itemviews/qitemdelegate.cpp')
-rw-r--r--src/widgets/itemviews/qitemdelegate.cpp42
1 files changed, 6 insertions, 36 deletions
diff --git a/src/widgets/itemviews/qitemdelegate.cpp b/src/widgets/itemviews/qitemdelegate.cpp
index cd952737dd..2b6e1210ca 100644
--- a/src/widgets/itemviews/qitemdelegate.cpp
+++ b/src/widgets/itemviews/qitemdelegate.cpp
@@ -61,6 +61,7 @@
#include <limits.h>
+// keep in sync with QAbstractItemDelegate::helpEvent()
#ifndef DBL_DIG
# define DBL_DIG 10
#endif
@@ -96,7 +97,7 @@ public:
return text;
}
- static QString valueToText(const QVariant &value, const QStyleOptionViewItem &option);
+ QString valueToText(const QVariant &value, const QStyleOptionViewItem &option) const;
QItemEditorFactory *f;
bool clipPainting;
@@ -326,40 +327,9 @@ void QItemDelegate::setClipping(bool clip)
d->clipPainting = clip;
}
-QString QItemDelegatePrivate::valueToText(const QVariant &value, const QStyleOptionViewItem &option)
+QString QItemDelegatePrivate::valueToText(const QVariant &value, const QStyleOptionViewItem &option) const
{
- QString text;
- 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;
- case QVariant::Int:
- case QVariant::LongLong:
- text = option.locale.toString(value.toLongLong());
- break;
- case QVariant::UInt:
- case QVariant::ULongLong:
- text = option.locale.toString(value.toULongLong());
- break;
- case QVariant::Date:
- text = option.locale.toString(value.toDate(), QLocale::ShortFormat);
- break;
- case QVariant::Time:
- text = option.locale.toString(value.toTime(), QLocale::ShortFormat);
- break;
- case QVariant::DateTime:
- text = option.locale.toString(value.toDateTime().date(), QLocale::ShortFormat);
- text += QLatin1Char(' ');
- text += option.locale.toString(value.toDateTime().time(), QLocale::ShortFormat);
- break;
- default:
- text = replaceNewLine(value.toString());
- break;
- }
- return text;
+ return textForRole(Qt::DisplayRole, value, option.locale, DBL_DIG);
}
/*!
@@ -428,7 +398,7 @@ void QItemDelegate::paint(QPainter *painter,
QRect displayRect;
value = index.data(Qt::DisplayRole);
if (value.isValid() && !value.isNull()) {
- text = QItemDelegatePrivate::valueToText(value, opt);
+ text = d->valueToText(value, opt);
displayRect = textRectangle(painter, d->textLayoutBounds(opt), opt.font, text);
}
@@ -1055,7 +1025,7 @@ QRect QItemDelegate::rect(const QStyleOptionViewItem &option,
return QRect(QPoint(0, 0), option.decorationSize);
case QVariant::String:
default: {
- QString text = QItemDelegatePrivate::valueToText(value, option);
+ const QString text = d->valueToText(value, option);
value = index.data(Qt::FontRole);
QFont fnt = qvariant_cast<QFont>(value).resolve(option.font);
return textRectangle(0, d->textLayoutBounds(option), fnt, text); }