1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25 
26 #pragma once
27 
28 #include <QComboBox>
29 #include <QCheckBox>
30 #include <QWizardPage>
31 #include <QSharedPointer>
32 
33 QT_BEGIN_NAMESPACE
34 class QFormLayout;
35 class QLineEdit;
36 class QTextEdit;
37 class QLabel;
38 QT_END_NAMESPACE
39 
40 namespace Utils { class PathChooser; }
41 
42 namespace ProjectExplorer {
43 namespace Internal {
44 
45 class CustomWizardField;
46 class CustomWizardParameters;
47 class CustomWizardContext;
48 
49 // Documentation inside.
50 class CustomWizardFieldPage : public QWizardPage {
51     Q_OBJECT
52 public:
53     using FieldList = QList<CustomWizardField>;
54 
55     explicit CustomWizardFieldPage(const QSharedPointer<CustomWizardContext> &ctx,
56                                    const QSharedPointer<CustomWizardParameters> &parameters,
57                                    QWidget *parent = nullptr);
58 
59     bool validatePage() override;
60     void initializePage() override;
61     void cleanupPage() override;
62 
63     static QMap<QString, QString> replacementMap(const QWizard *w,
64                                                  const QSharedPointer<CustomWizardContext> &ctx,
65                                                  const FieldList &f);
66 
67 protected:
68     inline void addRow(const QString &name, QWidget *w);
69     void showError(const QString &);
70     void clearError();
71 private:
72     class LineEditData {
73     public:
74         explicit LineEditData(QLineEdit *le = nullptr, const QString &defText = QString(), const QString &pText = QString());
75         QLineEdit *lineEdit;
76         QString defaultText;
77         QString placeholderText;
78         QString userChange;
79     };
80     class TextEditData {
81     public:
82         explicit TextEditData(QTextEdit *le = nullptr, const QString &defText = QString());
83         QTextEdit *textEdit;
84         QString defaultText;
85         QString userChange;
86     };
87     class PathChooserData {
88     public:
89         explicit PathChooserData(Utils::PathChooser *pe = nullptr, const QString &defText = QString());
90         Utils::PathChooser *pathChooser;
91         QString defaultText;
92         QString userChange;
93     };
94 
95     using LineEditDataList = QList<LineEditData>;
96     using TextEditDataList = QList<TextEditData>;
97     using PathChooserDataList = QList<PathChooserData>;
98 
99     QWidget *registerLineEdit(const QString &fieldName, const CustomWizardField &field);
100     QWidget *registerComboBox(const QString &fieldName, const CustomWizardField &field);
101     QWidget *registerTextEdit(const QString &fieldName, const CustomWizardField &field);
102     QWidget *registerPathChooser(const QString &fieldName, const CustomWizardField &field);
103     QWidget *registerCheckBox(const QString &fieldName,
104                               const QString &fieldDescription,
105                               const CustomWizardField &field);
106     void addField(const CustomWizardField &f);
107 
108     const QSharedPointer<CustomWizardParameters> m_parameters;
109     const QSharedPointer<CustomWizardContext> m_context;
110     QFormLayout *m_formLayout;
111     LineEditDataList m_lineEdits;
112     TextEditDataList m_textEdits;
113     PathChooserDataList m_pathChoosers;
114     QLabel *m_errorLabel;
115 };
116 
117 // Documentation inside.
118 class CustomWizardPage : public CustomWizardFieldPage {
119     Q_OBJECT
120 public:
121     explicit CustomWizardPage(const QSharedPointer<CustomWizardContext> &ctx,
122                               const QSharedPointer<CustomWizardParameters> &parameters,
123                               QWidget *parent = nullptr);
124 
125     QString path() const;
126     void setPath(const QString &path);
127 
128     bool isComplete() const override;
129 
130 private:
131     Utils::PathChooser *m_pathChooser;
132 };
133 
134 } // namespace Internal
135 } // namespace ProjectExplorer
136