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), forcingRedraw(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), forcingRedraw(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 || forcingRedraw)
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 PropertyInterface* pi = (PropertyInterface*)(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((PROPTYPE*) 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 int GraphPropertiesModel<PROPTYPE>::rowOf(
const QString& pName)
const {
171 for(
int i = 0; i < _properties.size(); ++i) {
172 if (pName == QString::fromUtf8(_properties[i]->getName().c_str()))
179 template<
typename PROPTYPE>
180 QVariant tlp::GraphPropertiesModel<PROPTYPE>::headerData(
int section, Qt::Orientation orientation,
int role)
const {
181 if (orientation == Qt::Horizontal) {
182 if (role == Qt::DisplayRole) {
184 return trUtf8(
"Name");
185 else if (section == 1)
186 return trUtf8(
"Type");
187 else if (section == 2)
188 return trUtf8(
"Scope");
192 return TulipModel::headerData(section,orientation,role);
195 template<
typename PROPTYPE>
196 bool tlp::GraphPropertiesModel<PROPTYPE>::setData(
const QModelIndex &index,
const QVariant &value,
int role) {
200 if (_checkable && role == Qt::CheckStateRole && index.column() == 0) {
201 if (value.value<
int>() == (int)Qt::Checked)
202 _checkedProperties.insert((PROPTYPE*)index.internalPointer());
204 _checkedProperties.remove((PROPTYPE*)index.internalPointer());
206 emit checkStateChanged(index,(Qt::CheckState)(value.value<
int>()));