OSDN Git Service

When adding a form file to a project add also its qrc files
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qt4projectmanager / qt4nodes.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** Commercial Usage
10 **
11 ** Licensees holding valid Qt Commercial licenses may use this file in
12 ** accordance with the Qt Commercial License Agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Nokia.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** If you are unsure which license is appropriate for your use, please
26 ** contact the sales department at http://qt.nokia.com/contact.
27 **
28 **************************************************************************/
29
30 #ifndef QT4NODES_H
31 #define QT4NODES_H
32
33 #include <coreplugin/ifile.h>
34 #include <projectexplorer/projectnodes.h>
35 #include <projectexplorer/project.h>
36
37 #include <QtCore/QHash>
38 #include <QtCore/QStringList>
39 #include <QtCore/QDateTime>
40 #include <QtCore/QMap>
41 #include <QtCore/QFutureWatcher>
42
43 // defined in proitems.h
44 QT_BEGIN_NAMESPACE
45 class ProFile;
46 QT_END_NAMESPACE
47
48 namespace Core {
49 class ICore;
50 }
51
52 namespace Qt4ProjectManager {
53
54 // Import base classes into namespace
55 using ProjectExplorer::Node;
56 using ProjectExplorer::FileNode;
57 using ProjectExplorer::FolderNode;
58 using ProjectExplorer::ProjectNode;
59 using ProjectExplorer::NodesWatcher;
60
61 // Import enums into namespace
62 using ProjectExplorer::NodeType;
63 using ProjectExplorer::FileNodeType;
64 using ProjectExplorer::FolderNodeType;
65 using ProjectExplorer::ProjectNodeType;
66
67 using ProjectExplorer::UnknownFileType;
68 using ProjectExplorer::ProjectFileType;
69
70 class Qt4Project;
71
72 namespace Internal {
73
74 using ProjectExplorer::FileType;
75 class ProFileReader;
76 class Qt4UiCodeModelSupport;
77
78 //  Type of projects
79 enum Qt4ProjectType {
80     InvalidProject = 0,
81     ApplicationTemplate,
82     LibraryTemplate,
83     ScriptTemplate,
84     SubDirsTemplate
85 };
86
87 // Other variables of interest
88 enum Qt4Variable {
89     DefinesVar = 1,
90     IncludePathVar,
91     UiDirVar,
92     MocDirVar,
93     PkgConfigVar,
94     PrecompiledHeaderVar,
95     LibDirectoriesVar
96 };
97
98 class Qt4PriFileNode;
99 class Qt4ProFileNode;
100
101 class Qt4PriFile : public Core::IFile
102 {
103     Q_OBJECT
104 public:
105     Qt4PriFile(Qt4PriFileNode *qt4PriFile);
106     virtual bool save(const QString &fileName = QString());
107     virtual QString fileName() const;
108     virtual void rename(const QString &newName);
109
110     virtual QString defaultPath() const;
111     virtual QString suggestedFileName() const;
112     virtual QString mimeType() const;
113
114     virtual bool isModified() const;
115     virtual bool isReadOnly() const;
116     virtual bool isSaveAsAllowed() const;
117
118     ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
119     void reload(ReloadFlag flag, ChangeType type);
120
121 private:
122     Qt4PriFileNode *m_priFile;
123 };
124
125 // Implements ProjectNode for qt4 pro files
126 class Qt4PriFileNode : public ProjectExplorer::ProjectNode
127 {
128     Q_OBJECT
129     Q_DISABLE_COPY(Qt4PriFileNode)
130 public:
131     Qt4PriFileNode(Qt4Project *project, Qt4ProFileNode* qt4ProFileNode, const QString &filePath);
132
133     void update(ProFile *includeFileExact, ProFileReader *readerExact, ProFile *includeFileCumlative, ProFileReader *readerCumalative);
134
135
136 // ProjectNode interface
137     QList<ProjectAction> supportedActions(Node *node) const;
138
139     bool hasBuildTargets() const { return false; }
140
141     bool addSubProjects(const QStringList &proFilePaths);
142     bool removeSubProjects(const QStringList &proFilePaths);
143
144     bool addFiles(const FileType fileType, const QStringList &filePaths,
145                   QStringList *notAdded = 0);
146     bool removeFiles(const FileType fileType, const QStringList &filePaths,
147                      QStringList *notRemoved = 0);
148     bool renameFile(const FileType fileType,
149                     const QString &filePath, const QString &newFilePath);
150
151 protected:
152     void clear();
153     static QStringList varNames(FileType type);
154
155     enum ChangeType {
156         AddToProFile,
157         RemoveFromProFile
158     };
159
160     bool changeIncludes(ProFile *includeFile,
161                        const QStringList &proFilePaths,
162                        ChangeType change);
163
164     void changeFiles(const FileType fileType,
165                      const QStringList &filePaths,
166                      QStringList *notChanged,
167                      ChangeType change);
168
169 private slots:
170     void scheduleUpdate();
171
172 private:
173     void save(const QStringList &lines);
174     bool priFileWritable(const QString &path);
175     bool saveModifiedEditors();
176     QStringList formResources(const QString &formFile) const;
177     QStringList baseVPaths(ProFileReader *reader, const QString &projectDir);
178     QStringList fullVPaths(const QStringList &baseVPaths, ProFileReader *reader, FileType type, const QString &qmakeVariable, const QString &projectDir);
179
180     Qt4Project *m_project;
181     Qt4ProFileNode *m_qt4ProFileNode;
182     QString m_projectFilePath;
183     QString m_projectDir;
184
185     QMap<QString, Qt4UiCodeModelSupport *> m_uiCodeModelSupport;
186     Qt4PriFile *m_qt4PriFile;
187
188     // managed by Qt4ProFileNode
189     friend class Qt4ProFileNode;
190     friend class Qt4PriFile; // for scheduling updates on modified
191     // internal temporary subtree representation
192     friend struct InternalNode;
193 };
194
195 struct TargetInformation
196 {
197     bool valid;
198     QString workingDir;
199     QString target;
200     QString executable;
201     QString buildDir;
202     bool operator==(const TargetInformation &other) const
203     {
204         return workingDir == other.workingDir
205                 && target == other.target
206                 && executable == other.executable
207                 && valid == valid
208                 && buildDir == buildDir;
209     }
210     bool operator!=(const TargetInformation &other) const
211     {
212         return !(*this == other);
213     }
214
215     TargetInformation()
216         : valid(false)
217     {}
218
219     TargetInformation(const TargetInformation &other)
220         : valid(other.valid),
221           workingDir(other.workingDir),
222           target(other.target),
223           executable(other.executable),
224           buildDir(other.buildDir)
225     {
226     }
227
228 };
229
230 // Implements ProjectNode for qt4 pro files
231 class Qt4ProFileNode : public Qt4PriFileNode
232 {
233     Q_OBJECT
234     Q_DISABLE_COPY(Qt4ProFileNode)
235 public:
236     Qt4ProFileNode(Qt4Project *project,
237                    const QString &filePath,
238                    QObject *parent = 0);
239     ~Qt4ProFileNode();
240
241     bool isParent(Qt4ProFileNode *node);
242
243     bool hasBuildTargets() const;
244
245     Qt4ProjectType projectType() const;
246
247     QStringList variableValue(const Qt4Variable var) const;
248
249     void updateCodeModelSupportFromBuild(const QStringList &files);
250     void updateCodeModelSupportFromEditor(const QString &uiFileName, const QString &contents);
251
252     QString buildDir() const;
253
254     QString uiDirectory() const;
255     static QString uiHeaderFile(const QString &uiDir, const QString &formFile);
256
257     Qt4ProFileNode *findProFileFor(const QString &string);
258     TargetInformation targetInformation(const QString &fileName);
259     TargetInformation targetInformation();
260
261     void update();
262     void scheduleUpdate();
263
264 public slots:
265     void asyncUpdate();
266
267 private slots:
268     void buildStateChanged(ProjectExplorer::Project*);
269     void applyAsyncEvaluate();
270
271 private:
272     void setupReader();
273     bool evaluate();
274     void applyEvaluate(bool parseResult, bool async);
275
276     void asyncEvaluate(QFutureInterface<bool> &fi);
277
278     typedef QHash<Qt4Variable, QStringList> Qt4VariablesHash;
279
280     void createUiCodeModelSupport();
281     QStringList updateUiFiles();
282
283     QString uiDirPath(ProFileReader *reader) const;
284     QString mocDirPath(ProFileReader *reader) const;
285     QStringList includePaths(ProFileReader *reader) const;
286     QStringList libDirectories(ProFileReader *reader) const;
287     QStringList subDirsPaths(ProFileReader *reader) const;
288     TargetInformation targetInformation(ProFileReader *reader) const;
289
290     void invalidate();
291
292     Qt4ProjectType m_projectType;
293     Qt4VariablesHash m_varValues;
294
295     QMap<QString, QDateTime> m_uitimestamps;
296     TargetInformation m_qt4targetInformation;
297     friend class Qt4NodeHierarchy;
298
299     // Async stuff
300     QFutureWatcher<bool> m_parseFutureWatcher;
301     ProFileReader *m_readerExact;
302     ProFileReader *m_readerCumulative;
303 };
304
305 class Qt4NodesWatcher : public ProjectExplorer::NodesWatcher
306 {
307     Q_OBJECT
308     Q_DISABLE_COPY(Qt4NodesWatcher)
309 public:
310     Qt4NodesWatcher(QObject *parent = 0);
311
312 signals:
313     void projectTypeChanged(Qt4ProjectManager::Internal::Qt4ProFileNode *projectNode,
314                             const Qt4ProjectManager::Internal::Qt4ProjectType oldType,
315                             const Qt4ProjectManager::Internal::Qt4ProjectType newType);
316
317     void variablesChanged(Qt4ProFileNode *projectNode,
318                           const QHash<Qt4Variable, QStringList> &oldValues,
319                           const QHash<Qt4Variable, QStringList> &newValues);
320
321     void proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode *projectNode);
322
323 private:
324     // let them emit signals
325     friend class Qt4ProFileNode;
326     friend class Qt4PriFileNode;
327 };
328
329 } // namespace Internal
330 } // namespace Qt4ProjectManager
331
332 #endif // QT4NODES_H