aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmldesigner/components
diff options
context:
space:
mode:
authorHenning Gruendl <henning.gruendl@qt.io>2020-10-15 17:36:18 +0200
committerHenning Gründl <henning.gruendl@qt.io>2020-10-16 09:32:37 +0000
commit58e612c85fb8320fd99a28d573372220cbfe309a (patch)
treebf4ea6fce7cc4511cf0ec581481e213d908aeb0c /src/plugins/qmldesigner/components
parent5a97fa53dc1425f6ab35fc9f1540d13b29324604 (diff)
QmlDesigner: Sort items in FileResourceModel
* Sort items in FileResourceModel * Add FileSystemWatcher on directory Task-number: QDS-2919 Change-Id: I0ba50f03d4f901a48709ed0cc0e7f05d3037aeec Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Diffstat (limited to 'src/plugins/qmldesigner/components')
-rw-r--r--src/plugins/qmldesigner/components/propertyeditor/fileresourcesmodel.cpp33
-rw-r--r--src/plugins/qmldesigner/components/propertyeditor/fileresourcesmodel.h6
2 files changed, 29 insertions, 10 deletions
diff --git a/src/plugins/qmldesigner/components/propertyeditor/fileresourcesmodel.cpp b/src/plugins/qmldesigner/components/propertyeditor/fileresourcesmodel.cpp
index a42db492d9..71e2c99627 100644
--- a/src/plugins/qmldesigner/components/propertyeditor/fileresourcesmodel.cpp
+++ b/src/plugins/qmldesigner/components/propertyeditor/fileresourcesmodel.cpp
@@ -29,15 +29,21 @@
#include <model.h>
+#include <utils/algorithm.h>
+
#include <QFileDialog>
#include <QDirIterator>
#include <qmlmodelnodeproxy.h>
static QString s_lastBrowserPath;
-FileResourcesModel::FileResourcesModel(QObject *parent) :
- QObject(parent), m_filter(QLatin1String("(*.*)")), m_lock(false)
+FileResourcesModel::FileResourcesModel(QObject *parent)
+ : QObject(parent)
+ , m_filter(QLatin1String("(*.*)"))
+ , m_fileSystemWatcher(new Utils::FileSystemWatcher(this))
{
+ connect(m_fileSystemWatcher, &Utils::FileSystemWatcher::directoryChanged,
+ this, &FileResourcesModel::refreshModel);
}
void FileResourcesModel::setModelNodeBackend(const QVariant &modelNodeBackend)
@@ -163,7 +169,6 @@ QVariant FileResourcesModel::modelNodeBackend() const
bool filterMetaIcons(const QString &fileName)
{
-
QFileInfo info(fileName);
if (info.dir().path().split('/').contains("designer")) {
@@ -189,12 +194,20 @@ bool filterMetaIcons(const QString &fileName)
void FileResourcesModel::setupModel()
{
- m_lock = true;
+ m_dirPath = QFileInfo(m_path.toLocalFile()).dir();
+
+ refreshModel();
+
+ m_fileSystemWatcher->removeDirectories(m_fileSystemWatcher->directories());
+ m_fileSystemWatcher->addDirectory(m_dirPath.absolutePath(),
+ Utils::FileSystemWatcher::WatchAllChanges);
+}
+
+void FileResourcesModel::refreshModel()
+{
m_fullPathModel.clear();
m_fileNameModel.clear();
- m_dirPath = QFileInfo(m_path.toLocalFile()).dir();
-
QStringList filterList = m_filter.split(QLatin1Char(' '));
QDirIterator it(m_dirPath.absolutePath(), filterList, QDir::Files, QDirIterator::Subdirectories);
@@ -203,11 +216,15 @@ void FileResourcesModel::setupModel()
if (filterMetaIcons(absolutePath)) {
QString filePath = m_dirPath.relativeFilePath(absolutePath);
m_fullPathModel.append(filePath);
- m_fileNameModel.append(filePath.mid(filePath.lastIndexOf('/') + 1));
}
}
- m_lock = false;
+ Utils::sort(m_fullPathModel, [](const QString &s1, const QString &s2) {
+ return s1.mid(s1.lastIndexOf('/') + 1).toLower() < s2.mid(s2.lastIndexOf('/') + 1).toLower();
+ });
+
+ for (const QString &fullPath : qAsConst(m_fullPathModel))
+ m_fileNameModel.append(fullPath.mid(fullPath.lastIndexOf('/') + 1));
emit fullPathModelChanged();
emit fileNameModelChanged();
diff --git a/src/plugins/qmldesigner/components/propertyeditor/fileresourcesmodel.h b/src/plugins/qmldesigner/components/propertyeditor/fileresourcesmodel.h
index e0a1964347..226421f441 100644
--- a/src/plugins/qmldesigner/components/propertyeditor/fileresourcesmodel.h
+++ b/src/plugins/qmldesigner/components/propertyeditor/fileresourcesmodel.h
@@ -27,6 +27,8 @@
#include <qmlitemnode.h>
+#include <utils/filesystemwatcher.h>
+
#include <QDir>
#include <QObject>
#include <QStringList>
@@ -60,6 +62,7 @@ public:
QStringList fullPathModel() const;
QStringList fileNameModel() const;
void setupModel();
+ void refreshModel();
Q_INVOKABLE void openFileDialog();
@@ -79,12 +82,11 @@ private:
QUrl m_path;
QDir m_dirPath;
QString m_filter;
- bool m_lock;
QString m_currentPath;
QString m_lastModelPath;
QStringList m_fullPathModel;
QStringList m_fileNameModel;
-
+ Utils::FileSystemWatcher *m_fileSystemWatcher;
};
QML_DECLARE_TYPE(FileResourcesModel)