bool PlaylistsProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { if (!filterEnabled) { return true; } if (!isChildOfRoot(sourceParent)) { return true; } const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); PlaylistsModel::Item *item = static_cast<PlaylistsModel::Item *>(index.internalPointer()); if (item->isPlaylist()) { PlaylistsModel::PlaylistItem *pl = static_cast<PlaylistsModel::PlaylistItem *>(item); if (matchesFilter(QStringList() << pl->name)) { return true; } for (PlaylistsModel::SongItem *s: pl->songs) { if (matchesFilter(*s)) { return true; } } } else { PlaylistsModel::SongItem *s = static_cast<PlaylistsModel::SongItem *>(item); return matchesFilter(*s); } return false; }
bool MusicLibraryProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { if (!filterEnabled) { return true; } if (!isChildOfRoot(sourceParent)) { return true; } const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); const MusicLibraryItem *item = static_cast<const MusicLibraryItem *>(index.internalPointer()); if (!filterGenre.isEmpty() && !item->hasGenre(filterGenre)) { return false; } if (filter) { if (!sourceParent.isValid()) { // All top level items are valid return true; } const MusicLibraryItem *p=item->parentItem(); while (p->parentItem()) { p=p->parentItem(); } if (p!=filter) { // If item is not part of 'filter' tree - then we accept it return true; } } if (filterStrings.isEmpty()) { return true; } switch (item->itemType()) { case MusicLibraryItem::Type_Root: return filterAcceptsRoot(item); case MusicLibraryItem::Type_Artist: return filterAcceptsArtist(item); case MusicLibraryItem::Type_Album: return filterAcceptsAlbum(item); case MusicLibraryItem::Type_Song: return filterAcceptsSong(item); default: break; } return false; }
bool MusicLibraryProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { if (!filterEnabled) { return true; } if (!isChildOfRoot(sourceParent)) { return true; } const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); const MusicLibraryItem *item = static_cast<const MusicLibraryItem *>(index.internalPointer()); if (!filterGenre.isEmpty() && !item->hasGenre(filterGenre)) { return false; } if (filter) { if (item==filter) { // Accept top-level item! return true; } const MusicLibraryItem *p=item->parentItem(); while (p && p->parentItem()) { p=p->parentItem(); } if (p!=filter) { // Accept all items that are not children of top-level item! return true; } } if (filterStrings.isEmpty()) { return true; } switch (item->itemType()) { case MusicLibraryItem::Type_Root: return filterAcceptsRoot(item); case MusicLibraryItem::Type_Artist: return filterAcceptsArtist(item); case MusicLibraryItem::Type_Podcast: case MusicLibraryItem::Type_Album: return filterAcceptsAlbum(item); case MusicLibraryItem::Type_Song: return filterAcceptsSong(item); default: break; } return false; }
bool DynamicProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { if (!filterEnabled) { return true; } if (!isChildOfRoot(sourceParent)) { return true; } if (matchesFilter(QStringList() << sourceModel()->data(sourceModel()->index(sourceRow, 0, sourceParent), Qt::DisplayRole).toString())) { return true; } Dynamic::Entry item = Dynamic::self()->entry(sourceRow); foreach (const Dynamic::Rule & r, item.rules) { Dynamic::Rule::ConstIterator it=r.constBegin(); Dynamic::Rule::ConstIterator end=r.constEnd(); for (; it!=end; ++it) { if (matchesFilter(QStringList() << it.value())) { return true; } } } return false; }
bool DirViewProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { if (!filterEnabled) { return true; } if (!isChildOfRoot(sourceParent)) { return true; } const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); DirViewItem *item = static_cast<DirViewItem *>(index.internalPointer()); QModelIndex idx=index.parent(); QStringList strings; // Traverse back up tree, so we get parent strings... while (idx.isValid()) { DirViewItem *i = static_cast<DirViewItem *>(idx.internalPointer()); if (DirViewItem::Type_Dir!=i->type()) { break; } strings << i->data(); idx=idx.parent(); } if (DirViewItem::Type_Dir==item->type()) { // Check *all* children... if (filterAcceptsDirViewItem(item, strings)) { return true; } } else { strings << item->data(); return matchesFilter(strings); } return false; }