C++ (Qt)class COMMONS_USAGE AbstractSearchProxyModel : public QAbstractProxyModel{ Q_OBJECTpublic: explicit AbstractSearchProxyModel(QObject *parent = 0); QModelIndex mapToSource(const QModelIndex &proxyIndex) const; QModelIndex mapFromSource(const QModelIndex &sourceIndex) const; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; QModelIndex parent(const QModelIndex &child) const; };
C++ (Qt)AbstractSearchProxyModel::AbstractSearchProxyModel(QObject *parent) : QAbstractProxyModel(parent){} QModelIndex AbstractSearchProxyModel::mapToSource(const QModelIndex &proxyIndex) const{ return proxyIndex;} QModelIndex AbstractSearchProxyModel::mapFromSource(const QModelIndex &sourceIndex) const{ return sourceIndex;} QModelIndex AbstractSearchProxyModel::index(int row, int column, const QModelIndex &parent) const{ return mapFromSource(sourceModel()->index(row,column,parent));} int AbstractSearchProxyModel::rowCount(const QModelIndex &parent) const{ return sourceModel()->rowCount(mapToSource(parent));} int AbstractSearchProxyModel::columnCount(const QModelIndex &parent) const{ return sourceModel()->columnCount(mapToSource(parent));} QModelIndex AbstractSearchProxyModel::parent(const QModelIndex &child) const{ return mapFromSource(sourceModel()->parent(child));}
C++ (Qt)QModelIndex MyProxyModel::index(int row, int column, const QModelIndex &parent) const{ return mapFromSource(sourceModel()->index(row, column, parent));} QModelIndex MyProxyModel::parent(const QModelIndex &child) const{ return mapFromSource(sourceModel()->parent(child));}
C++ (Qt)QModelIndex MyProxyModel::mapFromSource(const QModelIndex &sourceIndex) const{ if(!sourceIndex.isValid()) { return QModelIndex(); } return createIndex(sourceIndex.row(), sourceIndex.column(), 0);}
C++ (Qt)return createIndex(sourceIndex.row(), sourceIndex.column(), sourceIndex.internalPointer());