From 0524e30987c32a52d17a2e00a8caff36b2dcd0f4 Mon Sep 17 00:00:00 2001
From: Craig Drummond
Date: Fri, 1 Dec 2017 19:12:37 +0000
Subject: [PATCH] Also add year filtering to playqueue Issue #1131
---
ChangeLog | 4 ++--
gui/librarypage.cpp | 2 +-
gui/mainwindow.cpp | 5 +++++
models/proxymodel.cpp | 36 +++++++++++++++++++++++++++++++++++-
models/proxymodel.h | 2 ++
5 files changed, 45 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 7d4350fa1..b594cab60 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -24,8 +24,8 @@
17. Add command-line options to set debugging and to disable network access.
18. Reduce memory usage by correctly calculating cost of covers for in-memory
cache.
-19. Make it possible to filter on year (or range of years) in library search
- field.
+19. Make it possible to filter on year (or range of years) in library and
+ playqueue search fields.
2.2.0
-----
diff --git a/gui/librarypage.cpp b/gui/librarypage.cpp
index 24e560d83..6c2365ca6 100644
--- a/gui/librarypage.cpp
+++ b/gui/librarypage.cpp
@@ -56,7 +56,7 @@ LibraryPage::LibraryPage(QWidget *p)
config.beginGroup(SqlLibraryModel::groupingStr(MpdLibraryModel::self()->topLevel()));
view->load(config);
- view->setSearchToolTip(tr("Enter a string to search artist, album, and track titles. To filter based on year, add #year-range to search string - e.g.
"
+ view->setSearchToolTip(tr("Enter a string to search artist, album, title, etc. To filter based on year, add #year-range to search string - e.g.
"
"- #2000 return tracks from 2000
"
"- #1980-1989 return tracks from the 80's
"
"- Blah #2000 to search for string Blah and only return tracks from 2000
"
diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp
index c64a37892..c9e95e3e3 100644
--- a/gui/mainwindow.cpp
+++ b/gui/mainwindow.cpp
@@ -491,6 +491,11 @@ void MainWindow::init()
} else {
playQueueSearchWidget->setVisible(false);
}
+ playQueueSearchWidget->setToolTip(tr("Enter a string to search artist, album, title, etc. To filter based on year, add #year-range to search string - e.g.
"
+ "- #2000 return tracks from 2000
"
+ "- #1980-1989 return tracks from the 80's
"
+ "- Blah #2000 to search for string Blah and only return tracks from 2000
"
+ "
"));
QList playbackBtns=QList() << prevTrackButton << stopTrackButton << playPauseTrackButton << nextTrackButton;
QList controlBtns=QList() << menuButton << songInfoButton;
int playbackIconSizeNonScaled=24==Icons::self()->toolbarPlayIcon.actualSize(QSize(24, 24)).width() ? 24 : 28;
diff --git a/models/proxymodel.cpp b/models/proxymodel.cpp
index 94ce1f32b..1ad98b7cb 100644
--- a/models/proxymodel.cpp
+++ b/models/proxymodel.cpp
@@ -31,6 +31,10 @@
bool ProxyModel::matchesFilter(const Song &s) const
{
+ if (yearFrom>0 && yearTo>0 && (s.yearyearTo)) {
+ return false;
+ }
+
QStringList strings;
strings << s.albumArtist();
@@ -90,6 +94,10 @@ bool ProxyModel::matchesFilter(const QStringList &strings) const
return false;
}
//#include
+
+static const quint16 constMinYear=1500;
+static const quint16 constMaxYear=2500; // 2500 (bit hopeful here :-) )
+
bool ProxyModel::update(const QString &txt)
{
QString text=txt.length()<2 ? QString() : txt;
@@ -100,7 +108,33 @@ bool ProxyModel::update(const QString &txt)
}
bool wasEmpty=isEmpty();
- filterStrings = text.split(' ', QString::SkipEmptyParts, Qt::CaseInsensitive);
+ filterStrings.clear();
+ yearFrom=yearTo=0;
+
+ QStringList parts = text.split(' ', QString::SkipEmptyParts, Qt::CaseInsensitive);
+
+ for (const auto &str: parts) {
+ if (str.startsWith('#')) {
+ QStringList parts=str.mid(1).split('-');
+ if (1==parts.length()) {
+ quint16 val=parts.at(0).simplified().toUInt();
+ if (val>=constMinYear && val<=constMaxYear) {
+ yearFrom = yearTo = val;
+ continue;
+ }
+ } else if (2==parts.length()) {
+ quint16 from=parts.at(0).simplified().toUInt();
+ quint16 to=parts.at(1).simplified().toUInt();
+ if (from>=constMinYear && from<=constMaxYear && to>=constMinYear && to<=constMaxYear) {
+ yearFrom=from;
+ yearTo=to;
+ continue;
+ }
+ }
+ }
+ filterStrings.append(str);
+ }
+
unmatchedStrings = 0;
const int n = qMin(filterStrings.count(), (int)(sizeof(uint)*8));
for ( int i = 0; i < n; ++i ) {
diff --git a/models/proxymodel.h b/models/proxymodel.h
index 4a325ce50..343f6fca0 100644
--- a/models/proxymodel.h
+++ b/models/proxymodel.h
@@ -69,6 +69,8 @@ protected:
QStringList filterStrings;
uint unmatchedStrings;
const void *filter;
+ quint16 yearFrom;
+ quint16 yearTo;
};
#endif