Use std::any_of
This commit is contained in:
@@ -590,17 +590,11 @@ void CollectionModel::SongsDeleted(const SongList &songs) {
|
|||||||
if (!divider_nodes_.contains(divider_key)) continue;
|
if (!divider_nodes_.contains(divider_key)) continue;
|
||||||
|
|
||||||
// Look to see if there are any other items still under this divider
|
// Look to see if there are any other items still under this divider
|
||||||
bool found = false;
|
|
||||||
QList<CollectionItem*> container_nodes = container_nodes_[0].values();
|
QList<CollectionItem*> container_nodes = container_nodes_[0].values();
|
||||||
for (CollectionItem *node : container_nodes) {
|
if (std::any_of(container_nodes.begin(), container_nodes.end(), [=](CollectionItem *node){ return DividerKey(group_by_[0], node) == divider_key; })) {
|
||||||
if (DividerKey(group_by_[0], node) == divider_key) {
|
continue;
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found) continue;
|
|
||||||
|
|
||||||
// Remove the divider
|
// Remove the divider
|
||||||
int row = divider_nodes_[divider_key]->row;
|
int row = divider_nodes_[divider_key]->row;
|
||||||
beginRemoveRows(ItemToIndex(root_), row, row);
|
beginRemoveRows(ItemToIndex(root_), row, row);
|
||||||
@@ -782,23 +776,21 @@ QVariant CollectionModel::data(const CollectionItem *item, const int role) const
|
|||||||
case Role_Artist:
|
case Role_Artist:
|
||||||
return item->metadata.artist();
|
return item->metadata.artist();
|
||||||
|
|
||||||
case Role_Editable:
|
case Role_Editable:{
|
||||||
if (!item->lazy_loaded) {
|
if (!item->lazy_loaded) {
|
||||||
const_cast<CollectionModel*>(this)->LazyPopulate(const_cast<CollectionItem*>(item), true);
|
const_cast<CollectionModel*>(this)->LazyPopulate(const_cast<CollectionItem*>(item), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item->type == CollectionItem::Type_Container) {
|
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 we have even one non editable item as a child, we ourselves are not available for edit
|
||||||
if (!item->children.isEmpty()) {
|
if (item->children.isEmpty()) {
|
||||||
for (CollectionItem *child : item->children) {
|
return false;
|
||||||
if (!data(child, role).toBool()) {
|
}
|
||||||
return false;
|
else if (std::any_of(item->children.begin(), item->children.end(), [=](CollectionItem *child) { return !data(child, role).toBool(); })) {
|
||||||
}
|
return false;
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (item->type == CollectionItem::Type_Song) {
|
else if (item->type == CollectionItem::Type_Song) {
|
||||||
@@ -807,6 +799,7 @@ QVariant CollectionModel::data(const CollectionItem *item, const int role) const
|
|||||||
else {
|
else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case Role_SortText:
|
case Role_SortText:
|
||||||
return item->SortText();
|
return item->SortText();
|
||||||
|
|||||||
@@ -187,12 +187,10 @@ bool CollectionView::RestoreLevelFocus(const QModelIndex &parent) {
|
|||||||
case CollectionItem::Type_Song:
|
case CollectionItem::Type_Song:
|
||||||
if (!last_selected_song_.url().isEmpty()) {
|
if (!last_selected_song_.url().isEmpty()) {
|
||||||
QModelIndex index = qobject_cast<QSortFilterProxyModel*>(model())->mapToSource(current);
|
QModelIndex index = qobject_cast<QSortFilterProxyModel*>(model())->mapToSource(current);
|
||||||
SongList songs = app_->collection_model()->GetChildSongs(index);
|
const SongList songs = app_->collection_model()->GetChildSongs(index);
|
||||||
for (const Song &song : songs) {
|
if (std::any_of(songs.begin(), songs.end(), [this](const Song &song) { return song == last_selected_song_; })) {
|
||||||
if (song == last_selected_song_) {
|
setCurrentIndex(current);
|
||||||
setCurrentIndex(current);
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -335,13 +335,11 @@ void CollectionWatcher::ScanTransaction::SetKnownSubdirs(const SubdirectoryList
|
|||||||
|
|
||||||
bool CollectionWatcher::ScanTransaction::HasSeenSubdir(const QString &path) {
|
bool CollectionWatcher::ScanTransaction::HasSeenSubdir(const QString &path) {
|
||||||
|
|
||||||
if (known_subdirs_dirty_)
|
if (known_subdirs_dirty_) {
|
||||||
SetKnownSubdirs(watcher_->backend_->SubdirsInDirectory(dir_));
|
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:
|
case CollectionItem::Type_Song:
|
||||||
if (!last_selected_song_.url().isEmpty()) {
|
if (!last_selected_song_.url().isEmpty()) {
|
||||||
QModelIndex index = qobject_cast<QSortFilterProxyModel*>(model())->mapToSource(current);
|
QModelIndex index = qobject_cast<QSortFilterProxyModel*>(model())->mapToSource(current);
|
||||||
SongList songs = model_->GetChildSongs(index);
|
const SongList songs = model_->GetChildSongs(index);
|
||||||
for (const Song &song : songs) {
|
if (std::any_of(songs.begin(), songs.end(), [this](const Song &song) { return song == last_selected_song_; })) {
|
||||||
if (song == last_selected_song_) {
|
setCurrentIndex(current);
|
||||||
setCurrentIndex(current);
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
@@ -117,12 +119,11 @@ void TaskManager::SetTaskFinished(const int id) {
|
|||||||
if (tasks_[id].blocks_collection_scans) {
|
if (tasks_[id].blocks_collection_scans) {
|
||||||
resume_collection_watchers = true;
|
resume_collection_watchers = true;
|
||||||
QList<Task> tasks = tasks_.values();
|
QList<Task> tasks = tasks_.values();
|
||||||
for (const Task &task : tasks) {
|
|
||||||
if (task.id != id && task.blocks_collection_scans) {
|
if (std::any_of(tasks.begin(), tasks.end(), [id](const Task &task) { return task.id != id && task.blocks_collection_scans; })) {
|
||||||
resume_collection_watchers = false;
|
resume_collection_watchers = false;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks_.remove(id);
|
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 {
|
bool EditTagDialog::IsValueModified(const QModelIndexList &sel, const QString &id) const {
|
||||||
|
|
||||||
for (const QModelIndex &i : sel) {
|
if (std::any_of(sel.begin(), sel.end(), [=](const QModelIndex &i){ return data_[i.row()].original_value(id) != data_[i.row()].current_value(id); })) {
|
||||||
if (data_[i.row()].original_value(id) != data_[i.row()].current_value(id))
|
return true;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include <glib-object.h>
|
#include <glib-object.h>
|
||||||
#include <gio/gio.h>
|
#include <gio/gio.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <algorithm>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -427,10 +428,7 @@ bool GstEngine::ValidOutput(const QString &output) {
|
|||||||
EnsureInitialized();
|
EnsureInitialized();
|
||||||
|
|
||||||
PluginDetailsList plugins = GetPluginList("Sink/Audio");
|
PluginDetailsList plugins = GetPluginList("Sink/Audio");
|
||||||
for (const PluginDetails &plugin : plugins) {
|
return std::any_of(plugins.begin(), plugins.end(), [output](const PluginDetails &plugin) { return plugin.name == output; });
|
||||||
if (plugin.name == output) return(true);
|
|
||||||
}
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -238,10 +238,7 @@ EngineBase::OutputDetailsList VLCEngine::GetOutputsList() const {
|
|||||||
bool VLCEngine::ValidOutput(const QString &output) {
|
bool VLCEngine::ValidOutput(const QString &output) {
|
||||||
|
|
||||||
PluginDetailsList plugins = GetPluginList();
|
PluginDetailsList plugins = GetPluginList();
|
||||||
for (const PluginDetails &plugin : plugins) {
|
return std::any_of(plugins.begin(), plugins.end(), [output](const PluginDetails &plugin) { return plugin.name == output; });
|
||||||
if (plugin.name == output) return(true);
|
|
||||||
}
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,8 @@
|
|||||||
along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QtConcurrentRun>
|
#include <QtConcurrentRun>
|
||||||
#include <QFuture>
|
#include <QFuture>
|
||||||
@@ -167,11 +169,8 @@ void MoodbarItemDelegate::StartLoadingData(const QUrl &url, Data *data) {
|
|||||||
bool MoodbarItemDelegate::RemoveFromCacheIfIndexesInvalid(const QUrl &url, Data *data) {
|
bool MoodbarItemDelegate::RemoveFromCacheIfIndexesInvalid(const QUrl &url, Data *data) {
|
||||||
|
|
||||||
QSet<QPersistentModelIndex> indexes = data->indexes_;
|
QSet<QPersistentModelIndex> indexes = data->indexes_;
|
||||||
for (const QPersistentModelIndex &idx : indexes) {
|
|
||||||
if (idx.isValid()) {
|
if (std::any_of(indexes.begin(), indexes.end(), [](const QPersistentModelIndex &idx) { return idx.isValid(); })) { return false; }
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data_.remove(url);
|
data_.remove(url);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QtConcurrentMap>
|
#include <QtConcurrentMap>
|
||||||
#include <QFuture>
|
#include <QFuture>
|
||||||
@@ -56,12 +58,8 @@ void TagFetcher::StartFetch(const SongList &songs) {
|
|||||||
songs_ = songs;
|
songs_ = songs;
|
||||||
|
|
||||||
bool have_fingerprints = true;
|
bool have_fingerprints = true;
|
||||||
|
if (std::any_of(songs.begin(), songs.end(), [](const Song &song){ return song.fingerprint().isEmpty(); })) {
|
||||||
for (const Song &song : songs_) {
|
have_fingerprints = false;
|
||||||
if (song.fingerprint().isEmpty()) {
|
|
||||||
have_fingerprints = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (have_fingerprints) {
|
if (have_fingerprints) {
|
||||||
|
|||||||
@@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
@@ -232,8 +234,8 @@ class OrFilter : public FilterTree {
|
|||||||
~OrFilter() override { qDeleteAll(children_); }
|
~OrFilter() override { qDeleteAll(children_); }
|
||||||
virtual void add(FilterTree *child) { children_.append(child); }
|
virtual void add(FilterTree *child) { children_.append(child); }
|
||||||
bool accept(int row, const QModelIndex &parent, const QAbstractItemModel *const model) const override {
|
bool accept(int row, const QModelIndex &parent, const QAbstractItemModel *const model) const override {
|
||||||
for (FilterTree *child : children_) {
|
if (std::any_of(children_.begin(), children_.end(), [row, parent, model](FilterTree *child) { return child->accept(row, parent, model); })) {
|
||||||
if (child->accept(row, parent, model)) return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -247,8 +249,8 @@ class AndFilter : public FilterTree {
|
|||||||
~AndFilter() override { qDeleteAll(children_); }
|
~AndFilter() override { qDeleteAll(children_); }
|
||||||
virtual void add(FilterTree *child) { children_.append(child); }
|
virtual void add(FilterTree *child) { children_.append(child); }
|
||||||
bool accept(int row, const QModelIndex &parent, const QAbstractItemModel *const model) const override {
|
bool accept(int row, const QModelIndex &parent, const QAbstractItemModel *const model) const override {
|
||||||
for (FilterTree *child : children_) {
|
if (std::any_of(children_.begin(), children_.end(), [row, parent, model](FilterTree *child) { return !child->accept(row, parent, model); })) {
|
||||||
if (!child->accept(row, parent, model)) return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <QWizardPage>
|
#include <QWizardPage>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
@@ -52,12 +53,14 @@ class SmartPlaylistQueryWizardPlugin::SearchPage : public QWizardPage { // claz
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool isComplete() const override {
|
bool isComplete() const override {
|
||||||
if (ui_->type->currentIndex() == 2) // All songs
|
if (ui_->type->currentIndex() == 2) { // All songs
|
||||||
return true;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user