qt4nodes.h 13.5 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
**
10
** GNU Lesser General Public License Usage
11
**
hjk's avatar
hjk committed
12
13
14
15
16
17
** 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.
18
**
con's avatar
con committed
19
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
con's avatar
con committed
21
22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23
24
25
26
27
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
con's avatar
con committed
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
con's avatar
con committed
30
**
31
**************************************************************************/
hjk's avatar
hjk committed
32

con's avatar
con committed
33
34
35
#ifndef QT4NODES_H
#define QT4NODES_H

36
#include "qt4projectmanager_global.h"
37

38
#include <utils/fileutils.h>
39
#include <coreplugin/idocument.h>
con's avatar
con committed
40
41
#include <projectexplorer/projectnodes.h>

42
43
44
45
46
#include <QHash>
#include <QStringList>
#include <QDateTime>
#include <QMap>
#include <QFutureWatcher>
con's avatar
con committed
47
48
49
50
51
52
53
54
55
56

// defined in proitems.h
QT_BEGIN_NAMESPACE
class ProFile;
QT_END_NAMESPACE

namespace Core {
class ICore;
}

57
58
59
60
namespace QtSupport {
class ProFileReader;
}

61
62
63
64
namespace ProjectExplorer {
class RunConfiguration;
class Project;
}
con's avatar
con committed
65

