Tulip  4.7.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
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 namespace tlp {
28 
29 class Graph;
30 
31 /**
32  * @see Observable
33  *
34  * @brief The GraphNeedsSavingObserver class will observe a graph and tells if it has been modified.
35  *
36  * @li The constructor. Observe the graph given in parameter for modification
37  * @li needsSaving. Returns true is the graph has been modified
38  * @li saved. The graph has been saved, and the status of the class must be reset. needsSaving will return false if called after saved().
39  * @li savingNeeded. Signal send when the status of the graph evolves.
40  *
41  */
42 class TLP_QT_SCOPE GraphNeedsSavingObserver : public QObject, Observable {
43 
44  Q_OBJECT
45 
46  bool _needsSaving;
47  Graph* _graph;
48 
49  void addObserver();
50  void removeObservers();
51 
52 public :
53  /**
54  * @brief GraphNeedsSavingObserver Class constructor
55  * @param graph the graph which needs to be observed for modifications
56  */
58 
59  /**
60  * @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).
61  * to indicate that the graph does not need to be saved until a new modification.
62  */
63  void saved();
64 
65  /**
66  * @brief needsSaving Indicates if the graph has been modified, and thus needs to be saved.
67  *
68  * @return true if the graph needs to be saved, false otherwise.
69  */
70  bool needsSaving() const;
71 
72 protected :
73  /**
74  * @see Listener
75  * @see Observer
76  * @see Observable
77  * @see Observable::treatEvents(const std::vector<Event>&)
78  *
79  * @brief treatEvents This function is called when events are sent to Observers, and Observers only.
80  *
81  * @param events The events that happened since the last unHoldObservers().
82  */
83  virtual void treatEvents(const std::vector<Event>&);
84 
85 signals:
86 
87  /**
88  * @brief savingNeeded This signal is sent when the graph needs to be saved (it has been modified).
89  */
90 
91  void savingNeeded();
92 
93 };
94 }
95 #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's observation system.
Definition: Observable.h:123