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