OpenMS
FileWatcher.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, The OpenMS Team -- 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
13 #include <OpenMS/CONCEPT/Types.h>
15 #include <map>
16 
17 //Qt
18 #include <QtCore/QFileSystemWatcher>
19 
20 //STL
21 #include <map>
22 
23 namespace OpenMS
24 {
25  class String;
26 
39  class OPENMS_DLLAPI FileWatcher :
40  public QFileSystemWatcher //find out why ICC requires public instead of protected
41  {
42  Q_OBJECT
43 
44 public:
46  FileWatcher(QObject * parent = nullptr);
47 
49  ~FileWatcher() override;
50 
52  inline void setDelayInSeconds(double delay)
53  {
54  delay_in_seconds_ = delay;
55  }
56 
58  inline void addFile(const String & path)
59  {
60  QFileSystemWatcher::addPath(path.toQString());
61  }
62 
64  inline void removeFile(const String & path)
65  {
66  QFileSystemWatcher::removePath(path.toQString());
67  }
68 
69 signals:
71  void fileChanged(const String &);
72 
73 protected slots:
75  void monitorFileChanged_(const QString & name);
78 
79 protected:
81  std::map<QString, QString> timers_;
84  };
85 
86  // OPENMS_DLLAPI extern FileWatcher myFileWatcher_instance;
87 }
88 
Watcher that monitors file changes.
Definition: FileWatcher.h:41
std::map< QString, QString > timers_
A map that links timer name and file.
Definition: FileWatcher.h:81
void fileChanged(const String &)
Delayed file change signal.
void removeFile(const String &path)
removes a file from the watcher
Definition: FileWatcher.h:64
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:52
~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:83
void addFile(const String &path)
Adds a file to the watcher.
Definition: FileWatcher.h:58
FileWatcher(QObject *parent=nullptr)
Constructor.
A more convenient string class.
Definition: String.h:34
QString toQString() const
Conversion to Qt QString.
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19