20 #include <tulip/Graph.h> 21 #include <tulip/TlpQtTools.h> 25 template<
typename PROPTYPE>
26 void tlp::GraphPropertiesModel<PROPTYPE>::rebuildCache() {
33 forEach(propName,_graph->getInheritedProperties()) {
36 if (propName ==
"viewMetaGraph")
40 PROPTYPE* prop =
dynamic_cast<PROPTYPE*
>(_graph->getProperty(propName));
46 forEach(propName,_graph->getLocalProperties()) {
49 if (propName ==
"viewMetaGraph")
53 PROPTYPE* prop =
dynamic_cast<PROPTYPE*
>(_graph->getProperty(propName));
61 template<
typename PROPTYPE>
62 GraphPropertiesModel<PROPTYPE>::GraphPropertiesModel(
tlp::Graph* graph,
bool checkable, QObject *parent):
tlp::TulipModel(parent), _graph(graph), _checkable(checkable), _removingRows(false), forcingRedraw(false) {
64 _graph->addListener(
this);
69 template<
typename PROPTYPE>
70 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) {
72 _graph->addListener(
this);
77 template<
typename PROPTYPE>
78 QModelIndex GraphPropertiesModel<PROPTYPE>::index(
int row,
int column,
const QModelIndex &parent)
const {
79 if (_graph == NULL || !hasIndex(row,column,parent))
82 int vectorIndex = row;
84 if (!_placeholder.isEmpty()) {
86 return createIndex(row,column);
91 return createIndex(row,column,_properties[vectorIndex]);
94 template<
typename PROPTYPE>
95 QModelIndex GraphPropertiesModel<PROPTYPE>::parent(
const QModelIndex &)
const {
99 template<
typename PROPTYPE>
100 int GraphPropertiesModel<PROPTYPE>::rowCount(
const QModelIndex &parent)
const {
101 if (parent.isValid() || _graph == NULL || forcingRedraw)
104 int result = _properties.size();
106 if (!_placeholder.isEmpty())
112 template<
typename PROPTYPE>
113 int GraphPropertiesModel<PROPTYPE>::columnCount(
const QModelIndex &)
const {
117 template<
typename PROPTYPE>
118 QVariant GraphPropertiesModel<PROPTYPE>::data(
const QModelIndex &index,
int role)
const {
119 if (_graph == NULL || (index.internalPointer() == NULL && index.row() != 0))
122 PropertyInterface* pi = (PropertyInterface*)(index.internalPointer());
124 if (role == Qt::DisplayRole || role == Qt::ToolTipRole) {
125 if (!_placeholder.isEmpty() && index.row() == 0)
131 if (index.column() == 0)
133 else if (index.column() == 1)
134 return pi->getTypename().c_str();
135 else if (index.column() == 2)
136 return (_graph->existLocalProperty(pi->getName()) ? trUtf8(
"Local") : tr(
"Inherited from graph ") + QString::number(pi->getGraph()->getId()) +
" (" +
tlpStringToQString(pi->getGraph()->getName()) +
')');
139 else if (role == Qt::DecorationRole && index.column() == 0 && pi != NULL && !_graph->existLocalProperty(pi->getName()))
140 return QIcon(
":/tulip/gui/ui/inherited_properties.png");
142 else if (role == Qt::FontRole) {
145 if (!_placeholder.isEmpty() && index.row() == 0)
150 else if (role == PropertyRole) {
151 return QVariant::fromValue<PropertyInterface*>(pi);
153 else if (_checkable && role == Qt::CheckStateRole && index.column() == 0) {
154 return (_checkedProperties.contains((PROPTYPE*) pi) ? Qt::Checked : Qt::Unchecked);
160 template<
typename PROPTYPE>
161 int GraphPropertiesModel<PROPTYPE>::rowOf(PROPTYPE* pi)
const {
162 int result = _properties.indexOf(pi);
164 if (!_placeholder.isEmpty())
170 template<
typename PROPTYPE>
171 int GraphPropertiesModel<PROPTYPE>::rowOf(
const QString& pName)
const {
172 for(
int i = 0; i < _properties.size(); ++i) {
180 template<
typename PROPTYPE>
181 QVariant tlp::GraphPropertiesModel<PROPTYPE>::headerData(
int section, Qt::Orientation orientation,
int role)
const {
182 if (orientation == Qt::Horizontal) {
183 if (role == Qt::DisplayRole) {
185 return trUtf8(
"Name");
186 else if (section == 1)
187 return trUtf8(
"Type");
188 else if (section == 2)
189 return trUtf8(
"Scope");
193 return TulipModel::headerData(section,orientation,role);
196 template<
typename PROPTYPE>
197 bool tlp::GraphPropertiesModel<PROPTYPE>::setData(
const QModelIndex &index,
const QVariant &value,
int role) {
201 if (_checkable && role == Qt::CheckStateRole && index.column() == 0) {
202 if (value.value<
int>() == (int)Qt::Checked)
203 _checkedProperties.insert((PROPTYPE*)index.internalPointer());
205 _checkedProperties.remove((PROPTYPE*)index.internalPointer());
207 emit checkStateChanged(index,(Qt::CheckState)(value.value<
int>()));
QString tlpStringToQString(const std::string &toConvert)
Convert a Tulip UTF-8 encoded std::string to a QString.