ich möchte für das SimpleTreeModel aus den Beispielen ein ProxyModel basteln. Aber irgendwie bekomm ich die Parent-Beziehung der ModelIndexe im Proxy nicht hin. Die erste Hierarchieebene unterhalb des Root wird richtig umgesetzt aber dann klappt das Indizieren über den Parent nicht. Das Model bekommt ja seine Parentbeziehung über das gespeicherte Item, aber wenn ich das richtig verstanden habe greift man mit dem Proxy nicht auf die Items zu sondern macht alles über den Index.
Code: Alles auswählen
QModelIndex CUserProxyNoMeta::index(int r, int c, const QModelIndex& parent) const
{
if (!hasIndex(r, c))
return QModelIndex();
return createIndex(r, c);
}
QModelIndex CUserProxyNoMeta::mapFromSource(const QModelIndex& sourceIndex) const
{
if (!sourceIndex.isValid()){
return QModelIndex();
}
return index(sourceIndex.row(), sourceIndex.column());
}
QModelIndex CUserProxyNoMeta::mapToSource(const QModelIndex& proxyIndex) const
{
if (!proxyIndex.isValid()){
return QModelIndex();
}
return sourceModel()->index(proxyIndex.row(), proxyIndex.column());
}
QVariant CUserProxyNoMeta::data(const QModelIndex& ind, int role) const
{
return sourceModel()->data(mapToSource(ind), role);
}
QModelIndex CUserProxyNoMeta::parent(const QModelIndex& index) const
{
if (!index.isValid()){
return QModelIndex();
}
return mapFromSource(sourceModel()->parent(mapToSource(index)));
}
int CUserProxyNoMeta::rowCount(const QModelIndex& ind) const{
return sourceModel()->rowCount(mapToSource(ind));
}
int CUserProxyNoMeta::columnCount(const QModelIndex& ind) const
{
return sourceModel()->columnCount(mapToSource(ind));
}
lg