OpenMS
Loading...
Searching...
No Matches
FileWatcher.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Timo Sachsenberg $
6// $Authors: Marc Sturm $
7// --------------------------------------------------------------------------
8
9
10#pragma once
11
12// OpenMS_GUI config
13#include <OpenMS/VISUAL/OpenMS_GUIConfig.h>
14
15//OpenMS
19#include <map>
20
21//Qt
22#include <QtCore/QFileSystemWatcher>
23
24//STL
25#include <map>
26
27namespace OpenMS
28{
29 class String;
30
42 class OPENMS_GUI_DLLAPI FileWatcher :
43 public QFileSystemWatcher //find out why ICC requires public instead of protected
44 {
45 Q_OBJECT
46
47public:
49 FileWatcher(QObject * parent = nullptr);
50
52 ~FileWatcher() override;
53
55 inline void setDelayInSeconds(double delay)
56 {
57 delay_in_seconds_ = delay;
58 }
59
61 inline void addFile(const String & path)
62 {
63 QFileSystemWatcher::addPath(toQString(path));
64 }
65
67 inline void removeFile(const String & path)
68 {
69 QFileSystemWatcher::removePath(toQString(path));
70 }
71
72signals:
74 void fileChanged(const String &);
75
76protected slots:
78 void monitorFileChanged_(const QString & name);
81
82protected:
84 std::map<QString, QString> timers_;
87 };
88
89 // OPENMS_DLLAPI extern FileWatcher myFileWatcher_instance;
90}
91
Watcher that monitors file changes.
Definition FileWatcher.h:44
std::map< QString, QString > timers_
A map that links timer name and file.
Definition FileWatcher.h:84
void fileChanged(const String &)
Delayed file change signal.
void removeFile(const String &path)
removes a file from the watcher
Definition FileWatcher.h:67
void timerTriggered_()
Slot that is called when the delay is over.
void setDelayInSeconds(double delay)
Sets the delay in seconds (default: 1s)
Definition FileWatcher.h:55
~FileWatcher() override
Destructor.
void monitorFileChanged_(const QString &name)
Slot that is connected to the fileChanged signal in order to track the changes.
double delay_in_seconds_
Delay (seconds)
Definition FileWatcher.h:86
void addFile(const String &path)
Adds a file to the watcher.
Definition FileWatcher.h:61
FileWatcher(QObject *parent=nullptr)
Constructor.
A more convenient string class.
Definition String.h:32
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
QString toQString(const String &s)
Convert OpenMS::String to QString (replaces String::toQString())
Definition Qt5Port.h:42