20 #include <tulip/Graph.h> 21 #include <tulip/TlpQtTools.h> 25 template <
typename PROPTYPE>
26 void tlp::GraphPropertiesModel<PROPTYPE>::rebuildCache() {
29 if (_graph ==
nullptr)
32 for (
auto inheritedProp : _graph->getInheritedObjectProperties()) {
35 if (inheritedProp->getName() ==
"viewMetaGraph")
39 PROPTYPE *prop =
dynamic_cast<PROPTYPE *
>(inheritedProp);
41 if (prop !=
nullptr) {
45 for (
auto localProp : _graph->getLocalObjectProperties()) {
48 if (localProp->getName() ==
"viewMetaGraph")
52 PROPTYPE *prop =
dynamic_cast<PROPTYPE *
>(localProp);
54 if (prop !=
nullptr) {
60 template <
typename PROPTYPE>
61 GraphPropertiesModel<PROPTYPE>::GraphPropertiesModel(
tlp::Graph *graph,
bool checkable,
63 :
tlp::TulipModel(parent), _graph(graph), _checkable(checkable), _removingRows(false),
64 forcingRedraw(false) {
65 if (_graph !=
nullptr) {
66 _graph->addListener(
this);
71 template <
typename PROPTYPE>
72 GraphPropertiesModel<PROPTYPE>::GraphPropertiesModel(QString placeholder,
tlp::Graph *graph,
73 bool checkable, QObject *parent)
74 :
tlp::TulipModel(parent), _graph(graph), _placeholder(placeholder), _checkable(checkable),
75 _removingRows(false), forcingRedraw(false) {
76 if (_graph !=
nullptr) {
77 _graph->addListener(
this);
82 template <
typename PROPTYPE>
83 QModelIndex GraphPropertiesModel<PROPTYPE>::index(
int row,
int column,
84 const QModelIndex &parent)
const {
85 if (_graph ==
nullptr || !hasIndex(row, column, parent))
88 int vectorIndex = row;
90 if (!_placeholder.isEmpty()) {
92 return createIndex(row, column);
97 return createIndex(row, column, _properties[vectorIndex]);
100 template <
typename PROPTYPE>
101 QModelIndex GraphPropertiesModel<PROPTYPE>::parent(
const QModelIndex &)
const {
102 return QModelIndex();
105 template <
typename PROPTYPE>
106 int GraphPropertiesModel<PROPTYPE>::rowCount(
const QModelIndex &parent)
const {
107 if (parent.isValid() || _graph ==
nullptr || forcingRedraw)
110 int result = _properties.size();
112 if (!_placeholder.isEmpty())
118 template <
typename PROPTYPE>
119 int GraphPropertiesModel<PROPTYPE>::columnCount(
const QModelIndex &)
const {
123 template <
typename PROPTYPE>
124 QVariant GraphPropertiesModel<PROPTYPE>::data(
const QModelIndex &index,
int role)
const {
125 if (_graph ==
nullptr || (index.internalPointer() ==
nullptr && index.row() != 0))
128 PropertyInterface *pi =
static_cast<PropertyInterface *
>(index.internalPointer());
130 if (role == Qt::DisplayRole || role == Qt::ToolTipRole) {
131 if (!_placeholder.isEmpty() && index.row() == 0)
137 if (index.column() == 0)
139 else if (index.column() == 1)
140 return pi->getTypename().c_str();
141 else if (index.column() == 2)
142 return (_graph->existLocalProperty(pi->getName())
144 : tr(
"Inherited from graph ") + QString::number(pi->getGraph()->getId()) +
" (" +
148 else if (role == Qt::DecorationRole && index.column() == 0 && pi !=
nullptr &&
149 !_graph->existLocalProperty(pi->getName()))
150 return QIcon(
":/tulip/gui/ui/inherited_properties.png");
152 else if (role == Qt::FontRole) {
155 if (!_placeholder.isEmpty() && index.row() == 0)
159 }
else if (role == PropertyRole) {
160 return QVariant::fromValue<PropertyInterface *>(pi);
161 }
else if (_checkable && role == Qt::CheckStateRole && index.column() == 0) {
162 return (_checkedProperties.contains(static_cast<PROPTYPE *>(pi)) ? Qt::Checked : Qt::Unchecked);
168 template <
typename PROPTYPE>
169 int GraphPropertiesModel<PROPTYPE>::rowOf(PROPTYPE *pi)
const {
170 int result = _properties.indexOf(pi);
172 if (result > -1 && !_placeholder.isEmpty())
178 template <
typename PROPTYPE>
179 int GraphPropertiesModel<PROPTYPE>::rowOf(
const QString &pName)
const {
180 for (
int i = 0; i < _properties.size(); ++i) {
188 template <
typename PROPTYPE>
189 QVariant tlp::GraphPropertiesModel<PROPTYPE>::headerData(
int section, Qt::Orientation orientation,
191 if (orientation == Qt::Horizontal) {
192 if (role == Qt::DisplayRole) {
194 return trUtf8(
"Name");
195 else if (section == 1)
196 return trUtf8(
"Type");
197 else if (section == 2)
198 return trUtf8(
"Scope");
202 return TulipModel::headerData(section, orientation, role);
205 template <
typename PROPTYPE>
206 bool tlp::GraphPropertiesModel<PROPTYPE>::setData(
const QModelIndex &index,
const QVariant &value,
208 if (_graph ==
nullptr)
211 if (_checkable && role == Qt::CheckStateRole && index.column() == 0) {
212 if (value.value<
int>() == int(Qt::Checked))
213 _checkedProperties.insert(static_cast<PROPTYPE *>(index.internalPointer()));
215 _checkedProperties.remove(static_cast<PROPTYPE *>(index.internalPointer()));
217 emit checkStateChanged(index, static_cast<Qt::CheckState>(value.value<
int>()));
QString tlpStringToQString(const std::string &toConvert)
Convert a Tulip UTF-8 encoded std::string to a QString.