OSDN Git Service

Class wizard: Replace "inherits QObject" by type information combo.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / designer / cpp / formclasswizardpage.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** Commercial Usage
10 **
11 ** Licensees holding valid Qt Commercial licenses may use this file in
12 ** accordance with the Qt Commercial License Agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Nokia.
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 ** If you are unsure which license is appropriate for your use, please
26 ** contact the sales department at http://qt.nokia.com/contact.
27 **
28 **************************************************************************/
29
30 #include "formclasswizardpage.h"
31 #include "ui_formclasswizardpage.h"
32 #include "formclasswizardparameters.h"
33
34 #include <coreplugin/icore.h>
35 #include <coreplugin/mimedatabase.h>
36 #include <cppeditor/cppeditorconstants.h>
37 #include <cpptools/cpptoolsconstants.h>
38
39 #include <QtCore/QDebug>
40 #include <QtCore/QSettings>
41
42 #include <QtGui/QAbstractButton>
43 #include <QtGui/QMessageBox>
44
45 namespace Designer {
46 namespace Internal {
47
48 // ----------------- FormClassWizardPage
49
50 FormClassWizardPage::FormClassWizardPage(QWidget * parent) :
51     QWizardPage(parent),
52     m_ui(new Ui::FormClassWizardPage),
53     m_isValid(false)
54 {
55     m_ui->setupUi(this);
56
57     m_ui->newClassWidget->setBaseClassInputVisible(false);
58     m_ui->newClassWidget->setNamespacesEnabled(true);
59     m_ui->newClassWidget->setAllowDirectories(true);
60     m_ui->newClassWidget->setClassTypeComboVisible(false);
61
62     connect(m_ui->newClassWidget, SIGNAL(validChanged()), this, SLOT(slotValidChanged()));
63     connect(m_ui->settingsToolButton, SIGNAL(clicked()), this, SLOT(slotSettings()));
64
65     initFileGenerationSettings();
66 }
67
68 FormClassWizardPage::~FormClassWizardPage()
69 {
70     delete m_ui;
71 }
72
73 // Retrieve settings of CppTools plugin.
74 static  bool inline lowerCaseFiles(const Core::ICore *core)
75 {
76     QString lowerCaseSettingsKey = QLatin1String(CppTools::Constants::CPPTOOLS_SETTINGSGROUP);
77     lowerCaseSettingsKey += QLatin1Char('/');
78     lowerCaseSettingsKey += QLatin1String(CppTools::Constants::LOWERCASE_CPPFILES_KEY);
79     const bool lowerCaseDefault = CppTools::Constants::lowerCaseFilesDefault;
80     return core->settings()->value(lowerCaseSettingsKey, QVariant(lowerCaseDefault)).toBool();
81 }
82
83 // Set up new class widget from settings
84 void FormClassWizardPage::initFileGenerationSettings()
85 {
86     Core::ICore *core = Core::ICore::instance();
87     const Core::MimeDatabase *mdb = core->mimeDatabase();
88     m_ui->newClassWidget->setHeaderExtension(mdb->preferredSuffixByType(QLatin1String(CppTools::Constants::CPP_HEADER_MIMETYPE)));
89     m_ui->newClassWidget->setSourceExtension(mdb->preferredSuffixByType(QLatin1String(CppTools::Constants::CPP_SOURCE_MIMETYPE)));
90     m_ui->newClassWidget->setLowerCaseFiles(lowerCaseFiles(core));
91 }
92
93 // Pop up settings dialog for generation settings
94 void FormClassWizardPage::slotSettings()
95 {
96     const QString id = QLatin1String(CppTools::Constants::CPP_SETTINGS_ID);
97     const QString cat = QLatin1String(CppTools::Constants::CPP_SETTINGS_CATEGORY);
98     if (Core::ICore::instance()->showOptionsDialog(cat, id, this)) {
99         initFileGenerationSettings();
100         m_ui->newClassWidget->triggerUpdateFileNames();
101     }
102 }
103
104 void FormClassWizardPage::setClassName(const QString &suggestedClassName)
105 {
106     // Is it valid, now?
107     m_ui->newClassWidget->setClassName(suggestedClassName);
108     slotValidChanged();
109 }
110
111 QString FormClassWizardPage::path() const
112 {
113     return m_ui->newClassWidget->path();
114 }
115
116 void FormClassWizardPage::setPath(const QString &p)
117 {
118     m_ui->newClassWidget->setPath(p);
119 }
120
121 void FormClassWizardPage::getParameters(FormClassWizardParameters *p) const
122 {
123     p->setClassName(m_ui->newClassWidget->className());
124     p->setPath(path());
125     p->setSourceFile(m_ui->newClassWidget->sourceFileName());
126     p->setHeaderFile(m_ui->newClassWidget->headerFileName());
127     p->setUiFile(m_ui->newClassWidget-> formFileName());
128 }
129
130 void FormClassWizardPage::slotValidChanged()
131 {
132     const bool validNow = m_ui->newClassWidget->isValid();
133     if (m_isValid != validNow) {
134         m_isValid = validNow;
135         emit completeChanged();
136     }
137 }
138
139 bool FormClassWizardPage::isComplete() const
140 {
141     return m_isValid;
142 }
143
144 bool FormClassWizardPage::validatePage()
145 {
146     QString errorMessage;
147     const bool rc = m_ui->newClassWidget->isValid(&errorMessage);
148     if (!rc) {
149         QMessageBox::warning(this, tr("%1 - Error").arg(title()), errorMessage);
150     }
151     return rc;
152 }
153
154 } // namespace Internal
155 } // namespace Designer