1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00
vcmi/launcher/modManager/modstateitemmodel_moc.h
2024-11-26 13:55:46 +00:00

105 lines
2.4 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 final : 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(std::shared_ptr<ModStateModel> model, QObject * parent);
/// 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) const override;
QModelIndex parent(const QModelIndex & child) const override;
Qt::ItemFlags flags(const QModelIndex & index) const override;
};
class CModFilterModel final : public QSortFilterProxyModel
{
ModStateItemModel * base;
ModFilterMask filterMask;
bool filterMatchesThis(const QModelIndex & source) const;
bool filterMatchesCategory(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);
};