Commit b88cdef0 authored by Daniel Teske's avatar Daniel Teske

ProjectTree: Fix signal emissions for nodes that are not yet mapped

The Generic Project Manager builds the tree from the bottom to the
top. Previously no signals were emitted while doing that since
the watchers were added on adding the top level node at the end.

With the new ProjectTree that leads to lots of signals, and leaves
the FlatModel confussed, as that expects the nodes to be already
in the hierarchy and crashes otherwise.

Restore this behavior by checking if the affected nodes are in
the hierarchy.

Change-Id: I832b348867a8abad2afef11297b44f058592cb1d
Reviewed-by: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
Reviewed-by: default avatarDaniel Teske <daniel.teske@theqtcompany.com>
parent d573195b
......@@ -89,7 +89,7 @@ void Node::emitNodeSortKeyAboutToChange()
void Node::emitNodeSortKeyChanged()
{
if (parentFolderNode())
ProjectTree::instance()->emitNodeSortKeyChanged();
ProjectTree::instance()->emitNodeSortKeyChanged(this);
}
/*!
......@@ -387,7 +387,7 @@ void FolderNode::addFileNodes(const QList<FileNode *> &files)
}
}
ProjectTree::instance()->emitFilesAdded();
ProjectTree::instance()->emitFilesAdded(this);
}
/*!
......@@ -422,7 +422,7 @@ void FolderNode::removeFileNodes(const QList<FileNode *> &files)
filesIter = m_fileNodes.erase(filesIter);
}
ProjectTree::instance()->emitFilesRemoved();
ProjectTree::instance()->emitFilesRemoved(this);
}
/*!
......@@ -462,7 +462,7 @@ void FolderNode::addFolderNodes(const QList<FolderNode*> &subFolders)
qDebug("project nodes have to be added via addProjectNodes"));
}
ProjectTree::instance()->emitFoldersAdded();
ProjectTree::instance()->emitFoldersAdded(this);
}
/*!
......@@ -497,7 +497,7 @@ void FolderNode::removeFolderNodes(const QList<FolderNode*> &subFolders)
folderIter = m_subFolderNodes.erase(folderIter);
}
ProjectTree::instance()->emitFoldersRemoved();
ProjectTree::instance()->emitFoldersRemoved(this);
}
bool FolderNode::showInSimpleTree() const
......@@ -635,7 +635,7 @@ void ProjectNode::addProjectNodes(const QList<ProjectNode*> &subProjects)
Utils::sort(m_subFolderNodes);
Utils::sort(m_subProjectNodes);
ProjectTree::instance()->emitFoldersAdded();
ProjectTree::instance()->emitFoldersAdded(this);
}
}
......@@ -675,7 +675,7 @@ void ProjectNode::removeProjectNodes(const QList<ProjectNode*> &subProjects)
folderIter = m_subFolderNodes.erase(folderIter);
}
ProjectTree::instance()->emitFoldersRemoved();
ProjectTree::instance()->emitFoldersRemoved(this);
}
}
......@@ -712,7 +712,7 @@ bool SessionNode::showInSimpleTree() const
void SessionNode::projectDisplayNameChanged(Node *node)
{
ProjectTree::instance()->emitNodeSortKeyAboutToChange(node);
ProjectTree::instance()->emitNodeSortKeyChanged();
ProjectTree::instance()->emitNodeSortKeyChanged(node);
}
QList<ProjectNode*> SessionNode::projectNodes() const
......@@ -740,7 +740,7 @@ void SessionNode::addProjectNodes(const QList<ProjectNode*> &projectNodes)
Utils::sort(m_subFolderNodes);
Utils::sort(m_projectNodes);
ProjectTree::instance()->emitFoldersAdded();
ProjectTree::instance()->emitFoldersAdded(this);
}
}
......@@ -773,6 +773,6 @@ void SessionNode::removeProjectNodes(const QList<ProjectNode*> &projectNodes)
folderIter = m_subFolderNodes.erase(folderIter);
}
ProjectTree::instance()->emitFoldersRemoved();
ProjectTree::instance()->emitFoldersRemoved(this);
}
}
......@@ -232,26 +232,38 @@ void ProjectTree::updateContext()
void ProjectTree::emitNodeUpdated(Node *node)
{
if (!isInNodeHierarchy(node))
return;
emit nodeUpdated(node);
}
void ProjectTree::emitAboutToChangeShowInSimpleTree(FolderNode *node)
{
if (!isInNodeHierarchy(node))
return;
emit aboutToChangeShowInSimpleTree(node);
}
void ProjectTree::emitShowInSimpleTreeChanged(FolderNode *node)
{
if (!isInNodeHierarchy(node))
return;
emit showInSimpleTreeChanged(node);
}
void ProjectTree::emitFoldersAboutToBeAdded(FolderNode *parentFolder, const QList<FolderNode *> &newFolders)
{
if (!isInNodeHierarchy(parentFolder))
return;
emit foldersAboutToBeAdded(parentFolder, newFolders);
}
void ProjectTree::emitFoldersAdded()
void ProjectTree::emitFoldersAdded(FolderNode *folder)
{
if (!isInNodeHierarchy(folder))
return;
emit foldersAdded();
if (Utils::anyOf(m_projectTreeWidgets, &ProjectTreeWidget::hasFocus))
......@@ -262,6 +274,9 @@ void ProjectTree::emitFoldersAdded()
void ProjectTree::emitFoldersAboutToBeRemoved(FolderNode *parentFolder, const QList<FolderNode *> &staleFolders)
{
if (!isInNodeHierarchy(parentFolder))
return;
Node *n = ProjectTree::currentNode();
while (n) {
if (FolderNode *fn = dynamic_cast<FolderNode *>(n)) {
......@@ -279,8 +294,11 @@ void ProjectTree::emitFoldersAboutToBeRemoved(FolderNode *parentFolder, const QL
emit foldersAboutToBeRemoved(parentFolder, staleFolders);
}
void ProjectTree::emitFoldersRemoved()
void ProjectTree::emitFoldersRemoved(FolderNode *folder)
{
if (!isInNodeHierarchy(folder))
return;
emit foldersRemoved();
if (m_resetCurrentNodeFolder) {
......@@ -291,11 +309,16 @@ void ProjectTree::emitFoldersRemoved()
void ProjectTree::emitFilesAboutToBeAdded(FolderNode *folder, const QList<FileNode *> &newFiles)
{
if (!isInNodeHierarchy(folder))
return;
emit filesAboutToBeAdded(folder, newFiles);
}
void ProjectTree::emitFilesAdded()
void ProjectTree::emitFilesAdded(FolderNode *folder)
{
if (!isInNodeHierarchy(folder))
return;
emit filesAdded();
if (Utils::anyOf(m_projectTreeWidgets, &ProjectTreeWidget::hasFocus))
......@@ -306,6 +329,9 @@ void ProjectTree::emitFilesAdded()
void ProjectTree::emitFilesAboutToBeRemoved(FolderNode *folder, const QList<FileNode *> &staleFiles)
{
if (!isInNodeHierarchy(folder))
return;
if (FileNode *fileNode = dynamic_cast<FileNode *>(m_currentNode))
if (staleFiles.contains(fileNode))
m_resetCurrentNodeFile = false;
......@@ -313,8 +339,10 @@ void ProjectTree::emitFilesAboutToBeRemoved(FolderNode *folder, const QList<File
emit filesAboutToBeRemoved(folder, staleFiles);
}
void ProjectTree::emitFilesRemoved()
void ProjectTree::emitFilesRemoved(FolderNode *folder)
{
if (!isInNodeHierarchy(folder))
return;
emit filesRemoved();
if (m_resetCurrentNodeFile) {
......@@ -325,11 +353,15 @@ void ProjectTree::emitFilesRemoved()
void ProjectTree::emitNodeSortKeyAboutToChange(Node *node)
{
if (!isInNodeHierarchy(node))
return;
emit nodeSortKeyAboutToChange(node);
}
void ProjectTree::emitNodeSortKeyChanged()
void ProjectTree::emitNodeSortKeyChanged(Node *node)
{
if (!isInNodeHierarchy(node))
return;
emit nodeSortKeyChanged();
}
......@@ -372,3 +404,14 @@ bool ProjectTree::hasFocus(ProjectTreeWidget *widget)
{
return widget && widget->focusWidget() && widget->focusWidget()->hasFocus();
}
bool ProjectTree::isInNodeHierarchy(Node *n)
{
Node *sessionNode = SessionManager::sessionNode();
do {
if (n == sessionNode)
return true;
n = n->parentFolderNode();
} while (n);
return false;
}
......@@ -104,22 +104,22 @@ public: // for nodes to emit signals, do not call unless you are a node
// folders & projects
void emitFoldersAboutToBeAdded(FolderNode *parentFolder,
const QList<FolderNode*> &newFolders);
void emitFoldersAdded();
void emitFoldersAdded(FolderNode *folder);
void emitFoldersAboutToBeRemoved(FolderNode *parentFolder,
const QList<FolderNode*> &staleFolders);
void emitFoldersRemoved();
void emitFoldersRemoved(FolderNode *folder);
// files
void emitFilesAboutToBeAdded(FolderNode *folder,
const QList<FileNode*> &newFiles);
void emitFilesAdded();
void emitFilesAdded(FolderNode *folder);
void emitFilesAboutToBeRemoved(FolderNode *folder,
const QList<FileNode*> &staleFiles);
void emitFilesRemoved();
void emitFilesRemoved(FolderNode *folder);
void emitNodeSortKeyAboutToChange(Node *node);
void emitNodeSortKeyChanged();
void emitNodeSortKeyChanged(Node *node);
private:
void focusChanged();
......@@ -133,6 +133,8 @@ private:
void updateExternalFileWarning();
static bool hasFocus(Internal::ProjectTreeWidget *widget);
void hideContextMenu();
bool isInNodeHierarchy(Node *n);
private:
static ProjectTree *s_instance;
......
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