Use std::any_of

This commit is contained in:
Jonas Kvinge
2021-06-21 19:52:37 +02:00
parent 6a7959547e
commit c61d1ce6b4
12 changed files with 55 additions and 70 deletions

View File

@@ -590,17 +590,11 @@ void CollectionModel::SongsDeleted(const SongList &songs) {
if (!divider_nodes_.contains(divider_key)) continue;
// Look to see if there are any other items still under this divider
bool found = false;
QList<CollectionItem*> container_nodes = container_nodes_[0].values();
for (CollectionItem *node : container_nodes) {
if (DividerKey(group_by_[0], node) == divider_key) {
found = true;
break;
}
if (std::any_of(container_nodes.begin(), container_nodes.end(), [=](CollectionItem *node){ return DividerKey(group_by_[0], node) == divider_key; })) {
continue;
}
if (found) continue;
// Remove the divider
int row = divider_nodes_[divider_key]->row;
beginRemoveRows(ItemToIndex(root_), row, row);
@@ -782,23 +776,21 @@ QVariant CollectionModel::data(const CollectionItem *item, const int role) const
case Role_Artist:
return item->metadata.artist();
case Role_Editable:
case Role_Editable:{
if (!item->lazy_loaded) {
const_cast<CollectionModel*>(this)->LazyPopulate(const_cast<CollectionItem*>(item), true);
}
if (item->type == CollectionItem::Type_Container) {
// if we have even one non editable item as a child, we ourselves are not available for edit
if (!item->children.isEmpty()) {
for (CollectionItem *child : item->children) {
if (!data(child, role).toBool()) {
return false;
}
}
return true;
// If we have even one non editable item as a child, we ourselves are not available for edit
if (item->children.isEmpty()) {
return false;
}
else if (std::any_of(item->children.begin(), item->children.end(), [=](CollectionItem *child) { return !data(child, role).toBool(); })) {
return false;
}
else {
return false;
return true;
}
}
else if (item->type == CollectionItem::Type_Song) {
@@ -807,6 +799,7 @@ QVariant CollectionModel::data(const CollectionItem *item, const int role) const
else {
return false;
}
}
case Role_SortText:
return item->SortText();

View File

@@ -187,12 +187,10 @@ bool CollectionView::RestoreLevelFocus(const QModelIndex &parent) {
case CollectionItem::Type_Song:
if (!last_selected_song_.url().isEmpty()) {
QModelIndex index = qobject_cast<QSortFilterProxyModel*>(model())->mapToSource(current);
SongList songs = app_->collection_model()->GetChildSongs(index);
for (const Song &song : songs) {
if (song == last_selected_song_) {
setCurrentIndex(current);
return true;
}
const SongList songs = app_->collection_model()->GetChildSongs(index);
if (std::any_of(songs.begin(), songs.end(), [this](const Song &song) { return song == last_selected_song_; })) {
setCurrentIndex(current);
return true;
}
}
break;

View File

@@ -335,13 +335,11 @@ void CollectionWatcher::ScanTransaction::SetKnownSubdirs(const SubdirectoryList
bool CollectionWatcher::ScanTransaction::HasSeenSubdir(const QString &path) {
if (known_subdirs_dirty_)
if (known_subdirs_dirty_) {
SetKnownSubdirs(watcher_->backend_->SubdirsInDirectory(dir_));
for (const Subdirectory &subdir : known_subdirs_) {
if (subdir.path == path && subdir.mtime != 0) return true;
}
return false;
return std::any_of(known_subdirs_.begin(), known_subdirs_.end(), [path](const Subdirectory &subdir) { return subdir.path == path && subdir.mtime != 0; });
}