QmlDesigner: fix adding effect to 2D does not work on windows

Effect cannot be added in windows, during to latest changes in QDS-7344
The QFileSystemModel::dataChanged doesn't emit with some file types
So I used Utils::FileSystemWatcher for watching files changes

Task-number: QDS-8452
Change-Id: Id381a78556a3dad56268cec506a0182d4343f0a2
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Amr Essam
2022-12-09 02:52:31 -08:00
committed by Tim Jenssen
parent e990b828a9
commit 944ba4a5be
3 changed files with 17 additions and 16 deletions

View File

@@ -35,24 +35,17 @@ void AssetsLibraryModel::createBackendModel()
setSourceModel(m_sourceFsModel); setSourceModel(m_sourceFsModel);
QObject::connect(m_sourceFsModel, &QFileSystemModel::directoryLoaded, this, &AssetsLibraryModel::directoryLoaded); QObject::connect(m_sourceFsModel, &QFileSystemModel::directoryLoaded, this, &AssetsLibraryModel::directoryLoaded);
QObject::connect(m_sourceFsModel, &QFileSystemModel::dataChanged, this, &AssetsLibraryModel::onDataChanged);
QObject::connect(m_sourceFsModel, &QFileSystemModel::directoryLoaded, this, QObject::connect(m_sourceFsModel, &QFileSystemModel::directoryLoaded, this,
[this]([[maybe_unused]] const QString &dir) { [this]([[maybe_unused]] const QString &dir) {
syncHaveFiles(); syncHaveFiles();
}); });
}
void AssetsLibraryModel::onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, m_fileWatcher = new Utils::FileSystemWatcher(parent());
[[maybe_unused]] const QList<int> &roles) QObject::connect(m_fileWatcher, &Utils::FileSystemWatcher::fileChanged, this,
{ [this] (const QString &path) {
for (int i = topLeft.row(); i <= bottomRight.row(); ++i) {
QModelIndex index = m_sourceFsModel->index(i, 0, topLeft.parent());
QString path = m_sourceFsModel->filePath(index);
if (!isDirectory(path))
emit fileChanged(path); emit fileChanged(path);
} });
} }
void AssetsLibraryModel::destroyBackendModel() void AssetsLibraryModel::destroyBackendModel()
@@ -61,6 +54,10 @@ void AssetsLibraryModel::destroyBackendModel()
m_sourceFsModel->disconnect(this); m_sourceFsModel->disconnect(this);
m_sourceFsModel->deleteLater(); m_sourceFsModel->deleteLater();
m_sourceFsModel = nullptr; m_sourceFsModel = nullptr;
m_fileWatcher->disconnect(this);
m_fileWatcher->deleteLater();
m_fileWatcher = nullptr;
} }
void AssetsLibraryModel::setSearchText(const QString &searchText) void AssetsLibraryModel::setSearchText(const QString &searchText)
@@ -196,6 +193,9 @@ bool AssetsLibraryModel::filterAcceptsRow(int sourceRow, const QModelIndex &sour
QModelIndex sourceIdx = m_sourceFsModel->index(sourceRow, 0, sourceParent); QModelIndex sourceIdx = m_sourceFsModel->index(sourceRow, 0, sourceParent);
QString sourcePath = m_sourceFsModel->filePath(sourceIdx); QString sourcePath = m_sourceFsModel->filePath(sourceIdx);
if (QFileInfo(sourcePath).isFile() && !m_fileWatcher->watchesFile(sourcePath))
m_fileWatcher->addFile(sourcePath, Utils::FileSystemWatcher::WatchModifiedDate);
if (!m_searchText.isEmpty() && path.startsWith(m_rootPath) && QFileInfo{path}.isDir()) { if (!m_searchText.isEmpty() && path.startsWith(m_rootPath) && QFileInfo{path}.isDir()) {
QString sourceName = m_sourceFsModel->fileName(sourceIdx); QString sourceName = m_sourceFsModel->fileName(sourceIdx);

View File

@@ -8,6 +8,7 @@
#include <QFileInfo> #include <QFileInfo>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/filesystemwatcher.h>
namespace QmlDesigner { namespace QmlDesigner {
@@ -73,7 +74,6 @@ signals:
private: private:
void setHaveFiles(bool value); void setHaveFiles(bool value);
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
void onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList<int> &roles);
void resetModel(); void resetModel();
void createBackendModel(); void createBackendModel();
void destroyBackendModel(); void destroyBackendModel();
@@ -84,6 +84,7 @@ private:
QString m_rootPath; QString m_rootPath;
QFileSystemModel *m_sourceFsModel = nullptr; QFileSystemModel *m_sourceFsModel = nullptr;
bool m_haveFiles = false; bool m_haveFiles = false;
Utils::FileSystemWatcher *m_fileWatcher = nullptr;
}; };
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -1725,7 +1725,7 @@ bool validateEffect(const QString &effectPath)
msgBox.setDefaultButton(QMessageBox::Yes); msgBox.setDefaultButton(QMessageBox::Yes);
msgBox.setIcon(QMessageBox::Question); msgBox.setIcon(QMessageBox::Question);
if (msgBox.exec() == QMessageBox::Yes) if (msgBox.exec() == QMessageBox::Yes)
ModelNodeOperations::openEffectMaker(effectName); ModelNodeOperations::openEffectMaker(effectPath);
return false; return false;
} }
return true; return true;