diff options
author | Tobias Hunger <tobias.hunger@digia.com> | 2013-01-16 15:27:03 +0100 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@digia.com> | 2013-01-21 13:40:03 +0100 |
commit | 459d471c2f9ddc9c4023c8396866e168f2a9e2ba (patch) | |
tree | 6840326f3b0aa51b52a12d3ba57ddd8f23a988e3 /src | |
parent | 1edce87173acbef69df733fe1aef348afbeae4ba (diff) | |
download | qt-creator-459d471c2f9ddc9c4023c8396866e168f2a9e2ba.tar.gz |
Allow for disabled nodes in Projects view
Change-Id: I8b9a2666c8efdc5981adfe6a3a032884a6e50d2a
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/projectexplorer/project.h | 3 | ||||
-rw-r--r-- | src/plugins/projectexplorer/projectmodels.cpp | 13 | ||||
-rw-r--r-- | src/plugins/projectexplorer/projectmodels.h | 2 | ||||
-rw-r--r-- | src/plugins/projectexplorer/projectnodes.cpp | 11 | ||||
-rw-r--r-- | src/plugins/projectexplorer/projectnodes.h | 13 | ||||
-rw-r--r-- | src/plugins/projectexplorer/projecttreewidget.cpp | 20 |
6 files changed, 60 insertions, 2 deletions
diff --git a/src/plugins/projectexplorer/project.h b/src/plugins/projectexplorer/project.h index cef039e816..78610a0d13 100644 --- a/src/plugins/projectexplorer/project.h +++ b/src/plugins/projectexplorer/project.h @@ -63,7 +63,8 @@ public: // Roles to be implemented by all models that are exported via model() enum ModelRoles { // Absolute file path - FilePathRole = QFileSystemModel::FilePathRole + FilePathRole = QFileSystemModel::FilePathRole, + EnabledRole }; Project(); diff --git a/src/plugins/projectexplorer/projectmodels.cpp b/src/plugins/projectexplorer/projectmodels.cpp index 9e08a27505..07fd6ad6af 100644 --- a/src/plugins/projectexplorer/projectmodels.cpp +++ b/src/plugins/projectexplorer/projectmodels.cpp @@ -197,6 +197,9 @@ FlatModel::FlatModel(SessionNode *rootNode, QObject *parent) this, SLOT(filesAboutToBeRemoved(FolderNode*,QList<FileNode*>))); connect(watcher, SIGNAL(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 @@ -296,6 +299,10 @@ QVariant FlatModel::data(const QModelIndex &index, int role) const result = node->path(); break; } + case ProjectExplorer::Project::EnabledRole: { + result = node->isEnabled(); + break; + } } } @@ -847,6 +854,12 @@ void FlatModel::filesRemoved() // Do nothing } +void FlatModel::nodeUpdated(Node *node) +{ + QModelIndex idx = indexForNode(node); + emit dataChanged(idx, idx); +} + namespace ProjectExplorer { namespace Internal { diff --git a/src/plugins/projectexplorer/projectmodels.h b/src/plugins/projectexplorer/projectmodels.h index 0032a2cb2c..b4197439d7 100644 --- a/src/plugins/projectexplorer/projectmodels.h +++ b/src/plugins/projectexplorer/projectmodels.h @@ -93,6 +93,8 @@ private slots: void filesAboutToBeRemoved(FolderNode *folder, const QList<FileNode*> &staleFiles); void filesRemoved(); + void nodeUpdated(ProjectExplorer::Node *node); + private: void added(FolderNode* folderNode, const QList<Node*> &newNodeList); void removed(FolderNode* parentNode, const QList<Node*> &newNodeList); diff --git a/src/plugins/projectexplorer/projectnodes.cpp b/src/plugins/projectexplorer/projectnodes.cpp index 45a18c0094..696ca553e8 100644 --- a/src/plugins/projectexplorer/projectnodes.cpp +++ b/src/plugins/projectexplorer/projectnodes.cpp @@ -117,6 +117,11 @@ QString Node::tooltip() const return QDir::toNativeSeparators(path()); } +bool Node::isEnabled() const +{ + return parentFolderNode()->isEnabled(); +} + void Node::setNodeType(NodeType type) { m_nodeType = type; @@ -127,6 +132,12 @@ void Node::setProjectNode(ProjectNode *project) m_projectNode = project; } +void Node::emitNodeUpdated() +{ + foreach (NodesWatcher *watcher, projectNode()->watchers()) + emit watcher->nodeUpdated(this); +} + void Node::setParentFolderNode(FolderNode *parentFolder) { m_folderNode = parentFolder; diff --git a/src/plugins/projectexplorer/projectnodes.h b/src/plugins/projectexplorer/projectnodes.h index 5cbdee4a9a..0b2f2e0945 100644 --- a/src/plugins/projectexplorer/projectnodes.h +++ b/src/plugins/projectexplorer/projectnodes.h @@ -88,6 +88,7 @@ public: virtual QString displayName() const; virtual QString vcsTopic() const; virtual QString tooltip() const; + virtual bool isEnabled() const; protected: Node(NodeType nodeType, const QString &path); @@ -96,6 +97,8 @@ protected: void setProjectNode(ProjectNode *project); void setParentFolderNode(FolderNode *parentFolder); + void emitNodeUpdated(); + private: NodeType m_nodeType; ProjectNode *m_projectNode; @@ -228,6 +231,8 @@ public: void accept(NodesVisitor *visitor); + bool isEnabled() const { return true; } + protected: // this is just the in-memory representation, a subclass // will add the persistent stuff @@ -270,6 +275,8 @@ public: void accept(NodesVisitor *visitor); + bool isEnabled() const { return true; } + protected: void addProjectNodes(const QList<ProjectNode*> &projectNodes); void removeProjectNodes(const QList<ProjectNode*> &projectNodes); @@ -289,6 +296,11 @@ public: explicit NodesWatcher(QObject *parent = 0); signals: + // everything + + // Emited whenever the model needs to send a update signal. + void nodeUpdated(ProjectExplorer::Node *node); + // projects void aboutToChangeHasBuildTargets(ProjectExplorer::ProjectNode*); void hasBuildTargetsChanged(ProjectExplorer::ProjectNode *node); @@ -316,6 +328,7 @@ private: // let project & session emit signals friend class ProjectNode; friend class SessionNode; + friend class Node; }; diff --git a/src/plugins/projectexplorer/projecttreewidget.cpp b/src/plugins/projectexplorer/projecttreewidget.cpp index 313eab457a..8e72e423cb 100644 --- a/src/plugins/projectexplorer/projecttreewidget.cpp +++ b/src/plugins/projectexplorer/projecttreewidget.cpp @@ -49,6 +49,7 @@ #include <QSettings> #include <QHeaderView> +#include <QStyledItemDelegate> #include <QTreeView> #include <QVBoxLayout> #include <QToolButton> @@ -62,7 +63,23 @@ using namespace ProjectExplorer; using namespace ProjectExplorer::Internal; 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 @@ -115,6 +132,7 @@ ProjectTreeWidget::ProjectTreeWidget(QWidget *parent) m_view = new ProjectTreeView; m_view->setModel(m_model); + m_view->setItemDelegate(new ProjectTreeItemDelegate(this)); setFocusProxy(m_view); initView(); |