plugin/fsm: allow disabling watching
This commit is contained in:
parent
a841c776d3
commit
74a99d2ac4
2 changed files with 24 additions and 2 deletions
|
|
@ -59,6 +59,21 @@ void FileSystemModel::setRecursive(bool recursive) {
|
|||
update();
|
||||
}
|
||||
|
||||
bool FileSystemModel::watchChanges() const {
|
||||
return m_watchChanges;
|
||||
}
|
||||
|
||||
void FileSystemModel::setWatchChanges(bool watchChanges) {
|
||||
if (m_watchChanges == watchChanges) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_watchChanges = watchChanges;
|
||||
emit watchChangesChanged();
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
FileSystemModel::Filter FileSystemModel::filter() const {
|
||||
return m_filter;
|
||||
}
|
||||
|
|
@ -79,7 +94,7 @@ QList<FileSystemEntry*> FileSystemModel::entries() const {
|
|||
}
|
||||
|
||||
void FileSystemModel::watchDirIfRecursive(const QString& path) {
|
||||
if (m_recursive) {
|
||||
if (m_recursive && m_watchChanges) {
|
||||
const auto currentDir = m_dir;
|
||||
const auto future = QtConcurrent::run([path]() {
|
||||
QDirIterator iter(path, QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
|
||||
|
|
@ -112,7 +127,7 @@ void FileSystemModel::updateWatcher() {
|
|||
m_watcher.removePaths(m_watcher.directories());
|
||||
}
|
||||
|
||||
if (m_path.isEmpty()) {
|
||||
if (!m_watchChanges || m_path.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ class FileSystemModel : public QAbstractListModel {
|
|||
|
||||
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged)
|
||||
Q_PROPERTY(bool recursive READ recursive WRITE setRecursive NOTIFY recursiveChanged)
|
||||
Q_PROPERTY(bool watchChanges READ watchChanges WRITE setWatchChanges NOTIFY watchChangesChanged)
|
||||
Q_PROPERTY(Filter filter READ filter WRITE setFilter NOTIFY filterChanged)
|
||||
|
||||
Q_PROPERTY(QList<FileSystemEntry*> entries READ entries NOTIFY entriesChanged)
|
||||
|
|
@ -77,6 +78,7 @@ public:
|
|||
explicit FileSystemModel(QObject* parent = nullptr)
|
||||
: QAbstractListModel(parent)
|
||||
, m_recursive(true)
|
||||
, m_watchChanges(true)
|
||||
, m_filter(NoFilter) {
|
||||
connect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &FileSystemModel::watchDirIfRecursive);
|
||||
connect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &FileSystemModel::updateEntriesForDir);
|
||||
|
|
@ -92,6 +94,9 @@ public:
|
|||
bool recursive() const;
|
||||
void setRecursive(bool recursive);
|
||||
|
||||
bool watchChanges() const;
|
||||
void setWatchChanges(bool watchChanges);
|
||||
|
||||
Filter filter() const;
|
||||
void setFilter(Filter filter);
|
||||
|
||||
|
|
@ -100,6 +105,7 @@ public:
|
|||
signals:
|
||||
void pathChanged();
|
||||
void recursiveChanged();
|
||||
void watchChangesChanged();
|
||||
void filterChanged();
|
||||
void entriesChanged();
|
||||
|
||||
|
|
@ -114,6 +120,7 @@ private:
|
|||
|
||||
QString m_path;
|
||||
bool m_recursive;
|
||||
bool m_watchChanges;
|
||||
Filter m_filter;
|
||||
|
||||
void watchDirIfRecursive(const QString& path);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue