OSDN Git Service

Update license.
[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) 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 #include "formclasswizardpage.h"
34 #include "ui_formclasswizardpage.h"
35 #include "formclasswizardparameters.h"
36
37 #include <coreplugin/icore.h>
38 #include <coreplugin/mimedatabase.h>
39 #include <cppeditor/cppeditorconstants.h>
40 #include <cpptools/cpptoolsconstants.h>
41
42 #include <QtCore/QDebug>
43 #include <QtCore/QSettings>
44
45 #include <QtGui/QAbstractButton>
46 #include <QtGui/QMessageBox>
47
48 namespace Designer {
49 namespace Internal {
50
51 // ----------------- FormClassWizardPage
52
53 FormClassWizardPage::FormClassWizardPage(QWidget * parent) :
54     QWizardPage(parent),
55     m_ui(new Ui::FormClassWizardPage),
56     m_isValid(false)
57 {
58     m_ui->setupUi(this);
59
60     m_ui->newClassWidget->setBaseClassInputVisible(false);
61     m_ui->newClassWidget->setNamespacesEnabled(true);
62     m_ui->newClassWidget->setAllowDirectories(true);
63     m_ui->newClassWidget->setClassTypeComboVisible(false);
64
65     connect(m_ui->newClassWidget, SIGNAL(validChanged()), this, SLOT(slotValidChanged()));
66
67     initFileGenerationSettings();
68 }
69
70 FormClassWizardPage::~FormClassWizardPage()
71 {
72     delete m_ui;
73 }
74
75 // Retrieve settings of CppTools plugin.
76 bool FormClassWizardPage::lowercaseHeaderFiles()
77 {
78     QString lowerCaseSettingsKey = QLatin1String(CppTools::Constants::CPPTOOLS_SETTINGSGROUP);
79     lowerCaseSettingsKey += QLatin1Char('/');
80     lowerCaseSettingsKey += QLatin1String(CppTools::Constants::LOWERCASE_CPPFILES_KEY);
81     const bool lowerCaseDefault = CppTools::Constants::lowerCaseFilesDefault;
82     return Core::ICore::instance()->settings()->value(lowerCaseSettingsKey, QVariant(lowerCaseDefault)).toBool();
83 }
84
85 // Set up new class widget from settings
86 void FormClassWizardPage::initFileGenerationSettings()
87 {
88     Core::ICore *core = Core::ICore::instance();
89     const Core::MimeDatabase *mdb = core->mimeDatabase();
90     m_ui->newClassWidget->setHeaderExtension(mdb->preferredSuffixByType(QLatin1String(CppTools::Constants::CPP_HEADER_MIMETYPE)));
91     m_ui->newClassWidget->setSourceExtension(mdb->preferredSuffixByType(QLatin1String(CppTools::Constants::CPP_SOURCE_MIMETYPE)));
92     m_ui->newClassWidget->setLowerCaseFiles(lowercaseHeaderFiles());
93 }
94
95 void FormClassWizardPage::setClassName(const QString &suggestedClassName)
96 {
97     // Is it valid, now?
98     m_ui->newClassWidget->setClassName(suggestedClassName);
99     slotValidChanged();
100 }
101
102 QString FormClassWizardPage::path() const
103 {
104     return m_ui->newClassWidget->path();
105 }
106
107 void FormClassWizardPage::setPath(const QString &p)
108 {
109     m_ui->newClassWidget->setPath(p);
110 }
111
112 void FormClassWizardPage::getParameters(FormClassWizardParameters *p) const
113 {
114     p->className = m_ui->newClassWidget->className();
115     p->path = path();
116     p->sourceFile = m_ui->newClassWidget->sourceFileName();
117     p->headerFile = m_ui->newClassWidget->headerFileName();
118     p->uiFile = m_ui->newClassWidget-> formFileName();
119 }
120
121 void FormClassWizardPage::slotValidChanged()
122 {
123     const bool validNow = m_ui->newClassWidget->isValid();
124     if (m_isValid != validNow) {
125         m_isValid = validNow;
126         emit completeChanged();
127     }
128 }
129
130 bool FormClassWizardPage::isComplete() const
131 {
132     return m_isValid;
133 }
134
135 bool FormClassWizardPage::validatePage()
136 {
137     QString errorMessage;
138     const bool rc = m_ui->newClassWidget->isValid(&errorMessage);
139     if (!rc) {
140         QMessageBox::warning(this, tr("%1 - Error").arg(title()), errorMessage);
141     }
142     return rc;
143 }
144
145 } // namespace Internal
146 } // namespace Designer