Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "customwizardparameters.h" #include "customwizardparameters.h"
#include <utils/pathchooser.h> #include <utils/pathchooser.h>
#include <utils/qtcassert.h>
#include <QtCore/QRegExp> #include <QtCore/QRegExp>
#include <QtCore/QDebug> #include <QtCore/QDebug>
...@@ -119,6 +120,7 @@ QWidget *CustomWizardFieldPage::registerControl(const CustomWizardField &field) ...@@ -119,6 +120,7 @@ QWidget *CustomWizardFieldPage::registerControl(const CustomWizardField &field)
} else { } else {
qWarning("Invalid custom wizard field validator regular expression %s.", qPrintable(validationRegExp)); qWarning("Invalid custom wizard field validator regular expression %s.", qPrintable(validationRegExp));
} }
m_validatorLineEdits.push_back(lineEdit);
} }
lineEdit->setText(field.controlAttributes.value(QLatin1String("defaulttext"))); lineEdit->setText(field.controlAttributes.value(QLatin1String("defaulttext")));
registerField(fieldName, lineEdit, "text", SIGNAL(textEdited(QString))); registerField(fieldName, lineEdit, "text", SIGNAL(textEdited(QString)));
...@@ -130,6 +132,22 @@ void CustomWizardFieldPage::addField(const CustomWizardField &field) ...@@ -130,6 +132,22 @@ void CustomWizardFieldPage::addField(const CustomWizardField &field)
addRow(field.description, registerControl(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::CustomWizardPage(const FieldList &f, CustomWizardPage::CustomWizardPage(const FieldList &f,
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QFormLayout; class QFormLayout;
class QLineEdit;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace Utils { namespace Utils {
...@@ -66,6 +67,8 @@ signals: ...@@ -66,6 +67,8 @@ signals:
// A simple custom wizard page presenting the fields to be used // A simple custom wizard page presenting the fields to be used
// as page 2 of a BaseProjectWizardDialog if there are any fields. // as page 2 of a BaseProjectWizardDialog if there are any fields.
// Uses the 'field' functionality of QWizard. // Uses the 'field' functionality of QWizard.
// Implements validatePage() as the field logic cannot be tied up
// with additional validation.
class CustomWizardFieldPage : public QWizardPage { class CustomWizardFieldPage : public QWizardPage {
Q_OBJECT Q_OBJECT
public: public:
...@@ -73,6 +76,8 @@ public: ...@@ -73,6 +76,8 @@ public:
explicit CustomWizardFieldPage(const FieldList &f, explicit CustomWizardFieldPage(const FieldList &f,
QWidget *parent = 0); QWidget *parent = 0);
virtual bool validatePage();
protected: protected:
inline void addRow(const QString &name, QWidget *w); inline void addRow(const QString &name, QWidget *w);
...@@ -81,6 +86,7 @@ private: ...@@ -81,6 +86,7 @@ private:
void addField(const CustomWizardField &f); void addField(const CustomWizardField &f);
QFormLayout *m_formLayout; QFormLayout *m_formLayout;
QList<QLineEdit*> m_validatorLineEdits;
}; };
// A custom wizard page presenting the fields to be used and a path chooser // A custom wizard page presenting the fields to be used and a path chooser
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment