2017-07-13 10:26:03 +02:00
|
|
|
/*
|
|
|
|
* cmodlistmodel_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
|
|
|
|
*
|
|
|
|
*/
|
2013-08-22 17:22:49 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "cmodlist.h"
|
|
|
|
|
|
|
|
#include <QAbstractTableModel>
|
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
|
|
|
|
namespace ModFields
|
|
|
|
{
|
2018-04-13 07:34:58 +02:00
|
|
|
enum EModFields
|
|
|
|
{
|
|
|
|
NAME,
|
|
|
|
STATUS_ENABLED,
|
|
|
|
STATUS_UPDATE,
|
|
|
|
TYPE,
|
|
|
|
VERSION,
|
|
|
|
SIZE,
|
|
|
|
AUTHOR,
|
|
|
|
COUNT
|
|
|
|
};
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
class CModListModel : public QAbstractItemModel, public CModList
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2014-03-20 20:06:25 +03:00
|
|
|
QVector<QString> modNameToID;
|
|
|
|
// contains mapping mod -> numbered list of submods
|
|
|
|
// mods that have no parent located under "" key (empty string)
|
|
|
|
QMap<QString, QVector<QString>> 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;
|
|
|
|
|
2014-01-30 15:35:17 +03:00
|
|
|
QVariant getTextAlign(int field) const;
|
|
|
|
QVariant getValue(const CModEntry & mod, int field) const;
|
|
|
|
QVariant getText(const CModEntry & mod, int field) const;
|
|
|
|
QVariant getIcon(const CModEntry & mod, int field) const;
|
2018-04-13 07:34:58 +02:00
|
|
|
|
2013-08-22 17:22:49 +03:00
|
|
|
public:
|
2018-04-13 07:34:58 +02:00
|
|
|
explicit CModListModel(QObject * parent = 0);
|
2014-03-20 20:06:25 +03:00
|
|
|
|
2013-08-22 17:22:49 +03:00
|
|
|
/// CModListContainer overrides
|
2014-03-20 20:06:25 +03:00
|
|
|
void resetRepositories() override;
|
|
|
|
void addRepository(QVariantMap data) override;
|
2015-12-04 01:06:02 +02:00
|
|
|
void modChanged(QString modID) override;
|
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
|
|
|
|
|
|
|
signals:
|
2018-04-13 07:34:58 +02:00
|
|
|
|
2013-08-22 17:22:49 +03:00
|
|
|
public slots:
|
2018-04-13 07:34:58 +02:00
|
|
|
|
2013-08-22 17:22:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class CModFilterModel : public QSortFilterProxyModel
|
|
|
|
{
|
|
|
|
CModListModel * base;
|
|
|
|
int filteredType;
|
|
|
|
int filterMask;
|
|
|
|
|
2014-03-20 20:06:25 +03:00
|
|
|
bool filterMatchesThis(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:
|
|
|
|
void setTypeFilter(int filteredType, int filterMask);
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
CModFilterModel(CModListModel * model, QObject * parent = 0);
|
2013-08-22 17:22:49 +03:00
|
|
|
};
|