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