From 695d85363e537b51b5d0ae6ab08a9a1e7d9e8354 Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Mon, 6 Apr 2015 13:47:16 +0300 Subject: 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 --- src/widgets/itemviews/qstyleditemdelegate.cpp | 36 +-------------------------- 1 file changed, 1 insertion(+), 35 deletions(-) (limited to 'src/widgets/itemviews/qstyleditemdelegate.cpp') diff --git a/src/widgets/itemviews/qstyleditemdelegate.cpp b/src/widgets/itemviews/qstyleditemdelegate.cpp index f02f98cb31..483cfbdc36 100644 --- a/src/widgets/itemviews/qstyleditemdelegate.cpp +++ b/src/widgets/itemviews/qstyleditemdelegate.cpp @@ -255,41 +255,7 @@ QStyledItemDelegate::~QStyledItemDelegate() */ QString QStyledItemDelegate::displayText(const QVariant &value, const QLocale& locale) const { - QString text; - switch (value.userType()) { - case QMetaType::Float: - case QVariant::Double: - text = locale.toString(value.toReal()); - break; - case QVariant::Int: - case QVariant::LongLong: - text = locale.toString(value.toLongLong()); - break; - case QVariant::UInt: - case QVariant::ULongLong: - text = locale.toString(value.toULongLong()); - break; - case QVariant::Date: - text = locale.toString(value.toDate(), QLocale::ShortFormat); - break; - case QVariant::Time: - text = locale.toString(value.toTime(), QLocale::ShortFormat); - break; - case QVariant::DateTime: - text = locale.toString(value.toDateTime().date(), QLocale::ShortFormat); - text += QLatin1Char(' '); - text += locale.toString(value.toDateTime().time(), QLocale::ShortFormat); - break; - default: - // convert new lines into line separators - text = value.toString(); - for (int i = 0; i < text.count(); ++i) { - if (text.at(i) == QLatin1Char('\n')) - text[i] = QChar::LineSeparator; - } - break; - } - return text; + return d_func()->textForRole(Qt::DisplayRole, value, locale); } /*! -- cgit v1.2.3