Commit 459d471c authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Allow for disabled nodes in Projects view



Change-Id: I8b9a2666c8efdc5981adfe6a3a032884a6e50d2a
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent 1edce871
...@@ -63,7 +63,8 @@ public: ...@@ -63,7 +63,8 @@ public:
// Roles to be implemented by all models that are exported via model() // Roles to be implemented by all models that are exported via model()
enum ModelRoles { enum ModelRoles {
// Absolute file path // Absolute file path
FilePathRole = QFileSystemModel::FilePathRole FilePathRole = QFileSystemModel::FilePathRole,
EnabledRole
}; };
Project(); Project();
......
...@@ -197,6 +197,9 @@ FlatModel::FlatModel(SessionNode *rootNode, QObject *parent) ...@@ -197,6 +197,9 @@ FlatModel::FlatModel(SessionNode *rootNode, QObject *parent)
this, SLOT(filesAboutToBeRemoved(FolderNode*,QList<FileNode*>))); this, SLOT(filesAboutToBeRemoved(FolderNode*,QList<FileNode*>)));
connect(watcher, SIGNAL(filesRemoved()), connect(watcher, SIGNAL(filesRemoved()),
this, SLOT(filesRemoved())); this, SLOT(filesRemoved()));
connect(watcher, SIGNAL(nodeUpdated(ProjectExplorer::Node*)),
this, SLOT(nodeUpdated(ProjectExplorer::Node*)));
} }
QModelIndex FlatModel::index(int row, int column, const QModelIndex &parent) const QModelIndex FlatModel::index(int row, int column, const QModelIndex &parent) const
...@@ -296,6 +299,10 @@ QVariant FlatModel::data(const QModelIndex &index, int role) const ...@@ -296,6 +299,10 @@ QVariant FlatModel::data(const QModelIndex &index, int role) const
result = node->path(); result = node->path();
break; break;
} }
case ProjectExplorer::Project::EnabledRole: {
result = node->isEnabled();
break;
}
} }
} }
...@@ -847,6 +854,12 @@ void FlatModel::filesRemoved() ...@@ -847,6 +854,12 @@ void FlatModel::filesRemoved()
// Do nothing // Do nothing
} }
void FlatModel::nodeUpdated(Node *node)
{
QModelIndex idx = indexForNode(node);
emit dataChanged(idx, idx);
}
namespace ProjectExplorer { namespace ProjectExplorer {
namespace Internal { namespace Internal {
......
...@@ -93,6 +93,8 @@ private slots: ...@@ -93,6 +93,8 @@ private slots:
void filesAboutToBeRemoved(FolderNode *folder, const QList<FileNode*> &staleFiles); void filesAboutToBeRemoved(FolderNode *folder, const QList<FileNode*> &staleFiles);
void filesRemoved(); void filesRemoved();
void nodeUpdated(ProjectExplorer::Node *node);
private: private:
void added(FolderNode* folderNode, const QList<Node*> &newNodeList); void added(FolderNode* folderNode, const QList<Node*> &newNodeList);
void removed(FolderNode* parentNode, const QList<Node*> &newNodeList); void removed(FolderNode* parentNode, const QList<Node*> &newNodeList);
......
...@@ -117,6 +117,11 @@ QString Node::tooltip() const ...@@ -117,6 +117,11 @@ QString Node::tooltip() const
return QDir::toNativeSeparators(path()); return QDir::toNativeSeparators(path());
} }
bool Node::isEnabled() const
{
return parentFolderNode()->isEnabled();
}
void Node::setNodeType(NodeType type) void Node::setNodeType(NodeType type)
{ {
m_nodeType = type; m_nodeType = type;
...@@ -127,6 +132,12 @@ void Node::setProjectNode(ProjectNode *project) ...@@ -127,6 +132,12 @@ void Node::setProjectNode(ProjectNode *project)
m_projectNode = project; m_projectNode = project;
} }
void Node::emitNodeUpdated()
{
foreach (NodesWatcher *watcher, projectNode()->watchers())
emit watcher->nodeUpdated(this);
}
void Node::setParentFolderNode(FolderNode *parentFolder) void Node::setParentFolderNode(FolderNode *parentFolder)
{ {
m_folderNode = parentFolder; m_folderNode = parentFolder;
......
...@@ -88,6 +88,7 @@ public: ...@@ -88,6 +88,7 @@ public:
virtual QString displayName() const; virtual QString displayName() const;
virtual QString vcsTopic() const; virtual QString vcsTopic() const;
virtual QString tooltip() const; virtual QString tooltip() const;
virtual bool isEnabled() const;
protected: protected:
Node(NodeType nodeType, const QString &path); Node(NodeType nodeType, const QString &path);
...@@ -96,6 +97,8 @@ protected: ...@@ -96,6 +97,8 @@ protected:
void setProjectNode(ProjectNode *project); void setProjectNode(ProjectNode *project);
void setParentFolderNode(FolderNode *parentFolder); void setParentFolderNode(FolderNode *parentFolder);
void emitNodeUpdated();
private: private:
NodeType m_nodeType; NodeType m_nodeType;
ProjectNode *m_projectNode; ProjectNode *m_projectNode;
...@@ -228,6 +231,8 @@ public: ...@@ -228,6 +231,8 @@ public:
void accept(NodesVisitor *visitor); void accept(NodesVisitor *visitor);
bool isEnabled() const { return true; }
protected: protected:
// this is just the in-memory representation, a subclass // this is just the in-memory representation, a subclass
// will add the persistent stuff // will add the persistent stuff
...@@ -270,6 +275,8 @@ public: ...@@ -270,6 +275,8 @@ public:
void accept(NodesVisitor *visitor); void accept(NodesVisitor *visitor);
bool isEnabled() const { return true; }
protected: protected:
void addProjectNodes(const QList<ProjectNode*> &projectNodes); void addProjectNodes(const QList<ProjectNode*> &projectNodes);
void removeProjectNodes(const QList<ProjectNode*> &projectNodes); void removeProjectNodes(const QList<ProjectNode*> &projectNodes);
...@@ -289,6 +296,11 @@ public: ...@@ -289,6 +296,11 @@ public:
explicit NodesWatcher(QObject *parent = 0); explicit NodesWatcher(QObject *parent = 0);
signals: signals:
// everything
// Emited whenever the model needs to send a update signal.
void nodeUpdated(ProjectExplorer::Node *node);
// projects // projects
void aboutToChangeHasBuildTargets(ProjectExplorer::ProjectNode*); void aboutToChangeHasBuildTargets(ProjectExplorer::ProjectNode*);
void hasBuildTargetsChanged(ProjectExplorer::ProjectNode *node); void hasBuildTargetsChanged(ProjectExplorer::ProjectNode *node);
...@@ -316,6 +328,7 @@ private: ...@@ -316,6 +328,7 @@ private:
// let project & session emit signals // let project & session emit signals
friend class ProjectNode; friend class ProjectNode;
friend class SessionNode; friend class SessionNode;
friend class Node;
}; };
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include <QSettings> #include <QSettings>
#include <QHeaderView> #include <QHeaderView>
#include <QStyledItemDelegate>
#include <QTreeView> #include <QTreeView>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QToolButton> #include <QToolButton>
...@@ -62,7 +63,23 @@ using namespace ProjectExplorer; ...@@ -62,7 +63,23 @@ using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal; using namespace ProjectExplorer::Internal;
namespace { namespace {
bool debug = false;
class ProjectTreeItemDelegate : public QStyledItemDelegate
{
public:
ProjectTreeItemDelegate(QObject *parent) : QStyledItemDelegate(parent)
{ }
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionViewItem opt = option;
if (!index.data(ProjectExplorer::Project::EnabledRole).toBool())
opt.state &= ~QStyle::State_Enabled;
QStyledItemDelegate::paint(painter, opt, index);
}
};
bool debug = false;
} }
class ProjectTreeView : public Utils::NavigationTreeView class ProjectTreeView : public Utils::NavigationTreeView
...@@ -115,6 +132,7 @@ ProjectTreeWidget::ProjectTreeWidget(QWidget *parent) ...@@ -115,6 +132,7 @@ ProjectTreeWidget::ProjectTreeWidget(QWidget *parent)
m_view = new ProjectTreeView; m_view = new ProjectTreeView;
m_view->setModel(m_model); m_view->setModel(m_model);
m_view->setItemDelegate(new ProjectTreeItemDelegate(this));
setFocusProxy(m_view); setFocusProxy(m_view);
initView(); initView();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment