Tulip  4.4.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
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 1 and Inria Bordeaux - Sud Ouest
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 
30 namespace tlp {
31 class Graph;
32 class GraphNeedsSavingObserver;
33 class TulipProject;
34 class PluginProgress;
35 
36 class TLP_QT_SCOPE GraphHierarchiesModel : public tlp::TulipModel, public tlp::Observable {
37  Q_OBJECT
38 
39  QList<tlp::Graph *> _graphs;
40  QString generateName(tlp::Graph *) const;
41 
42  tlp::Graph *_currentGraph;
43  QMap<const tlp::Graph*,QModelIndex> _indexCache;
44  QMap<const tlp::Graph*, GraphNeedsSavingObserver*> _saveNeeded;
45  void initIndexCache(tlp::Graph *root);
46 
47 public:
48  bool needsSaving();
49 
50  explicit GraphHierarchiesModel(QObject *parent=0);
51  GraphHierarchiesModel(const GraphHierarchiesModel &);
52  virtual ~GraphHierarchiesModel();
53 
54  // Allows the model to behave like a list and to be iterable
55  typedef QList<tlp::Graph *>::iterator iterator;
56  typedef QList<tlp::Graph *>::const_iterator const_iterator;
57  tlp::Graph *operator[](int i) const {
58  return _graphs[i];
59  }
60  tlp::Graph *operator[](int i) {
61  return _graphs[i];
62  }
63  int size() const {
64  return _graphs.size();
65  }
66 
67  iterator begin() {
68  return _graphs.begin();
69  }
70  iterator end() {
71  return _graphs.end();
72  }
73  const_iterator begin() const {
74  return _graphs.begin();
75  }
76  const_iterator end() const {
77  return _graphs.end();
78  }
79 
80  QList<tlp::Graph *> graphs() const {
81  return _graphs;
82  }
83  bool empty() const {
84  return _graphs.isEmpty();
85  }
86 
87  // Methods re-implemented from QAbstractItemModel
88  QModelIndex index(int row, int column,const QModelIndex &parent = QModelIndex()) const;
89  QModelIndex parent(const QModelIndex &child) const;
90  int rowCount(const QModelIndex &parent = QModelIndex()) const;
91  int columnCount(const QModelIndex &parent = QModelIndex()) const;
92  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
93  bool setData(const QModelIndex &index, const QVariant &value, int role);
94  Qt::ItemFlags flags(const QModelIndex &index) const;
95  QVariant headerData(int section, Qt::Orientation orientation, int role) const;
96  QMimeData* mimeData(const QModelIndexList &indexes) const;
97 
98  QModelIndex indexOf(const Graph *);
99  QModelIndex forceGraphIndex(Graph *);
100 
101  // Methods inherited from the observable system
102  void treatEvent(const tlp::Event &);
103 
104  // active graph handling
105  void setCurrentGraph(tlp::Graph *);
106  tlp::Graph *currentGraph() const;
107 
108 signals:
109  void currentGraphChanged(tlp::Graph *);
110 
111 public slots:
112  void addGraph(tlp::Graph *);
113  void removeGraph(tlp::Graph *);
114 
115  QMap<QString,tlp::Graph*> readProject(tlp::TulipProject *,tlp::PluginProgress *);
116  QMap<tlp::Graph*,QString> writeProject(tlp::TulipProject *, tlp::PluginProgress *);
117 
118 };
119 
120 }
121 
122 #endif // GRAPHHIERARCHIESMODEL_H
123 ///@endcond