Tulip  4.7.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
GraphModel.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
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 GRAPHMODEL_H
22 #define GRAPHMODEL_H
23 
24 #include <QVector>
25 #include <QSortFilterProxyModel>
26 
27 
28 #include <tulip/Observable.h>
29 #include <tulip/TulipModel.h>
30 
31 namespace tlp {
32 class Graph;
33 class PropertyInterface;
34 class BooleanProperty;
35 
36 class TLP_QT_SCOPE GraphModel : public tlp::TulipModel, public Observable {
37  tlp::Graph* _graph;
38 
39 public:
40  static QVariant nodeValue(unsigned int, tlp::PropertyInterface*);
41  static QVariant nodeDefaultValue(tlp::PropertyInterface*);
42  static bool setNodeValue(unsigned int,tlp::PropertyInterface*, QVariant);
43  static bool setAllNodeValue(tlp::PropertyInterface*, QVariant);
44  static QVariant edgeValue(unsigned int, tlp::PropertyInterface*);
45  static QVariant edgeDefaultValue(tlp::PropertyInterface*);
46  static bool setEdgeValue(unsigned int,tlp::PropertyInterface*, QVariant);
47  static bool setAllEdgeValue(tlp::PropertyInterface*, QVariant);
48 
49  explicit GraphModel(QObject *parent = NULL);
50 
51  virtual void setGraph(tlp::Graph*);
52  tlp::Graph* graph() const;
53 
54  // Methods re-implemented from QAbstractItemModel
55  int rowCount(const QModelIndex &parent = QModelIndex()) const;
56  int columnCount(const QModelIndex &parent = QModelIndex()) const;
57  QModelIndex parent(const QModelIndex &child) const;
58  Qt::ItemFlags flags(const QModelIndex &index) const;
59 
60  QVariant headerData(int section, Qt::Orientation orientation, int role) const;
61  QModelIndex index(int row, int column,const QModelIndex &parent = QModelIndex()) const;
62  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
63  bool setData(const QModelIndex &index, const QVariant &value, int role);
64 
65  void treatEvent(const tlp::Event&);
66  void treatEvents(const std::vector<tlp::Event> &);
67 
68  unsigned int elementAt(int) const;
69  virtual bool lessThan(unsigned int,unsigned int,tlp::PropertyInterface*) const = 0;
70  virtual QString stringValue(unsigned int,tlp::PropertyInterface*) const = 0;
71  virtual QVariant value(unsigned int,tlp::PropertyInterface*) const = 0;
72  virtual bool isNode() const = 0;
73 
74 protected:
75  QVector<unsigned int> _elements;
76  QVector<QPair<unsigned int,bool> > _elementsToModify;
77  QVector<PropertyInterface*> _properties;
78 
79  virtual bool setValue(unsigned int,tlp::PropertyInterface*,QVariant) const = 0;
80 };
81 
82 class TLP_QT_SCOPE GraphSortFilterProxyModel: public QSortFilterProxyModel, public Observable {
83  QVector<PropertyInterface*> _properties;
84  BooleanProperty* _filterProperty;
85 
86 public:
87  GraphSortFilterProxyModel(QObject* parent = NULL);
88 
89  void setFilterProperty(tlp::BooleanProperty*);
90  void setSelectedOnly(bool);
91  void setProperties(QVector<PropertyInterface*>);
92 
93  bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
94  bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
95 
96  void treatEvent(const tlp::Event&);
97 
98  tlp::BooleanProperty* filterProperty() const;
99 };
100 
101 class TLP_QT_SCOPE NodesGraphModel: public GraphModel {
102 public:
103  NodesGraphModel(QObject* parent = NULL);
104  void setGraph(Graph *);
105 
106  void treatEvent(const tlp::Event &);
107  virtual bool lessThan(unsigned int,unsigned int,tlp::PropertyInterface*) const;
108  virtual QString stringValue(unsigned int,tlp::PropertyInterface*) const;
109  virtual QVariant value(unsigned int,tlp::PropertyInterface*) const;
110  bool isNode() const {
111  return true;
112  }
113 
114 protected:
115  virtual bool setValue(unsigned int,tlp::PropertyInterface*,QVariant) const;
116 };
117 
118 class TLP_QT_SCOPE EdgesGraphModel: public GraphModel {
119 public:
120  EdgesGraphModel(QObject* parent = NULL);
121  void setGraph(Graph *);
122  void treatEvent(const tlp::Event &);
123  virtual bool lessThan(unsigned int,unsigned int,tlp::PropertyInterface*) const;
124  virtual QString stringValue(unsigned int,tlp::PropertyInterface*) const;
125  virtual QVariant value(unsigned int,tlp::PropertyInterface*) const;
126 
127  bool isNode() const {
128  return false;
129  }
130 protected:
131  virtual bool setValue(unsigned int,tlp::PropertyInterface*,QVariant) const;
132 };
133 
134 }
135 
136 #endif // GRAPHMODEL_H
137 ///@endcond
A graph property that maps a boolean value to graph elements.
PropertyInterface describes the interface of a graph property.
Event is the base class for all events used in the Observation mechanism.
Definition: Observable.h:47