From c223af0101496395a38642876ed5bc4a0b3c4cfb Mon Sep 17 00:00:00 2001 From: Amr Essam Date: Fri, 9 Dec 2022 02:52:31 -0800 Subject: [PATCH] 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: Amr Elsayed Reviewed-by: Thomas Hartmann --- .../assetslibrary/assetslibrarymodel.cpp | 28 +++++++++---------- .../assetslibrary/assetslibrarymodel.h | 3 +- .../componentcore/modelnodeoperations.cpp | 2 +- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp index 864660a1476..6587c89cf32 100644 --- a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp +++ b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp @@ -35,24 +35,17 @@ void AssetsLibraryModel::createBackendModel() setSourceModel(m_sourceFsModel); 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, [this]([[maybe_unused]] const QString &dir) { - syncHaveFiles(); - }); -} + syncHaveFiles(); + }); -void AssetsLibraryModel::onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, - [[maybe_unused]] const QList &roles) -{ - 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); - } + m_fileWatcher = new Utils::FileSystemWatcher(parent()); + QObject::connect(m_fileWatcher, &Utils::FileSystemWatcher::fileChanged, this, + [this] (const QString &path) { + emit fileChanged(path); + }); } void AssetsLibraryModel::destroyBackendModel() @@ -61,6 +54,10 @@ void AssetsLibraryModel::destroyBackendModel() m_sourceFsModel->disconnect(this); m_sourceFsModel->deleteLater(); m_sourceFsModel = nullptr; + + m_fileWatcher->disconnect(this); + m_fileWatcher->deleteLater(); + m_fileWatcher = nullptr; } 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); 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()) { QString sourceName = m_sourceFsModel->fileName(sourceIdx); diff --git a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.h b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.h index f73d7fb7e3f..99c96017084 100644 --- a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.h +++ b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.h @@ -8,6 +8,7 @@ #include #include +#include namespace QmlDesigner { @@ -73,7 +74,6 @@ signals: private: void setHaveFiles(bool value); bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; - void onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList &roles); void resetModel(); void createBackendModel(); void destroyBackendModel(); @@ -84,6 +84,7 @@ private: QString m_rootPath; QFileSystemModel *m_sourceFsModel = nullptr; bool m_haveFiles = false; + Utils::FileSystemWatcher *m_fileWatcher = nullptr; }; } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp index 3a3dd7d6838..711b84c3798 100644 --- a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp +++ b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp @@ -1725,7 +1725,7 @@ bool validateEffect(const QString &effectPath) msgBox.setDefaultButton(QMessageBox::Yes); msgBox.setIcon(QMessageBox::Question); if (msgBox.exec() == QMessageBox::Yes) - ModelNodeOperations::openEffectMaker(effectName); + ModelNodeOperations::openEffectMaker(effectPath); return false; } return true;