refactor(RD): clear up sorting methods
This refactors the sorting methods to join every bit of it into a single list, easing maintanance. It also removes the weird index contraint on the list of methods by adding an index field to the DS that holds the method. Lastly, it puts the available methods on their respective API, so other resources on the same API can re-use them later on. Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
@ -23,9 +23,6 @@
|
||||
|
||||
namespace ResourceDownload {
|
||||
|
||||
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
|
||||
const char* ModrinthModModel::sorts[5]{ "relevance", "downloads", "follows", "updated", "newest" };
|
||||
|
||||
ModrinthModModel::ModrinthModModel(BaseInstance const& base) : ModModel(base, new ModrinthAPI) {}
|
||||
|
||||
void ModrinthModModel::loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj)
|
||||
|
@ -41,10 +41,6 @@ class ModrinthModModel : public ModModel {
|
||||
void loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonArray& arr) override;
|
||||
|
||||
auto documentToArray(QJsonDocument& obj) const -> QJsonArray override;
|
||||
|
||||
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
|
||||
static const char* sorts[5];
|
||||
inline auto getSorts() const -> const char** override { return sorts; };
|
||||
};
|
||||
|
||||
} // namespace ResourceDownload
|
||||
|
@ -50,12 +50,7 @@ ModrinthModPage::ModrinthModPage(ModDownloadDialog* dialog, BaseInstance& instan
|
||||
m_model = new ModrinthModModel(instance);
|
||||
m_ui->packView->setModel(m_model);
|
||||
|
||||
// index is used to set the sorting with the modrinth api
|
||||
m_ui->sortByBox->addItem(tr("Sort by Relevance"));
|
||||
m_ui->sortByBox->addItem(tr("Sort by Downloads"));
|
||||
m_ui->sortByBox->addItem(tr("Sort by Follows"));
|
||||
m_ui->sortByBox->addItem(tr("Sort by Last Updated"));
|
||||
m_ui->sortByBox->addItem(tr("Sort by Newest"));
|
||||
addSortings();
|
||||
|
||||
// sometimes Qt just ignores virtual slots and doesn't work as intended it seems,
|
||||
// so it's best not to connect them in the parent's constructor...
|
||||
|
Reference in New Issue
Block a user