Fix no newlines warnings. Patch by Peter Oberndorfer
[kdevelopdvcssupport.git] / project / projectmodel.h
blob6dae174348f8e19ebf49fb4636f503b6d43f7e67
1 /* This file is part of KDevelop
2 Copyright 2005 Roberto Raggi <roberto@kdevelop.org>
3 Copyright 2007 Andreas Pakulat <apaku@gmx.de>
4 Copyright 2007 Aleix Pol <aleixpol@gmail.com>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
22 #ifndef KDEVPROJECTMODEL_H
23 #define KDEVPROJECTMODEL_H
25 #include <QtGui/QStandardItem>
26 #include <QtGui/QStandardItemModel>
27 #include "projectexport.h"
28 #include <kurl.h>
29 #include <ksharedconfig.h>
31 template<typename T1,typename T2> class QPair;
32 template<typename T> class QList;
34 namespace KDevelop
37 class IProject;
38 class ProjectFolderItem;
39 class ProjectBuildFolderItem;
40 class ProjectFileItem;
41 class ProjectTargetItem;
42 class ProjectExecutableTargetItem;
43 class ProjectLibraryTargetItem;
45 /**
46 * Interface that allows a developer to implement the three basic types of
47 * items you would see in a multi-project
48 * \li Folder
49 * \li Project
50 * \li Custom Target
51 * \li Library Target
52 * \li Executable Target
53 * \li File
55 class KDEVPLATFORMPROJECT_EXPORT ProjectBaseItem: public QStandardItem
57 public:
58 ProjectBaseItem( IProject*, const QString &name, QStandardItem *parent = 0 );
59 virtual ~ProjectBaseItem();
61 /**
62 * add the item @p item to the list of children for this item
63 * do not use this function if you gave the item a parent when you
64 * created it
66 void add( ProjectBaseItem* item );
68 enum ProjectItemType
70 BuildFolder = QStandardItem::UserType /** item is a buildable folder */,
71 Folder = QStandardItem::UserType+1 /** item is a folder */,
72 ExecutableTarget = QStandardItem::UserType+2 /** item is an executable target */,
73 LibraryTarget = QStandardItem::UserType+3 /** item is a library target */,
74 Target = QStandardItem::UserType+5 /** item is a target */,
75 File = QStandardItem::UserType+6 /** item is a file */
78 /** @returns Returns the project that the item belongs to. */
79 IProject* project() const;
81 /** @returns If this item is a folder, it returns a pointer to the folder, otherwise returns a 0 pointer. */
82 virtual ProjectFolderItem *folder() const;
84 /** @returns If this item is a target, it returns a pointer to the target, otherwise returns a 0 pointer. */
85 virtual ProjectTargetItem *target() const;
87 /** @returns If this item is a file, it returns a pointer to the file, otherwise returns a 0 pointer. */
88 virtual ProjectFileItem *file() const;
90 /** @returns If this item is a file, it returns a pointer to the file, otherwise returns a 0 pointer. */
91 virtual ProjectExecutableTargetItem *executable() const;
93 /** @param parent sets the item parent to @p parent */
94 void setParent( QStandardItem* parent);
95 virtual void setIcon();
97 /** @returns Returns a list of the folders that have this object as the parent. */
98 QList<ProjectFolderItem*> folderList() const;
100 /** @returns Returns a list of the targets that have this object as the parent. */
101 QList<ProjectTargetItem*> targetList() const;
103 /** @returns Returns a list of the files that have this object as the parent. */
104 QList<ProjectFileItem*> fileList() const;
106 protected:
107 class ProjectBaseItemPrivate* const d_ptr;
108 ProjectBaseItem( ProjectBaseItemPrivate& dd );
109 private:
110 Q_DECLARE_PRIVATE(ProjectBaseItem)
114 * Implementation of the ProjectBaseItem interface that is specific to a
115 * folder
117 class ProjectFolderItemPrivate;
118 class KDEVPLATFORMPROJECT_EXPORT ProjectFolderItem: public ProjectBaseItem
120 public:
121 ProjectFolderItem( IProject*, const KUrl &dir, QStandardItem *parent = 0 );
123 virtual ~ProjectFolderItem();
125 virtual ProjectFolderItem *folder() const;
127 ///Reimplemented from QStandardItem
128 virtual int type() const;
130 /** Get the url of this folder */
131 const KUrl& url() const;
133 /** Get the folder name, equal to url().fileName() but faster (precomputed) */
134 const QString& folderName() const;
136 /** Set the url of this folder */
137 void setUrl( const KUrl& );
139 virtual void setIcon();
141 /** Returns whether it is the project root folder */
142 bool isProjectRoot() const;
144 /** Sets whether it is the project root folder and sets the project name to the item */
145 void setProjectRoot(bool isRoot);
147 /** @returns Returns whether this folder directly contains the specified file or folder. */
148 bool hasFileOrFolder(const QString& name) const;
150 protected:
151 ProjectFolderItem( ProjectFolderItemPrivate& );
152 private:
153 Q_DECLARE_PRIVATE(ProjectFolderItem)
158 * Folder which contains buildable targets as part of a buildable project
160 class ProjectBuildFolderItemPrivate;
161 class KDEVPLATFORMPROJECT_EXPORT ProjectBuildFolderItem: public ProjectFolderItem
163 public:
164 ProjectBuildFolderItem( IProject*, const KUrl &dir, QStandardItem *parent = 0 );
166 ///Reimplemented from QStandardItem
167 virtual int type() const;
169 virtual void setIcon();
171 protected:
172 ProjectBuildFolderItem( ProjectBuildFolderItemPrivate& );
173 private:
174 Q_DECLARE_PRIVATE(ProjectBuildFolderItem)
178 * Object which represents a target in a build system.
180 * This object contains all properties specific to a target.
182 class ProjectTargetItemPrivate;
183 class KDEVPLATFORMPROJECT_EXPORT ProjectTargetItem: public ProjectBaseItem
185 public:
186 ProjectTargetItem( IProject*, const QString &name, QStandardItem *parent = 0 );
188 ///Reimplemented from QStandardItem
189 virtual int type() const;
191 virtual ProjectTargetItem *target() const;
192 virtual void setIcon();
193 protected:
194 ProjectTargetItem( ProjectTargetItemPrivate& );
195 private:
196 Q_DECLARE_PRIVATE(ProjectTargetItem)
200 * Object which represents an executable target in a build system.
202 * This object contains all properties specific to an executable.
204 class KDEVPLATFORMPROJECT_EXPORT ProjectExecutableTargetItem: public ProjectTargetItem
206 public:
207 ProjectExecutableTargetItem( IProject*, const QString &name, QStandardItem *parent = 0 );
209 virtual ProjectExecutableTargetItem *executable() const;
210 virtual int type() const;
211 virtual KUrl builtUrl() const=0;
212 virtual KUrl installedUrl() const=0;
217 * Object which represents a library target in a build system.
219 * This object contains all properties specific to a library.
221 class KDEVPLATFORMPROJECT_EXPORT ProjectLibraryTargetItem: public ProjectTargetItem
223 public:
224 ProjectLibraryTargetItem(IProject* project, const QString &name, QStandardItem *parent = 0 );
226 virtual int type() const;
230 * Object which represents a file.
232 class ProjectFileItemPrivate;
233 class KDEVPLATFORMPROJECT_EXPORT ProjectFileItem: public ProjectBaseItem
235 public:
236 ProjectFileItem( IProject*, const KUrl& file, QStandardItem *parent = 0 );
238 ///Reimplemented from QStandardItem
239 virtual int type() const;
241 virtual ProjectFileItem *file() const;
243 /** Get the url of this file. */
244 const KUrl& url() const;
246 /** Get the file name, equal to url().fileName() but faster (precomputed) */
247 const QString& fileName() const;
249 /** Set the url of this file. */
250 void setUrl( const KUrl& );
252 virtual void setIcon();
254 protected:
255 ProjectFileItem( ProjectFileItemPrivate& );
256 private:
257 Q_DECLARE_PRIVATE(ProjectFileItem)
261 * Class providing some convenience methods for accessing the project model
262 * @TODO: maybe switch to QAbstractItemModel, would make the implementation
263 * for at least the checkbox-behaviour easier
265 class KDEVPLATFORMPROJECT_EXPORT ProjectModel: public QStandardItemModel
267 Q_OBJECT
268 public:
269 ProjectModel( QObject *parent = 0 );
270 virtual ~ProjectModel();
272 using QStandardItemModel::item;
273 ProjectBaseItem *item( const QModelIndex &index ) const;
275 void resetModel();
277 virtual void fetchMore( const QModelIndex &parent );
278 virtual bool canFetchMore( const QModelIndex & parent ) const;
279 private:
280 class ProjectModelPrivate* const d;
285 #endif // KDEVPROJECTMODEL_H