qmljsmodelmanager.h 7.91 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
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
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
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
** 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.
23
**
hjk's avatar
hjk committed
24
25
** 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
****************************************************************************/
29

Roberto Raggi's avatar
Roberto Raggi committed
30
31
#ifndef QMLJSMODELMANAGER_H
#define QMLJSMODELMANAGER_H
32

33
34
#include "qmljstools_global.h"

35
#include <qmljs/qmljsmodelmanagerinterface.h>
Fawzi Mohamed's avatar
Fawzi Mohamed committed
36
#include <qmljs/qmljsqrcparser.h>
Fawzi Mohamed's avatar
Fawzi Mohamed committed
37
#include <qmljs/qmljsconstants.h>
Friedemann Kleint's avatar
Friedemann Kleint committed
38

39
#include <cplusplus/CppDocument.h>
40
#include <utils/qtcoverride.h>
41

42
43
44
#include <QFuture>
#include <QFutureSynchronizer>
#include <QMutex>
45

46
QT_FORWARD_DECLARE_CLASS(QTimer)
Fawzi Mohamed's avatar
Fawzi Mohamed committed
47
QT_FORWARD_DECLARE_CLASS(QLocale)
48

49
namespace Core {
50
class MimeType;
51
52
}

53
54
55
56
namespace CPlusPlus {
class CppModelManagerInterface;
}

Fawzi Mohamed's avatar
Fawzi Mohamed committed
57
58
59
60
namespace QmlJS {
class QrcParser;
}

