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) {
106 PROPTYPE* prop =
dynamic_cast<PROPTYPE*
>(_graph->getProperty(graphEvent->getPropertyName()));
109 int row = rowOf(prop);
110 beginRemoveRows(QModelIndex(),row,row);
111 _properties.remove(row);
112 _removingRows =
true;
115 else if (graphEvent->getType() == GraphEvent::TLP_AFTER_DEL_LOCAL_PROPERTY || graphEvent->getType() == GraphEvent::TLP_AFTER_DEL_INHERITED_PROPERTY) {
118 _removingRows =
false;
121 else if (graphEvent->getType() == GraphEvent::TLP_ADD_LOCAL_PROPERTY || graphEvent->getType() == GraphEvent::TLP_ADD_INHERITED_PROPERTY) {
122 PROPTYPE* prop =
dynamic_cast<PROPTYPE*
>(_graph->getProperty(graphEvent->getPropertyName()));
126 int row = rowOf(prop);
129 beginInsertRows(QModelIndex(),row,row);
136 int rowOf(PROPTYPE*)
const;
138 Qt::ItemFlags flags(
const QModelIndex &index)
const {
139 Qt::ItemFlags result = QAbstractItemModel::flags(index);
141 if (index.column() == 0 && _checkable)
142 result |= Qt::ItemIsUserCheckable;
150 #include "cxx/GraphPropertiesModel.cxx"
153 #endif // GRAPHPROPERTIESMODEL_H