clangmodelmanagersupport.h 4.15 KB
Newer Older
1 2
/****************************************************************************
**
3 4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
5 6 7 8 9 10 11
**
** 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
12 13 14
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
15
**
16 17 18 19 20 21 22
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 24 25
**
****************************************************************************/

hjk's avatar
hjk committed
26
#pragma once
27

28
#include "clangcompletionassistprovider.h"
29

30 31
#include <cpptools/cppmodelmanagersupport.h>

32
#include <QObject>
33 34
#include <QScopedPointer>

35 36 37 38 39
QT_BEGIN_NAMESPACE
class QMenu;
class QWidget;
QT_END_NAMESPACE

40
namespace Core { class IDocument; }
41
namespace TextEditor { class TextEditorWidget; }
42

43 44 45
namespace ClangCodeModel {
namespace Internal {

46 47 48
class ModelManagerSupportClang:
        public QObject,
        public CppTools::ModelManagerSupport
49
{
50
    Q_OBJECT
51 52

public:
53 54 55 56 57 58
    ModelManagerSupportClang();
    ~ModelManagerSupportClang();

    CppTools::CppCompletionAssistProvider *completionAssistProvider() override;
    CppTools::BaseEditorDocumentProcessor *editorDocumentProcessor(
                TextEditor::TextDocument *baseTextDocument) override;
59

60
    IpcCommunicator &ipcCommunicator();
61

62 63 64
#ifdef QT_TESTLIB_LIB
    static ModelManagerSupportClang *instance_forTestsOnly();
#endif
65 66

private:
67
    void onEditorOpened(Core::IEditor *editor);
68
    void onEditorClosed(const QList<Core::IEditor *> &editors);
69
    void onCurrentEditorChanged(Core::IEditor *newCurrent);
70
    void onCppDocumentAboutToReloadOnTranslationUnit();
71
    void onCppDocumentReloadFinishedOnTranslationUnit(bool success);
72 73 74
    void onCppDocumentContentsChangedOnTranslationUnit(int position,
                                                       int charsRemoved,
                                                       int charsAdded);
75
    void onCppDocumentAboutToReloadOnUnsavedFile();
76 77
    void onCppDocumentReloadFinishedOnUnsavedFile(bool success);
    void onCppDocumentContentsChangedOnUnsavedFile();
78 79 80 81

    void onAbstractEditorSupportContentsUpdated(const QString &filePath, const QByteArray &content);
    void onAbstractEditorSupportRemoved(const QString &filePath);

82 83 84 85
    void onTextMarkContextMenuRequested(TextEditor::TextEditorWidget *widget,
                                        int lineNumber,
                                        QMenu *menu);

86
    void onProjectPartsUpdated(ProjectExplorer::Project *project);
87
    void onProjectPartsRemoved(const QStringList &projectPartIds);
88

89 90
    void unregisterTranslationUnitsWithProjectParts(const QStringList &projectPartIds);

91 92
    void connectTextDocumentToTranslationUnit(TextEditor::TextDocument *textDocument);
    void connectTextDocumentToUnsavedFiles(TextEditor::TextDocument *textDocument);
93 94 95
    void connectToTextDocumentContentsChangedForTranslationUnit(
            TextEditor::TextDocument *textDocument);
    void connectToTextDocumentContentsChangedForUnsavedFile(TextEditor::TextDocument *textDocument);
96
    void connectToWidgetsMarkContextMenuRequested(QWidget *editorWidget);
97 98

private:
99 100
    IpcCommunicator m_ipcCommunicator;
    ClangCompletionAssistProvider m_completionAssistProvider;
101 102 103 104 105 106 107 108 109
};

class ModelManagerSupportProviderClang : public CppTools::ModelManagerSupportProvider
{
public:
    QString id() const override;
    QString displayName() const override;

    CppTools::ModelManagerSupport::Ptr createModelManagerSupport() override;
110 111 112 113
};

} // namespace Internal
} // namespace ClangCodeModel