diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index 39e4d7575b0896ad20a08e47c4ce3abad416ca14..49b6687d206a6f81c64b2acc91db39c2deca5038 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -43,7 +43,6 @@ #include <cpptools/cpptoolsconstants.h> #include <cpptools/cppchecksymbols.h> #include <cpptools/cppcodeformatter.h> -#include <cpptools/cppcompletionsupport.h> #include <cpptools/cppcompletionassistprovider.h> #include <cpptools/cpphighlightingsupport.h> #include <cpptools/cpplocalsymbols.h> @@ -511,7 +510,6 @@ CPPEditorWidget::CPPEditorWidget(QWidget *parent) , m_firstRenameChange(false) , m_objcEnabled(false) , m_commentsSettings(CppTools::CppToolsSettings::instance()->commentsSettings()) - , m_completionSupport(0) { qRegisterMetaType<SemanticInfo>("CppTools::SemanticInfo"); @@ -532,8 +530,6 @@ CPPEditorWidget::CPPEditorWidget(QWidget *parent) this, SLOT(updateSemanticInfo(CppTools::SemanticInfo))); connect(editorSupport, SIGNAL(highlighterStarted(QFuture<TextEditor::HighlightingResult>*,uint)), this, SLOT(highlighterStarted(QFuture<TextEditor::HighlightingResult>*,uint))); - - m_completionSupport = m_modelManager->completionSupport(editor()); } m_highlightRevision = 0; @@ -563,8 +559,6 @@ CPPEditorWidget::~CPPEditorWidget() { if (m_modelManager) m_modelManager->deleteCppEditorSupport(editor()); - - delete m_completionSupport; } TextEditor::BaseTextEditor *CPPEditorWidget::createEditor() @@ -2111,10 +2105,12 @@ TextEditor::IAssistInterface *CPPEditorWidget::createAssistInterface( TextEditor::AssistReason reason) const { if (kind == TextEditor::Completion) { - if (m_completionSupport) - return m_completionSupport->createAssistInterface( + CppEditorSupport *ces = CppModelManagerInterface::instance()->cppEditorSupport(editor()); + CppCompletionAssistProvider *cap = ces->completionAssistProvider(); + if (cap) + return cap->createAssistInterface( ProjectExplorer::ProjectExplorerPlugin::currentProject(), - document(), position(), reason); + editor()->document()->filePath(), document(), position(), reason); } else if (kind == TextEditor::QuickFix) { if (!semanticInfo().doc || isOutdated()) return 0; diff --git a/src/plugins/cppeditor/cppeditor.h b/src/plugins/cppeditor/cppeditor.h index 5bc92c91969f1d9d1aa2b3b83c6ca80f42925775..5573df9cc308e4294fa90d4a3dac2f9b531c1c5e 100644 --- a/src/plugins/cppeditor/cppeditor.h +++ b/src/plugins/cppeditor/cppeditor.h @@ -262,8 +262,6 @@ private: QSharedPointer<FunctionDeclDefLink> m_declDefLink; CppTools::CommentsSettings m_commentsSettings; - - CppTools::CppCompletionSupport *m_completionSupport; }; } // namespace Internal diff --git a/src/plugins/cpptools/cppcompletionassist.cpp b/src/plugins/cpptools/cppcompletionassist.cpp index c5a7b1a7bf3d776f19de370b8cc763632818c90d..3ad517e6502b077236968eec20f7118e2ac9496d 100644 --- a/src/plugins/cpptools/cppcompletionassist.cpp +++ b/src/plugins/cpptools/cppcompletionassist.cpp @@ -416,44 +416,25 @@ IAssistProcessor *InternalCompletionAssistProvider::createProcessor() const return new CppCompletionAssistProcessor; } -namespace { -class CppCompletionSupportInternal: public CppCompletionSupport +TextEditor::IAssistInterface *InternalCompletionAssistProvider::createAssistInterface( + ProjectExplorer::Project *project, const QString &filePath, QTextDocument *document, + int position, TextEditor::AssistReason reason) const { -public: - CppCompletionSupportInternal(TextEditor::ITextEditor *editor) - : CppCompletionSupport(editor) - {} - - virtual ~CppCompletionSupportInternal() - {} - - virtual TextEditor::IAssistInterface *createAssistInterface(ProjectExplorer::Project *project, - QTextDocument *document, - int position, - TextEditor::AssistReason reason) const - { - CppModelManagerInterface *modelManager = CppModelManagerInterface::instance(); - QStringList includePaths; - QStringList frameworkPaths; - if (project) { - includePaths = modelManager->projectInfo(project).includePaths(); - frameworkPaths = modelManager->projectInfo(project).frameworkPaths(); - } - return new CppTools::Internal::CppCompletionAssistInterface( - document, - position, - editor()->document()->filePath(), - reason, - modelManager->snapshot(), - includePaths, - frameworkPaths); + CppModelManagerInterface *modelManager = CppModelManagerInterface::instance(); + QStringList includePaths; + QStringList frameworkPaths; + if (project) { + includePaths = modelManager->projectInfo(project).includePaths(); + frameworkPaths = modelManager->projectInfo(project).frameworkPaths(); } -}; -} - -CppCompletionSupport *InternalCompletionAssistProvider::completionSupport(ITextEditor *editor) -{ - return new CppCompletionSupportInternal(editor); + return new CppTools::Internal::CppCompletionAssistInterface( + document, + position, + filePath, + reason, + modelManager->snapshot(), + includePaths, + frameworkPaths); } // ----------------- diff --git a/src/plugins/cpptools/cppcompletionassist.h b/src/plugins/cpptools/cppcompletionassist.h index 0515ce0804d3753562beae63013f1b04b87b5832..a78777a86373d77ee5bc72553091374e863a229b 100644 --- a/src/plugins/cpptools/cppcompletionassist.h +++ b/src/plugins/cpptools/cppcompletionassist.h @@ -89,7 +89,11 @@ class InternalCompletionAssistProvider : public CppCompletionAssistProvider public: virtual TextEditor::IAssistProcessor *createProcessor() const; - virtual CppCompletionSupport *completionSupport(TextEditor::ITextEditor *editor); + + virtual TextEditor::IAssistInterface *createAssistInterface( + ProjectExplorer::Project *project, const QString &filePath, QTextDocument *document, + int position, TextEditor::AssistReason reason) const; + }; class CppCompletionAssistProcessor : public TextEditor::IAssistProcessor diff --git a/src/plugins/cpptools/cppcompletionassistprovider.h b/src/plugins/cpptools/cppcompletionassistprovider.h index b9739e36480a216282f4c7a37f8921e9fe3c2e7a..e45b20946fb387462e1cddeb1c493d1267db3ecf 100644 --- a/src/plugins/cpptools/cppcompletionassistprovider.h +++ b/src/plugins/cpptools/cppcompletionassistprovider.h @@ -30,11 +30,23 @@ #ifndef CPPTOOLS_CPPCOMPLETIONASSISTPROVIDER_H #define CPPTOOLS_CPPCOMPLETIONASSISTPROVIDER_H -#include "cppcompletionsupport.h" #include "cpptools_global.h" +#include <texteditor/codeassist/assistenums.h> #include <texteditor/codeassist/completionassistprovider.h> +QT_BEGIN_NAMESPACE +class QTextDocument; +QT_END_NAMESPACE + +namespace ProjectExplorer { +class Project; +} + +namespace TextEditor { +class IAssistInterface; +} + namespace CppTools { class CPPTOOLS_EXPORT CppCompletionAssistProvider : public TextEditor::CompletionAssistProvider @@ -46,7 +58,9 @@ public: virtual int activationCharSequenceLength() const; virtual bool isActivationCharSequence(const QString &sequence) const; - virtual CppCompletionSupport *completionSupport(TextEditor::ITextEditor *editor) = 0; + virtual TextEditor::IAssistInterface *createAssistInterface( + ProjectExplorer::Project *project, const QString &filePath, QTextDocument *document, + int position, TextEditor::AssistReason reason) const = 0; static int activationSequenceChar(const QChar &ch, const QChar &ch2, const QChar &ch3, unsigned *kind, diff --git a/src/plugins/cpptools/cppcompletionsupport.cpp b/src/plugins/cpptools/cppcompletionsupport.cpp deleted file mode 100644 index 12665cb6b4318ea897777e1c92d302fa340bfe54..0000000000000000000000000000000000000000 --- a/src/plugins/cpptools/cppcompletionsupport.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "cppcompletionsupport.h" - -using namespace CppTools; - -CppCompletionSupport::CppCompletionSupport(TextEditor::ITextEditor *editor) - : m_editor(editor) -{ - Q_ASSERT(editor); -} - -CppCompletionSupport::~CppCompletionSupport() -{ -} diff --git a/src/plugins/cpptools/cppcompletionsupport.h b/src/plugins/cpptools/cppcompletionsupport.h deleted file mode 100644 index 216317e232b72d33aca34e9bea25119e53f9f238..0000000000000000000000000000000000000000 --- a/src/plugins/cpptools/cppcompletionsupport.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CPPTOOLS_CPPCOMPLETIONSUPPORT_H -#define CPPTOOLS_CPPCOMPLETIONSUPPORT_H - -#include "cpptools_global.h" - -#include <texteditor/codeassist/assistenums.h> - -QT_BEGIN_NAMESPACE -class QTextDocument; -QT_END_NAMESPACE - -namespace ProjectExplorer { -class Project; -} - -namespace TextEditor { -class IAssistInterface; -class ITextEditor; -} - -namespace CppTools { - -class CPPTOOLS_EXPORT CppCompletionSupport -{ -public: - CppCompletionSupport(TextEditor::ITextEditor *editor); - virtual ~CppCompletionSupport() = 0; - - virtual TextEditor::IAssistInterface *createAssistInterface(ProjectExplorer::Project *project, - QTextDocument *document, - int position, - TextEditor::AssistReason reason) const = 0; - -protected: - TextEditor::ITextEditor *editor() const - { return m_editor; } - -private: - TextEditor::ITextEditor *m_editor; -}; - -} // namespace CppTools - -#endif // CPPTOOLS_CPPCOMPLETIONSUPPORT_H diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp index cb2f88707417795cc0564e2edee03b3ddc7d0a2b..6e942767fdb26fc174af6a4dfd74a1e2d50a0669 100644 --- a/src/plugins/cpptools/cppmodelmanager.cpp +++ b/src/plugins/cpptools/cppmodelmanager.cpp @@ -259,9 +259,8 @@ CppModelManager::CppModelManager(QObject *parent) qRegisterMetaType<CPlusPlus::Document::Ptr>("CPlusPlus::Document::Ptr"); - m_completionFallback = new InternalCompletionAssistProvider; - m_completionAssistProvider = m_completionFallback; - ExtensionSystem::PluginManager::addObject(m_completionAssistProvider); + m_completionFallback.reset(new InternalCompletionAssistProvider); + m_completionAssistProvider = m_completionFallback.data(); m_highlightingFallback = new CppHighlightingSupportInternalFactory; m_highlightingFactory = m_highlightingFallback; m_internalIndexingSupport = new BuiltinIndexingSupport; @@ -269,8 +268,6 @@ CppModelManager::CppModelManager(QObject *parent) CppModelManager::~CppModelManager() { - ExtensionSystem::PluginManager::removeObject(m_completionAssistProvider); - delete m_completionFallback; delete m_highlightingFallback; delete m_internalIndexingSupport; } @@ -899,14 +896,6 @@ void CppModelManager::finishedRefreshingSourceFiles(const QStringList &files) emit sourceFilesRefreshed(files); } -CppCompletionSupport *CppModelManager::completionSupport(Core::IEditor *editor) const -{ - if (TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor *>(editor)) - return m_completionAssistProvider->completionSupport(textEditor); - else - return 0; -} - CppCompletionAssistProvider *CppModelManager::completionAssistProvider(Core::IEditor *editor) const { Q_UNUSED(editor); @@ -916,12 +905,10 @@ CppCompletionAssistProvider *CppModelManager::completionAssistProvider(Core::IEd void CppModelManager::setCppCompletionAssistProvider(CppCompletionAssistProvider *completionAssistProvider) { - ExtensionSystem::PluginManager::removeObject(m_completionAssistProvider); if (completionAssistProvider) m_completionAssistProvider = completionAssistProvider; else - m_completionAssistProvider = m_completionFallback; - ExtensionSystem::PluginManager::addObject(m_completionAssistProvider); + m_completionAssistProvider = m_completionFallback.data(); } CppHighlightingSupport *CppModelManager::highlightingSupport(Core::IEditor *editor) const diff --git a/src/plugins/cpptools/cppmodelmanager.h b/src/plugins/cpptools/cppmodelmanager.h index 5778d0f9ce68e96db3d9909486e26274a4e348e5..ff28eadd2dfdacb652bb5789a7b1f720ea30aeaa 100644 --- a/src/plugins/cpptools/cppmodelmanager.h +++ b/src/plugins/cpptools/cppmodelmanager.h @@ -104,7 +104,6 @@ public: void finishedRefreshingSourceFiles(const QStringList &files); - virtual CppCompletionSupport *completionSupport(Core::IEditor *editor) const; virtual CppCompletionAssistProvider *completionAssistProvider(Core::IEditor *editor) const; virtual void setCppCompletionAssistProvider(CppCompletionAssistProvider *completionAssistProvider); @@ -204,7 +203,7 @@ private: // Completion CppCompletionAssistProvider *m_completionAssistProvider; - CppCompletionAssistProvider *m_completionFallback; + QScopedPointer<CppCompletionAssistProvider> m_completionFallback; // Highlighting CppHighlightingSupportFactory *m_highlightingFactory; diff --git a/src/plugins/cpptools/cppmodelmanagerinterface.h b/src/plugins/cpptools/cppmodelmanagerinterface.h index 7dafdef8f08726a9b06969296175b907a4eb36d9..dd9f8b9ac33d9f0fb39cc6c08ae85a135408b3a4 100644 --- a/src/plugins/cpptools/cppmodelmanagerinterface.h +++ b/src/plugins/cpptools/cppmodelmanagerinterface.h @@ -53,7 +53,6 @@ namespace CppTools { class AbstractEditorSupport; class CppCompletionAssistProvider; -class CppCompletionSupport; class CppEditorSupport; class CppHighlightingSupport; class CppHighlightingSupportFactory; @@ -241,7 +240,6 @@ public: virtual void setIfdefedOutBlocks(const QString &fileName, const QList<TextEditor::BlockRange> &ifdeffedOutBlocks) = 0; - virtual CppTools::CppCompletionSupport *completionSupport(Core::IEditor *editor) const = 0; virtual CppCompletionAssistProvider *completionAssistProvider(Core::IEditor *editor) const = 0; virtual void setCppCompletionAssistProvider(CppTools::CppCompletionAssistProvider *completionAssistProvider) = 0; diff --git a/src/plugins/cpptools/cpptools.pro b/src/plugins/cpptools/cpptools.pro index 76dc4d5c3e0f359822337707dfe5779f1d4b23fd..7ddfa221a1b844d2b4431d92c3af75a5c6ba7e51 100644 --- a/src/plugins/cpptools/cpptools.pro +++ b/src/plugins/cpptools/cpptools.pro @@ -32,7 +32,6 @@ HEADERS += completionsettingspage.h \ doxygengenerator.h \ commentssettings.h \ symbolfinder.h \ - cppcompletionsupport.h \ cpphighlightingsupport.h \ cpphighlightingsupportinternal.h \ cppchecksymbols.h \ @@ -77,7 +76,6 @@ SOURCES += completionsettingspage.cpp \ doxygengenerator.cpp \ commentssettings.cpp \ symbolfinder.cpp \ - cppcompletionsupport.cpp \ cpphighlightingsupport.cpp \ cpphighlightingsupportinternal.cpp \ cppchecksymbols.cpp \ diff --git a/src/plugins/cpptools/cpptools.qbs b/src/plugins/cpptools/cpptools.qbs index ae3b719e1a4cd71b2594e347894a73fd7e40aa33..5055786a09a205576ba655647076e7e4416a7eec 100644 --- a/src/plugins/cpptools/cpptools.qbs +++ b/src/plugins/cpptools/cpptools.qbs @@ -43,8 +43,6 @@ QtcPlugin { "cppcompletionassist.h", "cppcompletionassistprovider.cpp", "cppcompletionassistprovider.h", - "cppcompletionsupport.cpp", - "cppcompletionsupport.h", "cppcurrentdocumentfilter.cpp", "cppcurrentdocumentfilter.h", "cppdoxygen.cpp", diff --git a/src/plugins/cpptools/cpptoolseditorsupport.cpp b/src/plugins/cpptools/cpptoolseditorsupport.cpp index cc1a0e74c8299027ab38ca329a3fe873150ef7fe..4c77287ac2b396a8c6129b1c54e7aaae6084bfcd 100644 --- a/src/plugins/cpptools/cpptoolseditorsupport.cpp +++ b/src/plugins/cpptools/cpptoolseditorsupport.cpp @@ -232,7 +232,7 @@ void CppEditorSupport::recalculateSemanticInfoDetached(bool force) CppCompletionAssistProvider *CppEditorSupport::completionAssistProvider() const { - return m_completionAssistProvider.data(); + return m_completionAssistProvider; } void CppEditorSupport::updateDocument() @@ -526,6 +526,8 @@ void CppEditorSupport::onMimeTypeChanged() connect(this, SIGNAL(semanticInfoUpdated(CppTools::SemanticInfo)), this, SLOT(startHighlighting())); + m_completionAssistProvider = m_modelManager->completionAssistProvider(m_textEditor); + updateDocumentNow(); } diff --git a/src/plugins/cpptools/cpptoolseditorsupport.h b/src/plugins/cpptools/cpptoolseditorsupport.h index 8a9f50b1c6f611ba43e5b22500b40d6b7a009526..255bc3a5a31e5a296e3589bdecff8098cdbbca29 100644 --- a/src/plugins/cpptools/cpptoolseditorsupport.h +++ b/src/plugins/cpptools/cpptoolseditorsupport.h @@ -195,7 +195,7 @@ private: QScopedPointer<CppTools::CppHighlightingSupport> m_highlightingSupport; // Completion: - QScopedPointer<CppCompletionAssistProvider> m_completionAssistProvider; + CppCompletionAssistProvider *m_completionAssistProvider; }; } // namespace CppTools