1#include "SubTreeProxyModel.h" 
    3#include <QAbstractItemModel> 
    4#include <QIdentityProxyModel> 
    7#include <QPersistentModelIndex> 
    8#include <QSortFilterProxyModel> 
    9#include <QStandardItem> 
   12#include "ProjectItem.h" 
   36  QModelIndex SubTreeProxyModel::mapFromSource(
const QModelIndex &sourceIndex)
 const {
 
   40      qDebug() << 
"creating index for invisible root item " 
   42      return createIndex(sourceIndex.row(), 0, sourceIndex.internalId());
 
   46    if (sourceIndex == m_root) {
 
   47      return createIndex(sourceIndex.row(), 0, sourceIndex.internalId());
 
   51    QModelIndex ancestorIndex = sourceIndex.parent();
 
   52    while (ancestorIndex.isValid() && ancestorIndex != m_root) {
 
   53      ancestorIndex = ancestorIndex.parent();
 
   55    if (ancestorIndex.isValid()) {
 
   56      return createIndex(sourceIndex.row(), 0, sourceIndex.internalId());
 
   66  QModelIndex SubTreeProxyModel::mapToSource(
const QModelIndex &proxyIndex)
 const {
 
   67    return QIdentityProxyModel::mapToSource(proxyIndex);
 
   71  void SubTreeProxyModel::setSourceModel(QAbstractItemModel *newSourceModel) {
 
   72    QPersistentModelIndex persistentIndex(newSourceModel->index(0,0,QModelIndex()));
 
   74    if (persistentIndex.isValid()) {
 
   75      m_root = persistentIndex;
 
   78      m_root = QPersistentModelIndex(QModelIndex());
 
   81    QIdentityProxyModel::setSourceModel(newSourceModel);
 
   86    QAbstractItemModel::removeRows(1,2,item->index());
 
   88    if (m_root.isValid()) {
 
SubTreeProxyModel(QObject *parent=0)
Constructs a SubTreeProxyModel.
This is free and unencumbered software released into the public domain.