qbsnodes.h 6.74 KB
Newer Older
1 2
/****************************************************************************
**
3 4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
5 6 7 8 9 10 11
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
12 13 14
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
15
**
16 17 18 19 20 21 22
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 24 25
**
****************************************************************************/

hjk's avatar
hjk committed
26
#pragma once
27 28 29

#include <projectexplorer/projectnodes.h>

30
#include <qbs.h>
31

32 33
#include <QIcon>

34 35 36 37
namespace QbsProjectManager {
namespace Internal {

class FileTreeNode;
38
class QbsProject;
39 40 41 42 43 44 45 46 47
class QbsProjectFile;

// ----------------------------------------------------------------------
// QbsFileNode:
// ----------------------------------------------------------------------

class QbsFileNode : public ProjectExplorer::FileNode
{
public:
48
    QbsFileNode(const Utils::FileName &filePath, const ProjectExplorer::FileType fileType, bool generated,
49 50
                int line);

51
    QString displayName() const override;
52 53
};

54 55 56 57 58 59 60
class QbsFolderNode : public ProjectExplorer::FolderNode
{
public:
    QbsFolderNode(const Utils::FileName &folderPath, ProjectExplorer::NodeType nodeType,
                  const QString &displayName);

private:
61
    QList<ProjectExplorer::ProjectAction> supportedActions(ProjectExplorer::Node *node) const override;
62 63
};

64 65 66 67
// ---------------------------------------------------------------------------
// QbsBaseProjectNode:
// ---------------------------------------------------------------------------

68 69
class QbsGroupNode;

70 71 72
class QbsBaseProjectNode : public ProjectExplorer::ProjectNode
{
public:
73
    explicit QbsBaseProjectNode(const Utils::FileName &absoluteFilePath);
74

75
    bool showInSimpleTree() const override;
76

77
    QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const override;
78 79
private:
    friend class QbsGroupNode;
80 81 82 83 84 85 86 87 88
};

// --------------------------------------------------------------------
// QbsGroupNode:
// --------------------------------------------------------------------

class QbsGroupNode : public QbsBaseProjectNode
{
public:
89
    QbsGroupNode(const qbs::GroupData &grp, const QString &productPath);
90

91 92 93 94 95
    bool isEnabled() const override;
    QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const override;
    bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0) override;
    bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0) override;
    bool renameFile(const QString &filePath, const QString &newFilePath) override;
96
    void updateQbsGroupData(const qbs::GroupData &grp, const QString &productPath,
97
                            bool productWasEnabled, bool productIsEnabled);
98

99
    qbs::GroupData qbsGroupData() const { return m_qbsGroupData; }
100

101 102
    QString productPath() const;

103 104
    // group can be invalid
    static void setupFiles(FolderNode *root, const qbs::GroupData &group, const QStringList &files,
105
                           const QString &productPath, bool updateExisting);
106

107
private:
108 109 110 111
    static void setupFolder(ProjectExplorer::FolderNode *folder,
                            const QHash<QString, ProjectExplorer::FileType> &fileTypeHash,
                            const FileTreeNode *subFileTree, const QString &baseDir,
                            bool updateExisting);
112
    static ProjectExplorer::FileType fileType(const qbs::SourceArtifact &artifact);
113

114
    qbs::GroupData m_qbsGroupData;
115
    QString m_productPath;
116 117

    static QIcon m_groupIcon;
118 119 120 121 122 123 124 125 126
};

// --------------------------------------------------------------------
// QbsProductNode:
// --------------------------------------------------------------------

class QbsProductNode : public QbsBaseProjectNode
{
public:
127
    explicit QbsProductNode(const qbs::Project &project, const qbs::ProductData &prd);
128

129 130 131 132 133 134
    bool isEnabled() const override;
    bool showInSimpleTree() const override;
    QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const override;
    bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0) override;
    bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0) override;
    bool renameFile(const QString &filePath, const QString &newFilePath) override;
135

136
    void setQbsProductData(const qbs::Project &project, const qbs::ProductData prd);
137
    const qbs::ProductData qbsProductData() const { return m_qbsProductData; }
138

139
    QList<ProjectExplorer::RunConfiguration *> runConfigurations() const override;
140

141 142 143
private:
    QbsGroupNode *findGroupNode(const QString &name);

144
    qbs::ProductData m_qbsProductData;
145
    static QIcon m_productIcon;
146 147 148 149 150 151 152 153 154
};

// ---------------------------------------------------------------------------
// QbsProjectNode:
// ---------------------------------------------------------------------------

class QbsProjectNode : public QbsBaseProjectNode
{
public:
155
    explicit QbsProjectNode(const Utils::FileName &absoluteFilePath);
156
    ~QbsProjectNode() override;
157

158
    virtual QbsProject *project() const;
159
    const qbs::Project qbsProject() const;
160
    const qbs::ProjectData qbsProjectData() const { return m_projectData; }
161

162
    bool showInSimpleTree() const override;
Tobias Hunger's avatar
Tobias Hunger committed
163

164
protected:
165
    void update(const qbs::Project &qbsProject, const qbs::ProjectData &prjData);
166

167 168 169
private:
    void ctor();

170
    QbsProductNode *findProductNode(const QString &uniqueName);
Tobias Hunger's avatar
Tobias Hunger committed
171
    QbsProjectNode *findProjectNode(const QString &name);
172

173
    static QIcon m_projectIcon;
174
    qbs::ProjectData m_projectData;
175
};
176

177 178 179 180
// --------------------------------------------------------------------
// QbsRootProjectNode:
// --------------------------------------------------------------------

181 182 183 184 185 186 187 188
class QbsRootProjectNode : public QbsProjectNode
{
public:
    explicit QbsRootProjectNode(QbsProject *project);

    using QbsProjectNode::update;
    void update();

189
    QbsProject *project() const  override { return m_project; }
190 191

private:
192 193
    QStringList unreferencedBuildSystemFiles(const qbs::Project &p) const;

194
    QbsProject *const m_project;
195
    ProjectExplorer::FolderNode *m_buildSystemFiles;
196 197 198
};


199 200
} // namespace Internal
} // namespace QbsProjectManager