Commit 5a5a464d authored by Tobias Hunger's avatar Tobias Hunger
Browse files

ProjectNodes: Introduce FolderNode::replaceSubtree



Introduce FolderNode::replaceSubtree incl. necessary signalling

Change-Id: I57762cd24a2986d3a04d0de6b794c1f6c772dbe6
Reviewed-by: default avatarhjk <hjk@qt.io>
parent 4b539cf5
......@@ -78,7 +78,8 @@ FlatModel::FlatModel(QObject *parent)
ProjectTree *tree = ProjectTree::instance();
connect(tree, &ProjectTree::dataChanged, this, &FlatModel::update);
connect(tree, &ProjectTree::nodeUpdated, this, &FlatModel::nodeUpdated);
connect(tree, &ProjectTree::nodeUpdated, this, &FlatModel::update);
connect(tree, &ProjectTree::subtreeChanged, this, &FlatModel::update);
SessionManager *sm = SessionManager::instance();
connect(sm, &SessionManager::projectRemoved, this, &FlatModel::update);
......@@ -394,11 +395,6 @@ bool isSorted(const QList<Node *> &nodes)
return true;
}
void FlatModel::nodeUpdated(Node *)
{
update();
}
namespace Internal {
int caseFriendlyCompare(const QString &a, const QString &b)
......
......@@ -85,8 +85,6 @@ signals:
void requestExpansion(const QModelIndex &index);
private:
void nodeUpdated(ProjectExplorer::Node *node);
bool filter(Node *node) const; // Returns true if node is hidden.
bool m_filterProjects = false;
......
......@@ -43,6 +43,8 @@
#include <QIcon>
#include <QStyle>
#include <memory>
namespace ProjectExplorer {
static FolderNode *folderNode(const FolderNode *folder, const Utils::FileName &directory)
......@@ -494,6 +496,29 @@ void FolderNode::compress()
}
}
bool FolderNode::replaceSubtree(Node *oldNode, Node *newNode)
{
std::unique_ptr<Node> nn(newNode);
if (!oldNode) {
addNode(nn.release()); // Happens e.g. when a project is registered
} else {
auto it = std::find_if(m_nodes.begin(), m_nodes.end(),
[oldNode](const Node *n) { return oldNode == n; });
QTC_ASSERT(it != m_nodes.end(), return false);
if (nn) {
nn->setParentFolderNode(this);
*it = nn.release();
} else {
removeNode(oldNode); // Happens e.g. when project is shutting down
}
delete oldNode;
}
ProjectTree::emitSubtreeChanged(this);
return true;
}
void FolderNode::setDisplayName(const QString &name)
{
if (m_displayName == name)
......
......@@ -201,6 +201,10 @@ public:
void buildTree(QList<FileNode *> &files, const Utils::FileName &overrideBaseDir = Utils::FileName());
void compress();
// takes ownership of newNode.
// Will delete newNode if oldNode is not a child of this node.
bool replaceSubtree(Node *oldNode, Node *newNode);
void setDisplayName(const QString &name);
void setIcon(const QIcon &icon);
......
......@@ -266,6 +266,13 @@ void ProjectTree::emitNodeUpdated(Node *node)
emit s_instance->nodeUpdated(node);
}
void ProjectTree::emitSubtreeChanged(Node *node)
{
if (!s_instance->isInNodeHierarchy(node))
return;
emit s_instance->subtreeChanged(node);
}
void ProjectTree::emitDataChanged()
{
instance()->dataChanged();
......
......@@ -68,6 +68,7 @@ signals:
// Emitted whenever the model needs to send a update signal.
void nodeUpdated(ProjectExplorer::Node *node);
void subtreeChanged(ProjectExplorer::Node *node);
void dataChanged();
void aboutToShowContextMenu(ProjectExplorer::Project *project,
......@@ -75,6 +76,7 @@ signals:
public: // for nodes to emit signals, do not call unless you are a node
static void emitNodeUpdated(ProjectExplorer::Node *node);
static void emitSubtreeChanged(ProjectExplorer::Node *node);
static void emitDataChanged();
void collapseAll();
......
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