Add support for line edit validators in wizards
This commit is contained in:
parent
d7a1d19fdf
commit
973b7e97b1
@ -18,6 +18,8 @@
|
|||||||
namespace nostalgia {
|
namespace nostalgia {
|
||||||
namespace studio {
|
namespace studio {
|
||||||
|
|
||||||
|
using std::function;
|
||||||
|
|
||||||
WizardSelect::WizardSelect() {
|
WizardSelect::WizardSelect() {
|
||||||
m_listWidget = new QListWidget(this);
|
m_listWidget = new QListWidget(this);
|
||||||
auto layout = new QVBoxLayout(this);
|
auto layout = new QVBoxLayout(this);
|
||||||
@ -74,6 +76,17 @@ void WizardSelect::itemSelected(int row) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
WizardConclusionPage::WizardConclusionPage(QString msg) {
|
||||||
|
auto text = new QLabel(msg, this);
|
||||||
|
auto layout = new QVBoxLayout(this);
|
||||||
|
layout->addWidget(text);
|
||||||
|
setLayout(layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
WizardConclusionPage::~WizardConclusionPage() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
WizardFormPage::WizardFormPage() {
|
WizardFormPage::WizardFormPage() {
|
||||||
m_layout = new QGridLayout(this);
|
m_layout = new QGridLayout(this);
|
||||||
m_layout->setColumnMinimumWidth(0, 20);
|
m_layout->setColumnMinimumWidth(0, 20);
|
||||||
@ -118,7 +131,7 @@ bool WizardFormPage::validatePage() {
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WizardFormPage::addLineEdit(QString displayName, QString fieldName, QString defaultVal) {
|
void WizardFormPage::addLineEdit(QString displayName, QString fieldName, QString defaultVal, 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);
|
||||||
@ -126,18 +139,21 @@ void WizardFormPage::addLineEdit(QString displayName, QString fieldName, QString
|
|||||||
m_layout->addWidget(lbl, m_currentLine, 0);
|
m_layout->addWidget(lbl, m_currentLine, 0);
|
||||||
m_layout->addWidget(le, m_currentLine, 1);
|
m_layout->addWidget(le, m_currentLine, 1);
|
||||||
|
|
||||||
m_fields[fieldName].defaultValue = defaultVal;
|
auto field = &m_fields[fieldName];
|
||||||
m_fields[fieldName].lineEdit = le;
|
|
||||||
|
field->defaultValue = defaultVal;
|
||||||
|
field->lineEdit = le;
|
||||||
|
field->validator = validator;
|
||||||
|
|
||||||
registerField(fieldName, le);
|
registerField(fieldName, le);
|
||||||
|
|
||||||
connect(le, &QLineEdit::textChanged, [this, fieldName, le](QString txt) {
|
connect(le, &QLineEdit::textChanged, [this, fieldName, le, field](QString txt) {
|
||||||
if (m_fields[fieldName].value == "" && txt != "") {
|
if (field->value == "" && txt != "") {
|
||||||
m_validFields++;
|
m_validFields++;
|
||||||
} else if (m_fields[fieldName].value != "" && txt == "") {
|
} else if (field->value != "" && txt == "") {
|
||||||
m_validFields--;
|
m_validFields--;
|
||||||
}
|
}
|
||||||
m_fields[fieldName].value = txt;
|
field->value = txt;
|
||||||
emit completeChanged();
|
emit completeChanged();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -44,6 +44,7 @@ class WizardSelect: public QWizardPage {
|
|||||||
void itemSelected(int row);
|
void itemSelected(int row);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class WizardFormPage: public QWizardPage {
|
class WizardFormPage: public QWizardPage {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
@ -69,7 +70,9 @@ class WizardFormPage: public QWizardPage {
|
|||||||
|
|
||||||
bool validatePage() override;
|
bool validatePage() override;
|
||||||
|
|
||||||
void addLineEdit(QString displayName, QString fieldName, QString defaultVal = "");
|
void addLineEdit(QString displayName, QString fieldName,
|
||||||
|
QString defaultVal = "",
|
||||||
|
std::function<int(QString)> validator = [](QString) { return 0; });
|
||||||
|
|
||||||
void addDirBrowse(QString displayName, QString fieldName, QString defaultVal = QDir::homePath());
|
void addDirBrowse(QString displayName, QString fieldName, QString defaultVal = QDir::homePath());
|
||||||
|
|
||||||
@ -77,6 +80,17 @@ class WizardFormPage: public QWizardPage {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class WizardConclusionPage: public QWizardPage {
|
||||||
|
Q_OBJECT
|
||||||
|
private:
|
||||||
|
|
||||||
|
public:
|
||||||
|
WizardConclusionPage(QString msg);
|
||||||
|
|
||||||
|
virtual ~WizardConclusionPage();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class Wizard: public QWizard {
|
class Wizard: public QWizard {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user