Use std::any_of
This commit is contained in:
parent
6a7959547e
commit
c61d1ce6b4
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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; });
|
||||
|
||||
}
|
||||
|
||||
|
@ -219,12 +219,10 @@ bool ContextAlbumsView::RestoreLevelFocus(const QModelIndex &parent) {
|
||||
case CollectionItem::Type_Song:
|
||||
if (!last_selected_song_.url().isEmpty()) {
|
||||
QModelIndex index = qobject_cast<QSortFilterProxyModel*>(model())->mapToSource(current);
|
||||
SongList songs = model_->GetChildSongs(index);
|
||||
for (const Song &song : songs) {
|
||||
if (song == last_selected_song_) {
|
||||
setCurrentIndex(current);
|
||||
return true;
|
||||
}
|
||||
const SongList songs = 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;
|
||||
|
@ -21,6 +21,8 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <QObject>
|
||||
#include <QMutex>
|
||||
#include <QList>
|
||||
@ -117,12 +119,11 @@ void TaskManager::SetTaskFinished(const int id) {
|
||||
if (tasks_[id].blocks_collection_scans) {
|
||||
resume_collection_watchers = true;
|
||||
QList<Task> tasks = tasks_.values();
|
||||
for (const Task &task : tasks) {
|
||||
if (task.id != id && task.blocks_collection_scans) {
|
||||
resume_collection_watchers = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (std::any_of(tasks.begin(), tasks.end(), [id](const Task &task) { return task.id != id && task.blocks_collection_scans; })) {
|
||||
resume_collection_watchers = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
tasks_.remove(id);
|
||||
|
@ -519,10 +519,10 @@ bool EditTagDialog::DoesValueVary(const QModelIndexList &sel, const QString &id)
|
||||
|
||||
bool EditTagDialog::IsValueModified(const QModelIndexList &sel, const QString &id) const {
|
||||
|
||||
for (const QModelIndex &i : sel) {
|
||||
if (data_[i.row()].original_value(id) != data_[i.row()].current_value(id))
|
||||
return true;
|
||||
if (std::any_of(sel.begin(), sel.end(), [=](const QModelIndex &i){ return data_[i.row()].original_value(id) != data_[i.row()].current_value(id); })) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <glib-object.h>
|
||||
#include <gio/gio.h>
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
@ -427,10 +428,7 @@ bool GstEngine::ValidOutput(const QString &output) {
|
||||
EnsureInitialized();
|
||||
|
||||
PluginDetailsList plugins = GetPluginList("Sink/Audio");
|
||||
for (const PluginDetails &plugin : plugins) {
|
||||
if (plugin.name == output) return(true);
|
||||
}
|
||||
return(false);
|
||||
return std::any_of(plugins.begin(), plugins.end(), [output](const PluginDetails &plugin) { return plugin.name == output; });
|
||||
|
||||
}
|
||||
|
||||
|
@ -238,10 +238,7 @@ EngineBase::OutputDetailsList VLCEngine::GetOutputsList() const {
|
||||
bool VLCEngine::ValidOutput(const QString &output) {
|
||||
|
||||
PluginDetailsList plugins = GetPluginList();
|
||||
for (const PluginDetails &plugin : plugins) {
|
||||
if (plugin.name == output) return(true);
|
||||
}
|
||||
return(false);
|
||||
return std::any_of(plugins.begin(), plugins.end(), [output](const PluginDetails &plugin) { return plugin.name == output; });
|
||||
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,8 @@
|
||||
along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QtConcurrentRun>
|
||||
#include <QFuture>
|
||||
@ -167,11 +169,8 @@ void MoodbarItemDelegate::StartLoadingData(const QUrl &url, Data *data) {
|
||||
bool MoodbarItemDelegate::RemoveFromCacheIfIndexesInvalid(const QUrl &url, Data *data) {
|
||||
|
||||
QSet<QPersistentModelIndex> indexes = data->indexes_;
|
||||
for (const QPersistentModelIndex &idx : indexes) {
|
||||
if (idx.isValid()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (std::any_of(indexes.begin(), indexes.end(), [](const QPersistentModelIndex &idx) { return idx.isValid(); })) { return false; }
|
||||
|
||||
data_.remove(url);
|
||||
return true;
|
||||
|
@ -21,6 +21,8 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <QObject>
|
||||
#include <QtConcurrentMap>
|
||||
#include <QFuture>
|
||||
@ -56,12 +58,8 @@ void TagFetcher::StartFetch(const SongList &songs) {
|
||||
songs_ = songs;
|
||||
|
||||
bool have_fingerprints = true;
|
||||
|
||||
for (const Song &song : songs_) {
|
||||
if (song.fingerprint().isEmpty()) {
|
||||
have_fingerprints = false;
|
||||
break;
|
||||
}
|
||||
if (std::any_of(songs.begin(), songs.end(), [](const Song &song){ return song.fingerprint().isEmpty(); })) {
|
||||
have_fingerprints = false;
|
||||
}
|
||||
|
||||
if (have_fingerprints) {
|
||||
|
@ -20,6 +20,8 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QSet>
|
||||
@ -232,8 +234,8 @@ class OrFilter : public FilterTree {
|
||||
~OrFilter() override { qDeleteAll(children_); }
|
||||
virtual void add(FilterTree *child) { children_.append(child); }
|
||||
bool accept(int row, const QModelIndex &parent, const QAbstractItemModel *const model) const override {
|
||||
for (FilterTree *child : children_) {
|
||||
if (child->accept(row, parent, model)) return true;
|
||||
if (std::any_of(children_.begin(), children_.end(), [row, parent, model](FilterTree *child) { return child->accept(row, parent, model); })) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -247,8 +249,8 @@ class AndFilter : public FilterTree {
|
||||
~AndFilter() override { qDeleteAll(children_); }
|
||||
virtual void add(FilterTree *child) { children_.append(child); }
|
||||
bool accept(int row, const QModelIndex &parent, const QAbstractItemModel *const model) const override {
|
||||
for (FilterTree *child : children_) {
|
||||
if (!child->accept(row, parent, model)) return false;
|
||||
if (std::any_of(children_.begin(), children_.end(), [row, parent, model](FilterTree *child) { return !child->accept(row, parent, model); })) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
|
||||
#include <QWizardPage>
|
||||
#include <QList>
|
||||
@ -52,12 +53,14 @@ class SmartPlaylistQueryWizardPlugin::SearchPage : public QWizardPage { // claz
|
||||
}
|
||||
|
||||
bool isComplete() const override {
|
||||
if (ui_->type->currentIndex() == 2) // All songs
|
||||
if (ui_->type->currentIndex() == 2) { // All songs
|
||||
return true;
|
||||
|
||||
for (SmartPlaylistSearchTermWidget *widget : terms_) {
|
||||
if (!widget->Term().is_valid()) return false;
|
||||
}
|
||||
|
||||
if (std::any_of(terms_.begin(), terms_.end(), [](SmartPlaylistSearchTermWidget *widget){ return !widget->Term().is_valid(); })) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user