1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00
vcmi/launcher/modManager/modstateitemmodel_moc.h

104 lines
2.3 KiB
C++

/*
* modstateview_moc.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
#include <QAbstractTableModel>
#include <QSortFilterProxyModel>
class ModStateModel;
class ModState;
namespace ModFields
{
enum EModFields
{
NAME,
STATUS_ENABLED,
STATUS_UPDATE,
TYPE,
COUNT
};
}
enum class ModFilterMask : uint8_t
{
ALL,
AVAILABLE,
INSTALLED,
UPDATEABLE,
ENABLED,
DISABLED
};
namespace ModRoles
{
enum EModRoles
{
ValueRole = Qt::UserRole,
ModNameRole
};
}
class ModStateItemModel : public QAbstractItemModel
{
friend class CModFilterModel;
Q_OBJECT
std::shared_ptr<ModStateModel> model;
QStringList modNameToID;
// contains mapping mod -> numbered list of submods
// mods that have no parent located under "" key (empty string)
QMap<QString, QStringList> modIndex;
void endResetModel();
QString modIndexToName(const QModelIndex & index) const;
QString modTypeName(QString modTypeID) const;
QVariant getTextAlign(int field) const;
QVariant getValue(const ModState & mod, int field) const;
QVariant getText(const ModState & mod, int field) const;
QVariant getIcon(const ModState & mod, int field) const;
public:
explicit ModStateItemModel(QObject * parent = nullptr);
/// CModListContainer overrides
void reloadRepositories();
void modChanged(QString modID);
QVariant data(const QModelIndex & index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
int rowCount(const QModelIndex & parent) const override;
int columnCount(const QModelIndex & parent) const override;
QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex & child) const override;
Qt::ItemFlags flags(const QModelIndex & index) const override;
};
class CModFilterModel : public QSortFilterProxyModel
{
ModStateItemModel * base;
ModFilterMask filterMask;
bool filterMatchesThis(const QModelIndex & source) const;
bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const override;
public:
void setTypeFilter(ModFilterMask filterMask);
CModFilterModel(ModStateItemModel * model, QObject * parent = nullptr);
};