1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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.
16 ** GNU Lesser General Public License Usage
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.
25 ** If you are unsure which license is appropriate for your use, please
26 ** contact the sales department at http://qt.nokia.com/contact.
28 **************************************************************************/
30 #include "formclasswizardpage.h"
31 #include "ui_formclasswizardpage.h"
32 #include "formclasswizardparameters.h"
34 #include <coreplugin/icore.h>
35 #include <coreplugin/mimedatabase.h>
36 #include <cppeditor/cppeditorconstants.h>
37 #include <cpptools/cpptoolsconstants.h>
39 #include <QtCore/QDebug>
40 #include <QtCore/QSettings>
42 #include <QtGui/QAbstractButton>
43 #include <QtGui/QMessageBox>
48 // ----------------- FormClassWizardPage
50 FormClassWizardPage::FormClassWizardPage(QWidget * parent) :
52 m_ui(new Ui::FormClassWizardPage),
57 m_ui->newClassWidget->setBaseClassInputVisible(false);
58 m_ui->newClassWidget->setNamespacesEnabled(true);
59 m_ui->newClassWidget->setAllowDirectories(true);
60 m_ui->newClassWidget->setClassTypeComboVisible(false);
62 connect(m_ui->newClassWidget, SIGNAL(validChanged()), this, SLOT(slotValidChanged()));
63 connect(m_ui->settingsToolButton, SIGNAL(clicked()), this, SLOT(slotSettings()));
65 initFileGenerationSettings();
68 FormClassWizardPage::~FormClassWizardPage()
73 // Retrieve settings of CppTools plugin.
74 static bool inline lowerCaseFiles(const Core::ICore *core)
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();
83 // Set up new class widget from settings
84 void FormClassWizardPage::initFileGenerationSettings()
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));
93 // Pop up settings dialog for generation settings
94 void FormClassWizardPage::slotSettings()
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();
104 void FormClassWizardPage::setClassName(const QString &suggestedClassName)
107 m_ui->newClassWidget->setClassName(suggestedClassName);
111 QString FormClassWizardPage::path() const
113 return m_ui->newClassWidget->path();
116 void FormClassWizardPage::setPath(const QString &p)
118 m_ui->newClassWidget->setPath(p);
121 void FormClassWizardPage::getParameters(FormClassWizardParameters *p) const
123 p->setClassName(m_ui->newClassWidget->className());
125 p->setSourceFile(m_ui->newClassWidget->sourceFileName());
126 p->setHeaderFile(m_ui->newClassWidget->headerFileName());
127 p->setUiFile(m_ui->newClassWidget-> formFileName());
130 void FormClassWizardPage::slotValidChanged()
132 const bool validNow = m_ui->newClassWidget->isValid();
133 if (m_isValid != validNow) {
134 m_isValid = validNow;
135 emit completeChanged();
139 bool FormClassWizardPage::isComplete() const
144 bool FormClassWizardPage::validatePage()
146 QString errorMessage;
147 const bool rc = m_ui->newClassWidget->isValid(&errorMessage);
149 QMessageBox::warning(this, tr("%1 - Error").arg(title()), errorMessage);
154 } // namespace Internal
155 } // namespace Designer