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 #include "formclasswizarddialog.h"
27 #include "formclasswizardpage.h"
28 #include "formclasswizardparameters.h"
29 #include <cpptools/abstracteditorsupport.h>
30 #include <designer/formtemplatewizardpage.h>
31 #include <qtsupport/codegenerator.h>
32
33 enum { FormPageId, ClassPageId };
34
35 namespace Designer {
36 namespace Internal {
37
38 // ----------------- FormClassWizardDialog
FormClassWizardDialog(const Core::BaseFileWizardFactory * factory,QWidget * parent)39 FormClassWizardDialog::FormClassWizardDialog(const Core::BaseFileWizardFactory *factory,
40 QWidget *parent) :
41 Core::BaseFileWizard(factory, QVariantMap(), parent),
42 m_formPage(new FormTemplateWizardPage),
43 m_classPage(new FormClassWizardPage)
44 {
45 setWindowTitle(tr("Qt Designer Form Class"));
46
47 setPage(FormPageId, m_formPage);
48 setPage(ClassPageId, m_classPage);
49
50 const auto pages = extensionPages();
51 for (QWizardPage *p : pages)
52 addPage(p);
53 }
54
path() const55 QString FormClassWizardDialog::path() const
56 {
57 return m_classPage->path();
58 }
59
setPath(const QString & p)60 void FormClassWizardDialog::setPath(const QString &p)
61 {
62 m_classPage->setPath(p);
63 }
64
initializePage(int id)65 void FormClassWizardDialog::initializePage(int id)
66 {
67 Core::BaseFileWizard::initializePage(id);
68 // Switching from form to class page: store XML template and set a suitable
69 // class name in the class page based on the form base class
70 if (id == ClassPageId) {
71 QString formBaseClass;
72 QString uiClassName;
73 m_rawFormTemplate = m_formPage->templateContents();
74 // Strip namespaces from the ui class and suggest it as a new class
75 // name
76 if (QtSupport::CodeGenerator::uiData(m_rawFormTemplate, &formBaseClass, &uiClassName))
77 m_classPage->setClassName(FormTemplateWizardPage::stripNamespaces(uiClassName));
78 }
79 }
80
parameters() const81 FormClassWizardParameters FormClassWizardDialog::parameters() const
82 {
83 FormClassWizardParameters rc;
84 m_classPage->getParameters(&rc);
85 // Name the ui class in the Ui namespace after the class specified
86 rc.uiTemplate = QtSupport::CodeGenerator::changeUiClassName(m_rawFormTemplate, rc.className);
87 rc.usePragmaOnce = CppTools::AbstractEditorSupport::usePragmaOnce();
88 return rc;
89 }
90
91 } // namespace Internal
92 } // namespace Designer
93