when in a lower level, and search to an item that matches higher - the model navigates up - but the nav buttons dont change!!!!
this leads to a crash when press nav button!
   e.g. Im/
          Final Front../
            El Dorado...
        A/
           B

        If we are in 'B' and type 'Dorado' then we change to 'Im' - but nav buttons do not!
This commit is contained in:
craig
2012-01-03 19:58:33 +00:00
committed by craig
parent ae450143a2
commit 2a32ec80c3
15 changed files with 119 additions and 32 deletions

View File

@@ -137,12 +137,6 @@ void AlbumsPage::itemActivated(const QModelIndex &)
void AlbumsPage::searchItems()
{
proxy.setFilterGenre(0==genreCombo->currentIndex() ? QString() : genreCombo->currentText());
if (view->searchText().isEmpty()) {
proxy.setFilterRegExp(QString());
return;
}
proxy.setFilterRegExp(view->searchText());
}

View File

@@ -88,11 +88,6 @@ void FolderPage::clear()
void FolderPage::searchItems()
{
if (view->searchText().isEmpty()) {
proxy.setFilterRegExp("");
return;
}
proxy.setFilterRegExp(view->searchText());
}

View File

@@ -23,7 +23,8 @@
#include "albumsproxymodel.h"
AlbumsProxyModel::AlbumsProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
AlbumsProxyModel::AlbumsProxyModel(QObject *parent)
: ProxyModel(parent)
{
setDynamicSortFilter(true);
setFilterCaseSensitivity(Qt::CaseInsensitive);
@@ -67,6 +68,9 @@ bool AlbumsProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &source
if (filterGenre.isEmpty() && filterRegExp().isEmpty()) {
return true;
}
if (!isChildOfRoot(sourceParent)) {
return true;
}
const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
AlbumsModel::Item *item = static_cast<AlbumsModel::Item *>(index.internalPointer());

View File

@@ -24,10 +24,10 @@
#ifndef ALBUMSPROXYMODEL_H
#define ALBUMSPROXYMODEL_H
#include <QtGui/QSortFilterProxyModel>
#include "proxymodel.h"
#include "albumsmodel.h"
class AlbumsProxyModel : public QSortFilterProxyModel
class AlbumsProxyModel : public ProxyModel
{
public:
AlbumsProxyModel(QObject *parent = 0);

View File

@@ -28,7 +28,8 @@
#include "dirviewitemfile.h"
#include "dirviewproxymodel.h"
DirViewProxyModel::DirViewProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
DirViewProxyModel::DirViewProxyModel(QObject *parent)
: ProxyModel(parent)
{
setDynamicSortFilter(true);
setFilterCaseSensitivity(Qt::CaseInsensitive);
@@ -75,6 +76,9 @@ bool DirViewProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourc
if (filterRegExp().isEmpty()) {
return true;
}
if (!isChildOfRoot(sourceParent)) {
return true;
}
const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
DirViewItem *item = static_cast<DirViewItem *>(index.internalPointer());

View File

@@ -26,11 +26,11 @@
#ifndef DIRVIEWPROXYMODEL_H
#define DIRVIEWPROXYMODEL_H
#include <QSortFilterProxyModel>
#include "proxymodel.h"
class DirViewItem;
class DirViewProxyModel : public QSortFilterProxyModel
class DirViewProxyModel : public ProxyModel
{
Q_OBJECT

View File

@@ -31,7 +31,7 @@
#include "musiclibraryproxymodel.h"
MusicLibraryProxyModel::MusicLibraryProxyModel(QObject *parent)
: QSortFilterProxyModel(parent),
: ProxyModel(parent),
_filterField(3)
{
setDynamicSortFilter(true);
@@ -139,6 +139,9 @@ bool MusicLibraryProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &
if (_filterGenre.isEmpty() && filterRegExp().isEmpty()) {
return true;
}
if (!isChildOfRoot(sourceParent)) {
return true;
}
const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
const MusicLibraryItem * const item = static_cast<MusicLibraryItem *>(index.internalPointer());

View File

@@ -27,11 +27,11 @@
#ifndef MUSIC_LIBRARY_SORT_FILTER_MODEL_H
#define MUSIC_LIBRARY_SORT_FILTER_MODEL_H
#include <QSortFilterProxyModel>
#include "proxymodel.h"
class MusicLibraryItem;
class MusicLibraryProxyModel : public QSortFilterProxyModel
class MusicLibraryProxyModel : public ProxyModel
{
Q_OBJECT
@@ -44,12 +44,13 @@ public:
void setFilterGenre(const QString &genre);
private:
QString _filterGenre;
int _filterField;
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

View File

@@ -27,7 +27,8 @@
#include "playlistsproxymodel.h"
#include "playlistsmodel.h"
PlaylistsProxyModel::PlaylistsProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
PlaylistsProxyModel::PlaylistsProxyModel(QObject *parent)
: ProxyModel(parent)
{
setDynamicSortFilter(true);
setFilterCaseSensitivity(Qt::CaseInsensitive);
@@ -40,6 +41,9 @@ bool PlaylistsProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sou
if (filterRegExp().isEmpty()) {
return true;
}
if (!isChildOfRoot(sourceParent)) {
return true;
}
const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
PlaylistsModel::Item *item = static_cast<PlaylistsModel::Item *>(index.internalPointer());

View File

@@ -26,9 +26,9 @@
#ifndef PLAYLISTSPROXYMODEL_H
#define PLAYLISTSPROXYMODEL_H
#include <QSortFilterProxyModel>
#include "proxymodel.h"
class PlaylistsProxyModel : public QSortFilterProxyModel
class PlaylistsProxyModel : public ProxyModel
{
Q_OBJECT

62
models/proxymodel.h Normal file
View File

@@ -0,0 +1,62 @@
/*
* Cantata
*
* Copyright (c) 2011 Craig Drummond <craig.p.drummond@gmail.com>
*
* ----
*
* 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.
*/
#ifndef PROXYMODEL_H
#define PROXYMODEL_H
#include <QtGui/QSortFilterProxyModel>
#include <QtCore/QDebug>
class ProxyModel : public QSortFilterProxyModel
{
public:
ProxyModel(QObject *parent)
: QSortFilterProxyModel(parent) {
}
virtual ~ProxyModel() {
}
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;
}
private:
QModelIndex rootIndex;
};
#endif

View File

@@ -23,7 +23,8 @@
#include "streamsproxymodel.h"
#include "streamsmodel.h"
StreamsProxyModel::StreamsProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
StreamsProxyModel::StreamsProxyModel(QObject *parent)
: ProxyModel(parent)
{
setDynamicSortFilter(true);
setFilterCaseSensitivity(Qt::CaseInsensitive);
@@ -31,3 +32,14 @@ StreamsProxyModel::StreamsProxyModel(QObject *parent) : QSortFilterProxyModel(pa
setSortLocaleAware(true);
sort(0);
}
bool StreamsProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
if (filterRegExp().isEmpty()) {
return true;
}
if (!isChildOfRoot(sourceParent)) {
return true;
}
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}

View File

@@ -24,12 +24,13 @@
#ifndef STREAMSPROXYMODEL_H
#define STREAMSPROXYMODEL_H
#include <QtGui/QSortFilterProxyModel>
#include "proxymodel.h"
class StreamsProxyModel : public QSortFilterProxyModel
class StreamsProxyModel : public ProxyModel
{
public:
StreamsProxyModel(QObject *parent = 0);
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
};
#endif

View File

@@ -24,6 +24,7 @@
#include "itemview.h"
#include "mainwindow.h"
#include "covers.h"
#include "proxymodel.h"
#include <QtGui/QIcon>
#include <QtGui/QToolButton>
#include <QtGui/QStyledItemDelegate>
@@ -393,11 +394,13 @@ void ItemView::setMode(Mode m)
if (Mode_Tree==mode) {
treeView->setModel(itemModel);
listView->setModel(0);
itemModel->setRootIndex(QModelIndex());
} else {
treeView->setModel(0);
listView->setModel(itemModel);
setLevel(0);
listView->setRootIndex(QModelIndex());
itemModel->setRootIndex(QModelIndex());
if (Mode_IconTop!=mode) {
listView->setGridSize(listGridSize);
listView->setViewMode(QListView::ListMode);
@@ -471,7 +474,7 @@ QAbstractItemView * ItemView::view() const
return Mode_Tree==mode ? (QAbstractItemView *)treeView : (QAbstractItemView *)listView;
}
void ItemView::setModel(QAbstractItemModel *m)
void ItemView::setModel(ProxyModel *m)
{
itemModel=m;
view()->setModel(m);
@@ -563,6 +566,7 @@ void ItemView::backActivated()
return;
}
setLevel(currentLevel-1);
itemModel->setRootIndex(listView->rootIndex().parent());
listView->setRootIndex(listView->rootIndex().parent());
listView->scrollTo(prevTopIndex, QAbstractItemView::PositionAtTop);
}
@@ -624,6 +628,7 @@ void ItemView::itemActivated(const QModelIndex &index)
listSearch->setPlaceholderText(tr("Search %1...").arg(index.data(Qt::DisplayRole).toString()));
#endif
listView->setRootIndex(index);
itemModel->setRootIndex(index);
listView->scrollToTop();
}
}

View File

@@ -31,6 +31,8 @@ class QAction;
class KPixmapSequenceOverlayPainter;
#endif
class ProxyModel;
class ItemView : public QWidget, public Ui::ItemView
{
Q_OBJECT
@@ -60,7 +62,7 @@ public:
Mode viewMode() const { return mode; }
void setLevel(int level);
QAbstractItemView * view() const;
void setModel(QAbstractItemModel *m);
void setModel(ProxyModel *m);
void clearSelection() { view()->selectionModel()->clearSelection(); }
QModelIndexList selectedIndexes() const;
QString searchText() const;
@@ -92,7 +94,7 @@ private:
QAction * getAction(const QModelIndex &index);
private:
QAbstractItemModel *itemModel;
ProxyModel *itemModel;
QAction *backAction;
QAction *act1;
QAction *act2;