2018-03-03 20:22:00 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-11-03 22:48:12 +00:00
|
|
|
#include <modplatform/legacy_ftb/PackHelpers.h>
|
2018-04-01 18:24:28 +00:00
|
|
|
#include <RWStorage.h>
|
|
|
|
|
2018-04-07 20:36:57 +00:00
|
|
|
#include <QAbstractListModel>
|
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
#include <QThreadPool>
|
2018-04-06 13:08:59 +00:00
|
|
|
#include <QIcon>
|
2018-08-01 22:52:31 +00:00
|
|
|
#include <QStyledItemDelegate>
|
2018-04-01 18:24:28 +00:00
|
|
|
|
2018-04-07 20:36:57 +00:00
|
|
|
#include <functional>
|
|
|
|
|
2019-11-03 22:48:12 +00:00
|
|
|
namespace LegacyFTB {
|
|
|
|
|
|
|
|
typedef QMap<QString, QIcon> FTBLogoMap;
|
2018-04-07 14:15:58 +00:00
|
|
|
typedef std::function<void(QString)> LogoCallback;
|
2018-03-03 20:22:00 +00:00
|
|
|
|
2019-11-03 22:48:12 +00:00
|
|
|
class FilterModel : public QSortFilterProxyModel
|
2018-03-03 20:22:00 +00:00
|
|
|
{
|
2018-12-23 00:05:11 +00:00
|
|
|
Q_OBJECT
|
2018-03-03 20:22:00 +00:00
|
|
|
public:
|
2019-11-03 22:48:12 +00:00
|
|
|
FilterModel(QObject* parent = Q_NULLPTR);
|
2018-07-15 12:51:05 +00:00
|
|
|
enum Sorting {
|
|
|
|
ByName,
|
|
|
|
ByGameVersion
|
|
|
|
};
|
|
|
|
const QMap<QString, Sorting> getAvailableSortings();
|
|
|
|
QString translateCurrentSorting();
|
|
|
|
void setSorting(Sorting sorting);
|
|
|
|
Sorting getCurrentSorting();
|
2018-03-03 20:22:00 +00:00
|
|
|
|
|
|
|
protected:
|
2018-07-15 12:51:05 +00:00
|
|
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
|
|
|
|
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
|
2018-03-03 20:22:00 +00:00
|
|
|
|
|
|
|
private:
|
2018-07-15 12:51:05 +00:00
|
|
|
QMap<QString, Sorting> sortings;
|
|
|
|
Sorting currentSorting;
|
2018-03-03 20:22:00 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-11-03 22:48:12 +00:00
|
|
|
class ListModel : public QAbstractListModel
|
2018-03-03 20:22:00 +00:00
|
|
|
{
|
2018-07-15 12:51:05 +00:00
|
|
|
Q_OBJECT
|
2018-03-03 20:22:00 +00:00
|
|
|
private:
|
2019-11-03 22:48:12 +00:00
|
|
|
ModpackList modpacks;
|
2018-07-15 12:51:05 +00:00
|
|
|
QStringList m_failedLogos;
|
|
|
|
QStringList m_loadingLogos;
|
2019-11-03 22:48:12 +00:00
|
|
|
FTBLogoMap m_logoMap;
|
2018-07-15 12:51:05 +00:00
|
|
|
QMap<QString, LogoCallback> waitingCallbacks;
|
2018-04-01 18:24:28 +00:00
|
|
|
|
2018-07-15 12:51:05 +00:00
|
|
|
void requestLogo(QString file);
|
2019-11-03 22:48:12 +00:00
|
|
|
QString translatePackType(PackType type) const;
|
2018-04-01 18:24:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
private slots:
|
2018-07-15 12:51:05 +00:00
|
|
|
void logoFailed(QString logo);
|
|
|
|
void logoLoaded(QString logo, QIcon out);
|
2018-03-03 20:22:00 +00:00
|
|
|
|
|
|
|
public:
|
2019-11-03 22:48:12 +00:00
|
|
|
ListModel(QObject *parent);
|
|
|
|
~ListModel();
|
2018-07-15 12:51:05 +00:00
|
|
|
int rowCount(const QModelIndex &parent) const override;
|
|
|
|
int columnCount(const QModelIndex &parent) const override;
|
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
2018-08-01 22:52:31 +00:00
|
|
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
2018-03-03 20:22:00 +00:00
|
|
|
|
2019-11-03 22:48:12 +00:00
|
|
|
void fill(ModpackList modpacks);
|
|
|
|
void addPack(Modpack modpack);
|
2018-08-01 22:52:31 +00:00
|
|
|
void clear();
|
|
|
|
void remove(int row);
|
2018-03-03 20:22:00 +00:00
|
|
|
|
2019-11-03 22:48:12 +00:00
|
|
|
Modpack at(int row);
|
2018-07-15 12:51:05 +00:00
|
|
|
void getLogo(const QString &logo, LogoCallback callback);
|
2018-03-03 20:22:00 +00:00
|
|
|
};
|
2019-11-03 22:48:12 +00:00
|
|
|
|
|
|
|
}
|