Commit f7da76ab authored by Friedemann Kleint's avatar Friedemann Kleint

Fix Gui app wizard to write form classes consistent with Designer.

Make Gui app wizard use Qt Designer wizard code to write the classes.
Remove the settings from the form class wizard page extension area and
add a settings page instead. Polish the designer plugin's structs to
parametrize class generation with QSharedData and settings code.
Export them and use them in the Gui app wizard.

Task-number: 256927
parent 310e28ba
......@@ -5,11 +5,14 @@ DEFINES+=CPP_ENABLED
HEADERS+=$$PWD/formclasswizardpage.h \
$$PWD/formclasswizarddialog.h \
$$PWD/formclasswizard.h \
$$PWD/formclasswizardparameters.h
$$PWD/formclasswizardparameters.h \
$$PWD/cppsettingspage.h
SOURCES+=$$PWD/formclasswizardpage.cpp \
$$PWD/formclasswizarddialog.cpp \
$$PWD/formclasswizard.cpp \
$$PWD/formclasswizardparameters.cpp
$$PWD/formclasswizardparameters.cpp \
$$PWD/cppsettingspage.cpp
FORMS+=$$PWD/formclasswizardpage.ui
FORMS+=$$PWD/formclasswizardpage.ui \
$$PWD/cppsettingspagewidget.ui
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://www.qtsoftware.com/contact.
**
**************************************************************************/
#include "cppsettingspage.h"
#include "designerconstants.h"
#include <QtCore/QCoreApplication>
#include <coreplugin/icore.h>
namespace Designer {
namespace Internal {
// ---------- CppSettingsPageWidget
CppSettingsPageWidget::CppSettingsPageWidget(QWidget *parent) :
QWidget(parent)
{
m_ui.setupUi(this);
}
FormClassWizardGenerationParameters CppSettingsPageWidget::parameters() const
{
FormClassWizardGenerationParameters rc;
rc.setEmbedding(static_cast<FormClassWizardGenerationParameters::UiClassEmbedding>(uiEmbedding()));
rc.setRetranslationSupport(m_ui.retranslateCheckBox->isChecked());
rc.setIncludeQtModule(m_ui.includeQtModuleCheckBox->isChecked());
return rc;
}
void CppSettingsPageWidget::setParameters(const FormClassWizardGenerationParameters &p)
{
m_ui.retranslateCheckBox->setChecked(p.retranslationSupport());
m_ui.includeQtModuleCheckBox->setChecked(p.includeQtModule());
setUiEmbedding(p.embedding());
}
int CppSettingsPageWidget::uiEmbedding() const
{
if (m_ui.ptrAggregationRadioButton->isChecked())
return FormClassWizardGenerationParameters::PointerAggregatedUiClass;
if (m_ui.aggregationButton->isChecked())
return FormClassWizardGenerationParameters::AggregatedUiClass;
return FormClassWizardGenerationParameters::InheritedUiClass;
}
void CppSettingsPageWidget::setUiEmbedding(int v)
{
switch (v) {
case FormClassWizardGenerationParameters::PointerAggregatedUiClass:
m_ui.ptrAggregationRadioButton->setChecked(true);
break;
case FormClassWizardGenerationParameters::AggregatedUiClass:
m_ui.aggregationButton->setChecked(true);
break;
case FormClassWizardGenerationParameters::InheritedUiClass:
m_ui.multipleInheritanceButton->setChecked(true);
break;
}
}
// ---------- CppSettingsPage
CppSettingsPage::CppSettingsPage(QObject *parent) : Core::IOptionsPage(parent)
{
m_parameters.fromSettings(Core::ICore::instance()->settings());
}
QString CppSettingsPage::id() const
{
return QLatin1String(Designer::Constants::SETTINGS_CPP_SETTINGS);
}
QString CppSettingsPage::trName() const
{
return QCoreApplication::translate("Designer", Designer::Constants::SETTINGS_CPP_SETTINGS);
}
QString CppSettingsPage::category() const
{
return QLatin1String(Designer::Constants::SETTINGS_CATEGORY);
}
QString CppSettingsPage::trCategory() const
{
return QCoreApplication::translate("Designer", Designer::Constants::SETTINGS_CATEGORY);
}
QWidget *CppSettingsPage::createPage(QWidget *parent)
{
m_widget = new CppSettingsPageWidget(parent);
m_widget->setParameters(m_parameters);
return m_widget;
}
void CppSettingsPage::apply()
{
if (m_widget) {
const FormClassWizardGenerationParameters newParameters = m_widget->parameters();
if (newParameters != m_parameters) {
m_parameters = newParameters;
m_parameters.toSettings(Core::ICore::instance()->settings());
}
}
}
void CppSettingsPage::finish()
{
}
} // namespace Internal
} // namespace Designer
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://www.qtsoftware.com/contact.
**
**************************************************************************/
#ifndef CPPSETTINGSPAGE_H
#define CPPSETTINGSPAGE_H
#include "formclasswizardparameters.h"
#include "ui_cppsettingspagewidget.h"
#include <coreplugin/dialogs/ioptionspage.h>
#include <QtCore/QPointer>
namespace Designer {
namespace Internal {
class CppSettingsPageWidget : public QWidget
{
Q_OBJECT
public:
explicit CppSettingsPageWidget(QWidget *parent = 0);
FormClassWizardGenerationParameters parameters() const;
void setParameters(const FormClassWizardGenerationParameters &p);
private:
int uiEmbedding() const;
void setUiEmbedding(int);
Ui::CppSettingsPageWidget m_ui;
};
class CppSettingsPage : public Core::IOptionsPage
{
public:
explicit CppSettingsPage(QObject *parent = 0);
virtual QString id() const;
virtual QString trName() const;
virtual QString category() const;
virtual QString trCategory() const;
virtual QWidget *createPage(QWidget *parent);
virtual void apply();
virtual void finish();
private:
QPointer<CppSettingsPageWidget> m_widget;
FormClassWizardGenerationParameters m_parameters;
};
} // namespace Internal
} // namespace Designer
#endif // CPPSETTINGSPAGE_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Designer::Internal::CppSettingsPageWidget</class>
<widget class="QWidget" name="Designer::Internal::CppSettingsPageWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>526</width>
<height>369</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QGroupBox" name="uiclassGroupBox">
<property name="title">
<string>Embedding of the UI Class</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QRadioButton" name="ptrAggregationRadioButton">
<property name="text">
<string>Aggregation as a pointer member</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="aggregationButton">
<property name="text">
<string>Aggregation</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="multipleInheritanceButton">
<property name="text">
<string>Multiple Inheritance</string>
</property>
</widget>
</item>
</layout>
<zorder>aggregationButton</zorder>
<zorder>multipleInheritanceButton</zorder>
<zorder>ptrAggregationRadioButton</zorder>
</widget>
</item>
<item>
<widget class="QGroupBox" name="codeGenerationGroupBox">
<property name="title">
<string>Code Generation</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="retranslateCheckBox">
<property name="text">
<string>Support for changing languages at runtime</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="includeQtModuleCheckBox">
<property name="text">
<string>Include Qt module name</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>169</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -87,17 +87,17 @@ QWizard *FormClassWizard::createWizardDialog(QWidget *parent,
Core::GeneratedFiles FormClassWizard::generateFiles(const QWizard *w, QString *errorMessage) const
{
const FormClassWizardDialog *wizardDialog = qobject_cast<const FormClassWizardDialog *>(w);
const FormClassWizardParameters params = wizardDialog->parameters();
const Designer::FormClassWizardParameters params = wizardDialog->parameters();
if (params.uiTemplate.isEmpty()) {
if (params.uiTemplate().isEmpty()) {
*errorMessage = QLatin1String("Internal error: FormClassWizard::generateFiles: empty template contents");
return Core::GeneratedFiles();
}
// header
const QString formFileName = buildFileName(params.path, params.uiFile, formSuffix());
const QString headerFileName = buildFileName(params.path, params.headerFile, headerSuffix());
const QString sourceFileName = buildFileName(params.path, params.sourceFile, sourceSuffix());
const QString formFileName = buildFileName(params.path(), params.uiFile(), formSuffix());
const QString headerFileName = buildFileName(params.path(), params.headerFile(), headerSuffix());
const QString sourceFileName = buildFileName(params.path(), params.sourceFile(), sourceSuffix());
Core::GeneratedFile headerFile(headerFileName);
headerFile.setEditorKind(QLatin1String(CppEditor::Constants::CPPEDITOR_KIND));
......@@ -108,11 +108,13 @@ Core::GeneratedFiles FormClassWizard::generateFiles(const QWizard *w, QString *e
// UI
Core::GeneratedFile uiFile(formFileName);
uiFile.setContents(params.uiTemplate);
uiFile.setContents(params.uiTemplate());
uiFile.setEditorKind(QLatin1String(Constants::C_FORMEDITOR));
QString source, header;
params.generateCpp(&header, &source);
Designer::FormClassWizardGenerationParameters generationParameters;
generationParameters.fromSettings(Core::ICore::instance()->settings());
params.generateCpp(generationParameters, &header, &source);
sourceFile.setContents(source);
headerFile.setContents(header);
......
......@@ -98,7 +98,7 @@ FormClassWizardParameters FormClassWizardDialog::parameters() const
FormClassWizardParameters rc;
m_classPage->getParameters(&rc);
// Name the ui class in the Ui namespace after the class specified
rc.uiTemplate = FormTemplateWizardPage::changeUiClassName(m_rawFormTemplate, rc.className);
rc.setUiTemplate(FormTemplateWizardPage::changeUiClassName(m_rawFormTemplate, rc.className()));
return rc;
}
......
......@@ -37,9 +37,12 @@ namespace Core {
}
namespace Designer {
namespace Internal {
struct FormClassWizardParameters;
namespace Internal {
class FormClassWizardPage;
class FormTemplateWizardPage;
......@@ -56,7 +59,7 @@ public:
QString path() const;
FormClassWizardParameters parameters() const;
Designer::FormClassWizardParameters parameters() const;
bool validateCurrentPage();
......
......@@ -43,10 +43,6 @@
#include <QtGui/QAbstractButton>
#include <QtGui/QMessageBox>
static const char *formClassWizardPageGroupC = "FormClassWizardPage";
static const char *translationKeyC = "RetranslationSupport";
static const char *embeddingModeKeyC = "Embedding";
namespace Designer {
namespace Internal {
......@@ -64,13 +60,7 @@ FormClassWizardPage::FormClassWizardPage(QWidget * parent) :
m_ui->newClassWidget->setAllowDirectories(true);
connect(m_ui->newClassWidget, SIGNAL(validChanged()), this, SLOT(slotValidChanged()));
m_ui->extensionWidget->setVisible(false);
connect(m_ui->moreButton, SIGNAL(clicked(bool)), m_ui->extensionWidget, SLOT(setVisible(bool)));
connect(m_ui->settingsToolButton, SIGNAL(clicked()), this, SLOT(slotSettings()));
restoreSettings();
}
FormClassWizardPage::~FormClassWizardPage()
......@@ -79,13 +69,13 @@ FormClassWizardPage::~FormClassWizardPage()
}
// Retrieve settings of CppTools plugin.
static inline bool lowerCaseFiles(const Core::ICore *core)
static bool inline lowerCaseFiles(const Core::ICore *core)
{
QString camelCaseSettingsKey = QLatin1String(CppTools::Constants::CPPTOOLS_SETTINGSGROUP);
camelCaseSettingsKey += QLatin1Char('/');
camelCaseSettingsKey += QLatin1String(CppTools::Constants::LOWERCASE_CPPFILES_KEY);
QString lowerCaseSettingsKey = QLatin1String(CppTools::Constants::CPPTOOLS_SETTINGSGROUP);
lowerCaseSettingsKey += QLatin1Char('/');
lowerCaseSettingsKey += QLatin1String(CppTools::Constants::LOWERCASE_CPPFILES_KEY);
return core->settings()->value(camelCaseSettingsKey, QVariant(false)).toBool();
return core->settings()->value(lowerCaseSettingsKey, QVariant(false)).toBool();
}
// Set up new class widget from settings
......@@ -115,40 +105,6 @@ void FormClassWizardPage::setClassName(const QString &suggestedClassName)
slotValidChanged();
}
int FormClassWizardPage::uiClassEmbedding() const
{
if (m_ui->ptrAggregationRadioButton->isChecked())
return PointerAggregatedUiClass;
if (m_ui->aggregationButton->isChecked())
return AggregatedUiClass;
return InheritedUiClass;
}
void FormClassWizardPage::setUiClassEmbedding(int v)
{
switch (v) {
case PointerAggregatedUiClass:
m_ui->ptrAggregationRadioButton->setChecked(true);
break;
case AggregatedUiClass:
m_ui->aggregationButton->setChecked(true);
break;
case InheritedUiClass:
m_ui->multipleInheritanceButton->setChecked(true);
break;
}
}
bool FormClassWizardPage::hasRetranslationSupport() const
{
return m_ui->retranslateCheckBox->isChecked();
}
void FormClassWizardPage::setRetranslationSupport(bool v)
{
m_ui->retranslateCheckBox->setChecked(v);
}
QString FormClassWizardPage::path() const
{
return m_ui->newClassWidget->path();
......@@ -161,13 +117,11 @@ void FormClassWizardPage::setPath(const QString &p)
void FormClassWizardPage::getParameters(FormClassWizardParameters *p) const
{
p->embedding = static_cast<UiClassEmbedding>(uiClassEmbedding());
p->languageChange = m_ui->retranslateCheckBox->isChecked();
p->className = m_ui->newClassWidget->className();
p->path = path();
p->sourceFile = m_ui->newClassWidget->sourceFileName();
p->headerFile = m_ui->newClassWidget->headerFileName();
p->uiFile = m_ui->newClassWidget-> formFileName();
p->setClassName(m_ui->newClassWidget->className());
p->setPath(path());
p->setSourceFile(m_ui->newClassWidget->sourceFileName());
p->setHeaderFile(m_ui->newClassWidget->headerFileName());
p->setUiFile(m_ui->newClassWidget-> formFileName());
}
void FormClassWizardPage::slotValidChanged()
......@@ -188,47 +142,11 @@ bool FormClassWizardPage::validatePage()
{
QString errorMessage;
const bool rc = m_ui->newClassWidget->isValid(&errorMessage);
if (rc) {
saveSettings();
} else {
if (!rc) {
QMessageBox::critical(this, tr("%1 - Error").arg(title()), errorMessage);
}
return rc;
}
void FormClassWizardPage::saveSettings()
{
Core::ICore *core = Core::ICore::instance();
if (QSettings *settings = core->settings()) {
settings->beginGroup(QLatin1String(formClassWizardPageGroupC));
settings->setValue(QLatin1String(translationKeyC), hasRetranslationSupport());
settings->setValue(QLatin1String(embeddingModeKeyC), uiClassEmbedding());
settings->endGroup();
}
}
void FormClassWizardPage::restoreSettings()
{
bool retranslationSupport = true;
int embedding = PointerAggregatedUiClass;
Core::ICore *core = Core::ICore::instance();
if (QSettings *settings = core->settings()) {
QString key = QLatin1String(formClassWizardPageGroupC);
key += QLatin1Char('/');
const int groupLength = key.size();
key += QLatin1String(translationKeyC);
retranslationSupport = settings->value(key, retranslationSupport).toBool();
key.truncate(groupLength);
key += QLatin1String(embeddingModeKeyC);
embedding = settings->value(key, embedding).toInt();
}
setUiClassEmbedding(embedding);
setRetranslationSupport(retranslationSupport);
}
} // namespace Internal
} // namespace Designer
......@@ -33,13 +33,16 @@
#include <QtGui/QWizardPage>
namespace Designer {
struct FormClassWizardParameters;
struct FormClassWizardGenerationParameters;
namespace Internal {
namespace Ui {
class FormClassWizardPage;
}
struct FormClassWizardParameters;
class FormClassWizardPage : public QWizardPage
{
......@@ -52,18 +55,17 @@ public:
virtual bool isComplete () const;
virtual bool validatePage();
int uiClassEmbedding() const;
bool hasRetranslationSupport() const;
QString path() const;
// Fill out applicable parameters
void getParameters(FormClassWizardParameters *) const;
void getParameters(FormClassWizardParameters *) const;
FormClassWizardGenerationParameters generationParameters() const;