QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCFileWatcher.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <QtCore/QFileSystemWatcher>
7#include <QtCore/QObject>
8#include <QtCore/QSet>
9#include <QtCore/QString>
10#include <QtCore/QTimer>
11
12#include <functional>
13
24class QGCFileWatcher : public QObject
25{
26 Q_OBJECT
27
28public:
31 using ChangeCallback = std::function<void(const QString &path)>;
32
35 explicit QGCFileWatcher(QObject *parent = nullptr);
36
37 ~QGCFileWatcher() override;
38
42 void setDebounceDelay(int milliseconds);
43
46 int debounceDelay() const { return _debounceDelay; }
47
48 // ========================================================================
49 // File Watching
50 // ========================================================================
51
56 bool watchFile(const QString &filePath, ChangeCallback callback);
57
61 bool unwatchFile(const QString &filePath);
62
66 bool isWatchingFile(const QString &filePath) const;
67
70 QStringList watchedFiles() const;
71
72 // ========================================================================
73 // Directory Watching
74 // ========================================================================
75
80 bool watchDirectory(const QString &directoryPath, ChangeCallback callback);
81
85 bool unwatchDirectory(const QString &directoryPath);
86
90 bool isWatchingDirectory(const QString &directoryPath) const;
91
94 QStringList watchedDirectories() const;
95
96 // ========================================================================
97 // Bulk Operations
98 // ========================================================================
99
104 int watchFiles(const QStringList &filePaths, ChangeCallback callback);
105
110 int watchDirectories(const QStringList &directoryPaths, ChangeCallback callback);
111
113 void clear();
114
115 // ========================================================================
116 // Convenience Methods
117 // ========================================================================
118
124 bool watchFilePersistent(const QString &filePath, ChangeCallback callback);
125
126signals:
129 void fileChanged(const QString &path);
130
133 void directoryChanged(const QString &path);
134
135private slots:
136 void _onFileChanged(const QString &path);
137 void _onDirectoryChanged(const QString &path);
138 void _processPendingChanges();
139
140private:
141 void _scheduleCallback(const QString &path, bool isDirectory);
142
143 QFileSystemWatcher *_watcher = nullptr;
144
145 // Callbacks per path
146 QHash<QString, ChangeCallback> _fileCallbacks;
147 QHash<QString, ChangeCallback> _directoryCallbacks;
148
149 // Persistent watch tracking
150 QSet<QString> _persistentFiles;
151
152 // Debouncing
153 int _debounceDelay = 100; // milliseconds
154 QTimer *_debounceTimer = nullptr;
155 QSet<QString> _pendingFileChanges;
156 QSet<QString> _pendingDirectoryChanges;
157 bool _processingPendingChanges = false;
158};
bool unwatchDirectory(const QString &directoryPath)
bool isWatchingDirectory(const QString &directoryPath) const
void clear()
Stop watching all files and directories.
int watchFiles(const QStringList &filePaths, ChangeCallback callback)
int watchDirectories(const QStringList &directoryPaths, ChangeCallback callback)
~QGCFileWatcher() override
QStringList watchedFiles() const
void setDebounceDelay(int milliseconds)
bool isWatchingFile(const QString &filePath) const
bool watchFilePersistent(const QString &filePath, ChangeCallback callback)
void directoryChanged(const QString &path)
void fileChanged(const QString &path)
int debounceDelay() const
std::function< void(const QString &path)> ChangeCallback
QStringList watchedDirectories() const
bool unwatchFile(const QString &filePath)
bool watchFile(const QString &filePath, ChangeCallback callback)
bool watchDirectory(const QString &directoryPath, ChangeCallback callback)