1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
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 ** 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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "formclasswizardpage.h"
35 #include "ui_formclasswizardpage.h"
36 #include "formclasswizardparameters.h"
38 #include <coreplugin/icore.h>
39 #include <coreplugin/mimedatabase.h>
40 #include <cppeditor/cppeditorconstants.h>
41 #include <cpptools/cpptoolsconstants.h>
43 #include <QtCore/QDebug>
44 #include <QtCore/QSettings>
46 #include <QtGui/QAbstractButton>
47 #include <QtGui/QMessageBox>
52 // ----------------- FormClassWizardPage
54 FormClassWizardPage::FormClassWizardPage(QWidget * parent) :
56 m_ui(new Ui::FormClassWizardPage),
61 m_ui->newClassWidget->setBaseClassInputVisible(false);
62 m_ui->newClassWidget->setNamespacesEnabled(true);
63 m_ui->newClassWidget->setAllowDirectories(true);
64 m_ui->newClassWidget->setClassTypeComboVisible(false);
66 connect(m_ui->newClassWidget, SIGNAL(validChanged()), this, SLOT(slotValidChanged()));
68 initFileGenerationSettings();
71 FormClassWizardPage::~FormClassWizardPage()
76 // Retrieve settings of CppTools plugin.
77 bool FormClassWizardPage::lowercaseHeaderFiles()
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();
86 // Set up new class widget from settings
87 void FormClassWizardPage::initFileGenerationSettings()
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());
96 void FormClassWizardPage::setClassName(const QString &suggestedClassName)
99 m_ui->newClassWidget->setClassName(suggestedClassName);
103 QString FormClassWizardPage::path() const
105 return m_ui->newClassWidget->path();
108 void FormClassWizardPage::setPath(const QString &p)
110 m_ui->newClassWidget->setPath(p);
113 void FormClassWizardPage::getParameters(FormClassWizardParameters *p) const
115 p->className = m_ui->newClassWidget->className();
117 p->sourceFile = m_ui->newClassWidget->sourceFileName();
118 p->headerFile = m_ui->newClassWidget->headerFileName();
119 p->uiFile = m_ui->newClassWidget-> formFileName();
122 void FormClassWizardPage::slotValidChanged()
124 const bool validNow = m_ui->newClassWidget->isValid();
125 if (m_isValid != validNow) {
126 m_isValid = validNow;
127 emit completeChanged();
131 bool FormClassWizardPage::isComplete() const
136 bool FormClassWizardPage::validatePage()
138 QString errorMessage;
139 const bool rc = m_ui->newClassWidget->isValid(&errorMessage);
141 QMessageBox::warning(this, tr("%1 - Error").arg(title()), errorMessage);
146 } // namespace Internal
147 } // namespace Designer