forked from qt-creator/qt-creator
QmlDesigner: Fix invalid path hang up
Fix issue where an invalid path results in QDir being set to "." which
in some cases results in iterating a huge amount of files ultimately
causing QtDS to stall.
Task-number: QDS-9437
Change-Id: I0f868f1a94341fbd4d18e98de012ecd5d2a6423a
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
(cherry picked from commit 9b4decf9af
)
This commit is contained in:
committed by
Tim Jenssen
parent
ee72b1099b
commit
9f725de283
@@ -51,7 +51,7 @@ void FileResourcesModel::setModelNodeBackend(const QVariant &modelNodeBackend)
|
||||
QmlDesigner::DocumentManager::currentProjectDirPath().toFileInfo().absoluteFilePath());
|
||||
}
|
||||
|
||||
setupModel();
|
||||
refreshModel();
|
||||
emit modelNodeBackendChanged();
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ void FileResourcesModel::setFileName(const QUrl &fileName)
|
||||
void FileResourcesModel::setPath(const QUrl &url)
|
||||
{
|
||||
m_path = url;
|
||||
setupModel();
|
||||
refreshModel();
|
||||
|
||||
emit pathChanged(url);
|
||||
}
|
||||
@@ -99,7 +99,7 @@ void FileResourcesModel::setFilter(const QString &filter)
|
||||
return;
|
||||
|
||||
m_filter = filter;
|
||||
setupModel();
|
||||
refreshModel();
|
||||
|
||||
emit filterChanged(filter);
|
||||
}
|
||||
@@ -201,33 +201,30 @@ bool filterMetaIcons(const QString &fileName)
|
||||
return true;
|
||||
}
|
||||
|
||||
void FileResourcesModel::setupModel()
|
||||
{
|
||||
m_dirPath = QDir(m_path.toLocalFile());
|
||||
refreshModel();
|
||||
}
|
||||
|
||||
void FileResourcesModel::refreshModel()
|
||||
{
|
||||
m_model.clear();
|
||||
|
||||
QStringList filterList = m_filter.split(QLatin1Char(' '));
|
||||
if (m_path.isValid()) {
|
||||
const QDir dirPath = QDir(m_path.toLocalFile());
|
||||
const QStringList filterList = m_filter.split(QLatin1Char(' '));
|
||||
|
||||
QDirIterator it(m_dirPath.absolutePath(), filterList, QDir::Files, QDirIterator::Subdirectories);
|
||||
while (it.hasNext()) {
|
||||
QString absolutePath = it.next();
|
||||
if (filterMetaIcons(absolutePath)) {
|
||||
QString relativeFilePath = m_docPath.relativeFilePath(absolutePath);
|
||||
m_model.append(
|
||||
FileResourcesItem(absolutePath,
|
||||
relativeFilePath,
|
||||
relativeFilePath.mid(relativeFilePath.lastIndexOf('/') + 1)));
|
||||
QDirIterator it(dirPath.absolutePath(), filterList, QDir::Files, QDirIterator::Subdirectories);
|
||||
while (it.hasNext()) {
|
||||
const QString absolutePath = it.next();
|
||||
if (filterMetaIcons(absolutePath)) {
|
||||
const QString relativeFilePath = m_docPath.relativeFilePath(absolutePath);
|
||||
m_model.append(
|
||||
FileResourcesItem(absolutePath,
|
||||
relativeFilePath,
|
||||
relativeFilePath.mid(relativeFilePath.lastIndexOf('/') + 1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Utils::sort(m_model, [](const FileResourcesItem &i1, const FileResourcesItem &i2) {
|
||||
return i1.fileName().toLower() < i2.fileName().toLower();
|
||||
});
|
||||
Utils::sort(m_model, [](const FileResourcesItem &i1, const FileResourcesItem &i2) {
|
||||
return i1.fileName().toLower() < i2.fileName().toLower();
|
||||
});
|
||||
}
|
||||
|
||||
emit modelChanged();
|
||||
}
|
||||
|
@@ -67,7 +67,6 @@ public:
|
||||
QString filter() const;
|
||||
QList<FileResourcesItem> model() const;
|
||||
|
||||
void setupModel();
|
||||
void refreshModel();
|
||||
|
||||
Q_INVOKABLE void openFileDialog();
|
||||
@@ -89,7 +88,6 @@ private:
|
||||
private:
|
||||
QUrl m_fileName;
|
||||
QUrl m_path;
|
||||
QDir m_dirPath;
|
||||
QDir m_docPath;
|
||||
QString m_filter;
|
||||
QString m_currentPath;
|
||||
|
Reference in New Issue
Block a user