add Project object and some metaobject crap
This commit is contained in:
parent
c6eb45589c
commit
69fe7cf9ca
|
@ -46,7 +46,10 @@ add_executable(
|
||||||
source/quam/main_window.h
|
source/quam/main_window.h
|
||||||
source/quam/main_window.ui
|
source/quam/main_window.ui
|
||||||
source/quam/pak.cc
|
source/quam/pak.cc
|
||||||
source/quam/pak.h)
|
source/quam/pak.h
|
||||||
|
source/quam/project.cc
|
||||||
|
source/quam/project.h
|
||||||
|
source/quam/project.ui)
|
||||||
|
|
||||||
make_qt_project(quam)
|
make_qt_project(quam)
|
||||||
|
|
||||||
|
|
|
@ -1,28 +1,20 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "quam/main_window.h"
|
#include "quam/main_window.h"
|
||||||
#include "quam/pak.h"
|
#include "quam/project.h"
|
||||||
|
|
||||||
#include <QAbstractItemModel>
|
|
||||||
#include <QErrorMessage>
|
#include <QErrorMessage>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QSortFilterProxyModel>
|
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) :
|
MainWindow::MainWindow(QWidget *parent) :
|
||||||
QMainWindow{parent},
|
QMainWindow{parent},
|
||||||
Ui::MainWindow{},
|
Ui::MainWindow{},
|
||||||
m_directory{},
|
m_errors{new QErrorMessage{this}}
|
||||||
m_errors{new QErrorMessage{this}},
|
|
||||||
m_model{nullptr},
|
|
||||||
m_sorter{nullptr}
|
|
||||||
{
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
|
||||||
actionClose->setShortcut(QKeySequence{QKeySequence::Close});
|
actionClose->setShortcut(QKeySequence{QKeySequence::Close});
|
||||||
actionOpen->setShortcut(QKeySequence{QKeySequence::Open});
|
actionOpen->setShortcut(QKeySequence{QKeySequence::Open});
|
||||||
actionQuit->setShortcut(QKeySequence{QKeySequence::Quit});
|
actionQuit->setShortcut(QKeySequence{QKeySequence::Quit});
|
||||||
|
|
||||||
tableView->sortByColumn(Pak::ColumnSize, Qt::AscendingOrder);
|
|
||||||
tableView->resizeColumnsToContents();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow() {
|
MainWindow::~MainWindow() {
|
||||||
|
@ -41,11 +33,8 @@ void MainWindow::fileOpen() {
|
||||||
if(!fileName.isEmpty()) {
|
if(!fileName.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
auto st = openReadBin(fileName.toStdString());
|
auto st = openReadBin(fileName.toStdString());
|
||||||
m_directory = readPak(st);
|
auto pak = readPak(st);
|
||||||
m_model = new PakDirModel{&m_directory, this};
|
new Project{std::move(pak), m_errors, mdiArea};
|
||||||
m_sorter = new PakDirModelSorter{m_model};
|
|
||||||
m_sorter->setSourceModel(m_model);
|
|
||||||
tableView->setModel(m_sorter);
|
|
||||||
} catch(std::exception const &exc) {
|
} catch(std::exception const &exc) {
|
||||||
m_errors->showMessage(tr(exc.what()));
|
m_errors->showMessage(tr(exc.what()));
|
||||||
}
|
}
|
||||||
|
@ -53,10 +42,9 @@ void MainWindow::fileOpen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::fileClose() {
|
void MainWindow::fileClose() {
|
||||||
tableView->setModel(nullptr);
|
if(auto win = mdiArea->activeSubWindow()) {
|
||||||
delete m_sorter;
|
mdiArea->removeSubWindow(win);
|
||||||
delete m_model;
|
}
|
||||||
m_directory = PakDir{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// EOF
|
// EOF
|
||||||
|
|
|
@ -6,9 +6,7 @@
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
class QAbstractItemModel;
|
|
||||||
class QErrorMessage;
|
class QErrorMessage;
|
||||||
class QSortFilterProxyModel;
|
|
||||||
|
|
||||||
class MainWindow : public QMainWindow, private Ui::MainWindow {
|
class MainWindow : public QMainWindow, private Ui::MainWindow {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -22,10 +20,7 @@ public slots:
|
||||||
void fileClose();
|
void fileClose();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PakDir m_directory;
|
|
||||||
QErrorMessage *m_errors;
|
QErrorMessage *m_errors;
|
||||||
QAbstractItemModel *m_model;
|
|
||||||
QSortFilterProxyModel *m_sorter;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// EOF
|
// EOF
|
||||||
|
|
|
@ -16,46 +16,19 @@
|
||||||
<widget class="QWidget" name="centralwidget">
|
<widget class="QWidget" name="centralwidget">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QSplitter" name="splitter">
|
<widget class="QMdiArea" name="mdiArea">
|
||||||
<property name="orientation">
|
<property name="viewMode">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>QMdiArea::TabbedView</enum>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QTableView" name="tableView">
|
<property name="documentMode">
|
||||||
<property name="verticalScrollBarPolicy">
|
|
||||||
<enum>Qt::ScrollBarAlwaysOn</enum>
|
|
||||||
</property>
|
|
||||||
<property name="horizontalScrollBarPolicy">
|
|
||||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
|
||||||
</property>
|
|
||||||
<property name="autoScroll">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="tabKeyNavigation">
|
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="alternatingRowColors">
|
<property name="tabsClosable">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="selectionMode">
|
<property name="tabsMovable">
|
||||||
<enum>QAbstractItemView::SingleSelection</enum>
|
|
||||||
</property>
|
|
||||||
<property name="selectionBehavior">
|
|
||||||
<enum>QAbstractItemView::SelectRows</enum>
|
|
||||||
</property>
|
|
||||||
<property name="showGrid">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="sortingEnabled">
|
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<attribute name="horizontalHeaderVisible">
|
|
||||||
<bool>true</bool>
|
|
||||||
</attribute>
|
|
||||||
<attribute name="verticalHeaderVisible">
|
|
||||||
<bool>false</bool>
|
|
||||||
</attribute>
|
|
||||||
</widget>
|
|
||||||
<widget class="QPlainTextEdit" name="textEdit"/>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
@ -101,7 +74,8 @@
|
||||||
</action>
|
</action>
|
||||||
<action name="actionClose">
|
<action name="actionClose">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset theme="document-close"/>
|
<iconset theme="document-close">
|
||||||
|
<normaloff>.</normaloff>.</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Close</string>
|
<string>&Close</string>
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "quam/pak.h"
|
#include "quam/pak.h"
|
||||||
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
#include <QMetaEnum>
|
||||||
|
|
||||||
struct PakHeader {
|
struct PakHeader {
|
||||||
quint32 dirOffset;
|
quint32 dirOffset;
|
||||||
|
@ -106,6 +107,15 @@ PakDir readPak(std::istream &st) {
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PakDirRoot::PakDirRoot(PakDir &&root, QObject *parent) :
|
||||||
|
QObject{parent},
|
||||||
|
PakDir{std::move(root)}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PakDirRoot::~PakDirRoot() {
|
||||||
|
}
|
||||||
|
|
||||||
PakDirModel::PakDirModel(PakDir const *root, QObject *parent) :
|
PakDirModel::PakDirModel(PakDir const *root, QObject *parent) :
|
||||||
QAbstractItemModel{parent},
|
QAbstractItemModel{parent},
|
||||||
m_root{root}
|
m_root{root}
|
||||||
|
@ -121,10 +131,11 @@ QVariant PakDirModel::data(QModelIndex const &index, int role) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto node = static_cast<PakNode *>(index.internalPointer());
|
auto node = static_cast<PakNode *>(index.internalPointer());
|
||||||
|
auto col = Pak::Column(index.column());
|
||||||
|
|
||||||
switch(role) {
|
switch(role) {
|
||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
if(index.column() == Pak::ColumnName) {
|
if(col == Pak::Column::Name) {
|
||||||
auto icon =
|
auto icon =
|
||||||
std::holds_alternative<PakDir>(*node) ? "folder"
|
std::holds_alternative<PakDir>(*node) ? "folder"
|
||||||
: "text-x-generic";
|
: "text-x-generic";
|
||||||
|
@ -132,13 +143,13 @@ QVariant PakDirModel::data(QModelIndex const &index, int role) const {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
switch(index.column()) {
|
switch(col) {
|
||||||
case Pak::ColumnSize:
|
case Pak::Column::Size:
|
||||||
if(auto file = std::get_if<PakFile>(node)) {
|
if(auto file = std::get_if<PakFile>(node)) {
|
||||||
return QVariant{QString::number(file->size())};
|
return QVariant{QString::number(file->size())};
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Pak::ColumnName:
|
case Pak::Column::Name:
|
||||||
return QVariant{tr(node->name.data())};
|
return QVariant{tr(node->name.data())};
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -162,9 +173,9 @@ QVariant PakDirModel::headerData(int section,
|
||||||
Qt::Orientation orientation,
|
Qt::Orientation orientation,
|
||||||
int role) const {
|
int role) const {
|
||||||
if(orientation == Qt::Horizontal && role == Qt::DisplayRole) {
|
if(orientation == Qt::Horizontal && role == Qt::DisplayRole) {
|
||||||
switch(section) {
|
switch(Pak::Column(section)) {
|
||||||
case Pak::ColumnSize: return QVariant{tr("Size")};
|
case Pak::Column::Size: return QVariant{tr("Size")};
|
||||||
case Pak::ColumnName: return QVariant{tr("Name")};
|
case Pak::Column::Name: return QVariant{tr("Name")};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QVariant{};
|
return QVariant{};
|
||||||
|
@ -191,7 +202,7 @@ int PakDirModel::rowCount(QModelIndex const &) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
int PakDirModel::columnCount(QModelIndex const &) const {
|
int PakDirModel::columnCount(QModelIndex const &) const {
|
||||||
return Pak::ColumnMax;
|
return QMetaEnum::fromType<Pak::Column>().keyCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
PakDirModelSorter::~PakDirModelSorter() {
|
PakDirModelSorter::~PakDirModelSorter() {
|
||||||
|
|
|
@ -4,11 +4,13 @@
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
namespace Pak {
|
namespace Pak {
|
||||||
enum PakColumn {
|
Q_NAMESPACE
|
||||||
ColumnSize,
|
|
||||||
ColumnName,
|
enum class Column {
|
||||||
ColumnMax,
|
Size,
|
||||||
|
Name,
|
||||||
};
|
};
|
||||||
|
Q_ENUM_NS(Column)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct PakNode;
|
struct PakNode;
|
||||||
|
@ -39,6 +41,14 @@ struct PakNode : public std::variant<PakDir, PakFile> {
|
||||||
};
|
};
|
||||||
Q_DECLARE_METATYPE(PakNode)
|
Q_DECLARE_METATYPE(PakNode)
|
||||||
|
|
||||||
|
class PakDirRoot : public QObject, public PakDir {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit PakDirRoot(PakDir &&root, QObject *parent);
|
||||||
|
virtual ~PakDirRoot();
|
||||||
|
};
|
||||||
|
|
||||||
class PakDirModel : public QAbstractItemModel {
|
class PakDirModel : public QAbstractItemModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
|
41
source/quam/project.cc
Normal file
41
source/quam/project.cc
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
#include "common.h"
|
||||||
|
#include "quam/project.h"
|
||||||
|
|
||||||
|
#include <QAbstractItemModel>
|
||||||
|
#include <QErrorMessage>
|
||||||
|
#include <QMdiArea>
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
|
Project::Project(QErrorMessage *errors, QMdiArea *parent) :
|
||||||
|
QMdiSubWindow{parent},
|
||||||
|
Ui::Project{},
|
||||||
|
m_errors{errors}
|
||||||
|
{
|
||||||
|
auto widget = new QWidget(this);
|
||||||
|
setupUi(widget);
|
||||||
|
setWidget(widget);
|
||||||
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
showMaximized();
|
||||||
|
}
|
||||||
|
|
||||||
|
Project::Project(PakDir &&dir, QErrorMessage *errors, QMdiArea *parent) :
|
||||||
|
Project{errors, parent}
|
||||||
|
{
|
||||||
|
auto root = new PakDirRoot{std::move(dir), this};
|
||||||
|
auto model = new PakDirModel{root, this};
|
||||||
|
setupModel(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
Project::~Project() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void Project::setupModel(QAbstractItemModel *model) {
|
||||||
|
m_model = model;
|
||||||
|
m_sorter = new QSortFilterProxyModel{this};
|
||||||
|
m_sorter->setSourceModel(m_model);
|
||||||
|
tableView->setModel(m_sorter);
|
||||||
|
tableView->sortByColumn(int(Pak::Column::Name), Qt::AscendingOrder);
|
||||||
|
tableView->resizeColumnsToContents();
|
||||||
|
}
|
||||||
|
|
||||||
|
// EOF
|
31
source/quam/project.h
Normal file
31
source/quam/project.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "quam/pak.h"
|
||||||
|
#include "quam/ui_project.h"
|
||||||
|
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QMdiSubWindow>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
class QAbstractItemModel;
|
||||||
|
class QErrorMessage;
|
||||||
|
class QSortFilterProxyModel;
|
||||||
|
|
||||||
|
class Project : public QMdiSubWindow, private Ui::Project {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit Project(PakDir &&dir, QErrorMessage *errors, QMdiArea *parent);
|
||||||
|
virtual ~Project();
|
||||||
|
|
||||||
|
private:
|
||||||
|
explicit Project(QErrorMessage *errors, QMdiArea *parent);
|
||||||
|
|
||||||
|
void setupModel(QAbstractItemModel *model);
|
||||||
|
|
||||||
|
QErrorMessage *m_errors;
|
||||||
|
QAbstractItemModel *m_model;
|
||||||
|
QSortFilterProxyModel *m_sorter;
|
||||||
|
};
|
||||||
|
|
||||||
|
// EOF
|
67
source/quam/project.ui
Normal file
67
source/quam/project.ui
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>Project</class>
|
||||||
|
<widget class="QWidget" name="Project">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>640</width>
|
||||||
|
<height>480</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Project View</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QSplitter" name="splitter">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<widget class="QTableView" name="tableView">
|
||||||
|
<property name="verticalScrollBarPolicy">
|
||||||
|
<enum>Qt::ScrollBarAlwaysOn</enum>
|
||||||
|
</property>
|
||||||
|
<property name="horizontalScrollBarPolicy">
|
||||||
|
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||||
|
</property>
|
||||||
|
<property name="autoScroll">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="tabKeyNavigation">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="alternatingRowColors">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="selectionMode">
|
||||||
|
<enum>QAbstractItemView::SingleSelection</enum>
|
||||||
|
</property>
|
||||||
|
<property name="selectionBehavior">
|
||||||
|
<enum>QAbstractItemView::SelectRows</enum>
|
||||||
|
</property>
|
||||||
|
<property name="showGrid">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="sortingEnabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<attribute name="horizontalHeaderVisible">
|
||||||
|
<bool>true</bool>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="horizontalHeaderStretchLastSection">
|
||||||
|
<bool>true</bool>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="verticalHeaderVisible">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
|
</widget>
|
||||||
|
<widget class="QPlainTextEdit" name="textEdit"/>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
Loading…
Reference in New Issue
Block a user