diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2016-03-03 12:53:06 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2016-03-04 16:08:01 +0000 |
commit | cb3086376fce460aa85b542d487d26b2506875f7 (patch) | |
tree | b81febecca91e2c8040e9f43a313ed697320c3ba | |
parent | 360f708326ed53285d0d65c0e9db9a3fcb4219ac (diff) |
QTextToSpeech: QObject *parent ctor args go last
This is one of the deepest and most long-standing
Qt API design patterns: subclasses add ctor args
_at the front_, not at the back.
To compensate the slight SC breakage, add an
overloaded ctor that only takes QObject *parent
(also a Qt API pattern worth following), so the
common case of
new QTextToSpeech(this)
continues to work.
Change-Id: I7253abada1355e53e9817914abd80e8af17ce429
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Reviewed-by: Jeremy Whiting <jpwhiting@kde.org>
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@theqtcompany.com>
-rw-r--r-- | examples/speech/hello_speak/mainwindow.cpp | 2 | ||||
-rw-r--r-- | src/tts/qtexttospeech.cpp | 25 | ||||
-rw-r--r-- | src/tts/qtexttospeech.h | 3 |
3 files changed, 26 insertions, 4 deletions
diff --git a/examples/speech/hello_speak/mainwindow.cpp b/examples/speech/hello_speak/mainwindow.cpp index b496cda..6f2f300 100644 --- a/examples/speech/hello_speak/mainwindow.cpp +++ b/examples/speech/hello_speak/mainwindow.cpp @@ -103,7 +103,7 @@ void MainWindow::engineSelected(int index) if (engineName == "default") m_speech = new QTextToSpeech(this); else - m_speech = new QTextToSpeech(this, engineName); + m_speech = new QTextToSpeech(engineName, QVariantMap(), this); disconnect(ui.language, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &MainWindow::languageSelected); ui.language->clear(); // Populate the languages combobox before connecting its signal. diff --git a/src/tts/qtexttospeech.cpp b/src/tts/qtexttospeech.cpp index 7157318..0fe752e 100644 --- a/src/tts/qtexttospeech.cpp +++ b/src/tts/qtexttospeech.cpp @@ -59,6 +59,7 @@ QTextToSpeechPrivate::QTextToSpeechPrivate(QTextToSpeech *speech, const QString m_providerName(engine), m_plugin(0) { + qRegisterMetaType<QTextToSpeech::State>(); if (m_providerName.isEmpty()) { m_providerName = QTextToSpeech::availableEngines().value(0); if (m_providerName.isEmpty()) { @@ -185,6 +186,27 @@ void QTextToSpeechPrivate::loadPluginMetadata(QHash<QString, QJsonObject> &list) */ /*! + Loads a text-to-speech engine from a plug-in that uses the default + engine plug-in and constructs a QTextToSpeech object as the child + of \a parent. + + The default engine may be platform-specific. + + If loading the plug-in fails, QTextToSpeech::state() will return + QTextToSpeech::BackendError. + + \sa availableEngines() +*/ +QTextToSpeech::QTextToSpeech(QObject *parent) + : QObject(*new QTextToSpeechPrivate(this, QString(), QVariantMap()), parent) +{ + Q_D(QTextToSpeech); + // Connect state change signal directly from the engine to the public API signal + if (d->m_engine) + connect(d->m_engine, &QTextToSpeechEngine::stateChanged, this, &QTextToSpeech::stateChanged); +} + +/*! Loads a text-to-speech engine from a plug-in that matches parameter \a engine and constructs a QTextToSpeech object as the child of \a parent. @@ -197,11 +219,10 @@ void QTextToSpeechPrivate::loadPluginMetadata(QHash<QString, QJsonObject> &list) \sa availableEngines() */ -QTextToSpeech::QTextToSpeech(QObject *parent, const QString &engine, const QVariantMap ¶meters) +QTextToSpeech::QTextToSpeech(const QString &engine, const QVariantMap ¶meters, QObject *parent) : QObject(*new QTextToSpeechPrivate(this, engine, parameters), parent) { Q_D(QTextToSpeech); - qRegisterMetaType<QTextToSpeech::State>(); // Connect state change signal directly from the engine to the public API signal if (d->m_engine) connect(d->m_engine, &QTextToSpeechEngine::stateChanged, this, &QTextToSpeech::stateChanged); diff --git a/src/tts/qtexttospeech.h b/src/tts/qtexttospeech.h index bcbe511..bd35c8f 100644 --- a/src/tts/qtexttospeech.h +++ b/src/tts/qtexttospeech.h @@ -70,7 +70,8 @@ public: BackendError }; - explicit QTextToSpeech(QObject *parent = 0, const QString &engine = QString(), const QVariantMap ¶meters = QVariantMap()); + explicit QTextToSpeech(QObject *parent = Q_NULLPTR); + explicit QTextToSpeech(const QString &engine, const QVariantMap ¶meters = QVariantMap(), QObject *parent = Q_NULLPTR); State state() const; QVector<QLocale> availableLocales() const; |