diff --git a/src/models/singleartistproxymodel.cpp b/src/models/singleartistproxymodel.cpp index bbf52c1e..474228cc 100644 --- a/src/models/singleartistproxymodel.cpp +++ b/src/models/singleartistproxymodel.cpp @@ -1,135 +1,123 @@ /* * Copyright 2016-2017 Matthieu Gallien * Copyright 2017 Alexander Stippich * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include "singleartistproxymodel.h" #include "genericdatamodel.h" #include "musicalbum.h" #include "databaseinterface.h" #include #include SingleArtistProxyModel::SingleArtistProxyModel(QObject *parent) : AbstractMediaProxyModel(parent) { this->setSortRole(DatabaseInterface::ColumnsRoles::TitleRole); this->setSortCaseSensitivity(Qt::CaseInsensitive); this->sortModel(Qt::AscendingOrder); } SingleArtistProxyModel::~SingleArtistProxyModel() = default; QString SingleArtistProxyModel::artistFilter() const { return mArtistFilter; } void SingleArtistProxyModel::setArtistFilterText(const QString &filterText) { if (mArtistFilter == filterText) return; mArtistFilter = filterText; mArtistExpression.setPattern(QStringLiteral(".*") + mArtistFilter + QStringLiteral(".*")); mArtistExpression.setPatternOptions(QRegularExpression::CaseInsensitiveOption); mArtistExpression.optimize(); invalidate(); Q_EMIT artistFilterTextChanged(mArtistFilter); } bool SingleArtistProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { bool result = false; - for (int column = 0, columnCount = sourceModel()->columnCount(source_parent); column < columnCount; ++column) { - auto currentIndex = sourceModel()->index(source_row, column, source_parent); + auto currentIndex = sourceModel()->index(source_row, 0, source_parent); - const auto &genreValue = sourceModel()->data(currentIndex, DatabaseInterface::ColumnsRoles::GenreRole); + const auto &genreValue = sourceModel()->data(currentIndex, DatabaseInterface::ColumnsRoles::GenreRole); - if (!genreFilterText().isNull() && !genreValue.isValid()) { - continue; - } - - if (!genreFilterText().isNull() && !genreValue.canConvert()) { - continue; - } - - if (!genreFilterText().isNull() && !genreValue.toStringList().contains(genreFilterText())) { - continue; - } - - const auto &artistValue = sourceModel()->data(currentIndex, DatabaseInterface::ColumnsRoles::TitleRole).toString(); - const auto &allArtistsValue = sourceModel()->data(currentIndex, DatabaseInterface::ColumnsRoles::AllArtistsRole).toStringList().join(QLatin1String(", ")); - const auto maximumRatingValue = sourceModel()->data(currentIndex, DatabaseInterface::ColumnsRoles::HighestTrackRating).toInt(); + if (!genreFilterText().isNull() && !genreValue.isValid()) { + return result; + } - if (maximumRatingValue < mFilterRating) { - result = false; - continue; - } + if (!genreFilterText().isNull() && !genreValue.canConvert()) { + return result; + } - if (mArtistExpression.match(artistValue).hasMatch()) { - if (mFilterExpression.match(allArtistsValue).hasMatch()) { - result = true; - continue; - } + if (!genreFilterText().isNull() && !genreValue.toStringList().contains(genreFilterText())) { + return result; + } - } + const auto &titleValue = sourceModel()->data(currentIndex, DatabaseInterface::ColumnsRoles::TitleRole).toString(); + const auto &allArtistsValue = sourceModel()->data(currentIndex, DatabaseInterface::ColumnsRoles::AllArtistsRole).toStringList().join(QLatin1String(", ")); + const auto maximumRatingValue = sourceModel()->data(currentIndex, DatabaseInterface::ColumnsRoles::HighestTrackRating).toInt(); - if (result) { - continue; - } + if (maximumRatingValue < mFilterRating) { + result = false; + return result; + } - if (!result) { - break; + if (mArtistExpression.match(allArtistsValue).hasMatch()) { + if (mFilterExpression.match(titleValue).hasMatch()) { + result = true; } } return result; } void SingleArtistProxyModel::genericEnqueueToPlayList(ElisaUtils::PlayListEnqueueMode enqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay) { QtConcurrent::run(&mThreadPool, [=] () { QReadLocker locker(&mDataLock); auto allAlbums = ElisaUtils::EntryDataList{}; allAlbums.reserve(rowCount()); for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) { auto currentIndex = index(rowIndex, 0); allAlbums.push_back({data(currentIndex, DatabaseInterface::ColumnsRoles::DatabaseIdRole).toULongLong(), data(currentIndex, DatabaseInterface::ColumnsRoles::TitleRole).toString()}); } Q_EMIT albumToEnqueue(allAlbums, ElisaUtils::Album, enqueueMode, triggerPlay); }); } void SingleArtistProxyModel::enqueueToPlayList() { genericEnqueueToPlayList(ElisaUtils::AppendPlayList, ElisaUtils::DoNotTriggerPlay); } void SingleArtistProxyModel::replaceAndPlayOfPlayList() { genericEnqueueToPlayList(ElisaUtils::ReplacePlayList, ElisaUtils::TriggerPlay); } #include "moc_singleartistproxymodel.cpp"