summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomi Korpipaa <tomi.korpipaa@qt.io>2019-01-22 13:57:23 +0200
committerTomi Korpipää <tomi.korpipaa@qt.io>2019-01-23 04:23:57 +0000
commit3b2fdb67349e1b6fc0829c12dc6c479590b2d0ae (patch)
tree73e24f598af97e7871a18b289ad55b3e72bb1d4c
parent4ad48bfb611379cf43896d8ca91b3d6e097303bd (diff)
Fix crash/freeze when changing project
If the new project is in a totally different directory tree, we may end up with crashes when trying to parse something that should not be parsed. Recreating the FileSystemModel removes unwanted items from the model. Task-number: QT3DS-2936 Change-Id: I280afe8afb4f9faa7b68f613de06520ad493ccff Reviewed-by: Antti Määttä <antti.maatta@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
-rw-r--r--src/Authoring/Studio/Palettes/Inspector/ChooserModelBase.cpp18
-rw-r--r--src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.cpp18
2 files changed, 36 insertions, 0 deletions
diff --git a/src/Authoring/Studio/Palettes/Inspector/ChooserModelBase.cpp b/src/Authoring/Studio/Palettes/Inspector/ChooserModelBase.cpp
index b9b5f92a..8cd3c577 100644
--- a/src/Authoring/Studio/Palettes/Inspector/ChooserModelBase.cpp
+++ b/src/Authoring/Studio/Palettes/Inspector/ChooserModelBase.cpp
@@ -231,6 +231,24 @@ void ChooserModelBase::expand(const QModelIndex &modelIndex)
void ChooserModelBase::setRootPath(const QString &path)
{
+ // Delete the old model. If the new project is in a totally different directory tree, not
+ // doing this will result in unexplicable crashes when trying to parse something that should
+ // not be parsed.
+ disconnect(m_model, &QAbstractItemModel::rowsInserted,
+ this, &ChooserModelBase::modelRowsInserted);
+ disconnect(m_model, &QAbstractItemModel::rowsAboutToBeRemoved,
+ this, &ChooserModelBase::modelRowsRemoved);
+ disconnect(m_model, &QAbstractItemModel::layoutChanged,
+ this, &ChooserModelBase::modelLayoutChanged);
+ delete m_model;
+ m_model = new QFileSystemModel(this);
+ connect(m_model, &QAbstractItemModel::rowsInserted,
+ this, &ChooserModelBase::modelRowsInserted);
+ connect(m_model, &QAbstractItemModel::rowsAboutToBeRemoved,
+ this, &ChooserModelBase::modelRowsRemoved);
+ connect(m_model, &QAbstractItemModel::layoutChanged,
+ this, &ChooserModelBase::modelLayoutChanged);
+
setRootIndex(m_model->setRootPath(path));
}
diff --git a/src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.cpp b/src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.cpp
index 95705cd9..51126536 100644
--- a/src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.cpp
+++ b/src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.cpp
@@ -454,6 +454,24 @@ void ProjectFileSystemModel::setRootPath(const QString &path)
m_projectReferencesUpdateMap.clear();
m_projectReferencesUpdateTimer.stop();
+ // Delete the old model. If the new project is in a totally different directory tree, not
+ // doing this will result in unexplicable crashes when trying to parse something that should
+ // not be parsed.
+ disconnect(m_model, &QAbstractItemModel::rowsInserted,
+ this, &ProjectFileSystemModel::modelRowsInserted);
+ disconnect(m_model, &QAbstractItemModel::rowsAboutToBeRemoved,
+ this, &ProjectFileSystemModel::modelRowsRemoved);
+ disconnect(m_model, &QAbstractItemModel::layoutChanged,
+ this, &ProjectFileSystemModel::modelLayoutChanged);
+ delete m_model;
+ m_model = new QFileSystemModel(this);
+ connect(m_model, &QAbstractItemModel::rowsInserted,
+ this, &ProjectFileSystemModel::modelRowsInserted);
+ connect(m_model, &QAbstractItemModel::rowsAboutToBeRemoved,
+ this, &ProjectFileSystemModel::modelRowsRemoved);
+ connect(m_model, &QAbstractItemModel::layoutChanged,
+ this, &ProjectFileSystemModel::modelLayoutChanged);
+
setRootIndex(m_model->setRootPath(path));
// Open the presentations folder by default