From db2220937ada75b222da394e8b14abacd47cb5f5 Mon Sep 17 00:00:00 2001 From: "craig.p.drummond" Date: Sun, 30 Dec 2012 21:00:23 +0000 Subject: [PATCH] Slightly speed up playqueue searches. --- ChangeLog | 1 + models/playqueuemodel.cpp | 2 +- models/playqueueproxymodel.cpp | 4 ++-- models/proxymodel.cpp | 25 +++++++++++++------------ widgets/groupedview.cpp | 15 +++++++++------ widgets/groupedview.h | 2 ++ widgets/itemview.cpp | 1 + widgets/playqueueview.cpp | 20 +++++++++++--------- widgets/playqueueview.h | 1 + 9 files changed, 41 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index e57420f48..72498cbc6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -40,6 +40,7 @@ that they always match consume and single icons. 22. Re-enable animation when showing messagewidget, for Qt-only builds and for non 4.9.4 KDE builds. +23. Slightly speed up playqueue searches. 0.9.2 ----- diff --git a/models/playqueuemodel.cpp b/models/playqueuemodel.cpp index dee4647f0..ba7bcc8a8 100644 --- a/models/playqueuemodel.cpp +++ b/models/playqueuemodel.cpp @@ -132,7 +132,7 @@ PlayQueueModel::~PlayQueueModel() QModelIndex PlayQueueModel::index(int row, int column, const QModelIndex &parent) const { - return hasIndex(row, column, parent) ? createIndex(row, column, 0) : QModelIndex(); + return hasIndex(row, column, parent) ? createIndex(row, column, (void *)&songs.at(row)) : QModelIndex(); } QModelIndex PlayQueueModel::parent(const QModelIndex &idx) const diff --git a/models/playqueueproxymodel.cpp b/models/playqueueproxymodel.cpp index cdfe4503c..02e011120 100644 --- a/models/playqueueproxymodel.cpp +++ b/models/playqueueproxymodel.cpp @@ -41,8 +41,8 @@ bool PlayQueueProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sou return true; } - Q_UNUSED(sourceParent) - return matchesFilter(static_cast(sourceModel())->getSongByRow(sourceRow)); + const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); + return matchesFilter(*static_cast(index.internalPointer())); } QMimeData *PlayQueueProxyModel::mimeData(const QModelIndexList &indexes) const diff --git a/models/proxymodel.cpp b/models/proxymodel.cpp index 11c62ec95..d200dda34 100644 --- a/models/proxymodel.cpp +++ b/models/proxymodel.cpp @@ -44,23 +44,23 @@ bool ProxyModel::matchesFilter(const QStringList &strings) const uint ums = unmatchedStrings; int numStrings = filterStrings.count(); - foreach (const QString &str, strings) { - QString candidate = str.simplified(); + foreach (const QString &candidate /*str*/, strings) { +// QString candidate = str.simplified(); - for (int i = 0; i < candidate.size(); ++i) { - if (candidate.at(i).decompositionTag() != QChar::NoDecomposition) { - candidate[i] = candidate[i].decomposition().at(0); - } - } +// for (int i = 0; i < candidate.size(); ++i) { +// if (candidate.at(i).decompositionTag() != QChar::NoDecomposition) { +// candidate[i] = candidate[i].decomposition().at(0); +// } +// } for (int i = 0; i < numStrings; ++i) { if (candidate.contains(filterStrings.at(i), Qt::CaseInsensitive)) { ums &= ~(1<rowCount(); for (quint32 i=0; iindex(i, 0); - if (model()->hasChildren(idx)) { - quint32 childCount=model()->rowCount(idx); - for (quint32 c=0; cindex(i, 0); + if (model()->hasChildren(idx)) { + quint32 childCount=model()->rowCount(idx); + for (quint32 c=0; chasChildren(index)) { + if (isMultiLevel && model()->hasChildren(index)) { quint32 childCount=model()->rowCount(index); for (quint32 c=0; cindex(i, 0, index); diff --git a/widgets/groupedview.h b/widgets/groupedview.h index df9652672..ac51b672e 100644 --- a/widgets/groupedview.h +++ b/widgets/groupedview.h @@ -66,6 +66,7 @@ public: bool isAutoExpand() const { return autoExpand; } void setStartClosed(bool sc); bool isStartClosed() const { return startClosed; } + void setMultiLevel(bool ml) { isMultiLevel=ml; } void updateRows(qint32 row, bool scroll, const QModelIndex &parent=QModelIndex()); void updateCollectionRows(); bool isCurrentAlbum(quint16 key) const { return key==currentAlbum; } @@ -91,6 +92,7 @@ private: bool startClosed; bool autoExpand; bool filterActive; + bool isMultiLevel; quint16 currentAlbum; QMap > controlledAlbums; }; diff --git a/widgets/itemview.cpp b/widgets/itemview.cpp index 632728e92..eb34a8bc4 100644 --- a/widgets/itemview.cpp +++ b/widgets/itemview.cpp @@ -439,6 +439,7 @@ void ItemView::allowGroupedView() if (!groupedView) { groupedView=new GroupedView(stackedWidget); groupedView->setAutoExpand(false); + groupedView->setMultiLevel(true); treeLayout->addWidget(groupedView); connect(groupedView, SIGNAL(itemsSelected(bool)), this, SIGNAL(itemsSelected(bool))); if (SINGLE_CLICK) { diff --git a/widgets/playqueueview.cpp b/widgets/playqueueview.cpp index a4824dd6e..e3949b6ab 100644 --- a/widgets/playqueueview.cpp +++ b/widgets/playqueueview.cpp @@ -225,19 +225,21 @@ bool PlayQueueView::isStartClosed() const void PlayQueueView::setFilterActive(bool f) { - groupedView->setFilterActive(f); + if (isGrouped()) { + groupedView->setFilterActive(f); + } } void PlayQueueView::updateRows(qint32 row, bool scroll) { - if (currentWidget()==groupedView) { + if (isGrouped()) { groupedView->updateRows(row, scroll); } } void PlayQueueView::scrollTo(const QModelIndex &index, QAbstractItemView::ScrollHint hint) { - if (currentWidget()==groupedView && !groupedView->isFilterActive()) { + if (isGrouped() && !groupedView->isFilterActive()) { return; } if (MPDState_Playing==MPDStatus::self()->state()) { @@ -248,7 +250,7 @@ void PlayQueueView::scrollTo(const QModelIndex &index, QAbstractItemView::Scroll void PlayQueueView::setModel(QAbstractItemModel *m) { - if (currentWidget()==groupedView) { + if (isGrouped()) { groupedView->setModel(m); } else { treeView->setModel(m); @@ -273,7 +275,7 @@ bool PlayQueueView::hasFocus() QAbstractItemModel * PlayQueueView::model() { - return currentWidget()==groupedView ? groupedView->model() : treeView->model(); + return isGrouped() ? groupedView->model() : treeView->model(); } void PlayQueueView::setContextMenuPolicy(Qt::ContextMenuPolicy policy) @@ -284,17 +286,17 @@ void PlayQueueView::setContextMenuPolicy(Qt::ContextMenuPolicy policy) bool PlayQueueView::haveUnSelectedItems() { - return currentWidget()==groupedView ? groupedView->haveUnSelectedItems() : treeView->haveUnSelectedItems(); + return isGrouped() ? groupedView->haveUnSelectedItems() : treeView->haveUnSelectedItems(); } QItemSelectionModel * PlayQueueView::selectionModel() const { - return currentWidget()==groupedView ? groupedView->selectionModel() : treeView->selectionModel(); + return isGrouped() ? groupedView->selectionModel() : treeView->selectionModel(); } void PlayQueueView::setCurrentIndex(const QModelIndex &index) { - if (currentWidget()==groupedView) { + if (isGrouped()) { groupedView->setCurrentIndex(index); } else { treeView->setCurrentIndex(index); @@ -318,7 +320,7 @@ QAbstractItemView * PlayQueueView::list() bool PlayQueueView::hasFocus() const { - return currentWidget()==groupedView ? groupedView->hasFocus() : treeView->hasFocus(); + return isGrouped() ? groupedView->hasFocus() : treeView->hasFocus(); } QModelIndexList PlayQueueView::selectedIndexes() const diff --git a/widgets/playqueueview.h b/widgets/playqueueview.h index 78a4d5beb..fee402d19 100644 --- a/widgets/playqueueview.h +++ b/widgets/playqueueview.h @@ -70,6 +70,7 @@ public: } void saveHeader(); void setGrouped(bool g); + bool isGrouped() const { return currentWidget()==(QWidget *)groupedView; } void setAutoExpand(bool ae); bool isAutoExpand() const; void setStartClosed(bool sc);