20 #include <tulip/Graph.h>
24 template<
typename PROPTYPE>
25 void tlp::GraphPropertiesModel<PROPTYPE>::rebuildCache() {
32 forEach(propName,_graph->getInheritedProperties()) {
35 if (propName ==
"viewMetaGraph")
39 PROPTYPE* prop =
dynamic_cast<PROPTYPE*
>(_graph->getProperty(propName));
45 forEach(propName,_graph->getLocalProperties()) {
48 if (propName ==
"viewMetaGraph")
52 PROPTYPE* prop =
dynamic_cast<PROPTYPE*
>(_graph->getProperty(propName));
60 template<
typename PROPTYPE>
61 GraphPropertiesModel<PROPTYPE>::GraphPropertiesModel(
tlp::Graph* graph,
bool checkable, QObject *parent): tlp::TulipModel(parent), _graph(graph), _placeholder(QString::null), _checkable(checkable), _removingRows(false) {
63 _graph->addListener(
this);
68 template<
typename PROPTYPE>
69 GraphPropertiesModel<PROPTYPE>::GraphPropertiesModel(QString placeholder,
tlp::Graph* graph,
bool checkable, QObject *parent): tlp::TulipModel(parent), _graph(graph), _placeholder(placeholder), _checkable(checkable), _removingRows(false) {
71 _graph->addListener(
this);
76 template<
typename PROPTYPE>
77 QModelIndex GraphPropertiesModel<PROPTYPE>::index(
int row,
int column,
const QModelIndex &parent)
const {
78 if (_graph == NULL || !hasIndex(row,column,parent))
81 int vectorIndex = row;
83 if (!_placeholder.isNull()) {
85 return createIndex(row,column);
90 return createIndex(row,column,_properties[vectorIndex]);
93 template<
typename PROPTYPE>
94 QModelIndex GraphPropertiesModel<PROPTYPE>::parent(
const QModelIndex &)
const {
98 template<
typename PROPTYPE>
99 int GraphPropertiesModel<PROPTYPE>::rowCount(
const QModelIndex &parent)
const {
100 if (parent.isValid() || _graph == NULL)
103 int result = _properties.size();
105 if (!_placeholder.isNull())
111 template<
typename PROPTYPE>
112 int GraphPropertiesModel<PROPTYPE>::columnCount(
const QModelIndex &)
const {
116 template<
typename PROPTYPE>
117 QVariant GraphPropertiesModel<PROPTYPE>::data(
const QModelIndex &index,
int role)
const {
118 if (_graph == NULL || (index.internalPointer() == NULL && index.row() != 0))
121 PROPTYPE* pi = (PROPTYPE*)(index.internalPointer());
123 if (role == Qt::DisplayRole || role == Qt::ToolTipRole) {
124 if (!_placeholder.isNull() && index.row() == 0)
130 if (index.column() == 0)
131 return QString::fromUtf8(pi->getName().c_str());
132 else if (index.column() == 1)
133 return pi->getTypename().c_str();
134 else if (index.column() == 2)
135 return (_graph->existLocalProperty(pi->getName()) ? trUtf8(
"Local") : tr(
"Inherited from graph ") + QString::number(pi->getGraph()->getId()) +
" (" + QString::fromUtf8(pi->getGraph()->getName().c_str()) +
')');
138 else if (role == Qt::DecorationRole && index.column() == 0 && pi != NULL && !_graph->existLocalProperty(pi->getName()))
139 return QIcon(
":/tulip/gui/ui/inherited_properties.png");
141 else if (role == Qt::FontRole) {
144 if (!_placeholder.isNull() && index.row() == 0)
149 else if (role == PropertyRole) {
150 return QVariant::fromValue<PropertyInterface*>(pi);
152 else if (_checkable && role == Qt::CheckStateRole && index.column() == 0) {
153 return (_checkedProperties.contains(pi) ? Qt::Checked : Qt::Unchecked);
159 template<
typename PROPTYPE>
160 int GraphPropertiesModel<PROPTYPE>::rowOf(PROPTYPE* pi)
const {
161 int result = _properties.indexOf(pi);
163 if (!_placeholder.isNull())
169 template<
typename PROPTYPE>
170 QVariant tlp::GraphPropertiesModel<PROPTYPE>::headerData(
int section, Qt::Orientation orientation,
int role)
const {
171 if (orientation == Qt::Horizontal) {
172 if (role == Qt::DisplayRole) {
174 return trUtf8(
"Name");
175 else if (section == 1)
176 return trUtf8(
"Type");
177 else if (section == 2)
178 return trUtf8(
"Scope");
182 return TulipModel::headerData(section,orientation,role);
185 template<
typename PROPTYPE>
186 bool tlp::GraphPropertiesModel<PROPTYPE>::setData(
const QModelIndex &index,
const QVariant &value,
int role) {
190 if (_checkable && role == Qt::CheckStateRole && index.column() == 0) {
191 if (value.value<
int>() == (int)Qt::Checked)
192 _checkedProperties.insert((PROPTYPE*)index.internalPointer());
194 _checkedProperties.remove((PROPTYPE*)index.internalPointer());
196 emit checkStateChanged(index,(Qt::CheckState)(value.value<
int>()));