Skip to content
Snippets Groups Projects
Commit ed843bf5 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Custom wizards: Add a checkbox.

Add a checkbox with configureable 'true'/'false' strings and illustrate
how to comment out a profile line using it in helloworld-example.
parent f753f9d2
No related branches found
No related tags found
No related merge requests found
QT -= core
QT = core
%NETWORK%QT += network
CONFIG += console
CONFIG -= app_bundle
......
......@@ -29,9 +29,9 @@
**
**************************************************************************/
Custom project wizard configuration example file. Note that by convention,
Custom project wizard configuration example file. Note that by convention,
the project file goes last.
The "class" and "firstpage" attributes specify that it is a Qt 4 wizard and
The "class" and "firstpage" attributes specify that it is a Qt 4 wizard and
leave room for the Qt 4 target page.
-->
<wizard version="1" kind="project"
......@@ -55,5 +55,11 @@ leave room for the Qt 4 target page.
<fielddescription>Hello world message:</fielddescription>
<fielddescription xml:lang="de">Hallo-Welt-Nachricht:</fielddescription>
</field>
<!-- Comment out network in profile according to user's wishes -->
<field name="NETWORK">
<fieldcontrol class="QCheckBox" truevalue="" falsevalue="# "/>
<fielddescription>Include network module</fielddescription>
<fielddescription xml:lang="de">Netzwerk-Modul verwenden</fielddescription>
</field>
</fields>
</wizard>
......@@ -49,6 +49,7 @@ enum { debug = 0 };
namespace ProjectExplorer {
namespace Internal {
// ----------- TextFieldComboBox
TextFieldComboBox::TextFieldComboBox(QWidget *parent) :
QComboBox(parent)
{
......@@ -63,6 +64,29 @@ void TextFieldComboBox::setText(const QString &s)
setCurrentIndex(index);
}
// -------------- TextCheckBox
TextFieldCheckBox::TextFieldCheckBox(const QString &text, QWidget *parent) :
QCheckBox(text, parent),
m_trueText(QLatin1String("true")), m_falseText(QLatin1String("false"))
{
connect(this, SIGNAL(stateChanged(int)), this, SLOT(slotStateChanged(int)));
}
QString TextFieldCheckBox::text() const
{
return isChecked() ? m_trueText : m_falseText;
}
void TextFieldCheckBox::setText(const QString &s)
{
setChecked(s == m_trueText);
}
void TextFieldCheckBox::slotStateChanged(int cs)
{
emit textChanged(cs == Qt::Checked ? m_trueText : m_falseText);
}
// --------------- CustomWizardFieldPage
CustomWizardFieldPage::LineEditData::LineEditData(QLineEdit* le, const QString &defText) :
......@@ -107,6 +131,7 @@ void CustomWizardFieldPage::addField(const CustomWizardField &field)\
QString fieldName = field.name;
if (field.mandatory)
fieldName += QLatin1Char('*');
bool spansRow = false;
// Check known classes: QComboBox
const QString className = field.controlAttributes.value(QLatin1String("class"));
QWidget *fieldWidget = 0;
......@@ -116,10 +141,17 @@ void CustomWizardFieldPage::addField(const CustomWizardField &field)\
fieldWidget = registerTextEdit(fieldName, field);
} else if (className == QLatin1String("Utils::PathChooser")) {
fieldWidget = registerPathChooser(fieldName, field);
} else if (className == QLatin1String("QCheckBox")) {
fieldWidget = registerCheckBox(fieldName, field.description, field);
spansRow = true; // Do not create a label for the checkbox.
} else {
fieldWidget = registerLineEdit(fieldName, field);
}
addRow(field.description, fieldWidget);
if (spansRow) {
m_formLayout->addRow(fieldWidget);
} else {
addRow(field.description, fieldWidget);
}
}
QWidget *CustomWizardFieldPage::registerComboBox(const QString &fieldName,
......@@ -162,6 +194,23 @@ QWidget *CustomWizardFieldPage::registerPathChooser(const QString &fieldName,
return pathChooser;
} // Utils::PathChooser
QWidget *CustomWizardFieldPage::registerCheckBox(const QString &fieldName,
const QString &fieldDescription,
const CustomWizardField &field)
{
typedef CustomWizardField::ControlAttributeMap::const_iterator AttributeMapConstIt;
TextFieldCheckBox *checkBox = new TextFieldCheckBox(fieldDescription);
const AttributeMapConstIt trueTextIt = field.controlAttributes.constFind(QLatin1String("truevalue"));
if (trueTextIt != field.controlAttributes.constEnd()) // Also set empty texts
checkBox->setTrueText(trueTextIt.value());
const AttributeMapConstIt falseTextIt = field.controlAttributes.constFind(QLatin1String("falsevalue"));
if (falseTextIt != field.controlAttributes.constEnd()) // Also set empty texts
checkBox->setFalseText(falseTextIt.value());
registerField(fieldName, checkBox, "text", SIGNAL(textChanged(QString)));
return checkBox;
}
QWidget *CustomWizardFieldPage::registerLineEdit(const QString &fieldName,
const CustomWizardField &field)
{
......
......@@ -31,6 +31,7 @@
#define CUSTOMPROJECTWIZARDDIALOG_H
#include <QtGui/QComboBox>
#include <QtGui/QCheckBox>
#include <QtGui/QWizardPage>
#include <QtCore/QSharedPointer>
......@@ -52,7 +53,7 @@ struct CustomWizardParameters;
struct CustomWizardContext;
// A non-editable combo for text editing purposes that plays
// with QWizard::registerField (providing a settable text property).
// with QWizard::registerField (providing a settable 'text' property).
class TextFieldComboBox : public QComboBox {
Q_PROPERTY(QString text READ text WRITE setText)
Q_OBJECT
......@@ -66,6 +67,35 @@ signals:
void text4Changed(const QString &); // Do not conflict with Qt 3 compat signal.
};
// A Checkbox that plays with QWizard::registerField (providing a settable
// 'text' property containing predefined strings for 'true'/'false').
class TextFieldCheckBox : public QCheckBox {
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(QString trueText READ trueText WRITE setTrueText)
Q_PROPERTY(QString falseText READ falseText WRITE setFalseText)
Q_OBJECT
public:
explicit TextFieldCheckBox(const QString &text, QWidget *parent = 0);
QString text() const;
void setText(const QString &s);
void setTrueText(const QString &t) { m_trueText = t; }
QString trueText() const { return m_trueText; }
void setFalseText(const QString &t) { m_falseText = t; }
QString falseText() const { return m_falseText; }
signals:
void textChanged(const QString &);
private slots:
void slotStateChanged(int);
private:
QString m_trueText;
QString m_falseText;
};
// 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.
......@@ -105,6 +135,9 @@ private:
QWidget *registerComboBox(const QString &fieldName, const CustomWizardField &field);
QWidget *registerTextEdit(const QString &fieldName, const CustomWizardField &field);
QWidget *registerPathChooser(const QString &fieldName, const CustomWizardField &field);
QWidget *registerCheckBox(const QString &fieldName,
const QString &fieldDescription,
const CustomWizardField &field);
void addField(const CustomWizardField &f);
const QSharedPointer<CustomWizardContext> m_context;
......
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