61
namespace QmlJSTools {
62

Fawzi Mohamed's avatar
Fawzi Mohamed committed
63
QMLJSTOOLS_EXPORT QmlJS::Language::Enum languageOfFile(const QString &fileName);
64
65
QMLJSTOOLS_EXPORT QStringList qmlAndJsGlobPatterns();

66
67
namespace Internal {

68
69
class PluginDumper;

70
class QMLJSTOOLS_EXPORT ModelManager: public QmlJS::ModelManagerInterface
71
72
73
74
{
    Q_OBJECT

public:
Roberto Raggi's avatar
Roberto Raggi committed
75
    ModelManager(QObject *parent = 0);
76
    ~ModelManager();
77

78
79
    void delayedInitialization();

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
    WorkingCopy workingCopy() const QTC_OVERRIDE;
    QmlJS::Snapshot snapshot() const QTC_OVERRIDE;
    QmlJS::Snapshot newestSnapshot() const QTC_OVERRIDE;

    void updateSourceFiles(const QStringList &files,
                           bool emitDocumentOnDiskChanged) QTC_OVERRIDE;
    void fileChangedOnDisk(const QString &path) QTC_OVERRIDE;
    void removeFiles(const QStringList &files) QTC_OVERRIDE;
    QStringList filesAtQrcPath(const QString &path, const QLocale *locale = 0,
                               ProjectExplorer::Project *project = 0,
                               QrcResourceSelector resources = AllQrcResources) QTC_OVERRIDE;
    QMap<QString,QStringList> filesInQrcPath(const QString &path,
                                             const QLocale *locale = 0,
                                             ProjectExplorer::Project *project = 0,
                                             bool addDirs = false,
                                             QrcResourceSelector resources = AllQrcResources) QTC_OVERRIDE;

    QList<ProjectInfo> projectInfos() const QTC_OVERRIDE;
    ProjectInfo projectInfo(ProjectExplorer::Project *project) const QTC_OVERRIDE;
    void updateProjectInfo(const ProjectInfo &pinfo) QTC_OVERRIDE;
100
    Q_SLOT virtual void removeProjectInfo(ProjectExplorer::Project *project);
101
    virtual ProjectInfo projectInfoForPath(QString path);
102

103
104
    void updateDocument(QmlJS::Document::Ptr doc);
    void updateLibraryInfo(const QString &path, const QmlJS::LibraryInfo &info);
105
    void emitDocumentChangedOnDisk(QmlJS::Document::Ptr doc);
Fawzi Mohamed's avatar
Fawzi Mohamed committed
106
    void updateQrcFile(const QString &path);
107

108
109
110
    QStringList importPaths() const QTC_OVERRIDE;
    QmlJS::QmlLanguageBundles activeBundles() const QTC_OVERRIDE;
    QmlJS::QmlLanguageBundles extendedBundles() const QTC_OVERRIDE;
111

112
113
    void loadPluginTypes(const QString &libraryPath, const QString &importPath,
                         const QString &importUri, const QString &importVersion) QTC_OVERRIDE;
114

115
    CppDataHash cppData() const QTC_OVERRIDE;
116

117
    QmlJS::LibraryInfo builtins(const QmlJS::Document::Ptr &doc) const QTC_OVERRIDE;
118

Fawzi Mohamed's avatar
Fawzi Mohamed committed
119
120
121
122
123
124
125
126
    QmlJS::ViewerContext completeVContext(
            const QmlJS::ViewerContext &vCtx,
            const QmlJS::Document::Ptr &doc = QmlJS::Document::Ptr(0)) const QTC_OVERRIDE;
    QmlJS::ViewerContext defaultVContext(
            bool autoComplete = true,
            const QmlJS::Document::Ptr &doc = QmlJS::Document::Ptr(0)) const QTC_OVERRIDE;
    void setDefaultVContext(const QmlJS::ViewerContext &vContext) QTC_OVERRIDE;

127
    void joinAllThreads() QTC_OVERRIDE;
128

129
public slots:
130
    void resetCodeModel() QTC_OVERRIDE;
131

132
133
134
135
Q_SIGNALS:
    void projectPathChanged(const QString &projectPath);

protected:
136
137
    QFuture<void> refreshSourceFiles(const QStringList &sourceFiles,
                                     bool emitDocumentOnDiskChanged);
138

Fawzi Mohamed's avatar
Fawzi Mohamed committed
139
140
141
142
    static void parseLoop(QSet<QString> &scannedPaths, QSet<QString> &newLibraries,
                          WorkingCopy workingCopy, QStringList files, ModelManager *modelManager,
                          QmlJS::Language::Enum mainLanguage, bool emitDocChangedOnDisk,
                          Utils::function<bool (qreal)> reportProgress);
143
    static void parse(QFutureInterface<void> &future,
144
                      WorkingCopy workingCopy,
145
                      QStringList files,
146
                      ModelManager *modelManager,
Fawzi Mohamed's avatar
Fawzi Mohamed committed
147
                      QmlJS::Language::Enum mainLanguage,
148
                      bool emitDocChangedOnDisk);
Fawzi Mohamed's avatar
Fawzi Mohamed committed
149
150
151
152
153
154
    static void importScan(QFutureInterface<void> &future,
                    WorkingCopy workingCopy,
                    QStringList paths,
                    ModelManager *modelManager,
                    QmlJS::Language::Enum mainLanguage,
                    bool emitDocChangedOnDisk);
155

156
    void loadQmlTypeDescriptions();
157
    void loadQmlTypeDescriptions(const QString &path);
158

159
160
    void updateImportPaths();

161
private slots:
162
163
    void maybeQueueCppQmlTypeUpdate(const CPlusPlus::Document::Ptr &doc);
    void queueCppQmlTypeUpdate(const CPlusPlus::Document::Ptr &doc, bool scan);
164
    void startCppQmlTypeUpdate();
165
    void asyncReset();
166

167
private:
168
    static bool matchesMimeType(const Core::MimeType &fileMimeType, const Core::MimeType &knownMimeType);
169
170
171
    static void updateCppQmlTypes(QFutureInterface<void> &interface,
                                  ModelManager *qmlModelManager,
                                  CPlusPlus::Snapshot snapshot,
172
                                  QHash<QString, QPair<CPlusPlus::Document::Ptr, bool> > documents);
173

174
    mutable QMutex m_mutex;
175
176
    QmlJS::Snapshot _validSnapshot;
    QmlJS::Snapshot _newestSnapshot;
177
    QStringList m_allImportPaths;
178
    QStringList m_defaultImportPaths;
179
180
    QmlJS::QmlLanguageBundles m_activeBundles;
    QmlJS::QmlLanguageBundles m_extendedBundles;
Fawzi Mohamed's avatar
Fawzi Mohamed committed
181
    QmlJS::ViewerContext m_vContext;
Fawzi Mohamed's avatar
Fawzi Mohamed committed
182
    QSet<QString> m_scannedPaths;
183

184
    QTimer *m_updateCppQmlTypesTimer;
185
    QTimer *m_asyncResetTimer;
186
    QHash<QString, QPair<CPlusPlus::Document::Ptr, bool> > m_queuedCppDocuments;
187
    QFuture<void> m_cppQmlTypesUpdater;
Fawzi Mohamed's avatar
Fawzi Mohamed committed
188
    QmlJS::QrcCache m_qrcCache;
189
190
191

    CppDataHash m_cppDataHash;
    mutable QMutex m_cppDataMutex;
192
193
194

    // project integration
    QMap<ProjectExplorer::Project *, ProjectInfo> m_projects;
195
196

    PluginDumper *m_pluginDumper;
197
198

    QFutureSynchronizer<void> m_synchronizer;
199
200
201
};

} // namespace Internal
202
203
204
205
206

QMLJSTOOLS_EXPORT QmlJS::ModelManagerInterface::ProjectInfo defaultProjectInfoForProject(
        ProjectExplorer::Project *project);
QMLJSTOOLS_EXPORT void setupProjectInfoQmlBundles(QmlJS::ModelManagerInterface::ProjectInfo &projectInfo);

207
} // namespace QmlJSTools
208

Roberto Raggi's avatar
Roberto Raggi committed
209
#endif // QMLJSMODELMANAGER_H