forked from qt-creator/qt-creator
Allow for disabled nodes in Projects view
Change-Id: I8b9a2666c8efdc5981adfe6a3a032884a6e50d2a Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
@@ -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();
|
||||
|
@@ -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 {
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -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();
|
||||
|
||||
|
Reference in New Issue
Block a user