General update
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QEventLoop>
|
||||
#include <QtConcurrent/QtConcurrentRun>
|
||||
|
||||
#include "paginators/imagesearchpaginator.h"
|
||||
|
||||
@@ -74,11 +75,19 @@ public:
|
||||
OriginalUrlRole,
|
||||
MediumUrlRole,
|
||||
LargeUrlRole,
|
||||
ExtraLargeUrlRole
|
||||
ExtraLargeUrlRole,
|
||||
PortraitSizeRole,
|
||||
LandscapeSizeRole,
|
||||
SmallSizeRole,
|
||||
OriginalSizeRole,
|
||||
MediumSizeRole,
|
||||
LargeSizeRole,
|
||||
ExtraLargeSizeRole
|
||||
};
|
||||
Q_ENUM(DataRole)
|
||||
|
||||
explicit ImageSearchModel(QObject *parent = nullptr);
|
||||
~ImageSearchModel();
|
||||
|
||||
auto rowCount(const QModelIndex &parent = QModelIndex()) const -> int override;
|
||||
|
||||
@@ -200,13 +209,13 @@ public:
|
||||
* @brief nextPage
|
||||
* Function for the QML frontend
|
||||
*/
|
||||
Q_INVOKABLE auto nextPage() const -> void;
|
||||
Q_INVOKABLE auto nextPage() -> void;
|
||||
|
||||
/**
|
||||
* @brief previousPage
|
||||
* Function for the QML frontend
|
||||
*/
|
||||
Q_INVOKABLE auto previousPage() const -> void;
|
||||
Q_INVOKABLE auto previousPage() -> void;
|
||||
|
||||
/**
|
||||
* @brief query
|
||||
@@ -217,20 +226,36 @@ public:
|
||||
|
||||
/**
|
||||
* @brief setQuery
|
||||
* Sets the current
|
||||
* 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 setErrorString
|
||||
* Sets the error string to be displayed to the user
|
||||
* @param errorString
|
||||
*/
|
||||
auto setErrorString(const QString &errorString) -> void;
|
||||
|
||||
/**
|
||||
* @brief setState
|
||||
* Sets the current state for QML
|
||||
* @param state
|
||||
*/
|
||||
auto setState(State state) -> void;
|
||||
@@ -240,23 +265,67 @@ protected:
|
||||
*/
|
||||
auto resetState() -> void;
|
||||
|
||||
/**
|
||||
* @brief resetDataModel
|
||||
* Clears the data model and creates a new one if data exists
|
||||
*/
|
||||
auto resetDataModel() -> void;
|
||||
|
||||
auto hasNextPage() -> bool;
|
||||
|
||||
auto hasPreviousPage() -> bool;
|
||||
/**
|
||||
* @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:
|
||||
/**
|
||||
* @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:
|
||||
/**
|
||||
* @brief m_dataRoles
|
||||
* Data role map that connects ImageSearchModel::DataRole to it's QML accessor name
|
||||
*/
|
||||
static inline const QHash<int, QByteArray> m_dataRoles =
|
||||
{
|
||||
{
|
||||
@@ -310,6 +379,34 @@ private:
|
||||
{
|
||||
static_cast<int>(ExtraLargeUrlRole),
|
||||
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;
|
||||
@@ -318,8 +415,6 @@ private:
|
||||
|
||||
ImageSearchPaginator *m_paginator = nullptr;
|
||||
|
||||
mutable QList<ImageCache> m_data;
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user