cppmodelmanagerinterface.h 9.69 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** 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.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
23
24
25
** 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
con's avatar
con committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
31
32
#ifndef CPPMODELMANAGERINTERFACE_H
#define CPPMODELMANAGERINTERFACE_H

33
#include "cpptools_global.h"
34

35
#include "cppprojectfile.h"
36

37
#include <cplusplus/CppDocument.h>
38
#include <projectexplorer/toolchain.h>
39

40
#include <QFuture>
41
#include <QHash>
42
#include <QObject>
43
44
#include <QPointer>
#include <QStringList>
con's avatar
con committed
45

46
47
namespace Core { class IEditor; }
namespace CPlusPlus { class LookupContext; }
48
namespace ProjectExplorer { class Project; }
49
namespace TextEditor { class BaseTextEditor; class BlockRange; }
50
namespace Utils { class FileName; }
con's avatar
con committed
51
52

namespace CppTools {
53

54
class AbstractEditorSupport;
55
class ModelManagerSupport;
56
class CppCompletionAssistProvider;
57
class CppEditorSupport;
58
59
60
class CppHighlightingSupport;
class CppHighlightingSupportFactory;
class CppIndexingSupport;
61

62
class CPPTOOLS_EXPORT ProjectPart
con's avatar
con committed
63
{
64
public:
65
    ProjectPart();
con's avatar
con committed
66

67
68
69
70
71
    void evaluateToolchain(const ProjectExplorer::ToolChain *tc,
                           const QStringList &cxxflags,
                           const QStringList &cflags,
                           const Utils::FileName &sysRoot);

con's avatar
con committed
72
public:
73
74
75
76
77
    enum CVersion {
        C89,
        C99,
        C11
    };
78

79
80
81
82
83
84
85
86
87
88
    enum CXXVersion {
        CXX98,
        CXX11
    };

    enum CXXExtension {
        NoExtensions = 0x0,
        GnuExtensions = 0x1,
        MicrosoftExtensions = 0x2,
        BorlandExtensions = 0x4,
89
90
91
        OpenMPExtensions = 0x8,

        AllExtensions = GnuExtensions | MicrosoftExtensions | BorlandExtensions | OpenMPExtensions
92
93
94
95
96
97
98
99
    };
    Q_DECLARE_FLAGS(CXXExtensions, CXXExtension)

    enum QtVersion {
        UnknownQt = -1,
        NoQt = 0,
        Qt4 = 1,
        Qt5 = 2
100
101
    };

102
103
    typedef QSharedPointer<ProjectPart> Ptr;

104
public:
105
106
107
108
109
110
111
112
113
    QList<ProjectFile> files;
    QByteArray defines;
    QStringList includePaths;
    QStringList frameworkPaths;
    QStringList precompiledHeaders;
    CVersion cVersion;
    CXXVersion cxxVersion;
    CXXExtensions cxxExtensions;
    QtVersion qtVersion;
114
115
    ProjectExplorer::ToolChain::WarningFlags cWarningFlags;
    ProjectExplorer::ToolChain::WarningFlags cxxWarningFlags;
116
117
118
119
120
121
122
};

class CPPTOOLS_EXPORT CppModelManagerInterface : public QObject
{
    Q_OBJECT

public:
123
     // Documented in source file.
124
125
126
127
128
     enum ProgressNotificationMode {
        ForcedProgressNotification,
        ReservedProgressNotification
    };

129
    class CPPTOOLS_EXPORT ProjectInfo
con's avatar
con committed
130
    {
131
132
    public:
        ProjectInfo()
133
        {}
134

135
        ProjectInfo(QPointer<ProjectExplorer::Project> project)
136
            : m_project(project)
137
        {}
138
139

        operator bool() const
140
        { return !m_project.isNull(); }
141
142

        bool isValid() const
143
        { return !m_project.isNull(); }
144
145

        bool isNull() const
146
        { return m_project.isNull(); }
147

148
        QPointer<ProjectExplorer::Project> project() const
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
        { return m_project; }

        const QList<ProjectPart::Ptr> projectParts() const
        { return m_projectParts; }

        void clearProjectParts();
        void appendProjectPart(const ProjectPart::Ptr &part);

        const QStringList includePaths() const
        { return m_includePaths; }

        const QStringList frameworkPaths() const
        { return m_frameworkPaths; }

        const QStringList sourceFiles() const
        { return m_sourceFiles; }

        const QByteArray defines() const
        { return m_defines; }

169
    private:
170
        QPointer<ProjectExplorer::Project> m_project;
171
        QList<ProjectPart::Ptr> m_projectParts;
172
        // The members below are (re)calculated from the project parts once a part is appended.
173
174
175
176
        QStringList m_includePaths;
        QStringList m_frameworkPaths;
        QStringList m_sourceFiles;
        QByteArray m_defines;
con's avatar
con committed
177
178
    };

179
180
181
182
183
184
185
186
187
    /// The working-copy stores all files that are stored on disk in their current state.
    ///
    /// So, currently the working copy holds:
    ///  - unsaved content of editors
    ///  - uic-ed UI files (through \c AbstractEditorSupport)
    ///  - the preprocessor configuration
    ///
    /// Contents are keyed on filename, and hold the revision in the editor and the editor's
    /// contents encoded as UTF-8.
188
    class CPPTOOLS_EXPORT WorkingCopy
189
190
    {
    public:
191
        void insert(const QString &fileName, const QByteArray &source, unsigned revision = 0)
192
        { _elements.insert(fileName, qMakePair(source, revision)); }
193
194
195
196

        bool contains(const QString &fileName) const
        { return _elements.contains(fileName); }

197
        QByteArray source(const QString &fileName) const
198
199
        { return _elements.value(fileName).first; }

200
        QPair<QByteArray, unsigned> get(const QString &fileName) const
201
202
        { return _elements.value(fileName); }

203
204
        QHashIterator<QString, QPair<QByteArray, unsigned> > iterator() const
        { return QHashIterator<QString, QPair<QByteArray, unsigned> >(_elements); }
205

206
207
208
        int size() const
        { return _elements.size(); }

209
    private:
210
        typedef QHash<QString, QPair<QByteArray, unsigned> > Table;
211
212
        Table _elements;
    };
213

214
215
216
public:
    static const QString configurationFileName();

con's avatar
con committed
217
public:
218
219
    CppModelManagerInterface(QObject *parent = 0);
    virtual ~CppModelManagerInterface();
con's avatar
con committed
220

221
222
    static CppModelManagerInterface *instance();

223
224
    virtual bool isCppEditor(Core::IEditor *editor) const = 0;

225
    virtual WorkingCopy workingCopy() const = 0;
226
    virtual CPlusPlus::Snapshot snapshot() const = 0;
con's avatar
con committed
227

228
229
    virtual QList<ProjectInfo> projectInfos() const = 0;
    virtual ProjectInfo projectInfo(ProjectExplorer::Project *project) const = 0;
230
    virtual QFuture<void> updateProjectInfo(const ProjectInfo &pinfo) = 0;
231
    virtual QList<ProjectPart::Ptr> projectPart(const QString &fileName) const = 0;
232
    virtual ProjectPart::Ptr fallbackProjectPart() const = 0;
233

234
235
    virtual QStringList includePaths() = 0;

236
237
238
239
    virtual void addExtraEditorSupport(CppTools::AbstractEditorSupport *editorSupport) = 0;
    virtual void removeExtraEditorSupport(CppTools::AbstractEditorSupport *editorSupport) = 0;
    virtual CppEditorSupport *cppEditorSupport(TextEditor::BaseTextEditor *textEditor) = 0;
    virtual void deleteCppEditorSupport(TextEditor::BaseTextEditor *textEditor) = 0;
Roberto Raggi's avatar
Roberto Raggi committed
240

241
    virtual QList<int> references(CPlusPlus::Symbol *symbol,
242
                                  const CPlusPlus::LookupContext &context) = 0;
243

244
245
    virtual void renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context,
                              const QString &replacement = QString()) = 0;
246
    virtual void findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context) = 0;
