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;
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() {
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 &quiindex,
const QVariant &value,
int role);
92 if (evt.type() == Event::TLP_DELETE) {
103 const GraphEvent* graphEvent =
dynamic_cast<const GraphEvent*
>(&evt);
105 if (graphEvent == NULL)
108 if (graphEvent->getType() == GraphEvent::TLP_BEFORE_DEL_LOCAL_PROPERTY || graphEvent->getType() == GraphEvent::TLP_BEFORE_DEL_INHERITED_PROPERTY) {
110 PROPTYPE* prop =
dynamic_cast<PROPTYPE*
>(_graph->
getProperty(graphEvent->getPropertyName()));
113 int row = rowOf(prop);
114 beginRemoveRows(QModelIndex(),row,row);
115 _properties.remove(_properties.indexOf(prop));
116 _removingRows =
true;
117 _checkedProperties.remove(prop);
120 else if (graphEvent->getType() == GraphEvent::TLP_AFTER_DEL_LOCAL_PROPERTY || graphEvent->getType() == GraphEvent::TLP_AFTER_DEL_INHERITED_PROPERTY) {
123 _removingRows =
false;
126 else if (graphEvent->getType() == GraphEvent::TLP_ADD_LOCAL_PROPERTY || graphEvent->getType() == GraphEvent::TLP_ADD_INHERITED_PROPERTY) {
127 PROPTYPE* prop =
dynamic_cast<PROPTYPE*
>(_graph->
getProperty(graphEvent->getPropertyName()));
131 int row = rowOf(prop);
134 beginInsertRows(QModelIndex(),row,row);
139 else if (graphEvent->getType() == GraphEvent::TLP_AFTER_RENAME_LOCAL_PROPERTY) {
141 emit layoutAboutToBeChanged();
142 changePersistentIndex(createIndex(0, 0),
143 createIndex(_properties.size() - 1, 0));
144 emit layoutChanged();
148 int rowOf(PROPTYPE*)
const;
150 int rowOf(
const QString& pName)
const;
152 Qt::ItemFlags flags(
const QModelIndex &index)
const {
153 Qt::ItemFlags result = QAbstractItemModel::flags(index);
155 if (index.column() == 0 && _checkable)
156 result |= Qt::ItemIsUserCheckable;
164 #include "cxx/GraphPropertiesModel.cxx" 167 #endif // GRAPHPROPERTIESMODEL_H
virtual PropertyInterface * getProperty(const std::string &name) const =0
Gets an existing property. In DEBUG mode an assertion checks the existence of the property...
void addListener(Observable *const listener) const
Adds a Listener to this object.
Event is the base class for all events used in the Observation mechanism.
void removeListener(Observable *const listener) const
Removes a listener from this object.
virtual void clear()=0
Removes all nodes, edges and sub-graphs from this graph.
The Observable class is the base of Tulip's observation system.