quake-tools/source/quam/archive.cc
2019-10-03 17:06:05 -04:00

124 lines
2.9 KiB
C++

#include "quam/archive.h"
#include <QMetaEnum>
Arc::FileType Arc::getFileType(int n) {
if(int t = QMetaEnum::fromType<Arc::FileType>().value(n); n != -1) {
return Arc::FileType(t);
} else {
throw std::range_error("invalid file type");
}
}
ArcDir::iterator ArcDir::findNode(std::string const &name) {
return std::find_if(begin(), end(), [&name](ArcNode const &node) {
return node.name == name;
});
}
ArcNode::ArcNode(ArcDir &&f, std::string &&n, Arc::FileType t) :
super_type(std::move(f)),
name(std::move(n)),
type(t)
{
}
ArcNode::ArcNode(ArcFile &&f, std::string &&n, Arc::FileType t) :
super_type(std::move(f)),
name(std::move(n)),
type(t)
{
}
/*
PakDirModel::PakDirModel(PakDir const *root, QObject *parent) :
QAbstractItemModel{parent},
m_root{root}
{
}
PakDirModel::~PakDirModel() {
}
QVariant PakDirModel::data(QModelIndex const &index, int role) const {
if(!index.isValid()) {
return QVariant{};
}
auto node = static_cast<PakNode *>(index.internalPointer());
switch(role) {
case Qt::DecorationRole:
if(index.column() == Arc::ColumnName) {
auto icon =
std::holds_alternative<PakDir>(*node) ? "folder"
: "text-x-generic";
return QVariant{QIcon::fromTheme(icon)};
}
break;
case Qt::DisplayRole:
switch(index.column()) {
case Arc::ColumnSize:
if(auto file = std::get_if<PakFile>(node)) {
return QVariant{QString::number(file->size())};
}
break;
case Arc::ColumnName:
return QVariant{tr(node->name.data())};
}
default:
break;
}
return QVariant{};
}
Qt::ItemFlags PakDirModel::flags(QModelIndex const &index) const {
if(!index.isValid()) {
return Qt::NoItemFlags;
} else {
return Qt::ItemIsSelectable |
Qt::ItemIsDragEnabled |
Qt::ItemIsEnabled |
Qt::ItemNeverHasChildren;
}
}
QVariant PakDirModel::headerData(int section,
Qt::Orientation orientation,
int role) const {
if(orientation == Qt::Horizontal && role == Qt::DisplayRole) {
switch(section) {
case Arc::ColumnSize: return QVariant{tr("Size")};
case Arc::ColumnName: return QVariant{tr("Name")};
}
}
return QVariant{};
}
QModelIndex PakDirModel::index(int row,
int col,
QModelIndex const &parent) const {
if(!hasIndex(row, col, parent) || row > m_root->size()) {
return QModelIndex{};
} else {
// despite index data being const, this function does not take a const
// pointer, which is very annoying!
return createIndex(row, col, const_cast<PakNode *>(&m_root->at(row)));
}
}
QModelIndex PakDirModel::parent(QModelIndex const &) const {
return QModelIndex{};
}
int PakDirModel::rowCount(QModelIndex const &) const {
return m_root->size();
}
int PakDirModel::columnCount(QModelIndex const &) const {
return Arc::ColumnMax;
}
*/
// EOF