OSDN Git Service

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