diff options
author | hjk <hjk@qt.io> | 2017-12-15 15:46:37 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2017-12-18 15:39:51 +0000 |
commit | 479ab4ef22e8810f059307b9eca68b79893db7a4 (patch) | |
tree | 31a9eb3710868f2a2619576af949c97866c15c6b /src/plugins/qmljseditor | |
parent | 4ed12d95f83a50d6020270b85718b446604df7f2 (diff) | |
download | qt-creator-479ab4ef22e8810f059307b9eca68b79893db7a4.tar.gz |
TextEditor: Split the global QuickFixFactory list
It's only ever used in the filtered Cpp/QmlJs variants. Splitting
the class simplifies the code and avoids re-doing filtering over
and over again.
Also inline QuickFixFactory::matchingOperations() into callers
Change-Id: I730756315f2e0321649259ef229631233b12fbdd
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/qmljseditor')
-rw-r--r-- | src/plugins/qmljseditor/qmljsquickfix.cpp | 7 | ||||
-rw-r--r-- | src/plugins/qmljseditor/qmljsquickfix.h | 9 | ||||
-rw-r--r-- | src/plugins/qmljseditor/qmljsquickfixassist.cpp | 24 |
3 files changed, 24 insertions, 16 deletions
diff --git a/src/plugins/qmljseditor/qmljsquickfix.cpp b/src/plugins/qmljseditor/qmljsquickfix.cpp index 926cf4a476..c6c1db2d0b 100644 --- a/src/plugins/qmljseditor/qmljsquickfix.cpp +++ b/src/plugins/qmljseditor/qmljsquickfix.cpp @@ -71,11 +71,4 @@ QString QmlJSQuickFixOperation::fileName() const return m_interface->semanticInfo().document->fileName(); } - -void QmlJSQuickFixFactory::matchingOperations(const QuickFixInterface &interface, - QuickFixOperations &result) -{ - match(interface.staticCast<const QmlJSQuickFixAssistInterface>(), result); -} - } // namespace QmlJSEditor diff --git a/src/plugins/qmljseditor/qmljsquickfix.h b/src/plugins/qmljseditor/qmljsquickfix.h index fda4a25a48..18e09f3d92 100644 --- a/src/plugins/qmljseditor/qmljsquickfix.h +++ b/src/plugins/qmljseditor/qmljsquickfix.h @@ -76,14 +76,13 @@ private: QmlJSQuickFixInterface m_interface; }; -class QmlJSQuickFixFactory: public TextEditor::QuickFixFactory +class QmlJSQuickFixFactory: public QObject { Q_OBJECT -protected: - QmlJSQuickFixFactory() {} - - void matchingOperations(const QuickFixInterface &interface, QuickFixOperations &result); +public: + QmlJSQuickFixFactory(); + ~QmlJSQuickFixFactory(); /*! Implement this function to match and create the appropriate diff --git a/src/plugins/qmljseditor/qmljsquickfixassist.cpp b/src/plugins/qmljseditor/qmljsquickfixassist.cpp index 52a23a43fa..9d3fa6e732 100644 --- a/src/plugins/qmljseditor/qmljsquickfixassist.cpp +++ b/src/plugins/qmljseditor/qmljsquickfixassist.cpp @@ -43,7 +43,23 @@ namespace QmlJSEditor { using namespace Internal; // ----------------------- -// QuickFixAssistInterface +// QmlJSQuickFixFactory +// ----------------------- + +static QList<QmlJSQuickFixFactory *> g_qmlJSQuickFixFactories; + +QmlJSQuickFixFactory::QmlJSQuickFixFactory() +{ + g_qmlJSQuickFixFactories.append(this); +} + +QmlJSQuickFixFactory::~QmlJSQuickFixFactory() +{ + g_qmlJSQuickFixFactories.removeOne(this); +} + +// ----------------------- +// QmlJSQuickFixAssistInterface // ----------------------- QmlJSQuickFixAssistInterface::QmlJSQuickFixAssistInterface(QmlJSEditorWidget *editor, AssistReason reason) @@ -74,12 +90,12 @@ class QmlJSQuickFixAssistProcessor : public IAssistProcessor IAssistProposal *perform(const AssistInterface *interface) override { QSharedPointer<const AssistInterface> assistInterface(interface); + auto qmlJSInterface = assistInterface.staticCast<const QmlJSQuickFixAssistInterface>(); QuickFixOperations quickFixes; - for (QuickFixFactory *factory : QuickFixFactory::allQuickFixFactories()) - if (qobject_cast<QmlJSQuickFixFactory *>(factory) != nullptr) - factory->matchingOperations(assistInterface, quickFixes); + for (QmlJSQuickFixFactory *factory : g_qmlJSQuickFixFactories) + factory->match(qmlJSInterface, quickFixes); return GenericProposal::createProposal(interface, quickFixes); } |