Qt4Project: Do not trigger updateCodeModels on folderChanged

This reverts commit 2fdb70bdce.
Be smarter about what to do on folder changes. Trigger at most
one codemodel update per folder change signal. (Thus still fixing
the original problem 2fdb70b fixed.) And only trigger one if the
actual file list changes. This could be further optimized to only
tell the code model about the new files, but that's for another
patch.

Task-number: QTCREATORBUG-9697
Change-Id: I78d134663f1455254caf812c27c048d4f0828242
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@digia.com>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
Daniel Teske
2013-07-01 11:35:38 +02:00
parent dea9672862
commit cdbbf37743
3 changed files with 80 additions and 10 deletions

View File

@@ -557,7 +557,7 @@ QStringList Qt4PriFileNode::fullVPaths(const QStringList &baseVPaths, QtSupport:
return vPaths; return vPaths;
} }
static QSet<Utils::FileName> recursiveEnumerate(const QString &folder) QSet<Utils::FileName> Qt4PriFileNode::recursiveEnumerate(const QString &folder)
{ {
QSet<Utils::FileName> result; QSet<Utils::FileName> result;
QFileInfo fi(folder); QFileInfo fi(folder);
@@ -718,10 +718,66 @@ void Qt4PriFileNode::watchFolders(const QSet<QString> &folders)
m_watchedFolders = folders; m_watchedFolders = folders;
} }
void Qt4PriFileNode::folderChanged(const QString &changedFolder) bool Qt4PriFileNode::folderChanged(const QString &changedFolder, const QSet<Utils::FileName> &newFiles)
{ {
Q_UNUSED(changedFolder); //qDebug()<<"########## Qt4PriFileNode::folderChanged";
scheduleUpdate(); // So, we need to figure out which files changed.
QSet<Utils::FileName> addedFiles = newFiles;
addedFiles.subtract(m_recursiveEnumerateFiles);
QSet<Utils::FileName> removedFiles = m_recursiveEnumerateFiles;
removedFiles.subtract(newFiles);
foreach (const Utils::FileName &file, removedFiles) {
if (!file.isChildOf(Utils::FileName::fromString(changedFolder)))
removedFiles.remove(file);
}
if (addedFiles.isEmpty() && removedFiles.isEmpty())
return false;
m_recursiveEnumerateFiles = newFiles;
// Apply the differences
// per file type
const QVector<Qt4NodeStaticData::FileTypeData> &fileTypes = qt4NodeStaticData()->fileTypeData;
for (int i = 0; i < fileTypes.size(); ++i) {
FileType type = fileTypes.at(i).type;
QSet<Utils::FileName> add = filterFilesRecursiveEnumerata(type, addedFiles);
QSet<Utils::FileName> remove = filterFilesRecursiveEnumerata(type, removedFiles);
if (!add.isEmpty() || !remove.isEmpty()) {
// Scream :)
// qDebug()<<"For type"<<fileTypes.at(i).typeName<<"\n"
// <<"added files"<<add<<"\n"
// <<"removed files"<<remove;
m_files[type].unite(add);
m_files[type].subtract(remove);
}
}
// Now apply stuff
InternalNode contents;
for (int i = 0; i < fileTypes.size(); ++i) {
FileType type = fileTypes.at(i).type;
if (!m_files[type].isEmpty()) {
InternalNode *subfolder = new InternalNode;
subfolder->type = type;
subfolder->icon = fileTypes.at(i).icon;
subfolder->fullPath = m_projectDir;
subfolder->typeName = fileTypes.at(i).typeName;
subfolder->priority = -i;
subfolder->displayName = fileTypes.at(i).typeName;
contents.virtualfolders.append(subfolder);
// create the hierarchy with subdirectories
subfolder->create(m_projectDir, m_files[type], type);
}
}
contents.updateSubFolders(this, this);
return true;
} }
bool Qt4PriFileNode::deploysFolder(const QString &folder) const bool Qt4PriFileNode::deploysFolder(const QString &folder) const

View File

@@ -162,7 +162,7 @@ public:
bool renameFile(const FileType fileType, bool renameFile(const FileType fileType,
const QString &filePath, const QString &newFilePath); const QString &filePath, const QString &newFilePath);
void folderChanged(const QString &changedFolder); bool folderChanged(const QString &changedFolder, const QSet<Utils::FileName> &newFiles);
bool deploysFolder(const QString &folder) const; bool deploysFolder(const QString &folder) const;
QList<ProjectExplorer::RunConfiguration *> runConfigurationsFor(Node *node); QList<ProjectExplorer::RunConfiguration *> runConfigurationsFor(Node *node);
@@ -172,6 +172,7 @@ public:
// Set by parent // Set by parent
bool includedInExactParse() const; bool includedInExactParse() const;
static QSet<Utils::FileName> recursiveEnumerate(const QString &folder);
protected: protected:
void setIncludedInExactParse(bool b); void setIncludedInExactParse(bool b);
static QStringList varNames(FileType type); static QStringList varNames(FileType type);

