mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-16 19:31:02 +01:00
Delay queries on large playlists.
Fixes issue 3148
This commit is contained in:
parent
3e9cfb5a0b
commit
96654efd3f
@ -32,9 +32,12 @@
|
||||
#include <QSettings>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QTimeLine>
|
||||
#include <QTimer>
|
||||
#include <QUndoStack>
|
||||
|
||||
const char* PlaylistContainer::kSettingsGroup = "Playlist";
|
||||
const int PlaylistContainer::kFilterDelayMs = 100;
|
||||
const int PlaylistContainer::kFilterDelayPlaylistSizeThreshold = 5000;
|
||||
|
||||
PlaylistContainer::PlaylistContainer(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
@ -47,7 +50,8 @@ PlaylistContainer::PlaylistContainer(QWidget *parent)
|
||||
tab_bar_visible_(false),
|
||||
tab_bar_animation_(new QTimeLine(500, this)),
|
||||
no_matches_label_(NULL),
|
||||
did_you_mean_(NULL)
|
||||
did_you_mean_(NULL),
|
||||
filter_timer_(new QTimer(this))
|
||||
{
|
||||
ui_->setupUi(this);
|
||||
|
||||
@ -83,8 +87,13 @@ PlaylistContainer::PlaylistContainer(QWidget *parent)
|
||||
connect(ui_->tab_bar, SIGNAL(currentChanged(int)), SLOT(Save()));
|
||||
connect(ui_->tab_bar, SIGNAL(Save(int)), SLOT(SavePlaylist(int)));
|
||||
|
||||
// set up timer for delayed filter updates
|
||||
filter_timer_->setSingleShot(true);
|
||||
filter_timer_->setInterval(kFilterDelayMs);
|
||||
connect(filter_timer_,SIGNAL(timeout()),this,SLOT(UpdateFilter()));
|
||||
|
||||
// Replace playlist search filter with native search box.
|
||||
connect(ui_->filter, SIGNAL(textChanged(QString)), SLOT(UpdateFilter()));
|
||||
connect(ui_->filter, SIGNAL(textChanged(QString)), SLOT(MaybeUpdateFilter()));
|
||||
connect(ui_->playlist, SIGNAL(FocusOnFilterSignal(QKeyEvent*)), SLOT(FocusOnFilter(QKeyEvent*)));
|
||||
ui_->filter->installEventFilter(this);
|
||||
|
||||
@ -374,6 +383,17 @@ void PlaylistContainer::SetTabBarHeight(int height) {
|
||||
ui_->tab_bar->setMaximumHeight(height);
|
||||
}
|
||||
|
||||
void PlaylistContainer::MaybeUpdateFilter() {
|
||||
// delaying the filter update on small playlists is undesirable
|
||||
// and an empty filter applies very quickly, too
|
||||
if (manager_->current()->rowCount() < kFilterDelayPlaylistSizeThreshold ||
|
||||
ui_->filter->text().isEmpty()) {
|
||||
UpdateFilter();
|
||||
} else {
|
||||
filter_timer_->start();
|
||||
}
|
||||
}
|
||||
|
||||
void PlaylistContainer::UpdateFilter() {
|
||||
Playlist* playlist = manager_->current();
|
||||
SpecialPlaylistType* type = manager_->GetPlaylistType(playlist->special_type());
|
||||
|
@ -30,6 +30,7 @@ class PlaylistManager;
|
||||
class PlaylistView;
|
||||
|
||||
class QTimeLine;
|
||||
class QTimer;
|
||||
class QLabel;
|
||||
|
||||
class PlaylistContainer : public QWidget {
|
||||
@ -86,6 +87,7 @@ private slots:
|
||||
void SetTabBarHeight(int height);
|
||||
|
||||
void SelectionChanged();
|
||||
void MaybeUpdateFilter();
|
||||
void UpdateFilter();
|
||||
void FocusOnFilter(QKeyEvent *event);
|
||||
|
||||
@ -97,6 +99,9 @@ private:
|
||||
void RepositionNoMatchesLabel(bool force = false);
|
||||
|
||||
private:
|
||||
static const int kFilterDelayMs;
|
||||
static const int kFilterDelayPlaylistSizeThreshold;
|
||||
|
||||
Ui_PlaylistContainer* ui_;
|
||||
|
||||
PlaylistManager* manager_;
|
||||
@ -113,6 +118,8 @@ private:
|
||||
QLabel* no_matches_label_;
|
||||
|
||||
DidYouMean* did_you_mean_;
|
||||
|
||||
QTimer* filter_timer_;
|
||||
};
|
||||
|
||||
#endif // PLAYLISTCONTAINER_H
|
||||
|
Loading…
Reference in New Issue
Block a user