66
67
namespace Qt4ProjectManager {
class Qt4BuildConfiguration;
68
class Qt4ProFileNode;
con's avatar
con committed
69
70
71
72
73
74
75
76
class Qt4Project;

//  Type of projects
enum Qt4ProjectType {
    InvalidProject = 0,
    ApplicationTemplate,
    LibraryTemplate,
    ScriptTemplate,
77
    AuxTemplate,
con's avatar
con committed
78
79
80
81
82
83
84
    SubDirsTemplate
};

// Other variables of interest
enum Qt4Variable {
    DefinesVar = 1,
    IncludePathVar,
85
    CppFlagsVar,
86
    CppHeaderVar,
87
88
    CppSourceVar,
    ObjCSourceVar,
con's avatar
con committed
89
    UiDirVar,
90
    MocDirVar,
91
    PkgConfigVar,
92
    PrecompiledHeaderVar,
93
    LibDirectoriesVar,
94
    ConfigVar,
95
    QtVar,
96
    QmlImportPathVar,
97
    Makefile,
98
99
100
    SymbianCapabilities,
    ObjectExt,
    ObjectsDir
con's avatar
con committed
101
102
};

103
104
105
106
107
108
// Import base classes into namespace
using ProjectExplorer::Node;
using ProjectExplorer::FileNode;
using ProjectExplorer::FolderNode;
using ProjectExplorer::ProjectNode;
using ProjectExplorer::NodesWatcher;
109

110
111
112
113
114
// Import enums into namespace
using ProjectExplorer::NodeType;
using ProjectExplorer::FileNodeType;
using ProjectExplorer::FolderNodeType;
using ProjectExplorer::ProjectNodeType;
115

116
117
using ProjectExplorer::UnknownFileType;
using ProjectExplorer::ProjectFileType;
118

119
using ProjectExplorer::FileType;
120

Daniel Teske's avatar
Daniel Teske committed
121
namespace Internal {
122
123
class Qt4UiCodeModelSupport;
class Qt4PriFile;
Daniel Teske's avatar
Daniel Teske committed
124
125
struct InternalNode;
}
126

con's avatar
con committed
127
// Implements ProjectNode for qt4 pro files
Daniel Teske's avatar
Daniel Teske committed
128
class QT4PROJECTMANAGER_EXPORT Qt4PriFileNode : public ProjectExplorer::ProjectNode
129
{
con's avatar
con committed
130
    Q_OBJECT
hjk's avatar
hjk committed
131

con's avatar
con committed
132
public:
133
    Qt4PriFileNode(Qt4Project *project, Qt4ProFileNode* qt4ProFileNode, const QString &filePath);
134
    ~Qt4PriFileNode();
con's avatar
con committed
135

136
    void update(ProFile *includeFileExact, QtSupport::ProFileReader *readerExact, ProFile *includeFileCumlative, QtSupport::ProFileReader *readerCumalative);
dt's avatar
dt committed
137

con's avatar
con committed
138
139

// ProjectNode interface
dt's avatar
dt committed
140
    QList<ProjectAction> supportedActions(Node *node) const;
con's avatar
con committed
141

142
    bool hasBuildTargets() const { return false; }
con's avatar
con committed
143

144
145
    bool canAddSubProject(const QString &proFilePath) const;

con's avatar
con committed
146
147
148
149
150
151
152
    bool addSubProjects(const QStringList &proFilePaths);
    bool removeSubProjects(const QStringList &proFilePaths);

    bool addFiles(const FileType fileType, const QStringList &filePaths,
                  QStringList *notAdded = 0);
    bool removeFiles(const FileType fileType, const QStringList &filePaths,
                     QStringList *notRemoved = 0);
153
154
    bool deleteFiles(const FileType fileType,
                     const QStringList &filePaths);
con's avatar
con committed
155
156
157
    bool renameFile(const FileType fileType,
                    const QString &filePath, const QString &newFilePath);

158
    void folderChanged(const QString &changedFolder);
159

dt's avatar
dt committed
160
    bool deploysFolder(const QString &folder) const;
dt's avatar
dt committed
161
    QList<ProjectExplorer::RunConfiguration *> runConfigurationsFor(Node *node);
dt's avatar
dt committed
162

163
164
165
166
167
    QList<Qt4PriFileNode*> subProjectNodesExact() const;

    // Set by parent
    bool includedInExactParse() const;

con's avatar
con committed
168
protected:
169
    void setIncludedInExactParse(bool b);
con's avatar
con committed
170
    static QStringList varNames(FileType type);
171
    static QStringList dynamicVarNames(QtSupport::ProFileReader *readerExact, QtSupport::ProFileReader *readerCumulative);
172
173
    static QSet<Utils::FileName> filterFilesProVariables(ProjectExplorer::FileType fileType, const QSet<Utils::FileName> &files);
    static QSet<Utils::FileName> filterFilesRecursiveEnumerata(ProjectExplorer::FileType fileType, const QSet<Utils::FileName> &files);
con's avatar
con committed
174
175
176
177
178
179
180
181
182
183

    enum ChangeType {
        AddToProFile,
        RemoveFromProFile
    };

    void changeFiles(const FileType fileType,
                     const QStringList &filePaths,
                     QStringList *notChanged,
                     ChangeType change);
184

185
186
187
private slots:
    void scheduleUpdate();

con's avatar
con committed
188
private:
189
    void save(const QStringList &lines);
con's avatar
con committed
190
    bool priFileWritable(const QString &path);
191
    bool saveModifiedEditors();
192
    QStringList formResources(const QString &formFile) const;
193
194
195
    QStringList baseVPaths(QtSupport::ProFileReader *reader, const QString &projectDir) const;
    QStringList fullVPaths(const QStringList &baseVPaths, QtSupport::ProFileReader *reader,
                           FileType type, const QString &qmakeVariable, const QString &projectDir) const;
196
    void watchFolders(const QSet<QString> &folders);
con's avatar
con committed
197
198

    Qt4Project *m_project;
199
    Qt4ProFileNode *m_qt4ProFileNode;
con's avatar
con committed
200
201
    QString m_projectFilePath;
    QString m_projectDir;
202

Daniel Teske's avatar
Daniel Teske committed
203
    QMap<QString, Internal::Qt4UiCodeModelSupport *> m_uiCodeModelSupport;
204
    Internal::Qt4PriFile *m_qt4PriFile;
dt's avatar
dt committed
205

206
    // Memory is cheap...
207
208
    QMap<ProjectExplorer::FileType, QSet<Utils::FileName> > m_files;
    QSet<Utils::FileName> m_recursiveEnumerateFiles;
209
    QSet<QString> m_watchedFolders;
210
    bool m_includedInExactParse;
211

con's avatar
con committed
212
    // managed by Qt4ProFileNode
213
    friend class Qt4ProjectManager::Qt4ProFileNode;
Daniel Teske's avatar
Daniel Teske committed
214
    friend class Internal::Qt4PriFile; // for scheduling updates on modified
215
    // internal temporary subtree representation
Daniel Teske's avatar
Daniel Teske committed
216
    friend struct Internal::InternalNode;
con's avatar
con committed
217
218
};

Daniel Teske's avatar
Daniel Teske committed
219
namespace Internal {
220
class Qt4PriFile : public Core::IDocument
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
{
    Q_OBJECT
public:
    Qt4PriFile(Qt4PriFileNode *qt4PriFile);
    virtual bool save(QString *errorString, const QString &fileName, bool autoSave);
    virtual QString fileName() const;
    virtual void rename(const QString &newName);

    virtual QString defaultPath() const;
    virtual QString suggestedFileName() const;
    virtual QString mimeType() const;

    virtual bool isModified() const;
    virtual bool isSaveAsAllowed() const;

    ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
    bool reload(QString *errorString, ReloadFlag flag, ChangeType type);

private:
    Qt4PriFileNode *m_priFile;
};

class Qt4NodesWatcher : public ProjectExplorer::NodesWatcher
{
    Q_OBJECT
hjk's avatar
hjk committed
246

247
248
249
250
251
252
253
254
255
256
257
258
public:
    Qt4NodesWatcher(QObject *parent = 0);

signals:
    void projectTypeChanged(Qt4ProjectManager::Qt4ProFileNode *projectNode,
                            const Qt4ProjectManager::Qt4ProjectType oldType,
                            const Qt4ProjectManager::Qt4ProjectType newType);

