26#include <QSortFilterProxyModel>
28#include <tulip/Edge.h>
29#include <tulip/Observable.h>
30#include <tulip/TulipModel.h>
37class TLP_QT_SCOPE GraphModel :
public tlp::TulipModel,
public Observable {
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 setNodeDefaultValue(tlp::PropertyInterface *, QVariant);
44 static bool setAllNodeValue(tlp::PropertyInterface *, QVariant, Graph *graph =
nullptr);
45 static QVariant edgeValue(
unsigned int, tlp::PropertyInterface *);
46 static QVariant edgeDefaultValue(tlp::PropertyInterface *);
47 static bool setEdgeValue(
unsigned int, tlp::PropertyInterface *, QVariant);
48 static bool setEdgeDefaultValue(tlp::PropertyInterface *, QVariant);
49 static bool setAllEdgeValue(tlp::PropertyInterface *, QVariant, Graph *graph =
nullptr);
51 explicit GraphModel(QObject *parent =
nullptr);
53 virtual void setGraph(tlp::Graph *);
54 tlp::Graph *graph()
const;
57 int rowCount(
const QModelIndex &parent = QModelIndex())
const override;
58 int columnCount(
const QModelIndex &parent = QModelIndex())
const override;
59 QModelIndex parent(
const QModelIndex &child)
const override;
60 Qt::ItemFlags flags(
const QModelIndex &index)
const override;
62 QVariant headerData(
int section, Qt::Orientation orientation,
int role)
const override;
63 QModelIndex index(
int row,
int column,
const QModelIndex &parent = QModelIndex())
const override;
64 QVariant data(
const QModelIndex &index,
int role = Qt::DisplayRole)
const override;
65 bool setData(
const QModelIndex &index,
const QVariant &value,
int role)
override;
67 void treatEvent(
const tlp::Event &)
override;
68 void treatEvents(
const std::vector<tlp::Event> &)
override;
70 unsigned int elementAt(
int)
const;
71 virtual bool lessThan(
unsigned int,
unsigned int, tlp::PropertyInterface *)
const = 0;
72 virtual QString stringValue(
unsigned int, tlp::PropertyInterface *)
const = 0;
73 virtual QVariant value(
unsigned int, tlp::PropertyInterface *)
const = 0;
74 virtual bool isNode()
const = 0;
78 QVector<unsigned int> _elements;
79 QVector<QPair<unsigned int, bool>> _elementsToModify;
80 QVector<PropertyInterface *> _properties;
81 QSet<PropertyInterface *> _propertiesModified;
83 virtual bool setValue(
unsigned int, tlp::PropertyInterface *, QVariant)
const = 0;
84 void addRemoveRowsSequence(QVector<unsigned int> &rowsSequence,
bool add);
87class TLP_QT_SCOPE GraphSortFilterProxyModel :
public QSortFilterProxyModel,
public Observable {
88 QVector<PropertyInterface *> _properties;
89 BooleanProperty *_filterProperty;
92 GraphSortFilterProxyModel(QObject *parent =
nullptr);
94 void setFilterProperty(tlp::BooleanProperty *);
95 void setSelectedOnly(
bool);
96 void setProperties(QVector<PropertyInterface *>);
98 bool lessThan(
const QModelIndex &left,
const QModelIndex &right)
const override;
99 bool filterAcceptsRow(
int sourceRow,
const QModelIndex &sourceParent)
const override;
101 void treatEvent(
const tlp::Event &)
override;
103 tlp::BooleanProperty *filterProperty()
const;
106class TLP_QT_SCOPE NodesGraphModel :
public GraphModel {
108 NodesGraphModel(QObject *parent =
nullptr);
109 void setGraph(Graph *)
override;
111 void treatEvent(
const tlp::Event &)
override;
112 void treatEvents(
const std::vector<tlp::Event> &)
override;
113 bool lessThan(
unsigned int,
unsigned int, tlp::PropertyInterface *)
const override;
114 QString stringValue(
unsigned int, tlp::PropertyInterface *)
const override;
115 QVariant value(
unsigned int, tlp::PropertyInterface *)
const override;
116 QVariant headerData(
int section, Qt::Orientation orientation,
int role)
const override;
118 bool isNode()
const override {
122 static QString getNodeTooltip(Graph *graph, node n);
125 bool setValue(
unsigned int, tlp::PropertyInterface *, QVariant)
const override;
132class TLP_QT_SCOPE EdgesGraphModel :
public GraphModel {
134 EdgesGraphModel(QObject *parent =
nullptr);
135 void setGraph(Graph *)
override;
136 void treatEvent(
const tlp::Event &)
override;
137 void treatEvents(
const std::vector<tlp::Event> &)
override;
138 bool lessThan(
unsigned int,
unsigned int, tlp::PropertyInterface *)
const override;
139 QString stringValue(
unsigned int, tlp::PropertyInterface *)
const override;
140 QVariant value(
unsigned int, tlp::PropertyInterface *)
const override;
141 QVariant headerData(
int section, Qt::Orientation orientation,
int role)
const override;
143 bool isNode()
const override {
147 static QString getEdgeTooltip(Graph *graph, edge e);
150 bool setValue(
unsigned int, tlp::PropertyInterface *, QVariant)
const override;
A graph property that maps a Boolean value to graph elements.
The Observable class is the base of Tulip's observation system.
PropertyInterface describes the interface of a graph property.