forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user