QmlDesigner: Fix regression

This regression was caused by an optimization.
I added updatePath() to avoid similar issues in the future.

Task-number: QDS-690
Change-Id: I0c1c67a3d35a6944da494651db34c746561a1e26
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Thomas Hartmann
2019-05-21 14:43:19 +02:00
committed by Tim Jenssen
parent a345fbb5b1
commit 7eb29b6505
2 changed files with 39 additions and 33 deletions

View File

@@ -79,7 +79,7 @@ CustomFileSystemModel::CustomFileSystemModel(QObject *parent) : QAbstractListMod
m_fileSystemModel->setIconProvider(new ItemLibraryFileIconProvider()); m_fileSystemModel->setIconProvider(new ItemLibraryFileIconProvider());
connect(m_fileSystemWatcher, &Utils::FileSystemWatcher::directoryChanged, [this] { connect(m_fileSystemWatcher, &Utils::FileSystemWatcher::directoryChanged, [this] {
setRootPath(m_fileSystemModel->rootPath()); updatePath(m_fileSystemModel->rootPath());
}); });
} }
@@ -120,38 +120,7 @@ QModelIndex CustomFileSystemModel::setRootPath(const QString &newPath)
if (m_fileSystemModel->rootPath() == newPath) if (m_fileSystemModel->rootPath() == newPath)
return QAbstractListModel::index(0, 0); return QAbstractListModel::index(0, 0);
beginResetModel(); return updatePath(newPath);
m_fileSystemModel->setRootPath(newPath);
m_fileSystemWatcher->removeDirectories(m_fileSystemWatcher->directories());
m_fileSystemWatcher->addDirectory(newPath, Utils::FileSystemWatcher::WatchAllChanges);
QStringList nameFilterList;
const QString searchFilter = m_searchFilter;
if (searchFilter.contains(QLatin1Char('.'))) {
nameFilterList.append(QString(QStringLiteral("*%1*")).arg(searchFilter));
} else {
foreach (const QByteArray &extension, QImageReader::supportedImageFormats()) {
nameFilterList.append(QString(QStringLiteral("*%1*.%2")).arg(searchFilter, QString::fromUtf8(extension)));
}
}
m_files.clear();
QDirIterator fileIterator(newPath, nameFilterList, QDir::Files, QDirIterator::Subdirectories);
while (fileIterator.hasNext())
m_files.append(filterMetaIcons(fileIterator.next()));
QDirIterator dirIterator(newPath, {}, QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
while (dirIterator.hasNext())
m_fileSystemWatcher->addDirectory(dirIterator.next(), Utils::FileSystemWatcher::WatchAllChanges);
endResetModel();
return QAbstractListModel::index(0, 0);
} }
QVariant CustomFileSystemModel::data(const QModelIndex &index, int role) const QVariant CustomFileSystemModel::data(const QModelIndex &index, int role) const
@@ -210,6 +179,42 @@ void CustomFileSystemModel::setSearchFilter(const QString &nameFilterList)
setRootPath(m_fileSystemModel->rootPath()); setRootPath(m_fileSystemModel->rootPath());
} }
QModelIndex CustomFileSystemModel::updatePath(const QString &newPath)
{
beginResetModel();
m_fileSystemModel->setRootPath(newPath);
m_fileSystemWatcher->removeDirectories(m_fileSystemWatcher->directories());
m_fileSystemWatcher->addDirectory(newPath, Utils::FileSystemWatcher::WatchAllChanges);
QStringList nameFilterList;
const QString searchFilter = m_searchFilter;
if (searchFilter.contains(QLatin1Char('.'))) {
nameFilterList.append(QString(QStringLiteral("*%1*")).arg(searchFilter));
} else {
foreach (const QByteArray &extension, QImageReader::supportedImageFormats()) {
nameFilterList.append(QString(QStringLiteral("*%1*.%2")).arg(searchFilter, QString::fromUtf8(extension)));
}
}
m_files.clear();
QDirIterator fileIterator(newPath, nameFilterList, QDir::Files, QDirIterator::Subdirectories);
while (fileIterator.hasNext())
m_files.append(filterMetaIcons(fileIterator.next()));
QDirIterator dirIterator(newPath, {}, QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
while (dirIterator.hasNext())
m_fileSystemWatcher->addDirectory(dirIterator.next(), Utils::FileSystemWatcher::WatchAllChanges);
endResetModel();
return QAbstractListModel::index(0, 0);
}
QModelIndex CustomFileSystemModel::fileSystemModelIndex(const QModelIndex &index) const QModelIndex CustomFileSystemModel::fileSystemModelIndex(const QModelIndex &index) const
{ {
const int row = index.row(); const int row = index.row();

View File

@@ -61,6 +61,7 @@ public:
void setSearchFilter(const QString &nameFilterList); void setSearchFilter(const QString &nameFilterList);
private: private:
QModelIndex updatePath(const QString &newPath);
QModelIndex fileSystemModelIndex(const QModelIndex &index) const; QModelIndex fileSystemModelIndex(const QModelIndex &index) const;
QFileSystemModel *m_fileSystemModel; QFileSystemModel *m_fileSystemModel;