More work for Jamendo searches

This commit is contained in:
craig.p.drummond
2013-07-15 19:13:14 +00:00
committed by craig.p.drummond
parent 867370c63b
commit ea0aef26df
11 changed files with 39 additions and 39 deletions

View File

@@ -32,6 +32,7 @@
MusicLibraryProxyModel::MusicLibraryProxyModel(QObject *parent)
: ProxyModel(parent)
, filter(0)
{
setDynamicSortFilter(true);
setFilterCaseSensitivity(Qt::CaseInsensitive);
@@ -81,9 +82,6 @@ bool MusicLibraryProxyModel::filterAcceptsSong(const MusicLibraryItem *item) con
bool MusicLibraryProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
if (filterIndex.isValid() && !sourceParent.isValid() && sourceRow!=filterIndex.row()) {
return false;
}
if (!filterEnabled) {
return true;
}
@@ -98,6 +96,22 @@ bool MusicLibraryProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &
return false;
}
if (filter) {
if (!sourceParent.isValid()) {
// All top level items are valid
return true;
}
const MusicLibraryItem *p=item->parentItem();
while (p->parentItem()) {
p=p->parentItem();
}
if (p!=filter) {
// If item is not part of 'filter' tree - then we accept it
return true;
}
}
switch (item->itemType()) {
case MusicLibraryItem::Type_Root:
return filterAcceptsRoot(item);
@@ -129,11 +143,3 @@ bool MusicLibraryProxyModel::lessThan(const QModelIndex &left, const QModelIndex
return QSortFilterProxyModel::lessThan(left, right);
}
void MusicLibraryProxyModel::setFilterIndex(const QModelIndex &f)
{
if (f!=filterIndex) {
filterIndex=f;
invalidate();
}
}

View File

@@ -39,7 +39,8 @@ public:
MusicLibraryProxyModel(QObject *parent = 0);
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
void setFilterIndex(const QModelIndex &f);
void setFilterItem(const MusicLibraryItem *f) { filter=f; }
const MusicLibraryItem *filterItem() const { return filter; }
private:
bool filterAcceptsRoot(const MusicLibraryItem *item) const;
@@ -48,7 +49,7 @@ private:
bool filterAcceptsSong(const MusicLibraryItem *item) const;
private:
QModelIndex filterIndex;
const MusicLibraryItem *filter;
};
#endif

View File

@@ -100,9 +100,9 @@ QModelIndex OnlineServicesModel::index(int row, int column, const QModelIndex &p
return QModelIndex();
}
QModelIndex OnlineServicesModel::index(OnlineService *srv) const
QModelIndex OnlineServicesModel::index(const OnlineService *srv) const
{
int row=services.indexOf(srv);
int row=services.indexOf(const_cast<OnlineService *>(srv));
return -1==row ? QModelIndex() : createIndex(row, 0, (void *)srv);
}

View File

@@ -45,7 +45,7 @@ public:
OnlineServicesModel(QObject *parent = 0);
~OnlineServicesModel();
QModelIndex index(int row, int column, const QModelIndex & = QModelIndex()) const;
QModelIndex index(OnlineService *srv) const;
QModelIndex index(const OnlineService *srv) const;
QModelIndex parent(const QModelIndex &) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;

View File

@@ -263,18 +263,18 @@ void OnlineServicesPage::controlSearch(bool on)
view->setBackgroundImage(srv->serviceIcon());
}
QModelIndex filterIndex=srv ? OnlineServicesModel::self()->index(srv) : QModelIndex();
proxy.setFilterIndex(filterIndex);
proxy.setFilterItem(srv);
if (filterIndex.isValid()) {
view->setExpanded(filterIndex);
view->showIndex(proxy.mapFromSource(filterIndex), true);
}
} else {
OnlineService *srv=OnlineServicesModel::self()->service(searchService);
if (srv && srv->isSearchBased()) {
if (srv) {
srv->cancelSearch();
}
genreCombo->setEnabled(true);
searchService=QString();
proxy.setFilterIndex(QModelIndex());
proxy.setFilterItem(0);
view->setBackgroundImage(QIcon());
}
}
@@ -290,7 +290,9 @@ void OnlineServicesPage::searchItems()
} else {
proxy.update(text, genreCombo->currentIndex()<=0 ? QString() : genreCombo->currentText());
if (proxy.enabled() && !text.isEmpty()) {
view->expandAll();
view->expandAll(proxy.filterItem()
? proxy.mapFromSource(OnlineServicesModel::self()->index(static_cast<const OnlineService *>(proxy.filterItem())))
: QModelIndex());
}
}
}

View File

@@ -799,14 +799,6 @@ void GroupedView::itemClicked(const QModelIndex &idx)
}
}
void GroupedView::expandAll()
{
quint32 count=model()->rowCount();
for (quint32 i=0; i<count; ++i) {
expand(model()->index(i, 0));
}
}
void GroupedView::expand(const QModelIndex &idx)
{
if (idx.isValid()) {

View File

@@ -81,7 +81,6 @@ public:
QModelIndexList selectedIndexes() const;
void dropEvent(QDropEvent *event);
void collectionRemoved(quint32 key);
void expandAll();
void expand(const QModelIndex &idx);
public Q_SLOTS:

View File

@@ -860,12 +860,12 @@ void ItemView::updateRows(const QModelIndex &idx)
}
}
void ItemView::expandAll()
void ItemView::expandAll(const QModelIndex &index)
{
if (Mode_SimpleTree==mode || Mode_DetailedTree==mode) {
treeView->expandAll();
treeView->expandAll(index);
} else if (Mode_GroupedTree==mode && groupedView) {
groupedView->expandAll();
groupedView->expandAll(index);
}
}

View File

@@ -126,7 +126,7 @@ public:
bool isSearchActive() const;
void setStartClosed(bool sc);
bool isStartClosed();
void expandAll();
void expandAll(const QModelIndex &index=QModelIndex());
void expand(const QModelIndex &index);
void showMessage(const QString &message, int timeout);
void setBackgroundImage(const QIcon &icon);

View File

@@ -269,11 +269,11 @@ QModelIndexList TreeView::selectedIndexes() const
return sort.values();
}
void TreeView::expandAll()
void TreeView::expandAll(const QModelIndex &idx)
{
quint32 count=model()->rowCount();
quint32 count=model()->rowCount(idx);
for (quint32 i=0; i<count; ++i) {
expand(model()->index(i, 0));
expand(model()->index(i, 0, idx));
}
}

View File

@@ -60,8 +60,8 @@ public:
void startDrag(Qt::DropActions supportedActions);
void mouseReleaseEvent(QMouseEvent *event);
QModelIndexList selectedIndexes() const;
void expandAll();
void expand(const QModelIndex &idx);
void expandAll(const QModelIndex &idx=QModelIndex());
virtual void expand(const QModelIndex &idx);
virtual void setModel(QAbstractItemModel *m);
bool checkBoxClicked(const QModelIndex &idx) const;
void setUseSimpleDelegate();