22 #ifndef GRAPHPROPERTIESMODEL_H
23 #define GRAPHPROPERTIESMODEL_H
25 #include <tulip/TulipModel.h>
26 #include <tulip/Observable.h>
27 #include <tulip/Graph.h>
35 template<
typename PROPTYPE>
36 class GraphPropertiesModel :
public tlp::TulipModel,
public tlp::Observable {
40 QSet<PROPTYPE*> _checkedProperties;
41 QVector<PROPTYPE*> _properties;
47 explicit GraphPropertiesModel(
tlp::Graph* graph,
bool checkable=
false, QObject *parent = NULL);
48 explicit GraphPropertiesModel(QString placeholder,
tlp::Graph* graph,
bool checkable=
false, QObject *parent = NULL);
49 virtual ~GraphPropertiesModel() {}
62 _graph->removeListener(
this);
73 QSet<PROPTYPE*> checkedProperties()
const {
74 return _checkedProperties;
78 QModelIndex index(
int row,
int column,
const QModelIndex &parent = QModelIndex())
const;
79 QModelIndex parent(
const QModelIndex &child)
const;
80 int rowCount(
const QModelIndex &parent = QModelIndex())
const;
81 int columnCount(
const QModelIndex &parent = QModelIndex())
const;
82 QVariant data(
const QModelIndex &index,
int role = Qt::DisplayRole)
const;
83 QVariant headerData(
int section, Qt::Orientation orientation,
int role)
const;
84 bool setData(
const QModelIndex &quiindex,
const QVariant &value,
int role);
88 if (evt.type() == Event::TLP_DELETE) {
96 const GraphEvent* graphEvent =
dynamic_cast<const GraphEvent*
>(&evt);
98 if (graphEvent == NULL)
101 if (graphEvent->getType() == GraphEvent::TLP_BEFORE_DEL_LOCAL_PROPERTY || graphEvent->getType() == GraphEvent::TLP_BEFORE_DEL_INHERITED_PROPERTY) {
103 PROPTYPE* prop =
dynamic_cast<PROPTYPE*
>(_graph->getProperty(graphEvent->getPropertyName()));
106 int row = rowOf(prop);
107 beginRemoveRows(QModelIndex(),row,row);
108 _properties.remove(_properties.indexOf(prop));
109 _removingRows =
true;
110 _checkedProperties.remove(prop);
113 else if (graphEvent->getType() == GraphEvent::TLP_AFTER_DEL_LOCAL_PROPERTY || graphEvent->getType() == GraphEvent::TLP_AFTER_DEL_INHERITED_PROPERTY) {
116 _removingRows =
false;
119 else if (graphEvent->getType() == GraphEvent::TLP_ADD_LOCAL_PROPERTY || graphEvent->getType() == GraphEvent::TLP_ADD_INHERITED_PROPERTY) {
120 PROPTYPE* prop =
dynamic_cast<PROPTYPE*
>(_graph->getProperty(graphEvent->getPropertyName()));
124 int row = rowOf(prop);
127 beginInsertRows(QModelIndex(),row,row);
134 int rowOf(PROPTYPE*)
const;
136 Qt::ItemFlags flags(
const QModelIndex &index)
const {
137 Qt::ItemFlags result = QAbstractItemModel::flags(index);
139 if (index.column() == 0 && _checkable)
140 result |= Qt::ItemIsUserCheckable;
148 #include "cxx/GraphPropertiesModel.cxx"
151 #endif // GRAPHPROPERTIESMODEL_H