1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00
vcmi/launcher/modManager/cmodlistmodel_moc.cpp
Ivan Savenko 208df34fc2 bigfixing & new file: launcher/jsonutils.cpp
- launcher uses json parser from vcmi lib instead of one from Qt #1469
- fixed abilities overrides for some creatures #1476
- fixed hero portraits in seer huts #1402
- ttf fonts will render text in utf-8 mode. Not really useful at this point
- new settings entry, available in launcher: encoding. Unused for now.
2013-09-21 18:29:26 +00:00

201 lines
4.2 KiB
C++

#include "StdInc.h"
#include "cmodlistmodel_moc.h"
#include <QIcon>
namespace ModFields
{
static const QString names [ModFields::COUNT] =
{
"",
"",
"modType",
"name",
"version",
"size",
"author"
};
static const QString header [ModFields::COUNT] =
{
"", // status icon
"", // status icon
"Type",
"Name",
"Version",
"Size (KB)",
"Author"
};
}
namespace ModStatus
{
static const QString iconDelete = "icons:mod-delete.png";
static const QString iconDisabled = "icons:mod-disabled.png";
static const QString iconDownload = "icons:mod-download.png";
static const QString iconEnabled = "icons:mod-enabled.png";
static const QString iconUpdate = "icons:mod-update.png";
}
CModListModel::CModListModel(QObject *parent) :
QAbstractTableModel(parent)
{
}
QString CModListModel::modIndexToName(int index) const
{
return indexToName[index];
}
QVariant CModListModel::data(const QModelIndex &index, int role) const
{
if (index.isValid())
{
auto mod = getMod(modIndexToName(index.row()));
if (index.column() == ModFields::STATUS_ENABLED)
{
if (role == Qt::DecorationRole)
{
if (mod.isEnabled())
return QIcon(ModStatus::iconEnabled);
if (mod.isDisabled())
return QIcon(ModStatus::iconDisabled);
return QVariant();
}
}
if (index.column() == ModFields::STATUS_UPDATE)
{
if (role == Qt::DecorationRole)
{
if (mod.isUpdateable())
return QIcon(ModStatus::iconUpdate);
if (!mod.isInstalled())
return QIcon(ModStatus::iconDownload);
return QVariant();
}
}
if (role == Qt::DisplayRole)
{
return mod.getValue(ModFields::names[index.column()]);
}
}
return QVariant();
}
int CModListModel::rowCount(const QModelIndex &) const
{
return indexToName.size();
}
int CModListModel::columnCount(const QModelIndex &) const
{
return ModFields::COUNT;
}
Qt::ItemFlags CModListModel::flags(const QModelIndex &) const
{
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
}
QVariant CModListModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role == Qt::DisplayRole && orientation == Qt::Horizontal)
return ModFields::header[section];
return QVariant();
}
void CModListModel::resetRepositories()
{
beginResetModel();
CModList::resetRepositories();
endResetModel();
}
void CModListModel::addRepository(QVariantMap data)
{
beginResetModel();
CModList::addRepository(data);
endResetModel();
}
void CModListModel::setLocalModList(QVariantMap data)
{
beginResetModel();
CModList::setLocalModList(data);
endResetModel();
}
void CModListModel::setModSettings(QVariant data)
{
beginResetModel();
CModList::setModSettings(data);
endResetModel();
}
void CModListModel::endResetModel()
{
indexToName = getModList();
QAbstractItemModel::endResetModel();
}
void CModFilterModel::setTypeFilter(int filteredType, int filterMask)
{
this->filterMask = filterMask;
this->filteredType = filteredType;
invalidateFilter();
}
bool CModFilterModel::filterMatches(int modIndex) const
{
CModEntry mod = base->getMod(base->modIndexToName(modIndex));
return (mod.getModStatus() & filterMask) == filteredType;
}
bool CModFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
if (filterMatches(source_row))
return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
return false;
}
bool CModFilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
assert(left.column() == right.column());
CModEntry mod = base->getMod(base->modIndexToName(left.row()));
switch (left.column())
{
case ModFields::STATUS_ENABLED:
{
return (mod.getModStatus() & (ModStatus::ENABLED | ModStatus::INSTALLED))
< (mod.getModStatus() & (ModStatus::ENABLED | ModStatus::INSTALLED));
}
case ModFields::STATUS_UPDATE:
{
return (mod.getModStatus() & (ModStatus::UPDATEABLE | ModStatus::INSTALLED))
< (mod.getModStatus() & (ModStatus::UPDATEABLE | ModStatus::INSTALLED));
}
default:
{
return QSortFilterProxyModel::lessThan(left, right);
}
}
}
CModFilterModel::CModFilterModel(CModListModel * model, QObject * parent):
QSortFilterProxyModel(parent),
base(model),
filteredType(ModStatus::MASK_NONE),
filterMask(ModStatus::MASK_NONE)
{
setSourceModel(model);
}