Add project explorer
This commit is contained in:
parent
cb427dccd0
commit
1b9f8f40f4
@ -20,7 +20,7 @@ target_link_libraries(
|
||||
OxStd
|
||||
NostalgiaCommon
|
||||
NostalgiaCore
|
||||
NostalgiaStudioStatic
|
||||
NostalgiaStudio
|
||||
NostalgiaStudioJson
|
||||
)
|
||||
|
||||
|
@ -6,7 +6,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
add_library(
|
||||
NostalgiaStudioStatic
|
||||
NostalgiaStudio
|
||||
newwizard.cpp
|
||||
oxfstreeview.cpp
|
||||
project.cpp
|
||||
@ -14,27 +14,11 @@ add_library(
|
||||
|
||||
set_property(
|
||||
TARGET
|
||||
NostalgiaStudioStatic
|
||||
NostalgiaStudio
|
||||
PROPERTY
|
||||
POSITION_INDEPENDENT_CODE ON
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
NostalgiaStudioStatic
|
||||
Qt5::Core
|
||||
Qt5::Widgets
|
||||
OxFS
|
||||
OxStd
|
||||
)
|
||||
|
||||
add_library(
|
||||
NostalgiaStudio
|
||||
SHARED
|
||||
newwizard.cpp
|
||||
oxfstreeview.cpp
|
||||
project.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
NostalgiaStudio
|
||||
Qt5::Core
|
||||
|
@ -6,12 +6,168 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include <QVector>
|
||||
|
||||
#include "oxfstreeview.hpp"
|
||||
|
||||
namespace nostalgia {
|
||||
namespace studio {
|
||||
|
||||
using namespace ox;
|
||||
|
||||
OxFSFile::OxFSFile(FileSystem *fs, QString path, OxFSFile *parentItem) {
|
||||
m_fs = fs;
|
||||
m_path = path;
|
||||
m_parentItem = parentItem;
|
||||
}
|
||||
|
||||
OxFSFile::~OxFSFile() {
|
||||
qDeleteAll(m_childItems);
|
||||
}
|
||||
|
||||
void OxFSFile::appendChild(OxFSFile*) {
|
||||
}
|
||||
|
||||
OxFSFile *OxFSFile::child(int row) {
|
||||
if (m_fs) {
|
||||
QVector<DirectoryListing<QString>> ls;
|
||||
m_fs->ls(m_path.toUtf8(), &ls);
|
||||
auto ch = new OxFSFile(m_fs, m_path + "/" + ls[row].name, this);
|
||||
m_childItems.push_back(ch);
|
||||
return ch;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
int OxFSFile::childCount() const {
|
||||
if (m_fs) {
|
||||
QVector<DirectoryListing<QString>> ls;
|
||||
m_fs->ls(m_path.toUtf8(), &ls);
|
||||
return ls.size();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int OxFSFile::columnCount() const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
QVariant OxFSFile::data(int) const {
|
||||
return m_path.mid(m_path.lastIndexOf('/') + 1);
|
||||
}
|
||||
|
||||
int OxFSFile::row() const {
|
||||
if (m_parentItem) {
|
||||
return m_parentItem->m_childItems.indexOf(const_cast<OxFSFile*>(this));
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
OxFSFile *OxFSFile::parentItem() {
|
||||
return m_parentItem;
|
||||
}
|
||||
|
||||
|
||||
// OxFSModel
|
||||
|
||||
OxFSModel::OxFSModel(FileSystem *fs, QObject *parent) {
|
||||
m_rootItem = new OxFSFile(fs, "");
|
||||
}
|
||||
|
||||
OxFSModel::~OxFSModel() {
|
||||
if (m_rootItem) {
|
||||
delete m_rootItem;
|
||||
}
|
||||
}
|
||||
|
||||
QVariant OxFSModel::data(const QModelIndex &index, int role) const {
|
||||
if (!index.isValid() || role != Qt::DisplayRole) {
|
||||
return QVariant();
|
||||
} else {
|
||||
OxFSFile *item = static_cast<OxFSFile*>(index.internalPointer());
|
||||
return item->data(index.column());
|
||||
}
|
||||
}
|
||||
|
||||
Qt::ItemFlags OxFSModel::flags(const QModelIndex &index) const {
|
||||
if (!index.isValid()) {
|
||||
return 0;
|
||||
} else {
|
||||
return QAbstractItemModel::flags(index);
|
||||
}
|
||||
}
|
||||
|
||||
QVariant OxFSModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||
return QVariant();
|
||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
|
||||
return m_rootItem->data(section);
|
||||
} else {
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex OxFSModel::index(int row, int column, const QModelIndex &parent) const {
|
||||
if (!hasIndex(row, column, parent)) {
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
OxFSFile *parentItem;
|
||||
if (!parent.isValid()) {
|
||||
parentItem = m_rootItem;
|
||||
} else {
|
||||
parentItem = static_cast<OxFSFile*>(parent.internalPointer());
|
||||
}
|
||||
|
||||
OxFSFile *childItem = parentItem->child(row);
|
||||
if (childItem) {
|
||||
return createIndex(row, column, childItem);
|
||||
} else {
|
||||
return QModelIndex();
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex OxFSModel::parent(const QModelIndex &index) const {
|
||||
if (!index.isValid()) {
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
OxFSFile *childItem = static_cast<OxFSFile*>(index.internalPointer());
|
||||
OxFSFile *parentItem = childItem->parentItem();
|
||||
if (parentItem == m_rootItem) {
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
return createIndex(parentItem->row(), 0, parentItem);
|
||||
}
|
||||
|
||||
int OxFSModel::rowCount(const QModelIndex &parent) const {
|
||||
if (parent.column() > 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
OxFSFile *parentItem;
|
||||
if (!parent.isValid()) {
|
||||
parentItem = m_rootItem;
|
||||
} else {
|
||||
parentItem = static_cast<OxFSFile*>(parent.internalPointer());
|
||||
}
|
||||
|
||||
return parentItem->childCount();
|
||||
}
|
||||
|
||||
int OxFSModel::columnCount(const QModelIndex &parent) const {
|
||||
if (parent.isValid()) {
|
||||
return static_cast<OxFSFile*>(parent.internalPointer())->columnCount();
|
||||
} else {
|
||||
return m_rootItem->columnCount();
|
||||
}
|
||||
}
|
||||
|
||||
void OxFSModel::setupModelData(const QStringList &lines, OxFSFile *parent) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -8,31 +8,71 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
#include <QModelIndex>
|
||||
#include <QVector>
|
||||
#include <QVariant>
|
||||
|
||||
#include <ox/fs/filesystem.hpp>
|
||||
|
||||
namespace nostalgia {
|
||||
namespace studio {
|
||||
|
||||
class OxFSFile {
|
||||
private:
|
||||
QList<OxFSFile*> m_childItems;
|
||||
QList<QVariant> m_itemData;
|
||||
OxFSFile *m_parentItem;
|
||||
ox::FileSystem *m_fs = nullptr;
|
||||
OxFSFile *m_parentItem = nullptr;
|
||||
QString m_path;
|
||||
QVector<OxFSFile*> m_childItems;
|
||||
|
||||
public:
|
||||
explicit OxFSFile(const QList<QVariant> &data, OxFSFile *parentItem = 0);
|
||||
~OxFSFile();
|
||||
OxFSFile(ox::FileSystem *fs, QString path, OxFSFile *parentItem = nullptr);
|
||||
|
||||
void appendChild(OxFSFile *child);
|
||||
~OxFSFile();
|
||||
|
||||
OxFSFile *child(int row);
|
||||
int childCount() const;
|
||||
int columnCount() const;
|
||||
QVariant data(int column) const;
|
||||
int row() const;
|
||||
OxFSFile *parentItem();
|
||||
void appendChild(OxFSFile *child);
|
||||
|
||||
OxFSFile *child(int row);
|
||||
|
||||
int childCount() const;
|
||||
|
||||
int columnCount() const;
|
||||
|
||||
QVariant data(int column) const;
|
||||
|
||||
int row() const;
|
||||
|
||||
OxFSFile *parentItem();
|
||||
};
|
||||
|
||||
class OxFSModel: public QAbstractItemModel {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
OxFSFile *m_rootItem = nullptr;
|
||||
|
||||
public:
|
||||
explicit OxFSModel(ox::FileSystem *fs, QObject *parent = 0);
|
||||
|
||||
~OxFSModel();
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const override;
|
||||
|
||||
QModelIndex index(int row, int column,
|
||||
const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
QModelIndex parent(const QModelIndex &index) const override;
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
private:
|
||||
void setupModelData(const QStringList &lines, OxFSFile *parent);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -22,6 +22,9 @@ Project::Project(QString path) {
|
||||
}
|
||||
|
||||
Project::~Project() {
|
||||
if (m_fs) {
|
||||
delete m_fs;
|
||||
}
|
||||
}
|
||||
|
||||
void Project::create() {
|
||||
@ -29,7 +32,7 @@ void Project::create() {
|
||||
|
||||
m_romBuff = QSharedPointer<QByteArray>(new QByteArray(1024, 0));
|
||||
FileSystem32::format(m_romBuff->data(), m_romBuff->size(), true);
|
||||
m_fs = QSharedPointer<FileSystem>(createFileSystem(m_romBuff->data(), m_romBuff->size()));
|
||||
m_fs = createFileSystem(m_romBuff->data(), m_romBuff->size());
|
||||
|
||||
m_fs->mkdir("/Tilesets");
|
||||
|
||||
@ -45,7 +48,9 @@ int Project::open() {
|
||||
if (file.exists()) {
|
||||
file.open(QIODevice::ReadOnly);
|
||||
if (file.read(m_romBuff->data(), file.size()) > 0) {
|
||||
m_fs = QSharedPointer<FileSystem>(createFileSystem(m_romBuff->data(), m_romBuff->size()));
|
||||
m_fs = createFileSystem(m_romBuff->data(), m_romBuff->size());
|
||||
|
||||
m_fs->mkdir("/Tilesets");
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
@ -62,5 +67,9 @@ void Project::save() {
|
||||
file.close();
|
||||
}
|
||||
|
||||
FileSystem *Project::romFS() {
|
||||
return m_fs;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ class Project: public QObject {
|
||||
|
||||
QString m_path = "";
|
||||
QSharedPointer<QByteArray> m_romBuff;
|
||||
QSharedPointer<ox::FileSystem> m_fs;
|
||||
ox::FileSystem *m_fs = nullptr;
|
||||
|
||||
public:
|
||||
Project(QString path);
|
||||
@ -35,6 +35,8 @@ class Project: public QObject {
|
||||
int open();
|
||||
|
||||
void save();
|
||||
|
||||
ox::FileSystem *romFS();
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <QDialog>
|
||||
#include <QFileDialog>
|
||||
#include <QGridLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QMenuBar>
|
||||
@ -18,6 +19,7 @@
|
||||
#include <QVector>
|
||||
|
||||
#include "lib/newwizard.hpp"
|
||||
#include "lib/oxfstreeview.hpp"
|
||||
#include "lib/project.hpp"
|
||||
#include "mainwindow.hpp"
|
||||
|
||||
@ -43,6 +45,9 @@ MainWindow::MainWindow(NostalgiaStudioProfile config, QWidget *parent) {
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
if (m_projectExplorer->model()) {
|
||||
delete m_projectExplorer->model();
|
||||
}
|
||||
for (auto f : m_cleanupTasks) {
|
||||
f();
|
||||
}
|
||||
@ -91,6 +96,9 @@ void MainWindow::setupProjectExplorer() {
|
||||
resizeDocks({dock}, {(int) (width() * 0.25)}, Qt::Horizontal);
|
||||
|
||||
// setup tree view
|
||||
m_projectExplorer = new QTreeView(dock);
|
||||
m_projectExplorer->header()->hide();
|
||||
dock->setWidget(m_projectExplorer);
|
||||
}
|
||||
|
||||
void MainWindow::addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockWidget) {
|
||||
@ -127,6 +135,7 @@ void MainWindow::openProject() {
|
||||
auto err = project->open();
|
||||
if (err == 0) {
|
||||
m_project = project;
|
||||
m_projectExplorer->setModel(new OxFSModel(m_project->romFS()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <QPointer>
|
||||
#include <QSharedPointer>
|
||||
#include <QString>
|
||||
#include <QTreeView>
|
||||
#include <QVector>
|
||||
#include <functional>
|
||||
|
||||
@ -60,6 +61,7 @@ class MainWindow: public QMainWindow {
|
||||
QPointer<QMenu> m_viewMenu;
|
||||
QVector<std::function<void()>> m_cleanupTasks;
|
||||
QVector<QPointer<QDockWidget>> m_dockWidgets;
|
||||
QTreeView *m_projectExplorer = nullptr;
|
||||
|
||||
public:
|
||||
MainWindow(NostalgiaStudioProfile config, QWidget *parent = 0);
|
||||
|
Loading…
Reference in New Issue
Block a user