Tulip 5.7.1
Large graphs analysis and drawing
Loading...
Searching...
No Matches
GraphNeedsSavingObserver.h
1/*
2 *
3 * This file is part of Tulip (https://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///@cond DOXYGEN_HIDDEN
21
22#ifndef GRAPHNEEDSSAVINGOBSERVER_H
23#define GRAPHNEEDSSAVINGOBSERVER_H
24
25#include <tulip/Observable.h>
26
27#include <QObject>
28
29class QMainWindow;
30
31namespace tlp {
32
33class Graph;
34
35/**
36 * @see Observable
37 *
38 * @brief The GraphNeedsSavingObserver class will observe a graph and tells if it has been modified.
39 *
40 * @li The constructor. Observe the graph given in parameter for modification
41 * @li needsSaving. Returns true is the graph has been modified
42 * @li saved. The graph has been saved, and the status of the class must be reset. needsSaving will
43 * return false if called after saved().
44 * @li savingNeeded. Signal send when the status of the graph evolves.
45 *
46 */
47class TLP_QT_SCOPE GraphNeedsSavingObserver : public QObject, Observable {
48
49 Q_OBJECT
50
51 bool _needsSaving;
52 Graph *_graph;
53 QMainWindow *_mainWindow;
54
55 void addObserver();
56 void removeObservers();
57
58public:
59 /**
60 * @brief GraphNeedsSavingObserver Class constructor
61 * @param graph The graph which needs to be observed for modifications
62 * @param mainWindow The Qt QMainWindow object behin the perspective
63 */
64 GraphNeedsSavingObserver(Graph *graph, QMainWindow *mainWindow = nullptr);
65
66 /**
67 * @brief saved If the graph has been saved, one has to call this method to reset the status of
68 * the graph (it does not need to be saved).
69 * to indicate that the graph does not need to be saved until a new modification.
70 */
71 void saved();
72
73 /**
74 * @brief needsSaving Indicates if the graph has been modified, and thus needs to be saved.
75 *
76 * @return true if the graph needs to be saved, false otherwise.
77 */
78 bool needsSaving() const;
79
80 /**
81 *
82 * @brief forceToSave Even if there is no modification on the graph, this method can be used to
83 * force to save the graph.
84 */
85 void forceToSave();
86
87protected:
88 /**
89 * @see Listener
90 * @see Observer
91 * @see Observable
92 * @see Observable::treatEvents(const std::vector<Event>&)
93 *
94 * @brief treatEvents This function is called when events are sent to Observers, and Observers
95 * only.
96 *
97 * @param events The events that happened since the last unHoldObservers().
98 */
99 void treatEvents(const std::vector<Event> &) override;
100
101signals:
102
103 /**
104 * @brief savingNeeded This signal is sent when the graph needs to be saved (it has been
105 * modified).
106 */
107
108 void savingNeeded();
109};
110} // namespace tlp
111#endif // GRAPHNEEDSSAVINGOBSERVER_H
112
113///@endcond