2017-07-13 10:26:03 +02:00
|
|
|
/*
|
2024-11-12 22:00:21 +02:00
|
|
|
* modstateview_moc.h, part of VCMI engine
|
2017-07-13 10:26:03 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
2013-08-22 17:22:49 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QAbstractTableModel>
|
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
|
2024-11-12 22:00:21 +02:00
|
|
|
class ModStateModel;
|
|
|
|
class ModState;
|
|
|
|
|
2013-08-22 17:22:49 +03:00
|
|
|
namespace ModFields
|
|
|
|
{
|
2018-04-13 07:34:58 +02:00
|
|
|
enum EModFields
|
|
|
|
{
|
|
|
|
NAME,
|
|
|
|
STATUS_ENABLED,
|
|
|
|
STATUS_UPDATE,
|
|
|
|
TYPE,
|
|
|
|
COUNT
|
|
|
|
};
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
2024-11-12 22:00:21 +02:00
|
|
|
enum class ModFilterMask : uint8_t
|
|
|
|
{
|
|
|
|
ALL,
|
|
|
|
AVAILABLE,
|
|
|
|
INSTALLED,
|
|
|
|
UPDATEABLE,
|
|
|
|
ENABLED,
|
|
|
|
DISABLED
|
|
|
|
};
|
|
|
|
|
2014-03-20 20:06:25 +03:00
|
|
|
namespace ModRoles
|
|
|
|
{
|
2018-04-13 07:34:58 +02:00
|
|
|
enum EModRoles
|
|
|
|
{
|
|
|
|
ValueRole = Qt::UserRole,
|
|
|
|
ModNameRole
|
|
|
|
};
|
2014-03-20 20:06:25 +03:00
|
|
|
}
|
|
|
|
|
2024-11-13 22:27:51 +02:00
|
|
|
class ModStateItemModel : public QAbstractItemModel
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
2024-11-12 22:00:21 +02:00
|
|
|
friend class CModFilterModel;
|
2013-08-22 17:22:49 +03:00
|
|
|
Q_OBJECT
|
|
|
|
|
2024-11-12 22:00:21 +02:00
|
|
|
std::shared_ptr<ModStateModel> model;
|
|
|
|
|
|
|
|
QStringList modNameToID;
|
2014-03-20 20:06:25 +03:00
|
|
|
// contains mapping mod -> numbered list of submods
|
|
|
|
// mods that have no parent located under "" key (empty string)
|
2024-11-12 22:00:21 +02:00
|
|
|
QMap<QString, QStringList> modIndex;
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
void endResetModel();
|
2014-01-30 15:35:17 +03:00
|
|
|
|
2014-03-20 20:06:25 +03:00
|
|
|
QString modIndexToName(const QModelIndex & index) const;
|
2023-03-27 00:10:44 +02:00
|
|
|
QString modTypeName(QString modTypeID) const;
|
2014-03-20 20:06:25 +03:00
|
|
|
|
2014-01-30 15:35:17 +03:00
|
|
|
QVariant getTextAlign(int field) const;
|
2024-11-12 22:00:21 +02:00
|
|
|
QVariant getValue(const ModState & mod, int field) const;
|
|
|
|
QVariant getText(const ModState & mod, int field) const;
|
|
|
|
QVariant getIcon(const ModState & mod, int field) const;
|
2018-04-13 07:34:58 +02:00
|
|
|
|
2013-08-22 17:22:49 +03:00
|
|
|
public:
|
2024-11-13 19:25:59 +02:00
|
|
|
explicit ModStateItemModel(std::shared_ptr<ModStateModel> model, QObject * parent = nullptr);
|
2014-03-20 20:06:25 +03:00
|
|
|
|
2013-08-22 17:22:49 +03:00
|
|
|
/// CModListContainer overrides
|
2024-11-12 22:00:21 +02:00
|
|
|
void reloadRepositories();
|
|
|
|
void modChanged(QString modID);
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
QVariant data(const QModelIndex & index, int role) const override;
|
2014-03-20 20:06:25 +03:00
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
int rowCount(const QModelIndex & parent) const override;
|
|
|
|
int columnCount(const QModelIndex & parent) const override;
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
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;
|
2013-08-22 17:22:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class CModFilterModel : public QSortFilterProxyModel
|
|
|
|
{
|
2024-11-12 22:00:21 +02:00
|
|
|
ModStateItemModel * base;
|
|
|
|
ModFilterMask filterMask;
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2014-03-20 20:06:25 +03:00
|
|
|
bool filterMatchesThis(const QModelIndex & source) const;
|
2024-11-14 18:42:30 +02:00
|
|
|
bool filterMatchesCategory(const QModelIndex & source) const;
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const override;
|
|
|
|
|
2013-08-22 17:22:49 +03:00
|
|
|
public:
|
2024-11-12 22:00:21 +02:00
|
|
|
void setTypeFilter(ModFilterMask filterMask);
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2024-11-12 22:00:21 +02:00
|
|
|
CModFilterModel(ModStateItemModel * model, QObject * parent = nullptr);
|
2013-08-22 17:22:49 +03:00
|
|
|
};
|