[nostalgia/studio] Add PathExistsValidator

This commit is contained in:
Gary Talent 2020-04-16 23:47:08 -05:00
parent cef5fcd86f
commit f758566041
2 changed files with 30 additions and 2 deletions

View File

@ -15,12 +15,26 @@
#include <QPushButton> #include <QPushButton>
#include <QVBoxLayout> #include <QVBoxLayout>
#include "context.hpp"
#include "project.hpp"
#include "plugin.hpp" #include "plugin.hpp"
#include "wizard.hpp" #include "wizard.hpp"
namespace nostalgia::studio { namespace nostalgia::studio {
using std::function; PathExistsValidator::PathExistsValidator(const Context *ctx, QString pathTemplate, bool shouldExist) {
m_ctx = ctx;
m_pathTemplate = pathTemplate;
m_shouldExist = shouldExist;
}
QValidator::State PathExistsValidator::validate(QString &input, int&) const {
auto path = m_pathTemplate.arg(input);
if (m_ctx->project->exists(path) == m_shouldExist) {
return QValidator::Acceptable;
}
return QValidator::Invalid;
}
WizardSelect::WizardSelect() { WizardSelect::WizardSelect() {
m_listWidget = new QListWidget(this); m_listWidget = new QListWidget(this);
@ -203,7 +217,7 @@ QComboBox *WizardFormPage::addComboBox(QString displayName, QString fieldName, Q
return cb; return cb;
} }
QLineEdit *WizardFormPage::addLineEdit(QString displayName, QString fieldName, QString defaultVal, function<int(QString)> validator) { QLineEdit *WizardFormPage::addLineEdit(QString displayName, QString fieldName, QString defaultVal, std::function<int(QString)> validator) {
auto lbl = new QLabel(displayName, this); auto lbl = new QLabel(displayName, this);
auto le = new QLineEdit(this); auto le = new QLineEdit(this);
lbl->setBuddy(le); lbl->setBuddy(le);

View File

@ -18,6 +18,7 @@
#include <QLineEdit> #include <QLineEdit>
#include <QListWidget> #include <QListWidget>
#include <QMap> #include <QMap>
#include <QValidator>
#include <QVector> #include <QVector>
#include <QWizard> #include <QWizard>
@ -25,6 +26,19 @@
namespace nostalgia::studio { namespace nostalgia::studio {
class PathExistsValidator: public QValidator {
private:
const class Context *m_ctx = nullptr;
QString m_pathTemplate;
bool m_shouldExist = true;
public:
PathExistsValidator(const class Context *ctx, QString pathTemplate, bool shouldExist);
QValidator::State validate(QString &input, int &pos) const override;
};
struct NOSTALGIASTUDIO_EXPORT WizardMaker { struct NOSTALGIASTUDIO_EXPORT WizardMaker {
QString name; QString name;
std::function<QVector<QWizardPage*>()> make; std::function<QVector<QWizardPage*>()> make;