removed some duplicate code

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97
2025-03-30 00:32:59 +02:00
parent ab3bfb0f74
commit 29cff14fd6
52 changed files with 928 additions and 2318 deletions

View File

@@ -43,10 +43,7 @@ class ResourceModel : public QAbstractListModel {
virtual auto debugName() const -> QString;
virtual auto metaEntryBase() const -> QString = 0;
inline int rowCount(const QModelIndex& parent) const override
{
return parent.isValid() ? 0 : static_cast<int>(m_packs.size());
}
inline int rowCount(const QModelIndex& parent) const override { return parent.isValid() ? 0 : static_cast<int>(m_packs.size()); }
inline int columnCount(const QModelIndex& parent) const override { return parent.isValid() ? 0 : 1; }
inline auto flags(const QModelIndex& index) const -> Qt::ItemFlags override { return QAbstractListModel::flags(index); }
@@ -77,13 +74,10 @@ class ResourceModel : public QAbstractListModel {
void setSearchTerm(QString term) { m_search_term = term; }
virtual ResourceAPI::SearchArgs createSearchArguments() = 0;
virtual ResourceAPI::SearchCallbacks createSearchCallbacks() { return {}; }
virtual ResourceAPI::VersionSearchArgs createVersionsArguments(const QModelIndex&) = 0;
virtual ResourceAPI::VersionSearchCallbacks createVersionsCallbacks(const QModelIndex&) { return {}; }
virtual ResourceAPI::ProjectInfoArgs createInfoArguments(const QModelIndex&) = 0;
virtual ResourceAPI::ProjectInfoCallbacks createInfoCallbacks(const QModelIndex&) { return {}; }
/** Requests the API for more entries. */
virtual void search();
@@ -114,22 +108,6 @@ class ResourceModel : public QAbstractListModel {
auto getCurrentSortingMethodByIndex() const -> std::optional<ResourceAPI::SortingMethod>;
/** Converts a JSON document to a common array format.
*
* This is needed so that different providers, with different JSON structures, can be parsed
* uniformally. You NEED to re-implement this if you intend on using the default callbacks.
*/
virtual auto documentToArray(QJsonDocument&) const -> QJsonArray;
/** Functions to load data into a pack.
*
* Those are needed for the same reason as documentToArray, and NEED to be re-implemented in the same way.
*/
virtual void loadIndexedPack(ModPlatform::IndexedPack&, QJsonObject&);
virtual void loadExtraPackInfo(ModPlatform::IndexedPack&, QJsonObject&);
virtual void loadIndexedPackVersions(ModPlatform::IndexedPack&, QJsonArray&);
virtual bool isPackInstalled(ModPlatform::IndexedPack::Ptr) const { return false; }
protected:
@@ -159,14 +137,14 @@ class ResourceModel : public QAbstractListModel {
private:
/* Default search request callbacks */
void searchRequestSucceeded(QJsonDocument&);
void searchRequestForOneSucceeded(QJsonDocument&);
void searchRequestSucceeded(QList<ModPlatform::IndexedPack::Ptr>&);
void searchRequestForOneSucceeded(ModPlatform::IndexedPack&);
void searchRequestFailed(QString reason, int network_error_code);
void searchRequestAborted();
void versionRequestSucceeded(QJsonDocument&, ModPlatform::IndexedPack&, const QModelIndex&);
void versionRequestSucceeded(QVector<ModPlatform::IndexedVersion>&, QVariant, const QModelIndex&);
void infoRequestSucceeded(QJsonDocument&, ModPlatform::IndexedPack&, const QModelIndex&);
void infoRequestSucceeded(ModPlatform::IndexedPack&, const QModelIndex&);
signals:
void versionListUpdated(const QModelIndex& index);