Add new World wizard

This commit is contained in:
2017-12-20 22:41:14 -06:00
parent 2edee450aa
commit 4e50d80f5f
31 changed files with 415 additions and 94 deletions
+6 -6
View File
@@ -11,17 +11,17 @@
namespace nostalgia {
namespace studio {
void Plugin::addNewWizard(QString name, std::function<QVector<QWizardPage*>()> make) {
m_newWizards.push_back({name, make});
}
QVector<WizardMaker> Plugin::newWizards(PluginArgs) {
QVector<WizardMaker> Plugin::newWizards(const Context *ctx) {
return {};
}
QVector<WizardMaker> Plugin::importWizards(PluginArgs) {
QVector<WizardMaker> Plugin::importWizards(const Context *ctx) {
return {};
}
QWidget *Plugin::makeEditor(QString path, const Context *ctx) {
return nullptr;
}
}
}
+11 -8
View File
@@ -21,27 +21,30 @@
namespace nostalgia {
namespace studio {
struct PluginArgs {
Project *&project;
struct Context {
QWidget *tabParent = nullptr;
const Project *project = nullptr;
};
struct WizardMaker {
QString name;
std::function<QVector<QWizardPage*>()> make;
std::function<int(QWizard*)> onAccept;
};
struct EditorMaker {
virtual QWidget *make(QString path, const Context *ctx) = 0;
};
class Plugin {
private:
QVector<WizardMaker> m_newWizards;
public:
void addNewWizard(QString name, std::function<QVector<QWizardPage*>()> make);
virtual QVector<WizardMaker> newWizards(const Context *ctx);
void addImportWizard(QString name, std::function<QVector<QWizardPage*>()> make);
virtual QVector<WizardMaker> importWizards(const Context *ctx);
virtual QVector<WizardMaker> newWizards(PluginArgs);
virtual QWidget *makeEditor(QString path, const Context *ctx);
virtual QVector<WizardMaker> importWizards(PluginArgs);
};
}
+7 -3
View File
@@ -65,7 +65,7 @@ int Project::openRomFs() {
}
}
int Project::saveRomFs() {
int Project::saveRomFs() const {
int err = 0;
QFile file(m_path + ROM_FILE);
err |= file.open(QIODevice::WriteOnly) == false;
@@ -78,17 +78,21 @@ FileSystem *Project::romFs() {
return m_fs;
}
int Project::mkdir(QString path) {
int Project::mkdir(QString path) const {
auto err = m_fs->mkdir(path.toUtf8().data());
emit updated(path);
return err;
}
int Project::write(QString path, uint8_t *buff, size_t buffLen) {
int Project::write(QString path, uint8_t *buff, size_t buffLen) const {
auto err = m_fs->write(path.toUtf8().data(), buff, buffLen);
emit updated(path);
return err;
}
ox::FileStat Project::stat(QString path) const {
return m_fs->stat(path.toUtf8().data());
}
}
}
+7 -4
View File
@@ -33,16 +33,19 @@ class Project: public QObject {
int openRomFs();
int saveRomFs();
int saveRomFs() const;
ox::FileSystem *romFs();
int mkdir(QString path);
int mkdir(QString path) const;
int write(QString path, uint8_t *buff, size_t buffLen);
int write(QString path, uint8_t *buff, size_t buffLen) const;
ox::FileStat stat(QString path) const;
signals:
void updated(QString path);
void updated(QString path) const;
};
}
+16 -11
View File
@@ -7,6 +7,7 @@
*/
#include <QComboBox>
#include <QDebug>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
@@ -14,6 +15,7 @@
#include <QPushButton>
#include <QVBoxLayout>
#include "plugin.hpp"
#include "wizard.hpp"
namespace nostalgia {
@@ -43,9 +45,9 @@ void WizardSelect::initializePage() {
emit completeChanged();
}
void WizardSelect::addOption(QString name, function<QVector<QWizardPage*>()> makePage) {
m_options[name] = makePage;
m_listWidget->addItem(name);
void WizardSelect::addOption(WizardMaker wm) {
m_options[wm.name] = {wm.make, wm.onAccept};
m_listWidget->addItem(wm.name);
}
bool WizardSelect::isComplete() const {
@@ -53,18 +55,21 @@ bool WizardSelect::isComplete() const {
}
void WizardSelect::itemSelected(int row) {
if (row > -1) {
auto w = wizard();
if (nextId() > -1) {
auto w = dynamic_cast<Wizard*>(wizard());
if (w and row > -1) {
// remove other pages
while (nextId() > -1) {
w->removePage(nextId());
}
auto selected = m_listWidget->currentItem()->text();
if (m_options.contains(selected)) {
for (auto p : m_options[selected]()) {
auto &o = m_options[selected];
for (auto p : o.make()) {
w->addPage(p);
}
w->setAccept(o.onAccept);
// for some reason the continue button only appears correctly after remove runs
w->removePage(w->addPage(new QWizardPage()));
}
@@ -313,7 +318,7 @@ void WizardFormPage::showValidationError(QString msg) {
// set message
if (msg != "") {
m_errorMsg->setText(tr("Error: ") + msg);
m_errorMsg->setText(msg);
} else {
m_errorMsg->setText("");
}
@@ -325,7 +330,7 @@ Wizard::Wizard(QString windowTitle, QWidget *parent): QWizard(parent) {
setModal(true);
}
void Wizard::setAccept(std::function<int()> acceptFunc) {
void Wizard::setAccept(std::function<int(QWizard*)> acceptFunc) {
m_acceptFunc = acceptFunc;
}
@@ -333,7 +338,7 @@ void Wizard::accept() {
auto page = dynamic_cast<WizardFormPage*>(currentPage());
if (page != nullptr && page->accept() == 0) {
QDialog::accept();
} else if (m_acceptFunc != nullptr && m_acceptFunc() == 0) {
} else if (m_acceptFunc != nullptr && m_acceptFunc(this) == 0) {
QDialog::accept();
}
}
+11 -4
View File
@@ -22,18 +22,25 @@
namespace nostalgia {
namespace studio {
class WizardMaker;
class WizardSelect: public QWizardPage {
Q_OBJECT
private:
QMap<QString, std::function<QVector<QWizardPage*>()>> m_options;
struct WizardFuncs {
std::function<QVector<QWizardPage*>()> make;
std::function<int(QWizard*)> onAccept;
};
QHash<QString, WizardFuncs> m_options;
QListWidget *m_listWidget = nullptr;
bool m_complete = false;
public:
WizardSelect();
void addOption(QString name, std::function<QVector<QWizardPage*>()> makePage);
void addOption(WizardMaker wm);
void initializePage() override;
@@ -109,12 +116,12 @@ class WizardConclusionPage: public QWizardPage {
class Wizard: public QWizard {
Q_OBJECT
private:
std::function<int()> m_acceptFunc;
std::function<int(QWizard*)> m_acceptFunc;
public:
Wizard(QString windowTitle, QWidget *parent = 0);
void setAccept(std::function<int()> acceptFunc);
void setAccept(std::function<int(QWizard*)> acceptFunc);
void accept();
};