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 <tulip/TlpQtTools.h>
30 #include <QtGui/QFont>
31 #include <QtGui/QIcon>
32 #include <QtCore/QSet>
36 template<
typename PROPTYPE>
37 class GraphPropertiesModel :
public tlp::TulipModel,
public tlp::Observable {
41 QSet<PROPTYPE*> _checkedProperties;
42 QVector<PROPTYPE*> _properties;
48 explicit GraphPropertiesModel(
tlp::Graph* graph,
bool checkable=
false, QObject *parent = NULL);
49 explicit GraphPropertiesModel(QString placeholder,
tlp::Graph* graph,
bool checkable=
false, QObject *parent = NULL);
50 virtual ~GraphPropertiesModel() {
52 qDebug() <<
"Deleting GraphPropertiesModel<" <<
typeid(PROPTYPE).name() <<
"*>";
67 _graph->removeListener(
this);
78 QSet<PROPTYPE*> checkedProperties()
const {
79 return _checkedProperties;
83 QModelIndex index(
int row,
int column,
const QModelIndex &parent = QModelIndex())
const;
84 QModelIndex parent(
const QModelIndex &child)
const;
85 int rowCount(
const QModelIndex &parent = QModelIndex())
const;
86 int columnCount(
const QModelIndex &parent = QModelIndex())
const;
87 QVariant data(
const QModelIndex &index,
int role = Qt::DisplayRole)
const;
88 QVariant headerData(
int section, Qt::Orientation orientation,
int role)
const;
89 bool setData(
const QModelIndex &quiindex,
const QVariant &value,
int role);
93 if (evt.type() == Event::TLP_DELETE) {
101 const GraphEvent* graphEvent =
dynamic_cast<const GraphEvent*
>(&evt);
103 if (graphEvent == NULL)
106 if (graphEvent->getType() == GraphEvent::TLP_BEFORE_DEL_LOCAL_PROPERTY || graphEvent->getType() == GraphEvent::TLP_BEFORE_DEL_INHERITED_PROPERTY) {
108 PROPTYPE* prop =
dynamic_cast<PROPTYPE*
>(_graph->getProperty(graphEvent->getPropertyName()));
111 int row = rowOf(prop);
112 beginRemoveRows(QModelIndex(),row,row);
113 _properties.remove(_properties.indexOf(prop));
114 _removingRows =
true;
115 _checkedProperties.remove(prop);
118 else if (graphEvent->getType() == GraphEvent::TLP_AFTER_DEL_LOCAL_PROPERTY || graphEvent->getType() == GraphEvent::TLP_AFTER_DEL_INHERITED_PROPERTY) {
121 _removingRows =
false;
124 else if (graphEvent->getType() == GraphEvent::TLP_ADD_LOCAL_PROPERTY || graphEvent->getType() == GraphEvent::TLP_ADD_INHERITED_PROPERTY) {
125 PROPTYPE* prop =
dynamic_cast<PROPTYPE*
>(_graph->getProperty(graphEvent->getPropertyName()));
129 int row = rowOf(prop);
132 beginInsertRows(QModelIndex(),row,row);
139 int rowOf(PROPTYPE*)
const;
141 Qt::ItemFlags flags(
const QModelIndex &index)
const {
142 Qt::ItemFlags result = QAbstractItemModel::flags(index);
144 if (index.column() == 0 && _checkable)
145 result |= Qt::ItemIsUserCheckable;
153 #include "cxx/GraphPropertiesModel.cxx"
156 #endif // GRAPHPROPERTIESMODEL_H