View File

@@ -146,7 +146,7 @@ class CentralizedFolderWatcher : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
CentralizedFolderWatcher(QObject *parent); CentralizedFolderWatcher(Qt4Project *parent);
~CentralizedFolderWatcher(); ~CentralizedFolderWatcher();
void watchFolders(const QList<QString> &folders, Qt4ProjectManager::Qt4PriFileNode *node); void watchFolders(const QList<QString> &folders, Qt4ProjectManager::Qt4PriFileNode *node);
void unwatchFolders(const QList<QString> &folders, Qt4ProjectManager::Qt4PriFileNode *node); void unwatchFolders(const QList<QString> &folders, Qt4ProjectManager::Qt4PriFileNode *node);
@@ -157,6 +157,7 @@ private slots:
void delayedFolderChanged(const QString &folder); void delayedFolderChanged(const QString &folder);
private: private:
Qt4Project *m_project;
QSet<QString> recursiveDirs(const QString &folder); QSet<QString> recursiveDirs(const QString &folder);
QFileSystemWatcher m_watcher; QFileSystemWatcher m_watcher;
QMultiMap<QString, Qt4ProjectManager::Qt4PriFileNode *> m_map; QMultiMap<QString, Qt4ProjectManager::Qt4PriFileNode *> m_map;
@@ -1215,7 +1216,8 @@ namespace {
bool debugCFW = false; bool debugCFW = false;
} }
CentralizedFolderWatcher::CentralizedFolderWatcher(QObject *parent) : QObject(parent) CentralizedFolderWatcher::CentralizedFolderWatcher(Qt4Project *parent)
: QObject(parent), m_project(parent)
{ {
m_compressTimer.setSingleShot(true); m_compressTimer.setSingleShot(true);
m_compressTimer.setInterval(200); m_compressTimer.setInterval(200);
@@ -1337,12 +1339,19 @@ void CentralizedFolderWatcher::delayedFolderChanged(const QString &folder)
QString dir = folder; QString dir = folder;
const QChar slash = QLatin1Char('/'); const QChar slash = QLatin1Char('/');
bool newOrRemovedFiles = false;
while (true) { while (true) {
if (!dir.endsWith(slash)) if (!dir.endsWith(slash))
dir.append(slash); dir.append(slash);
QList<Qt4ProjectManager::Qt4PriFileNode *> nodes = m_map.values(dir); QList<Qt4ProjectManager::Qt4PriFileNode *> nodes = m_map.values(dir);
foreach (Qt4ProjectManager::Qt4PriFileNode *node, nodes) { if (!nodes.isEmpty()) {
node->folderChanged(folder); // Collect all the files
QSet<Utils::FileName> newFiles;
newFiles += Qt4PriFileNode::recursiveEnumerate(folder);
foreach (Qt4ProjectManager::Qt4PriFileNode *node, nodes) {
newOrRemovedFiles = newOrRemovedFiles
|| node->folderChanged(folder, newFiles);
}
} }
// Chop off last part, and break if there's nothing to chop off // Chop off last part, and break if there's nothing to chop off
@@ -1357,7 +1366,6 @@ void CentralizedFolderWatcher::delayedFolderChanged(const QString &folder)
dir.truncate(index + 1); dir.truncate(index + 1);
} }
QString folderWithSlash = folder; QString folderWithSlash = folder;
if (!folder.endsWith(slash)) if (!folder.endsWith(slash))
folderWithSlash.append(slash); folderWithSlash.append(slash);
@@ -1374,6 +1382,11 @@ void CentralizedFolderWatcher::delayedFolderChanged(const QString &folder)
m_watcher.addPaths(tmp.toList()); m_watcher.addPaths(tmp.toList());
m_recursiveWatchedFolders += tmp; m_recursiveWatchedFolders += tmp;
} }
if (newOrRemovedFiles) {
m_project->updateFileList();
m_project->updateCodeModels();
}
} }
bool Qt4Project::needsConfiguration() const bool Qt4Project::needsConfiguration() const