forked from qt-creator/qt-creator
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:
@@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
void AssetsLibraryModel::onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
|
||||
[[maybe_unused]] const QList<int> &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))
|
||||
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);
|
||||
|
||||
|
@@ -8,6 +8,7 @@
|
||||
#include <QFileInfo>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/filesystemwatcher.h>
|
||||
|
||||
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<int> &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
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user