Hey Mobi, 2010/2/26 mobi phil <[email protected]>: > back to real problems :) > > I was trying to find info about nested WAbstractItemModel or > QAbstractItemModel and, but nothing to be found... > > I have a complex tree like data structure, where different subtrees > have particular implementations. Of course the entire logic could fit > into one subclass of WAbstractItemModel, but as implementation detail > might grow i have to split the item model into separate pieces. > > The question is if it would be enough to implement WMyModel::index > that would retrieve WModelIndex to children, sthg. like: > > WModelIndex WMyModel::index(int row, int col, parent) > { > //this is the root "column" so we do not look at parent > // datacontainer is a vector of boost tuples of label, key, childModel > if( !get<2>( datacontainer_[row] ) / > // me have to create the nested model > // the second element of the tuple contains the key of the model type > get<2>( datacontainer_[row] ) = myFactory->createModel( > get<1>(container_[row]) ) > } > return get<2>( container_[row] ).index(row, col); > }
No, this would not be enough (unfortunately). In your custom model, you need to return indexes for which model() == this. Moreover, you need to be able to implement all the methods like data() and setData() in terms of these model indexes, which means that somehow you need to be able to recognize which source model you should forward the request to. I think the following should work though: pass the original index.data() to createIndex() with the updated (virtual) row/column. Then, whenever you need to interpret an index, you should be able to deduce the source model from the index location (row/column and parent index hierarchy) and then return the right index in the source model. The last step you cannot do unless the source model cooperates (because createIndex() is protected). A workaround here would be to start from WAbstractProxyModel which has a createSourceIndex() method which you can use together with setSourceModel() to workaround this access protection. You need to reimplement all of the data access methods too to reinterpret the model index and talk to the correct source model. Regards, koen ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ witty-interest mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/witty-interest
