summaryrefslogtreecommitdiffstats
path: root/src/widgets/dialogs
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2017-02-21 09:10:47 +0100
committerMarc Mutz <marc.mutz@kdab.com>2017-04-20 18:09:10 +0000
commit7291a244161ddf77308413b5abad9def68e4415a (patch)
tree62ad7cac3e07ab7273a4180a0ecb227fa01baf74 /src/widgets/dialogs
parenteec388865f20dda209e1805f55f4185e8ab07546 (diff)
QErrorMessage: use QStringBuilder
Extract Method msgType2i18nString() and use it to build 'rich' in a single QStringBuilder expression. Replace the switch over QtMsgType with an array of QT_TRANSLATE_NOOP'ed strings. That introduces a dependency on the order and amount of enum values, so add static and dynamic asserts to catch any change. Saves memory allocations, as well as nearly 300B in text size on GCC 7 optimized Linux AMD64 builds. Change-Id: I48cc916cba283e482a90ca4ae28aa17b26a4e5ab Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/widgets/dialogs')
-rw-r--r--src/widgets/dialogs/qerrormessage.cpp45
1 files changed, 24 insertions, 21 deletions
diff --git a/src/widgets/dialogs/qerrormessage.cpp b/src/widgets/dialogs/qerrormessage.cpp
index 8200135abe..4ec4da6e1a 100644
--- a/src/widgets/dialogs/qerrormessage.cpp
+++ b/src/widgets/dialogs/qerrormessage.cpp
@@ -161,32 +161,35 @@ static void deleteStaticcQErrorMessage() // post-routine
static bool metFatal = false;
+static QString msgType2i18nString(QtMsgType t)
+{
+ Q_STATIC_ASSERT(QtDebugMsg == 0);
+ Q_STATIC_ASSERT(QtWarningMsg == 1);
+ Q_STATIC_ASSERT(QtCriticalMsg == 2);
+ Q_STATIC_ASSERT(QtFatalMsg == 3);
+ Q_STATIC_ASSERT(QtInfoMsg == 4);
+
+ // adjust the array below if any of the above fire...
+
+ const char * const messages[] = {
+ QT_TRANSLATE_NOOP("QErrorMessage", "Debug Message:"),
+ QT_TRANSLATE_NOOP("QErrorMessage", "Warning:"),
+ QT_TRANSLATE_NOOP("QErrorMessage", "Critical Error:"),
+ QT_TRANSLATE_NOOP("QErrorMessage", "Fatal Error:"),
+ QT_TRANSLATE_NOOP("QErrorMessage", "Information:"),
+ };
+ Q_ASSERT(size_t(t) < sizeof messages / sizeof *messages);
+
+ return QCoreApplication::translate("QErrorMessage", messages[t]);
+}
+
static void jump(QtMsgType t, const QMessageLogContext & /*context*/, const QString &m)
{
if (!qtMessageHandler)
return;
- QString rich;
-
- switch (t) {
- case QtDebugMsg:
- rich = QErrorMessage::tr("Debug Message:");
- break;
- case QtWarningMsg:
- rich = QErrorMessage::tr("Warning:");
- break;
- case QtCriticalMsg:
- rich = QErrorMessage::tr("Critical Error:");
- break;
- case QtFatalMsg:
- rich = QErrorMessage::tr("Fatal Error:");
- break;
- case QtInfoMsg:
- rich = QErrorMessage::tr("Information:");
- break;
- }
- rich = QString::fromLatin1("<p><b>%1</b></p>").arg(rich);
- rich += Qt::convertFromPlainText(m, Qt::WhiteSpaceNormal);
+ QString rich = QLatin1String("<p><b>") + msgType2i18nString(t) + QLatin1String("</b></p>")
+ + Qt::convertFromPlainText(m, Qt::WhiteSpaceNormal);
// ### work around text engine quirk
if (rich.endsWith(QLatin1String("</p>")))