From 0f3d8b65b14bbc441cc79a4280c5b94d299f9ca2 Mon Sep 17 00:00:00 2001
From: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Date: Wed, 17 Mar 2010 16:24:57 +0100
Subject: [PATCH] CustomWizard: Implement validatePage() for CustomWizardPage

checking the validation line edits as a last resort.
---
 .../customwizard/customwizardpage.cpp          | 18 ++++++++++++++++++
 .../customwizard/customwizardpage.h            |  6 ++++++
 2 files changed, 24 insertions(+)

diff --git a/src/plugins/projectexplorer/customwizard/customwizardpage.cpp b/src/plugins/projectexplorer/customwizard/customwizardpage.cpp
index 716b843c3a3..9aa122e5602 100644
--- a/src/plugins/projectexplorer/customwizard/customwizardpage.cpp
+++ b/src/plugins/projectexplorer/customwizard/customwizardpage.cpp
@@ -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,
diff --git a/src/plugins/projectexplorer/customwizard/customwizardpage.h b/src/plugins/projectexplorer/customwizard/customwizardpage.h
index 26ec8e9910f..ce1484ab0c3 100644
--- a/src/plugins/projectexplorer/customwizard/customwizardpage.h
+++ b/src/plugins/projectexplorer/customwizard/customwizardpage.h
@@ -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
-- 
GitLab