MultiMC5/application/pages/modplatform/FtbListModel.h

74 lines
1.9 KiB
C
Raw Normal View History

#pragma once
#include <modplatform/ftb/PackHelpers.h>
#include <RWStorage.h>
#include <QAbstractListModel>
#include <QSortFilterProxyModel>
#include <QThreadPool>
2018-04-06 13:08:59 +00:00
#include <QIcon>
#include <QStyledItemDelegate>
#include <functional>
2018-04-06 13:08:59 +00:00
typedef QMap<QString, QIcon> FtbLogoMap;
typedef std::function<void(QString)> LogoCallback;
class FtbFilterModel : public QSortFilterProxyModel
{
public:
2018-07-15 12:51:05 +00:00
FtbFilterModel(QObject* parent = Q_NULLPTR);
enum Sorting {
ByName,
ByGameVersion
};
const QMap<QString, Sorting> getAvailableSortings();
QString translateCurrentSorting();
void setSorting(Sorting sorting);
Sorting getCurrentSorting();
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;
private:
2018-07-15 12:51:05 +00:00
QMap<QString, Sorting> sortings;
Sorting currentSorting;
};
class FtbListModel : public QAbstractListModel
{
2018-07-15 12:51:05 +00:00
Q_OBJECT
private:
2018-07-15 12:51:05 +00:00
FtbModpackList modpacks;
QStringList m_failedLogos;
QStringList m_loadingLogos;
FtbLogoMap m_logoMap;
QMap<QString, LogoCallback> waitingCallbacks;
2018-07-15 12:51:05 +00:00
void requestLogo(QString file);
QString translatePackType(FtbPackType type) const;
private slots:
2018-07-15 12:51:05 +00:00
void logoFailed(QString logo);
void logoLoaded(QString logo, QIcon out);
public:
2018-07-15 12:51:05 +00:00
FtbListModel(QObject *parent);
~FtbListModel();
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
2018-07-15 12:51:05 +00:00
void fill(FtbModpackList modpacks);
void addPack(FtbModpack modpack);
void clear();
void remove(int row);
2018-07-15 12:51:05 +00:00
FtbModpack at(int row);
void getLogo(const QString &logo, LogoCallback callback);
};