Tulip  6.0.0
Large graphs analysis and drawing
GraphElementModel.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 GRAPHELEMENTMODEL_H
22 #define GRAPHELEMENTMODEL_H
23 
24 #include <set>
25 #include <string>
26 #include <vector>
27 
28 #include <tulip/TulipModel.h>
29 #include <tulip/GraphModel.h>
30 
31 namespace tlp {
32 
33 class TLP_QT_SCOPE GraphElementModel : public TulipModel {
34 
35 public:
36  GraphElementModel(Graph *graph, unsigned int id, QObject *parent = nullptr);
37 
38  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
39  int columnCount(const QModelIndex &parent = QModelIndex()) const override;
40  QModelIndex parent(const QModelIndex &child) const override;
41 
42  QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
43  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
44  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
45 
46  virtual QString headerText(unsigned int id) const = 0;
47  virtual QVariant value(unsigned int id, PropertyInterface *prop) const = 0;
48 
49  Qt::ItemFlags flags(const QModelIndex &index) const override;
50 
51  const static int PropertyNameRole = 33;
52 
53  void setVisibleProperties(const std::vector<std::string> &props) {
54  _visibleProps.clear();
55  for (auto prop : props)
56  _visibleProps.insert(prop);
57  }
58 
59 protected:
60  std::vector<PropertyInterface *> getGraphProperties() const;
61 
62  Graph *_graph;
63  unsigned int _id;
64  std::set<std::string> _visibleProps;
65 };
66 
67 class TLP_QT_SCOPE GraphNodeElementModel : public GraphElementModel {
68 
69 public:
70  GraphNodeElementModel(Graph *graph, unsigned int id, QObject *parent = nullptr)
71  : GraphElementModel(graph, id, parent) {}
72 
73  QString headerText(unsigned int id) const override {
74  return QString("node: ") + QString::number(id);
75  }
76 
77  QVariant value(unsigned int id, PropertyInterface *prop) const override {
78  return GraphModel::nodeValue(id, prop);
79  }
80 
81  bool setData(const QModelIndex &index, const QVariant &value, int role) override;
82 };
83 
84 class TLP_QT_SCOPE GraphEdgeElementModel : public GraphElementModel {
85 
86 public:
87  GraphEdgeElementModel(Graph *graph, unsigned int id, QObject *parent = nullptr)
88  : GraphElementModel(graph, id, parent) {}
89 
90  QString headerText(unsigned int id) const override {
91  return QString("edge: ") + QString::number(id);
92  }
93 
94  QVariant value(unsigned int id, PropertyInterface *prop) const override {
95  return GraphModel::edgeValue(id, prop);
96  }
97 
98  bool setData(const QModelIndex &index, const QVariant &value, int role) override;
99 };
100 } // namespace tlp
101 
102 #endif // GRAPHELEMENTMODEL_H
103 ///@endcond