135 lines
2.6 KiB
C++
135 lines
2.6 KiB
C++
#pragma once
|
|
|
|
#include "common.h"
|
|
|
|
#include <QAbstractItemModel>
|
|
#include <QByteArray>
|
|
#include <QMetaObject>
|
|
#include <QObject>
|
|
#include <QValidator>
|
|
|
|
namespace Arc {
|
|
Q_NAMESPACE
|
|
|
|
enum class Column {
|
|
Size,
|
|
Type,
|
|
Name,
|
|
};
|
|
Q_ENUM_NS(Column)
|
|
|
|
enum class FileType {
|
|
Label,
|
|
MipTexture,
|
|
Normal,
|
|
Palette,
|
|
Picture,
|
|
Sound,
|
|
Texture,
|
|
};
|
|
Q_ENUM_NS(FileType)
|
|
|
|
enum class ArcType {
|
|
Pack,
|
|
Wad2,
|
|
};
|
|
Q_ENUM_NS(ArcType)
|
|
|
|
struct Node;
|
|
|
|
struct Dir : public std::vector<Node> {
|
|
using std::vector<Node>::vector;
|
|
|
|
Node *findNode(std::string const &name);
|
|
|
|
static Dir readArchive(std::istream &st, ArcType type);
|
|
};
|
|
|
|
struct File : public QByteArray {
|
|
using QByteArray::QByteArray;
|
|
};
|
|
|
|
struct Node : public Variant<Dir, File> {
|
|
using superType = Variant<Dir, File>;
|
|
|
|
Node() = default;
|
|
|
|
Node(Dir &&f, std::string &&n, FileType t = FileType::Normal);
|
|
Node(File &&f, std::string &&n, FileType t = FileType::Normal);
|
|
|
|
Node(Node const &) = default;
|
|
Node(Node &&) = default;
|
|
|
|
std::string name;
|
|
FileType type;
|
|
};
|
|
|
|
class Model : public QAbstractItemModel {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit Model(QObject *parent);
|
|
~Model();
|
|
|
|
QVariant data(QModelIndex const &index, int role) const override;
|
|
Qt::ItemFlags flags(QModelIndex const &index) const override;
|
|
QVariant headerData(int section, Qt::Orientation ori, int role)
|
|
const override;
|
|
QModelIndex index(int row,
|
|
int col,
|
|
QModelIndex const &parent = QModelIndex())
|
|
const override;
|
|
QModelIndex parent(QModelIndex const &index = QModelIndex())
|
|
const override;
|
|
int rowCount(QModelIndex const &index = QModelIndex()) const override;
|
|
int columnCount(QModelIndex const &index = QModelIndex()) const override;
|
|
|
|
Dir *dir() const;
|
|
|
|
public slots:
|
|
void setDir(Dir *dir);
|
|
void setDirToIndex(QModelIndex const &ind);
|
|
|
|
signals:
|
|
void dirChanged(Dir *from, Dir *to);
|
|
|
|
private:
|
|
Dir *m_dir;
|
|
};
|
|
|
|
struct ArcInfo {
|
|
ArcInfo(ArcType arcType) noexcept;
|
|
|
|
ArcType type;
|
|
std::size_t pathMaxChars;
|
|
QMetaObject validatorType;
|
|
};
|
|
|
|
class Arc : QObject {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit Arc(std::istream &st, QObject *parent = nullptr);
|
|
~Arc();
|
|
|
|
ArcInfo info;
|
|
Dir root;
|
|
QValidator *validator;
|
|
};
|
|
|
|
Option<ArcType> getArchiveType(std::istream &st) noexcept;
|
|
}
|
|
Q_DECLARE_METATYPE(Arc::Dir)
|
|
Q_DECLARE_METATYPE(Arc::File)
|
|
Q_DECLARE_METATYPE(Arc::Node)
|
|
|
|
static inline QDebug operator<<(QDebug debug, Arc::Node const &t) {
|
|
debug << "Arc::Node(" << t.name << ", ";
|
|
std::visit([&](auto &&arg) {debug << arg;},
|
|
static_cast<Variant<Arc::Dir, Arc::File>>(t));
|
|
debug << ")";
|
|
return debug;
|
|
}
|
|
|
|
// EOF
|