OSDN Git Service

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