1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
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.
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "formclasswizardpage.h"
34 #include "ui_formclasswizardpage.h"
35 #include "formclasswizardparameters.h"
37 #include <coreplugin/icore.h>
38 #include <coreplugin/mimedatabase.h>
39 #include <cppeditor/cppeditorconstants.h>
40 #include <cpptools/cpptoolsconstants.h>
42 #include <QtCore/QDebug>
43 #include <QtCore/QSettings>
45 #include <QtGui/QAbstractButton>
46 #include <QtGui/QMessageBox>
51 // ----------------- FormClassWizardPage
53 FormClassWizardPage::FormClassWizardPage(QWidget * parent) :
55 m_ui(new Ui::FormClassWizardPage),
60 m_ui->newClassWidget->setBaseClassInputVisible(false);
61 m_ui->newClassWidget->setNamespacesEnabled(true);
62 m_ui->newClassWidget->setAllowDirectories(true);
63 m_ui->newClassWidget->setClassTypeComboVisible(false);
65 connect(m_ui->newClassWidget, SIGNAL(validChanged()), this, SLOT(slotValidChanged()));
67 initFileGenerationSettings();
70 FormClassWizardPage::~FormClassWizardPage()
75 // Retrieve settings of CppTools plugin.
76 bool FormClassWizardPage::lowercaseHeaderFiles()
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();
85 // Set up new class widget from settings
86 void FormClassWizardPage::initFileGenerationSettings()
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());
95 void FormClassWizardPage::setClassName(const QString &suggestedClassName)
98 m_ui->newClassWidget->setClassName(suggestedClassName);
102 QString FormClassWizardPage::path() const
104 return m_ui->newClassWidget->path();
107 void FormClassWizardPage::setPath(const QString &p)
109 m_ui->newClassWidget->setPath(p);
112 void FormClassWizardPage::getParameters(FormClassWizardParameters *p) const
114 p->className = m_ui->newClassWidget->className();
116 p->sourceFile = m_ui->newClassWidget->sourceFileName();
117 p->headerFile = m_ui->newClassWidget->headerFileName();
118 p->uiFile = m_ui->newClassWidget-> formFileName();
121 void FormClassWizardPage::slotValidChanged()
123 const bool validNow = m_ui->newClassWidget->isValid();
124 if (m_isValid != validNow) {
125 m_isValid = validNow;
126 emit completeChanged();
130 bool FormClassWizardPage::isComplete() const
135 bool FormClassWizardPage::validatePage()
137 QString errorMessage;
138 const bool rc = m_ui->newClassWidget->isValid(&errorMessage);
140 QMessageBox::warning(this, tr("%1 - Error").arg(title()), errorMessage);
145 } // namespace Internal
146 } // namespace Designer