OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / projectexplorer / customwizard / customwizardpage.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #ifndef CUSTOMPROJECTWIZARDDIALOG_H
34 #define CUSTOMPROJECTWIZARDDIALOG_H
35
36 #include <QtGui/QComboBox>
37 #include <QtGui/QCheckBox>
38 #include <QtGui/QWizardPage>
39 #include <QtCore/QSharedPointer>
40
41 QT_BEGIN_NAMESPACE
42 class QFormLayout;
43 class QLineEdit;
44 class QTextEdit;
45 class QLabel;
46 QT_END_NAMESPACE
47
48 namespace Utils {
49     class PathChooser;
50 }
51
52 namespace ProjectExplorer {
53 namespace Internal {
54
55 struct CustomWizardField;
56 struct CustomWizardParameters;
57 struct CustomWizardContext;
58
59 // A non-editable combo for text editing purposes that plays
60 // with QWizard::registerField (providing a settable 'text' property).
61 // Allows for a separation of values to be used for wizard fields replacement
62 // and display texts.
63 class TextFieldComboBox : public QComboBox {
64     Q_PROPERTY(QString text READ text WRITE setText)
65     Q_OBJECT
66 public:
67     explicit TextFieldComboBox(QWidget *parent = 0);
68
69     QString text() const;
70     void setText(const QString &s);
71
72     void setItems(const QStringList &displayTexts, const QStringList &values);
73
74 signals:
75     void text4Changed(const QString &); // Do not conflict with Qt 3 compat signal.
76
77 private slots:
78     void slotCurrentIndexChanged(int);
79
80 private:
81     inline QString valueAt(int) const;
82 };
83
84 // A Checkbox that plays with QWizard::registerField (providing a settable
85 // 'text' property containing predefined strings for 'true'/'false').
86 class TextFieldCheckBox : public QCheckBox {
87     Q_PROPERTY(QString text READ text WRITE setText)
88     Q_PROPERTY(QString trueText READ trueText WRITE setTrueText)
89     Q_PROPERTY(QString falseText READ falseText WRITE setFalseText)
90     Q_OBJECT
91 public:
92     explicit TextFieldCheckBox(const QString &text, QWidget *parent = 0);
93
94     QString text() const;
95     void setText(const QString &s);
96
97     void setTrueText(const QString &t)  { m_trueText = t;    }
98     QString trueText() const            { return m_trueText; }
99     void setFalseText(const QString &t) { m_falseText = t; }
100     QString falseText() const              { return m_falseText; }
101
102 signals:
103     void textChanged(const QString &);
104
105 private slots:
106     void slotStateChanged(int);
107
108 private:
109     QString m_trueText;
110     QString m_falseText;
111 };
112
113 // A simple custom wizard page presenting the fields to be used
114 // as page 2 of a BaseProjectWizardDialog if there are any fields.
115 // Uses the 'field' functionality of QWizard.
116 // Implements validatePage() as the field logic cannot be tied up
117 // with additional validation. Performs checking of the Javascript-based
118 // validation rules of the parameters and displays error messages in a red
119 // warning label.
120 class CustomWizardFieldPage : public QWizardPage {
121     Q_OBJECT
122 public:
123     typedef QList<CustomWizardField> FieldList;
124
125     explicit CustomWizardFieldPage(const QSharedPointer<CustomWizardContext> &ctx,
126                                    const QSharedPointer<CustomWizardParameters> &parameters,
127                                    QWidget *parent = 0);
128     virtual ~CustomWizardFieldPage();
129
130     virtual bool validatePage();
131     virtual void initializePage();
132
133     static QMap<QString, QString> replacementMap(const QWizard *w,
134                                                  const QSharedPointer<CustomWizardContext> &ctx,
135                                                  const FieldList &f);
136
137 protected:
138     inline void addRow(const QString &name, QWidget *w);
139     void showError(const QString &);
140     void clearError();
141 private:
142     struct LineEditData {
143         explicit LineEditData(QLineEdit* le = 0, const QString &defText = QString());
144         QLineEdit* lineEdit;
145         QString defaultText;
146     };
147     struct TextEditData {
148         explicit TextEditData(QTextEdit* le = 0, const QString &defText = QString());
149         QTextEdit* textEdit;
150         QString defaultText;
151     };
152     typedef QList<LineEditData> LineEditDataList;
153     typedef QList<TextEditData> TextEditDataList;
154
155     QWidget *registerLineEdit(const QString &fieldName, const CustomWizardField &field);
156     QWidget *registerComboBox(const QString &fieldName, const CustomWizardField &field);
157     QWidget *registerTextEdit(const QString &fieldName, const CustomWizardField &field);
158     QWidget *registerPathChooser(const QString &fieldName, const CustomWizardField &field);
159     QWidget *registerCheckBox(const QString &fieldName,
160                               const QString &fieldDescription,
161                               const CustomWizardField &field);
162     void addField(const CustomWizardField &f);
163
164     const QSharedPointer<CustomWizardParameters> m_parameters;
165     const QSharedPointer<CustomWizardContext> m_context;
166     QFormLayout *m_formLayout;
167     LineEditDataList m_lineEdits;
168     TextEditDataList m_textEdits;
169     QLabel *m_errorLabel;
170 };
171
172 // A custom wizard page presenting the fields to be used and a path chooser
173 // at the bottom (for use by "class"/"file" wizards). Does validation on
174 // the Path chooser only (as the other fields can by validated by regexps).
175
176 class CustomWizardPage : public CustomWizardFieldPage {
177     Q_OBJECT
178 public:
179     explicit CustomWizardPage(const QSharedPointer<CustomWizardContext> &ctx,
180                               const QSharedPointer<CustomWizardParameters> &parameters,
181                               QWidget *parent = 0);
182
183     QString path() const;
184     void setPath(const QString &path);
185
186     virtual bool isComplete() const;
187
188 private:
189     Utils::PathChooser *m_pathChooser;
190 };
191
192 } // namespace Internal
193 } // namespace ProjectExplorer
194
195 #endif // CUSTOMPROJECTWIZARDDIALOG_H