From bc6fc26951e6a23a38d91dff2ea93191e2e97c0c Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 26 Jan 2023 11:24:06 +0100 Subject: [PATCH] QtSupport: Remove {Designer,Linguist}ExternalEditorFactory classes ... again, use the editors themselves, which are singletons. Change-Id: I8ec7bce58414a23169831956c00bbdd73c6bfec3 Reviewed-by: Eike Ziller --- src/plugins/qtsupport/externaleditors.cpp | 75 +++++++---------------- src/plugins/qtsupport/externaleditors.h | 14 +++-- src/plugins/qtsupport/qtsupportplugin.cpp | 4 +- 3 files changed, 33 insertions(+), 60 deletions(-) diff --git a/src/plugins/qtsupport/externaleditors.cpp b/src/plugins/qtsupport/externaleditors.cpp index aa55b592849..dff234e760c 100644 --- a/src/plugins/qtsupport/externaleditors.cpp +++ b/src/plugins/qtsupport/externaleditors.cpp @@ -3,8 +3,6 @@ #include "externaleditors.h" -#include - #include #include #include @@ -37,14 +35,10 @@ enum { debug = 0 }; namespace QtSupport::Internal { -struct Tr -{ +struct Tr { Q_DECLARE_TR_FUNCTIONS(::QmakeProjectManager) }; -const char designerDisplayName[] = QT_TRANSLATE_NOOP("OpenWith::Editors", "Qt Designer"); -const char linguistDisplayName[] = QT_TRANSLATE_NOOP("OpenWith::Editors", "Qt Linguist"); - static QString msgStartFailed(const QString &binary, QStringList arguments) { arguments.push_front(binary); @@ -160,28 +154,12 @@ static bool startEditorProcess(const LaunchData &data, QString *errorMessage) // DesignerExternalEditor with Designer Tcp remote control. -class DesignerExternalEditor : public Core::IExternalEditor -{ -public: - DesignerExternalEditor() - { - setId("Qt.Designer"); - setDisplayName(designerDisplayName); - setMimeTypes({ProjectExplorer::Constants::FORM_MIMETYPE}); - } +// A per-binary entry containing the socket +using ProcessCache = QMap; - bool startEditor(const FilePath &filePath, QString *errorMessage) override; +static ProcessCache m_processCache; -private: - void processTerminated(const QString &binary); - - // A per-binary entry containing the socket - using ProcessCache = QMap; - - ProcessCache m_processCache; -}; - -void DesignerExternalEditor::processTerminated(const QString &binary) +static void processTerminated(const QString &binary) { const ProcessCache::iterator it = m_processCache.find(binary); if (it == m_processCache.end()) @@ -196,6 +174,13 @@ void DesignerExternalEditor::processTerminated(const QString &binary) socket->deleteLater(); } +DesignerExternalEditor::DesignerExternalEditor() +{ + setId("Qt.Designer"); + setDisplayName(QT_TRANSLATE_NOOP("OpenWith::Editors", "Qt Designer")); + setMimeTypes({ProjectExplorer::Constants::FORM_MIMETYPE}); +} + bool DesignerExternalEditor::startEditor(const FilePath &filePath, QString *errorMessage) { LaunchData data; @@ -246,19 +231,13 @@ bool DesignerExternalEditor::startEditor(const FilePath &filePath, QString *erro socket->setParent(this); const QString binary = data.binary; m_processCache.insert(binary, socket); - auto mapSlot = [this, binary] { processTerminated(binary); }; + auto mapSlot = [binary] { processTerminated(binary); }; connect(socket, &QAbstractSocket::disconnected, this, mapSlot); connect(socket, &QAbstractSocket::errorOccurred, this, mapSlot); } return true; } -DesignerEditorFactory::DesignerEditorFactory() -{ - auto editor = new DesignerExternalEditor; - editor->setParent(this); -} - // Linguist static QString linguistBinary(const QtSupport::QtVersion *qtVersion) @@ -268,28 +247,18 @@ static QString linguistBinary(const QtSupport::QtVersion *qtVersion) return QLatin1String(HostOsInfo::isMacHost() ? "Linguist" : "linguist"); } -class LinguistEditor : public Core::IExternalEditor +LinguistEditor::LinguistEditor() { -public: - LinguistEditor() - { - setId("Qt.Linguist"); - setDisplayName(linguistDisplayName); - setMimeTypes({ProjectExplorer::Constants::LINGUIST_MIMETYPE}); - } + setId("Qt.Linguist"); + setDisplayName(QT_TRANSLATE_NOOP("OpenWith::Editors", "Qt Linguist")); + setMimeTypes({ProjectExplorer::Constants::LINGUIST_MIMETYPE}); +} - bool startEditor(const FilePath &filePath, QString *errorMessage) override - { - LaunchData data; - return getEditorLaunchData(linguistBinary, filePath, &data, errorMessage) - && startEditorProcess(data, errorMessage); - } -}; - -LinguistEditorFactory::LinguistEditorFactory() +bool LinguistEditor::startEditor(const Utils::FilePath &filePath, QString *errorMessage) { - auto editor = new LinguistEditor; - editor->setParent(this); + LaunchData data; + return getEditorLaunchData(linguistBinary, filePath, &data, errorMessage) + && startEditorProcess(data, errorMessage); } } // QtSupport::Internal diff --git a/src/plugins/qtsupport/externaleditors.h b/src/plugins/qtsupport/externaleditors.h index ae6ab904fdc..14fd2ea2272 100644 --- a/src/plugins/qtsupport/externaleditors.h +++ b/src/plugins/qtsupport/externaleditors.h @@ -3,20 +3,24 @@ #pragma once -#include +#include namespace QtSupport::Internal { -class DesignerEditorFactory : public QObject +class DesignerExternalEditor : public Core::IExternalEditor { public: - DesignerEditorFactory(); + DesignerExternalEditor(); + + bool startEditor(const Utils::FilePath &filePath, QString *errorMessage) final; }; -class LinguistEditorFactory : public QObject +class LinguistEditor : public Core::IExternalEditor { public: - LinguistEditorFactory(); + LinguistEditor(); + + bool startEditor(const Utils::FilePath &filePath, QString *errorMessage) final; }; } // QtSupport::Internal diff --git a/src/plugins/qtsupport/qtsupportplugin.cpp b/src/plugins/qtsupport/qtsupportplugin.cpp index e07b2a5317c..c54c1bfc232 100644 --- a/src/plugins/qtsupport/qtsupportplugin.cpp +++ b/src/plugins/qtsupport/qtsupportplugin.cpp @@ -63,8 +63,8 @@ public: UicGeneratorFactory uicGeneratorFactory; QScxmlcGeneratorFactory qscxmlcGeneratorFactory; - DesignerEditorFactory designerEditorFactory; - LinguistEditorFactory linguistEditorFactory; + DesignerExternalEditor designerEditor; + LinguistEditor linguistEditor; }; QtSupportPlugin::~QtSupportPlugin()