247

248
    virtual void renameMacroUsages(const CPlusPlus::Macro &macro, const QString &replacement = QString()) = 0;
Christian Kamm's avatar
Christian Kamm committed
249
250
    virtual void findMacroUsages(const CPlusPlus::Macro &macro) = 0;

251
    virtual void setExtraDiagnostics(const QString &fileName, const QString &kind,
252
                                     const QList<CPlusPlus::Document::DiagnosticMessage> &diagnostics) = 0;
253
254
    virtual void setIfdefedOutBlocks(const QString &fileName,
                                     const QList<TextEditor::BlockRange> &ifdeffedOutBlocks) = 0;
255

256
257
    virtual void addModelManagerSupport(ModelManagerSupport *modelManagerSupport) = 0;
    virtual ModelManagerSupport *modelManagerSupportForMimeType(const QString &mimeType) const = 0;
258
    virtual CppCompletionAssistProvider *completionAssistProvider(Core::IEditor *editor) const = 0;
259
    virtual CppHighlightingSupport *highlightingSupport(Core::IEditor *editor) const = 0;
260

261
    virtual void setIndexingSupport(CppTools::CppIndexingSupport *indexingSupport) = 0;
262
    virtual CppIndexingSupport *indexingSupport() = 0;
263

264
signals:
265
266
267
    /// Project data might be locked while this is emitted.
    void aboutToRemoveFiles(const QStringList &files);

268
    void documentUpdated(CPlusPlus::Document::Ptr doc);
269
    void sourceFilesRefreshed(const QStringList &files);
270

271
272
273
274
275
    /// \brief Emitted after updateProjectInfo method is called on the model-manager.
    ///
    /// Other classes can use this to get notified when the \c ProjectExplorer has updated the parts.
    void projectPartsUpdated(ProjectExplorer::Project *project);

276
public slots:
277
    // Documented in source file.
278
279
    virtual QFuture<void> updateSourceFiles(const QStringList &sourceFiles,
        ProgressNotificationMode mode = ReservedProgressNotification) = 0;
280
281

    virtual void updateModifiedSourceFiles() = 0;
282
    virtual void GC() = 0;
283
284
};

285
} // namespace CppTools
con's avatar
con committed
286
287

#endif // CPPMODELMANAGERINTERFACE_H