//--------------------------------------------------------------------------------- bool ResourceSortFilterProxyModel::filterAcceptsRow(int p_row, const QModelIndex& p_parent) const { QModelIndex currentIndex = sourceModel()->index(p_row, 0, p_parent); ResourceDefinition* currentItem = static_cast<ResourceDefinition*>(currentIndex.internalPointer()); // Check the item bool accept = filterAcceptsItem(currentItem); // We may hide a category if it is empty if (accept && currentItem->isCategory && !_showEmptyCategories) { // Iterate over the children to find out if any will be accepted // And if so, accept the category int numChildren = currentItem->children.size(); accept = false; for (int i = 0; i < numChildren; ++i) { ResourceDefinition* item = currentItem->children[i]; if (filterAcceptsItem(item)) { accept = true; break; } } } // Return result return accept; }
bool QgsBrowserProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const { if ( ( mFilter.isEmpty() && !mFilterByLayerType ) || !mModel ) return true; QModelIndex sourceIndex = mModel->index( sourceRow, 0, sourceParent ); return filterAcceptsItem( sourceIndex ) || filterAcceptsAncestor( sourceIndex ) || filterAcceptsDescendant( sourceIndex ); }
bool QgsBrowserProxyModel::filterAcceptsDescendant( const QModelIndex &sourceIndex ) const { if ( !mModel ) return true; for ( int i = 0; i < mModel->rowCount( sourceIndex ); i++ ) { QModelIndex sourceChildIndex = mModel->index( i, 0, sourceIndex ); if ( filterAcceptsItem( sourceChildIndex ) ) return true; if ( filterAcceptsDescendant( sourceChildIndex ) ) return true; } return false; }
bool QgsBrowserProxyModel::filterAcceptsAncestor( const QModelIndex &sourceIndex ) const { if ( !mModel ) return true; if ( mFilterByLayerType ) return false; QModelIndex sourceParentIndex = mModel->parent( sourceIndex ); if ( !sourceParentIndex.isValid() ) return false; if ( filterAcceptsItem( sourceParentIndex ) ) return true; return filterAcceptsAncestor( sourceParentIndex ); }