diff --git a/CMakeLists.txt b/CMakeLists.txt index 550a75048..018ee10d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,6 +58,7 @@ SET( CANTATA_SRCS models/albumsmodel.cpp models/albumsproxymodel.cpp models/streamfetcher.cpp + models/proxymodel.cpp mpd/mpdconnection.cpp mpd/mpdparseutils.cpp mpd/mpdstatus.cpp diff --git a/devices/devicespage.cpp b/devices/devicespage.cpp index dab373116..8509329eb 100644 --- a/devices/devicespage.cpp +++ b/devices/devicespage.cpp @@ -224,26 +224,7 @@ void DevicesPage::itemDoubleClicked(const QModelIndex &) void DevicesPage::searchItems() { - QString genre=0==genreCombo->currentIndex() ? QString() : genreCombo->currentText(); - QString filter=view->searchText().trimmed(); - - if (filter.isEmpty() && genre.isEmpty()) { - proxy.setFilterEnabled(false); - proxy.setFilterGenre(genre); - if (!proxy.filterRegExp().isEmpty()) { - proxy.setFilterRegExp(QString()); - } else { - proxy.invalidate(); - } - } else { - proxy.setFilterEnabled(true); - proxy.setFilterGenre(genre); - if (filter!=proxy.filterRegExp().pattern()) { - proxy.setFilterRegExp(filter); - } else { - proxy.invalidate(); - } - } + proxy.update(view->searchText().trimmed(), genreCombo->currentIndex()<=0 ? QString() : genreCombo->currentText()); } void DevicesPage::controlActions() diff --git a/gui/albumspage.cpp b/gui/albumspage.cpp index c54bf56d9..b0b38197a 100644 --- a/gui/albumspage.cpp +++ b/gui/albumspage.cpp @@ -198,27 +198,7 @@ void AlbumsPage::itemActivated(const QModelIndex &) void AlbumsPage::searchItems() { - QString genre=genreCombo->currentIndex()<=0 ? QString() : genreCombo->currentText(); - QString filter=view->searchText().trimmed(); - - if (filter.isEmpty() && genre.isEmpty()) { - bool wasEmpty=proxy.isEmpty(); - proxy.setFilterEnabled(false); - proxy.setFilterGenre(genre); - if (!proxy.filterRegExp().isEmpty()) { - proxy.setFilterRegExp(QString()); - } else if (!wasEmpty) { - proxy.invalidate(); - } - } else { - proxy.setFilterEnabled(true); - proxy.setFilterGenre(genre); - if (filter!=proxy.filterRegExp().pattern()) { - proxy.setFilterRegExp(filter); - } else { - proxy.invalidate(); - } - } + proxy.update(view->searchText().trimmed(), genreCombo->currentIndex()<=0 ? QString() : genreCombo->currentText()); } void AlbumsPage::controlActions() diff --git a/gui/folderpage.cpp b/gui/folderpage.cpp index 0e88a7c9f..266a0e611 100644 --- a/gui/folderpage.cpp +++ b/gui/folderpage.cpp @@ -132,17 +132,7 @@ void FolderPage::clear() void FolderPage::searchItems() { - QString filter=view->searchText().trimmed(); - - if (filter.isEmpty() ) { - proxy.setFilterEnabled(false); - if (!proxy.filterRegExp().isEmpty()) { - proxy.setFilterRegExp(QString()); - } - } else if (filter!=proxy.filterRegExp().pattern()) { - proxy.setFilterEnabled(true); - proxy.setFilterRegExp(filter); - } + proxy.update(view->searchText().trimmed()); } void FolderPage::controlActions() diff --git a/gui/librarypage.cpp b/gui/librarypage.cpp index bd67e7341..5b4da98bd 100644 --- a/gui/librarypage.cpp +++ b/gui/librarypage.cpp @@ -241,27 +241,7 @@ void LibraryPage::itemDoubleClicked(const QModelIndex &) void LibraryPage::searchItems() { - QString genre=genreCombo->currentIndex()<=0 ? QString() : genreCombo->currentText(); - QString filter=view->searchText().trimmed(); - - if (filter.isEmpty() && genre.isEmpty()) { - bool wasEmpty=proxy.isEmpty(); - proxy.setFilterEnabled(false); - proxy.setFilterGenre(genre); - if (!proxy.filterRegExp().isEmpty()) { - proxy.setFilterRegExp(QString()); - } else if (!wasEmpty) { - proxy.invalidate(); - } - } else { - proxy.setFilterEnabled(true); - proxy.setFilterGenre(genre); - if (filter!=proxy.filterRegExp().pattern()) { - proxy.setFilterRegExp(filter); - } else { - proxy.invalidate(); - } - } + proxy.update(view->searchText().trimmed(), genreCombo->currentIndex()<=0 ? QString() : genreCombo->currentText()); } void LibraryPage::controlActions() diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 125f357b5..b275179bf 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -1412,10 +1412,6 @@ void MainWindow::realSearchPlaylist() playQueue->updateRows(playQueueModel.currentSongRow(), autoScrollPlayQueue && MPDState_Playing==MPDStatus::self()->state()); scrollPlayQueue(); } - playQueueProxyModel.setFilterEnabled(false); - if (!playQueueProxyModel.filterRegExp().isEmpty()) { - playQueueProxyModel.setFilterRegExp(QString()); - } } else if (filter!=playQueueProxyModel.filterRegExp().pattern()) { if (!usingProxy) { if (playQueue->selectionModel()->hasSelection()) { @@ -1429,9 +1425,8 @@ void MainWindow::realSearchPlaylist() playQueue->updateRows(playQueueModel.rowCount()+10, false); playQueue->setFilterActive(true); } - playQueueProxyModel.setFilterEnabled(true); - playQueueProxyModel.setFilterRegExp(filter); } + playQueueProxyModel.update(filter); if (selectedSongIds.size() > 0) { foreach (qint32 i, selectedSongIds) { diff --git a/gui/playlistspage.cpp b/gui/playlistspage.cpp index 28e590658..9f2374f59 100644 --- a/gui/playlistspage.cpp +++ b/gui/playlistspage.cpp @@ -351,27 +351,7 @@ void PlaylistsPage::controlActions() void PlaylistsPage::searchItems() { - QString genre=genreCombo->currentIndex()<=0 ? QString() : genreCombo->currentText(); - QString filter=view->searchText().trimmed(); - - if (filter.isEmpty() && genre.isEmpty()) { - bool wasEmpty=proxy.isEmpty(); - proxy.setFilterEnabled(false); - proxy.setFilterGenre(genre); - if (!proxy.filterRegExp().isEmpty()) { - proxy.setFilterRegExp(QString()); - } else if (!wasEmpty) { - proxy.invalidate(); - } - } else { - proxy.setFilterEnabled(true); - proxy.setFilterGenre(genre); - if (filter!=proxy.filterRegExp().pattern()) { - proxy.setFilterRegExp(filter); - } else { - proxy.invalidate(); - } - } + proxy.update(view->searchText().trimmed(), genreCombo->currentIndex()<=0 ? QString() : genreCombo->currentText()); } void PlaylistsPage::updated(const QModelIndex &index) diff --git a/gui/streamspage.cpp b/gui/streamspage.cpp index 5022692c2..a7158fc81 100644 --- a/gui/streamspage.cpp +++ b/gui/streamspage.cpp @@ -436,27 +436,7 @@ void StreamsPage::controlActions() void StreamsPage::searchItems() { - QString genre=genreCombo->currentIndex()<=0 ? QString() : genreCombo->currentText(); - QString filter=view->searchText().trimmed(); - - if (filter.isEmpty() && genre.isEmpty()) { - bool wasEmpty=proxy.isEmpty(); - proxy.setFilterEnabled(false); - proxy.setFilterGenre(genre); - if (!proxy.filterRegExp().isEmpty()) { - proxy.setFilterRegExp(QString()); - } else if (!wasEmpty) { - proxy.invalidate(); - } - } else { - proxy.setFilterEnabled(true); - proxy.setFilterGenre(genre); - if (filter!=proxy.filterRegExp().pattern()) { - proxy.setFilterRegExp(filter); - } else { - proxy.invalidate(); - } - } + proxy.update(view->searchText().trimmed(), genreCombo->currentIndex()<=0 ? QString() : genreCombo->currentText()); } QStringList StreamsPage::getCategories() diff --git a/models/albumsproxymodel.cpp b/models/albumsproxymodel.cpp index 771712579..8e1670338 100644 --- a/models/albumsproxymodel.cpp +++ b/models/albumsproxymodel.cpp @@ -65,7 +65,7 @@ bool AlbumsProxyModel::filterAcceptsSong(AlbumsModel::Item *item) const bool AlbumsProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { - if (filterGenre.isEmpty() && filterRegExp().isEmpty()) { + if (!filterEnabled) { return true; } if (!isChildOfRoot(sourceParent)) { @@ -82,14 +82,6 @@ bool AlbumsProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &source return item->isAlbum() ? filterAcceptsAlbum(item) : filterAcceptsSong(item); } -void AlbumsProxyModel::setFilterGenre(const QString &genre) -{ - if (filterGenre!=genre) { - invalidate(); - } - filterGenre=genre; -} - bool AlbumsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const { AlbumsModel::Item *l=static_cast(left.internalPointer()); diff --git a/models/albumsproxymodel.h b/models/albumsproxymodel.h index a6715c311..32b94d371 100644 --- a/models/albumsproxymodel.h +++ b/models/albumsproxymodel.h @@ -31,19 +31,12 @@ class AlbumsProxyModel : public ProxyModel { public: AlbumsProxyModel(QObject *parent = 0); - void setFilterGenre(const QString &genre); bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; bool lessThan(const QModelIndex &left, const QModelIndex &right) const; - bool isEmpty() const { - return filterGenre.isEmpty() && filterRegExp().isEmpty(); - } private: bool filterAcceptsAlbum(AlbumsModel::Item *item) const; bool filterAcceptsSong(AlbumsModel::Item *item) const; - -private: - QString filterGenre; }; #endif diff --git a/models/dirviewproxymodel.cpp b/models/dirviewproxymodel.cpp index 5782721e0..107d2f7ee 100644 --- a/models/dirviewproxymodel.cpp +++ b/models/dirviewproxymodel.cpp @@ -73,7 +73,7 @@ bool DirViewProxyModel::filterAcceptsDirViewItem(const DirViewItem * const item, bool DirViewProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { - if (filterRegExp().isEmpty()) { + if (!filterEnabled) { return true; } if (!isChildOfRoot(sourceParent)) { diff --git a/models/musiclibraryproxymodel.cpp b/models/musiclibraryproxymodel.cpp index 554033d44..34df791e1 100644 --- a/models/musiclibraryproxymodel.cpp +++ b/models/musiclibraryproxymodel.cpp @@ -42,158 +42,85 @@ MusicLibraryProxyModel::MusicLibraryProxyModel(QObject *parent) bool MusicLibraryProxyModel::filterAcceptsRoot(const MusicLibraryItem * const item) const { -// switch (filterField) { -// case 0: // Artist -// return item->data().contains(filterRegExp()); -// case 1: // Album -// for (int i = 0; i < item->childCount(); i++) { -// if (item->child(i)->data().contains(filterRegExp())) { -// return true; -// } -// } -// break; -// case 2: // Song -// for (int i = 0; i < item->childCount(); i++) { -// for (int j = 0; j < item->child(i)->childCount(); j++) { -// if (item->child(i)->child(j)->data().contains(filterRegExp())) { -// return true; -// } -// } -// } -// break; -// case 3: // Any - if (item->data().contains(filterRegExp())) - return true; + if (item->data().contains(filterRegExp())) { + return true; + } - foreach (const MusicLibraryItem *i, item->children()) { - if (i->data().contains(filterRegExp())) { + foreach (const MusicLibraryItem *i, item->children()) { + if (i->data().contains(filterRegExp())) { + return true; + } + } + + foreach (const MusicLibraryItem *i, item->children()) { + foreach (const MusicLibraryItem *j, i->children()) { + if (j->data().contains(filterRegExp())) { return true; } } + } - foreach (const MusicLibraryItem *i, item->children()) { - foreach (const MusicLibraryItem *j, i->children()) { - if (j->data().contains(filterRegExp())) { + foreach (const MusicLibraryItem *i, item->children()) { + foreach (const MusicLibraryItem *j, i->children()) { + foreach (const MusicLibraryItem *k, j->children()) { + if (k->data().contains(filterRegExp())) { return true; } } } + } - foreach (const MusicLibraryItem *i, item->children()) { - foreach (const MusicLibraryItem *j, i->children()) { - foreach (const MusicLibraryItem *k, j->children()) { - if (k->data().contains(filterRegExp())) { - return true; - } - } - } - } -// break; -// default: -// break; -// } -// return false; } bool MusicLibraryProxyModel::filterAcceptsArtist(const MusicLibraryItem * const item) const { -// switch (filterField) { -// case 0: // Artist -// return item->data().contains(filterRegExp()); -// case 1: // Album -// for (int i = 0; i < item->childCount(); i++) { -// if (item->child(i)->data().contains(filterRegExp())) { -// return true; -// } -// } -// break; -// case 2: // Song -// for (int i = 0; i < item->childCount(); i++) { -// for (int j = 0; j < item->child(i)->childCount(); j++) { -// if (item->child(i)->child(j)->data().contains(filterRegExp())) { -// return true; -// } -// } -// } -// break; -// case 3: // Any - if (item->data().contains(filterRegExp())) - return true; + if (item->data().contains(filterRegExp())) { + return true; + } - foreach (const MusicLibraryItem *i, item->children()) { - if (i->data().contains(filterRegExp())) { + foreach (const MusicLibraryItem *i, item->children()) { + if (i->data().contains(filterRegExp())) { + return true; + } + } + + foreach (const MusicLibraryItem *i, item->children()) { + foreach (const MusicLibraryItem *j, i->children()) { + if (j->data().contains(filterRegExp())) { return true; } } + } - foreach (const MusicLibraryItem *i, item->children()) { - foreach (const MusicLibraryItem *j, i->children()) { - if (j->data().contains(filterRegExp())) { - return true; - } - } - } -// break; -// default: -// break; -// } -// return false; } bool MusicLibraryProxyModel::filterAcceptsAlbum(const MusicLibraryItem * const item) const { -// switch (filterField) { -// case 0: // Artist -// return item->parent()->data().contains(filterRegExp()); -// case 1: // Album -// return item->data().contains(filterRegExp()); -// case 2: // Song -// for (int i = 0; i < item->childCount(); i++) { -// if (item->child(i)->data().contains(filterRegExp())) -// return true; -// } -// break; -// case 3: // Any - if (item->parent()->data().contains(filterRegExp()) || item->data().contains(filterRegExp())) + if (item->parent()->data().contains(filterRegExp()) || item->data().contains(filterRegExp())) { + return true; + } + + foreach (const MusicLibraryItem *i, item->children()) { + if (i->data().contains(filterRegExp())) { return true; - foreach (const MusicLibraryItem *i, item->children()) { - if (i->data().contains(filterRegExp())) { - return true; - } } -// break; -// default: -// break; -// } + } return false; } bool MusicLibraryProxyModel::filterAcceptsSong(const MusicLibraryItem * const item) const { -// switch (filterField) { -// case 0: // Artist -// return item->parent()->parent()->data().contains(filterRegExp()); -// case 1: // Album -// return item->parent()->data().contains(filterRegExp()); -// case 2: // Song -// return item->data().contains(filterRegExp()); -// case 3: // Any - return item->parent()->parent()->data().contains(filterRegExp()) || - item->parent()->data().contains(filterRegExp()) || - item->data().contains(filterRegExp()); -// default: -// break; -// } - - return false; + return item->parent()->parent()->data().contains(filterRegExp()) || + item->parent()->data().contains(filterRegExp()) || + item->data().contains(filterRegExp()); } bool MusicLibraryProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { - if (filterGenre.isEmpty() && filterRegExp().isEmpty()) { + if (!filterEnabled) { return true; } if (!isChildOfRoot(sourceParent)) { @@ -264,16 +191,3 @@ bool MusicLibraryProxyModel::lessThan(const QModelIndex &left, const QModelIndex return QSortFilterProxyModel::lessThan(left, right); } - -// void MusicLibraryProxyModel::setFilterField(int field) -// { -// filterField = field; -// } - -void MusicLibraryProxyModel::setFilterGenre(const QString &genre) -{ - if (filterGenre!=genre) { - invalidate(); - } - filterGenre=genre; -} diff --git a/models/musiclibraryproxymodel.h b/models/musiclibraryproxymodel.h index 507ee8153..0e1460894 100644 --- a/models/musiclibraryproxymodel.h +++ b/models/musiclibraryproxymodel.h @@ -39,21 +39,12 @@ public: MusicLibraryProxyModel(QObject *parent = 0); bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; bool lessThan(const QModelIndex &left, const QModelIndex &right) const; -// void setFilterField(int field); - void setFilterGenre(const QString &genre); - bool isEmpty() const { - return filterGenre.isEmpty() && filterRegExp().isEmpty(); - } private: bool filterAcceptsRoot(const MusicLibraryItem * const item) const; bool filterAcceptsArtist(const MusicLibraryItem * const item) const; bool filterAcceptsAlbum(const MusicLibraryItem * const item) const; bool filterAcceptsSong(const MusicLibraryItem * const item) const; - -private: - QString filterGenre; -// int filterField; }; #endif diff --git a/models/playlistsproxymodel.cpp b/models/playlistsproxymodel.cpp index 4dba7c2dc..c8c3c17c9 100644 --- a/models/playlistsproxymodel.cpp +++ b/models/playlistsproxymodel.cpp @@ -36,17 +36,9 @@ PlaylistsProxyModel::PlaylistsProxyModel(QObject *parent) setSortLocaleAware(true); } -void PlaylistsProxyModel::setFilterGenre(const QString &genre) -{ - if (filterGenre!=genre) { - invalidate(); - } - filterGenre=genre; -} - bool PlaylistsProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { - if (filterGenre.isEmpty() && filterRegExp().isEmpty()) { + if (!filterEnabled) { return true; } if (!isChildOfRoot(sourceParent)) { @@ -96,4 +88,4 @@ bool PlaylistsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &r } return false; -} \ No newline at end of file +} diff --git a/models/playlistsproxymodel.h b/models/playlistsproxymodel.h index 4bcdb95bd..57f2dfe91 100644 --- a/models/playlistsproxymodel.h +++ b/models/playlistsproxymodel.h @@ -34,15 +34,8 @@ class PlaylistsProxyModel : public ProxyModel public: PlaylistsProxyModel(QObject *parent = 0); - void setFilterGenre(const QString &genre); bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; bool lessThan(const QModelIndex &left, const QModelIndex &right) const; - bool isEmpty() const { - return filterGenre.isEmpty() && filterRegExp().isEmpty(); - } - -private: - QString filterGenre; }; #endif diff --git a/models/playqueueproxymodel.cpp b/models/playqueueproxymodel.cpp index cb69a8d4b..03ac0460d 100644 --- a/models/playqueueproxymodel.cpp +++ b/models/playqueueproxymodel.cpp @@ -30,13 +30,9 @@ #include "song.h" PlayQueueProxyModel::PlayQueueProxyModel(QObject *parent) - : QSortFilterProxyModel(parent) - , filterEnabled(false) + : ProxyModel(parent) { - //setDynamicSortFilter(true); setFilterCaseSensitivity(Qt::CaseInsensitive); - //setSortCaseSensitivity(Qt::CaseInsensitive); - //setSortLocaleAware(true); } bool PlayQueueProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const @@ -50,27 +46,11 @@ bool PlayQueueProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sou Song s=m->getSongByRow(sourceRow); QRegExp re=filterRegExp(); - /*if (m->isGrouped()) { - return QString(!s.albumartist.isEmpty() && s.albumartist != s.artist - ? s.title + " - " + s.artist - : s.title).contains(re); - } else*/ { - return s.album.contains(re) || s.artist.contains(re) || s.genre.contains(re) || - (s.title.isEmpty() ? s.file.contains(re) : s.title.contains(re)); - } - -// int columnCount = sourceModel()->columnCount(sourceParent); -// -// for (int i = 0; i < columnCount; i++) { -// QModelIndex index = sourceModel()->index(sourceRow, i, sourceParent); -// if (sourceModel()->data(index).toString().contains(filterRegExp())) { -// return true; -// } -// } - return false; + return s.album.contains(re) || s.artist.contains(re) || s.genre.contains(re) || + (s.title.isEmpty() ? s.file.contains(re) : s.title.contains(re)); +; } -/* map proxy to real indexes and redirect to sourceModel */ QMimeData *PlayQueueProxyModel::mimeData(const QModelIndexList &indexes) const { QModelIndexList sourceIndexes; @@ -82,7 +62,6 @@ QMimeData *PlayQueueProxyModel::mimeData(const QModelIndexList &indexes) const return sourceModel()->mimeData(sourceIndexes); } -/* map proxy to real indexes and redirect to sourceModel */ bool PlayQueueProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) { const QModelIndex sourceIndex = mapToSource(index(row, column, parent)); diff --git a/models/playqueueproxymodel.h b/models/playqueueproxymodel.h index 4d16155b6..735ef2abc 100644 --- a/models/playqueueproxymodel.h +++ b/models/playqueueproxymodel.h @@ -27,9 +27,9 @@ #ifndef PLAYQUEUEPROXYMODEL_H #define PLAYQUEUEPROXYMODEL_H -#include +#include "proxymodel.h" -class PlayQueueProxyModel : public QSortFilterProxyModel +class PlayQueueProxyModel : public ProxyModel { Q_OBJECT @@ -39,10 +39,6 @@ public: QMimeData *mimeData(const QModelIndexList &indexes) const; bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); - void setFilterEnabled(bool e) { filterEnabled=e; } - -private: - bool filterEnabled; }; #endif diff --git a/models/proxymodel.cpp b/models/proxymodel.cpp new file mode 100644 index 000000000..572b8fc58 --- /dev/null +++ b/models/proxymodel.cpp @@ -0,0 +1,61 @@ +/* + * Cantata + * + * Copyright (c) 2011-2012 Craig Drummond + * + * ---- + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "proxymodel.h" + +void ProxyModel::update(const QString &text, const QString &genre) +{ + if (text.length()<2 && genre.isEmpty()) { + bool wasEmpty=isEmpty(); + filterEnabled=false; + filterGenre=genre; + if (!filterRegExp().isEmpty()) { + setFilterRegExp(QString()); + } else if (!wasEmpty) { + invalidate(); + } + } else { + filterEnabled=true; + filterGenre=genre; + if (text!=filterRegExp().pattern()) { + setFilterRegExp(text); + } else { + invalidate(); + } + } +} + +bool ProxyModel::isChildOfRoot(const QModelIndex &idx) const { + if (!rootIndex.isValid()) { + return true; + } + + QModelIndex i=idx; + while(i.isValid()) { + if (i==rootIndex) { + return true; + } + i=i.parent(); + } + return false; +} diff --git a/models/proxymodel.h b/models/proxymodel.h index 0a6ed2a37..78e80f1f3 100644 --- a/models/proxymodel.h +++ b/models/proxymodel.h @@ -36,29 +36,18 @@ public: virtual ~ProxyModel() { } + void 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 { - if (!rootIndex.isValid()) { - return true; - } - - QModelIndex i=idx; - while(i.isValid()) { - if (i==rootIndex) { - return true; - } - i=i.parent(); - } - return false; + bool isChildOfRoot(const QModelIndex &idx) const; + bool isEmpty() const { + return filterGenre.isEmpty() && filterRegExp().isEmpty(); } - void setFilterEnabled(bool e) { filterEnabled=e; } - -private: +protected: bool filterEnabled; + QString filterGenre; QModelIndex rootIndex; }; diff --git a/models/streamsproxymodel.cpp b/models/streamsproxymodel.cpp index c302fd5f4..341b1a9b6 100644 --- a/models/streamsproxymodel.cpp +++ b/models/streamsproxymodel.cpp @@ -33,17 +33,9 @@ StreamsProxyModel::StreamsProxyModel(QObject *parent) sort(0); } -void StreamsProxyModel::setFilterGenre(const QString &genre) -{ - if (filterGenre!=genre) { - invalidate(); - } - filterGenre=genre; -} - bool StreamsProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { - if (filterGenre.isEmpty() && filterRegExp().isEmpty()) { + if (!filterEnabled) { return true; } if (!isChildOfRoot(sourceParent)) { diff --git a/models/streamsproxymodel.h b/models/streamsproxymodel.h index bfe61cc52..06c20d7c1 100644 --- a/models/streamsproxymodel.h +++ b/models/streamsproxymodel.h @@ -32,12 +32,6 @@ public: StreamsProxyModel(QObject *parent = 0); void setFilterGenre(const QString &genre); bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; - bool isEmpty() const { - return filterGenre.isEmpty() && filterRegExp().isEmpty(); - } - -private: - QString filterGenre; }; #endif