diff options
author | Tim Jenssen <tim.jenssen@qt.io> | 2023-09-14 17:25:47 +0200 |
---|---|---|
committer | Tim Jenssen <tim.jenssen@qt.io> | 2023-09-14 17:37:24 +0200 |
commit | 1a3a8ecc96542d6556baac373c8f8d8de5c68325 (patch) | |
tree | ae2bdce03596e8c6461c55de791720531d9c8e91 /src/plugins/qmlpreview | |
parent | 93273af6dc2ee18c5748bd267628ce3d6cff2d5f (diff) | |
parent | 3473d9d3887ef6851797eec248352ced4d4b4857 (diff) |
Merge remote-tracking branch 'origin/qds/dev'
Change-Id: Id242ab4ca485527defdcc1555d204e12e50ddb7a
Diffstat (limited to 'src/plugins/qmlpreview')
-rw-r--r-- | src/plugins/qmlpreview/CMakeLists.txt | 18 | ||||
-rw-r--r-- | src/plugins/qmlpreview/qmldebugtranslationclient.cpp | 7 | ||||
-rw-r--r-- | src/plugins/qmlpreview/qmlpreviewconnectionmanager.cpp | 4 | ||||
-rw-r--r-- | src/plugins/qmlpreview/qmlpreviewconnectionmanager.h | 6 | ||||
-rw-r--r-- | src/plugins/qmlpreview/qmlpreviewfileontargetfinder.cpp | 2 | ||||
-rw-r--r-- | src/plugins/qmlpreview/qmlpreviewfileontargetfinder.h | 2 | ||||
-rw-r--r-- | src/plugins/qmlpreview/qmlpreviewplugin.cpp | 20 | ||||
-rw-r--r-- | src/plugins/qmlpreview/qmlpreviewplugin.h | 7 | ||||
-rw-r--r-- | src/plugins/qmlpreview/qmlpreviewruncontrol.cpp | 48 | ||||
-rw-r--r-- | src/plugins/qmlpreview/qmlpreviewruncontrol.h | 4 |
10 files changed, 71 insertions, 47 deletions
diff --git a/src/plugins/qmlpreview/CMakeLists.txt b/src/plugins/qmlpreview/CMakeLists.txt index 40114a7e47..4c1889143a 100644 --- a/src/plugins/qmlpreview/CMakeLists.txt +++ b/src/plugins/qmlpreview/CMakeLists.txt @@ -1,7 +1,7 @@ add_qtc_plugin(QmlPreview CONDITION TARGET QmlProjectManager PUBLIC_DEPENDS QmlDebug - DEPENDS QmlJS + DEPENDS QmlJS Qt::QmlPrivate PLUGIN_DEPENDS Core ProjectExplorer QmlJSTools QtSupport ResourceEditor QmlProjectManager @@ -22,19 +22,3 @@ extend_qtc_plugin(QmlPreview tests/qmlpreviewclient_test.cpp tests/qmlpreviewclient_test.h tests/qmlpreviewplugin_test.cpp tests/qmlpreviewplugin_test.h ) - -if(TARGET Qt6::QmlPrivate) - get_target_property(qmldebugprivate_include_directories - Qt6::QmlPrivate - INTERFACE_INCLUDE_DIRECTORIES - ) - find_file(have_qml_debug_translation_protocol - NAMES private/qqmldebugtranslationprotocol_p.h - PATHS ${qmldebugprivate_include_directories} - ) - extend_qtc_plugin(QmlPreview - CONDITION have_qml_debug_translation_protocol - PUBLIC_DEPENDS Qt::QmlPrivate - PUBLIC_DEFINES "FOUND_QML_DEBUG_TRANSLATION_PROTOCOL" - ) -endif() diff --git a/src/plugins/qmlpreview/qmldebugtranslationclient.cpp b/src/plugins/qmlpreview/qmldebugtranslationclient.cpp index d0cfc2d96e..fc3018018e 100644 --- a/src/plugins/qmlpreview/qmldebugtranslationclient.cpp +++ b/src/plugins/qmlpreview/qmldebugtranslationclient.cpp @@ -6,9 +6,7 @@ #include <QUrl> -#ifdef FOUND_QML_DEBUG_TRANSLATION_PROTOCOL #include <private/qqmldebugtranslationprotocol_p.h> -#endif namespace QmlPreview { @@ -20,14 +18,9 @@ QmlDebugTranslationClient::QmlDebugTranslationClient(QmlDebug::QmlDebugConnectio void QmlDebugTranslationClient::changeLanguage(const QUrl &url, const QString &localeIsoCode) { QmlDebug::QPacket packet(dataStreamVersion()); -#ifdef FOUND_QML_DEBUG_TRANSLATION_PROTOCOL - sendMessage(QQmlDebugTranslation::createChangeLanguageRequest(packet, url, localeIsoCode)); -#else const int request_change_language = 1; packet << request_change_language << url << localeIsoCode; sendMessage(packet.data()); -#endif - } void QmlDebugTranslationClient::stateChanged(QmlDebug::QmlDebugClient::State state) diff --git a/src/plugins/qmlpreview/qmlpreviewconnectionmanager.cpp b/src/plugins/qmlpreview/qmlpreviewconnectionmanager.cpp index 358991f2ba..9b27047859 100644 --- a/src/plugins/qmlpreview/qmlpreviewconnectionmanager.cpp +++ b/src/plugins/qmlpreview/qmlpreviewconnectionmanager.cpp @@ -12,7 +12,6 @@ #include <QMessageBox> namespace QmlPreview { -namespace Internal { QmlPreviewConnectionManager::QmlPreviewConnectionManager(QObject *parent) : QmlDebug::QmlDebugConnectionManager(parent) @@ -44,7 +43,7 @@ void QmlPreviewConnectionManager::setFpsHandler(QmlPreviewFpsHandler fpsHandler) m_fpsHandler = fpsHandler; } -void QmlPreviewConnectionManager::setQmlDebugTranslationClientCreator(QmlDebugTranslationClientCreator creator) +void QmlPreviewConnectionManager::setQmlDebugTranslationClientCreator(QmlDebugTranslationClientFactoryFunction creator) { m_createDebugTranslationClientMethod = creator; } @@ -249,5 +248,4 @@ void QmlPreviewConnectionManager::destroyClients() m_fileSystemWatcher.clear(); } -} // namespace Internal } // namespace QmlPreview diff --git a/src/plugins/qmlpreview/qmlpreviewconnectionmanager.h b/src/plugins/qmlpreview/qmlpreviewconnectionmanager.h index d965d4216a..6ce92f99ff 100644 --- a/src/plugins/qmlpreview/qmlpreviewconnectionmanager.h +++ b/src/plugins/qmlpreview/qmlpreviewconnectionmanager.h @@ -17,7 +17,6 @@ class Target; } namespace QmlPreview { -namespace Internal { class QmlPreviewConnectionManager : public QmlDebug::QmlDebugConnectionManager { @@ -30,7 +29,7 @@ public: void setFileLoader(QmlPreviewFileLoader fileLoader); void setFileClassifier(QmlPreviewFileClassifier fileClassifier); void setFpsHandler(QmlPreviewFpsHandler fpsHandler); - void setQmlDebugTranslationClientCreator(QmlDebugTranslationClientCreator creator); + void setQmlDebugTranslationClientCreator(QmlDebugTranslationClientFactoryFunction creator); signals: void loadFile(const QString &filename, const QString &changedFile, const QByteArray &contents); @@ -58,8 +57,7 @@ private: QmlPreviewFileLoader m_fileLoader = nullptr; QmlPreviewFileClassifier m_fileClassifier = nullptr; QmlPreviewFpsHandler m_fpsHandler = nullptr; - QmlDebugTranslationClientCreator m_createDebugTranslationClientMethod; + QmlDebugTranslationClientFactoryFunction m_createDebugTranslationClientMethod; }; -} // namespace Internal } // namespace QmlPreview diff --git a/src/plugins/qmlpreview/qmlpreviewfileontargetfinder.cpp b/src/plugins/qmlpreview/qmlpreviewfileontargetfinder.cpp index d1d9b4fced..146195dc27 100644 --- a/src/plugins/qmlpreview/qmlpreviewfileontargetfinder.cpp +++ b/src/plugins/qmlpreview/qmlpreviewfileontargetfinder.cpp @@ -14,7 +14,6 @@ #include <utils/qtcassert.h> namespace QmlPreview { -namespace Internal { void QmlPreviewFileOnTargetFinder::setTarget(ProjectExplorer::Target *target) { @@ -96,5 +95,4 @@ QUrl QmlPreviewFileOnTargetFinder::findUrl(const QString &filePath, bool *succes } } -} // namespace Internal } // namespace QmlPreview diff --git a/src/plugins/qmlpreview/qmlpreviewfileontargetfinder.h b/src/plugins/qmlpreview/qmlpreviewfileontargetfinder.h index 4ab4a5a4a8..c0873ebe71 100644 --- a/src/plugins/qmlpreview/qmlpreviewfileontargetfinder.h +++ b/src/plugins/qmlpreview/qmlpreviewfileontargetfinder.h @@ -12,7 +12,6 @@ class Target; } namespace QmlPreview { -namespace Internal { class QmlPreviewFileOnTargetFinder { @@ -27,5 +26,4 @@ private: QPointer<ProjectExplorer::Target> m_target; }; -} // namespace Internal } // namespace QmlPreview diff --git a/src/plugins/qmlpreview/qmlpreviewplugin.cpp b/src/plugins/qmlpreview/qmlpreviewplugin.cpp index 550af3a6a9..9d05d0ee39 100644 --- a/src/plugins/qmlpreview/qmlpreviewplugin.cpp +++ b/src/plugins/qmlpreview/qmlpreviewplugin.cpp @@ -44,6 +44,7 @@ #include <android/androidconstants.h> #include <QAction> +#include <QPointer> #include <QTimer> using namespace ProjectExplorer; @@ -95,6 +96,9 @@ static std::unique_ptr<QmlDebugTranslationClient> defaultCreateDebugTranslationC return client; } +static void defaultRefreshTranslationFunction() +{} + class QmlPreviewPluginPrivate : public QObject { public: @@ -127,7 +131,7 @@ public: QmlPreviewPlugin *q = nullptr; QThread m_parseThread; QString m_previewedFile; - Core::IEditor *m_lastEditor = nullptr; + QPointer<Core::IEditor> m_lastEditor; QmlPreviewRunControlList m_runningPreviews; bool m_dirty = false; QString m_localeIsoCode; @@ -145,6 +149,7 @@ QmlPreviewPluginPrivate::QmlPreviewPluginPrivate(QmlPreviewPlugin *parent) m_settings.fileClassifier = &defaultFileClassifier; m_settings.fpsHandler = &defaultFpsHandler; m_settings.createDebugTranslationClientMethod = &defaultCreateDebugTranslationClientMethod; + m_settings.refreshTranslationsFunction = &defaultRefreshTranslationFunction; Core::ActionContainer *menu = Core::ActionManager::actionContainer( Constants::M_BUILDPROJECT); @@ -236,6 +241,12 @@ QmlPreviewRunControlList QmlPreviewPlugin::runningPreviews() const return d->m_runningPreviews; } +void QmlPreviewPlugin::stopAllPreviews() +{ + for (auto &runningPreview : d->m_runningPreviews) + runningPreview->initiateStop(); +} + QmlPreviewFileLoader QmlPreviewPlugin::fileLoader() const { return d->m_settings.fileLoader; @@ -299,11 +310,16 @@ void QmlPreviewPlugin::setLocaleIsoCode(const QString &localeIsoCode) emit localeIsoCodeChanged(d->m_localeIsoCode); } -void QmlPreviewPlugin::setQmlDebugTranslationClientCreator(QmlDebugTranslationClientCreator creator) +void QmlPreviewPlugin::setQmlDebugTranslationClientCreator(QmlDebugTranslationClientFactoryFunction creator) { d->m_settings.createDebugTranslationClientMethod = creator; } +void QmlPreviewPlugin::setRefreshTranslationsFunction(QmlPreviewRefreshTranslationFunction refreshTranslationsFunction) +{ + d->m_settings.refreshTranslationsFunction = refreshTranslationsFunction; +} + void QmlPreviewPlugin::setFileLoader(QmlPreviewFileLoader fileLoader) { if (d->m_settings.fileLoader == fileLoader) diff --git a/src/plugins/qmlpreview/qmlpreviewplugin.h b/src/plugins/qmlpreview/qmlpreviewplugin.h index 15a5d3e181..30f0eb54f4 100644 --- a/src/plugins/qmlpreview/qmlpreviewplugin.h +++ b/src/plugins/qmlpreview/qmlpreviewplugin.h @@ -25,8 +25,9 @@ using QmlPreviewFileClassifier = bool (*)(const QString &); using QmlPreviewFileLoader = QByteArray (*)(const QString &, bool *); using QmlPreviewFpsHandler = void (*)(quint16[8]); using QmlPreviewRunControlList = QList<ProjectExplorer::RunControl *>; -using QmlDebugTranslationClientCreator = +using QmlDebugTranslationClientFactoryFunction = std::function<std::unique_ptr<QmlDebugTranslationClient>(QmlDebug::QmlDebugConnection *)>; +using QmlPreviewRefreshTranslationFunction = std::function<void ()>; class QMLPREVIEW_EXPORT QmlPreviewPlugin : public ExtensionSystem::IPlugin { @@ -54,6 +55,7 @@ public: QString previewedFile() const; void setPreviewedFile(const QString &previewedFile); QmlPreviewRunControlList runningPreviews() const; + void stopAllPreviews(); void setFileLoader(QmlPreviewFileLoader fileLoader); QmlPreviewFileLoader fileLoader() const; @@ -70,7 +72,8 @@ public: QString localeIsoCode() const; void setLocaleIsoCode(const QString &localeIsoCode); - void setQmlDebugTranslationClientCreator(QmlDebugTranslationClientCreator creator); + void setQmlDebugTranslationClientCreator(QmlDebugTranslationClientFactoryFunction creator); + void setRefreshTranslationsFunction(QmlPreviewRefreshTranslationFunction refreshTranslationsFunction); void previewCurrentFile(); void addPreview(ProjectExplorer::RunControl *preview); diff --git a/src/plugins/qmlpreview/qmlpreviewruncontrol.cpp b/src/plugins/qmlpreview/qmlpreviewruncontrol.cpp index 19bf396ce7..2857c15fbb 100644 --- a/src/plugins/qmlpreview/qmlpreviewruncontrol.cpp +++ b/src/plugins/qmlpreview/qmlpreviewruncontrol.cpp @@ -13,22 +13,54 @@ #include <projectexplorer/target.h> #include <qmldebug/qmldebugcommandlinearguments.h> +#include <qmlprojectmanager/qmlmultilanguageaspect.h> #include <qtsupport/baseqtversion.h> #include <qtsupport/qtkitaspect.h> +#include <utils/async.h> #include <utils/filepath.h> #include <utils/port.h> #include <utils/process.h> #include <utils/url.h> +#include <QFutureWatcher> + using namespace ProjectExplorer; using namespace Utils; -using namespace QmlPreview::Internal; namespace QmlPreview { static const Key QmlServerUrl = "QmlServerUrl"; +class RefreshTranslationWorker final : public ProjectExplorer::RunWorker +{ +public: + explicit RefreshTranslationWorker(ProjectExplorer::RunControl *runControl, + const QmlPreviewRunnerSetting &runnerSettings) + : ProjectExplorer::RunWorker(runControl), m_runnerSettings(runnerSettings) + { + setId("RefreshTranslationWorker"); + connect(this, &RunWorker::started, this, &RefreshTranslationWorker::startRefreshTranslationsAsync); + connect(this, &RunWorker::stopped, &m_futureWatcher, &QFutureWatcher<void>::cancel); + } + ~RefreshTranslationWorker() + { + m_futureWatcher.cancel(); + m_futureWatcher.waitForFinished(); + } + +private: + void startRefreshTranslationsAsync() + { + m_futureWatcher.setFuture(Utils::asyncRun([this] { + m_runnerSettings.refreshTranslationsFunction(); + stop(); + })); + } + QmlPreviewRunnerSetting m_runnerSettings; + QFutureWatcher<void> m_futureWatcher; +}; + class QmlPreviewRunner : public ProjectExplorer::RunWorker { Q_OBJECT @@ -51,11 +83,12 @@ private: void start() override; void stop() override; - Internal::QmlPreviewConnectionManager m_connectionManager; + QmlPreviewConnectionManager m_connectionManager; + RefreshTranslationWorker m_refreshTranslationWorker; }; QmlPreviewRunner::QmlPreviewRunner(RunControl *runControl, const QmlPreviewRunnerSetting &settings) - : RunWorker(runControl) + : RunWorker(runControl), m_refreshTranslationWorker(runControl, settings) { setId("QmlPreviewRunner"); m_connectionManager.setFileLoader(settings.fileLoader); @@ -78,9 +111,10 @@ QmlPreviewRunner::QmlPreviewRunner(RunControl *runControl, const QmlPreviewRunne this, [this, settings]() { if (settings.zoomFactor > 0) emit zoom(settings.zoomFactor); - if (!settings.language.isEmpty()) - emit language(settings.language); - + if (auto multiLanguageAspect = QmlProjectManager::QmlMultiLanguageAspect::current()) { + if (!multiLanguageAspect->currentLocale().isEmpty()) + emit language(multiLanguageAspect->currentLocale()); + } emit ready(); }); @@ -99,6 +133,8 @@ QmlPreviewRunner::QmlPreviewRunner(RunControl *runControl, const QmlPreviewRunne runControl->initiateStop(); }); + + addStartDependency(&m_refreshTranslationWorker); } void QmlPreviewRunner::start() diff --git a/src/plugins/qmlpreview/qmlpreviewruncontrol.h b/src/plugins/qmlpreview/qmlpreviewruncontrol.h index 371ac180f6..d1fbdb88d1 100644 --- a/src/plugins/qmlpreview/qmlpreviewruncontrol.h +++ b/src/plugins/qmlpreview/qmlpreviewruncontrol.h @@ -15,8 +15,8 @@ struct QmlPreviewRunnerSetting QmlPreviewFileClassifier fileClassifier; QmlPreviewFpsHandler fpsHandler; float zoomFactor = -1.0; - QString language; - QmlDebugTranslationClientCreator createDebugTranslationClientMethod; + QmlDebugTranslationClientFactoryFunction createDebugTranslationClientMethod; + QmlPreviewRefreshTranslationFunction refreshTranslationsFunction; }; class QmlPreviewRunWorkerFactory final : public ProjectExplorer::RunWorkerFactory |