qmljsmodelmanagerinterface.h 7.18 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2014 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 QMLJSMODELMANAGERINTERFACE_H
#define QMLJSMODELMANAGERINTERFACE_H
32

33 34
#include "qmljs_global.h"
#include "qmljsdocument.h"
35
#include "qmljsbundle.h"
Fawzi Mohamed's avatar
Fawzi Mohamed committed
36 37
#include "qmljsconstants.h"
#include "qmljsviewercontext.h"
38 39
#include <utils/environment.h>

40 41 42
#include <QObject>
#include <QStringList>
#include <QPointer>
43

44
namespace ProjectExplorer { class Project; }
45

46
namespace QmlJS {
47

48
class Snapshot;
49

50
class QMLJS_EXPORT ModelManagerInterface: public QObject
51 52 53
{
    Q_OBJECT

54
public:
Fawzi Mohamed's avatar
Fawzi Mohamed committed
55 56 57 58 59
    enum QrcResourceSelector {
        ActiveQrcResources,
        AllQrcResources
    };

60 61 62 63
    class ProjectInfo
    {
    public:
        ProjectInfo()
64
            : tryQmlDump(false), qmlDumpHasRelocatableFlag(true)
65 66 67 68
        { }

        ProjectInfo(QPointer<ProjectExplorer::Project> project)
            : project(project)
69
            , tryQmlDump(false), qmlDumpHasRelocatableFlag(true)
70 71 72 73 74 75 76 77 78 79 80
        { }

        operator bool() const
        { return ! project.isNull(); }

        bool isValid() const
        { return ! project.isNull(); }

        bool isNull() const
        { return project.isNull(); }

81 82
        QStringList completeImportPaths();

83 84 85 86
    public: // attributes
        QPointer<ProjectExplorer::Project> project;
        QStringList sourceFiles;
        QStringList importPaths;
Fawzi Mohamed's avatar
Fawzi Mohamed committed
87 88
        QStringList activeResourceFiles;
        QStringList allResourceFiles;
89 90 91

        // whether trying to run qmldump makes sense
        bool tryQmlDump;
92
        bool qmlDumpHasRelocatableFlag;
93
        QString qmlDumpPath;
94
        ::Utils::Environment qmlDumpEnvironment;
95

96
        QString qtImportsPath;
97
        QString qtQmlPath;
98
        QString qtVersionString;
99 100
        QmlJS::QmlLanguageBundles activeBundle;
        QmlJS::QmlLanguageBundles extendedBundle;
101 102
    };

103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
    class WorkingCopy
    {
    public:
        typedef QHash<QString, QPair<QString, int> > Table;

        void insert(const QString &fileName, const QString &source, int revision = 0)
        { _elements.insert(fileName, qMakePair(source, revision)); }

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

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

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

        Table all() const
        { return _elements; }

    private:
        Table _elements;
    };

127 128 129 130
    class CppData
    {
    public:
        QList<LanguageUtils::FakeMetaObject::ConstPtr> exportedTypes;
131
        QHash<QString, QString> contextProperties;
132 133 134
    };

    typedef QHash<QString, CppData> CppDataHash;
135

136
public:
Roberto Raggi's avatar
Roberto Raggi committed
137 138
    ModelManagerInterface(QObject *parent = 0);
    virtual ~ModelManagerInterface();
139

140 141
    static Language::Enum guessLanguageOfFile(const QString &fileName);
    static QStringList globPatternsForLanguages(const QList<Language::Enum> languages);
142 143
    static ModelManagerInterface *instance();

144
    virtual WorkingCopy workingCopy() const = 0;
145 146 147

    virtual QmlJS::Snapshot snapshot() const = 0;
    virtual QmlJS::Snapshot newestSnapshot() const = 0;
148

149 150
    virtual void updateSourceFiles(const QStringList &files,
                                   bool emitDocumentOnDiskChanged) = 0;
151
    virtual void fileChangedOnDisk(const QString &path) = 0;
Erik Verbruggen's avatar
Erik Verbruggen committed
152
    virtual void removeFiles(const QStringList &files) = 0;
Fawzi Mohamed's avatar
Fawzi Mohamed committed
153 154 155 156 157 158 159 160
    virtual QStringList filesAtQrcPath(const QString &path, const QLocale *locale = 0,
                                       ProjectExplorer::Project *project = 0,
                                       QrcResourceSelector resources = AllQrcResources) = 0;
    virtual QMap<QString,QStringList> filesInQrcPath(const QString &path,
                                                     const QLocale *locale = 0,
                                                     ProjectExplorer::Project *project = 0,
                                                     bool addDirs = false,
                                                     QrcResourceSelector resources = AllQrcResources) = 0;
161

162
    virtual QList<ProjectInfo> projectInfos() const = 0;
163 164
    virtual ProjectInfo projectInfo(ProjectExplorer::Project *project) const = 0;
    virtual void updateProjectInfo(const ProjectInfo &pinfo) = 0;
165
    Q_SLOT virtual void removeProjectInfo(ProjectExplorer::Project *project) = 0;
166
    virtual ProjectInfo projectInfoForPath(QString path) = 0;
167

168
    virtual QStringList importPaths() const = 0;
169 170
    virtual QmlJS::QmlLanguageBundles activeBundles() const = 0;
    virtual QmlJS::QmlLanguageBundles extendedBundles() const = 0;
171

172 173
    virtual void loadPluginTypes(const QString &libraryPath, const QString &importPath,
                                 const QString &importUri, const QString &importVersion) = 0;
174

175
    virtual CppDataHash cppData() const = 0;
176 177

    virtual LibraryInfo builtins(const Document::Ptr &doc) const = 0;
178

Fawzi Mohamed's avatar
Fawzi Mohamed committed
179 180 181 182 183 184
    virtual ViewerContext completeVContext(const ViewerContext &vCtx,
                                           const Document::Ptr &doc = Document::Ptr(0)) const = 0;
    virtual ViewerContext defaultVContext(bool autoComplete = true,
                                          const Document::Ptr &doc = Document::Ptr(0)) const = 0;
    virtual void setDefaultVContext(const ViewerContext &vContext) = 0;

185 186
    // Blocks until all parsing threads are done. Used for testing.
    virtual void joinAllThreads() = 0;
187 188 189
public slots:
    virtual void resetCodeModel() = 0;

190
signals:
191
    void documentUpdated(QmlJS::Document::Ptr doc);
192 193
    void documentChangedOnDisk(QmlJS::Document::Ptr doc);
    void aboutToRemoveFiles(const QStringList &files);
194
    void libraryInfoUpdated(const QString &path, const QmlJS::LibraryInfo &info);
195
    void projectInfoUpdated(const ProjectInfo &pinfo);
196 197
protected:
    virtual QHash<QString,Language::Enum> languageForSuffix() const;
198 199
};

200
} // namespace QmlJS
201

Roberto Raggi's avatar
Roberto Raggi committed
202
#endif // QMLJSMODELMANAGERINTERFACE_H