From 3f39943a37821cc2c4559560ab7eb2bb1649ef38 Mon Sep 17 00:00:00 2001
From: Aurindam Jana <aurindam.jana@digia.com>
Date: Fri, 17 May 2013 12:16:09 +0200
Subject: [PATCH] CustomWizard: Add a placeholder field for QLineEdit

The XML file now has a placeholdertext attribute that sets
the place holder text for the corrsponding QLineEdit.

Change-Id: I537721a5e5be796f4f88054751e66e557e718948
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
---
 doc/src/projects/creator-projects-custom-wizards.qdoc    | 5 ++++-
 .../templates/wizards/helloworld/wizard_sample.xml       | 2 +-
 .../templates/wizards/listmodel/wizard_sample.xml        | 2 +-
 .../projectexplorer/customwizard/customwizardpage.cpp    | 9 ++++++---
 .../projectexplorer/customwizard/customwizardpage.h      | 3 ++-
 5 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/doc/src/projects/creator-projects-custom-wizards.qdoc b/doc/src/projects/creator-projects-custom-wizards.qdoc
index 4aefc1295e7..9c50be37adf 100644
--- a/doc/src/projects/creator-projects-custom-wizards.qdoc
+++ b/doc/src/projects/creator-projects-custom-wizards.qdoc
@@ -257,7 +257,7 @@
             <fieldpagetitle xml:lang="de">Hallo Welt Parameter</fieldpagetitle>
             <fields>
                 <field mandatory="true" name="MESSAGE">
-                    <fieldcontrol class="QLineEdit" validator='^[^"]+$'  defaulttext="Hello world!" />
+                    <fieldcontrol class="QLineEdit" validator='^[^"]+$'  defaulttext="Hello world!" placeholdertext="Enter a message"/>
                     <fielddescription>Hello world message:</fielddescription>
                     <fielddescription xml:lang="de">Hallo-Welt-Nachricht:</fielddescription>
                 </field>
@@ -290,6 +290,9 @@
             \li \c defaulttext specifies text that appears in the field by
                 default.
 
+            \li For a QLineEdit, \c placeholdertext specifies placeholder text that appears in the
+                field.
+
             \li \c fielddescription specifies the field name that appears on the
                 wizard page.
 
diff --git a/share/qtcreator/templates/wizards/helloworld/wizard_sample.xml b/share/qtcreator/templates/wizards/helloworld/wizard_sample.xml
index 7ba312f925e..df3724c2689 100644
--- a/share/qtcreator/templates/wizards/helloworld/wizard_sample.xml
+++ b/share/qtcreator/templates/wizards/helloworld/wizard_sample.xml
@@ -51,7 +51,7 @@ leave room for the Qt 4 target page.
     <fields>
         <field mandatory="true" name="MESSAGE">
             <fieldcontrol class="QLineEdit" validator='^[^"]+$'
-                          defaulttext="Hello world from project  '%ProjectName:c%'!" />
+                          defaulttext="Hello world from project  '%ProjectName:c%'!" placeholdertext="Enter a message"/>
             <fielddescription>Hello world message:</fielddescription>
             <fielddescription xml:lang="de">Hallo-Welt-Nachricht:</fielddescription>
         </field>
diff --git a/share/qtcreator/templates/wizards/listmodel/wizard_sample.xml b/share/qtcreator/templates/wizards/listmodel/wizard_sample.xml
index cdfd456f150..d608fe3a1de 100644
--- a/share/qtcreator/templates/wizards/listmodel/wizard_sample.xml
+++ b/share/qtcreator/templates/wizards/listmodel/wizard_sample.xml
@@ -46,7 +46,7 @@ Custom class wizard example configuration file. -->
     <fieldpagetitle xml:lang="de">Parameter des ListModel</fieldpagetitle>
     <fields>
         <field name="ClassName">
-            <fieldcontrol class="QLineEdit" validator="^[a-zA-Z0-9_]+$" defaulttext="MyListModel" />
+            <fieldcontrol class="QLineEdit" validator="^[a-zA-Z0-9_]+$" defaulttext="MyListModel" placeholdertext="Enter a class name"/>
             <fielddescription>Class name:</fielddescription>
             <fielddescription xml:lang="de">Klassenname:</fielddescription>
         </field>
diff --git a/src/plugins/projectexplorer/customwizard/customwizardpage.cpp b/src/plugins/projectexplorer/customwizard/customwizardpage.cpp
index f4d1a76236b..72ce236fba5 100644
--- a/src/plugins/projectexplorer/customwizard/customwizardpage.cpp
+++ b/src/plugins/projectexplorer/customwizard/customwizardpage.cpp
@@ -153,8 +153,8 @@ void TextFieldCheckBox::slotStateChanged(int cs)
     \sa ProjectExplorer::CustomWizard
 */
 
-CustomWizardFieldPage::LineEditData::LineEditData(QLineEdit* le, const QString &defText) :
-    lineEdit(le), defaultText(defText)
+CustomWizardFieldPage::LineEditData::LineEditData(QLineEdit* le, const QString &defText, const QString &pText) :
+    lineEdit(le), defaultText(defText), placeholderText(pText)
 {
 }
 
@@ -380,7 +380,8 @@ QWidget *CustomWizardFieldPage::registerLineEdit(const QString &fieldName,
     connect(lineEdit, SIGNAL(textEdited(QString)), SIGNAL(completeChanged()));
 
     const QString defaultText = field.controlAttributes.value(QLatin1String("defaulttext"));
-    m_lineEdits.push_back(LineEditData(lineEdit, defaultText));
+    const QString placeholderText = field.controlAttributes.value(QLatin1String("placeholdertext"));
+    m_lineEdits.push_back(LineEditData(lineEdit, defaultText, placeholderText));
     return lineEdit;
 }
 
@@ -396,6 +397,8 @@ void CustomWizardFieldPage::initializePage()
             CustomWizardContext::replaceFields(m_context->baseReplacements, &defaultText);
             led.lineEdit->setText(defaultText);
         }
+        if (!led.placeholderText.isEmpty())
+            led.lineEdit->setPlaceholderText(led.placeholderText);
     }
     foreach (const TextEditData &ted, m_textEdits) {
         if (!ted.userChange.isNull()) {
diff --git a/src/plugins/projectexplorer/customwizard/customwizardpage.h b/src/plugins/projectexplorer/customwizard/customwizardpage.h
index 766845268d1..21ded031c54 100644
--- a/src/plugins/projectexplorer/customwizard/customwizardpage.h
+++ b/src/plugins/projectexplorer/customwizard/customwizardpage.h
@@ -128,9 +128,10 @@ protected:
     void clearError();
 private:
     struct LineEditData {
-        explicit LineEditData(QLineEdit* le = 0, const QString &defText = QString());
+        explicit LineEditData(QLineEdit* le = 0, const QString &defText = QString(), const QString &pText = QString());
         QLineEdit* lineEdit;
         QString defaultText;
+        QString placeholderText;
         QString userChange;
     };
     struct TextEditData {
-- 
GitLab