forked from qt-creator/qt-creator
Don't pass explicitly the QFutureInterface into Utils::runAsync
Don't pass the QFutureInterface by lambda capture to the lambda. Instead, define additional argument to the lambda. The QFutureInterface will be instantiated by the runAsync itself. Change-Id: Id3a12f306e91f76239134312bb46f7d8aefd03a4 Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -382,10 +382,11 @@ FileType FileNode::fileType() const
|
||||
return m_fileType;
|
||||
}
|
||||
|
||||
static QList<FileNode *> scanForFilesRecursively(const Utils::FilePath &directory,
|
||||
const std::function<FileNode *(const Utils::FilePath &)> factory,
|
||||
QSet<QString> &visited, QFutureInterface<QList<FileNode*>> *future,
|
||||
static QList<FileNode *> scanForFilesRecursively(QFutureInterface<QList<FileNode*>> &future,
|
||||
double progressStart, double progressRange,
|
||||
const Utils::FilePath &directory,
|
||||
const std::function<FileNode *(const Utils::FilePath &)> factory,
|
||||
QSet<QString> &visited,
|
||||
const QList<Core::IVersionControl*> &versionControls)
|
||||
{
|
||||
QList<FileNode *> result;
|
||||
@@ -403,7 +404,7 @@ static QList<FileNode *> scanForFilesRecursively(const Utils::FilePath &director
|
||||
const double progressIncrement = progressRange / static_cast<double>(entries.count());
|
||||
int lastIntProgress = 0;
|
||||
for (const QFileInfo &entry : entries) {
|
||||
if (future && future->isCanceled())
|
||||
if (future.isCanceled())
|
||||
return result;
|
||||
|
||||
const Utils::FilePath entryName = Utils::FilePath::fromString(entry.absoluteFilePath());
|
||||
@@ -411,33 +412,29 @@ static QList<FileNode *> scanForFilesRecursively(const Utils::FilePath &director
|
||||
return vc->isVcsFileOrDirectory(entryName);
|
||||
})) {
|
||||
if (entry.isDir())
|
||||
result.append(scanForFilesRecursively(entryName, factory, visited, future, progress, progressIncrement, versionControls));
|
||||
result.append(scanForFilesRecursively(future, progress, progressIncrement, entryName, factory, visited, versionControls));
|
||||
else if (FileNode *node = factory(entryName))
|
||||
result.append(node);
|
||||
}
|
||||
if (future) {
|
||||
progress += progressIncrement;
|
||||
const int intProgress = std::min(static_cast<int>(progressStart + progress), future->progressMaximum());
|
||||
if (lastIntProgress < intProgress) {
|
||||
future->setProgressValue(intProgress);
|
||||
lastIntProgress = intProgress;
|
||||
}
|
||||
progress += progressIncrement;
|
||||
const int intProgress = std::min(static_cast<int>(progressStart + progress), future.progressMaximum());
|
||||
if (lastIntProgress < intProgress) {
|
||||
future.setProgressValue(intProgress);
|
||||
lastIntProgress = intProgress;
|
||||
}
|
||||
}
|
||||
if (future)
|
||||
future->setProgressValue(std::min(static_cast<int>(progressStart + progressRange), future->progressMaximum()));
|
||||
future.setProgressValue(std::min(static_cast<int>(progressStart + progressRange), future.progressMaximum()));
|
||||
return result;
|
||||
}
|
||||
|
||||
QList<FileNode *>
|
||||
FileNode::scanForFiles(const Utils::FilePath &directory,
|
||||
const std::function<FileNode *(const Utils::FilePath &)> factory,
|
||||
QFutureInterface<QList<FileNode *>> *future)
|
||||
FileNode::scanForFiles(QFutureInterface<QList<FileNode *>> &future,
|
||||
const Utils::FilePath &directory,
|
||||
const std::function<FileNode *(const Utils::FilePath &)> factory)
|
||||
{
|
||||
QSet<QString> visited;
|
||||
if (future)
|
||||
future->setProgressRange(0, 1000000);
|
||||
return scanForFilesRecursively(directory, factory, visited, future, 0.0, 1000000.0,
|
||||
future.setProgressRange(0, 1000000);
|
||||
return scanForFilesRecursively(future, 0.0, 1000000.0, directory, factory, visited,
|
||||
Core::VcsManager::versionControls());
|
||||
}
|
||||
|
||||
|
@@ -201,9 +201,9 @@ public:
|
||||
const FileNode *asFileNode() const final { return this; }
|
||||
|
||||
static QList<FileNode *>
|
||||
scanForFiles(const Utils::FilePath &directory,
|
||||
const std::function<FileNode *(const Utils::FilePath &fileName)> factory,
|
||||
QFutureInterface<QList<FileNode *>> *future = nullptr);
|
||||
scanForFiles(QFutureInterface<QList<FileNode *>> &future,
|
||||
const Utils::FilePath &directory,
|
||||
const std::function<FileNode *(const Utils::FilePath &fileName)> factory);
|
||||
bool supportsAction(ProjectAction action, const Node *node) const override;
|
||||
QString displayName() const override;
|
||||
|
||||
|
@@ -64,12 +64,11 @@ bool TreeScanner::asyncScanForFiles(const Utils::FilePath &directory)
|
||||
if (!m_futureWatcher.isFinished())
|
||||
return false;
|
||||
|
||||
auto fi = new FutureInterface();
|
||||
m_scanFuture = fi->future();
|
||||
m_scanFuture = Utils::runAsync([this, directory](FutureInterface &fi) {
|
||||
TreeScanner::scanForFiles(fi, directory, m_filter, m_factory);
|
||||
});
|
||||
m_futureWatcher.setFuture(m_scanFuture);
|
||||
|
||||
Utils::runAsync([this, fi, directory]() { TreeScanner::scanForFiles(fi, directory, m_filter, m_factory); });
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -145,14 +144,10 @@ FileType TreeScanner::genericFileType(const Utils::MimeType &mimeType, const Uti
|
||||
return Node::fileTypeForMimeType(mimeType);
|
||||
}
|
||||
|
||||
void TreeScanner::scanForFiles(FutureInterface *fi, const Utils::FilePath& directory,
|
||||
void TreeScanner::scanForFiles(FutureInterface &fi, const Utils::FilePath& directory,
|
||||
const FileFilter &filter, const FileTypeFactory &factory)
|
||||
{
|
||||
std::unique_ptr<FutureInterface> fip(fi);
|
||||
fip->reportStarted();
|
||||
|
||||
Result nodes = FileNode::scanForFiles(
|
||||
directory,
|
||||
Result nodes = FileNode::scanForFiles(fi, directory,
|
||||
[&filter, &factory](const Utils::FilePath &fn) -> FileNode * {
|
||||
const Utils::MimeType mimeType = Utils::mimeTypeForFile(fn.toString());
|
||||
|
||||
@@ -166,13 +161,12 @@ void TreeScanner::scanForFiles(FutureInterface *fi, const Utils::FilePath& direc
|
||||
type = factory(mimeType, fn);
|
||||
|
||||
return new FileNode(fn, type);
|
||||
}, fip.get());
|
||||
});
|
||||
|
||||
Utils::sort(nodes, ProjectExplorer::Node::sortByPath);
|
||||
|
||||
fip->setProgressValue(fip->progressMaximum());
|
||||
fip->reportResult(nodes);
|
||||
fip->reportFinished();
|
||||
fi.setProgressValue(fi.progressMaximum());
|
||||
fi.reportResult(nodes);
|
||||
}
|
||||
|
||||
} // namespace ProjectExplorer
|
||||
|
@@ -87,7 +87,7 @@ signals:
|
||||
void finished();
|
||||
|
||||
private:
|
||||
static void scanForFiles(FutureInterface *fi, const Utils::FilePath &directory,
|
||||
static void scanForFiles(FutureInterface &fi, const Utils::FilePath &directory,
|
||||
const FileFilter &filter, const FileTypeFactory &factory);
|
||||
|
||||
private:
|
||||
|
Reference in New Issue
Block a user