Tulip  4.3.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  static void setApplicationDefaults(tlp::Graph*);
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  // active graph handling
106  void setCurrentGraph(tlp::Graph *);
107  tlp::Graph *currentGraph() const;
108 
109 signals:
110  void currentGraphChanged(tlp::Graph *);
111 
112 public slots:
113  void addGraph(tlp::Graph *);
114  void removeGraph(tlp::Graph *);
115 
116  QMap<QString,tlp::Graph*> readProject(tlp::TulipProject *,tlp::PluginProgress *);
117  QMap<tlp::Graph*,QString> writeProject(tlp::TulipProject *, tlp::PluginProgress *);
118 
119 };
120 
121 }
122 
123 #endif // GRAPHHIERARCHIESMODEL_H
124 ///@endcond