summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2014-07-29 23:32:13 +0200
committerMarc Mutz <marc.mutz@kdab.com>2014-07-30 23:41:01 +0200
commitc7386938b43f3564b3e3a6fe5f98009e39d52e4c (patch)
treed288735af2b0f898e225675aeba901541dade3f9
parentab79a8a76c6fae9d92b9b0718eee60d60c73ecc8 (diff)
QProgressDialog: make the cancel button retranslate on LanguageChange
It is documented to be, and the LanguageChange event is caught and processed. However, retranslateStrings() uses QProgressDialog::setCancelButtonText(), which unconditionally sets useDefaultCancelText=true, blocking any further changes to the button text by subsequent LanguageChange events. The fix is to use extracted QProgressDialogPrivate::setCancelButtonText() which - quite intentionally - doesn't set useDefaultCancelText. Task-number: QTBUG-40504 Change-Id: I6e701deda10c454cb088c0b0778ac2d6adff574a Reviewed-by: David Faure <david.faure@kdab.com>
-rw-r--r--src/widgets/dialogs/qprogressdialog.cpp3
-rw-r--r--tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp45
2 files changed, 46 insertions, 2 deletions
diff --git a/src/widgets/dialogs/qprogressdialog.cpp b/src/widgets/dialogs/qprogressdialog.cpp
index d160ab0ae1..35a75adea2 100644
--- a/src/widgets/dialogs/qprogressdialog.cpp
+++ b/src/widgets/dialogs/qprogressdialog.cpp
@@ -179,9 +179,8 @@ void QProgressDialogPrivate::layout()
void QProgressDialogPrivate::retranslateStrings()
{
- Q_Q(QProgressDialog);
if (useDefaultCancelText)
- q->setCancelButtonText(QProgressDialog::tr("Cancel"));
+ setCancelButtonText(QProgressDialog::tr("Cancel"));
}
void QProgressDialogPrivate::_q_disconnectOnClose()
diff --git a/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp b/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp
index 4ff158f632..86b9d7eee2 100644
--- a/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp
+++ b/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp
@@ -50,6 +50,7 @@
#include <qlabel.h>
#include <qpointer.h>
#include <qthread.h>
+#include <qtranslator.h>
class tst_QProgressDialog : public QObject
{
@@ -63,6 +64,7 @@ private Q_SLOTS:
void task198202();
void QTBUG_31046();
void settingCustomWidgets();
+ void i18n();
};
void tst_QProgressDialog::cleanup()
@@ -234,5 +236,48 @@ void tst_QProgressDialog::settingCustomWidgets()
#endif
}
+class QTestTranslator : public QTranslator
+{
+ const QString m_str;
+public:
+ explicit QTestTranslator(QString str) : m_str(qMove(str)) {}
+
+ QString translate(const char *, const char *sourceText, const char *, int) const Q_DECL_OVERRIDE
+ { return m_str + sourceText + m_str; }
+
+ bool isEmpty() const Q_DECL_OVERRIDE { return false; }
+};
+
+template <typename Translator>
+class QTranslatorGuard {
+ Translator t;
+public:
+ template <typename Arg>
+ explicit QTranslatorGuard(Arg a) : t(qMove(a))
+ { qApp->installTranslator(&t); }
+ ~QTranslatorGuard()
+ { qApp->removeTranslator(&t); }
+};
+
+void tst_QProgressDialog::i18n()
+{
+ QProgressDialog dlg;
+ QPushButton *btn = dlg.findChild<QPushButton*>();
+ QVERIFY(btn);
+ const QString xxx = QStringLiteral("xxx");
+ {
+ QTranslatorGuard<QTestTranslator> guard(xxx);
+ {
+ QPushButton *btn = dlg.findChild<QPushButton*>();
+ QVERIFY(btn);
+ QTRY_COMPARE(btn->text(), QProgressDialog::tr("Cancel"));
+ QVERIFY(btn->text().startsWith(xxx));
+ }
+ }
+ QVERIFY(btn);
+ QTRY_COMPARE(btn->text(), QProgressDialog::tr("Cancel"));
+ QVERIFY(!btn->text().startsWith(xxx));
+}
+
QTEST_MAIN(tst_QProgressDialog)
#include "tst_qprogressdialog.moc"