cppmodelmanagerinterface.h 9.25 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
55
class AbstractEditorSupport;
class CppCompletionAssistProvider;
56
class CppCompletionSupport;
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
89
90
91
92
93
94
95
96
97
    enum CXXVersion {
        CXX98,
        CXX11
    };

    enum CXXExtension {
        NoExtensions = 0x0,
        GnuExtensions = 0x1,
        MicrosoftExtensions = 0x2,
        BorlandExtensions = 0x4,
        OpenMP = 0x8
    };
    Q_DECLARE_FLAGS(CXXExtensions, CXXExtension)

    enum QtVersion {
        UnknownQt = -1,
        NoQt = 0,
        Qt4 = 1,
        Qt5 = 2
98
99
    };

100
101
    typedef QSharedPointer<ProjectPart> Ptr;

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

class CPPTOOLS_EXPORT CppModelManagerInterface : public QObject
{
    Q_OBJECT

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

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

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

        operator bool() const
138
        { return !m_project.isNull(); }
139
140

        bool isValid() const
141
        { return !m_project.isNull(); }
142
143

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

146
        QPointer<ProjectExplorer::Project> project() const
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
        { 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; }

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

177
    class CPPTOOLS_EXPORT WorkingCopy
178
179
    {
    public:
180
181
        void insert(const QString &fileName, const QString &source, unsigned revision = 0)
        { _elements.insert(fileName, qMakePair(source, revision)); }
182
183
184
185
186

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

        QString source(const QString &fileName) const
187
188
189
        { return _elements.value(fileName).first; }

        QPair<QString, unsigned> get(const QString &fileName) const
190
191
        { return _elements.value(fileName); }

192
193
194
        QHashIterator<QString, QPair<QString, unsigned> > iterator() const
        { return QHashIterator<QString, QPair<QString, unsigned> >(_elements); }

195
196
197
        int size() const
        { return _elements.size(); }

198
    private:
199
        typedef QHash<QString, QPair<QString, unsigned> > Table;
200
201
        Table _elements;
    };
202

203
204
205
public:
    static const QString configurationFileName();

con's avatar
con committed
206
public:
207
208
    CppModelManagerInterface(QObject *parent = 0);
    virtual ~CppModelManagerInterface();
con's avatar
con committed
209

210
211
    static CppModelManagerInterface *instance();

212
213
    virtual bool isCppEditor(Core::IEditor *editor) const = 0;

214
    virtual WorkingCopy workingCopy() const = 0;
215
    virtual CPlusPlus::Snapshot snapshot() const = 0;
con's avatar
con committed
216

217
218
    virtual QList<ProjectInfo> projectInfos() const = 0;
    virtual ProjectInfo projectInfo(ProjectExplorer::Project *project) const = 0;
219
    virtual QFuture<void> updateProjectInfo(const ProjectInfo &pinfo) = 0;
220
    virtual QList<ProjectPart::Ptr> projectPart(const QString &fileName) const = 0;
221

222
223
    virtual QStringList includePaths() = 0;

224
225
226
227
    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
228

229
    virtual QList<int> references(CPlusPlus::Symbol *symbol,
230
                                  const CPlusPlus::LookupContext &context) = 0;
231

232
233
    virtual void renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context,
                              const QString &replacement = QString()) = 0;
234
    virtual void findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context) = 0;
235

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

239
    virtual void setExtraDiagnostics(const QString &fileName, const QString &kind,
240
                                     const QList<CPlusPlus::Document::DiagnosticMessage> &diagnostics) = 0;
241
242
    virtual void setIfdefedOutBlocks(const QString &fileName,
                                     const QList<TextEditor::BlockRange> &ifdeffedOutBlocks) = 0;
243

244
    virtual CppTools::CppCompletionSupport *completionSupport(Core::IEditor *editor) const = 0;
245
    virtual CppCompletionAssistProvider *completionAssistProvider(Core::IEditor *editor) const = 0;
246
247
    virtual void setCppCompletionAssistProvider(CppTools::CppCompletionAssistProvider *completionAssistProvider) = 0;

248
    virtual CppTools::CppHighlightingSupport *highlightingSupport(Core::IEditor *editor) const = 0;
249
    virtual void setHighlightingSupportFactory(CppTools::CppHighlightingSupportFactory *highlightingFactory) = 0;
250

251
252
    virtual void setIndexingSupport(CppTools::CppIndexingSupport *indexingSupport) = 0;
    virtual CppTools::CppIndexingSupport *indexingSupport() = 0;
253

254
signals:
255
256
257
    /// Project data might be locked while this is emitted.
    void aboutToRemoveFiles(const QStringList &files);

258
    void documentUpdated(CPlusPlus::Document::Ptr doc);
259
    void sourceFilesRefreshed(const QStringList &files);
260

261
262
263
264
265
    /// \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);

266
public slots:
267
    // Documented in source file.
268
269
    virtual QFuture<void> updateSourceFiles(const QStringList &sourceFiles,
        ProgressNotificationMode mode = ReservedProgressNotification) = 0;
270
271

    virtual void updateModifiedSourceFiles() = 0;
272
    virtual void GC() = 0;
273
274
};

275
} // namespace CppTools
con's avatar
con committed
276
277

#endif // CPPMODELMANAGERINTERFACE_H