Add conclusion page to wizard and prevent recreating already existing

projects
This commit is contained in:
Gary Talent 2017-05-03 23:20:53 -05:00
parent 973b7e97b1
commit 258be70528
4 changed files with 50 additions and 27 deletions

View File

@ -9,15 +9,17 @@ include(address_sanitizer)
if (WOMBAT_BUILD_TYPE STREQUAL "GBA")
include(GBA)
add_definitions(
-nostdlib
-fno-exceptions
-fno-rtti
)
endif()
add_definitions(
-std=c++11
-Wall
-Wsign-compare
-nostdlib
-fno-exceptions
-fno-rtti
)
if (CMAKE_BUILD_TYPE STREQUAL "Release")

View File

@ -39,11 +39,10 @@ WizardSelect::WizardSelect() {
}
void WizardSelect::initializePage() {
m_nextId = -1;
emit completeChanged();
}
void WizardSelect::addOption(QString name, std::function<QWizardPage*()> makePage) {
void WizardSelect::addOption(QString name, function<QVector<QWizardPage*>()> makePage) {
m_options[name] = makePage;
m_listWidget->addItem(name);
}
@ -52,40 +51,45 @@ bool WizardSelect::isComplete() const {
return m_complete;
}
int WizardSelect::nextId() const {
return m_nextId;
}
void WizardSelect::itemSelected(int row) {
if (row > -1) {
auto w = wizard();
if (nextId() > -1) {
w->removePage(nextId());
m_nextId = -1;
}
auto selected = m_listWidget->currentItem()->text();
if (m_options.contains(selected)) {
m_nextId = w->addPage(m_options[selected]());
for (auto p : m_options[selected]()) {
w->addPage(p);
}
// for some reason the continue button only appears correctly after remove runs
w->removePage(nextId());
m_nextId = w->addPage(m_options[selected]());
w->removePage(w->addPage(new QWizardPage()));
}
}
}
WizardConclusionPage::WizardConclusionPage(QString msg) {
WizardConclusionPage::WizardConclusionPage(QString msg, QVector<QString> fields) {
m_baseMsg = msg;
m_fields = fields;
}
WizardConclusionPage::~WizardConclusionPage() {
}
void WizardConclusionPage::initializePage() {
QString msg = m_baseMsg;
for (auto field : m_fields) {
msg = msg.arg(this->field(field).toString());
}
auto text = new QLabel(msg, this);
auto layout = new QVBoxLayout(this);
layout->addWidget(text);
setLayout(layout);
}
WizardConclusionPage::~WizardConclusionPage() {
}
WizardFormPage::WizardFormPage() {
m_layout = new QGridLayout(this);

View File

@ -24,22 +24,19 @@ class WizardSelect: public QWizardPage {
Q_OBJECT
private:
QMap<QString, std::function<QWizardPage*()>> m_options;
QMap<QString, std::function<QVector<QWizardPage*>()>> m_options;
QListWidget *m_listWidget = nullptr;
bool m_complete = false;
int m_nextId = -1;
public:
WizardSelect();
void addOption(QString name, std::function<QWizardPage*()> makePage);
void addOption(QString name, std::function<QVector<QWizardPage*>()> makePage);
void initializePage() override;
bool isComplete() const override;
int nextId() const override;
private slots:
void itemSelected(int row);
};
@ -83,11 +80,15 @@ class WizardFormPage: public QWizardPage {
class WizardConclusionPage: public QWizardPage {
Q_OBJECT
private:
QString m_baseMsg = "";
QVector<QString> m_fields;
public:
WizardConclusionPage(QString msg);
WizardConclusionPage(QString msg, QVector<QString> field);
virtual ~WizardConclusionPage();
void initializePage() override;
};

View File

@ -13,6 +13,7 @@
#include <QLabel>
#include <QLineEdit>
#include <QMenuBar>
#include <QVector>
#include "lib/newwizard.hpp"
#include "lib/project.hpp"
#include "mainwindow.hpp"
@ -92,14 +93,29 @@ void MainWindow::showNewWizard() {
Wizard wizard;
auto ws = new WizardSelect();
wizard.addPage(ws);
ws->addOption(tr("Project"), [PROJECT_NAME, PROJECT_PATH]() {
ws->addOption(tr("Project"),
[&wizard, PROJECT_NAME, PROJECT_PATH]() {
QVector<QWizardPage*> pgs;
auto pg = new WizardFormPage();
pg->addLineEdit(tr("Project &Name:"), PROJECT_NAME + "*");
pg->addLineEdit(tr("Project &Name:"), PROJECT_NAME + "*", "", [PROJECT_PATH, pg, &wizard](QString projectName) {
auto projectPath = wizard.field(PROJECT_PATH).toString();
auto path = projectPath + "/" + projectName;
if (!QDir(path).exists()) {
return 0;
} else {
pg->showValidationError(tr("This project directory already exists."));
return 1;
}
}
);
pg->addDirBrowse(tr("Project &Path:"), PROJECT_PATH + "*");
return pg;
pgs.push_back(pg);
pgs.push_back(new WizardConclusionPage(tr("Creating project: %1/%2"), {PROJECT_PATH, PROJECT_NAME}));
return pgs;
}
);
wizard.setAccept([&wizard, PROJECT_NAME, PROJECT_PATH]() {
wizard.setAccept([&wizard, ws, PROJECT_NAME, PROJECT_PATH]() {
auto projectName = wizard.field(PROJECT_NAME).toString();
auto projectPath = wizard.field(PROJECT_PATH).toString();
if (QDir(projectPath).exists()) {