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