21 #ifndef GRAPHPROPERTIESMODEL_H 22 #define GRAPHPROPERTIESMODEL_H 24 #include <tulip/TulipModel.h> 25 #include <tulip/Observable.h> 26 #include <tulip/Graph.h> 34 template <
typename PROPTYPE>
35 class GraphPropertiesModel :
public tlp::TulipModel,
public tlp::Observable {
39 QSet<PROPTYPE *> _checkedProperties;
40 QVector<PROPTYPE *> _properties;
47 explicit GraphPropertiesModel(
tlp::Graph *graph,
bool checkable =
false,
48 QObject *parent =
nullptr);
49 explicit GraphPropertiesModel(QString placeholder,
tlp::Graph *graph,
bool checkable =
false,
50 QObject *parent =
nullptr);
51 ~GraphPropertiesModel()
override {
52 if (_graph !=
nullptr)
66 if (_graph !=
nullptr)
71 if (_graph !=
nullptr)
78 QSet<PROPTYPE *> checkedProperties()
const {
79 return _checkedProperties;
83 QModelIndex index(
int row,
int column,
const QModelIndex &parent = QModelIndex())
const override;
84 QModelIndex parent(
const QModelIndex &child)
const override;
85 int rowCount(
const QModelIndex &parent = QModelIndex())
const override;
86 int columnCount(
const QModelIndex &parent = QModelIndex())
const override;
87 QVariant data(
const QModelIndex &index,
int role = Qt::DisplayRole)
const override;
88 QVariant headerData(
int section, Qt::Orientation orientation,
int role)
const override;
89 bool setData(
const QModelIndex &quiindex,
const QVariant &value,
int role)
override;
92 void treatEvent(
const tlp::Event &evt)
override {
93 if (evt.type() == Event::TLP_DELETE) {
104 const GraphEvent *graphEvent =
dynamic_cast<const GraphEvent *
>(&evt);
106 if (graphEvent ==
nullptr)
109 if (graphEvent->getType() == GraphEvent::TLP_BEFORE_DEL_LOCAL_PROPERTY ||
110 graphEvent->getType() == GraphEvent::TLP_BEFORE_DEL_INHERITED_PROPERTY) {
112 PROPTYPE *prop =
dynamic_cast<PROPTYPE *
>(_graph->
getProperty(graphEvent->getPropertyName()));
114 if (prop !=
nullptr) {
115 int row = rowOf(prop);
117 beginRemoveRows(QModelIndex(), row, row);
118 _properties.remove(_properties.indexOf(prop));
119 _removingRows =
true;
120 _checkedProperties.remove(prop);
123 }
else if (graphEvent->getType() == GraphEvent::TLP_AFTER_DEL_LOCAL_PROPERTY ||
124 graphEvent->getType() == GraphEvent::TLP_AFTER_DEL_INHERITED_PROPERTY) {
127 _removingRows =
false;
129 }
else if (graphEvent->getType() == GraphEvent::TLP_ADD_LOCAL_PROPERTY ||
130 graphEvent->getType() == GraphEvent::TLP_ADD_INHERITED_PROPERTY) {
131 PROPTYPE *prop =
dynamic_cast<PROPTYPE *
>(_graph->
getProperty(graphEvent->getPropertyName()));
133 if (prop !=
nullptr) {
135 int row = rowOf(prop);
138 beginInsertRows(QModelIndex(), row, row);
142 }
else if (graphEvent->getType() == GraphEvent::TLP_AFTER_RENAME_LOCAL_PROPERTY) {
144 emit layoutAboutToBeChanged();
145 changePersistentIndex(createIndex(0, 0), createIndex(_properties.size() - 1, 0));
146 emit layoutChanged();
150 int rowOf(PROPTYPE *)
const;
152 int rowOf(
const QString &pName)
const;
154 Qt::ItemFlags flags(
const QModelIndex &index)
const override {
155 Qt::ItemFlags result = QAbstractItemModel::flags(index);
157 if (index.column() == 0 && _checkable)
158 result |= Qt::ItemIsUserCheckable;
165 #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 removeListener(Observable *const listener) const
Removes a listener from this object.
Event is the base class for all events used in the Observation mechanism.
virtual void clear()=0
Removes all nodes, edges and subgraphs from this graph.
The Observable class is the base of Tulip's observation system.
void addListener(Observable *const listener) const
Adds a Listener to this object.