Modify proxy for online services
This commit is contained in:
committed by
craig.p.drummond
parent
23a0161275
commit
9e75dee7d1
@@ -66,38 +66,12 @@ bool ProxyModel::matchesFilter(const QStringList &strings) const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ProxyModel::update(const QString &text, const QString &genre)
|
||||
bool ProxyModel::update(const QString &text, const QString &genre, const void *f)
|
||||
{
|
||||
bool wasEmpty=isEmpty();
|
||||
filterStrings = text.split(' ', QString::SkipEmptyParts, Qt::CaseInsensitive);
|
||||
unmatchedStrings = 0;
|
||||
const int n = qMin(filterStrings.count(), (int)sizeof(uint));
|
||||
for ( int i = 0; i < n; ++i ) {
|
||||
unmatchedStrings |= (1<<i);
|
||||
if (text==origFilterText && genre==filterGenre && f==filter) {
|
||||
return false;
|
||||
}
|
||||
|
||||
origFilterText=text;
|
||||
filterGenre=genre;
|
||||
|
||||
if (text.length()<2 && genre.isEmpty()) {
|
||||
if (filterEnabled) {
|
||||
filterEnabled=false;
|
||||
if (!wasEmpty) {
|
||||
invalidate();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
filterEnabled=true;
|
||||
invalidate();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ProxyModel::updateWithFilter(const QString &text, const QString &genre, const void *f)
|
||||
{
|
||||
bool wasEmpty=isEmpty();
|
||||
filterStrings = text.split(' ', QString::SkipEmptyParts, Qt::CaseInsensitive);
|
||||
unmatchedStrings = 0;
|
||||
@@ -114,13 +88,13 @@ bool ProxyModel::updateWithFilter(const QString &text, const QString &genre, con
|
||||
if (filterEnabled) {
|
||||
filterEnabled=false;
|
||||
if (!wasEmpty) {
|
||||
invalidate();
|
||||
invalidateFilter();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
filterEnabled=true;
|
||||
invalidate();
|
||||
invalidateFilter();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,7 @@ public:
|
||||
ProxyModel(QObject *parent) : QSortFilterProxyModel(parent), isSorted(false), filterEnabled(false), filter(0) { }
|
||||
virtual ~ProxyModel() { }
|
||||
|
||||
bool update(const QString &text, const QString &genre=QString());
|
||||
bool updateWithFilter(const QString &text, const QString &genre, const void *f);
|
||||
bool update(const QString &text, const QString &genre=QString(), const void *f=0);
|
||||
const void * filterItem() const { return filter; }
|
||||
void setRootIndex(const QModelIndex &idx) { rootIndex=idx.isValid() ? mapToSource(idx) : idx; }
|
||||
bool isChildOfRoot(const QModelIndex &idx) const;
|
||||
|
||||
@@ -256,7 +256,7 @@ void OnlineServicesPage::itemDoubleClicked(const QModelIndex &)
|
||||
addSelectionToPlaylist();
|
||||
}
|
||||
}
|
||||
|
||||
#include <QDebug>
|
||||
void OnlineServicesPage::controlSearch(bool on)
|
||||
{
|
||||
// Can only search when we are at top level...
|
||||
@@ -332,7 +332,8 @@ void OnlineServicesPage::controlSearch(bool on)
|
||||
view->setBackgroundImage(srv->icon());
|
||||
}
|
||||
QModelIndex filterIndex=srv ? OnlineServicesModel::self()->serviceIndex(srv) : QModelIndex();
|
||||
proxy.updateWithFilter(QString(), QString(), srv);
|
||||
qWarning() << "TURN FILTER ON";
|
||||
proxy.update(QString(), QString(), srv);
|
||||
if (filterIndex.isValid()) {
|
||||
view->expand(proxy.mapFromSource(filterIndex), true);
|
||||
}
|
||||
@@ -343,7 +344,8 @@ void OnlineServicesPage::controlSearch(bool on)
|
||||
}
|
||||
genreCombo->setEnabled(true);
|
||||
searchService=QString();
|
||||
proxy.updateWithFilter(QString(), QString(), 0);
|
||||
qWarning() << "TURN FILTER OFF";
|
||||
proxy.update(QString(), QString(), 0);
|
||||
view->setBackgroundImage(QIcon());
|
||||
}
|
||||
}
|
||||
@@ -357,7 +359,7 @@ void OnlineServicesPage::searchItems()
|
||||
OnlineServicesModel::self()->setSearch(searchService, text);
|
||||
}
|
||||
} else {
|
||||
proxy.updateWithFilter(text, genreCombo->currentIndex()<=0 ? QString() : genreCombo->currentText(), proxy.filterItem());
|
||||
proxy.update(text, genreCombo->currentIndex()<=0 ? QString() : genreCombo->currentText(), view->isSearchActive() ? proxy.filterItem() : 0);
|
||||
if (proxy.enabled() && !text.isEmpty()) {
|
||||
view->expandAll(proxy.filterItem()
|
||||
? proxy.mapFromSource(OnlineServicesModel::self()->serviceIndex(static_cast<const OnlineService *>(proxy.filterItem())))
|
||||
|
||||
@@ -499,7 +499,7 @@ void StreamsPage::searchItems()
|
||||
searchModel.search(searchView->searchText().trimmed(), false);
|
||||
} else {
|
||||
QString text=view->searchText().trimmed();
|
||||
proxy->updateWithFilter(text, QString(), proxy->filterItem());
|
||||
proxy->update(text, QString(), proxy->filterItem());
|
||||
if (proxy->enabled() && !text.isEmpty()) {
|
||||
view->expandAll(proxy->filterItem()
|
||||
? proxy->mapFromSource(StreamsModel::self()->categoryIndex(static_cast<const StreamsModel::CategoryItem *>(proxy->filterItem())))
|
||||
@@ -546,7 +546,7 @@ void StreamsPage::controlSearch(bool on)
|
||||
viewStack->setCurrentIndex(0);
|
||||
view->setSearchLabelText(i18n("Search %1:", cat->name));
|
||||
view->setBackgroundImage(cat->icon);
|
||||
proxy->updateWithFilter(QString(), QString(), cat);
|
||||
proxy->update(QString(), QString(), cat);
|
||||
QModelIndex filterIndex=cat ? StreamsModel::self()->categoryIndex(cat) : QModelIndex();
|
||||
if (filterIndex.isValid()) {
|
||||
view->expand(proxy->mapFromSource(filterIndex), true);
|
||||
@@ -564,7 +564,7 @@ void StreamsPage::controlSearch(bool on)
|
||||
}
|
||||
view->clearSelection();
|
||||
} else {
|
||||
proxy->updateWithFilter(QString(), QString(), 0);
|
||||
proxy->update(QString(), QString(), 0);
|
||||
proxy=&streamsProxy;
|
||||
searchModel.clear();
|
||||
view->setSearchVisible(false);
|
||||
|
||||
Reference in New Issue
Block a user