20 #include <tulip/Graph.h>
24 template<
typename PROPTYPE>
25 void tlp::GraphPropertiesModel<PROPTYPE>::rebuildCache() {
32 forEach(propName,_graph->getInheritedProperties()) {
34 if (propName ==
"viewMetaGraph")
37 PROPTYPE* prop =
dynamic_cast<PROPTYPE*
>(_graph->getProperty(propName));
43 forEach(propName,_graph->getLocalProperties()) {
46 if (propName ==
"viewMetaGraph")
50 PROPTYPE* prop =
dynamic_cast<PROPTYPE*
>(_graph->getProperty(propName));
58 template<
typename PROPTYPE>
59 GraphPropertiesModel<PROPTYPE>::GraphPropertiesModel(
tlp::Graph* graph,
bool checkable, QObject *parent): tlp::TulipModel(parent), _graph(graph), _placeholder(QString::null), _checkable(checkable), _removingRows(false) {
61 _graph->addListener(
this);
66 template<
typename PROPTYPE>
67 GraphPropertiesModel<PROPTYPE>::GraphPropertiesModel(QString placeholder,
tlp::Graph* graph,
bool checkable, QObject *parent): tlp::TulipModel(parent), _graph(graph), _placeholder(placeholder), _checkable(checkable), _removingRows(false) {
69 _graph->addListener(
this);
74 template<
typename PROPTYPE>
75 QModelIndex GraphPropertiesModel<PROPTYPE>::index(
int row,
int column,
const QModelIndex &parent)
const {
76 if (_graph == NULL || !hasIndex(row,column,parent))
79 int vectorIndex = row;
81 if (!_placeholder.isNull()) {
83 return createIndex(row,column);
88 return createIndex(row,column,_properties[vectorIndex]);
91 template<
typename PROPTYPE>
92 QModelIndex GraphPropertiesModel<PROPTYPE>::parent(
const QModelIndex &)
const {
96 template<
typename PROPTYPE>
97 int GraphPropertiesModel<PROPTYPE>::rowCount(
const QModelIndex &parent)
const {
98 if (parent.isValid() || _graph == NULL)
101 int result = _properties.size();
103 if (!_placeholder.isNull())
109 template<
typename PROPTYPE>
110 int GraphPropertiesModel<PROPTYPE>::columnCount(
const QModelIndex &)
const {
114 template<
typename PROPTYPE>
115 QVariant GraphPropertiesModel<PROPTYPE>::data(
const QModelIndex &index,
int role)
const {
116 if (_graph == NULL || (index.internalPointer() == NULL && index.row() != 0))
119 PROPTYPE* pi = (PROPTYPE*)(index.internalPointer());
121 if (role == Qt::DisplayRole || role == Qt::ToolTipRole) {
122 if (!_placeholder.isNull() && index.row() == 0)
128 if (index.column() == 0)
129 return QString::fromUtf8(pi->getName().c_str());
130 else if (index.column() == 1)
131 return pi->getTypename().c_str();
132 else if (index.column() == 2)
133 return (_graph->existLocalProperty(pi->getName()) ? trUtf8(
"Local") : trUtf8(
"Inherited"));
136 else if (role == Qt::DecorationRole && index.column() == 0 && pi != NULL && !_graph->existLocalProperty(pi->getName()))
137 return QIcon(
":/tulip/gui/ui/inherited_properties.png");
139 else if (role == Qt::FontRole) {
142 if (!_placeholder.isNull() && index.row() == 0)
147 else if (role == PropertyRole) {
148 return QVariant::fromValue<PropertyInterface*>(pi);
150 else if (_checkable && role == Qt::CheckStateRole && index.column() == 0) {
151 return (_checkedProperties.contains(pi) ? Qt::Checked : Qt::Unchecked);
157 template<
typename PROPTYPE>
158 int GraphPropertiesModel<PROPTYPE>::rowOf(PROPTYPE* pi)
const {
159 return _properties.indexOf(pi);
162 template<
typename PROPTYPE>
163 QVariant tlp::GraphPropertiesModel<PROPTYPE>::headerData(
int section, Qt::Orientation orientation,
int role)
const {
164 if (orientation == Qt::Horizontal) {
165 if (role == Qt::DisplayRole) {
167 return trUtf8(
"Name");
168 else if (section == 1)
169 return trUtf8(
"Type");
170 else if (section == 2)
171 return trUtf8(
"Scope");
175 return TulipModel::headerData(section,orientation,role);
178 template<
typename PROPTYPE>
179 bool tlp::GraphPropertiesModel<PROPTYPE>::setData(
const QModelIndex &index,
const QVariant &value,
int role) {
183 if (_checkable && role == Qt::CheckStateRole && index.column() == 0) {
184 if (value.value<
int>() == (int)Qt::Checked)
185 _checkedProperties.insert((PROPTYPE*)index.internalPointer());
187 _checkedProperties.remove((PROPTYPE*)index.internalPointer());
189 emit checkStateChanged(index,(Qt::CheckState)(value.value<
int>()));