From 761b1dcc5d497c06ee70fd7e13ab342b4b268d83 Mon Sep 17 00:00:00 2001 From: Bart De Vries Date: Thu, 27 Jul 2023 16:50:59 +0200 Subject: [PATCH] Revert to non-proxied QueueModel The proxy model was causing issues with item dragging. The model would reset after each swapped item. This meant that items could only be swapped one position at a time. --- src/CMakeLists.txt | 1 - src/main.cpp | 4 +-- src/models/abstractepisodeproxymodel.cpp | 12 ++++----- src/models/abstractepisodeproxymodel.h | 8 +++--- src/models/queuemodel.cpp | 16 ++++++++++++ src/models/queuemodel.h | 15 +++++++++-- src/models/queueproxymodel.cpp | 28 -------------------- src/models/queueproxymodel.h | 33 ------------------------ src/qml/QueuePage.qml | 2 +- 9 files changed, 42 insertions(+), 77 deletions(-) delete mode 100644 src/models/queueproxymodel.cpp delete mode 100644 src/models/queueproxymodel.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 485f943d..068e6688 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -34,7 +34,6 @@ set(kasts_srcs models/entriesmodel.cpp models/entriesproxymodel.cpp models/queuemodel.cpp - models/queueproxymodel.cpp models/episodemodel.cpp models/episodeproxymodel.cpp models/downloadmodel.cpp diff --git a/src/main.cpp b/src/main.cpp index b5771ac2..2538b6b2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -48,7 +48,7 @@ #include "models/errorlogmodel.h" #include "models/feedsproxymodel.h" #include "models/podcastsearchmodel.h" -#include "models/queueproxymodel.h" +#include "models/queuemodel.h" #include "networkconnectionmanager.h" #include "settingsmanager.h" #include "storagemanager.h" @@ -138,7 +138,7 @@ int main(int argc, char *argv[]) about.processCommandLine(&parser); qmlRegisterType("org.kde.kasts", 1, 0, "FeedsProxyModel"); - qmlRegisterType("org.kde.kasts", 1, 0, "QueueProxyModel"); + qmlRegisterType("org.kde.kasts", 1, 0, "QueueModel"); qmlRegisterType("org.kde.kasts", 1, 0, "EpisodeProxyModel"); qmlRegisterType("org.kde.kasts", 1, 0, "PodcastSearchModel"); qmlRegisterType("org.kde.kasts", 1, 0, "ChapterModel"); diff --git a/src/models/abstractepisodeproxymodel.cpp b/src/models/abstractepisodeproxymodel.cpp index aee1cd3b..b625d0b9 100644 --- a/src/models/abstractepisodeproxymodel.cpp +++ b/src/models/abstractepisodeproxymodel.cpp @@ -4,13 +4,13 @@ * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ -#include "models/episodeproxymodel.h" +#include "models/abstractepisodemodel.h" #include #include "datamanager.h" #include "entry.h" -#include "models/abstractepisodemodel.h" +#include "models/episodeproxymodel.h" AbstractEpisodeProxyModel::AbstractEpisodeProxyModel(QObject *parent) : QSortFilterProxyModel(parent) @@ -177,7 +177,7 @@ void AbstractEpisodeProxyModel::setSortType(SortType type) } } -QString AbstractEpisodeProxyModel::getFilterName(FilterType type) const +QString AbstractEpisodeProxyModel::getFilterName(FilterType type) { switch (type) { case FilterType::NoFilter: @@ -199,7 +199,7 @@ QString AbstractEpisodeProxyModel::getFilterName(FilterType type) const } } -QString AbstractEpisodeProxyModel::getSearchFlagName(SearchFlag flag) const +QString AbstractEpisodeProxyModel::getSearchFlagName(SearchFlag flag) { switch (flag) { case SearchFlag::TitleFlag: @@ -213,7 +213,7 @@ QString AbstractEpisodeProxyModel::getSearchFlagName(SearchFlag flag) const } } -QString AbstractEpisodeProxyModel::getSortName(SortType type) const +QString AbstractEpisodeProxyModel::getSortName(SortType type) { switch (type) { case SortType::DateDescending: @@ -225,7 +225,7 @@ QString AbstractEpisodeProxyModel::getSortName(SortType type) const } } -QString AbstractEpisodeProxyModel::getSortIconName(SortType type) const +QString AbstractEpisodeProxyModel::getSortIconName(SortType type) { switch (type) { case SortType::DateDescending: diff --git a/src/models/abstractepisodeproxymodel.h b/src/models/abstractepisodeproxymodel.h index a94a7072..1873b7fa 100644 --- a/src/models/abstractepisodeproxymodel.h +++ b/src/models/abstractepisodeproxymodel.h @@ -66,10 +66,10 @@ public: void setSearchFlags(SearchFlags searchFlags); void setSortType(SortType type); - Q_INVOKABLE QString getFilterName(FilterType type) const; - Q_INVOKABLE QString getSearchFlagName(SearchFlag flag) const; - Q_INVOKABLE QString getSortName(SortType type) const; - Q_INVOKABLE QString getSortIconName(SortType type) const; + Q_INVOKABLE static QString getFilterName(FilterType type); + Q_INVOKABLE static QString getSearchFlagName(SearchFlag flag); + Q_INVOKABLE static QString getSortName(SortType type); + Q_INVOKABLE static QString getSortIconName(SortType type); Q_INVOKABLE QItemSelection createSelection(int rowa, int rowb); diff --git a/src/models/queuemodel.cpp b/src/models/queuemodel.cpp index 8c3de991..ecf22419 100644 --- a/src/models/queuemodel.cpp +++ b/src/models/queuemodel.cpp @@ -96,7 +96,23 @@ QString QueueModel::formattedTimeLeft() const return format.formatDuration(timeLeft() / rate); } +QString QueueModel::getSortName(AbstractEpisodeProxyModel::SortType type) +{ + return AbstractEpisodeProxyModel::getSortName(type); +} + +QString QueueModel::getSortIconName(AbstractEpisodeProxyModel::SortType type) +{ + return AbstractEpisodeProxyModel::getSortIconName(type); +} + void QueueModel::updateInternalState() { // nothing to do; DataManager already has the updated data. } + +// Hack to get a QItemSelection in QML +QItemSelection QueueModel::createSelection(int rowa, int rowb) +{ + return QItemSelection(index(rowa, 0), index(rowb, 0)); +} diff --git a/src/models/queuemodel.h b/src/models/queuemodel.h index c70bb4e4..951092fe 100644 --- a/src/models/queuemodel.h +++ b/src/models/queuemodel.h @@ -6,17 +6,23 @@ #pragma once +#include #include #include +#include #include #include "models/abstractepisodemodel.h" +#include "models/abstractepisodeproxymodel.h" class QueueModel : public AbstractEpisodeModel { Q_OBJECT public: + Q_PROPERTY(int timeLeft READ timeLeft NOTIFY timeLeftChanged) + Q_PROPERTY(QString formattedTimeLeft READ formattedTimeLeft NOTIFY timeLeftChanged) + static QueueModel &instance() { static QueueModel _instance; @@ -29,9 +35,14 @@ public: int timeLeft() const; QString formattedTimeLeft() const; -Q_SIGNALS: - void timeLeftChanged(); + Q_INVOKABLE static QString getSortName(AbstractEpisodeProxyModel::SortType type); + Q_INVOKABLE static QString getSortIconName(AbstractEpisodeProxyModel::SortType type); + + Q_INVOKABLE QItemSelection createSelection(int rowa, int rowb); public Q_SLOTS: void updateInternalState() override; + +Q_SIGNALS: + void timeLeftChanged(); }; diff --git a/src/models/queueproxymodel.cpp b/src/models/queueproxymodel.cpp deleted file mode 100644 index 79cabd6b..00000000 --- a/src/models/queueproxymodel.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/** - * SPDX-FileCopyrightText: 2023 Bart De Vries - * - * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL - */ - -#include "models/queueproxymodel.h" - -QueueProxyModel::QueueProxyModel(QObject *parent) - : AbstractEpisodeProxyModel(parent) -{ - m_queueModel = &QueueModel::instance(); - setSourceModel(m_queueModel); - - connect(m_queueModel, &QueueModel::timeLeftChanged, this, [this]() { - Q_EMIT timeLeftChanged(); - }); -} - -int QueueProxyModel::timeLeft() const -{ - return m_queueModel->timeLeft(); -} - -QString QueueProxyModel::formattedTimeLeft() const -{ - return m_queueModel->formattedTimeLeft(); -} diff --git a/src/models/queueproxymodel.h b/src/models/queueproxymodel.h deleted file mode 100644 index 5d0d01a6..00000000 --- a/src/models/queueproxymodel.h +++ /dev/null @@ -1,33 +0,0 @@ -/** - * SPDX-FileCopyrightText: 2023 Bart De Vries - * - * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL - */ - -#pragma once - -#include -#include - -#include "models/abstractepisodeproxymodel.h" -#include "models/queuemodel.h" - -class QueueProxyModel : public AbstractEpisodeProxyModel -{ - Q_OBJECT - - Q_PROPERTY(int timeLeft READ timeLeft NOTIFY timeLeftChanged) - Q_PROPERTY(QString formattedTimeLeft READ formattedTimeLeft NOTIFY timeLeftChanged) - -public: - explicit QueueProxyModel(QObject *parent = nullptr); - - int timeLeft() const; - QString formattedTimeLeft() const; - -Q_SIGNALS: - void timeLeftChanged(); - -private: - QueueModel *m_queueModel; -}; diff --git a/src/qml/QueuePage.qml b/src/qml/QueuePage.qml index 5775d66c..d70c0875 100644 --- a/src/qml/QueuePage.qml +++ b/src/qml/QueuePage.qml @@ -77,7 +77,7 @@ Kirigami.ScrollablePage { } } - model: QueueProxyModel { + model: QueueModel { id: queueModel }