Changeset View
Changeset View
Standalone View
Standalone View
src/models/singlealbumproxymodel.cpp
Show All 11 Lines | |||||
12 | * Lesser General Public License for more details. | 12 | * Lesser General Public License for more details. | ||
13 | * | 13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public License | 14 | * You should have received a copy of the GNU Lesser General Public License | ||
15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | 15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
16 | */ | 16 | */ | ||
17 | 17 | | |||
18 | #include "singlealbumproxymodel.h" | 18 | #include "singlealbumproxymodel.h" | ||
19 | 19 | | |||
20 | #include "databaseinterface.h" | 20 | #include "datatypes.h" | ||
21 | 21 | | |||
22 | #include <QReadLocker> | 22 | #include <QReadLocker> | ||
23 | #include <QtConcurrentRun> | 23 | #include <QtConcurrentRun> | ||
24 | 24 | | |||
25 | SingleAlbumProxyModel::SingleAlbumProxyModel(QObject *parent) : AbstractMediaProxyModel(parent) | 25 | SingleAlbumProxyModel::SingleAlbumProxyModel(QObject *parent) : AbstractMediaProxyModel(parent) | ||
26 | { | 26 | { | ||
27 | } | 27 | } | ||
28 | 28 | | |||
29 | SingleAlbumProxyModel::~SingleAlbumProxyModel() = default; | 29 | SingleAlbumProxyModel::~SingleAlbumProxyModel() = default; | ||
30 | 30 | | |||
31 | bool SingleAlbumProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const | 31 | bool SingleAlbumProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const | ||
32 | { | 32 | { | ||
33 | bool result = false; | 33 | bool result = false; | ||
34 | 34 | | |||
35 | auto currentIndex = sourceModel()->index(source_row, 0, source_parent); | 35 | auto currentIndex = sourceModel()->index(source_row, 0, source_parent); | ||
36 | 36 | | |||
37 | const auto &titleValue = sourceModel()->data(currentIndex, DatabaseInterface::ColumnsRoles::TitleRole).toString(); | 37 | const auto &titleValue = sourceModel()->data(currentIndex, DataTypes::ColumnsRoles::TitleRole).toString(); | ||
38 | const auto maximumRatingValue = sourceModel()->data(currentIndex, DatabaseInterface::ColumnsRoles::RatingRole).toInt(); | 38 | const auto maximumRatingValue = sourceModel()->data(currentIndex, DataTypes::ColumnsRoles::RatingRole).toInt(); | ||
39 | 39 | | |||
40 | if (maximumRatingValue < mFilterRating) { | 40 | if (maximumRatingValue < mFilterRating) { | ||
41 | return result; | 41 | return result; | ||
42 | } | 42 | } | ||
43 | 43 | | |||
44 | if (mFilterExpression.match(titleValue).hasMatch()) { | 44 | if (mFilterExpression.match(titleValue).hasMatch()) { | ||
45 | result = true; | 45 | result = true; | ||
46 | } | 46 | } | ||
47 | 47 | | |||
48 | return result; | 48 | return result; | ||
49 | } | 49 | } | ||
50 | 50 | | |||
51 | void SingleAlbumProxyModel::genericEnqueueToPlayList(ElisaUtils::PlayListEnqueueMode enqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay) | 51 | void SingleAlbumProxyModel::genericEnqueueToPlayList(ElisaUtils::PlayListEnqueueMode enqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay) | ||
52 | { | 52 | { | ||
53 | QtConcurrent::run(&mThreadPool, [=] () { | 53 | QtConcurrent::run(&mThreadPool, [=] () { | ||
54 | QReadLocker locker(&mDataLock); | 54 | QReadLocker locker(&mDataLock); | ||
55 | auto allTracks = ElisaUtils::EntryDataList{}; | 55 | auto allTracks = ElisaUtils::EntryDataList{}; | ||
56 | allTracks.reserve(rowCount()); | 56 | allTracks.reserve(rowCount()); | ||
57 | for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) { | 57 | for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) { | ||
58 | auto currentIndex = index(rowIndex, 0); | 58 | auto currentIndex = index(rowIndex, 0); | ||
59 | allTracks.push_back(ElisaUtils::EntryData{data(currentIndex, DatabaseInterface::ColumnsRoles::DatabaseIdRole).toULongLong(), | 59 | allTracks.push_back(ElisaUtils::EntryData{data(currentIndex, DataTypes::ColumnsRoles::DatabaseIdRole).toULongLong(), | ||
60 | data(currentIndex, DatabaseInterface::ColumnsRoles::TitleRole).toString()}); | 60 | data(currentIndex, DataTypes::ColumnsRoles::TitleRole).toString()}); | ||
61 | } | 61 | } | ||
62 | Q_EMIT entriesToEnqueue(allTracks, ElisaUtils::Track, enqueueMode, triggerPlay); | 62 | Q_EMIT entriesToEnqueue(allTracks, ElisaUtils::Track, enqueueMode, triggerPlay); | ||
63 | }); | 63 | }); | ||
64 | } | 64 | } | ||
65 | 65 | | |||
66 | void SingleAlbumProxyModel::enqueueToPlayList() | 66 | void SingleAlbumProxyModel::enqueueToPlayList() | ||
67 | { | 67 | { | ||
68 | genericEnqueueToPlayList(ElisaUtils::AppendPlayList, ElisaUtils::DoNotTriggerPlay); | 68 | genericEnqueueToPlayList(ElisaUtils::AppendPlayList, ElisaUtils::DoNotTriggerPlay); | ||
69 | } | 69 | } | ||
70 | 70 | | |||
71 | void SingleAlbumProxyModel::replaceAndPlayOfPlayList() | 71 | void SingleAlbumProxyModel::replaceAndPlayOfPlayList() | ||
72 | { | 72 | { | ||
73 | genericEnqueueToPlayList(ElisaUtils::ReplacePlayList, ElisaUtils::TriggerPlay); | 73 | genericEnqueueToPlayList(ElisaUtils::ReplacePlayList, ElisaUtils::TriggerPlay); | ||
74 | } | 74 | } | ||
75 | 75 | | |||
76 | #include "moc_singlealbumproxymodel.cpp" | 76 | #include "moc_singlealbumproxymodel.cpp" |