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