Tulip  5.0.0
Large graphs analysis and drawing
GraphHierarchiesModel.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 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef GRAPHHIERARCHIESMODEL_H
22 #define GRAPHHIERARCHIESMODEL_H
23 
24 #include <tulip/tulipconf.h>
25 #include <tulip/TulipModel.h>
26 #include <tulip/Observable.h>
27 
28 #include <QList>
29 #include <QSet>
30 
31 namespace tlp {
32 class Graph;
33 class GraphNeedsSavingObserver;
34 class TulipProject;
35 class PluginProgress;
36 
37 class TLP_QT_SCOPE GraphHierarchiesModel : public tlp::TulipModel, public tlp::Observable {
38  Q_OBJECT
39 
40  QList<tlp::Graph *> _graphs;
41  QString generateName(tlp::Graph *) const;
42 
43  tlp::Graph *_currentGraph;
44  QMap<const tlp::Graph*,QModelIndex> _indexCache;
45  QMap<const tlp::Graph*, GraphNeedsSavingObserver*> _saveNeeded;
46  void initIndexCache(tlp::Graph *root);
47 
48 public:
49  bool needsSaving();
50 
51  explicit GraphHierarchiesModel(QObject *parent=0);
52  GraphHierarchiesModel(const GraphHierarchiesModel &);
53  virtual ~GraphHierarchiesModel();
54 
55  // Allows the model to behave like a list and to be iterable
56  typedef QList<tlp::Graph *>::iterator iterator;
57  typedef QList<tlp::Graph *>::const_iterator const_iterator;
58  tlp::Graph *operator[](int i) const {
59  return _graphs[i];
60  }
61  tlp::Graph *operator[](int i) {
62  return _graphs[i];
63  }
64  int size() const {
65  return _graphs.size();
66  }
67 
68  iterator begin() {
69  return _graphs.begin();
70  }
71  iterator end() {
72  return _graphs.end();
73  }
74  const_iterator begin() const {
75  return _graphs.begin();
76  }
77  const_iterator end() const {
78  return _graphs.end();
79  }
80 
81  QList<tlp::Graph *> graphs() const {
82  return _graphs;
83  }
84  bool empty() const {
85  return _graphs.isEmpty();
86  }
87 
88  // Methods re-implemented from QAbstractItemModel
89  QModelIndex index(int row, int column,const QModelIndex &parent = QModelIndex()) const;
90  QModelIndex parent(const QModelIndex &child) const;
91  int rowCount(const QModelIndex &parent = QModelIndex()) const;
92  int columnCount(const QModelIndex &parent = QModelIndex()) const;
93  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
94  bool setData(const QModelIndex &index, const QVariant &value, int role);
95  Qt::ItemFlags flags(const QModelIndex &index) const;
96  QVariant headerData(int section, Qt::Orientation orientation, int role) const;
97  QMimeData* mimeData(const QModelIndexList &indexes) const;
98 
99  QModelIndex indexOf(const Graph *);
100  QModelIndex forceGraphIndex(Graph *);
101 
102  // Methods inherited from the observable system
103  void treatEvent(const tlp::Event &);
104 
105  void treatEvents(const std::vector<tlp::Event> &);
106 
107  // active graph handling
108  void setCurrentGraph(tlp::Graph *);
109  tlp::Graph *currentGraph() const;
110 
111 signals:
112  void currentGraphChanged(tlp::Graph *);
113 
114 public slots:
115  void addGraph(tlp::Graph *);
116  void removeGraph(tlp::Graph *);
117 
118  QMap<QString,tlp::Graph*> readProject(tlp::TulipProject *, tlp::PluginProgress *);
119  QMap<tlp::Graph*,QString> writeProject(tlp::TulipProject *, tlp::PluginProgress *);
120 
121 private:
122 
123  QSet<const Graph *> _graphsChanged;
124 
125 
126 };
127 
128 }
129 
130 #endif // GRAPHHIERARCHIESMODEL_H
131 ///@endcond
The TulipProject object handles the content of a Tulip project.
Definition: TulipProject.h:71
Event is the base class for all events used in the Observation mechanism.
Definition: Observable.h:47
PluginProcess subclasses are meant to notify about the progress state of some process (typically a pl...
The Observable class is the base of Tulip&#39;s observation system.
Definition: Observable.h:123