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