OSDN Git Service

df1b9a7a577c628a077deaf4275ca4197b7f6f4c
[qt-creator-jp/qt-creator-jp.git] / src / plugins / cmakeprojectmanager / cmakeproject.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
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 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef CMAKEPROJECT_H
35 #define CMAKEPROJECT_H
36
37 #include "cmakeprojectmanager.h"
38 #include "cmakeprojectnodes.h"
39 #include "cmakebuildconfiguration.h"
40 #include "cmaketarget.h"
41 #include "makestep.h"
42
43 #include <projectexplorer/project.h>
44 #include <projectexplorer/projectnodes.h>
45 #include <projectexplorer/buildstep.h>
46 #include <projectexplorer/filewatcher.h>
47 #include <projectexplorer/buildconfiguration.h>
48 #include <coreplugin/ifile.h>
49 #include <coreplugin/editormanager/ieditor.h>
50
51 #include <QtCore/QXmlStreamReader>
52 #include <QtGui/QPushButton>
53 #include <QtGui/QLineEdit>
54
55 namespace CMakeProjectManager {
56 namespace Internal {
57
58 class CMakeFile;
59 class CMakeBuildSettingsWidget;
60 class CMakeUiCodeModelSupport;
61
62 struct CMakeBuildTarget
63 {
64     QString title;
65     QString executable; // TODO: rename to output?
66     bool library;
67     QString workingDirectory;
68     QString makeCommand;
69     QString makeCleanCommand;
70     void clear();
71 };
72
73 class CMakeProject : public ProjectExplorer::Project
74 {
75     Q_OBJECT
76     // for changeBuildDirectory
77     friend class CMakeBuildSettingsWidget;
78 public:
79     CMakeProject(CMakeManager *manager, const QString &filename);
80     ~CMakeProject();
81
82     QString displayName() const;
83     QString id() const;
84     Core::IFile *file() const;
85     CMakeManager *projectManager() const;
86
87     CMakeTarget *activeTarget() const;
88
89     QList<ProjectExplorer::Project *> dependsOn(); //NBS TODO implement dependsOn
90
91     QList<ProjectExplorer::BuildConfigWidget*> subConfigWidgets();
92
93     ProjectExplorer::ProjectNode *rootProjectNode() const;
94
95     QStringList files(FilesMode fileMode) const;
96     QStringList buildTargetTitles() const;
97     QList<CMakeBuildTarget> buildTargets() const;
98     bool hasBuildTarget(const QString &title) const;
99
100     CMakeBuildTarget buildTargetForTitle(const QString &title);
101
102     QString defaultBuildDirectory() const;
103
104     bool parseCMakeLists();
105
106     QString uicCommand() const;
107
108 signals:
109     /// emitted after parsing
110     void buildTargetsChanged();
111
112 protected:
113     bool fromMap(const QVariantMap &map);
114
115     // called by CMakeBuildSettingsWidget
116     void changeBuildDirectory(CMakeBuildConfiguration *bc, const QString &newBuildDirectory);
117
118 private slots:
119     void fileChanged(const QString &fileName);
120     void changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*);
121     void targetAdded(ProjectExplorer::Target *);
122
123     void editorChanged(Core::IEditor *editor);
124     void editorAboutToClose(Core::IEditor *editor);
125     void uiEditorContentsChanged();
126     void buildStateChanged(ProjectExplorer::Project *project);
127 private:
128     void buildTree(CMakeProjectNode *rootNode, QList<ProjectExplorer::FileNode *> list);
129     void gatherFileNodes(ProjectExplorer::FolderNode *parent, QList<ProjectExplorer::FileNode *> &list);
130     ProjectExplorer::FolderNode *findOrCreateFolder(CMakeProjectNode *rootNode, QString directory);
131     void updateCodeModelSupportFromEditor(const QString &uiFileName, const QString &contents);
132     void createUiCodeModelSupport();
133     QString uiHeaderFile(const QString &uiFile);
134
135     CMakeManager *m_manager;
136     QString m_fileName;
137     CMakeFile *m_file;
138     QString m_projectName;
139     QString m_uicCommand;
140
141     // TODO probably need a CMake specific node structure
142     CMakeProjectNode *m_rootNode;
143     QStringList m_files;
144     QList<CMakeBuildTarget> m_buildTargets;
145     ProjectExplorer::FileWatcher *m_watcher;
146     bool m_insideFileChanged;
147     QSet<QString> m_watchedFiles;
148     QFuture<void> m_codeModelFuture;
149
150     QMap<QString, CMakeUiCodeModelSupport *> m_uiCodeModelSupport;
151     Core::IEditor *m_lastEditor;
152     bool m_dirtyUic;
153 };
154
155 class CMakeCbpParser : public QXmlStreamReader
156 {
157 public:
158     bool parseCbpFile(const QString &fileName);
159     QList<ProjectExplorer::FileNode *> fileList();
160     QList<ProjectExplorer::FileNode *> cmakeFileList();
161     QStringList includeFiles();
162     QList<CMakeBuildTarget> buildTargets();
163     QString projectName() const;
164     QString compilerName() const;
165     bool hasCMakeFiles();
166 private:
167     void parseCodeBlocks_project_file();
168     void parseProject();
169     void parseBuild();
170     void parseOption();
171     void parseBuildTarget();
172     void parseBuildTargetOption();
173     void parseMakeCommand();
174     void parseBuildTargetBuild();
175     void parseBuildTargetClean();
176     void parseCompiler();
177     void parseAdd();
178     void parseUnit();
179     void parseUnitOption();
180     void parseUnknownElement();
181
182     QList<ProjectExplorer::FileNode *> m_fileList;
183     QList<ProjectExplorer::FileNode *> m_cmakeFileList;
184     QSet<QString> m_processedUnits;
185     bool m_parsingCmakeUnit;
186     QStringList m_includeFiles;
187
188     CMakeBuildTarget m_buildTarget;
189     bool m_buildTargetType;
190     QList<CMakeBuildTarget> m_buildTargets;
191     QString m_projectName;
192     QString m_compiler;
193 };
194
195 class CMakeFile : public Core::IFile
196 {
197     Q_OBJECT
198 public:
199     CMakeFile(CMakeProject *parent, QString fileName);
200
201     bool save(const QString &fileName = QString());
202     QString fileName() const;
203
204     QString defaultPath() const;
205     QString suggestedFileName() const;
206     QString mimeType() const;
207
208     bool isModified() const;
209     bool isReadOnly() const;
210     bool isSaveAsAllowed() const;
211
212     ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
213     void reload(ReloadFlag flag, ChangeType type);
214
215     void rename(const QString &newName);
216
217 private:
218     CMakeProject *m_project;
219     QString m_fileName;
220 };
221
222 class CMakeBuildSettingsWidget : public ProjectExplorer::BuildConfigWidget
223 {
224     Q_OBJECT
225 public:
226     explicit CMakeBuildSettingsWidget(CMakeTarget *target);
227     QString displayName() const;
228
229     // This is called to set up the config widget before showing it
230     virtual void init(ProjectExplorer::BuildConfiguration *bc);
231 private slots:
232     void openChangeBuildDirectoryDialog();
233     void runCMake();
234 private:
235     CMakeTarget *m_target;
236     QLineEdit *m_pathLineEdit;
237     QPushButton *m_changeButton;
238     CMakeBuildConfiguration *m_buildConfiguration;
239 };
240
241 } // namespace Internal
242 } // namespace CMakeProjectManager
243
244 #endif // CMAKEPROJECT_H