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