Compare commits
67 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 53f95a775d | |||
| a100814875 | |||
| 8948946491 | |||
| 098c3f67e5 | |||
| 39988a555c | |||
| f4cd9c8c17 | |||
| 7833970236 | |||
| 520c1226da | |||
| f65026d173 | |||
| 7fe140ce7e | |||
| 9570aed12c | |||
| bfa2a50dfb | |||
| 22cdb351ca | |||
| 9e765837f5 | |||
| 43fc2d8455 | |||
| 112110a6f2 | |||
| 49ee8bb952 | |||
| 7bfe9f86bc | |||
| dfd789fb6c | |||
| 5e4c4f2b99 | |||
| 26fb04431e | |||
| be089a43f7 | |||
| d523b297f3 | |||
| c8cbdae511 | |||
| 3ceeac3e20 | |||
| eeee3f0c04 | |||
| 1522dbdbfc | |||
| 773f5946bd | |||
| c493758876 | |||
| c2efa5a005 | |||
| 5f31bc9fc2 | |||
| d5314b9066 | |||
| 81551df2e5 | |||
| 2a4eeab436 | |||
| 9d310850ac | |||
| fcd59ffd45 | |||
| e3c92133cf | |||
| 1dea9a6ae3 | |||
| 57568dba31 | |||
| 7534e0208d | |||
| 6b64994ae2 | |||
| b7dfe53e7e | |||
| 4004124a33 | |||
| 5d7bfc6a49 | |||
| 9b4510f518 | |||
| be263c934a | |||
| 25c27d70e8 | |||
| 6151edeb1c | |||
| 122ba7de13 | |||
| abbcc5b211 | |||
| 2debbf2102 | |||
| 39a06e0e8c | |||
| e309107f4d | |||
| 5eb160a792 | |||
| aa15cef4fe | |||
| cc8f1b8fad | |||
| 1154f9b004 | |||
| 3b7267c538 | |||
| 311b69a98c | |||
| 8cb213c3e3 | |||
| aa52a82ba2 | |||
| b88ec5b67b | |||
| 6ca41ada22 | |||
| 6c3c06b818 | |||
| c0e439ce6d | |||
| fb90713022 | |||
| 96a7c71a29 |
+2
-2
@@ -20,12 +20,13 @@ set(QML_IMPORT_PATH ${QT_QML_OUTPUT_DIRECTORY}
|
|||||||
FORCE
|
FORCE
|
||||||
)
|
)
|
||||||
|
|
||||||
find_package(Qt6 6.8 REQUIRED COMPONENTS Core Gui Widgets Qml Quick QuickControls2 QuickTimeline ShaderTools Concurrent)
|
find_package(Qt6 6.8 REQUIRED COMPONENTS Core Gui Widgets Qml Quick QuickControls2 QuickTimeline ShaderTools)
|
||||||
qt_standard_project_setup()
|
qt_standard_project_setup()
|
||||||
|
|
||||||
qt_add_executable(${CMAKE_PROJECT_NAME}
|
qt_add_executable(${CMAKE_PROJECT_NAME}
|
||||||
README.md
|
README.md
|
||||||
LICENSE
|
LICENSE
|
||||||
|
images/icons/icons8-video.svg
|
||||||
)
|
)
|
||||||
qt_add_resources(${CMAKE_PROJECT_NAME} "configuration"
|
qt_add_resources(${CMAKE_PROJECT_NAME} "configuration"
|
||||||
PREFIX "/"
|
PREFIX "/"
|
||||||
@@ -58,7 +59,6 @@ qt_add_resources(${CMAKE_PROJECT_NAME} "app_images"
|
|||||||
"images/icons/icons8-user-account.svg"
|
"images/icons/icons8-user-account.svg"
|
||||||
"images/icons/icons8-view-more.svg"
|
"images/icons/icons8-view-more.svg"
|
||||||
"images/icons/icons8-video.svg"
|
"images/icons/icons8-video.svg"
|
||||||
"images/icons/pexels-icon-filled-256.svg"
|
|
||||||
"images/kero/kero_build_1.png"
|
"images/kero/kero_build_1.png"
|
||||||
"images/kero/kero_build_2.png"
|
"images/kero/kero_build_2.png"
|
||||||
"images/kero/kero_build_3.png"
|
"images/kero/kero_build_3.png"
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ qt6_add_qml_module(KomplexHubContent
|
|||||||
"pages/UserProfilePage.qml"
|
"pages/UserProfilePage.qml"
|
||||||
"pages/WallpaperSettingsPage.qml"
|
"pages/WallpaperSettingsPage.qml"
|
||||||
QML_FILES pages/VideoSearchPage.qml
|
QML_FILES pages/VideoSearchPage.qml
|
||||||
QML_FILES views/ImageView.qml
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -317,19 +317,21 @@ Rectangle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KeroBuildingAnimation
|
KeroBuildingAnimation {
|
||||||
{
|
|
||||||
id: buildingOverlay
|
id: buildingOverlay
|
||||||
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
visible: false
|
visible: false
|
||||||
}
|
}
|
||||||
|
|
||||||
KeroLoadingAnimation
|
KeroLoadingAnimation {
|
||||||
{
|
|
||||||
id: loadingAnimation
|
id: loadingAnimation
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
|
// OpacityAnimator on opacity {
|
||||||
|
// duration: 150
|
||||||
|
// }
|
||||||
|
|
||||||
visible: opacity > 0
|
visible: opacity > 0
|
||||||
opacity: 0
|
opacity: 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import QtQuick 2.15
|
import QtQuick
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
import QtQuick.Effects
|
import QtQuick.Effects
|
||||||
@@ -20,54 +20,18 @@ Item {
|
|||||||
{
|
{
|
||||||
id: newestPacksModel
|
id: newestPacksModel
|
||||||
resultsPerPage: homePageRoot.resultsPerRow
|
resultsPerPage: homePageRoot.resultsPerRow
|
||||||
|
|
||||||
onStateChanged: () =>
|
|
||||||
{
|
|
||||||
if(state == NewestPacksModel.Loading)
|
|
||||||
{
|
|
||||||
console.log("Newest packs loading")
|
|
||||||
}
|
|
||||||
else if(state == NewestPacksModel.Idle)
|
|
||||||
{
|
|
||||||
console.log("Newest packs finished")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FeaturedImagesModel
|
FeaturedImagesModel
|
||||||
{
|
{
|
||||||
id: featuredImagesModel
|
id: featuredImagesModel
|
||||||
resultsPerPage: homePageRoot.resultsPerRow
|
resultsPerPage: homePageRoot.resultsPerRow
|
||||||
|
|
||||||
onStateChanged: () =>
|
|
||||||
{
|
|
||||||
if(state == FeaturedImagesModel.Loading)
|
|
||||||
{
|
|
||||||
console.log("Featured Images loading")
|
|
||||||
}
|
|
||||||
else if(state == FeaturedImagesModel.Idle)
|
|
||||||
{
|
|
||||||
console.log("Featured Images finished")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FeaturedVideosModel
|
FeaturedVideosModel
|
||||||
{
|
{
|
||||||
id: featuredVideosModel
|
id: featuredVideosModel
|
||||||
resultsPerPage: homePageRoot.resultsPerRow
|
resultsPerPage: homePageRoot.resultsPerRow
|
||||||
|
|
||||||
onStateChanged: () =>
|
|
||||||
{
|
|
||||||
if(state == FeaturedVideosModel.Loading)
|
|
||||||
{
|
|
||||||
console.log("Featured Videos loading")
|
|
||||||
}
|
|
||||||
else if(state == FeaturedVideosModel.Idle)
|
|
||||||
{
|
|
||||||
console.log("Featured Videos finished")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle
|
Rectangle
|
||||||
@@ -246,11 +210,10 @@ Item {
|
|||||||
{
|
{
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
title: parent.author
|
title: parent.author
|
||||||
|
author: qsTr("Pexels Images")
|
||||||
description: parent.description
|
description: parent.description
|
||||||
thumbnail: parent.thumbnail
|
thumbnail: parent.thumbnail
|
||||||
uuid: parent.uuid
|
uuid: parent.uuid
|
||||||
|
|
||||||
pexels: true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -349,9 +312,10 @@ Item {
|
|||||||
{
|
{
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
title: parent.author
|
title: parent.author
|
||||||
|
author: parent.author
|
||||||
|
description: "Video provided by Pexels"
|
||||||
thumbnail: parent.thumbnail
|
thumbnail: parent.thumbnail
|
||||||
uuid: parent.uuid
|
uuid: parent.uuid
|
||||||
pexels: true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -393,13 +357,6 @@ Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: () =>
|
|
||||||
{
|
|
||||||
featuredImagesModel.nextPage()
|
|
||||||
featuredVideosModel.nextPage()
|
|
||||||
newestPacksModel.nextPage()
|
|
||||||
}
|
|
||||||
|
|
||||||
KeroLoadingAnimation
|
KeroLoadingAnimation
|
||||||
{
|
{
|
||||||
id: loadingAnimation
|
id: loadingAnimation
|
||||||
|
|||||||
@@ -9,43 +9,217 @@ import KomplexHubPlugin
|
|||||||
|
|
||||||
Item
|
Item
|
||||||
{
|
{
|
||||||
id: rootItem
|
|
||||||
|
|
||||||
property string query
|
property string query
|
||||||
readonly property bool searchable: paginator.searchable
|
readonly property bool searchable: true
|
||||||
|
property int resultsPerRow: (resultsContainer.width - (Constants.largeMargin * 2)) / (resultWidth + Constants.mediumMargin)
|
||||||
|
property int rows: ((resultsContainer.height - (Constants.largeMargin * 2)) / (resultHeight + Constants.mediumMargin))
|
||||||
|
property int resultsPerPage: resultsPerRow * rows
|
||||||
|
property int emptyWidth: (resultsContainer.width - (Constants.largeMargin * 2)) - (resultsPerRow * (resultWidth + Constants.mediumMargin))
|
||||||
|
property int resultWidth: 256
|
||||||
|
property int resultHeight: 245
|
||||||
|
|
||||||
|
id: imageSearchPageRoot
|
||||||
|
|
||||||
ImageSearchModel
|
ImageSearchModel
|
||||||
{
|
{
|
||||||
id: searchModel
|
id: searchModel
|
||||||
query: rootItem.query
|
query: imageSearchPageRoot.query
|
||||||
resultsPerPage: paginator.resultsPerPage
|
resultsPerPage: imageSearchPageRoot.resultsPerPage
|
||||||
}
|
}
|
||||||
|
|
||||||
PaginatorGrid
|
Rectangle
|
||||||
{
|
{
|
||||||
id: paginator
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
model: searchModel
|
color: palette.base
|
||||||
loading: model.state === ImageSearchModel.Loading
|
|
||||||
|
|
||||||
delegate: Item
|
Rectangle
|
||||||
{
|
{
|
||||||
width: 256
|
id: resultsContainer
|
||||||
height: 245
|
anchors.top: parent.top
|
||||||
required property string author
|
anchors.left: parent.left
|
||||||
required property string description
|
anchors.right: parent.right
|
||||||
required property string uuid
|
anchors.bottom: buttonBoxLayout.top
|
||||||
required property string thumbnail
|
|
||||||
required property string authorId
|
|
||||||
|
|
||||||
SearchResultItem
|
color: "transparent"
|
||||||
|
|
||||||
|
ScrollView
|
||||||
{
|
{
|
||||||
|
id: resultsView
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
title: parent.author
|
|
||||||
description: parent.description
|
RowLayout
|
||||||
thumbnail: parent.thumbnail
|
{
|
||||||
uuid: parent.uuid
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.bottom: parent.bottom
|
||||||
|
anchors.top: parent.top
|
||||||
|
anchors.margins: Constants.largeMargin
|
||||||
|
|
||||||
|
Item
|
||||||
|
{
|
||||||
|
Layout.fillHeight: true
|
||||||
|
Layout.preferredWidth: emptyWidth / 2
|
||||||
|
Layout.maximumWidth: emptyWidth / 2
|
||||||
|
}
|
||||||
|
|
||||||
|
GridLayout
|
||||||
|
{
|
||||||
|
Layout.fillHeight: true
|
||||||
|
Layout.fillWidth: true
|
||||||
|
|
||||||
|
columns: imageSearchPageRoot.resultsPerRow
|
||||||
|
columnSpacing: Constants.mediumMargin
|
||||||
|
rowSpacing: Constants.mediumMargin
|
||||||
|
|
||||||
|
Repeater
|
||||||
|
{
|
||||||
|
model: searchModel
|
||||||
|
|
||||||
|
delegate: Item
|
||||||
|
{
|
||||||
|
width: 256
|
||||||
|
height: 245
|
||||||
|
required property string author
|
||||||
|
required property string description
|
||||||
|
required property string uuid
|
||||||
|
required property string thumbnail
|
||||||
|
required property string authorId
|
||||||
|
|
||||||
|
SearchResultItem
|
||||||
|
{
|
||||||
|
anchors.fill: parent
|
||||||
|
title: parent.author
|
||||||
|
author: qsTr("Pexels Images")
|
||||||
|
description: parent.description
|
||||||
|
thumbnail: parent.thumbnail
|
||||||
|
uuid: parent.uuid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RowLayout
|
||||||
|
{
|
||||||
|
id: buttonBoxLayout
|
||||||
|
height: 35
|
||||||
|
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.bottom: parent.bottom
|
||||||
|
anchors.margins: Constants.largeMargin
|
||||||
|
|
||||||
|
SquareButton
|
||||||
|
{
|
||||||
|
Layout.fillHeight: true
|
||||||
|
Layout.preferredWidth: 128
|
||||||
|
|
||||||
|
icon.source: "qrc:/images/icons/icons8-back.svg"
|
||||||
|
icon.height: 16
|
||||||
|
icon.width: 16
|
||||||
|
text: qsTr("Previous")
|
||||||
|
enabled: searchModel.hasPreviousPage
|
||||||
|
|
||||||
|
onTriggered: () => searchModel.previousPage()
|
||||||
|
}
|
||||||
|
|
||||||
|
Item { Layout.fillWidth: true }
|
||||||
|
|
||||||
|
SquareButton
|
||||||
|
{
|
||||||
|
Layout.fillHeight: true
|
||||||
|
Layout.preferredWidth: 128
|
||||||
|
|
||||||
|
icon.source: "qrc:/images/icons/icons8-next.svg"
|
||||||
|
icon.height: 16
|
||||||
|
icon.width: 16
|
||||||
|
text: qsTr("Next")
|
||||||
|
enabled: searchModel.hasNextPage
|
||||||
|
|
||||||
|
onTriggered: () => searchModel.nextPage()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KeroErrorAvatar
|
||||||
|
{
|
||||||
|
id: errorOverlay
|
||||||
|
|
||||||
|
anchors.fill: parent
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
KeroNoResultsAvatar
|
||||||
|
{
|
||||||
|
id: noResultsOverlay
|
||||||
|
|
||||||
|
anchors.fill: parent
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
KeroLoadingAnimation
|
||||||
|
{
|
||||||
|
id: loadingOverlay
|
||||||
|
|
||||||
|
anchors.fill: parent
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
states: [
|
||||||
|
State
|
||||||
|
{
|
||||||
|
name: "loading"
|
||||||
|
when: searchModel.state == ImageSearchModel.Loading
|
||||||
|
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: loadingOverlay
|
||||||
|
opacity: 1
|
||||||
|
}
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: resultsView
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
State
|
||||||
|
{
|
||||||
|
name: "empty"
|
||||||
|
when: searchModel.totalResults === 0
|
||||||
|
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: noResultsOverlay
|
||||||
|
opacity: 1
|
||||||
|
}
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: resultsView
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: buttonBoxLayout
|
||||||
|
visible: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
State
|
||||||
|
{
|
||||||
|
name: "error"
|
||||||
|
when: searchModel.state == ImageSearchModel.Error
|
||||||
|
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: errorOverlay
|
||||||
|
opacity: 1
|
||||||
|
}
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: resultsView
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,47 +3,76 @@ import QtQuick.Controls
|
|||||||
import KomplexHub
|
import KomplexHub
|
||||||
import KomplexHub.Controls
|
import KomplexHub.Controls
|
||||||
import KomplexHub.Kero
|
import KomplexHub.Kero
|
||||||
import KomplexHubPlugin
|
|
||||||
|
|
||||||
Item
|
Item {
|
||||||
{
|
id: imageSearchPageRoot
|
||||||
id: rootItem
|
|
||||||
|
|
||||||
property string query
|
SearchResultList {
|
||||||
readonly property bool searchable: paginator.searchable
|
id: searchResultList
|
||||||
|
anchors.fill: parent
|
||||||
VideoSearchModel
|
color: palette.base
|
||||||
{
|
|
||||||
id: searchModel
|
|
||||||
query: rootItem.query
|
|
||||||
resultsPerPage: paginator.resultsPerPage
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PaginatorGrid
|
KeroErrorAvatar {
|
||||||
{
|
id: errorOverlay
|
||||||
id: paginator
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
model: searchModel
|
opacity: 0
|
||||||
loading: model.state === VideoSearchModel.Loading
|
}
|
||||||
|
|
||||||
delegate: Item
|
KeroNoResultsAvatar {
|
||||||
{
|
id: noResultsOverlay
|
||||||
width: 256
|
|
||||||
height: 245
|
|
||||||
required property string author
|
|
||||||
required property string description
|
|
||||||
required property string uuid
|
|
||||||
required property string thumbnail
|
|
||||||
required property string authorId
|
|
||||||
|
|
||||||
SearchResultItem
|
anchors.fill: parent
|
||||||
{
|
opacity: 0
|
||||||
anchors.fill: parent
|
}
|
||||||
title: parent.author
|
|
||||||
description: parent.description
|
KeroLoadingAnimation {
|
||||||
thumbnail: parent.thumbnail
|
id: loadingOverlay
|
||||||
uuid: parent.uuid
|
|
||||||
|
anchors.fill: parent
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
states: [
|
||||||
|
State {
|
||||||
|
name: "loading"
|
||||||
|
when: searchResultList.state === "loading"
|
||||||
|
|
||||||
|
PropertyChanges {
|
||||||
|
target: loadingOverlay
|
||||||
|
opacity: 1
|
||||||
|
}
|
||||||
|
PropertyChanges {
|
||||||
|
target: resultsView
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
State {
|
||||||
|
name: "empty"
|
||||||
|
when: searchResultList.state === "empty"
|
||||||
|
|
||||||
|
PropertyChanges {
|
||||||
|
target: noResultsOverlay
|
||||||
|
opacity: 1
|
||||||
|
}
|
||||||
|
PropertyChanges {
|
||||||
|
target: resultsView
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
State {
|
||||||
|
name: "error"
|
||||||
|
when: searchResultList.state === "error"
|
||||||
|
|
||||||
|
PropertyChanges {
|
||||||
|
target: errorOverlay
|
||||||
|
opacity: 1
|
||||||
|
}
|
||||||
|
PropertyChanges {
|
||||||
|
target: resultsView
|
||||||
|
opacity: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,43 +9,217 @@ import KomplexHubPlugin
|
|||||||
|
|
||||||
Item
|
Item
|
||||||
{
|
{
|
||||||
id: rootItem
|
|
||||||
|
|
||||||
property string query
|
property string query
|
||||||
readonly property bool searchable: paginator.searchable
|
readonly property bool searchable: true
|
||||||
|
property int resultsPerRow: (resultsContainer.width - (Constants.largeMargin * 2)) / (resultWidth + Constants.mediumMargin)
|
||||||
|
property int rows: ((resultsContainer.height - (Constants.largeMargin * 2)) / (resultHeight + Constants.mediumMargin))
|
||||||
|
property int resultsPerPage: resultsPerRow * rows
|
||||||
|
property int emptyWidth: (resultsContainer.width - (Constants.largeMargin * 2)) - (resultsPerRow * (resultWidth + Constants.mediumMargin))
|
||||||
|
property int resultWidth: 256
|
||||||
|
property int resultHeight: 245
|
||||||
|
|
||||||
|
id: videoSearchPageRoot
|
||||||
|
|
||||||
VideoSearchModel
|
VideoSearchModel
|
||||||
{
|
{
|
||||||
id: searchModel
|
id: searchModel
|
||||||
query: rootItem.query
|
query: videoSearchPageRoot.query
|
||||||
resultsPerPage: paginator.resultsPerPage
|
resultsPerPage: videoSearchPageRoot.resultsPerPage
|
||||||
}
|
}
|
||||||
|
|
||||||
PaginatorGrid
|
Rectangle
|
||||||
{
|
{
|
||||||
id: paginator
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
model: searchModel
|
color: palette.base
|
||||||
loading: model.state === VideoSearchModel.Loading
|
|
||||||
|
|
||||||
delegate: Item
|
Rectangle
|
||||||
{
|
{
|
||||||
width: 256
|
id: resultsContainer
|
||||||
height: 245
|
anchors.top: parent.top
|
||||||
required property string author
|
anchors.left: parent.left
|
||||||
required property string description
|
anchors.right: parent.right
|
||||||
required property string uuid
|
anchors.bottom: buttonBoxLayout.top
|
||||||
required property string thumbnail
|
|
||||||
required property string authorId
|
|
||||||
|
|
||||||
SearchResultItem
|
color: "transparent"
|
||||||
|
|
||||||
|
ScrollView
|
||||||
{
|
{
|
||||||
|
id: resultsView
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
title: parent.author
|
|
||||||
description: parent.description
|
RowLayout
|
||||||
thumbnail: parent.thumbnail
|
{
|
||||||
uuid: parent.uuid
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.bottom: parent.bottom
|
||||||
|
anchors.top: parent.top
|
||||||
|
anchors.margins: Constants.largeMargin
|
||||||
|
|
||||||
|
Item
|
||||||
|
{
|
||||||
|
Layout.fillHeight: true
|
||||||
|
Layout.preferredWidth: emptyWidth / 2
|
||||||
|
Layout.maximumWidth: emptyWidth / 2
|
||||||
|
}
|
||||||
|
|
||||||
|
GridLayout
|
||||||
|
{
|
||||||
|
Layout.fillHeight: true
|
||||||
|
Layout.fillWidth: true
|
||||||
|
|
||||||
|
columns: videoSearchPageRoot.resultsPerRow
|
||||||
|
columnSpacing: Constants.mediumMargin
|
||||||
|
rowSpacing: Constants.mediumMargin
|
||||||
|
|
||||||
|
Repeater
|
||||||
|
{
|
||||||
|
model: searchModel
|
||||||
|
|
||||||
|
delegate: Item {
|
||||||
|
width: resultWidth
|
||||||
|
height: resultHeight
|
||||||
|
|
||||||
|
required property string uuid
|
||||||
|
required property string author
|
||||||
|
required property string authorId
|
||||||
|
required property string authorUrl
|
||||||
|
required property string thumbnail
|
||||||
|
|
||||||
|
SearchResultItem
|
||||||
|
{
|
||||||
|
anchors.fill: parent
|
||||||
|
title: parent.author
|
||||||
|
author: parent.author
|
||||||
|
description: "Video provided by Pexels"
|
||||||
|
thumbnail: parent.thumbnail
|
||||||
|
uuid: parent.uuid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RowLayout
|
||||||
|
{
|
||||||
|
id: buttonBoxLayout
|
||||||
|
height: 35
|
||||||
|
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.bottom: parent.bottom
|
||||||
|
anchors.margins: Constants.largeMargin
|
||||||
|
|
||||||
|
SquareButton
|
||||||
|
{
|
||||||
|
Layout.fillHeight: true
|
||||||
|
Layout.preferredWidth: 128
|
||||||
|
|
||||||
|
icon.source: "qrc:/images/icons/icons8-back.svg"
|
||||||
|
icon.height: 16
|
||||||
|
icon.width: 16
|
||||||
|
text: qsTr("Previous")
|
||||||
|
enabled: searchModel.hasPreviousPage
|
||||||
|
|
||||||
|
onTriggered: () => searchModel.previousPage()
|
||||||
|
}
|
||||||
|
|
||||||
|
Item { Layout.fillWidth: true }
|
||||||
|
|
||||||
|
SquareButton
|
||||||
|
{
|
||||||
|
Layout.fillHeight: true
|
||||||
|
Layout.preferredWidth: 128
|
||||||
|
|
||||||
|
icon.source: "qrc:/images/icons/icons8-next.svg"
|
||||||
|
icon.height: 16
|
||||||
|
icon.width: 16
|
||||||
|
text: qsTr("Next")
|
||||||
|
enabled: searchModel.hasNextPage
|
||||||
|
|
||||||
|
onTriggered: () => searchModel.nextPage()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KeroErrorAvatar
|
||||||
|
{
|
||||||
|
id: errorOverlay
|
||||||
|
|
||||||
|
anchors.fill: parent
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
KeroNoResultsAvatar
|
||||||
|
{
|
||||||
|
id: noResultsOverlay
|
||||||
|
|
||||||
|
anchors.fill: parent
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
KeroLoadingAnimation
|
||||||
|
{
|
||||||
|
id: loadingOverlay
|
||||||
|
|
||||||
|
anchors.fill: parent
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
states: [
|
||||||
|
State
|
||||||
|
{
|
||||||
|
name: "loading"
|
||||||
|
when: searchModel.state == VideoSearchModel.Loading
|
||||||
|
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: loadingOverlay
|
||||||
|
opacity: 1
|
||||||
|
}
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: resultsView
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
State
|
||||||
|
{
|
||||||
|
name: "empty"
|
||||||
|
when: searchModel.totalResults === 0
|
||||||
|
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: noResultsOverlay
|
||||||
|
opacity: 1
|
||||||
|
}
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: resultsView
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: buttonBoxLayout
|
||||||
|
visible: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
State
|
||||||
|
{
|
||||||
|
name: "error"
|
||||||
|
when: searchModel.state == VideoSearchModel.Error
|
||||||
|
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: errorOverlay
|
||||||
|
opacity: 1
|
||||||
|
}
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: resultsView
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,98 +0,0 @@
|
|||||||
import QtQuick 2.15
|
|
||||||
import QtQuick.Controls
|
|
||||||
import QtQuick.Layouts
|
|
||||||
import QtQuick.Effects
|
|
||||||
|
|
||||||
import KomplexHub
|
|
||||||
import KomplexHub.Controls
|
|
||||||
import KomplexHub.Kero
|
|
||||||
import KomplexHubPlugin
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
property string uuid
|
|
||||||
property string author
|
|
||||||
property string authorUrl
|
|
||||||
property string description
|
|
||||||
property string thumbnail
|
|
||||||
property string portrait
|
|
||||||
property string landscape
|
|
||||||
property string small
|
|
||||||
property string original
|
|
||||||
property string medium
|
|
||||||
property string large
|
|
||||||
property string extraLarge
|
|
||||||
property string portraitSize
|
|
||||||
property string landscapeSize
|
|
||||||
property string smallSize
|
|
||||||
property string originalSize
|
|
||||||
property string mediumSize
|
|
||||||
property string largeSize
|
|
||||||
property string extraLargeSize
|
|
||||||
|
|
||||||
property int imageHeight
|
|
||||||
property int imageWidth
|
|
||||||
|
|
||||||
id: rootItem
|
|
||||||
|
|
||||||
Rectangle
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
color: palette.base
|
|
||||||
|
|
||||||
ColumnLayout
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
anchors.margins: Constants.largeMargin
|
|
||||||
spacing: Constants.largeMargin
|
|
||||||
|
|
||||||
RowLayout
|
|
||||||
{
|
|
||||||
Layout.fillWidth: true
|
|
||||||
|
|
||||||
/** Spacer **/
|
|
||||||
Item { Layout.fillWidth: true }
|
|
||||||
|
|
||||||
Image
|
|
||||||
{
|
|
||||||
width: imageWidth
|
|
||||||
height: imageHeight
|
|
||||||
transform: Image.PreserveAspectFit
|
|
||||||
source: "qrc:/images/icons/pexels-icon-filled-256.svg"
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Spacer **/
|
|
||||||
Item { Layout.fillWidth: true }
|
|
||||||
}
|
|
||||||
|
|
||||||
Text
|
|
||||||
{
|
|
||||||
id: titleText
|
|
||||||
text: rootItem.author
|
|
||||||
|
|
||||||
font.bold: true
|
|
||||||
font.pixelSize: Constants.h3Font.pixelSize
|
|
||||||
|
|
||||||
Layout.fillWidth: true
|
|
||||||
}
|
|
||||||
|
|
||||||
Text
|
|
||||||
{
|
|
||||||
id: descriptionText
|
|
||||||
text: rootItem.description
|
|
||||||
|
|
||||||
font.pointSize: Constants.h4Font.pixelSize
|
|
||||||
}
|
|
||||||
|
|
||||||
Image
|
|
||||||
{
|
|
||||||
width: 64
|
|
||||||
height: 64
|
|
||||||
transform: Image.PreserveAspectFit
|
|
||||||
source: "qrc:/images/icons/pexels-icon-filled-256.svg"
|
|
||||||
|
|
||||||
Layout.alignment: Qt.AlignBottom | Qt.AlignRight
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -14,7 +14,5 @@ qt6_add_qml_module(KomplexHubModule_Controls
|
|||||||
"Throbber.qml"
|
"Throbber.qml"
|
||||||
"SearchResultItem.qml"
|
"SearchResultItem.qml"
|
||||||
"SearchResultList.qml"
|
"SearchResultList.qml"
|
||||||
QML_FILES PaginationBox.qml
|
|
||||||
QML_FILES PaginatorGrid.qml
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
import QtQuick
|
|
||||||
import QtQuick.Layouts
|
|
||||||
import QtQuick.Controls
|
|
||||||
|
|
||||||
import KomplexHub
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
id: itemRoot
|
|
||||||
|
|
||||||
property int page: 0
|
|
||||||
property int totalPages: 0
|
|
||||||
|
|
||||||
property bool enablePrevious: false
|
|
||||||
property bool enableNext: false
|
|
||||||
|
|
||||||
signal next
|
|
||||||
signal previous
|
|
||||||
|
|
||||||
RowLayout
|
|
||||||
{
|
|
||||||
id: buttonBoxLayout
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
SquareButton
|
|
||||||
{
|
|
||||||
Layout.fillHeight: true
|
|
||||||
Layout.preferredWidth: 128
|
|
||||||
|
|
||||||
icon.source: "qrc:/images/icons/icons8-back.svg"
|
|
||||||
icon.height: 16
|
|
||||||
icon.width: 16
|
|
||||||
text: qsTr("Previous")
|
|
||||||
enabled: itemRoot.enablePrevious
|
|
||||||
|
|
||||||
onTriggered: () => itemRoot.previous()
|
|
||||||
}
|
|
||||||
|
|
||||||
Item { Layout.fillWidth: true }
|
|
||||||
|
|
||||||
SquareButton
|
|
||||||
{
|
|
||||||
Layout.fillHeight: true
|
|
||||||
Layout.preferredWidth: 128
|
|
||||||
|
|
||||||
icon.source: "qrc:/images/icons/icons8-next.svg"
|
|
||||||
icon.height: 16
|
|
||||||
icon.width: 16
|
|
||||||
text: qsTr("Next")
|
|
||||||
enabled: itemRoot.enableNext
|
|
||||||
|
|
||||||
onTriggered: () => itemRoot.next()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,384 +0,0 @@
|
|||||||
import QtQuick
|
|
||||||
import QtQuick.Controls
|
|
||||||
import QtQuick.Layouts
|
|
||||||
|
|
||||||
import KomplexHub
|
|
||||||
import KomplexHub.Controls
|
|
||||||
import KomplexHub.Kero
|
|
||||||
import KomplexHubPlugin
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
property string query
|
|
||||||
readonly property bool searchable: true
|
|
||||||
property int resultsPerRow: (resultsContainer.width - (Constants.largeMargin * 2)) / (resultWidth + Constants.mediumMargin)
|
|
||||||
property int rows: ((resultsContainer.height - (Constants.largeMargin * 2)) / (resultHeight + Constants.mediumMargin))
|
|
||||||
property int resultsPerPage: resultsPerRow * rows
|
|
||||||
property int emptyWidth: (resultsContainer.width - (Constants.largeMargin * 2)) - (resultsPerRow * (resultWidth + Constants.mediumMargin))
|
|
||||||
property int resultWidth: 256
|
|
||||||
property int resultHeight: 245
|
|
||||||
property bool loading: false
|
|
||||||
|
|
||||||
property var model
|
|
||||||
|
|
||||||
property Component delegate
|
|
||||||
|
|
||||||
id: rootItem
|
|
||||||
|
|
||||||
KeroErrorAvatar
|
|
||||||
{
|
|
||||||
id: errorOverlay
|
|
||||||
|
|
||||||
anchors.fill: parent
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
KeroNoResultsAvatar
|
|
||||||
{
|
|
||||||
id: noResultsOverlay
|
|
||||||
|
|
||||||
anchors.fill: parent
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
KeroChoiceAvatar
|
|
||||||
{
|
|
||||||
id: noSearchOverlay
|
|
||||||
|
|
||||||
title: qsTr("No Search Term")
|
|
||||||
description: qsTr("Kero needs a subject or term to search for wallpapers")
|
|
||||||
|
|
||||||
anchors.fill: parent
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
KeroLoadingAnimation
|
|
||||||
{
|
|
||||||
id: loadingOverlay
|
|
||||||
|
|
||||||
anchors.fill: parent
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
Rectangle
|
|
||||||
{
|
|
||||||
id: resultsContainer
|
|
||||||
anchors.fill: parent
|
|
||||||
color: palette.base
|
|
||||||
|
|
||||||
RowLayout
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
anchors.margins: Constants.largeMargin
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
Layout.fillHeight: true
|
|
||||||
Layout.preferredWidth: emptyWidth / 2
|
|
||||||
Layout.maximumWidth: emptyWidth / 2
|
|
||||||
}
|
|
||||||
|
|
||||||
GridView
|
|
||||||
{
|
|
||||||
id: resultsView
|
|
||||||
Layout.fillHeight: true
|
|
||||||
Layout.fillWidth: true
|
|
||||||
|
|
||||||
cellWidth: 256 + Constants.mediumMargin
|
|
||||||
cellHeight: 245 + Constants.mediumMargin
|
|
||||||
focus: true
|
|
||||||
model: rootItem.model
|
|
||||||
|
|
||||||
delegate: rootItem.delegate
|
|
||||||
|
|
||||||
add: Transition
|
|
||||||
{
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
properties: "x"
|
|
||||||
from: resultsContainer.width
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
properties: "opacity,scale"
|
|
||||||
to: 1.0
|
|
||||||
duration: 500
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
move: Transition
|
|
||||||
{
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
properties: "x,y"
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
populate: Transition
|
|
||||||
{
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
properties: "opacity,scale"
|
|
||||||
to: 1.0
|
|
||||||
duration: 500
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
remove: Transition
|
|
||||||
{
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
properties: "x"
|
|
||||||
to: 0
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
properties: "opacity"
|
|
||||||
to: 0
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PaginationBox
|
|
||||||
{
|
|
||||||
height: 35
|
|
||||||
|
|
||||||
anchors.left: parent.left
|
|
||||||
anchors.right: parent.right
|
|
||||||
anchors.bottom: parent.bottom
|
|
||||||
anchors.margins: Constants.largeMargin
|
|
||||||
|
|
||||||
onNext: () => model.nextPage()
|
|
||||||
onPrevious: () => model.previousPage()
|
|
||||||
|
|
||||||
enablePrevious: model.hasPreviousPage
|
|
||||||
enableNext: model.hasNextPage
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
states: [
|
|
||||||
State
|
|
||||||
{
|
|
||||||
name: "loading"
|
|
||||||
when: loading
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: loadingOverlay
|
|
||||||
opacity: 1
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: resultsContainer
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: noSearchOverlay
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: errorOverlay
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: buttonBoxLayout
|
|
||||||
visible: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
State
|
|
||||||
{
|
|
||||||
name: "empty"
|
|
||||||
when: model.totalResults === 0 && model.query.length > 0
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: noResultsOverlay
|
|
||||||
opacity: 1
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: noSearchOverlay
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: resultsContainer
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: buttonBoxLayout
|
|
||||||
visible: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
State
|
|
||||||
{
|
|
||||||
name: "nosearch"
|
|
||||||
when: model.query.length === 0
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: noResultsOverlay
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: noSearchOverlay
|
|
||||||
opacity: 1
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: resultsContainer
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: buttonBoxLayout
|
|
||||||
visible: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
State
|
|
||||||
{
|
|
||||||
name: "idle"
|
|
||||||
when: model.totalResults !== 0 && !loading
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: loadingOverlay
|
|
||||||
opacity: 0.0
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: resultsContainer
|
|
||||||
opacity: 1.0
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: buttonBoxLayout
|
|
||||||
visible: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
State
|
|
||||||
{
|
|
||||||
name: "error"
|
|
||||||
when: model.errorString.length > 0
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: errorOverlay
|
|
||||||
opacity: 1.0
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: resultsContainer
|
|
||||||
opacity: 0.0
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: noSearchOverlay
|
|
||||||
opacity: 0.0
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: noResultsOverlay
|
|
||||||
opacity: 0.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
transitions: [
|
|
||||||
Transition
|
|
||||||
{
|
|
||||||
from: "empty"
|
|
||||||
to: "loading"
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
target: noResultsOverlay
|
|
||||||
duration: 250
|
|
||||||
property: "opacity";
|
|
||||||
}
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
target: loadingOverlay
|
|
||||||
duration: 250
|
|
||||||
property: "opacity";
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Transition
|
|
||||||
{
|
|
||||||
from: "nosearch"
|
|
||||||
to: "loading"
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
target: noSearchOverlay
|
|
||||||
duration: 250
|
|
||||||
property: "opacity";
|
|
||||||
}
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
target: loadingOverlay
|
|
||||||
duration: 250
|
|
||||||
property: "opacity";
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Transition
|
|
||||||
{
|
|
||||||
from: "loading"
|
|
||||||
to: "nosearch"
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
target: noSearchOverlay
|
|
||||||
duration: 250
|
|
||||||
property: "opacity";
|
|
||||||
}
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
target: loadingOverlay
|
|
||||||
duration: 250
|
|
||||||
property: "opacity";
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Transition
|
|
||||||
{
|
|
||||||
from: "loading"
|
|
||||||
to: "empty"
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
target: noResultsOverlay
|
|
||||||
duration: 250
|
|
||||||
property: "opacity";
|
|
||||||
}
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
target: loadingOverlay
|
|
||||||
duration: 250
|
|
||||||
property: "opacity";
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Transition
|
|
||||||
{
|
|
||||||
from: "loading"
|
|
||||||
to: "idle"
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
target: loadingOverlay
|
|
||||||
duration: 250
|
|
||||||
property: "opacity";
|
|
||||||
}
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
target: resultsView
|
|
||||||
duration: 250
|
|
||||||
property: "opacity";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -2,16 +2,13 @@ import QtQuick
|
|||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
|
|
||||||
import KomplexHub
|
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
property string author: ""
|
property string author: "Author"
|
||||||
property string description: ""
|
property string description: "This is a description of the search result item"
|
||||||
property string title: ""
|
property string title: "Wallpaper Title"
|
||||||
property string thumbnail: ""
|
property string thumbnail: ""
|
||||||
property string uuid: ""
|
property string uuid: ""
|
||||||
property bool selected: false
|
property bool selected: false
|
||||||
property bool pexels: false
|
|
||||||
|
|
||||||
signal triggered
|
signal triggered
|
||||||
|
|
||||||
@@ -51,22 +48,6 @@ Item {
|
|||||||
id: thumnailImage
|
id: thumnailImage
|
||||||
source: searchResultItemRoot.thumbnail
|
source: searchResultItemRoot.thumbnail
|
||||||
}
|
}
|
||||||
|
|
||||||
Image
|
|
||||||
{
|
|
||||||
antialiasing: true
|
|
||||||
anchors.right: parent.right
|
|
||||||
anchors.bottom: parent.bottom
|
|
||||||
anchors.margins: Constants.mediumMargin
|
|
||||||
|
|
||||||
width: 24
|
|
||||||
height: 24
|
|
||||||
transform: Image.PreserveAspectFit
|
|
||||||
opacity: 0.5
|
|
||||||
source: "qrc:/images/icons/pexels-icon-filled-256.svg"
|
|
||||||
|
|
||||||
visible: searchResultItemRoot.pexels
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
@@ -81,8 +62,6 @@ Item {
|
|||||||
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
|
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
|
||||||
}
|
}
|
||||||
|
|
||||||
Item { Layout.fillHeight: true }
|
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
color: palette.text
|
color: palette.text
|
||||||
font.pixelSize: 12
|
font.pixelSize: 12
|
||||||
@@ -91,7 +70,6 @@ Item {
|
|||||||
|
|
||||||
Layout.alignment: Qt.AlignLeft | Qt.AlignBottom
|
Layout.alignment: Qt.AlignLeft | Qt.AlignBottom
|
||||||
Layout.preferredWidth: 250
|
Layout.preferredWidth: 250
|
||||||
visible: !searchResultItemRoot.pexels
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
@@ -110,8 +88,6 @@ Item {
|
|||||||
Layout.maximumWidth: 236
|
Layout.maximumWidth: 236
|
||||||
Layout.bottomMargin: 3
|
Layout.bottomMargin: 3
|
||||||
}
|
}
|
||||||
|
|
||||||
Item { Layout.fillHeight: true }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Behavior on color {
|
Behavior on color {
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ qt_add_qml_module(
|
|||||||
newestpacksmodel.cpp
|
newestpacksmodel.cpp
|
||||||
common/komplex_global.h
|
common/komplex_global.h
|
||||||
common/slidingcachecontroller.h
|
common/slidingcachecontroller.h
|
||||||
|
|
||||||
common/paginator.h
|
common/paginator.h
|
||||||
|
|
||||||
common/coreservices.h
|
common/coreservices.h
|
||||||
common/coreservices.cpp
|
common/coreservices.cpp
|
||||||
common/logging.h
|
common/logging.h
|
||||||
@@ -28,7 +30,7 @@ qt_add_qml_module(
|
|||||||
SOURCES paginators/featuredpackspaginator.h
|
SOURCES paginators/featuredpackspaginator.h
|
||||||
SOURCES paginators/featuredimagespaginator.h
|
SOURCES paginators/featuredimagespaginator.h
|
||||||
SOURCES paginators/wallpaperpaginator.h
|
SOURCES paginators/wallpaperpaginator.h
|
||||||
SOURCES paginators/packsearchpaginator.h
|
SOURCES paginators/searchpackspaginator.h
|
||||||
SOURCES paginators/imagesearchpaginator.h
|
SOURCES paginators/imagesearchpaginator.h
|
||||||
SOURCES paginators/newestshaderspaginator.h
|
SOURCES paginators/newestshaderspaginator.h
|
||||||
SOURCES paginators/newestcubemapspaginator.h
|
SOURCES paginators/newestcubemapspaginator.h
|
||||||
@@ -52,10 +54,6 @@ qt_add_qml_module(
|
|||||||
SOURCES imagesearchmodel.h
|
SOURCES imagesearchmodel.h
|
||||||
SOURCES videosearchmodel.h
|
SOURCES videosearchmodel.h
|
||||||
SOURCES videosearchmodel.cpp
|
SOURCES videosearchmodel.cpp
|
||||||
SOURCES
|
|
||||||
SOURCES
|
|
||||||
SOURCES packsearchmodel.cpp
|
|
||||||
SOURCES packsearchmodel.h
|
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ struct KOMPLEX_EXPORT ImageCache
|
|||||||
QString photographerUrl;
|
QString photographerUrl;
|
||||||
qint64 photographerId;
|
qint64 photographerId;
|
||||||
QMap<QString, QString> sources;
|
QMap<QString, QString> sources;
|
||||||
QMap<QString, QString> sourceSizes;
|
|
||||||
QString url;
|
QString url;
|
||||||
|
|
||||||
auto operator == (const ImageCache &other) const -> bool
|
auto operator == (const ImageCache &other) const -> bool
|
||||||
@@ -34,7 +33,6 @@ struct KOMPLEX_EXPORT ImageCache
|
|||||||
other.photographerUrl == photographerUrl &&
|
other.photographerUrl == photographerUrl &&
|
||||||
other.photographerId == photographerId &&
|
other.photographerId == photographerId &&
|
||||||
other.sources == sources &&
|
other.sources == sources &&
|
||||||
other.sourceSizes == sourceSizes &&
|
|
||||||
other.url == url
|
other.url == url
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,8 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef KOMPLEX_GLOBAL_H
|
#ifndef KOMPLEX_GLOBAL_H
|
||||||
#define KOMPLEX_GLOBAL_H
|
#define KOMPLEX_GLOBAL_H
|
||||||
#include <QtTypes>
|
|
||||||
#include <chrono>
|
|
||||||
|
|
||||||
#ifdef KOMPLEX_PLUGIN
|
#ifdef KOMPLEX_PLUGIN
|
||||||
#define KOMPLEX_EXPORT Q_DECL_EXPORT
|
#define KOMPLEX_EXPORT Q_DECL_EXPORT
|
||||||
@@ -63,7 +61,4 @@
|
|||||||
#define KOMPLEX_ENDPOINT_PACKS_ITEM "packs/item"
|
#define KOMPLEX_ENDPOINT_PACKS_ITEM "packs/item"
|
||||||
#define KOMPLEX_ENDPOINT_PACKS_NEWEST "packs/newest"
|
#define KOMPLEX_ENDPOINT_PACKS_NEWEST "packs/newest"
|
||||||
|
|
||||||
inline static qsizetype nullsize = std::numeric_limits<qsizetype>::min();
|
|
||||||
inline static std::chrono::milliseconds KOMPLEX_RATE_LIMIT(500);
|
|
||||||
|
|
||||||
#endif // KOMPLEX_GLOBAL_H
|
#endif // KOMPLEX_GLOBAL_H
|
||||||
|
|||||||
@@ -39,14 +39,12 @@ class KOMPLEX_EXPORT PaginationNotifier : public QObject
|
|||||||
protected:
|
protected:
|
||||||
explicit PaginationNotifier(QObject *parent = nullptr) : QObject(parent) {}
|
explicit PaginationNotifier(QObject *parent = nullptr) : QObject(parent) {}
|
||||||
signals:
|
signals:
|
||||||
auto fetchComplete() -> void;
|
auto dataChanged() -> void;
|
||||||
auto fetching() -> void;
|
|
||||||
auto resultsPerPageChanged() -> void;
|
auto resultsPerPageChanged() -> void;
|
||||||
auto totalResultsChanged() -> void;
|
auto totalResultsChanged() -> void;
|
||||||
auto totalPagesChanged() -> void;
|
auto totalPagesChanged() -> void;
|
||||||
auto pageChanged() -> void;
|
auto pageChanged() -> void;
|
||||||
auto countChanged() -> void;
|
auto countChanged() -> void;
|
||||||
auto queryChanged() -> void;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -59,21 +57,7 @@ class KOMPLEX_EXPORT Paginator : public PaginationNotifier
|
|||||||
public:
|
public:
|
||||||
explicit Paginator(QObject *parent = nullptr) : PaginationNotifier(parent)
|
explicit Paginator(QObject *parent = nullptr) : PaginationNotifier(parent)
|
||||||
{
|
{
|
||||||
QObject::connect
|
|
||||||
(
|
|
||||||
&m_cacheController,
|
|
||||||
&SlidingCacheNotifier::fetchComplete,
|
|
||||||
this,
|
|
||||||
&PaginationNotifier::fetchComplete
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect
|
|
||||||
(
|
|
||||||
&m_cacheController,
|
|
||||||
&SlidingCacheNotifier::fetching,
|
|
||||||
this,
|
|
||||||
&PaginationNotifier::fetching
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,15 +67,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
auto next() -> void
|
auto next() -> void
|
||||||
{
|
{
|
||||||
if(m_offset != nullsize)
|
setOffset(m_offset + m_resultsPerPage);
|
||||||
{
|
|
||||||
setOffset(m_offset + m_resultsPerPage);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
controller()->init();
|
|
||||||
setOffset(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -101,15 +77,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
auto previous() -> void
|
auto previous() -> void
|
||||||
{
|
{
|
||||||
if(m_offset != nullsize && m_offset > m_resultsPerPage)
|
setOffset(m_offset - m_resultsPerPage);
|
||||||
{
|
|
||||||
setOffset(m_offset - m_resultsPerPage);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
controller()->init();
|
|
||||||
setOffset(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -127,6 +95,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
auto setResultsPerPage(qsizetype resultsPerPage) -> void
|
auto setResultsPerPage(qsizetype resultsPerPage) -> void
|
||||||
{
|
{
|
||||||
|
QMutexLocker dataLocker(&m_dataMutex);
|
||||||
|
|
||||||
if(resultsPerPage == m_resultsPerPage)
|
if(resultsPerPage == m_resultsPerPage)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -134,53 +104,18 @@ public:
|
|||||||
|
|
||||||
m_resultsPerPage = resultsPerPage;
|
m_resultsPerPage = resultsPerPage;
|
||||||
Q_EMIT static_cast<PaginationNotifier*>(this)->resultsPerPageChanged();
|
Q_EMIT static_cast<PaginationNotifier*>(this)->resultsPerPageChanged();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
m_data = m_cacheController.chunk(m_offset, m_resultsPerPage);
|
||||||
* @brief query
|
Q_EMIT static_cast<PaginationNotifier*>(this)->dataChanged();
|
||||||
* Current query string, if the API Endpoint supports queries
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
[[nodiscard]]
|
|
||||||
auto query() const -> QString
|
|
||||||
{
|
|
||||||
return m_query;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief setQuery
|
|
||||||
* Sets the new query string and updates the controller
|
|
||||||
* @param query
|
|
||||||
*/
|
|
||||||
auto setQuery(const QString &query) -> void
|
|
||||||
{
|
|
||||||
if(query == m_query)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
reset();
|
|
||||||
|
|
||||||
m_query = query;
|
|
||||||
Q_EMIT queryChanged();
|
|
||||||
|
|
||||||
controller()->init();
|
|
||||||
setOffset(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief data
|
* @brief data
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
auto data() const -> const QList<T>
|
auto data() const -> QList<T>
|
||||||
{
|
{
|
||||||
if(boundaryCheck(m_resultsPerPage))
|
return m_data;
|
||||||
{
|
|
||||||
return m_cacheController.chunk(m_offset, m_resultsPerPage);
|
|
||||||
}
|
|
||||||
|
|
||||||
qsizetype count = (m_cacheController.totalCount() - m_offset);
|
|
||||||
return m_cacheController.chunk(m_offset, count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -189,18 +124,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
auto count() const -> qsizetype
|
auto count() const -> qsizetype
|
||||||
{
|
{
|
||||||
if(m_offset == nullsize)
|
return m_data.count();
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(boundaryCheck(m_resultsPerPage))
|
|
||||||
{
|
|
||||||
return m_resultsPerPage;
|
|
||||||
}
|
|
||||||
|
|
||||||
qsizetype count = (m_cacheController.totalCount() - m_offset);
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -208,9 +132,16 @@ public:
|
|||||||
* @param index
|
* @param index
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
auto at(qsizetype index) const -> const T&
|
auto at(qsizetype index) const -> T
|
||||||
{
|
{
|
||||||
return m_cacheController.at(m_offset + index);
|
QMutexLocker dataLocker(&m_dataMutex);
|
||||||
|
|
||||||
|
if(index < 0 || index >= m_data.count())
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_data.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -250,16 +181,6 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
auto queryable() const -> bool
|
|
||||||
{
|
|
||||||
return m_queryable;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto setQueryable(bool queryable) -> void
|
|
||||||
{
|
|
||||||
m_queryable = queryable;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief controller
|
* @brief controller
|
||||||
* Reference to the underlying cache controller
|
* Reference to the underlying cache controller
|
||||||
@@ -277,11 +198,16 @@ protected:
|
|||||||
*/
|
*/
|
||||||
auto setOffset(qsizetype offset) -> void
|
auto setOffset(qsizetype offset) -> void
|
||||||
{
|
{
|
||||||
if(offset == m_offset)
|
if(offset == m_offset && offset != std::numeric_limits<qsizetype>::infinity())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(offset == std::numeric_limits<qsizetype>::infinity())
|
||||||
|
{
|
||||||
|
offset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
m_offset = offset;
|
m_offset = offset;
|
||||||
|
|
||||||
if(m_offset >= totalResults())
|
if(m_offset >= totalResults())
|
||||||
@@ -294,11 +220,26 @@ protected:
|
|||||||
m_offset = 0;
|
m_offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_cacheController.focus(offset, m_resultsPerPage);
|
QList<T> data = m_cacheController.chunk(m_offset, m_resultsPerPage);
|
||||||
|
setData(data);
|
||||||
|
|
||||||
Q_EMIT totalResultsChanged();
|
Q_EMIT this->pageChanged();
|
||||||
Q_EMIT totalPagesChanged();
|
}
|
||||||
Q_EMIT pageChanged();
|
|
||||||
|
/**
|
||||||
|
* @brief setData
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
auto setData(const QList<T> &data)
|
||||||
|
{
|
||||||
|
m_dataMutex.lock();
|
||||||
|
|
||||||
|
m_data.clear();
|
||||||
|
m_data.append(std::move(data));
|
||||||
|
m_dataMutex.unlock();
|
||||||
|
|
||||||
|
Q_EMIT this->countChanged();
|
||||||
|
Q_EMIT this->dataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -316,34 +257,26 @@ protected:
|
|||||||
*/
|
*/
|
||||||
auto reset() -> void
|
auto reset() -> void
|
||||||
{
|
{
|
||||||
m_query.clear();
|
m_dataMutex.lock();
|
||||||
m_offset = nullsize;
|
|
||||||
|
m_data.clear();
|
||||||
controller()->reset();
|
controller()->reset();
|
||||||
|
m_dataMutex.unlock();
|
||||||
|
|
||||||
|
Q_EMIT totalPagesChanged();
|
||||||
|
Q_EMIT dataChanged();
|
||||||
|
Q_EMIT pageChanged();
|
||||||
|
|
||||||
|
setOffset(std::numeric_limits<qsizetype>::infinity());
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief boundaryCheck
|
|
||||||
* Checks if the index is within the bounds of the dataset
|
|
||||||
* @param index
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto boundaryCheck(qsizetype index) const -> bool
|
|
||||||
{
|
|
||||||
if(index < 0 || (m_offset + index) >= m_cacheController.totalCount())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief m_offset
|
* @brief m_offset
|
||||||
* Current absolute offset. Used in fetch operations
|
* Current absolute offset. Used in fetch operations
|
||||||
*/
|
*/
|
||||||
mutable qsizetype m_offset = nullsize;
|
qsizetype m_offset = std::numeric_limits<qsizetype>::infinity();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief m_resultsPerPage
|
* @brief m_resultsPerPage
|
||||||
@@ -361,22 +294,16 @@ private:
|
|||||||
*/
|
*/
|
||||||
SlidingCacheController<T> m_cacheController;
|
SlidingCacheController<T> m_cacheController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief m_data
|
||||||
|
* Internal data copy
|
||||||
|
*/
|
||||||
|
QList<T> m_data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief m_dataMutex
|
* @brief m_dataMutex
|
||||||
*/
|
*/
|
||||||
mutable QMutex m_dataMutex;
|
mutable QMutex m_dataMutex;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief m_query
|
|
||||||
* The query string used in fetch operations
|
|
||||||
*/
|
|
||||||
QString m_query;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief m_queryable
|
|
||||||
* Controls the queryable state of the paginator
|
|
||||||
*/
|
|
||||||
bool m_queryable = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PAGINATOR_H
|
#endif // PAGINATOR_H
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
#include <QThread>
|
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include "fetchresult.h"
|
#include "fetchresult.h"
|
||||||
@@ -41,9 +40,6 @@ class KOMPLEX_EXPORT SlidingCacheNotifier : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
signals:
|
signals:
|
||||||
auto countChanged() -> void;
|
auto countChanged() -> void;
|
||||||
auto fetching() -> void;
|
|
||||||
auto fetchComplete() -> void;
|
|
||||||
auto windowSizeChanged() -> void;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,12 +50,6 @@ signals:
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
class KOMPLEX_EXPORT SlidingCacheController : public SlidingCacheNotifier
|
class KOMPLEX_EXPORT SlidingCacheController : public SlidingCacheNotifier
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @brief FetchFunction
|
|
||||||
* Convenience def used by setFetch
|
|
||||||
*/
|
|
||||||
typedef std::function<FetchResult<T> (qsizetype offset, qsizetype limit)> FetchFunction;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
explicit SlidingCacheController() : SlidingCacheNotifier{}
|
explicit SlidingCacheController() : SlidingCacheNotifier{}
|
||||||
@@ -80,7 +70,9 @@ public:
|
|||||||
* QObject
|
* QObject
|
||||||
* @param fetch
|
* @param fetch
|
||||||
*/
|
*/
|
||||||
auto setFetch(const FetchFunction &fetch) -> void
|
auto setFetch(
|
||||||
|
const std::function<FetchResult<T> (qsizetype offset, qsizetype limit)> &fetch
|
||||||
|
) -> void
|
||||||
{
|
{
|
||||||
m_fetch = std::move(fetch);
|
m_fetch = std::move(fetch);
|
||||||
}
|
}
|
||||||
@@ -93,26 +85,25 @@ public:
|
|||||||
* @return CacheObject* or nullptr
|
* @return CacheObject* or nullptr
|
||||||
*/
|
*/
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
auto at(qsizetype index) const -> const T&
|
auto at(qsizetype index) const -> T
|
||||||
{
|
{
|
||||||
QMutexLocker cacheLocker(&m_cacheMutex);
|
QMutexLocker cacheLocker(&m_cacheMutex);
|
||||||
T defaultValue;
|
|
||||||
|
|
||||||
if(!externalBoundaryCheck(index))
|
if(!externalBoundaryCheck(index))
|
||||||
{
|
{
|
||||||
return defaultValue;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!const_cast<SlidingCacheController*>(this)->slideWindow(index))
|
if(!const_cast<SlidingCacheController*>(this)->slideWindow(index))
|
||||||
{
|
{
|
||||||
return defaultValue;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
qsizetype internalIndex = this->internalIndex(index);
|
qsizetype internalIndex = this->internalIndex(index);
|
||||||
|
|
||||||
if(!internalBoundaryCheck(index))
|
if(!internalBoundaryCheck(index))
|
||||||
{
|
{
|
||||||
return defaultValue;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_cache.at(index);
|
return m_cache.at(index);
|
||||||
@@ -153,7 +144,19 @@ public:
|
|||||||
count = m_cache.count() - index;
|
count = m_cache.count() - index;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_cache.mid(index, count);
|
QList<T> dataChunk;
|
||||||
|
|
||||||
|
for(qsizetype i = index; (i - index) < count; ++i)
|
||||||
|
{
|
||||||
|
T data = m_cache.at(i);
|
||||||
|
|
||||||
|
if(data != T{})
|
||||||
|
{
|
||||||
|
dataChunk.append(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dataChunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -164,7 +167,7 @@ public:
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
auto totalCount() const -> qsizetype
|
auto totalCount() const -> qsizetype
|
||||||
{
|
{
|
||||||
if(m_totalCount == nullsize)
|
if(m_totalCount == std::numeric_limits<qsizetype>::infinity())
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -192,53 +195,10 @@ public:
|
|||||||
QMutexLocker cacheLocker(&m_cacheMutex);
|
QMutexLocker cacheLocker(&m_cacheMutex);
|
||||||
|
|
||||||
m_cache.clear();
|
m_cache.clear();
|
||||||
setTotalCount(nullsize);
|
setTotalCount(std::numeric_limits<qsizetype>::infinity());
|
||||||
m_windowOffset = 0;
|
m_windowOffset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto focus(qsizetype index, qsizetype count) -> void
|
|
||||||
{
|
|
||||||
if(inFocus(index, count) || !externalBoundaryCheck(index))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!externalBoundaryCheck(index + count))
|
|
||||||
{
|
|
||||||
slideWindow(index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto init() -> bool
|
|
||||||
{
|
|
||||||
if(m_totalCount != nullsize)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return slideForward();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto windowSize() const -> qsizetype
|
|
||||||
{
|
|
||||||
if(m_windowSize == nullsize)
|
|
||||||
{
|
|
||||||
return SLIDING_CACHE_WINDOW_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_windowSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto setWindowSize(qsizetype windowSize) -> void
|
|
||||||
{
|
|
||||||
if(windowSize == m_windowSize)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* @brief setTotalCount
|
* @brief setTotalCount
|
||||||
@@ -255,16 +215,6 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
auto inFocus(qsizetype index, qsizetype count) -> bool
|
|
||||||
{
|
|
||||||
qsizetype internalIndex = this->internalIndex(index);
|
|
||||||
|
|
||||||
return
|
|
||||||
(
|
|
||||||
internalBoundaryCheck(internalIndex, internalIndex + count)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief externalBoundaryCheck
|
* @brief externalBoundaryCheck
|
||||||
*
|
*
|
||||||
@@ -274,29 +224,12 @@ private:
|
|||||||
* @return True if index is within the external dataset boundary
|
* @return True if index is within the external dataset boundary
|
||||||
* OR an initial fetch has not been performed.
|
* OR an initial fetch has not been performed.
|
||||||
*/
|
*/
|
||||||
template<typename... Ts>
|
auto externalBoundaryCheck(qsizetype index) const -> bool
|
||||||
auto externalBoundaryCheck(Ts... index) const -> bool
|
|
||||||
{
|
{
|
||||||
static_assert
|
return (
|
||||||
(
|
|
||||||
(std::is_same_v<Ts, qsizetype> && ...),
|
|
||||||
"All arguments must be qsizetype"
|
|
||||||
);
|
|
||||||
|
|
||||||
bool safe = false;
|
|
||||||
|
|
||||||
((safe = externalBoundaryCheckHelper(index)),...);
|
|
||||||
|
|
||||||
return safe;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto externalBoundaryCheckHelper(qsizetype index) const -> bool
|
|
||||||
{
|
|
||||||
return
|
|
||||||
(
|
|
||||||
index >= 0 &&
|
index >= 0 &&
|
||||||
(
|
(
|
||||||
m_totalCount == nullsize ||
|
m_totalCount == std::numeric_limits<qsizetype>::infinity() ||
|
||||||
index < m_totalCount
|
index < m_totalCount
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -309,18 +242,12 @@ private:
|
|||||||
* @param index
|
* @param index
|
||||||
* @return True if index is within the internal dataset boundary
|
* @return True if index is within the internal dataset boundary
|
||||||
*/
|
*/
|
||||||
template<typename... Ts>
|
auto internalBoundaryCheck(qsizetype index) const -> bool
|
||||||
auto internalBoundaryCheck(Ts... index) const -> bool
|
|
||||||
{
|
{
|
||||||
static_assert
|
return (
|
||||||
(
|
index >= 0 &&
|
||||||
(std::is_same_v<Ts, qsizetype> && ...),
|
index < m_cache.count()
|
||||||
"All arguments must be qsizetype"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
bool safe = false;
|
|
||||||
((safe = index >= 0 && index < m_cache.count()), ...);
|
|
||||||
return safe;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -353,6 +280,14 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(m_totalCount == std::numeric_limits<qsizetype>::infinity())
|
||||||
|
{
|
||||||
|
if(!slideForward())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,41 +299,20 @@ private:
|
|||||||
auto slideForward() -> bool
|
auto slideForward() -> bool
|
||||||
{
|
{
|
||||||
LOG_ERROR_X(!m_fetch,
|
LOG_ERROR_X(!m_fetch,
|
||||||
"SlidingCacheController::slideForward",
|
"SlidingCacheController::slideBackward",
|
||||||
"Fetch function not set",
|
"Fetch function not set",
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
Q_EMIT fetching();
|
|
||||||
|
|
||||||
qsizetype movementSize = SLIDING_CACHE_WINDOW_SIZE;
|
qsizetype movementSize = SLIDING_CACHE_WINDOW_SIZE;
|
||||||
qsizetype prefetchThreshold = SLIDING_CACHE_PREFETCH_THRESHOLD;
|
|
||||||
|
|
||||||
if(m_windowSize != nullsize)
|
|
||||||
{
|
|
||||||
movementSize = m_windowSize;
|
|
||||||
|
|
||||||
if(prefetchThreshold >= m_windowSize)
|
|
||||||
{
|
|
||||||
prefetchThreshold = std::floor(
|
|
||||||
static_cast<qreal>(movementSize) * 0.8
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG_ERROR_X(movementSize <= 0 || prefetchThreshold <= 0,
|
|
||||||
"SlidingCacheController::slideForward",
|
|
||||||
"Invalid movement size",
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
//after initial inflation we should only arrive here when the prefetch threshold is reached
|
//after initial inflation we should only arrive here when the prefetch threshold is reached
|
||||||
if(!m_cache.isEmpty())
|
if(!m_cache.isEmpty())
|
||||||
{
|
{
|
||||||
movementSize -= prefetchThreshold;
|
movementSize -= SLIDING_CACHE_PREFETCH_THRESHOLD;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_totalCount != nullsize)
|
if(m_totalCount != std::numeric_limits<qsizetype>::infinity())
|
||||||
{
|
{
|
||||||
m_windowOffset += movementSize;
|
m_windowOffset += movementSize;
|
||||||
}
|
}
|
||||||
@@ -407,8 +321,6 @@ private:
|
|||||||
m_windowOffset = 0;
|
m_windowOffset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QThread::sleep(KOMPLEX_RATE_LIMIT);
|
|
||||||
|
|
||||||
FetchResult<T> result = m_fetch(
|
FetchResult<T> result = m_fetch(
|
||||||
m_windowOffset,
|
m_windowOffset,
|
||||||
movementSize
|
movementSize
|
||||||
@@ -425,8 +337,6 @@ private:
|
|||||||
if(result.data.isEmpty())
|
if(result.data.isEmpty())
|
||||||
{
|
{
|
||||||
m_windowOffset -= movementSize;
|
m_windowOffset -= movementSize;
|
||||||
|
|
||||||
Q_EMIT fetchComplete();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -449,8 +359,6 @@ private:
|
|||||||
m_cache.append(std::move(result.data));
|
m_cache.append(std::move(result.data));
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_EMIT fetchComplete();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -467,31 +375,7 @@ private:
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
Q_EMIT fetching();
|
qsizetype movementSize = SLIDING_CACHE_WINDOW_SIZE - SLIDING_CACHE_PREFETCH_THRESHOLD;
|
||||||
|
|
||||||
qsizetype movementSize = SLIDING_CACHE_WINDOW_SIZE;
|
|
||||||
qsizetype prefetchThreshold = SLIDING_CACHE_PREFETCH_THRESHOLD;
|
|
||||||
|
|
||||||
if(m_windowSize != nullsize)
|
|
||||||
{
|
|
||||||
movementSize = m_windowSize;
|
|
||||||
|
|
||||||
if(prefetchThreshold >= m_windowSize)
|
|
||||||
{
|
|
||||||
prefetchThreshold = std::floor(
|
|
||||||
static_cast<qreal>(movementSize) * 0.8
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG_ERROR_X(movementSize <= 0 || prefetchThreshold <= 0,
|
|
||||||
"SlidingCacheController::slideBackward",
|
|
||||||
"Invalid movement size",
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
QThread::sleep(KOMPLEX_RATE_LIMIT);
|
|
||||||
|
|
||||||
m_windowOffset -= movementSize;
|
m_windowOffset -= movementSize;
|
||||||
|
|
||||||
if(m_windowOffset < 0)
|
if(m_windowOffset < 0)
|
||||||
@@ -507,8 +391,6 @@ private:
|
|||||||
if(result.count == 0)
|
if(result.count == 0)
|
||||||
{
|
{
|
||||||
m_windowOffset += movementSize;
|
m_windowOffset += movementSize;
|
||||||
|
|
||||||
Q_EMIT fetchComplete();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -537,8 +419,6 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_EMIT fetchComplete();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -564,7 +444,7 @@ private:
|
|||||||
* Total number of results available. Data comes from the return data of
|
* Total number of results available. Data comes from the return data of
|
||||||
* m_fetch
|
* m_fetch
|
||||||
*/
|
*/
|
||||||
qsizetype m_totalCount = nullsize;
|
qsizetype m_totalCount = std::numeric_limits<qsizetype>::infinity();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief m_fetch
|
* @brief m_fetch
|
||||||
@@ -583,12 +463,6 @@ private:
|
|||||||
* @brief m_cacheMutex
|
* @brief m_cacheMutex
|
||||||
*/
|
*/
|
||||||
mutable QMutex m_cacheMutex;
|
mutable QMutex m_cacheMutex;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief m_windowSize
|
|
||||||
* Override for window size
|
|
||||||
*/
|
|
||||||
qsizetype m_windowSize = nullsize;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SLIDINGCACHECONTROLLER_H
|
#endif // SLIDINGCACHECONTROLLER_H
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
FeaturedImagesModel::FeaturedImagesModel(QObject *parent) : QAbstractListModel{parent}
|
FeaturedImagesModel::FeaturedImagesModel(QObject *parent) : QAbstractListModel{parent}
|
||||||
{
|
{
|
||||||
|
setState(Loading);
|
||||||
|
|
||||||
m_paginator = new FeaturedImagesPaginator(this);
|
m_paginator = new FeaturedImagesPaginator(this);
|
||||||
PaginationNotifier *notifier = static_cast<PaginationNotifier*>(m_paginator);
|
PaginationNotifier *notifier = static_cast<PaginationNotifier*>(m_paginator);
|
||||||
|
|
||||||
@@ -35,24 +37,10 @@ FeaturedImagesModel::FeaturedImagesModel(QObject *parent) : QAbstractListModel{p
|
|||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
notifier,
|
notifier,
|
||||||
&PaginationNotifier::pageChanged,
|
&PaginationNotifier::dataChanged,
|
||||||
this,
|
this,
|
||||||
&FeaturedImagesModel::resetDataModel
|
&FeaturedImagesModel::resetDataModel
|
||||||
);
|
);
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetchComplete,
|
|
||||||
this,
|
|
||||||
&FeaturedImagesModel::resetState
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetching,
|
|
||||||
this,
|
|
||||||
&FeaturedImagesModel::onPaginatorFetching
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedImagesModel::rowCount(const QModelIndex &) const -> int
|
auto FeaturedImagesModel::rowCount(const QModelIndex &) const -> int
|
||||||
@@ -67,12 +55,12 @@ auto FeaturedImagesModel::rowCount(const QModelIndex &) const -> int
|
|||||||
|
|
||||||
auto FeaturedImagesModel::data(const QModelIndex &index, int role) const -> QVariant
|
auto FeaturedImagesModel::data(const QModelIndex &index, int role) const -> QVariant
|
||||||
{
|
{
|
||||||
if(!boundaryCheck(index.row()))
|
if(index.row() < 0 || m_paginator == nullptr)
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageCache dataPoint = m_paginator->at(index.row());
|
ImageCache dataPoint = m_data.at(index.row());
|
||||||
|
|
||||||
QVariant data;
|
QVariant data;
|
||||||
|
|
||||||
@@ -126,12 +114,10 @@ auto FeaturedImagesModel::index(int row, int column, const QModelIndex &parent)
|
|||||||
{
|
{
|
||||||
Q_UNUSED(parent)
|
Q_UNUSED(parent)
|
||||||
|
|
||||||
if(!boundaryCheck(row))
|
if(row < 0 || row >= m_data.count())
|
||||||
{
|
|
||||||
return {};
|
return {};
|
||||||
}
|
|
||||||
|
|
||||||
return createIndex(row, column, &m_paginator[row]);
|
return createIndex(row, column, &m_data[row]);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedImagesModel::columnCount(const QModelIndex &) const -> int
|
auto FeaturedImagesModel::columnCount(const QModelIndex &) const -> int
|
||||||
@@ -172,28 +158,25 @@ auto FeaturedImagesModel::resetState() -> void
|
|||||||
|
|
||||||
auto FeaturedImagesModel::resetDataModel() -> void
|
auto FeaturedImagesModel::resetDataModel() -> void
|
||||||
{
|
{
|
||||||
|
setState(Loading);
|
||||||
|
|
||||||
//invalidate previous model data
|
//invalidate previous model data
|
||||||
beginRemoveRows(QModelIndex(), 0, m_paginator->count());
|
beginRemoveRows(QModelIndex(), 0, m_data.count());
|
||||||
|
m_data.clear();
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
|
||||||
//signal new data
|
//signal new data
|
||||||
beginInsertRows(QModelIndex(), 0, m_paginator->count() - 1);
|
beginInsertRows(QModelIndex(), 0, m_paginator->count() - 1);
|
||||||
endInsertRows();
|
auto dataset = m_paginator->data();
|
||||||
}
|
|
||||||
|
|
||||||
auto FeaturedImagesModel::onPaginatorFetching() -> void
|
for(const ImageCache& data : std::as_const(dataset))
|
||||||
{
|
|
||||||
setState(Loading);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto FeaturedImagesModel::boundaryCheck(qsizetype index) const -> bool
|
|
||||||
{
|
|
||||||
if(index < 0 || m_paginator == nullptr || index >= m_paginator->count())
|
|
||||||
{
|
{
|
||||||
return false;
|
m_data.append(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
endInsertRows();
|
||||||
|
|
||||||
|
setState(Idle);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedImagesModel::roleNames() const -> QHash<int, QByteArray>
|
auto FeaturedImagesModel::roleNames() const -> QHash<int, QByteArray>
|
||||||
@@ -231,13 +214,7 @@ auto FeaturedImagesModel::setResultsPerPage(qsizetype resultsPerPage) -> void
|
|||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->setResultsPerPage(resultsPerPage);
|
||||||
(
|
|
||||||
[this, resultsPerPage]
|
|
||||||
{
|
|
||||||
m_paginator->setResultsPerPage(resultsPerPage);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,31 +228,19 @@ auto FeaturedImagesModel::totalResults() const -> qsizetype
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedImagesModel::nextPage() -> void
|
auto FeaturedImagesModel::nextPage() const -> void
|
||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->next();
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->next();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedImagesModel::previousPage() -> void
|
auto FeaturedImagesModel::previousPage() const -> void
|
||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->previous();
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->previous();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,6 @@
|
|||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
#include <QtConcurrent/QtConcurrentRun>
|
|
||||||
|
|
||||||
#include "paginators/featuredimagespaginator.h"
|
#include "paginators/featuredimagespaginator.h"
|
||||||
|
|
||||||
@@ -201,13 +200,13 @@ public:
|
|||||||
* @brief nextPage
|
* @brief nextPage
|
||||||
* Function for the QML frontend
|
* Function for the QML frontend
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE auto nextPage() -> void;
|
Q_INVOKABLE auto nextPage() const -> void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief previousPage
|
* @brief previousPage
|
||||||
* Function for the QML frontend
|
* Function for the QML frontend
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE auto previousPage() -> void;
|
Q_INVOKABLE auto previousPage() const -> void;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
@@ -227,19 +226,8 @@ protected:
|
|||||||
*/
|
*/
|
||||||
auto resetState() -> void;
|
auto resetState() -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief resetDataModel
|
|
||||||
* Clears the data model and creates a new one if data exists
|
|
||||||
*/
|
|
||||||
auto resetDataModel() -> void;
|
auto resetDataModel() -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief onPaginatorFetching
|
|
||||||
* Sets current state to loading. Triggered when paginator's cache controller
|
|
||||||
* needs to fetch data from the remote endpoint.
|
|
||||||
*/
|
|
||||||
auto onPaginatorFetching() -> void;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
auto stateChanged() -> void;
|
auto stateChanged() -> void;
|
||||||
auto errorStringChanged() -> void;
|
auto errorStringChanged() -> void;
|
||||||
@@ -250,18 +238,6 @@ signals:
|
|||||||
auto totalPagesChanged() -> void;
|
auto totalPagesChanged() -> void;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
|
||||||
* @brief boundaryCheck
|
|
||||||
* Helper function to check the requested index boundary
|
|
||||||
* @param index
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto boundaryCheck(qsizetype index) const -> bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief m_dataRoles
|
|
||||||
* Data role map that connects ImageSearchModel::DataRole to it's QML accessor name
|
|
||||||
*/
|
|
||||||
static inline const QHash<int, QByteArray> m_dataRoles =
|
static inline const QHash<int, QByteArray> m_dataRoles =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
@@ -323,6 +299,8 @@ private:
|
|||||||
|
|
||||||
FeaturedImagesPaginator *m_paginator = nullptr;
|
FeaturedImagesPaginator *m_paginator = nullptr;
|
||||||
|
|
||||||
|
mutable QList<ImageCache> m_data;
|
||||||
|
|
||||||
Q_PROPERTY(State state READ state WRITE setState RESET resetState NOTIFY stateChanged FINAL)
|
Q_PROPERTY(State state READ state WRITE setState RESET resetState NOTIFY stateChanged FINAL)
|
||||||
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
||||||
Q_PROPERTY(qsizetype resultsPerPage READ resultsPerPage WRITE setResultsPerPage NOTIFY resultsPerPageChanged FINAL)
|
Q_PROPERTY(qsizetype resultsPerPage READ resultsPerPage WRITE setResultsPerPage NOTIFY resultsPerPageChanged FINAL)
|
||||||
|
|||||||
@@ -36,24 +36,10 @@ FeaturedPacksModel::FeaturedPacksModel(QObject *parent) : QAbstractListModel{par
|
|||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
notifier,
|
notifier,
|
||||||
&PaginationNotifier::pageChanged,
|
&PaginationNotifier::dataChanged,
|
||||||
this,
|
this,
|
||||||
&FeaturedPacksModel::resetDataModel
|
&FeaturedPacksModel::resetDataModel
|
||||||
);
|
);
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetchComplete,
|
|
||||||
this,
|
|
||||||
&FeaturedPacksModel::resetState
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetching,
|
|
||||||
this,
|
|
||||||
&FeaturedPacksModel::onPaginatorFetching
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedPacksModel::rowCount(const QModelIndex &) const -> int
|
auto FeaturedPacksModel::rowCount(const QModelIndex &) const -> int
|
||||||
@@ -68,12 +54,12 @@ auto FeaturedPacksModel::rowCount(const QModelIndex &) const -> int
|
|||||||
|
|
||||||
auto FeaturedPacksModel::data(const QModelIndex &index, int role) const -> QVariant
|
auto FeaturedPacksModel::data(const QModelIndex &index, int role) const -> QVariant
|
||||||
{
|
{
|
||||||
if(index.row() < 0 || m_paginator == nullptr || index.row() >= m_paginator->count())
|
if(index.row() < 0 || m_paginator == nullptr)
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
WallpaperCache dataPoint = m_paginator->at(index.row());
|
WallpaperCache dataPoint = m_data.at(index.row());
|
||||||
|
|
||||||
QVariant data;
|
QVariant data;
|
||||||
|
|
||||||
@@ -121,12 +107,10 @@ auto FeaturedPacksModel::index(int row, int column, const QModelIndex &parent) c
|
|||||||
{
|
{
|
||||||
Q_UNUSED(parent)
|
Q_UNUSED(parent)
|
||||||
|
|
||||||
if(row < 0 || row >= m_paginator->count())
|
if(row < 0 || row >= m_data.count())
|
||||||
{
|
|
||||||
return {};
|
return {};
|
||||||
}
|
|
||||||
|
|
||||||
return createIndex(row, column, &m_paginator[row]);
|
return createIndex(row, column, &m_data[row]);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedPacksModel::columnCount(const QModelIndex &) const -> int
|
auto FeaturedPacksModel::columnCount(const QModelIndex &) const -> int
|
||||||
@@ -157,7 +141,7 @@ auto FeaturedPacksModel::setState(State state) -> void
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_state = state;
|
m_state = state;
|
||||||
Q_EMIT stateChanged();
|
emit stateChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedPacksModel::resetState() -> void
|
auto FeaturedPacksModel::resetState() -> void
|
||||||
@@ -168,17 +152,20 @@ auto FeaturedPacksModel::resetState() -> void
|
|||||||
auto FeaturedPacksModel::resetDataModel() -> void
|
auto FeaturedPacksModel::resetDataModel() -> void
|
||||||
{
|
{
|
||||||
//invalidate previous model data
|
//invalidate previous model data
|
||||||
beginRemoveRows(QModelIndex(), 0, m_paginator->count());
|
beginRemoveRows(QModelIndex(), 0, m_data.count());
|
||||||
|
m_data.clear();
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
|
||||||
//signal new data
|
//signal new data
|
||||||
beginInsertRows(QModelIndex(), 0, m_paginator->count() - 1);
|
beginInsertRows(QModelIndex(), 0, m_paginator->count() - 1);
|
||||||
endInsertRows();
|
auto dataset = m_paginator->data();
|
||||||
}
|
|
||||||
|
|
||||||
auto FeaturedPacksModel::onPaginatorFetching() -> void
|
for(const WallpaperCache& data : std::as_const(dataset))
|
||||||
{
|
{
|
||||||
setState(Loading);
|
m_data.append(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedPacksModel::roleNames() const -> QHash<int, QByteArray>
|
auto FeaturedPacksModel::roleNames() const -> QHash<int, QByteArray>
|
||||||
@@ -199,7 +186,7 @@ auto FeaturedPacksModel::setErrorString(const QString &errorString) -> void
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_errorString = errorString;
|
m_errorString = errorString;
|
||||||
Q_EMIT errorStringChanged();
|
emit errorStringChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedPacksModel::resultsPerPage() const -> qsizetype
|
auto FeaturedPacksModel::resultsPerPage() const -> qsizetype
|
||||||
@@ -216,13 +203,7 @@ auto FeaturedPacksModel::setResultsPerPage(qsizetype resultsPerPage) -> void
|
|||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->setResultsPerPage(resultsPerPage);
|
||||||
(
|
|
||||||
[this, resultsPerPage]
|
|
||||||
{
|
|
||||||
m_paginator->setResultsPerPage(resultsPerPage);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,31 +217,19 @@ auto FeaturedPacksModel::totalResults() const -> qsizetype
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedPacksModel::nextPage() -> void
|
auto FeaturedPacksModel::nextPage() const -> void
|
||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->next();
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->next();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedPacksModel::previousPage() -> void
|
auto FeaturedPacksModel::previousPage() const -> void
|
||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->previous();
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->previous();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,6 @@
|
|||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
#include <QtConcurrent/QtConcurrentRun>
|
|
||||||
|
|
||||||
#include "paginators/featuredpackspaginator.h"
|
#include "paginators/featuredpackspaginator.h"
|
||||||
|
|
||||||
@@ -199,13 +198,13 @@ public:
|
|||||||
* @brief nextPage
|
* @brief nextPage
|
||||||
* Function for the QML frontend
|
* Function for the QML frontend
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE auto nextPage() -> void;
|
Q_INVOKABLE auto nextPage() const -> void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief previousPage
|
* @brief previousPage
|
||||||
* Function for the QML frontend
|
* Function for the QML frontend
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE auto previousPage() -> void;
|
Q_INVOKABLE auto previousPage() const -> void;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
@@ -227,8 +226,6 @@ protected:
|
|||||||
|
|
||||||
auto resetDataModel() -> void;
|
auto resetDataModel() -> void;
|
||||||
|
|
||||||
auto onPaginatorFetching() -> void;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
auto stateChanged() -> void;
|
auto stateChanged() -> void;
|
||||||
auto errorStringChanged() -> void;
|
auto errorStringChanged() -> void;
|
||||||
@@ -239,10 +236,6 @@ signals:
|
|||||||
auto totalPagesChanged() -> void;
|
auto totalPagesChanged() -> void;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
|
||||||
* @brief m_dataRoles
|
|
||||||
* Data role map that connects ImageSearchModel::DataRole to it's QML accessor name
|
|
||||||
*/
|
|
||||||
static inline const QHash<int, QByteArray> m_dataRoles =
|
static inline const QHash<int, QByteArray> m_dataRoles =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
@@ -296,6 +289,8 @@ private:
|
|||||||
|
|
||||||
FeaturedPacksPaginator *m_paginator = nullptr;
|
FeaturedPacksPaginator *m_paginator = nullptr;
|
||||||
|
|
||||||
|
mutable QList<WallpaperCache> m_data;
|
||||||
|
|
||||||
Q_PROPERTY(State state READ state WRITE setState RESET resetState NOTIFY stateChanged FINAL)
|
Q_PROPERTY(State state READ state WRITE setState RESET resetState NOTIFY stateChanged FINAL)
|
||||||
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
||||||
Q_PROPERTY(qsizetype resultsPerPage READ resultsPerPage WRITE setResultsPerPage NOTIFY resultsPerPageChanged FINAL)
|
Q_PROPERTY(qsizetype resultsPerPage READ resultsPerPage WRITE setResultsPerPage NOTIFY resultsPerPageChanged FINAL)
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
FeaturedVideosModel::FeaturedVideosModel(QObject *parent) : QAbstractListModel{parent}
|
FeaturedVideosModel::FeaturedVideosModel(QObject *parent) : QAbstractListModel{parent}
|
||||||
{
|
{
|
||||||
|
setState(Loading);
|
||||||
|
|
||||||
m_paginator = new FeaturedVideosPaginator(this);
|
m_paginator = new FeaturedVideosPaginator(this);
|
||||||
PaginationNotifier *notifier = static_cast<PaginationNotifier*>(m_paginator);
|
PaginationNotifier *notifier = static_cast<PaginationNotifier*>(m_paginator);
|
||||||
|
|
||||||
@@ -36,24 +38,10 @@ FeaturedVideosModel::FeaturedVideosModel(QObject *parent) : QAbstractListModel{p
|
|||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
notifier,
|
notifier,
|
||||||
&PaginationNotifier::pageChanged,
|
&PaginationNotifier::dataChanged,
|
||||||
this,
|
this,
|
||||||
&FeaturedVideosModel::resetDataModel
|
&FeaturedVideosModel::resetDataModel
|
||||||
);
|
);
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetchComplete,
|
|
||||||
this,
|
|
||||||
&FeaturedVideosModel::resetState
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetching,
|
|
||||||
this,
|
|
||||||
&FeaturedVideosModel::onPaginatorFetching
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedVideosModel::rowCount(const QModelIndex &) const -> int
|
auto FeaturedVideosModel::rowCount(const QModelIndex &) const -> int
|
||||||
@@ -68,12 +56,12 @@ auto FeaturedVideosModel::rowCount(const QModelIndex &) const -> int
|
|||||||
|
|
||||||
auto FeaturedVideosModel::data(const QModelIndex &index, int role) const -> QVariant
|
auto FeaturedVideosModel::data(const QModelIndex &index, int role) const -> QVariant
|
||||||
{
|
{
|
||||||
if(index.row() < 0 || m_paginator == nullptr || index.row() >= m_paginator->count())
|
if(index.row() < 0 || m_paginator == nullptr)
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
VideoCache dataPoint = m_paginator->at(index.row());
|
VideoCache dataPoint = m_data.at(index.row());
|
||||||
|
|
||||||
QVariant data;
|
QVariant data;
|
||||||
|
|
||||||
@@ -115,17 +103,10 @@ auto FeaturedVideosModel::index(int row, int column, const QModelIndex &parent)
|
|||||||
{
|
{
|
||||||
Q_UNUSED(parent)
|
Q_UNUSED(parent)
|
||||||
|
|
||||||
if(m_paginator == nullptr)
|
if(row < 0 || row >= m_data.count())
|
||||||
{
|
|
||||||
return {};
|
return {};
|
||||||
}
|
|
||||||
|
|
||||||
if(row < 0 || row >= m_paginator->count())
|
return createIndex(row, column, &m_data[row]);
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
return createIndex(row, column, &m_paginator[row]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedVideosModel::columnCount(const QModelIndex &) const -> int
|
auto FeaturedVideosModel::columnCount(const QModelIndex &) const -> int
|
||||||
@@ -166,18 +147,25 @@ auto FeaturedVideosModel::resetState() -> void
|
|||||||
|
|
||||||
auto FeaturedVideosModel::resetDataModel() -> void
|
auto FeaturedVideosModel::resetDataModel() -> void
|
||||||
{
|
{
|
||||||
|
setState(Loading);
|
||||||
|
|
||||||
//invalidate previous model data
|
//invalidate previous model data
|
||||||
beginRemoveRows(QModelIndex(), 0, m_paginator->count());
|
beginRemoveRows(QModelIndex(), 0, m_data.count());
|
||||||
|
m_data.clear();
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
|
||||||
//signal new data
|
//signal new data
|
||||||
beginInsertRows(QModelIndex(), 0, m_paginator->count() - 1);
|
beginInsertRows(QModelIndex(), 0, m_paginator->count() - 1);
|
||||||
endInsertRows();
|
auto dataset = m_paginator->data();
|
||||||
}
|
|
||||||
|
|
||||||
auto FeaturedVideosModel::onPaginatorFetching() -> void
|
for(const VideoCache& data : std::as_const(dataset))
|
||||||
{
|
{
|
||||||
setState(Loading);
|
m_data.append(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
endInsertRows();
|
||||||
|
|
||||||
|
setState(Idle);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedVideosModel::roleNames() const -> QHash<int, QByteArray>
|
auto FeaturedVideosModel::roleNames() const -> QHash<int, QByteArray>
|
||||||
@@ -215,13 +203,7 @@ auto FeaturedVideosModel::setResultsPerPage(qsizetype resultsPerPage) -> void
|
|||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->setResultsPerPage(resultsPerPage);
|
||||||
(
|
|
||||||
[this, resultsPerPage]
|
|
||||||
{
|
|
||||||
m_paginator->setResultsPerPage(resultsPerPage);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,31 +217,19 @@ auto FeaturedVideosModel::totalResults() const -> qsizetype
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedVideosModel::nextPage() -> void
|
auto FeaturedVideosModel::nextPage() const -> void
|
||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->next();
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->next();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedVideosModel::previousPage() -> void
|
auto FeaturedVideosModel::previousPage() const -> void
|
||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->previous();
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->previous();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,6 @@
|
|||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
#include <QtConcurrent/QtConcurrentRun>
|
|
||||||
|
|
||||||
#include "paginators/featuredvideospaginator.h"
|
#include "paginators/featuredvideospaginator.h"
|
||||||
|
|
||||||
@@ -197,13 +196,13 @@ public:
|
|||||||
* @brief nextPage
|
* @brief nextPage
|
||||||
* Function for the QML frontend
|
* Function for the QML frontend
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE auto nextPage() -> void;
|
Q_INVOKABLE auto nextPage() const -> void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief previousPage
|
* @brief previousPage
|
||||||
* Function for the QML frontend
|
* Function for the QML frontend
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE auto previousPage() -> void;
|
Q_INVOKABLE auto previousPage() const -> void;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
@@ -225,8 +224,6 @@ protected:
|
|||||||
|
|
||||||
auto resetDataModel() -> void;
|
auto resetDataModel() -> void;
|
||||||
|
|
||||||
auto onPaginatorFetching() -> void;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
auto stateChanged() -> void;
|
auto stateChanged() -> void;
|
||||||
auto errorStringChanged() -> void;
|
auto errorStringChanged() -> void;
|
||||||
@@ -237,10 +234,6 @@ signals:
|
|||||||
auto totalPagesChanged() -> void;
|
auto totalPagesChanged() -> void;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
|
||||||
* @brief m_dataRoles
|
|
||||||
* Data role map that connects ImageSearchModel::DataRole to it's QML accessor name
|
|
||||||
*/
|
|
||||||
static inline const QHash<int, QByteArray> m_dataRoles =
|
static inline const QHash<int, QByteArray> m_dataRoles =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
@@ -286,6 +279,8 @@ private:
|
|||||||
|
|
||||||
FeaturedVideosPaginator *m_paginator = nullptr;
|
FeaturedVideosPaginator *m_paginator = nullptr;
|
||||||
|
|
||||||
|
mutable QList<VideoCache> m_data;
|
||||||
|
|
||||||
Q_PROPERTY(State state READ state WRITE setState RESET resetState NOTIFY stateChanged FINAL)
|
Q_PROPERTY(State state READ state WRITE setState RESET resetState NOTIFY stateChanged FINAL)
|
||||||
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
||||||
Q_PROPERTY(qsizetype resultsPerPage READ resultsPerPage WRITE setResultsPerPage NOTIFY resultsPerPageChanged FINAL)
|
Q_PROPERTY(qsizetype resultsPerPage READ resultsPerPage WRITE setResultsPerPage NOTIFY resultsPerPageChanged FINAL)
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
ImageSearchModel::ImageSearchModel(QObject *parent) : QAbstractListModel{parent}
|
ImageSearchModel::ImageSearchModel(QObject *parent) : QAbstractListModel{parent}
|
||||||
{
|
{
|
||||||
|
setState(Loading);
|
||||||
|
|
||||||
m_paginator = new ImageSearchPaginator(this);
|
m_paginator = new ImageSearchPaginator(this);
|
||||||
PaginationNotifier *notifier = static_cast<PaginationNotifier*>(m_paginator);
|
PaginationNotifier *notifier = static_cast<PaginationNotifier*>(m_paginator);
|
||||||
|
|
||||||
@@ -35,25 +37,11 @@ ImageSearchModel::ImageSearchModel(QObject *parent) : QAbstractListModel{parent}
|
|||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
notifier,
|
notifier,
|
||||||
&PaginationNotifier::pageChanged,
|
&PaginationNotifier::dataChanged,
|
||||||
this,
|
this,
|
||||||
&ImageSearchModel::resetDataModel
|
&ImageSearchModel::resetDataModel
|
||||||
);
|
);
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetchComplete,
|
|
||||||
this,
|
|
||||||
&ImageSearchModel::resetState
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetching,
|
|
||||||
this,
|
|
||||||
&ImageSearchModel::onPaginatorFetching
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
m_paginator,
|
m_paginator,
|
||||||
&ImageSearchPaginator::queryChanged,
|
&ImageSearchPaginator::queryChanged,
|
||||||
@@ -62,14 +50,6 @@ ImageSearchModel::ImageSearchModel(QObject *parent) : QAbstractListModel{parent}
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageSearchModel::~ImageSearchModel()
|
|
||||||
{
|
|
||||||
if(m_paginator != nullptr)
|
|
||||||
{
|
|
||||||
delete m_paginator;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto ImageSearchModel::rowCount(const QModelIndex &) const -> int
|
auto ImageSearchModel::rowCount(const QModelIndex &) const -> int
|
||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
@@ -82,12 +62,12 @@ auto ImageSearchModel::rowCount(const QModelIndex &) const -> int
|
|||||||
|
|
||||||
auto ImageSearchModel::data(const QModelIndex &index, int role) const -> QVariant
|
auto ImageSearchModel::data(const QModelIndex &index, int role) const -> QVariant
|
||||||
{
|
{
|
||||||
if(index.row() < 0 || m_paginator == nullptr || index.row() >= m_paginator->count())
|
if(index.row() < 0 || m_paginator == nullptr)
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageCache dataPoint = m_paginator->at(index.row());
|
ImageCache dataPoint = m_data.at(index.row());
|
||||||
|
|
||||||
QVariant data;
|
QVariant data;
|
||||||
|
|
||||||
@@ -132,27 +112,6 @@ auto ImageSearchModel::data(const QModelIndex &index, int role) const -> QVarian
|
|||||||
case ExtraLargeUrlRole:
|
case ExtraLargeUrlRole:
|
||||||
data = dataPoint.sources.value(QString::fromUtf8("large2x"));
|
data = dataPoint.sources.value(QString::fromUtf8("large2x"));
|
||||||
break;
|
break;
|
||||||
case PortraitSizeRole:
|
|
||||||
data = dataPoint.sourceSizes.value(QString::fromUtf8("portrait"));
|
|
||||||
break;
|
|
||||||
case LandscapeSizeRole:
|
|
||||||
data = dataPoint.sourceSizes.value(QString::fromUtf8("landscape"));
|
|
||||||
break;
|
|
||||||
case SmallSizeRole:
|
|
||||||
data = dataPoint.sourceSizes.value(QString::fromUtf8("small"));
|
|
||||||
break;
|
|
||||||
case OriginalSizeRole:
|
|
||||||
data = dataPoint.sourceSizes.value(QString::fromUtf8("original"));
|
|
||||||
break;
|
|
||||||
case MediumSizeRole:
|
|
||||||
data = dataPoint.sourceSizes.value(QString::fromUtf8("medium"));
|
|
||||||
break;
|
|
||||||
case LargeSizeRole:
|
|
||||||
data = dataPoint.sourceSizes.value(QString::fromUtf8("large"));
|
|
||||||
break;
|
|
||||||
case ExtraLargeSizeRole:
|
|
||||||
data = dataPoint.sourceSizes.value(QString::fromUtf8("large2x"));
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
@@ -162,12 +121,10 @@ auto ImageSearchModel::index(int row, int column, const QModelIndex &parent) con
|
|||||||
{
|
{
|
||||||
Q_UNUSED(parent)
|
Q_UNUSED(parent)
|
||||||
|
|
||||||
if(row < 0 || row >= m_paginator->count())
|
if(row < 0 || row >= m_data.count())
|
||||||
{
|
|
||||||
return {};
|
return {};
|
||||||
}
|
|
||||||
|
|
||||||
return createIndex(row, column, &m_paginator->at(row));
|
return createIndex(row, column, &m_data[row]);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ImageSearchModel::columnCount(const QModelIndex &) const -> int
|
auto ImageSearchModel::columnCount(const QModelIndex &) const -> int
|
||||||
@@ -208,26 +165,33 @@ auto ImageSearchModel::resetState() -> void
|
|||||||
|
|
||||||
auto ImageSearchModel::resetDataModel() -> void
|
auto ImageSearchModel::resetDataModel() -> void
|
||||||
{
|
{
|
||||||
|
setState(Loading);
|
||||||
|
|
||||||
//invalidate previous model data
|
//invalidate previous model data
|
||||||
beginRemoveRows(QModelIndex(), 0, m_paginator->count());
|
beginRemoveRows(QModelIndex(), 0, m_data.count());
|
||||||
|
m_data.clear();
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
|
||||||
//signal new data
|
//signal new data
|
||||||
beginInsertRows(QModelIndex(), 0, m_paginator->count() - 1);
|
beginInsertRows(QModelIndex(), 0, m_paginator->count() - 1);
|
||||||
|
auto dataset = m_paginator->data();
|
||||||
|
|
||||||
|
for(const ImageCache& data : std::as_const(dataset))
|
||||||
|
{
|
||||||
|
m_data.append(data);
|
||||||
|
}
|
||||||
|
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
|
setState(Idle);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ImageSearchModel::onPaginatorFetching() -> void
|
auto ImageSearchModel::hasNextPage() -> bool
|
||||||
{
|
|
||||||
setState(Loading);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto ImageSearchModel::hasNextPage() const -> bool
|
|
||||||
{
|
{
|
||||||
return m_paginator->page() < m_paginator->totalPages();
|
return m_paginator->page() < m_paginator->totalPages();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ImageSearchModel::hasPreviousPage() const -> bool
|
auto ImageSearchModel::hasPreviousPage() -> bool
|
||||||
{
|
{
|
||||||
return m_paginator->page() > 0;
|
return m_paginator->page() > 0;
|
||||||
}
|
}
|
||||||
@@ -267,42 +231,7 @@ auto ImageSearchModel::setResultsPerPage(qsizetype resultsPerPage) -> void
|
|||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->setResultsPerPage(resultsPerPage);
|
||||||
(
|
|
||||||
[this, resultsPerPage]
|
|
||||||
{
|
|
||||||
qsizetype difference = resultsPerPage - m_paginator->resultsPerPage();
|
|
||||||
m_paginator->setResultsPerPage(resultsPerPage);
|
|
||||||
|
|
||||||
if(difference > 0)
|
|
||||||
{
|
|
||||||
qsizetype firstIndex = m_paginator->resultsPerPage() - difference;
|
|
||||||
|
|
||||||
beginInsertRows
|
|
||||||
(
|
|
||||||
QModelIndex(),
|
|
||||||
firstIndex,
|
|
||||||
m_paginator->count() - 1
|
|
||||||
);
|
|
||||||
|
|
||||||
endInsertRows();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(difference < 0)
|
|
||||||
{
|
|
||||||
qsizetype firstIndex = m_paginator->resultsPerPage();
|
|
||||||
|
|
||||||
beginRemoveRows
|
|
||||||
(
|
|
||||||
QModelIndex(),
|
|
||||||
firstIndex,
|
|
||||||
firstIndex - difference
|
|
||||||
);
|
|
||||||
|
|
||||||
endRemoveRows();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,31 +245,19 @@ auto ImageSearchModel::totalResults() const -> qsizetype
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ImageSearchModel::nextPage() -> void
|
auto ImageSearchModel::nextPage() const -> void
|
||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->next();
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->next();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ImageSearchModel::previousPage() -> void
|
auto ImageSearchModel::previousPage() const -> void
|
||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->previous();
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->previous();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,13 +275,7 @@ auto ImageSearchModel::setQuery(const QString &query) -> void
|
|||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->setQuery(query);
|
||||||
(
|
|
||||||
[this, query]
|
|
||||||
{
|
|
||||||
m_paginator->setQuery(query);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,6 @@
|
|||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
#include <QtConcurrent/QtConcurrentRun>
|
|
||||||
|
|
||||||
#include "paginators/imagesearchpaginator.h"
|
#include "paginators/imagesearchpaginator.h"
|
||||||
|
|
||||||
@@ -75,19 +74,11 @@ public:
|
|||||||
OriginalUrlRole,
|
OriginalUrlRole,
|
||||||
MediumUrlRole,
|
MediumUrlRole,
|
||||||
LargeUrlRole,
|
LargeUrlRole,
|
||||||
ExtraLargeUrlRole,
|
ExtraLargeUrlRole
|
||||||
PortraitSizeRole,
|
|
||||||
LandscapeSizeRole,
|
|
||||||
SmallSizeRole,
|
|
||||||
OriginalSizeRole,
|
|
||||||
MediumSizeRole,
|
|
||||||
LargeSizeRole,
|
|
||||||
ExtraLargeSizeRole
|
|
||||||
};
|
};
|
||||||
Q_ENUM(DataRole)
|
Q_ENUM(DataRole)
|
||||||
|
|
||||||
explicit ImageSearchModel(QObject *parent = nullptr);
|
explicit ImageSearchModel(QObject *parent = nullptr);
|
||||||
~ImageSearchModel();
|
|
||||||
|
|
||||||
auto rowCount(const QModelIndex &parent = QModelIndex()) const -> int override;
|
auto rowCount(const QModelIndex &parent = QModelIndex()) const -> int override;
|
||||||
|
|
||||||
@@ -209,13 +200,13 @@ public:
|
|||||||
* @brief nextPage
|
* @brief nextPage
|
||||||
* Function for the QML frontend
|
* Function for the QML frontend
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE auto nextPage() -> void;
|
Q_INVOKABLE auto nextPage() const -> void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief previousPage
|
* @brief previousPage
|
||||||
* Function for the QML frontend
|
* Function for the QML frontend
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE auto previousPage() -> void;
|
Q_INVOKABLE auto previousPage() const -> void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief query
|
* @brief query
|
||||||
@@ -226,36 +217,20 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief setQuery
|
* @brief setQuery
|
||||||
* Sets the current search query
|
* Sets the current
|
||||||
* @param query
|
* @param query
|
||||||
*/
|
*/
|
||||||
auto setQuery(const QString &query) -> void;
|
auto setQuery(const QString &query) -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief hasNextPage
|
|
||||||
* Calculates if there are more pages based on the current page calculation
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto hasNextPage() const -> bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief hasPreviousPage
|
|
||||||
* If page is greater than 1, returns true
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto hasPreviousPage() const -> bool;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* @brief setErrorString
|
* @brief setErrorString
|
||||||
* Sets the error string to be displayed to the user
|
|
||||||
* @param errorString
|
* @param errorString
|
||||||
*/
|
*/
|
||||||
auto setErrorString(const QString &errorString) -> void;
|
auto setErrorString(const QString &errorString) -> void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief setState
|
* @brief setState
|
||||||
* Sets the current state for QML
|
|
||||||
* @param state
|
* @param state
|
||||||
*/
|
*/
|
||||||
auto setState(State state) -> void;
|
auto setState(State state) -> void;
|
||||||
@@ -265,67 +240,23 @@ protected:
|
|||||||
*/
|
*/
|
||||||
auto resetState() -> void;
|
auto resetState() -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief resetDataModel
|
|
||||||
* Clears the data model and creates a new one if data exists
|
|
||||||
*/
|
|
||||||
auto resetDataModel() -> void;
|
auto resetDataModel() -> void;
|
||||||
|
|
||||||
/**
|
auto hasNextPage() -> bool;
|
||||||
* @brief onPaginatorFetching
|
|
||||||
* Sets current state to loading. Triggered when paginator's cache controller
|
auto hasPreviousPage() -> bool;
|
||||||
* needs to fetch data from the remote endpoint.
|
|
||||||
*/
|
|
||||||
auto onPaginatorFetching() -> void;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/**
|
|
||||||
* @brief stateChanged
|
|
||||||
* Signaled when reported state changes
|
|
||||||
*/
|
|
||||||
auto stateChanged() -> void;
|
auto stateChanged() -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief errorStringChanged
|
|
||||||
* Signaled when reported error message changes
|
|
||||||
*/
|
|
||||||
auto errorStringChanged() -> void;
|
auto errorStringChanged() -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief pageChanged
|
|
||||||
* Forwarding signal connected in constructor
|
|
||||||
*/
|
|
||||||
auto resultsPerPageChanged() -> void;
|
auto resultsPerPageChanged() -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief pageChanged
|
|
||||||
* Forwarding signal connected in constructor
|
|
||||||
*/
|
|
||||||
auto pageChanged() -> void;
|
auto pageChanged() -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief pageChanged
|
|
||||||
* Forwarding signal connected in constructor
|
|
||||||
*/
|
|
||||||
auto totalResultsChanged() -> void;
|
auto totalResultsChanged() -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief pageChanged
|
|
||||||
* Forwarding signal connected in constructor
|
|
||||||
*/
|
|
||||||
auto totalPagesChanged() -> void;
|
auto totalPagesChanged() -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief pageChanged
|
|
||||||
* Forwarding signal connected in constructor
|
|
||||||
*/
|
|
||||||
auto queryChanged() -> void;
|
auto queryChanged() -> void;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
|
||||||
* @brief m_dataRoles
|
|
||||||
* Data role map that connects ImageSearchModel::DataRole to it's QML accessor name
|
|
||||||
*/
|
|
||||||
static inline const QHash<int, QByteArray> m_dataRoles =
|
static inline const QHash<int, QByteArray> m_dataRoles =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
@@ -379,34 +310,6 @@ private:
|
|||||||
{
|
{
|
||||||
static_cast<int>(ExtraLargeUrlRole),
|
static_cast<int>(ExtraLargeUrlRole),
|
||||||
QByteArray("extraLarge")
|
QByteArray("extraLarge")
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(PortraitSizeRole),
|
|
||||||
QByteArray("portraitSize")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(LandscapeSizeRole),
|
|
||||||
QByteArray("landscapeSize")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(SmallSizeRole),
|
|
||||||
QByteArray("smallSize")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(OriginalSizeRole),
|
|
||||||
QByteArray("originalSize")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(MediumSizeRole),
|
|
||||||
QByteArray("mediumSize")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(LargeSizeRole),
|
|
||||||
QByteArray("largeSize")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(ExtraLargeSizeRole),
|
|
||||||
QByteArray("extraLargeSize")
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
State m_state = Idle;
|
State m_state = Idle;
|
||||||
@@ -415,6 +318,8 @@ private:
|
|||||||
|
|
||||||
ImageSearchPaginator *m_paginator = nullptr;
|
ImageSearchPaginator *m_paginator = nullptr;
|
||||||
|
|
||||||
|
mutable QList<ImageCache> m_data;
|
||||||
|
|
||||||
Q_PROPERTY(State state READ state WRITE setState RESET resetState NOTIFY stateChanged FINAL)
|
Q_PROPERTY(State state READ state WRITE setState RESET resetState NOTIFY stateChanged FINAL)
|
||||||
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
||||||
Q_PROPERTY(qsizetype resultsPerPage READ resultsPerPage WRITE setResultsPerPage NOTIFY resultsPerPageChanged FINAL)
|
Q_PROPERTY(qsizetype resultsPerPage READ resultsPerPage WRITE setResultsPerPage NOTIFY resultsPerPageChanged FINAL)
|
||||||
|
|||||||
@@ -38,24 +38,10 @@ NewestPacksModel::NewestPacksModel(QObject *parent) : QAbstractListModel{parent}
|
|||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
notifier,
|
notifier,
|
||||||
&PaginationNotifier::pageChanged,
|
&PaginationNotifier::dataChanged,
|
||||||
this,
|
this,
|
||||||
&NewestPacksModel::resetDataModel
|
&NewestPacksModel::resetDataModel
|
||||||
);
|
);
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetchComplete,
|
|
||||||
this,
|
|
||||||
&NewestPacksModel::resetState
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetching,
|
|
||||||
this,
|
|
||||||
&NewestPacksModel::onPaginatorFetching
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto NewestPacksModel::rowCount(const QModelIndex &) const -> int
|
auto NewestPacksModel::rowCount(const QModelIndex &) const -> int
|
||||||
@@ -70,12 +56,12 @@ auto NewestPacksModel::rowCount(const QModelIndex &) const -> int
|
|||||||
|
|
||||||
auto NewestPacksModel::data(const QModelIndex &index, int role) const -> QVariant
|
auto NewestPacksModel::data(const QModelIndex &index, int role) const -> QVariant
|
||||||
{
|
{
|
||||||
if(index.row() < 0 || m_paginator == nullptr || index.row() >= m_paginator->count())
|
if(index.row() < 0 || m_paginator == nullptr)
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
WallpaperCache dataPoint = m_paginator->at(index.row());
|
WallpaperCache dataPoint = m_data.at(index.row());
|
||||||
|
|
||||||
QVariant data;
|
QVariant data;
|
||||||
|
|
||||||
@@ -123,10 +109,10 @@ auto NewestPacksModel::index(int row, int column, const QModelIndex &parent) con
|
|||||||
{
|
{
|
||||||
Q_UNUSED(parent)
|
Q_UNUSED(parent)
|
||||||
|
|
||||||
if(row < 0 || row >= m_paginator->count())
|
if(row < 0 || row >= m_data.count())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
return createIndex(row, column, &m_paginator[row]);
|
return createIndex(row, column, &m_data[row]);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto NewestPacksModel::columnCount(const QModelIndex &) const -> int
|
auto NewestPacksModel::columnCount(const QModelIndex &) const -> int
|
||||||
@@ -167,18 +153,23 @@ auto NewestPacksModel::resetState() -> void
|
|||||||
|
|
||||||
auto NewestPacksModel::resetDataModel() -> void
|
auto NewestPacksModel::resetDataModel() -> void
|
||||||
{
|
{
|
||||||
|
setState(Loading);
|
||||||
//invalidate previous model data
|
//invalidate previous model data
|
||||||
beginRemoveRows(QModelIndex(), 0, m_paginator->count());
|
beginRemoveRows(QModelIndex(), 0, m_data.count());
|
||||||
|
m_data.clear();
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
|
||||||
//signal new data
|
//signal new data
|
||||||
beginInsertRows(QModelIndex(), 0, m_paginator->count() - 1);
|
beginInsertRows(QModelIndex(), 0, m_paginator->count() - 1);
|
||||||
endInsertRows();
|
auto dataset = m_paginator->data();
|
||||||
}
|
|
||||||
|
|
||||||
auto NewestPacksModel::onPaginatorFetching() -> void
|
for(const WallpaperCache& data : std::as_const(dataset))
|
||||||
{
|
{
|
||||||
setState(Loading);
|
m_data.append(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
endInsertRows();
|
||||||
|
setState(Idle);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto NewestPacksModel::roleNames() const -> QHash<int, QByteArray>
|
auto NewestPacksModel::roleNames() const -> QHash<int, QByteArray>
|
||||||
@@ -234,13 +225,7 @@ auto NewestPacksModel::nextPage() const -> void
|
|||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->next();
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->next();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,13 +233,7 @@ auto NewestPacksModel::previousPage() const -> void
|
|||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->previous();
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->previous();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,6 @@
|
|||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
#include <QtConcurrent/QtConcurrentRun>
|
|
||||||
|
|
||||||
#include "paginators/newestpackspaginator.h"
|
#include "paginators/newestpackspaginator.h"
|
||||||
|
|
||||||
@@ -237,8 +236,6 @@ protected:
|
|||||||
*/
|
*/
|
||||||
auto resetDataModel() -> void;
|
auto resetDataModel() -> void;
|
||||||
|
|
||||||
auto onPaginatorFetching() -> void;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
auto stateChanged() -> void;
|
auto stateChanged() -> void;
|
||||||
auto errorStringChanged() -> void;
|
auto errorStringChanged() -> void;
|
||||||
@@ -302,6 +299,8 @@ private:
|
|||||||
|
|
||||||
NewestPacksPaginator *m_paginator = nullptr;
|
NewestPacksPaginator *m_paginator = nullptr;
|
||||||
|
|
||||||
|
mutable QList<WallpaperCache> m_data;
|
||||||
|
|
||||||
Q_PROPERTY(State state READ state WRITE setState RESET resetState NOTIFY stateChanged FINAL)
|
Q_PROPERTY(State state READ state WRITE setState RESET resetState NOTIFY stateChanged FINAL)
|
||||||
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
||||||
Q_PROPERTY(qsizetype resultsPerPage READ resultsPerPage WRITE setResultsPerPage NOTIFY resultsPerPageChanged FINAL)
|
Q_PROPERTY(qsizetype resultsPerPage READ resultsPerPage WRITE setResultsPerPage NOTIFY resultsPerPageChanged FINAL)
|
||||||
|
|||||||
@@ -1,328 +0,0 @@
|
|||||||
#include "packsearchmodel.h"
|
|
||||||
|
|
||||||
PackSearchModel::PackSearchModel(QObject *parent) : QAbstractListModel{parent}
|
|
||||||
{
|
|
||||||
m_paginator = new PackSearchPaginator(this);
|
|
||||||
PaginationNotifier *notifier = static_cast<PaginationNotifier*>(m_paginator);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::resultsPerPageChanged,
|
|
||||||
this,
|
|
||||||
&PackSearchModel::resultsPerPageChanged
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::totalResultsChanged,
|
|
||||||
this,
|
|
||||||
&PackSearchModel::totalResultsChanged
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::totalPagesChanged,
|
|
||||||
this,
|
|
||||||
&PackSearchModel::totalPagesChanged
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::pageChanged,
|
|
||||||
this,
|
|
||||||
&PackSearchModel::pageChanged
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::pageChanged,
|
|
||||||
this,
|
|
||||||
&PackSearchModel::resetDataModel
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetchComplete,
|
|
||||||
this,
|
|
||||||
&PackSearchModel::resetState
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetching,
|
|
||||||
this,
|
|
||||||
&PackSearchModel::onPaginatorFetching
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
m_paginator,
|
|
||||||
&PaginationNotifier::queryChanged,
|
|
||||||
this,
|
|
||||||
&PackSearchModel::queryChanged
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::rowCount(const QModelIndex &) const -> int
|
|
||||||
{
|
|
||||||
if(m_paginator != nullptr)
|
|
||||||
{
|
|
||||||
return m_paginator->count();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::data(const QModelIndex &index, int role) const -> QVariant
|
|
||||||
{
|
|
||||||
if(m_paginator == nullptr)
|
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if(index.row() < 0 || index.row() >= m_paginator->count() )
|
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
WallpaperCache dataPoint = m_paginator->at(index.row());
|
|
||||||
|
|
||||||
QVariant data;
|
|
||||||
|
|
||||||
switch(static_cast<DataRole>(role))
|
|
||||||
{
|
|
||||||
case UuidRole:
|
|
||||||
data = dataPoint.uuid;
|
|
||||||
break;
|
|
||||||
case AuthorRole:
|
|
||||||
data = dataPoint.author;
|
|
||||||
break;
|
|
||||||
case DescriptionRole:
|
|
||||||
data = dataPoint.description;
|
|
||||||
break;
|
|
||||||
case NameRole:
|
|
||||||
data = dataPoint.name;
|
|
||||||
break;
|
|
||||||
case ThumbnailRole:
|
|
||||||
data = dataPoint.thumbnail;
|
|
||||||
break;
|
|
||||||
case CreatedDateRole:
|
|
||||||
data = dataPoint.createdDate;
|
|
||||||
break;
|
|
||||||
case AuthorIdRole:
|
|
||||||
data = dataPoint.authorId;
|
|
||||||
break;
|
|
||||||
case PriceRole:
|
|
||||||
data = dataPoint.price;
|
|
||||||
break;
|
|
||||||
case CurrencyRole:
|
|
||||||
data = dataPoint.currency;
|
|
||||||
break;
|
|
||||||
case DownloadCountRole:
|
|
||||||
data = dataPoint.downloadCount;
|
|
||||||
break;
|
|
||||||
case TypeRole:
|
|
||||||
data = dataPoint.type;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::index(int row, int column, const QModelIndex &parent) const -> QModelIndex
|
|
||||||
{
|
|
||||||
Q_UNUSED(parent)
|
|
||||||
|
|
||||||
if(row < 0 || row >= m_paginator->count())
|
|
||||||
return {};
|
|
||||||
|
|
||||||
return createIndex(row, column, &m_paginator[row]);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::columnCount(const QModelIndex &) const -> int
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::parent(const QModelIndex &) const -> QModelIndex
|
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::setData(const QModelIndex &, const QVariant &, int) -> bool
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::state() const -> PackSearchModel::State
|
|
||||||
{
|
|
||||||
return m_state;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::setState(State state) -> void
|
|
||||||
{
|
|
||||||
if (m_state == state)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_state = state;
|
|
||||||
emit stateChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::resetState() -> void
|
|
||||||
{
|
|
||||||
setState(Idle);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::resetDataModel() -> void
|
|
||||||
{
|
|
||||||
//invalidate previous model data
|
|
||||||
beginRemoveRows(QModelIndex(), 0, m_paginator->count());
|
|
||||||
endRemoveRows();
|
|
||||||
|
|
||||||
//signal new data
|
|
||||||
beginInsertRows(QModelIndex(), 0, m_paginator->count() - 1);
|
|
||||||
endInsertRows();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::hasNextPage() const -> bool
|
|
||||||
{
|
|
||||||
return m_paginator->page() < m_paginator->totalPages();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::hasPreviousPage() const -> bool
|
|
||||||
{
|
|
||||||
return m_paginator->page() > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::onPaginatorFetching() -> void
|
|
||||||
{
|
|
||||||
setState(Loading);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::roleNames() const -> QHash<int, QByteArray>
|
|
||||||
{
|
|
||||||
return m_dataRoles;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::errorString() const -> QString
|
|
||||||
{
|
|
||||||
return m_errorString;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::setErrorString(const QString &errorString) -> void
|
|
||||||
{
|
|
||||||
if (m_errorString == errorString)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_errorString = errorString;
|
|
||||||
emit errorStringChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::resultsPerPage() const -> qsizetype
|
|
||||||
{
|
|
||||||
if(m_paginator != nullptr)
|
|
||||||
{
|
|
||||||
return m_paginator->resultsPerPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::setResultsPerPage(qsizetype resultsPerPage) -> void
|
|
||||||
{
|
|
||||||
if(m_paginator != nullptr)
|
|
||||||
{
|
|
||||||
QFuture<void> future = QtConcurrent::run
|
|
||||||
(
|
|
||||||
[this, resultsPerPage]
|
|
||||||
{
|
|
||||||
m_paginator->setResultsPerPage(resultsPerPage);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::totalResults() const -> qsizetype
|
|
||||||
{
|
|
||||||
if(m_paginator != nullptr)
|
|
||||||
{
|
|
||||||
return m_paginator->totalResults();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::nextPage() -> void
|
|
||||||
{
|
|
||||||
if(m_paginator != nullptr)
|
|
||||||
{
|
|
||||||
QFuture<void> future = QtConcurrent::run
|
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->next();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::previousPage() -> void
|
|
||||||
{
|
|
||||||
if(m_paginator != nullptr)
|
|
||||||
{
|
|
||||||
QFuture<void> future = QtConcurrent::run
|
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->previous();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::query() const -> QString
|
|
||||||
{
|
|
||||||
if(m_paginator != nullptr)
|
|
||||||
{
|
|
||||||
return m_paginator->query();
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::setQuery(const QString &query) -> void
|
|
||||||
{
|
|
||||||
if(m_paginator != nullptr)
|
|
||||||
{
|
|
||||||
QFuture<void> future = QtConcurrent::run
|
|
||||||
(
|
|
||||||
[this, query]
|
|
||||||
{
|
|
||||||
m_paginator->setQuery(query);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
qsizetype PackSearchModel::page() const
|
|
||||||
{
|
|
||||||
if(m_paginator != nullptr)
|
|
||||||
{
|
|
||||||
return m_paginator->page();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::totalPages() const -> qsizetype
|
|
||||||
{
|
|
||||||
if(m_paginator != nullptr)
|
|
||||||
{
|
|
||||||
return m_paginator->totalPages();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,383 +0,0 @@
|
|||||||
/*
|
|
||||||
* Komplex Wallpaper Engine
|
|
||||||
* Copyright (C) 2026 @DigitalArtifex
|
|
||||||
* https://digitalartifex.dev - https://github.com/DigitalArtifex
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>
|
|
||||||
*/
|
|
||||||
#ifndef PackSearchModel_H
|
|
||||||
#define PackSearchModel_H
|
|
||||||
#include <QObject>
|
|
||||||
#include <QQmlEngine>
|
|
||||||
#include <QList>
|
|
||||||
#include <QStandardPaths>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QFile>
|
|
||||||
#include <QFileInfo>
|
|
||||||
#include <QJsonParseError>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QAbstractListModel>
|
|
||||||
#include <QProcess>
|
|
||||||
#include <QNetworkAccessManager>
|
|
||||||
#include <QNetworkReply>
|
|
||||||
#include <QNetworkRequest>
|
|
||||||
#include <QEventLoop>
|
|
||||||
#include <QtConcurrent/QtConcurrentRun>
|
|
||||||
|
|
||||||
#include "paginators/packsearchpaginator.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The PackSearchModel class
|
|
||||||
*/
|
|
||||||
class KOMPLEX_EXPORT PackSearchModel : public QAbstractListModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
QML_ELEMENT
|
|
||||||
public:
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Used to control the UI state
|
|
||||||
*/
|
|
||||||
enum State
|
|
||||||
{
|
|
||||||
Idle,
|
|
||||||
Loading,
|
|
||||||
Error
|
|
||||||
};
|
|
||||||
Q_ENUM(State)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Data roles used by the view to request data
|
|
||||||
*/
|
|
||||||
enum DataRole {
|
|
||||||
UuidRole = Qt::UserRole + 1,
|
|
||||||
AuthorRole,
|
|
||||||
AuthorIdRole,
|
|
||||||
DescriptionRole,
|
|
||||||
NameRole,
|
|
||||||
ThumbnailRole,
|
|
||||||
CreatedDateRole,
|
|
||||||
PriceRole,
|
|
||||||
CurrencyRole,
|
|
||||||
DownloadCountRole,
|
|
||||||
TypeRole
|
|
||||||
};
|
|
||||||
Q_ENUM(DataRole)
|
|
||||||
|
|
||||||
explicit PackSearchModel(QObject *parent = nullptr);
|
|
||||||
|
|
||||||
auto rowCount(const QModelIndex &parent = QModelIndex()) const -> int override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief data
|
|
||||||
* Used by the view to pull data from the model.
|
|
||||||
* Required by QAbstractListModel
|
|
||||||
* @param index
|
|
||||||
* @param role
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto data(
|
|
||||||
const QModelIndex &index,
|
|
||||||
int role = Qt::DisplayRole
|
|
||||||
) const -> QVariant override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief index
|
|
||||||
* Used by the view to create an index for the data point.
|
|
||||||
* Required by QAbstractListModel
|
|
||||||
* @param row
|
|
||||||
* @param column
|
|
||||||
* @param parent
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto index(
|
|
||||||
int row,
|
|
||||||
int column,
|
|
||||||
const QModelIndex &parent = QModelIndex()
|
|
||||||
) const -> QModelIndex override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief columnCount
|
|
||||||
* Required by QAbstractListModel, but just returns 0
|
|
||||||
* since we dont use cols
|
|
||||||
* @param parent
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto columnCount(
|
|
||||||
const QModelIndex &parent = QModelIndex()
|
|
||||||
) const -> int override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief parent
|
|
||||||
* @param index
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto parent(const QModelIndex &index) const -> QModelIndex override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief setData
|
|
||||||
* Required by QAbstractListModel but not used
|
|
||||||
* @param index
|
|
||||||
* @param value
|
|
||||||
* @param role
|
|
||||||
* @return true always
|
|
||||||
*/
|
|
||||||
auto setData(
|
|
||||||
const QModelIndex &index,
|
|
||||||
const QVariant &value,
|
|
||||||
int role = Qt::EditRole
|
|
||||||
) -> bool override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief state
|
|
||||||
* Current Model State
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto state() const -> State;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief roleNames
|
|
||||||
* Used to tell the view what data roles are available
|
|
||||||
* and their QML friendly names
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto roleNames() const -> QHash<int, QByteArray> override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief errorString
|
|
||||||
* User-friendly error string to be reported to the user
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto errorString() const -> QString;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief resultsPerPage
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto resultsPerPage() const -> qsizetype;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief setResultsPerPage
|
|
||||||
* @param resultsPerPage
|
|
||||||
*/
|
|
||||||
auto setResultsPerPage(qsizetype resultsPerPage) -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief totalResults
|
|
||||||
* Total number of results available
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto totalResults() const -> qsizetype;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief page
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto page() const -> qsizetype;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief totalPages
|
|
||||||
* Total pages based on the current resultsPerPage
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto totalPages() const -> qsizetype;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief nextPage
|
|
||||||
* Function for the QML frontend
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE auto nextPage() -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief previousPage
|
|
||||||
* Function for the QML frontend
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE auto previousPage() -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief query
|
|
||||||
* Current search query
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto query() const -> QString;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief setQuery
|
|
||||||
* Sets the current search query
|
|
||||||
* @param query
|
|
||||||
*/
|
|
||||||
auto setQuery(const QString &query) -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief hasNextPage
|
|
||||||
* Calculates if there are more pages based on the current page calculation
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto hasNextPage() const -> bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief hasPreviousPage
|
|
||||||
* If page is greater than 1, returns true
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto hasPreviousPage() const -> bool;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief onPaginatorFetching
|
|
||||||
* Sets current state to loading. Triggered when paginator's cache controller
|
|
||||||
* needs to fetch data from the remote endpoint.
|
|
||||||
*/
|
|
||||||
auto onPaginatorFetching() -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief setErrorString
|
|
||||||
* @param errorString
|
|
||||||
*/
|
|
||||||
auto setErrorString(const QString &errorString) -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief setState
|
|
||||||
* @param state
|
|
||||||
*/
|
|
||||||
auto setState(State state) -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief resetState
|
|
||||||
*/
|
|
||||||
auto resetState() -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief resetDataModel
|
|
||||||
* Clears the data model and creates a new one if data exists
|
|
||||||
*/
|
|
||||||
auto resetDataModel() -> void;
|
|
||||||
|
|
||||||
signals:
|
|
||||||
/**
|
|
||||||
* @brief stateChanged
|
|
||||||
* Signaled when reported state changes
|
|
||||||
*/
|
|
||||||
auto stateChanged() -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief errorStringChanged
|
|
||||||
* Signaled when reported error message changes
|
|
||||||
*/
|
|
||||||
auto errorStringChanged() -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief pageChanged
|
|
||||||
* Forwarding signal connected in constructor
|
|
||||||
*/
|
|
||||||
auto resultsPerPageChanged() -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief pageChanged
|
|
||||||
* Forwarding signal connected in constructor
|
|
||||||
*/
|
|
||||||
auto pageChanged() -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief pageChanged
|
|
||||||
* Forwarding signal connected in constructor
|
|
||||||
*/
|
|
||||||
auto totalResultsChanged() -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief pageChanged
|
|
||||||
* Forwarding signal connected in constructor
|
|
||||||
*/
|
|
||||||
auto totalPagesChanged() -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief pageChanged
|
|
||||||
* Forwarding signal connected in constructor
|
|
||||||
*/
|
|
||||||
auto queryChanged() -> void;
|
|
||||||
|
|
||||||
private:
|
|
||||||
/**
|
|
||||||
* Data role map that connects PackSearchModel::DataRole to it's QML accessor name
|
|
||||||
*/
|
|
||||||
static inline const QHash<int, QByteArray> m_dataRoles =
|
|
||||||
{
|
|
||||||
{
|
|
||||||
static_cast<int>(UuidRole),
|
|
||||||
QByteArray("uuid")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(AuthorRole),
|
|
||||||
QByteArray("author")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(AuthorIdRole),
|
|
||||||
QByteArray("authorId")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(DescriptionRole),
|
|
||||||
QByteArray("description")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(NameRole),
|
|
||||||
QByteArray("name")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(ThumbnailRole),
|
|
||||||
QByteArray("thumbnail")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(CreatedDateRole),
|
|
||||||
QByteArray("createdDate")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(PriceRole),
|
|
||||||
QByteArray("price")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(CurrencyRole),
|
|
||||||
QByteArray("currency")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(DownloadCountRole),
|
|
||||||
QByteArray("downloadCount")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(TypeRole),
|
|
||||||
QByteArray("type")
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
State m_state = Idle;
|
|
||||||
|
|
||||||
QString m_errorString = QString();
|
|
||||||
|
|
||||||
PackSearchPaginator *m_paginator = nullptr;
|
|
||||||
|
|
||||||
Q_PROPERTY(State state READ state WRITE setState RESET resetState NOTIFY stateChanged FINAL)
|
|
||||||
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
|
||||||
Q_PROPERTY(qsizetype resultsPerPage READ resultsPerPage WRITE setResultsPerPage NOTIFY resultsPerPageChanged FINAL)
|
|
||||||
Q_PROPERTY(qsizetype totalResults READ totalResults NOTIFY totalResultsChanged FINAL)
|
|
||||||
Q_PROPERTY(qsizetype totalPages READ totalPages NOTIFY totalPagesChanged FINAL)
|
|
||||||
Q_PROPERTY(qsizetype page READ page NOTIFY pageChanged FINAL)
|
|
||||||
Q_PROPERTY(bool hasNextPage READ hasNextPage NOTIFY pageChanged FINAL)
|
|
||||||
Q_PROPERTY(bool hasPreviousPage READ hasPreviousPage NOTIFY pageChanged FINAL)
|
|
||||||
Q_PROPERTY(QString query READ query WRITE setQuery NOTIFY queryChanged FINAL)
|
|
||||||
};
|
|
||||||
Q_DECLARE_METATYPE(PackSearchModel)
|
|
||||||
|
|
||||||
#endif // PackSearchModel_H
|
|
||||||
@@ -39,8 +39,6 @@ public:
|
|||||||
setUri(
|
setUri(
|
||||||
QString::fromUtf8(KOMPLEX_ENDPOINT_CUBEMAPS_FEATURED)
|
QString::fromUtf8(KOMPLEX_ENDPOINT_CUBEMAPS_FEATURED)
|
||||||
);
|
);
|
||||||
|
|
||||||
controller()->setWindowSize(20);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -39,8 +39,6 @@ public:
|
|||||||
setUri(
|
setUri(
|
||||||
QString::fromUtf8(KOMPLEX_ENDPOINT_IMAGES_FEATURED)
|
QString::fromUtf8(KOMPLEX_ENDPOINT_IMAGES_FEATURED)
|
||||||
);
|
);
|
||||||
|
|
||||||
controller()->setWindowSize(20);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -39,8 +39,6 @@ public:
|
|||||||
setUri(
|
setUri(
|
||||||
QString::fromUtf8(KOMPLEX_ENDPOINT_PACKS_FEATURED)
|
QString::fromUtf8(KOMPLEX_ENDPOINT_PACKS_FEATURED)
|
||||||
);
|
);
|
||||||
|
|
||||||
controller()->setWindowSize(20);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -39,8 +39,6 @@ public:
|
|||||||
setUri(
|
setUri(
|
||||||
QString::fromUtf8(KOMPLEX_ENDPOINT_SHADERS_FEATURED)
|
QString::fromUtf8(KOMPLEX_ENDPOINT_SHADERS_FEATURED)
|
||||||
);
|
);
|
||||||
|
|
||||||
controller()->setWindowSize(20);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -39,8 +39,6 @@ public:
|
|||||||
setUri(
|
setUri(
|
||||||
QString::fromUtf8(KOMPLEX_ENDPOINT_VIDEOS_FEATURED)
|
QString::fromUtf8(KOMPLEX_ENDPOINT_VIDEOS_FEATURED)
|
||||||
);
|
);
|
||||||
|
|
||||||
controller()->setWindowSize(20);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -62,12 +62,46 @@ public:
|
|||||||
return m_uri;
|
return m_uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief query
|
||||||
|
* Current query string, if the API Endpoint supports queries
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
[[nodiscard]]
|
||||||
|
auto query() const -> QString
|
||||||
|
{
|
||||||
|
return m_query;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief setQuery
|
||||||
|
* Sets the new query string and updates the controller
|
||||||
|
* @param query
|
||||||
|
*/
|
||||||
|
auto setQuery(const QString &query) -> void
|
||||||
|
{
|
||||||
|
if(query == m_query)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_query = query;
|
||||||
|
Q_EMIT queryChanged();
|
||||||
|
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/**
|
/**
|
||||||
* @brief uriChanged
|
* @brief uriChanged
|
||||||
*/
|
*/
|
||||||
auto uriChanged() -> void;
|
auto uriChanged() -> void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief queryChanged
|
||||||
|
*/
|
||||||
|
auto queryChanged() -> void;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* @brief fetch
|
* @brief fetch
|
||||||
@@ -90,11 +124,6 @@ protected:
|
|||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
if(queryable() && query().isEmpty())
|
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
QUrl url(
|
QUrl url(
|
||||||
QString::fromUtf8("%1/%2/%3").arg(
|
QString::fromUtf8("%1/%2/%3").arg(
|
||||||
KOMPLEX_API_HOST,
|
KOMPLEX_API_HOST,
|
||||||
@@ -109,7 +138,7 @@ protected:
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
QByteArray("query"),
|
QByteArray("query"),
|
||||||
query().toUtf8()
|
m_query.toUtf8()
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
QByteArray("offset"),
|
QByteArray("offset"),
|
||||||
@@ -152,28 +181,13 @@ protected:
|
|||||||
|
|
||||||
const QVariantMap sources = resultObject.value(QString::fromUtf8("src")).toObject().toVariantMap();
|
const QVariantMap sources = resultObject.value(QString::fromUtf8("src")).toObject().toVariantMap();
|
||||||
QMap<QString, QString> sourceMap;
|
QMap<QString, QString> sourceMap;
|
||||||
QMap<QString, QString> sizeMap;
|
|
||||||
|
|
||||||
QMapIterator<QString,QVariant> sourceIterator(sources);
|
QMapIterator<QString,QVariant> sourceIterator(sources);
|
||||||
|
|
||||||
while(sourceIterator.hasNext())
|
while(sourceIterator.hasNext())
|
||||||
{
|
{
|
||||||
sourceIterator.next();
|
sourceIterator.next();
|
||||||
|
sourceMap.insert(sourceIterator.key(), sourceIterator.value().toString());
|
||||||
QString url = sourceIterator.value().toString();
|
|
||||||
sourceMap.insert(sourceIterator.key(), url);
|
|
||||||
|
|
||||||
auto matches = s_sizeExpression.match(url);
|
|
||||||
|
|
||||||
if(matches.hasMatch())
|
|
||||||
{
|
|
||||||
QString size = matches.captured();
|
|
||||||
size.remove(QString::fromUtf8("w="));
|
|
||||||
size.remove(QString::fromUtf8("h="));
|
|
||||||
size.replace(QLatin1Char('&'), QLatin1Char('x'));
|
|
||||||
|
|
||||||
sizeMap.insert(sourceIterator.key(), std::move(size));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchedResults.append(
|
fetchedResults.append(
|
||||||
@@ -188,7 +202,6 @@ protected:
|
|||||||
resultObject.value(QString::fromUtf8("photographer_url")).toString(),
|
resultObject.value(QString::fromUtf8("photographer_url")).toString(),
|
||||||
resultObject.value(QString::fromUtf8("photographer_id")).toInteger(),
|
resultObject.value(QString::fromUtf8("photographer_id")).toInteger(),
|
||||||
std::move(sourceMap),
|
std::move(sourceMap),
|
||||||
std::move(sizeMap),
|
|
||||||
resultObject.value(QString::fromUtf8("url")).toString()
|
resultObject.value(QString::fromUtf8("url")).toString()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -294,13 +307,10 @@ private:
|
|||||||
QString m_uri;
|
QString m_uri;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief s_sizeExpression
|
* @brief m_query
|
||||||
* Regular expression used to extract size data from the url
|
* The query string used in fetch operations
|
||||||
*/
|
*/
|
||||||
inline static QRegularExpression s_sizeExpression = QRegularExpression
|
QString m_query;
|
||||||
(
|
|
||||||
QString::fromUtf8("[h]\\=\\d{1,}\\&[w]\\=\\d{1,}")
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // IMAGEPAGINATOR_H
|
#endif // IMAGEPAGINATOR_H
|
||||||
|
|||||||
@@ -41,8 +41,6 @@ public:
|
|||||||
setUri(
|
setUri(
|
||||||
QString::fromUtf8(KOMPLEX_ENDPOINT_IMAGES_SEARCH)
|
QString::fromUtf8(KOMPLEX_ENDPOINT_IMAGES_SEARCH)
|
||||||
);
|
);
|
||||||
|
|
||||||
setQueryable(true);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -39,8 +39,6 @@ public:
|
|||||||
setUri(
|
setUri(
|
||||||
QString::fromUtf8(KOMPLEX_ENDPOINT_PACKS_NEWEST)
|
QString::fromUtf8(KOMPLEX_ENDPOINT_PACKS_NEWEST)
|
||||||
);
|
);
|
||||||
|
|
||||||
controller()->setWindowSize(20);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+5
-7
@@ -16,8 +16,8 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>
|
* along with this program. If not, see <https://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
#ifndef PACKSEARCHPAGINATOR_H
|
#ifndef SEARCHPACKSPAGINATOR_H
|
||||||
#define PACKSEARCHPAGINATOR_H
|
#define SEARCHPACKSPAGINATOR_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
@@ -31,17 +31,15 @@
|
|||||||
|
|
||||||
#include "wallpaperpaginator.h"
|
#include "wallpaperpaginator.h"
|
||||||
|
|
||||||
class KOMPLEX_EXPORT PackSearchPaginator : public WallpaperPaginator
|
class KOMPLEX_EXPORT SearchPacksPaginator : public WallpaperPaginator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit PackSearchPaginator(QObject *parent = nullptr) : WallpaperPaginator(parent)
|
explicit SearchPacksPaginator(QObject *parent = nullptr) : WallpaperPaginator(parent)
|
||||||
{
|
{
|
||||||
setUri(
|
setUri(
|
||||||
QString::fromUtf8(KOMPLEX_ENDPOINT_PACKS_SEARCH)
|
QString::fromUtf8(KOMPLEX_ENDPOINT_PACKS_SEARCH)
|
||||||
);
|
);
|
||||||
|
|
||||||
setQueryable(true);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PACKSEARCHPAGINATOR_H
|
#endif // SEARCHPACKSPAGINATOR_H
|
||||||
@@ -62,12 +62,47 @@ public:
|
|||||||
return m_uri;
|
return m_uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief query
|
||||||
|
* Current query string, if the API Endpoint supports queries
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
[[nodiscard]]
|
||||||
|
auto query() const -> QString
|
||||||
|
{
|
||||||
|
return m_query;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief setQuery
|
||||||
|
* Sets the new query string and updates the controller
|
||||||
|
* @param query
|
||||||
|
*/
|
||||||
|
auto setQuery(const QString &query) -> void
|
||||||
|
{
|
||||||
|
if(query == m_query)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_query = query;
|
||||||
|
Q_EMIT queryChanged();
|
||||||
|
|
||||||
|
reset();
|
||||||
|
setOffset(0);
|
||||||
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/**
|
/**
|
||||||
* @brief uriChanged
|
* @brief uriChanged
|
||||||
*/
|
*/
|
||||||
auto uriChanged() -> void;
|
auto uriChanged() -> void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief queryChanged
|
||||||
|
*/
|
||||||
|
auto queryChanged() -> void;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* @brief fetch
|
* @brief fetch
|
||||||
@@ -90,11 +125,6 @@ protected:
|
|||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
if(queryable() && query().isEmpty())
|
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
QUrl url(
|
QUrl url(
|
||||||
QString::fromUtf8("%1/%2/%3").arg(
|
QString::fromUtf8("%1/%2/%3").arg(
|
||||||
KOMPLEX_API_HOST,
|
KOMPLEX_API_HOST,
|
||||||
@@ -109,7 +139,7 @@ protected:
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
QByteArray("query"),
|
QByteArray("query"),
|
||||||
query().toUtf8()
|
m_query.toUtf8()
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
QByteArray("offset"),
|
QByteArray("offset"),
|
||||||
@@ -228,12 +258,7 @@ protected:
|
|||||||
|
|
||||||
QNetworkReply *reply = manager->post(request, nullptr);
|
QNetworkReply *reply = manager->post(request, nullptr);
|
||||||
QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
||||||
|
QObject::connect(reply, &QNetworkReply::errorOccurred, &loop,
|
||||||
QObject::connect
|
|
||||||
(
|
|
||||||
reply,
|
|
||||||
&QNetworkReply::errorOccurred,
|
|
||||||
&loop,
|
|
||||||
[&loop](QNetworkReply::NetworkError error) -> void
|
[&loop](QNetworkReply::NetworkError error) -> void
|
||||||
{
|
{
|
||||||
loop.quit();
|
loop.quit();
|
||||||
|
|||||||
@@ -39,8 +39,6 @@ public:
|
|||||||
setUri(
|
setUri(
|
||||||
QString::fromUtf8(KOMPLEX_ENDPOINT_VIDEOS_SEARCH)
|
QString::fromUtf8(KOMPLEX_ENDPOINT_VIDEOS_SEARCH)
|
||||||
);
|
);
|
||||||
|
|
||||||
setQueryable(true);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -98,6 +98,11 @@ signals:
|
|||||||
*/
|
*/
|
||||||
auto uriChanged() -> void;
|
auto uriChanged() -> void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief queryChanged
|
||||||
|
*/
|
||||||
|
auto queryChanged() -> void;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* @brief fetch
|
* @brief fetch
|
||||||
@@ -120,11 +125,6 @@ protected:
|
|||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
if(queryable() && query().isEmpty())
|
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
QUrl url(
|
QUrl url(
|
||||||
QString::fromUtf8("%1/%2/%3").arg(
|
QString::fromUtf8("%1/%2/%3").arg(
|
||||||
KOMPLEX_API_HOST,
|
KOMPLEX_API_HOST,
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
VideoSearchModel::VideoSearchModel(QObject *parent) : QAbstractListModel{parent}
|
VideoSearchModel::VideoSearchModel(QObject *parent) : QAbstractListModel{parent}
|
||||||
{
|
{
|
||||||
|
setState(Loading);
|
||||||
|
|
||||||
m_paginator = new VideoSearchPaginator(this);
|
m_paginator = new VideoSearchPaginator(this);
|
||||||
PaginationNotifier *notifier = static_cast<PaginationNotifier*>(m_paginator);
|
PaginationNotifier *notifier = static_cast<PaginationNotifier*>(m_paginator);
|
||||||
|
|
||||||
@@ -35,25 +37,11 @@ VideoSearchModel::VideoSearchModel(QObject *parent) : QAbstractListModel{parent}
|
|||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
notifier,
|
notifier,
|
||||||
&PaginationNotifier::pageChanged,
|
&PaginationNotifier::dataChanged,
|
||||||
this,
|
this,
|
||||||
&VideoSearchModel::resetDataModel
|
&VideoSearchModel::resetDataModel
|
||||||
);
|
);
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetchComplete,
|
|
||||||
this,
|
|
||||||
&VideoSearchModel::resetState
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetching,
|
|
||||||
this,
|
|
||||||
&VideoSearchModel::onPaginatorFetching
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
m_paginator,
|
m_paginator,
|
||||||
&VideoSearchPaginator::queryChanged,
|
&VideoSearchPaginator::queryChanged,
|
||||||
@@ -74,17 +62,12 @@ auto VideoSearchModel::rowCount(const QModelIndex &) const -> int
|
|||||||
|
|
||||||
auto VideoSearchModel::data(const QModelIndex &index, int role) const -> QVariant
|
auto VideoSearchModel::data(const QModelIndex &index, int role) const -> QVariant
|
||||||
{
|
{
|
||||||
if(m_paginator == nullptr)
|
if(index.row() < 0 || m_paginator == nullptr)
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if(index.row() < 0 || index.row() >= m_paginator->count() )
|
VideoCache dataPoint = m_data.at(index.row());
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
VideoCache dataPoint = m_paginator->at(index.row());
|
|
||||||
|
|
||||||
QVariant data;
|
QVariant data;
|
||||||
|
|
||||||
@@ -126,10 +109,10 @@ auto VideoSearchModel::index(int row, int column, const QModelIndex &parent) con
|
|||||||
{
|
{
|
||||||
Q_UNUSED(parent)
|
Q_UNUSED(parent)
|
||||||
|
|
||||||
if(row < 0 || row >= m_paginator->count())
|
if(row < 0 || row >= m_data.count())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
return createIndex(row, column, &m_paginator[row]);
|
return createIndex(row, column, &m_data[row]);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto VideoSearchModel::columnCount(const QModelIndex &) const -> int
|
auto VideoSearchModel::columnCount(const QModelIndex &) const -> int
|
||||||
@@ -170,30 +153,37 @@ auto VideoSearchModel::resetState() -> void
|
|||||||
|
|
||||||
auto VideoSearchModel::resetDataModel() -> void
|
auto VideoSearchModel::resetDataModel() -> void
|
||||||
{
|
{
|
||||||
|
setState(Loading);
|
||||||
|
|
||||||
//invalidate previous model data
|
//invalidate previous model data
|
||||||
beginRemoveRows(QModelIndex(), 0, m_paginator->count());
|
beginRemoveRows(QModelIndex(), 0, m_data.count());
|
||||||
|
m_data.clear();
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
|
||||||
//signal new data
|
//signal new data
|
||||||
beginInsertRows(QModelIndex(), 0, m_paginator->count() - 1);
|
beginInsertRows(QModelIndex(), 0, m_paginator->count() - 1);
|
||||||
|
auto dataset = m_paginator->data();
|
||||||
|
|
||||||
|
for(const VideoCache& data : std::as_const(dataset))
|
||||||
|
{
|
||||||
|
m_data.append(data);
|
||||||
|
}
|
||||||
|
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
|
setState(Idle);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto VideoSearchModel::hasNextPage() const -> bool
|
auto VideoSearchModel::hasNextPage() -> bool
|
||||||
{
|
{
|
||||||
return m_paginator->page() < m_paginator->totalPages();
|
return m_paginator->page() < m_paginator->totalPages();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto VideoSearchModel::hasPreviousPage() const -> bool
|
auto VideoSearchModel::hasPreviousPage() -> bool
|
||||||
{
|
{
|
||||||
return m_paginator->page() > 0;
|
return m_paginator->page() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto VideoSearchModel::onPaginatorFetching() -> void
|
|
||||||
{
|
|
||||||
setState(Loading);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto VideoSearchModel::roleNames() const -> QHash<int, QByteArray>
|
auto VideoSearchModel::roleNames() const -> QHash<int, QByteArray>
|
||||||
{
|
{
|
||||||
return m_dataRoles;
|
return m_dataRoles;
|
||||||
@@ -229,13 +219,7 @@ auto VideoSearchModel::setResultsPerPage(qsizetype resultsPerPage) -> void
|
|||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->setResultsPerPage(resultsPerPage);
|
||||||
(
|
|
||||||
[this, resultsPerPage]
|
|
||||||
{
|
|
||||||
m_paginator->setResultsPerPage(resultsPerPage);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,31 +233,19 @@ auto VideoSearchModel::totalResults() const -> qsizetype
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto VideoSearchModel::nextPage() -> void
|
auto VideoSearchModel::nextPage() const -> void
|
||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->next();
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->next();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto VideoSearchModel::previousPage() -> void
|
auto VideoSearchModel::previousPage() const -> void
|
||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->previous();
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->previous();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,13 +263,7 @@ auto VideoSearchModel::setQuery(const QString &query) -> void
|
|||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->setQuery(query);
|
||||||
(
|
|
||||||
[this, query]
|
|
||||||
{
|
|
||||||
m_paginator->setQuery(query);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,6 @@
|
|||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
#include <QtConcurrent/QtConcurrentRun>
|
|
||||||
|
|
||||||
#include "paginators/videosearchpaginator.h"
|
#include "paginators/videosearchpaginator.h"
|
||||||
|
|
||||||
@@ -197,13 +196,13 @@ public:
|
|||||||
* @brief nextPage
|
* @brief nextPage
|
||||||
* Function for the QML frontend
|
* Function for the QML frontend
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE auto nextPage() -> void;
|
Q_INVOKABLE auto nextPage() const -> void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief previousPage
|
* @brief previousPage
|
||||||
* Function for the QML frontend
|
* Function for the QML frontend
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE auto previousPage() -> void;
|
Q_INVOKABLE auto previousPage() const -> void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief query
|
* @brief query
|
||||||
@@ -214,34 +213,12 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief setQuery
|
* @brief setQuery
|
||||||
* Sets the current search query
|
* Sets the current
|
||||||
* @param query
|
* @param query
|
||||||
*/
|
*/
|
||||||
auto setQuery(const QString &query) -> void;
|
auto setQuery(const QString &query) -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief hasNextPage
|
|
||||||
* Calculates if there are more pages based on the current page calculation
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto hasNextPage() const -> bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief hasPreviousPage
|
|
||||||
* If page is greater than 1, returns true
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto hasPreviousPage() const -> bool;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief onPaginatorFetching
|
|
||||||
* Sets current state to loading. Triggered when paginator's cache controller
|
|
||||||
* needs to fetch data from the remote endpoint.
|
|
||||||
*/
|
|
||||||
auto onPaginatorFetching() -> void;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief setErrorString
|
* @brief setErrorString
|
||||||
* @param errorString
|
* @param errorString
|
||||||
@@ -259,59 +236,23 @@ protected:
|
|||||||
*/
|
*/
|
||||||
auto resetState() -> void;
|
auto resetState() -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief resetDataModel
|
|
||||||
* Clears the data model and creates a new one if data exists
|
|
||||||
*/
|
|
||||||
auto resetDataModel() -> void;
|
auto resetDataModel() -> void;
|
||||||
|
|
||||||
|
auto hasNextPage() -> bool;
|
||||||
|
|
||||||
|
auto hasPreviousPage() -> bool;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/**
|
|
||||||
* @brief stateChanged
|
|
||||||
* Signaled when reported state changes
|
|
||||||
*/
|
|
||||||
auto stateChanged() -> void;
|
auto stateChanged() -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief errorStringChanged
|
|
||||||
* Signaled when reported error message changes
|
|
||||||
*/
|
|
||||||
auto errorStringChanged() -> void;
|
auto errorStringChanged() -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief pageChanged
|
|
||||||
* Forwarding signal connected in constructor
|
|
||||||
*/
|
|
||||||
auto resultsPerPageChanged() -> void;
|
auto resultsPerPageChanged() -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief pageChanged
|
|
||||||
* Forwarding signal connected in constructor
|
|
||||||
*/
|
|
||||||
auto pageChanged() -> void;
|
auto pageChanged() -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief pageChanged
|
|
||||||
* Forwarding signal connected in constructor
|
|
||||||
*/
|
|
||||||
auto totalResultsChanged() -> void;
|
auto totalResultsChanged() -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief pageChanged
|
|
||||||
* Forwarding signal connected in constructor
|
|
||||||
*/
|
|
||||||
auto totalPagesChanged() -> void;
|
auto totalPagesChanged() -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief pageChanged
|
|
||||||
* Forwarding signal connected in constructor
|
|
||||||
*/
|
|
||||||
auto queryChanged() -> void;
|
auto queryChanged() -> void;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
|
||||||
* Data role map that connects VideoSearchModel::DataRole to it's QML accessor name
|
|
||||||
*/
|
|
||||||
static inline const QHash<int, QByteArray> m_dataRoles =
|
static inline const QHash<int, QByteArray> m_dataRoles =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
@@ -357,6 +298,8 @@ private:
|
|||||||
|
|
||||||
VideoSearchPaginator *m_paginator = nullptr;
|
VideoSearchPaginator *m_paginator = nullptr;
|
||||||
|
|
||||||
|
mutable QList<VideoCache> m_data;
|
||||||
|
|
||||||
Q_PROPERTY(State state READ state WRITE setState RESET resetState NOTIFY stateChanged FINAL)
|
Q_PROPERTY(State state READ state WRITE setState RESET resetState NOTIFY stateChanged FINAL)
|
||||||
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
||||||
Q_PROPERTY(qsizetype resultsPerPage READ resultsPerPage WRITE setResultsPerPage NOTIFY resultsPerPageChanged FINAL)
|
Q_PROPERTY(qsizetype resultsPerPage READ resultsPerPage WRITE setResultsPerPage NOTIFY resultsPerPageChanged FINAL)
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="256" height="256">
|
|
||||||
<path d="M0 0 C84.48 0 168.96 0 256 0 C256 84.48 256 168.96 256 256 C171.52 256 87.04 256 0 256 C0 171.52 0 87.04 0 0 Z " fill="#181818" transform="translate(0,0)"/>
|
|
||||||
<path d="M0 0 C1.09441406 0.84304687 1.09441406 0.84304687 2.2109375 1.703125 C3.02304688 2.32703125 3.83515625 2.9509375 4.671875 3.59375 C16.47013653 13.39538265 25.38731594 28.22446593 27.03222656 43.60986328 C28.60593213 62.04285713 25.62016469 78.91524518 13.76953125 93.76171875 C5.01402855 103.96349254 -4.93033814 111.41182902 -17.7890625 115.703125 C-18.4694458 115.96569092 -19.1498291 116.22825684 -19.85083008 116.4987793 C-29.75386424 119.8404508 -40.1667607 119.02518869 -50.4765625 118.890625 C-57.1796875 118.82875 -63.8828125 118.766875 -70.7890625 118.703125 C-70.7890625 145.763125 -70.7890625 172.823125 -70.7890625 200.703125 C-108.4090625 200.703125 -146.0290625 200.703125 -184.7890625 200.703125 C-184.7890625 163.083125 -184.7890625 125.463125 -184.7890625 86.703125 C-157.7290625 86.703125 -130.6690625 86.703125 -102.7890625 86.703125 C-102.7890625 73.503125 -102.7890625 60.303125 -102.7890625 46.703125 C-99.26329541 30.24954527 -99.26329541 30.24954527 -96.2890625 24.578125 C-95.7784729 23.58437866 -95.7784729 23.58437866 -95.25756836 22.57055664 C-86.70637388 6.77129742 -71.67156051 -4.50909354 -54.7890625 -10.171875 C-36.32361252 -14.71432194 -15.42912627 -11.02876174 0 0 Z " fill="#FDFDFD" transform="translate(184.7890625,55.296875)"/>
|
|
||||||
<path d="M0 0 C27.06 0 54.12 0 82 0 C82 27.06 82 54.12 82 82 C54.94 82 27.88 82 0 82 C0 54.94 0 27.88 0 0 Z " fill="#181818" transform="translate(0,174)"/>
|
|
||||||
<path d="M0 0 C8.54223462 5.26240815 13.58712715 12.26138144 16.7265625 21.6796875 C17.61615271 33.71103045 16.47172139 42.47747774 8.6640625 51.9921875 C2.30756952 58.68544832 -5.98410523 62.52737517 -15.21582031 62.79321289 C-16.80274318 62.79305528 -18.38967179 62.78744838 -19.9765625 62.77734375 C-21.23324738 62.77522133 -21.23324738 62.77522133 -22.51531982 62.77305603 C-25.18472907 62.76746947 -27.8540537 62.75491944 -30.5234375 62.7421875 C-32.33593629 62.73717076 -34.14843639 62.73260816 -35.9609375 62.72851562 C-40.39846998 62.71750444 -44.83593941 62.70024905 -49.2734375 62.6796875 C-49.3730552 57.16623069 -49.4452566 51.65330922 -49.49316406 46.13916016 C-49.51315613 44.26732241 -49.54035918 42.39554612 -49.57519531 40.52392578 C-49.99909869 17.1469011 -49.99909869 17.1469011 -41.2734375 7.4296875 C-29.8843011 -4.33043054 -14.910255 -7.11351788 0 0 Z " fill="#1A1A1A" transform="translate(163.2734375,79.3203125)"/>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 2.6 KiB |
Reference in New Issue
Block a user