Faster filter

This commit is contained in:
craig
2012-01-03 19:54:24 +00:00
committed by craig
parent 1872cef46f
commit a069ee80fe
5 changed files with 22 additions and 7 deletions

View File

@@ -64,6 +64,10 @@ bool AlbumsProxyModel::filterAcceptsSong(AlbumsModel::Item *item) const
bool AlbumsProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
if (filterGenre.isEmpty() && filterRegExp().isEmpty()) {
return true;
}
const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
AlbumsModel::Item *item = static_cast<AlbumsModel::Item *>(index.internalPointer());

View File

@@ -72,14 +72,16 @@ bool DirViewProxyModel::filterAcceptsDirViewItem(const DirViewItem * const item,
bool DirViewProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
if (filterRegExp().isEmpty()) {
return true;
}
const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
DirViewItem *item = static_cast<DirViewItem *>(index.internalPointer());
return filterAcceptsDirViewItem(item, true);
}
bool DirViewProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
const DirViewItem * const leftItem = static_cast<DirViewItem *>(left.internalPointer());

View File

@@ -136,6 +136,10 @@ bool MusicLibraryProxyModel::filterAcceptsSong(const MusicLibraryItem * const it
bool MusicLibraryProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
if (_filterGenre.isEmpty() && filterRegExp().isEmpty()) {
return true;
}
const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
const MusicLibraryItem * const item = static_cast<MusicLibraryItem *>(index.internalPointer());

View File

@@ -37,6 +37,10 @@ PlaylistsProxyModel::PlaylistsProxyModel(QObject *parent) : QSortFilterProxyMode
bool PlaylistsProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
if (filterRegExp().isEmpty()) {
return true;
}
const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
PlaylistsModel::Item *item = static_cast<PlaylistsModel::Item *>(index.internalPointer());

View File

@@ -38,6 +38,10 @@ PlayQueueProxyModel::PlayQueueProxyModel(QObject *parent) : QSortFilterProxyMode
bool PlayQueueProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
if (filterRegExp().isEmpty()) {
return true;
}
int columnCount = sourceModel()->columnCount(sourceParent);
for (int i = 0; i < columnCount; i++) {
@@ -62,11 +66,8 @@ QMimeData *PlayQueueProxyModel::mimeData(const QModelIndexList &indexes) const
}
/* 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)
bool PlayQueueProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
{
const QModelIndex index = this->index(row, column, parent);
const QModelIndex sourceIndex = mapToSource(index);
const QModelIndex sourceIndex = mapToSource(index(row, column, parent));
return sourceModel()->dropMimeData(data, action, sourceIndex.row(), sourceIndex.column(), sourceIndex.parent());
}