Tulip  4.10.0
Better Visualization Through Research
GraphNeedsSavingObserver.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
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 return false if called after saved().
41  * @li savingNeeded. Signal send when the status of the graph evolves.
42  *
43  */
44 class TLP_QT_SCOPE GraphNeedsSavingObserver : public QObject, Observable {
45 
46  Q_OBJECT
47 
48  bool _needsSaving;
49  Graph* _graph;
50  QMainWindow* _mainWindow;
51 
52  void addObserver();
53  void removeObservers();
54 
55 public :
56  /**
57  * @brief GraphNeedsSavingObserver Class constructor
58  * @param graph The graph which needs to be observed for modifications
59  * @param mainWindow The Qt QMainWindow object behin the perspective
60  */
61  GraphNeedsSavingObserver(Graph* graph,QMainWindow* mainWindow=NULL);
62 
63  /**
64  * @brief saved If the graph has been saved, one has to call this method to reset the status of the graph (it does not need to be saved).
65  * to indicate that the graph does not need to be saved until a new modification.
66  */
67  void saved();
68 
69  /**
70  * @brief needsSaving Indicates if the graph has been modified, and thus needs to be saved.
71  *
72  * @return true if the graph needs to be saved, false otherwise.
73  */
74  bool needsSaving() const;
75 
76  /**
77  *
78  * @brief forceToSave Even if there is no modification on the graph, this method can be used to force to save the graph.
79  */
80  void forceToSave();
81 
82 protected :
83  /**
84  * @see Listener
85  * @see Observer
86  * @see Observable
87  * @see Observable::treatEvents(const std::vector<Event>&)
88  *
89  * @brief treatEvents This function is called when events are sent to Observers, and Observers only.
90  *
91  * @param events The events that happened since the last unHoldObservers().
92  */
93  virtual void treatEvents(const std::vector<Event>&);
94 
95 signals:
96 
97  /**
98  * @brief savingNeeded This signal is sent when the graph needs to be saved (it has been modified).
99  */
100 
101  void savingNeeded();
102 
103 };
104 }
105 #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:123