pollymc/launcher/pages/modplatform/legacy_ftb/ListModel.h

79 lines
1.9 KiB
C
Raw Normal View History

#pragma once
#include <modplatform/legacy_ftb/PackHelpers.h>
#include <RWStorage.h>
#include <QAbstractListModel>
#include <QSortFilterProxyModel>
#include <QThreadPool>
2018-04-06 18:38:59 +05:30
#include <QIcon>
#include <QStyledItemDelegate>
#include <functional>
namespace LegacyFTB {
typedef QMap<QString, QIcon> FTBLogoMap;
typedef std::function<void(QString)> LogoCallback;
class FilterModel : public QSortFilterProxyModel
{
2018-12-23 05:35:11 +05:30
Q_OBJECT
public:
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();
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;
private:
2018-07-15 18:21:05 +05:30
QMap<QString, Sorting> sortings;
Sorting currentSorting;
};
class ListModel : public QAbstractListModel
{
2018-07-15 18:21:05 +05:30
Q_OBJECT
private:
ModpackList modpacks;
2018-07-15 18:21:05 +05:30
QStringList m_failedLogos;
QStringList m_loadingLogos;
FTBLogoMap m_logoMap;
2018-07-15 18:21:05 +05:30
QMap<QString, LogoCallback> waitingCallbacks;
2018-07-15 18:21:05 +05:30
void requestLogo(QString file);
QString translatePackType(PackType type) const;
private slots:
2018-07-15 18:21:05 +05:30
void logoFailed(QString logo);
void logoLoaded(QString logo, QIcon out);
public:
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;
Qt::ItemFlags flags(const QModelIndex &index) const override;
void fill(ModpackList modpacks);
void addPack(Modpack modpack);
void clear();
void remove(int row);
Modpack at(int row);
2018-07-15 18:21:05 +05:30
void getLogo(const QString &logo, LogoCallback callback);
};
}