From db03bdbce2fa0f55d33fb3a42cd2f5766e708be0 Mon Sep 17 00:00:00 2001 From: Luca Beltrame Date: Sat, 21 Feb 2015 10:40:36 +0100 Subject: [PATCH] Add tag sorting (based on counts) to the tag view --- src/mainwindow.cpp | 33 +++++++++++++++++++++------------ src/mainwindow.h | 3 +++ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 1b47334..aa1906f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -74,6 +75,7 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent) m_connectWidget(Q_NULLPTR), m_searchWidget(new DanbooruSearchWidget(this)), m_tagWidget(new DanbooruTagWidget(this)), + m_proxyModel(new QSortFilterProxyModel(this)), m_tableView(new QTableView(this)), m_cache(Q_NULLPTR) { @@ -89,8 +91,14 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent) m_cache = new KImageCache(qApp->applicationName(), DanbooruSettings::self()->cacheSize()); m_service->setImageCache(m_cache); + + m_proxyModel->setSortRole(DanbooruTagModel::TagCountRole); + m_proxyModel->setSourceModel(m_tagModel); + m_proxyModel->setDynamicSortFilter(true); + m_tableView->setModel(m_poolModel); - m_tagWidget->setModel(m_tagModel); + m_tagWidget->setModel(m_proxyModel); + // Set up declarative bindings for the QQuickWidget @@ -183,6 +191,18 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent) searchDockWidget->hide(); }); + connect(m_service, &DanbooruService::postDownloadFinished, [this]() { + + if (m_tagModel->rowCount() == 0) { + // Only get tags if we don't have any already + for (auto tag: m_model->postTags()) { + m_service->getTagList(1, tag); + } + } + m_proxyModel->sort(0, Qt::DescendingOrder); + + }); + connect(m_view->rootObject(), SIGNAL(downloadRequested(const QUrl&)), this, SLOT(slotHandleDownload(const QUrl&))); @@ -375,17 +395,6 @@ void DanbooruMainWindow::setupDockWidgets() { qobject_cast(actionCollection()->action(QLatin1String("tags")))->setActive(visible); }); - connect(m_service, &DanbooruService::postDownloadFinished, [this]() { - - if (m_tagModel->rowCount() == 0) { - // Only get tags if we don't have any already - for (auto tag: m_model->postTags()) { - m_service->getTagList(1, tag); - } - } - - }); - } void DanbooruMainWindow::connectToBoard() diff --git a/src/mainwindow.h b/src/mainwindow.h index aa3fbd5..86fb2ad 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -35,6 +35,7 @@ class QQuickWidget; +class QSortFilterProxyModel; namespace Danbooru @@ -70,6 +71,8 @@ private: DanbooruConnectWidget *m_connectWidget; DanbooruSearchWidget *m_searchWidget; DanbooruTagWidget *m_tagWidget; + QSortFilterProxyModel *m_proxyModel; + QTableView *m_tableView; KImageCache *m_cache; static QHash ratingMap;