cppeditordocument.h 3.9 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 29
#include <cpptools/baseeditordocumentprocessor.h>
#include <cpptools/cppcompletionassistprovider.h>
30
#include <cpptools/cppmodelmanager.h>
31 32 33
#include <cpptools/cppsemanticinfo.h>
#include <cpptools/editordocumenthandle.h>

34
#include <texteditor/textdocument.h>
35

36 37 38
#include <QMutex>
#include <QTimer>

39 40 41
namespace CppEditor {
namespace Internal {

42
class CppEditorDocument : public TextEditor::TextDocument
43 44
{
    Q_OBJECT
45

46
    friend class CppEditorDocumentHandleImpl;
47

48
public:
49
    explicit CppEditorDocument();
50 51

    bool isObjCEnabled() const;
52
    TextEditor::CompletionAssistProvider *completionAssistProvider() const override;
53
    TextEditor::QuickFixAssistProvider *quickFixAssistProvider() const override;
54

55
    void recalculateSemanticInfoDetached();
56 57
    CppTools::SemanticInfo recalculateSemanticInfo(); // TODO: Remove me

58 59
    void setPreprocessorSettings(const CppTools::ProjectPart::Ptr &projectPart,
                                 const QByteArray &defines);
60
    void scheduleProcessDocument();
61

62 63
signals:
    void codeWarningsUpdated(unsigned contentsRevision,
64 65
                             const QList<QTextEdit::ExtraSelection> selections,
                             const TextEditor::RefactorMarkers &refactorMarkers);
66 67 68 69 70 71

    void ifdefedOutBlocksUpdated(unsigned contentsRevision,
                                 const QList<TextEditor::BlockRange> ifdefedOutBlocks);

    void cppDocumentUpdated(const CPlusPlus::Document::Ptr document);    // TODO: Remove me
    void semanticInfoUpdated(const CppTools::SemanticInfo semanticInfo); // TODO: Remove me
72

73 74
    void preprocessorSettingsChanged(bool customSettings);

75
protected:
76
    void applyFontSettings() override;
77

78
private:
79
    void invalidateFormatterCache();
80
    void onFilePathChanged(const Utils::FileName &oldPath, const Utils::FileName &newPath);
81 82
    void onMimeTypeChanged();

83 84 85 86 87 88 89 90 91 92
    void onAboutToReload();
    void onReloadFinished();

    void processDocument();

    QByteArray contentsText() const;
    unsigned contentsRevision() const;

    CppTools::BaseEditorDocumentProcessor *processor();
    void resetProcessor();
93
    void updatePreprocessorSettings();
94 95
    void releaseResources();

96 97
    void initializeTimer();

98
private:
99
    bool m_fileIsBeingReloaded;
100
    bool m_isObjCEnabled;
101 102 103 104 105 106 107 108 109 110 111 112 113

    // Caching contents
    mutable QMutex m_cachedContentsLock;
    mutable QByteArray m_cachedContents;
    mutable int m_cachedContentsRevision;

    unsigned m_processorRevision;
    QTimer m_processorTimer;
    QScopedPointer<CppTools::BaseEditorDocumentProcessor> m_processor;

    CppTools::CppCompletionAssistProvider *m_completionAssistProvider;

    // (Un)Registration in CppModelManager
114
    QScopedPointer<CppTools::CppEditorDocumentHandle> m_editorDocumentHandle;
115 116 117 118
};

} // namespace Internal
} // namespace CppEditor