From 654953025801e680f6f50b4742649f827b8fd070 Mon Sep 17 00:00:00 2001 From: Elias Steurer Date: Fri, 19 Feb 2021 16:42:55 +0100 Subject: [PATCH] Add sort by date for installed content --- ScreenPlay/Resources.qrc | 2 ++ .../assets/icons/icon_sort-down-solid.svg | 8 +++++ .../assets/icons/icon_sort-up-solid.svg | 8 +++++ ScreenPlay/qml/Installed/Navigation.qml | 31 +++++++++++++++++-- ScreenPlay/qml/Installed/ScreenPlayItem.qml | 2 +- ScreenPlay/src/installedlistfilter.cpp | 26 +++++++++++++--- ScreenPlay/src/installedlistfilter.h | 2 ++ ScreenPlay/src/installedlistmodel.cpp | 26 ++++++++-------- ScreenPlay/src/installedlistmodel.h | 7 +++-- .../inc/public/ScreenPlayUtil/projectfile.h | 5 ++- 10 files changed, 93 insertions(+), 24 deletions(-) create mode 100644 ScreenPlay/assets/icons/icon_sort-down-solid.svg create mode 100644 ScreenPlay/assets/icons/icon_sort-up-solid.svg diff --git a/ScreenPlay/Resources.qrc b/ScreenPlay/Resources.qrc index fa4dd880..8281fc2e 100644 --- a/ScreenPlay/Resources.qrc +++ b/ScreenPlay/Resources.qrc @@ -135,5 +135,7 @@ translations/ScreenPlay_zh_cn.qm assets/images/Early_Access.png translations/ScreenPlay_pt_br.qm + assets/icons/icon_sort-up-solid.svg + assets/icons/icon_sort-down-solid.svg diff --git a/ScreenPlay/assets/icons/icon_sort-down-solid.svg b/ScreenPlay/assets/icons/icon_sort-down-solid.svg new file mode 100644 index 00000000..f145176f --- /dev/null +++ b/ScreenPlay/assets/icons/icon_sort-down-solid.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/ScreenPlay/assets/icons/icon_sort-up-solid.svg b/ScreenPlay/assets/icons/icon_sort-up-solid.svg new file mode 100644 index 00000000..bb81430d --- /dev/null +++ b/ScreenPlay/assets/icons/icon_sort-up-solid.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/ScreenPlay/qml/Installed/Navigation.qml b/ScreenPlay/qml/Installed/Navigation.qml index f6101469..24843207 100644 --- a/ScreenPlay/qml/Installed/Navigation.qml +++ b/ScreenPlay/qml/Installed/Navigation.qml @@ -122,11 +122,38 @@ Item { Common.Search { height: parent.height anchors { - right: parent.right - rightMargin: 30 + right: btnSortOrder.left + rightMargin: 10 top: parent.top } } + + ToolButton { + id: btnSortOrder + property int sortOrder: Qt.DescendingOrder + onClicked: { + sortOrder = (sortOrder + === Qt.DescendingOrder) ? Qt.AscendingOrder : Qt.DescendingOrder + ScreenPlay.installedListFilter.setSortOrder(sortOrder) + } + + icon.source: (sortOrder === Qt.AscendingOrder) ? "qrc:/assets/icons/icon_sort-down-solid.svg" : "qrc:/assets/icons/icon_sort-up-solid.svg" + icon.width: 12 + icon.height: 12 + anchors { + right: parent.right + rightMargin: 10 + top: parent.top + verticalCenter: parent.verticalCenter + } + hoverEnabled: true + + ToolTip.delay: 100 + ToolTip.timeout: 5000 + ToolTip.visible: hovered + ToolTip.text: (sortOrder === Qt.AscendingOrder) ? qsTr("Install Date Ascending") : qsTr( + "Install Date Descending") + } } states: [ diff --git a/ScreenPlay/qml/Installed/ScreenPlayItem.qml b/ScreenPlay/qml/Installed/ScreenPlayItem.qml index 3818de0a..f48e5771 100644 --- a/ScreenPlay/qml/Installed/ScreenPlayItem.qml +++ b/ScreenPlay/qml/Installed/ScreenPlayItem.qml @@ -143,7 +143,7 @@ Item { id: screenPlayItemImage anchors.fill: parent enabled: visible - visible: m_preview !== "" && m_previewGIF !== "" + visible: m_preview !== "" || m_previewGIF !== "" sourceImage: m_preview sourceImageGIF: m_previewGIF type: root.type diff --git a/ScreenPlay/src/installedlistfilter.cpp b/ScreenPlay/src/installedlistfilter.cpp index 29a5c958..2bed6621 100644 --- a/ScreenPlay/src/installedlistfilter.cpp +++ b/ScreenPlay/src/installedlistfilter.cpp @@ -20,6 +20,9 @@ InstalledListFilter::InstalledListFilter(const std::shared_ptr(InstalledListModel::ScreenPlayItem::Title)); + setSortRole(static_cast(InstalledListModel::ScreenPlayItem::LastModified)); + sort(0, m_sortOrder); + emit sortChanged(); } /*! @@ -31,12 +34,17 @@ void InstalledListFilter::sortByName(const QString& name) setFilterRole(static_cast(InstalledListModel::ScreenPlayItem::Title)); setFilterCaseSensitivity(Qt::CaseInsensitive); setFilterFixedString(name); - sort(0); + sort(0, m_sortOrder); emit sortChanged(); } /*! - \brief . + \brief Sort by: + All, + Text, + Scene, //QML, HTML, Godot, Gif, Website wallpaper + Wallpaper, + Widget, */ void InstalledListFilter::sortBySearchType(const ScreenPlay::SearchType::SearchType searchType) { @@ -47,7 +55,17 @@ void InstalledListFilter::sortBySearchType(const ScreenPlay::SearchType::SearchT } setFilterRole(static_cast(InstalledListModel::ScreenPlayItem::SearchType)); setFilterFixedString(QVariant::fromValue(searchType).toString()); - sort(0); + sort(0, m_sortOrder); + emit sortChanged(); +} + +/*! + \brief sets the sort order by date. +*/ +void InstalledListFilter::setSortOrder(const Qt::SortOrder sortOrder) +{ + m_sortOrder = sortOrder; + sort(0, m_sortOrder); emit sortChanged(); } @@ -58,7 +76,7 @@ void InstalledListFilter::resetFilter() { setFilterRole(static_cast(InstalledListModel::ScreenPlayItem::Title)); setFilterWildcard("*"); - sort(0); + sort(0, m_sortOrder); emit sortChanged(); } diff --git a/ScreenPlay/src/installedlistfilter.h b/ScreenPlay/src/installedlistfilter.h index 2d156840..f0bafe58 100644 --- a/ScreenPlay/src/installedlistfilter.h +++ b/ScreenPlay/src/installedlistfilter.h @@ -51,6 +51,7 @@ public: public slots: void sortBySearchType(const ScreenPlay::SearchType::SearchType searchType); + void setSortOrder(const Qt::SortOrder sortOrder); void sortByName(const QString& name); void resetFilter(); @@ -60,5 +61,6 @@ signals: private: const std::shared_ptr m_ilm; ScreenPlay::SearchType::SearchType m_searchType = ScreenPlay::SearchType::SearchType::All; + Qt::SortOrder m_sortOrder = Qt::SortOrder::DescendingOrder; }; } diff --git a/ScreenPlay/src/installedlistmodel.cpp b/ScreenPlay/src/installedlistmodel.cpp index 8eea6556..49fe4df8 100644 --- a/ScreenPlay/src/installedlistmodel.cpp +++ b/ScreenPlay/src/installedlistmodel.cpp @@ -21,8 +21,6 @@ InstalledListModel::InstalledListModel( : QAbstractListModel(parent) , m_globalVariables { globalVariables } { - QObject::connect(this, &InstalledListModel::addInstalledItem, - this, &InstalledListModel::append, Qt::QueuedConnection); } /*! @@ -34,8 +32,6 @@ void InstalledListModel::init() qWarning() << "Could not setup file system watcher for changed files with path: " << m_globalVariables->localStoragePath().toLocalFile(); } - loadInstalledContent(); - auto reloadLambda = [this]() { QTimer::singleShot(500, [this]() { reset(); @@ -47,7 +43,8 @@ void InstalledListModel::init() } /*! - \brief . + \brief Deleted the item from the local storage and removes it from the + installed list. */ bool InstalledListModel::deinstallItemAt(const int index) { @@ -114,6 +111,8 @@ QVariant InstalledListModel::data(const QModelIndex& index, int role) const return m_screenPlayFiles.at(row).m_publishedFileID; case static_cast(ScreenPlayItem::Tags): return m_screenPlayFiles.at(row).m_tags; + case static_cast(ScreenPlayItem::LastModified): + return m_screenPlayFiles.at(row).m_lastModified; case static_cast(ScreenPlayItem::SearchType): return QVariant::fromValue(m_screenPlayFiles.at(row).m_searchType); default: @@ -138,33 +137,32 @@ QHash InstalledListModel::roleNames() const { static_cast(ScreenPlayItem::PublishedFileID), "m_publishedFileID" }, { static_cast(ScreenPlayItem::Tags), "m_tags" }, { static_cast(ScreenPlayItem::SearchType), "m_searchType" }, + { static_cast(ScreenPlayItem::LastModified), "m_lastModified" }, }; } /*! - \brief . + \brief Append an ProjectFile to the list. */ -void InstalledListModel::append(const QJsonObject& obj, const QString& folderName) +void InstalledListModel::append(const QJsonObject& obj, const QString& folderName, const QDateTime& lastModified) { beginInsertRows(QModelIndex(), m_screenPlayFiles.size(), m_screenPlayFiles.size()); - m_screenPlayFiles.append(ProjectFile(obj, folderName, m_globalVariables->localStoragePath())); + m_screenPlayFiles.append(ProjectFile(obj, folderName, m_globalVariables->localStoragePath(), lastModified)); endInsertRows(); } /*! - \brief . + \brief Loads all installed content. Skips projects.json without a "type" field. */ void InstalledListModel::loadInstalledContent() { QtConcurrent::run([this]() { QFileInfoList list = QDir(m_globalVariables->localStoragePath().toLocalFile()).entryInfoList(QDir::NoDotAndDotDot | QDir::AllDirs); - QString projectItemPath; int counter = 0; for (const auto& item : list) { - projectItemPath = m_globalVariables->localStoragePath().toLocalFile() + "/" + item.baseName() + "/project.json"; - if (auto obj = ScreenPlayUtil::openJsonFileToObject(projectItemPath)) { + if (auto obj = ScreenPlayUtil::openJsonFileToObject(m_globalVariables->localStoragePath().toLocalFile() + "/" + item.baseName() + "/project.json")) { if (obj->isEmpty()) continue; @@ -172,9 +170,10 @@ void InstalledListModel::loadInstalledContent() if (!obj->contains("type")) continue; + if (ScreenPlayUtil::getAvailableTypes().contains(obj->value("type").toString())) { if (ScreenPlayUtil::getAvailableTypes().contains(obj->value("type").toString(), Qt::CaseInsensitive)) { - emit addInstalledItem(*obj, item.baseName()); + append(*obj, item.baseName(), item.lastModified()); } counter += 1; @@ -206,6 +205,7 @@ QVariantMap InstalledListModel::get(const QString& folderId) const map.insert("m_type", QVariant::fromValue(m_screenPlayFiles[i].m_type)); map.insert("m_absoluteStoragePath", m_screenPlayFiles[i].m_absoluteStoragePath); map.insert("m_publishedFileID", m_screenPlayFiles[i].m_publishedFileID); + map.insert("m_lastModified", m_screenPlayFiles[i].m_lastModified); return map; } } diff --git a/ScreenPlay/src/installedlistmodel.h b/ScreenPlay/src/installedlistmodel.h index c9ad7238..d566d42d 100644 --- a/ScreenPlay/src/installedlistmodel.h +++ b/ScreenPlay/src/installedlistmodel.h @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -53,9 +54,9 @@ #include #include +#include "ScreenPlayUtil/projectfile.h" #include "globalvariables.h" #include "profilelistmodel.h" -#include "ScreenPlayUtil/projectfile.h" #include "util.h" #include @@ -87,6 +88,7 @@ public: PublishedFileID, Tags, SearchType, + LastModified, }; Q_ENUM(ScreenPlayItem) @@ -99,7 +101,7 @@ public slots: QVariantMap get(const QString& folderId) const; void loadInstalledContent(); - void append(const QJsonObject&, const QString&); + void append(const QJsonObject&, const QString&, const QDateTime& lastModified); void reset(); void init(); bool deinstallItemAt(const int index); @@ -114,7 +116,6 @@ public slots: } signals: - void addInstalledItem(const QJsonObject, const QString); void installedLoadingFinished(); void countChanged(int count); diff --git a/ScreenPlayUtil/inc/public/ScreenPlayUtil/projectfile.h b/ScreenPlayUtil/inc/public/ScreenPlayUtil/projectfile.h index 9ecad22d..045e45cc 100644 --- a/ScreenPlayUtil/inc/public/ScreenPlayUtil/projectfile.h +++ b/ScreenPlayUtil/inc/public/ScreenPlayUtil/projectfile.h @@ -57,7 +57,8 @@ struct ProjectFile { ProjectFile( const QJsonObject& obj, const QString& folderName, - const QUrl& absolutePath) + const QUrl& absolutePath, + const QDateTime& lastModified) { if (obj.contains("description")) @@ -113,6 +114,7 @@ struct ProjectFile { m_preview = m_previewGIF; } m_searchType = ScreenPlayUtil::getSearchTypeFromInstalledType(m_type); + m_lastModified = lastModified; } ProjectFile() { } @@ -133,5 +135,6 @@ struct ProjectFile { InstalledType::InstalledType m_type = InstalledType::InstalledType::Unknown; SearchType::SearchType m_searchType = SearchType::SearchType::All; + QDateTime m_lastModified; }; }