Speed up online services model by disabling dynamic sort
This commit is contained in:
committed by
craig.p.drummond
parent
53a4d299ac
commit
f51a6f2fb9
@@ -1692,7 +1692,7 @@ void MainWindow::realSearchPlayQueue()
|
||||
filter=QString();
|
||||
}
|
||||
|
||||
if (filter!=playQueueProxyModel.filterRegExp().pattern()) {
|
||||
if (filter!=playQueueProxyModel.filterText()) {
|
||||
playQueue->setFilterActive(!filter.isEmpty());
|
||||
playQueue->selectionModel()->clear();
|
||||
playQueueProxyModel.update(filter);
|
||||
|
||||
@@ -112,6 +112,10 @@ bool MusicLibraryProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &
|
||||
}
|
||||
}
|
||||
|
||||
if (filterStrings.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (item->itemType()) {
|
||||
case MusicLibraryItem::Type_Root:
|
||||
return filterAcceptsRoot(item);
|
||||
|
||||
@@ -55,7 +55,7 @@ bool PlaylistsProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sou
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pl->name.contains(filterRegExp())) {
|
||||
if (matchesFilter(QStringList() << pl->name)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ bool ProxyModel::matchesFilter(const QStringList &strings) const
|
||||
|
||||
bool ProxyModel::update(const QString &text, const QString &genre)
|
||||
{
|
||||
bool wasEmpty=isEmpty();
|
||||
filterStrings = text.split(' ', QString::SkipEmptyParts, Qt::CaseInsensitive);
|
||||
unmatchedStrings = 0;
|
||||
const int n = qMin(filterStrings.count(), (int)sizeof(uint));
|
||||
@@ -75,33 +76,28 @@ bool ProxyModel::update(const QString &text, const QString &genre)
|
||||
unmatchedStrings |= (1<<i);
|
||||
}
|
||||
|
||||
origFilterText=text;
|
||||
filterGenre=genre;
|
||||
|
||||
if (text.length()<2 && genre.isEmpty()) {
|
||||
if (filterEnabled) {
|
||||
bool wasEmpty=isEmpty();
|
||||
filterEnabled=false;
|
||||
filterGenre=genre;
|
||||
if (!wasEmpty || !filterRegExp().isEmpty()) {
|
||||
if (!wasEmpty) {
|
||||
invalidate();
|
||||
}
|
||||
if (!filterRegExp().isEmpty()) {
|
||||
setFilterRegExp(QString());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
filterEnabled=true;
|
||||
filterGenre=genre;
|
||||
invalidate();
|
||||
if (text!=filterRegExp().pattern()) {
|
||||
setFilterRegExp(text);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ProxyModel::isChildOfRoot(const QModelIndex &idx) const {
|
||||
bool ProxyModel::isChildOfRoot(const QModelIndex &idx) const
|
||||
{
|
||||
if (!rootIndex.isValid()) {
|
||||
return true;
|
||||
}
|
||||
@@ -115,3 +111,11 @@ bool ProxyModel::isChildOfRoot(const QModelIndex &idx) const {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ProxyModel::sort(int column, Qt::SortOrder order)
|
||||
{
|
||||
if (!isSorted || dynamicSortFilter()) {
|
||||
QSortFilterProxyModel::sort(column, order);
|
||||
isSorted=true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,23 +31,28 @@
|
||||
class ProxyModel : public QSortFilterProxyModel
|
||||
{
|
||||
public:
|
||||
ProxyModel(QObject *parent) : QSortFilterProxyModel(parent), filterEnabled(false) { }
|
||||
ProxyModel(QObject *parent) : QSortFilterProxyModel(parent), isSorted(false), filterEnabled(false) { }
|
||||
virtual ~ProxyModel() { }
|
||||
|
||||
bool update(const QString &text, const QString &genre=QString());
|
||||
void setRootIndex(const QModelIndex &idx) { rootIndex=idx.isValid() ? mapToSource(idx) : idx; }
|
||||
bool isChildOfRoot(const QModelIndex &idx) const;
|
||||
bool isEmpty() const { return filterGenre.isEmpty() && filterRegExp().isEmpty(); }
|
||||
bool isEmpty() const { return filterGenre.isEmpty() && filterStrings.isEmpty(); }
|
||||
bool enabled() const { return filterEnabled; }
|
||||
const QString & filterText() const { return origFilterText; }
|
||||
void sort() { isSorted=false; sort(0); }
|
||||
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
|
||||
|
||||
protected:
|
||||
bool matchesFilter(const Song &s) const;
|
||||
bool matchesFilter(const QStringList &strings) const;
|
||||
|
||||
protected:
|
||||
bool isSorted;
|
||||
bool filterEnabled;
|
||||
QString filterGenre;
|
||||
QModelIndex rootIndex;
|
||||
QString origFilterText;
|
||||
QStringList filterStrings;
|
||||
uint unmatchedStrings;
|
||||
};
|
||||
|
||||
@@ -79,6 +79,7 @@ OnlineServicesPage::OnlineServicesPage(QWidget *p)
|
||||
view->addAction(downloadAction);
|
||||
menuButton->setMenu(menu);
|
||||
proxy.setSourceModel(OnlineServicesModel::self());
|
||||
proxy.setDynamicSortFilter(false);
|
||||
view->setModel(&proxy);
|
||||
view->setRootIsDecorated(true);
|
||||
view->setUniformRowHeights(true);
|
||||
@@ -447,5 +448,10 @@ void OnlineServicesPage::download()
|
||||
|
||||
void OnlineServicesPage::updated(const QModelIndex &idx)
|
||||
{
|
||||
MusicLibraryItem *item=static_cast<MusicLibraryItem *>(idx.internalPointer());
|
||||
if (MusicLibraryItem::Type_Root==item->itemType() && !static_cast<OnlineService *>(item)->isSearchBased()) {
|
||||
proxy.sort();
|
||||
}
|
||||
|
||||
view->setExpanded(proxy.mapFromSource(idx));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user