OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / designer / cpp / formclasswizarddialog.cpp
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 (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "formclasswizarddialog.h"
35 #include "formtemplatewizardpage.h"
36 #include "formclasswizardpage.h"
37 #include "formclasswizardparameters.h"
38
39 #include <coreplugin/basefilewizard.h>
40
41 #include <QtCore/QDebug>
42 #include <QtGui/QAbstractButton>
43
44 enum { FormPageId, ClassPageId };
45
46 namespace Designer {
47 namespace Internal {
48
49 // ----------------- FormClassWizardDialog
50 FormClassWizardDialog::FormClassWizardDialog(const WizardPageList &extensionPages,
51                                              QWidget *parent) :
52     Utils::Wizard(parent),
53     m_formPage(new FormTemplateWizardPage),
54     m_classPage(new FormClassWizardPage)
55 {
56     setWindowTitle(tr("Qt Designer Form Class"));
57
58     setPage(FormPageId, m_formPage);
59     wizardProgress()->item(FormPageId)->setTitle(tr("Form Template"));
60     connect(m_formPage, SIGNAL(templateActivated()),
61             button(QWizard::NextButton), SLOT(animateClick()));
62
63     setPage(ClassPageId, m_classPage);
64     wizardProgress()->item(ClassPageId)->setTitle(tr("Class Details"));
65
66     foreach (QWizardPage *p, extensionPages)
67         Core::BaseFileWizard::applyExtensionPageShortTitle(this, addPage(p));
68 }
69
70 QString FormClassWizardDialog::path() const
71 {
72     return m_classPage->path();
73 }
74
75 void FormClassWizardDialog::setPath(const QString &p)
76 {
77     m_classPage->setPath(p);
78 }
79
80 bool FormClassWizardDialog::validateCurrentPage()
81 {
82     return QWizard::validateCurrentPage();
83 }
84
85 void FormClassWizardDialog::initializePage(int id)
86 {
87     QWizard::initializePage(id);
88     // Switching from form to class page: store XML template and set a suitable
89     // class name in the class page based on the form base class
90     if (id == ClassPageId) {
91         QString formBaseClass;
92         QString uiClassName;
93         m_rawFormTemplate = m_formPage->templateContents();
94         // Strip namespaces from the ui class and suggest it as a new class
95         // name
96         if (FormTemplateWizardPage::getUIXmlData(m_rawFormTemplate, &formBaseClass, &uiClassName))
97             m_classPage->setClassName(FormTemplateWizardPage::stripNamespaces(uiClassName));
98     }
99 }
100
101 FormClassWizardParameters FormClassWizardDialog::parameters() const
102 {
103     FormClassWizardParameters rc;
104     m_classPage->getParameters(&rc);
105     // Name the ui class in the Ui namespace after the class specified
106     rc.uiTemplate = FormTemplateWizardPage::changeUiClassName(m_rawFormTemplate, rc.className);
107     return rc;
108 }
109
110 } // namespace Internal
111 } // namespace Designer