Tulip  5.2.1
Large graphs analysis and drawing
GraphNeedsSavingObserver.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 
20 #ifndef GRAPHNEEDSSAVINGOBSERVER_H
21 #define GRAPHNEEDSSAVINGOBSERVER_H
22 
23 #include <tulip/Observable.h>
24 
25 #include <QObject>
26 
27 class QMainWindow;
28 
29 namespace tlp {
30 
31 class Graph;
32 
33 /**
34  * @see Observable
35  *
36  * @brief The GraphNeedsSavingObserver class will observe a graph and tells if it has been modified.
37  *
38  * @li The constructor. Observe the graph given in parameter for modification
39  * @li needsSaving. Returns true is the graph has been modified
40  * @li saved. The graph has been saved, and the status of the class must be reset. needsSaving will
41  * return false if called after saved().
42  * @li savingNeeded. Signal send when the status of the graph evolves.
43  *
44  */
45 class TLP_QT_SCOPE GraphNeedsSavingObserver : public QObject, Observable {
46 
47  Q_OBJECT
48 
49  bool _needsSaving;
50  Graph *_graph;
51  QMainWindow *_mainWindow;
52 
53  void addObserver();
54  void removeObservers();
55 
56 public:
57  /**
58  * @brief GraphNeedsSavingObserver Class constructor
59  * @param graph The graph which needs to be observed for modifications
60  * @param mainWindow The Qt QMainWindow object behin the perspective
61  */
62  GraphNeedsSavingObserver(Graph *graph, QMainWindow *mainWindow = nullptr);
63 
64  /**
65  * @brief saved If the graph has been saved, one has to call this method to reset the status of
66  * the graph (it does not need to be saved).
67  * to indicate that the graph does not need to be saved until a new modification.
68  */
69  void saved();
70 
71  /**
72  * @brief needsSaving Indicates if the graph has been modified, and thus needs to be saved.
73  *
74  * @return true if the graph needs to be saved, false otherwise.
75  */
76  bool needsSaving() const;
77 
78  /**
79  *
80  * @brief forceToSave Even if there is no modification on the graph, this method can be used to
81  * force to save the graph.
82  */
83  void forceToSave();
84 
85 protected:
86  /**
87  * @see Listener
88  * @see Observer
89  * @see Observable
90  * @see Observable::treatEvents(const std::vector<Event>&)
91  *
92  * @brief treatEvents This function is called when events are sent to Observers, and Observers
93  * only.
94  *
95  * @param events The events that happened since the last unHoldObservers().
96  */
97  void treatEvents(const std::vector<Event> &) override;
98 
99 signals:
100 
101  /**
102  * @brief savingNeeded This signal is sent when the graph needs to be saved (it has been
103  * modified).
104  */
105 
106  void savingNeeded();
107 };
108 } // namespace tlp
109 #endif // GRAPHNEEDSSAVINGOBSERVER_H
The GraphNeedsSavingObserver class will observe a graph and tells if it has been modified.
The Observable class is the base of Tulip&#39;s observation system.
Definition: Observable.h:141