[Qt-interest] Qt MVC Questions
Willy P
willy.lists at gmail.com
Mon Sep 21 00:59:20 CEST 2009
Sean,
Thanks for writing back. Late last night I came across the ProxyModel
classes. I inherited from QSortFilterProxyModel and am attempting to
create mapTo / mapFrom source functions that, for starters, simply
pass the the values back and forth with no modification. It is not
working at all:
QModelIndex ReducedTreeModel::mapFromSource( const QModelIndex & source ) const
{
qDebug() << "from Source" << source.row() << source.column() <<
source.internalId();
return createIndex( source.row(), source.column(), ( quint32
)source.internalId() );
}
QModelIndex ReducedTreeModel::mapToSource( const QModelIndex& proxy ) const
{
qDebug() << "to Source" << proxy.row() << proxy.column() <<
proxy.internalId();
return (sourceModel()&&proxy.isValid())
? sourceModel()->index(proxy.row(), proxy.column(), proxy.parent())
: QModelIndex();
}
Can you tell me what I'm doing wrong here? It's crashing when an
absolutely junk value comes into mapToSource for proxy.internalId().
Thanks again...
-Willy
On Sun, Sep 20, 2009 at 4:21 AM, Sean Harmer
<sean.harmer at maps-technology.com> wrote:
> Willy P wrote:
>> I have built a Model, a view and a delegate that represents a tree
>> like data structure.
>>
>> Two related questions:
>>
>> 1) Is there a way to hide TreeNodes in a view but show their
>> children? Basically I have data structures that are programatically
>> useful but the user doesn't need to know about them. So I'd like the
>> view to show the invisible node's children as if they were children of
>> the invisible node's parent. I've tried setRowHidden() but it hides
>> all the children as well.
>>
> Try a custom class derived from QProxySortFilterModel.
>
>> 2) The opposite question. Is there a way to have nodes appear in the
>> view but not the model? I basically want to add categorical
>> separators. In some situations I want them and in others I don't, but
>> in no case do I need them in the raw model.
>>
> Once again a custom proxy that sits between your source model and your
> custom view(s) will be the way to go. I think that there is already some
> classes in KDE that do this. Yes, check out KCategorizedView and
> KCategorizedSortFilterProxyModel:
>
> http://api.kde.org/4.x-api/kdelibs-apidocs/kdeui/html/classKCategorizedView.html
> http://api.kde.org/4.x-api/kdelibs-apidocs/kdeui/html/classKCategorizedSortFilterProxyModel.html
>
> They should do what you need for (2) without any work needed on your part.
>
> Sean
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
More information about the Qt-interest-old
mailing list