Commit 0f3d8b65 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

CustomWizard: Implement validatePage() for CustomWizardPage

checking the validation line edits as a last resort.
parent 292db7a5
......@@ -31,6 +31,7 @@
#include "customwizardparameters.h"
#include <utils/pathchooser.h>
#include <utils/qtcassert.h>
#include <QtCore/QRegExp>
#include <QtCore/QDebug>
......@@ -119,6 +120,7 @@ QWidget *CustomWizardFieldPage::registerControl(const CustomWizardField &field)
} else {
qWarning("Invalid custom wizard field validator regular expression %s.", qPrintable(validationRegExp));
}
m_validatorLineEdits.push_back(lineEdit);
}
lineEdit->setText(field.controlAttributes.value(QLatin1String("defaulttext")));
registerField(fieldName, lineEdit, "text", SIGNAL(textEdited(QString)));
......@@ -130,6 +132,22 @@ void CustomWizardFieldPage::addField(const CustomWizardField &field)
addRow(field.description, registerControl(field));
}
bool CustomWizardFieldPage::validatePage()
{
// Check line edits with validators
foreach(QLineEdit *le, m_validatorLineEdits) {
int pos = 0;
const QValidator *val = le->validator();
QTC_ASSERT(val, return false);
QString text = le->text();
if (val->validate(text, pos) != QValidator::Acceptable) {
le->setFocus();
return false;
}
}
return true;
}
// --------------- CustomWizardPage
CustomWizardPage::CustomWizardPage(const FieldList &f,
......
......@@ -36,6 +36,7 @@
QT_BEGIN_NAMESPACE
class QFormLayout;
class QLineEdit;
QT_END_NAMESPACE
namespace Utils {
......@@ -66,6 +67,8 @@ signals:
// A simple custom wizard page presenting the fields to be used
// as page 2 of a BaseProjectWizardDialog if there are any fields.
// Uses the 'field' functionality of QWizard.
// Implements validatePage() as the field logic cannot be tied up
// with additional validation.
class CustomWizardFieldPage : public QWizardPage {
Q_OBJECT
public:
......@@ -73,6 +76,8 @@ public:
explicit CustomWizardFieldPage(const FieldList &f,
QWidget *parent = 0);
virtual bool validatePage();
protected:
inline void addRow(const QString &name, QWidget *w);
......@@ -81,6 +86,7 @@ private:
void addField(const CustomWizardField &f);
QFormLayout *m_formLayout;
QList<QLineEdit*> m_validatorLineEdits;
};
// A custom wizard page presenting the fields to be used and a path chooser
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment