Add option to only act on songs that pass current string or genre filter.

BUG: 473
This commit is contained in:
craig.p.drummond
2014-04-30 18:48:00 +00:00
committed by craig.p.drummond
parent 6f79dee43d
commit a1337b933c
13 changed files with 193 additions and 112 deletions

View File

@@ -22,10 +22,14 @@
*/
#include "proxymodel.h"
#ifndef ENABLE_UBUNTU
#include "settings.h"
#endif
#include <QMap>
#include <QString>
#include <QLatin1String>
#include <QChar>
#include <QMimeData>
bool ProxyModel::matchesFilter(const Song &s) const
{
@@ -161,3 +165,55 @@ QList<int> ProxyModel::mapToSourceRows(const QModelIndexList &list) const
}
return rows;
}
QModelIndexList ProxyModel::mapToSource(const QModelIndexList &list, bool leavesOnly) const
{
QModelIndexList mapped;
if (leavesOnly) {
QModelIndexList l=leaves(list);
foreach (const QModelIndex &idx, l) {
mapped.append(mapToSource(idx));
}
} else {
foreach (const QModelIndex &idx, list) {
mapped.append(mapToSource(idx));
}
}
return mapped;
}
#ifndef ENABLE_UBUNTU
QMimeData * ProxyModel::mimeData(const QModelIndexList &indexes) const
{
QModelIndexList nodes=Settings::self()->filteredOnly() ? leaves(indexes) : indexes;
QModelIndexList sourceIndexes;
foreach (const QModelIndex &idx, nodes) {
sourceIndexes << mapToSource(idx);
}
return sourceModel()->mimeData(sourceIndexes);
}
#endif
QModelIndexList ProxyModel::leaves(const QModelIndexList &list) const
{
QModelIndexList l;
foreach (const QModelIndex &idx, list) {
l+=leaves(idx);
}
return l;
}
QModelIndexList ProxyModel::leaves(const QModelIndex &idx) const
{
QModelIndexList list;
int rc=rowCount(idx);
if (rc>0) {
for (int i=0; i<rc; ++i) {
list+=leaves(index(i, 0, idx));
}
} else {
list+=idx;
}
return list;
}