Seting 'filter item' does not invalidate sort

This commit is contained in:
craig.p.drummond
2013-10-10 20:30:35 +00:00
parent 63c89af45a
commit de04d871b0
4 changed files with 21 additions and 11 deletions

View File

@@ -66,11 +66,11 @@ bool ProxyModel::matchesFilter(const QStringList &strings) const
return false;
}
//#include <QDebug>
bool ProxyModel::update(const QString &txt, const QString &genre, const void *f)
bool ProxyModel::update(const QString &txt, const QString &genre)
{
QString text=txt.length()<2 ? QString() : txt;
// qWarning() << "UPDATE" << txt << genre << (void *)f;
if (text==origFilterText && genre==filterGenre && f==filter) {
if (text==origFilterText && genre==filterGenre) {
// qWarning() <<"NO CHANGE";
return false;
}
@@ -85,9 +85,8 @@ bool ProxyModel::update(const QString &txt, const QString &genre, const void *f)
origFilterText=text;
filterGenre=genre;
filter=f;
if (text.isEmpty() && genre.isEmpty() && !filter) {
if (text.isEmpty() && genre.isEmpty()) {
if (filterEnabled) {
filterEnabled=false;
if (!wasEmpty) {

View File

@@ -34,8 +34,9 @@ public:
ProxyModel(QObject *parent) : QSortFilterProxyModel(parent), isSorted(false), filterEnabled(false), filter(0) { }
virtual ~ProxyModel() { }
bool update(const QString &text, const QString &genre=QString(), const void *f=0);
bool update(const QString &text, const QString &genre=QString());
const void * filterItem() const { return filter; }
void setFilterItem(void *f) { filter=f; }
void setRootIndex(const QModelIndex &idx) { rootIndex=idx.isValid() ? mapToSource(idx) : idx; }
bool isChildOfRoot(const QModelIndex &idx) const;
bool isEmpty() const { return filterGenre.isEmpty() && filterStrings.isEmpty() && 0==filter; }

View File

@@ -332,7 +332,8 @@ void OnlineServicesPage::controlSearch(bool on)
view->setBackgroundImage(srv->icon());
}
QModelIndex filterIndex=srv ? OnlineServicesModel::self()->serviceIndex(srv) : QModelIndex();
proxy.update(QString(), QString(), srv);
proxy.setFilterItem(srv);
proxy.update(QString(), QString());
if (filterIndex.isValid()) {
view->expand(proxy.mapFromSource(filterIndex), true);
}
@@ -343,7 +344,8 @@ void OnlineServicesPage::controlSearch(bool on)
}
genreCombo->setEnabled(true);
searchService=QString();
proxy.update(QString(), QString(), 0);
proxy.setFilterItem(0);
proxy.update(QString(), QString());
view->setBackgroundImage(QIcon());
}
}
@@ -357,7 +359,10 @@ void OnlineServicesPage::searchItems()
OnlineServicesModel::self()->setSearch(searchService, text);
}
} else {
proxy.update(text, genreCombo->currentIndex()<=0 ? QString() : genreCombo->currentText(), view->isSearchActive() ? proxy.filterItem() : 0);
if (!view->isSearchActive()) {
proxy.setFilterItem(0);
}
proxy.update(view->isSearchActive() ? text : QString(), genreCombo->currentIndex()<=0 ? QString() : genreCombo->currentText());
if (proxy.enabled() && !proxy.filterText().isEmpty()) {
view->expandAll(proxy.filterItem() && view->isSearchActive()
? proxy.mapFromSource(OnlineServicesModel::self()->serviceIndex(static_cast<const OnlineService *>(proxy.filterItem())))

View File

@@ -499,7 +499,10 @@ void StreamsPage::searchItems()
searchModel.search(searchView->searchText().trimmed(), false);
} else {
QString text=view->searchText().trimmed();
proxy->update(text, QString(), proxy->filterItem());
if (!view->isSearchActive()) {
proxy->setFilterItem(0);
}
proxy->update(view->isSearchActive() ? text : QString(), QString());
if (proxy->enabled() && !text.isEmpty()) {
view->expandAll(proxy->filterItem()
? proxy->mapFromSource(StreamsModel::self()->categoryIndex(static_cast<const StreamsModel::CategoryItem *>(proxy->filterItem())))
@@ -546,7 +549,8 @@ void StreamsPage::controlSearch(bool on)
viewStack->setCurrentIndex(0);
view->setSearchLabelText(i18n("Search %1:", cat->name));
view->setBackgroundImage(cat->icon);
proxy->update(QString(), QString(), cat);
proxy->setFilterItem(cat);
proxy->update(QString(), QString());
QModelIndex filterIndex=cat ? StreamsModel::self()->categoryIndex(cat) : QModelIndex();
if (filterIndex.isValid()) {
view->expand(proxy->mapFromSource(filterIndex), true);
@@ -564,7 +568,8 @@ void StreamsPage::controlSearch(bool on)
}
view->clearSelection();
} else {
proxy->update(QString(), QString(), 0);
proxy->setFilterItem(0);
proxy->update(QString(), QString());
proxy=&streamsProxy;
searchModel.clear();
view->setSearchVisible(false);