patrikd
7th February 2008, 10:19
Hello,
I'm trying to create a proxy for the simpletreemodel from the examples. But I have a problem translating the parent relation. The first level beneath the root works fine but my proxy doesn't get the right parents for the subitems.
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));
}
How can I get the right parent relations for the proxy?
Thanks,
Patrik
I'm trying to create a proxy for the simpletreemodel from the examples. But I have a problem translating the parent relation. The first level beneath the root works fine but my proxy doesn't get the right parents for the subitems.
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));
}
How can I get the right parent relations for the proxy?
Thanks,
Patrik