    void variablesChanged(Qt4ProFileNode *projectNode,
                          const QHash<Qt4Variable, QStringList> &oldValues,
                          const QHash<Qt4Variable, QStringList> &newValues);

259
    void proFileUpdated(Qt4ProjectManager::Qt4ProFileNode *projectNode, bool success, bool parseInProgress);
260
261
262
263
264
265
266

private:
    // let them emit signals
    friend class Qt4ProjectManager::Qt4ProFileNode;
    friend class Qt4PriFileNode;
};

267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
class ProVirtualFolderNode : public ProjectExplorer::VirtualFolderNode
{
public:
    explicit ProVirtualFolderNode(const QString &folderPath, int priority, const QString &typeName)
        : VirtualFolderNode(folderPath, priority), m_typeName(typeName)
    {

    }

    QString displayName() const
    {
        return m_typeName;
    }

    QString tooltip() const
    {
        return QString();
    }

private:
    QString m_typeName;
};

290
291
292
} // namespace Internal

struct QT4PROJECTMANAGER_EXPORT TargetInformation
dt's avatar
dt committed
293
294
295
296
297
{
    bool valid;
    QString workingDir;
    QString target;
    QString executable;
298
    QString buildDir;
dt's avatar
dt committed
299
300
301
302
303
    bool operator==(const TargetInformation &other) const
    {
        return workingDir == other.workingDir
                && target == other.target
                && executable == other.executable
304
305
                && valid == other.valid
                && buildDir == other.buildDir;
dt's avatar
dt committed
306
307
308
309
310
311
312
313
314
315
316
317
318
319
    }
    bool operator!=(const TargetInformation &other) const
    {
        return !(*this == other);
    }

    TargetInformation()
        : valid(false)
    {}

    TargetInformation(const TargetInformation &other)
        : valid(other.valid),
          workingDir(other.workingDir),
          target(other.target),
320
321
          executable(other.executable),
          buildDir(other.buildDir)
dt's avatar
dt committed
322
323
324
325
326
    {
    }

};

327
struct QT4PROJECTMANAGER_EXPORT InstallsItem {
328
329
330
331
332
    InstallsItem(QString p, QStringList f) : path(p), files(f) {}
    QString path;
    QStringList files;
};

333
struct QT4PROJECTMANAGER_EXPORT InstallsList {
334
335
336
337
338
    void clear() { targetPath.clear(); items.clear(); }
    QString targetPath;
    QList<InstallsItem> items;
};

339
struct QT4PROJECTMANAGER_EXPORT ProjectVersion {
340
341
342
343
344
    int major;
    int minor;
    int patch;
};

con's avatar
con committed
345
// Implements ProjectNode for qt4 pro files
Daniel Teske's avatar
Daniel Teske committed
346
class QT4PROJECTMANAGER_EXPORT Qt4ProFileNode : public Qt4PriFileNode
347
{
con's avatar
con committed
348
    Q_OBJECT
hjk's avatar
hjk committed
349

con's avatar
con committed
350
351
352
353
public:
    Qt4ProFileNode(Qt4Project *project,
                   const QString &filePath,
                   QObject *parent = 0);
dt's avatar
dt committed
354
    ~Qt4ProFileNode();
con's avatar
con committed
355

dt's avatar
dt committed
356
357
    bool isParent(Qt4ProFileNode *node);

358
    bool hasBuildTargets() const;
con's avatar
con committed
359
360
361
362
363

    Qt4ProjectType projectType() const;

    QStringList variableValue(const Qt4Variable var) const;

364
365
366
367
    bool isSubProjectDeployable(const QString &filePath) const {
        return !m_subProjectsNotToDeploy.contains(filePath);
    }

dt's avatar
dt committed
368
    void updateCodeModelSupportFromBuild(const QStringList &files);
369
    void updateCodeModelSupportFromEditor(const QString &uiFileName, const QString &contents);
370

371
    QString sourceDir() const;
372
    QString buildDir(Qt4BuildConfiguration *bc = 0) const;
373

374
375
376
    QString uiDirectory() const;
    static QString uiHeaderFile(const QString &uiDir, const QString &formFile);

377
378
379
    const Qt4ProFileNode *findProFileFor(const QString &string) const;
    TargetInformation targetInformation(const QString &fileName) const;
    TargetInformation targetInformation() const;
380

381
    InstallsList installsList() const;
382
    ProjectVersion projectVersion() const { return m_projectVersion; }
383

384
    QString makefile() const;
385
    QStringList symbianCapabilities() const;
386
387
    QString objectExtension() const;
    QString objectsDirectory() const;
388
    QByteArray cxxDefines() const;
389
    bool isDeployable() const;
390
    QString resolvedMkspecPath() const;
391

con's avatar
con committed
392
    void update();
dt's avatar
dt committed
393
394
    void scheduleUpdate();

395
    bool validParse() const;
396
    bool parseInProgress() const;
397

398
    bool hasBuildTargets(Qt4ProjectType projectType) const;
Orgad Shaneh's avatar
Orgad Shaneh committed
399
    bool isDebugAndRelease() const;
dt's avatar
dt committed
400

Daniel Teske's avatar
Daniel Teske committed
401
402
    void setParseInProgress(bool b);
    void setParseInProgressRecursive(bool b);
403
404
    void setValidParse(bool b);
    void setValidParseRecursive(bool b);
Daniel Teske's avatar
Daniel Teske committed
405
    void emitProFileUpdatedRecursive();
dt's avatar
dt committed
406
407
408
public slots:
    void asyncUpdate();

con's avatar
con committed
409
private slots:
410
    void buildStateChanged(ProjectExplorer::Project*);
dt's avatar
dt committed
411
    void applyAsyncEvaluate();
con's avatar
con committed
412

413
private:
dt's avatar
dt committed
414
    void setupReader();
415
416
417
    enum EvalResult { EvalFail, EvalPartial, EvalOk };
    EvalResult evaluate();
    void applyEvaluate(EvalResult parseResult, bool async);
dt's avatar
dt committed
418

419
    void asyncEvaluate(QFutureInterface<EvalResult> &fi);
dt's avatar
dt committed
420

421
422
    typedef QHash<Qt4Variable, QStringList> Qt4VariablesHash;

dt's avatar
dt committed
423
424
    void createUiCodeModelSupport();
    QStringList updateUiFiles();
con's avatar
con committed
425

426
    QStringList fileListForVar(QtSupport::ProFileReader *readerExact, QtSupport::ProFileReader *readerCumulative,
427
                               const QString &varName, const QString &projectDir, FileType type) const;
428
429
430
431
    QString uiDirPath(QtSupport::ProFileReader *reader) const;
    QString mocDirPath(QtSupport::ProFileReader *reader) const;
    QStringList includePaths(QtSupport::ProFileReader *reader) const;
    QStringList libDirectories(QtSupport::ProFileReader *reader) const;
432
433
    QStringList subDirsPaths(QtSupport::ProFileReader *reader, QStringList *subProjectsNotToDeploy = 0) const;

434
435
436
    TargetInformation targetInformation(QtSupport::ProFileReader *reader) const;
    void setupInstallsList(const QtSupport::ProFileReader *reader);
    void setupProjectVersion(const QtSupport::ProFileReader *reader);
con's avatar
con committed
437
438

    Qt4ProjectType m_projectType;
439
    Qt4VariablesHash m_varValues;
440
    bool m_isDeployable;
con's avatar
con committed
441

442
    QMap<QString, QDateTime> m_uitimestamps;
dt's avatar
dt committed
443
    TargetInformation m_qt4targetInformation;
444
    QString m_resolvedMkspecPath;
445
    QStringList m_subProjectsNotToDeploy;
446
    InstallsList m_installsList;
447
    ProjectVersion m_projectVersion;
con's avatar
con committed
448
    friend class Qt4NodeHierarchy;
dt's avatar
dt committed
449

450
    bool m_validParse;
451
    bool m_parseInProgress;
452

dt's avatar
dt committed
453
    // Async stuff
454
    QFutureWatcher<EvalResult> m_parseFutureWatcher;
455
456
    QtSupport::ProFileReader *m_readerExact;
    QtSupport::ProFileReader *m_readerCumulative;
con's avatar
con committed
457
458
459
460
461
};

} // namespace Qt4ProjectManager

#endif // QT4NODES_H