22 #ifndef GRAPHPROPERTIESMODEL_H
23 #define GRAPHPROPERTIESMODEL_H
25 #include <tulip/TulipModel.h>
26 #include <tulip/Observable.h>
27 #include <tulip/Graph.h>
28 #include <tulip/PropertyInterface.h>
29 #include <QtGui/QFont>
30 #include <QtGui/QIcon>
31 #include <QtCore/QSet>
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() {
51 qDebug() <<
"Deleting GraphPropertiesModel<" <<
typeid(PROPTYPE).name() <<
"*>";
66 _graph->removeListener(
this);
77 QSet<PROPTYPE*> checkedProperties()
const {
78 return _checkedProperties;
82 QModelIndex index(
int row,
int column,
const QModelIndex &parent = QModelIndex())
const;
83 QModelIndex parent(
const QModelIndex &child)
const;
84 int rowCount(
const QModelIndex &parent = QModelIndex())
const;
85 int columnCount(
const QModelIndex &parent = QModelIndex())
const;
86 QVariant data(
const QModelIndex &index,
int role = Qt::DisplayRole)
const;
87 QVariant headerData(
int section, Qt::Orientation orientation,
int role)
const;
88 bool setData(
const QModelIndex &index,
const QVariant &value,
int role);
92 if (evt.type() == Event::TLP_DELETE) {
100 const GraphEvent* graphEvent =
dynamic_cast<const GraphEvent*
>(&evt);
102 if (graphEvent == NULL)
105 if (graphEvent->getType() == GraphEvent::TLP_BEFORE_DEL_LOCAL_PROPERTY || graphEvent->getType() == GraphEvent::TLP_BEFORE_DEL_INHERITED_PROPERTY) {
107 PROPTYPE* prop =
dynamic_cast<PROPTYPE*
>(_graph->getProperty(graphEvent->getPropertyName()));
110 int row = rowOf(prop);
111 beginRemoveRows(QModelIndex(),row,row);
112 _properties.remove(row);
113 _removingRows =
true;
116 else if (graphEvent->getType() == GraphEvent::TLP_AFTER_DEL_LOCAL_PROPERTY || graphEvent->getType() == GraphEvent::TLP_AFTER_DEL_INHERITED_PROPERTY) {
119 _removingRows =
false;
122 else if (graphEvent->getType() == GraphEvent::TLP_ADD_LOCAL_PROPERTY || graphEvent->getType() == GraphEvent::TLP_ADD_INHERITED_PROPERTY) {
123 PROPTYPE* prop =
dynamic_cast<PROPTYPE*
>(_graph->getProperty(graphEvent->getPropertyName()));
127 int row = rowOf(prop);
130 beginInsertRows(QModelIndex(),row,row);
137 int rowOf(PROPTYPE*)
const;
139 Qt::ItemFlags flags(
const QModelIndex &index)
const {
140 Qt::ItemFlags result = QAbstractItemModel::flags(index);
142 if (index.column() == 0 && _checkable)
143 result |= Qt::ItemIsUserCheckable;
151 #include "cxx/GraphPropertiesModel.cxx"
154 #endif // GRAPHPROPERTIESMODEL_H