17 return QString::fromStdString(_propertyPath);
22 return QString::fromLatin1(_roleName);
28 if (_propertyPath ==
path.toStdString())
31 _propertyPath =
path.toStdString();
37 if (_roleName ==
roleName.toLatin1())
51 std::string _propertyPath;
70 if (
static_cast<size_t>(index.row()) >= _nodes.size())
73 SGPropertyNode_ptr n = _nodes.at(index.row());
75 int mappingIndex = role - Qt::UserRole;
76 if ((mappingIndex < 0) || (mappingIndex >= _roleMappings.size()))
79 const std::string& nodePath = _roleMappings.at(mappingIndex)->_propertyPath;
80 SGPropertyNode_ptr valueNode = n->getNode(nodePath);
89 QHash<int, QByteArray> result;
91 for (
auto m : _roleMappings) {
92 result[Qt::UserRole + count++] = m->_roleName;
99 return QString::fromStdString(_modelRoot->getPath());
104 return _childNameFilter;
116 if (_modelRoot->getPath() ==
rootPath.toStdString())
137 if (
root->node() == _modelRoot) {
141 innerSetRoot(
root->node());
151 if (parent == _modelRoot) {
152 if (_childNameFilter.isEmpty() || (child->getNameString() == _childNameFilter.toStdString())) {
163 if (parent == _modelRoot) {
173 return QQmlListProperty<PropertyItemModelRoleMapping>(
this,
nullptr,
174 &PropertyItemModel::append_mapping,
175 &PropertyItemModel::count_mapping,
176 &PropertyItemModel::at_mapping,
177 &PropertyItemModel::clear_mapping
181void PropertyItemModel::rebuild()
188 if (_childNameFilter.isEmpty()) {
191 const int nChildren = _modelRoot->nChildren();
192 _nodes.resize(nChildren);
193 for (
int c=0; c < nChildren; ++c) {
194 _nodes[c] = _modelRoot->getChild(c);
197 _nodes = _modelRoot->getChildren(_childNameFilter.toStdString());
201void PropertyItemModel::innerSetRoot(SGPropertyNode_ptr
root)
204 _modelRoot->removeChangeListener(
this);;
210 _modelRoot->addChangeListener(
this);
218void PropertyItemModel::append_mapping(QQmlListProperty<PropertyItemModelRoleMapping> *list,
223 model->_roleMappings.append(mapping);
233 return model->_roleMappings.at(index);
238QML_LIST_INDEX_TYPE PropertyItemModel::count_mapping(QQmlListProperty<PropertyItemModelRoleMapping>* list)
242 return model->_roleMappings.size();
247void PropertyItemModel::clear_mapping(QQmlListProperty<PropertyItemModelRoleMapping> *list)
251 model->_roleMappings.clear();
258#include "PropertyItemModel.moc"
#define QML_LIST_INDEX_TYPE
void setNode(SGPropertyNode_ptr node)
void pathChanged(QString path)
void roleNameChanged(QString roleName)
void setPath(QString path)
friend class PropertyItemModel
void setRoleName(QString roleName)
void childRemoved(SGPropertyNode *parent, SGPropertyNode *child) override
QHash< int, QByteArray > roleNames() const override
void setRootPath(QString rootPath)
void setChildNameFilter(QString childNameFilter)
void childNameFilterChanged(QString childNameFilter)
QVariant data(const QModelIndex &index, int role) const override
void childAdded(SGPropertyNode *parent, SGPropertyNode *child) override
int rowCount(const QModelIndex &parent) const override
void setRoot(FGQmlPropertyNode *root)
void valueChanged(SGPropertyNode *node) override
QQmlListProperty< PropertyItemModelRoleMapping > mappings
SGPropertyNode * fgGetNode(const char *path, bool create)
Get a property node.