summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>2009-07-01 16:27:40 +0200
committerFriedemann Kleint <Friedemann.Kleint@nokia.com>2009-07-01 16:27:40 +0200
commitf7da76ab277977438dadbf388cd17898e3e4b677 (patch)
tree5ec9fec6ca2184c4cc2a84bf5f40ec774a474098
parent310e28ba95d297366e6838996cefaf8099eb89cd (diff)
downloadqt-creator-f7da76ab277977438dadbf388cd17898e3e4b677.tar.gz
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
-rw-r--r--src/plugins/designer/cpp/cpp.pri9
-rw-r--r--src/plugins/designer/cpp/cppsettingspage.cpp136
-rw-r--r--src/plugins/designer/cpp/cppsettingspage.h81
-rw-r--r--src/plugins/designer/cpp/cppsettingspagewidget.ui110
-rw-r--r--src/plugins/designer/cpp/formclasswizard.cpp16
-rw-r--r--src/plugins/designer/cpp/formclasswizarddialog.cpp2
-rw-r--r--src/plugins/designer/cpp/formclasswizarddialog.h7
-rw-r--r--src/plugins/designer/cpp/formclasswizardpage.cpp104
-rw-r--r--src/plugins/designer/cpp/formclasswizardpage.h16
-rw-r--r--src/plugins/designer/cpp/formclasswizardpage.ui112
-rw-r--r--src/plugins/designer/cpp/formclasswizardparameters.cpp333
-rw-r--r--src/plugins/designer/cpp/formclasswizardparameters.h98
-rw-r--r--src/plugins/designer/designerconstants.h5
-rw-r--r--src/plugins/designer/formeditorplugin.cpp38
-rw-r--r--src/plugins/designer/formeditorplugin.h16
-rw-r--r--src/plugins/designer/formtemplatewizardpage.h4
-rw-r--r--src/plugins/designer/settingspage.cpp6
-rw-r--r--src/plugins/qt4projectmanager/wizards/guiappwizard.cpp60
18 files changed, 826 insertions, 327 deletions
diff --git a/src/plugins/designer/cpp/cpp.pri b/src/plugins/designer/cpp/cpp.pri
index 3827bc836f..a30a794022 100644
--- a/src/plugins/designer/cpp/cpp.pri
+++ b/src/plugins/designer/cpp/cpp.pri
@@ -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
diff --git a/src/plugins/designer/cpp/cppsettingspage.cpp b/src/plugins/designer/cpp/cppsettingspage.cpp
new file mode 100644
index 0000000000..1486bd0ad2
--- /dev/null
+++ b/src/plugins/designer/cpp/cppsettingspage.cpp
@@ -0,0 +1,136 @@
+/**************************************************************************
+**
+** 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
diff --git a/src/plugins/designer/cpp/cppsettingspage.h b/src/plugins/designer/cpp/cppsettingspage.h
new file mode 100644
index 0000000000..bb52a83363
--- /dev/null
+++ b/src/plugins/designer/cpp/cppsettingspage.h
@@ -0,0 +1,81 @@
+/**************************************************************************
+**
+** 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
diff --git a/src/plugins/designer/cpp/cppsettingspagewidget.ui b/src/plugins/designer/cpp/cppsettingspagewidget.ui
new file mode 100644
index 0000000000..8a34601df9
--- /dev/null
+++ b/src/plugins/designer/cpp/cppsettingspagewidget.ui
@@ -0,0 +1,110 @@
+<?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>
diff --git a/src/plugins/designer/cpp/formclasswizard.cpp b/src/plugins/designer/cpp/formclasswizard.cpp
index 28e767ee9b..3cbb42f5ae 100644
--- a/src/plugins/designer/cpp/formclasswizard.cpp
+++ b/src/plugins/designer/cpp/formclasswizard.cpp
@@ -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);
diff --git a/src/plugins/designer/cpp/formclasswizarddialog.cpp b/src/plugins/designer/cpp/formclasswizarddialog.cpp
index f1b95e1729..191200b9e3 100644
--- a/src/plugins/designer/cpp/formclasswizarddialog.cpp
+++ b/src/plugins/designer/cpp/formclasswizarddialog.cpp
@@ -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;
}
diff --git a/src/plugins/designer/cpp/formclasswizarddialog.h b/src/plugins/designer/cpp/formclasswizarddialog.h
index bcbe8e9885..c6522de3ab 100644
--- a/src/plugins/designer/cpp/formclasswizarddialog.h
+++ b/src/plugins/designer/cpp/formclasswizarddialog.h
@@ -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();
diff --git a/src/plugins/designer/cpp/formclasswizardpage.cpp b/src/plugins/designer/cpp/formclasswizardpage.cpp
index 9697ed33a0..86284a6ee8 100644
--- a/src/plugins/designer/cpp/formclasswizardpage.cpp
+++ b/src/plugins/designer/cpp/formclasswizardpage.cpp
@@ -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
diff --git a/src/plugins/designer/cpp/formclasswizardpage.h b/src/plugins/designer/cpp/formclasswizardpage.h
index 7221460427..d335d95366 100644
--- a/src/plugins/designer/cpp/formclasswizardpage.h
+++ b/src/plugins/designer/cpp/formclasswizardpage.h
@@ -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;
+ void setGenerationParameters(const FormClassWizardGenerationParameters &gp);
public slots:
void setClassName(const QString &suggestedClassName);
void setPath(const QString &);
- void setRetranslationSupport(bool);
- void setUiClassEmbedding(int v);
void slotSettings();
private slots:
@@ -71,8 +73,6 @@ private slots:
private:
void initParameters();
- void saveSettings();
- void restoreSettings();
Ui::FormClassWizardPage *m_ui;
bool m_isValid;
diff --git a/src/plugins/designer/cpp/formclasswizardpage.ui b/src/plugins/designer/cpp/formclasswizardpage.ui
index 9a2849ad0a..6381b45fd0 100644
--- a/src/plugins/designer/cpp/formclasswizardpage.ui
+++ b/src/plugins/designer/cpp/formclasswizardpage.ui
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>552</width>
- <height>498</height>
+ <width>542</width>
+ <height>267</height>
</rect>
</property>
<property name="title">
@@ -21,7 +21,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
- <widget class="Core::Utils::NewClassWidget" name="newClassWidget" native="true"/>
+ <widget class="Core::Utils::NewClassWidget" name="newClassWidget"/>
</item>
</layout>
</widget>
@@ -48,114 +48,8 @@
</property>
</widget>
</item>
- <item>
- <widget class="QToolButton" name="moreButton">
- <property name="text">
- <string>More</string>
- </property>
- <property name="checkable">
- <bool>true</bool>
- </property>
- </widget>
- </item>
</layout>
</item>
- <item row="1" column="0">
- <widget class="QWidget" name="extensionWidget" native="true">
- <layout class="QVBoxLayout" name="verticalLayout_5">
- <property name="margin">
- <number>0</number>
- </property>
- <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>
- <attribute name="buttonGroup">
- <string notr="true">buttonGroup</string>
- </attribute>
- </widget>
- </item>
- <item>
- <widget class="QRadioButton" name="aggregationButton">
- <property name="text">
- <string>Aggregation</string>
- </property>
- <attribute name="buttonGroup">
- <string notr="true">buttonGroup</string>
- </attribute>
- </widget>
- </item>
- <item>
- <widget class="QRadioButton" name="multipleInheritanceButton">
- <property name="text">
- <string>Multiple Inheritance</string>
- </property>
- <attribute name="buttonGroup">
- <string notr="true">buttonGroup</string>
- </attribute>
- </widget>
- </item>
- </layout>
- <zorder>aggregationButton</zorder>
- <zorder>multipleInheritanceButton</zorder>
- <zorder>ptrAggregationRadioButton</zorder>
- </widget>
- </item>
- <item>
- <widget class="QGroupBox" name="variousGroupBox">
- <property name="title">
- <string/>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout_3">
- <item>
- <widget class="QCheckBox" name="retranslateCheckBox">
- <property name="text">
- <string>Support for changing languages at runtime</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- <item>
- <spacer name="verticalSpacer_3">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>57</height>
- </size>
- </property>
- </spacer>
- </item>
- </layout>
- </widget>
- </item>
- <item row="1" column="1">
- <spacer name="verticalSpacer_2">
- <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>
</widget>
<customwidgets>
diff --git a/src/plugins/designer/cpp/formclasswizardparameters.cpp b/src/plugins/designer/cpp/formclasswizardparameters.cpp
index b9a88e4a2c..4f0881d948 100644
--- a/src/plugins/designer/cpp/formclasswizardparameters.cpp
+++ b/src/plugins/designer/cpp/formclasswizardparameters.cpp
@@ -34,32 +34,298 @@
#include <cpptools/cppmodelmanagerinterface.h>
#include <QtCore/QTextStream>
+#include <QtCore/QSettings>
#include <QtCore/QFileInfo>
#include <QtCore/QDebug>
+#include <QtCore/QSharedData>
static const char *uiMemberC = "m_ui";
static const char *uiNamespaceC = "Ui";
+static const char *formClassWizardPageGroupC = "FormClassWizardPage";
+static const char *translationKeyC = "RetranslationSupport";
+static const char *embeddingModeKeyC = "Embedding";
+
+// TODO: These 2 are general coding convention settings and
+// should go to CppTools...
+static const char *includeQtModuleKeyC = "IncludeQtModule";
+static const char *indentNamespaceKeyC = "IndentNamespace";
+
namespace Designer {
-namespace Internal {
+
+class FormClassWizardGenerationParametersPrivate : public QSharedData
+{
+public:
+ FormClassWizardGenerationParametersPrivate();
+ void fromSettings(const QSettings *);
+ void toSettings(QSettings *) const;
+ bool equals(const FormClassWizardGenerationParametersPrivate &rhs) const;
+
+ FormClassWizardGenerationParameters::UiClassEmbedding embedding;
+ bool retranslationSupport; // Add handling for language change events
+ bool includeQtModule; // Include "<QtGui/[Class]>" or just "<[Class]>"
+ bool indentNamespace;
+};
+
+FormClassWizardGenerationParametersPrivate::FormClassWizardGenerationParametersPrivate() :
+ embedding(FormClassWizardGenerationParameters::PointerAggregatedUiClass),
+ retranslationSupport(true),
+ includeQtModule(false),
+ indentNamespace(false)
+{
+}
+
+void FormClassWizardGenerationParametersPrivate::fromSettings(const QSettings *settings)
+{
+ QString key = QLatin1String(formClassWizardPageGroupC);
+ key += QLatin1Char('/');
+ const int groupLength = key.size();
+
+ key += QLatin1String(translationKeyC);
+ retranslationSupport = settings->value(key, true).toBool();
+
+ key.truncate(groupLength);
+ key += QLatin1String(embeddingModeKeyC);
+ embedding = static_cast<FormClassWizardGenerationParameters::UiClassEmbedding>(settings->value(key, int(FormClassWizardGenerationParameters::PointerAggregatedUiClass)).toInt());
+
+ key.truncate(groupLength);
+ key += QLatin1String(includeQtModuleKeyC);
+ includeQtModule = settings->value(key, false).toBool();
+
+ key.truncate(groupLength);
+ key += QLatin1String(indentNamespaceKeyC);
+ indentNamespace = settings->value(key, false).toBool();
+}
+
+void FormClassWizardGenerationParametersPrivate::toSettings(QSettings *settings) const
+{
+ settings->beginGroup(QLatin1String(formClassWizardPageGroupC));
+ settings->setValue(QLatin1String(translationKeyC), retranslationSupport);
+ settings->setValue(QLatin1String(embeddingModeKeyC), embedding);
+ settings->setValue(QLatin1String(includeQtModuleKeyC), includeQtModule);
+ settings->setValue(QLatin1String(indentNamespaceKeyC), indentNamespace);
+ settings->endGroup();
+}
+
+bool FormClassWizardGenerationParametersPrivate::equals(const FormClassWizardGenerationParametersPrivate &rhs) const
+{
+ return embedding == rhs.embedding && retranslationSupport == rhs.retranslationSupport
+ && includeQtModule == rhs.includeQtModule && indentNamespace == rhs.indentNamespace;
+}
+
+FormClassWizardGenerationParameters::FormClassWizardGenerationParameters() :
+ m_d(new FormClassWizardGenerationParametersPrivate)
+{
+}
+
+FormClassWizardGenerationParameters::~FormClassWizardGenerationParameters()
+{
+}
+
+FormClassWizardGenerationParameters::FormClassWizardGenerationParameters(const FormClassWizardGenerationParameters &rhs) :
+ m_d(rhs.m_d)
+{
+}
+
+FormClassWizardGenerationParameters &FormClassWizardGenerationParameters::operator=(const FormClassWizardGenerationParameters &rhs)
+{
+ if (this != &rhs)
+ m_d.operator=(rhs.m_d);
+ return *this;
+}
+
+bool FormClassWizardGenerationParameters::equals(const FormClassWizardGenerationParameters &rhs) const
+{
+ return m_d->equals(*rhs.m_d.constData());
+}
+
+FormClassWizardGenerationParameters::UiClassEmbedding FormClassWizardGenerationParameters::embedding() const
+{
+ return m_d->embedding;
+}
+
+void FormClassWizardGenerationParameters::setEmbedding(UiClassEmbedding e)
+{
+ m_d->embedding = e;
+}
+
+bool FormClassWizardGenerationParameters::retranslationSupport() const
+{
+ return m_d->retranslationSupport;
+}
+
+void FormClassWizardGenerationParameters::setRetranslationSupport(bool v)
+{
+ m_d->retranslationSupport = v;
+}
+
+bool FormClassWizardGenerationParameters::includeQtModule() const
+{
+ return m_d->includeQtModule;
+}
+
+void FormClassWizardGenerationParameters::setIncludeQtModule(bool v)
+{
+ m_d->includeQtModule = v;
+}
+
+bool FormClassWizardGenerationParameters::indentNamespace() const
+{
+ return m_d->indentNamespace;
+}
+
+void FormClassWizardGenerationParameters::setIndentNamespace(bool v)
+{
+ m_d->indentNamespace = v;
+}
+
+void FormClassWizardGenerationParameters::fromSettings(const QSettings *settings)
+{
+ m_d->fromSettings(settings);
+}
+
+void FormClassWizardGenerationParameters::toSettings(QSettings *settings) const
+{
+ m_d->toSettings(settings);
+}
+
+// -----------
+
+class FormClassWizardParametersPrivate : public QSharedData {
+public:
+ bool generateCpp(const FormClassWizardGenerationParameters &fgp,
+ QString *header, QString *source, int indentation) const;
+
+ QString uiTemplate;
+ QString className;
+
+ QString path;
+ QString sourceFile;
+ QString headerFile;
+ QString uiFile;
+};
FormClassWizardParameters::FormClassWizardParameters() :
- embedding(PointerAggregatedUiClass),
- languageChange(true)
+ m_d(new FormClassWizardParametersPrivate)
{
}
-bool FormClassWizardParameters::generateCpp(QString *header, QString *source, int indentation) const
+FormClassWizardParameters::~FormClassWizardParameters()
{
- const QString indent = QString(indentation, QLatin1Char(' '));
+}
+
+FormClassWizardParameters::FormClassWizardParameters(const FormClassWizardParameters &rhs) :
+ m_d(rhs.m_d)
+{
+}
+
+FormClassWizardParameters &FormClassWizardParameters::operator=(const FormClassWizardParameters &rhs)
+{
+ if (this != &rhs)
+ m_d.operator =(rhs.m_d);
+ return *this;
+}
+
+QString FormClassWizardParameters::uiTemplate() const
+{
+ return m_d->uiTemplate;
+}
+
+void FormClassWizardParameters::setUiTemplate(const QString &s)
+{
+ m_d->uiTemplate = s;
+}
+
+QString FormClassWizardParameters::className() const
+{
+ return m_d->className;
+}
+
+void FormClassWizardParameters::setClassName(const QString &s)
+{
+ m_d->className = s;
+}
+
+QString FormClassWizardParameters::path() const
+{
+ return m_d->path;
+}
+
+void FormClassWizardParameters::setPath(const QString &s)
+{
+ m_d->path = s;
+}
+
+
+QString FormClassWizardParameters::sourceFile() const
+{
+ return m_d->sourceFile;
+}
+
+void FormClassWizardParameters::setSourceFile(const QString &s)
+{
+ m_d->sourceFile = s;
+}
+
+QString FormClassWizardParameters::headerFile() const
+{
+ return m_d->headerFile;
+}
+
+void FormClassWizardParameters::setHeaderFile(const QString &s)
+{
+ m_d->headerFile = s;
+}
+
+
+QString FormClassWizardParameters::uiFile() const
+{
+ return m_d->uiFile;
+}
+
+void FormClassWizardParameters::setUiFile(const QString &s)
+{
+ m_d->uiFile = s;
+}
+
+bool FormClassWizardParameters::getUIXmlData(const QString &uiXml, QString *formBaseClass, QString *uiClassName)
+{
+ return Designer::Internal::FormTemplateWizardPage::getUIXmlData(uiXml, formBaseClass, uiClassName);
+}
+
+QString FormClassWizardParameters::changeUiClassName(const QString &uiXml, const QString &newUiClassName)
+{
+ return Designer::Internal::FormTemplateWizardPage::changeUiClassName(uiXml, newUiClassName);
+}
+
+// Write out how to access the Ui class in the source code.
+static inline void writeUiMemberAccess(const FormClassWizardGenerationParameters &fp, QTextStream &str)
+{
+ switch(fp.embedding()) {
+ case FormClassWizardGenerationParameters::PointerAggregatedUiClass:
+ str << uiMemberC << "->";
+ break;
+ case FormClassWizardGenerationParameters::AggregatedUiClass:
+ str << uiMemberC << '.';
+ break;
+ case FormClassWizardGenerationParameters::InheritedUiClass:
+ break;
+ }
+}
+
+bool FormClassWizardParametersPrivate::generateCpp(const FormClassWizardGenerationParameters &generationParameters,
+ QString *header, QString *source, int indentation) const
+{
+ const QString indent = QString(indentation, QLatin1Char(' '));
QString formBaseClass;
QString uiClassName;
- if (!FormTemplateWizardPage::getUIXmlData(uiTemplate, &formBaseClass, &uiClassName)) {
+ if (!FormClassWizardParameters::getUIXmlData(uiTemplate, &formBaseClass, &uiClassName)) {
qWarning("Unable to determine the form base class from %s.", uiTemplate.toUtf8().constData());
return false;
}
// Build the ui class (Ui::Foo) name relative to the namespace (which is the same):
+ const FormClassWizardGenerationParameters::UiClassEmbedding embedding = generationParameters.embedding();
const QString colonColon = QLatin1String("::");
const int lastSeparator = uiClassName.lastIndexOf(colonColon);
if (lastSeparator != -1)
@@ -87,88 +353,89 @@ bool FormClassWizardParameters::generateCpp(QString *header, QString *source, in
<< "\n#define " << guard << '\n' << '\n';
// Include 'ui_'
- if (embedding != PointerAggregatedUiClass) {
+ if (embedding != FormClassWizardGenerationParameters::PointerAggregatedUiClass) {
Core::Utils::writeIncludeFileDirective(uiInclude, false, headerStr);
} else {
// Todo: Can we obtain the header from the code model for custom widgets?
// Alternatively, from Designer.
if (formBaseClass.startsWith(QLatin1Char('Q'))) {
- QString baseInclude = QLatin1String("QtGui/");
- baseInclude += formBaseClass;
+ QString baseInclude = formBaseClass;
+ if (generationParameters.includeQtModule())
+ baseInclude.insert(0, QLatin1String("QtGui/"));
Core::Utils::writeIncludeFileDirective(baseInclude, true, headerStr);
}
}
- const QString namespaceIndent = Core::Utils::writeOpeningNameSpaces(namespaceList, indent, headerStr);
+ const QString namespaceIndent = Core::Utils::writeOpeningNameSpaces(namespaceList,
+ generationParameters.indentNamespace() ? indent : QString(),
+ headerStr);
// Forward-declare the UI class
- if (embedding == PointerAggregatedUiClass) {
+ if (embedding == FormClassWizardGenerationParameters::PointerAggregatedUiClass) {
headerStr << '\n'
<< namespaceIndent << "namespace " << uiNamespaceC << " {\n"
- << namespaceIndent << indent << "class " << FormTemplateWizardPage::stripNamespaces(uiClassName) << ";\n"
+ << namespaceIndent << indent << "class " << Internal::FormTemplateWizardPage::stripNamespaces(uiClassName) << ";\n"
<< namespaceIndent << "}\n";
}
// Class declaration
headerStr << '\n' << namespaceIndent << "class " << unqualifiedClassName
<< " : public " << formBaseClass;
- if (embedding == InheritedUiClass) {
+ if (embedding == FormClassWizardGenerationParameters::InheritedUiClass) {
headerStr << ", private " << uiClassName;
}
headerStr << " {\n" << namespaceIndent << indent << "Q_OBJECT\n"
<< namespaceIndent << "public:\n"
<< namespaceIndent << indent << unqualifiedClassName << "(QWidget *parent = 0);\n";
- if (embedding == PointerAggregatedUiClass)
+ if (embedding == FormClassWizardGenerationParameters::PointerAggregatedUiClass)
headerStr << namespaceIndent << indent << "~" << unqualifiedClassName << "();\n";
// retranslation
- if (languageChange)
+ if (generationParameters.retranslationSupport())
headerStr << '\n' << namespaceIndent << "protected:\n"
<< namespaceIndent << indent << "void changeEvent(QEvent *e);\n";
// Member variable
- if (embedding != InheritedUiClass) {
+ if (embedding != FormClassWizardGenerationParameters::InheritedUiClass) {
headerStr << '\n' << namespaceIndent << "private:\n"
<< namespaceIndent << indent << uiClassName << ' ';
- if (embedding == PointerAggregatedUiClass)
+ if (embedding == FormClassWizardGenerationParameters::PointerAggregatedUiClass)
headerStr << '*';
headerStr << uiMemberC << ";\n";
}
headerStr << namespaceIndent << "};\n\n";
- Core::Utils::writeClosingNameSpaces(namespaceList, indent, headerStr);
+ Core::Utils::writeClosingNameSpaces(namespaceList, generationParameters.indentNamespace() ? indent : QString(), headerStr);
headerStr << "#endif // "<< guard << '\n';
// 2) Source file
QTextStream sourceStr(source);
sourceStr << license;
Core::Utils::writeIncludeFileDirective(headerFile, false, sourceStr);
- if (embedding == PointerAggregatedUiClass)
+ if (embedding == FormClassWizardGenerationParameters::PointerAggregatedUiClass)
Core::Utils::writeIncludeFileDirective(uiInclude, false, sourceStr);
// NameSpaces(
- Core::Utils::writeOpeningNameSpaces(namespaceList, indent, sourceStr);
+ Core::Utils::writeOpeningNameSpaces(namespaceList, generationParameters.indentNamespace() ? indent : QString(), sourceStr);
// Constructor with setupUi
sourceStr << '\n' << namespaceIndent << unqualifiedClassName << "::" << unqualifiedClassName << "(QWidget *parent) :\n"
<< namespaceIndent << indent << formBaseClass << "(parent)";
- if (embedding == PointerAggregatedUiClass)
+ if (embedding == FormClassWizardGenerationParameters::PointerAggregatedUiClass)
sourceStr << ",\n" << namespaceIndent << indent << uiMemberC << "(new " << uiClassName << ")\n";
sourceStr << namespaceIndent << "{\n" << namespaceIndent << indent;
- if (embedding != InheritedUiClass)
- sourceStr << uiMemberC << (embedding == PointerAggregatedUiClass ? "->" : ".");
- sourceStr << "setupUi(this);\n" << namespaceIndent << "}\n";
+ writeUiMemberAccess(generationParameters, sourceStr);
+ sourceStr << "setupUi(this);\n" << namespaceIndent << "}\n";
// Deleting destructor for ptr
- if (embedding == PointerAggregatedUiClass) {
+ if (embedding == FormClassWizardGenerationParameters::PointerAggregatedUiClass) {
sourceStr << '\n' << namespaceIndent << unqualifiedClassName << "::~" << unqualifiedClassName
<< "()\n" << namespaceIndent << "{\n"
<< namespaceIndent << indent << "delete " << uiMemberC << ";\n"
<< namespaceIndent << "}\n";
}
// retranslation
- if (languageChange) {
+ if (generationParameters.retranslationSupport()) {
sourceStr << '\n' << namespaceIndent << "void " << unqualifiedClassName << "::" << "changeEvent(QEvent *e)\n"
<< namespaceIndent << "{\n"
<< namespaceIndent << indent << formBaseClass << "::changeEvent(e);\n"
<< namespaceIndent << indent << "switch (e->type()) {\n" << namespaceIndent << indent << "case QEvent::LanguageChange:\n"
<< namespaceIndent << indent << indent;
- if (embedding != InheritedUiClass)
- sourceStr << uiMemberC << (embedding == PointerAggregatedUiClass ? "->" : ".");
+ writeUiMemberAccess(generationParameters, sourceStr);
sourceStr << "retranslateUi(this);\n"
<< namespaceIndent << indent << indent << "break;\n"
<< namespaceIndent << indent << "default:\n"
@@ -176,9 +443,15 @@ bool FormClassWizardParameters::generateCpp(QString *header, QString *source, in
<< namespaceIndent << indent << "}\n"
<< namespaceIndent << "}\n";
}
- Core::Utils::writeClosingNameSpaces(namespaceList, indent, sourceStr);
+ Core::Utils::writeClosingNameSpaces(namespaceList, generationParameters.indentNamespace() ? indent : QString(), sourceStr);
return true;
}
-} // namespace Internal
+bool FormClassWizardParameters::generateCpp(const FormClassWizardGenerationParameters &fgp,
+ QString *header, QString *source, int indentation) const
+{
+ return m_d->generateCpp(fgp, header, source, indentation);
+}
+
+
} // namespace Designer
diff --git a/src/plugins/designer/cpp/formclasswizardparameters.h b/src/plugins/designer/cpp/formclasswizardparameters.h
index 15c9525327..6a5c65ac06 100644
--- a/src/plugins/designer/cpp/formclasswizardparameters.h
+++ b/src/plugins/designer/cpp/formclasswizardparameters.h
@@ -30,35 +30,99 @@
#ifndef FORMCLASSWIZARDPARAMETERS_H
#define FORMCLASSWIZARDPARAMETERS_H
+#include "../designer_export.h"
#include <QtCore/QString>
+#include <QtCore/QSharedDataPointer>
+
+QT_BEGIN_NAMESPACE
+class QSettings;
+QT_END_NAMESPACE
namespace Designer {
-namespace Internal {
+class FormClassWizardGenerationParametersPrivate;
+class FormClassWizardParametersPrivate;
+
+// Parameters influencing the code generation.
+class DESIGNER_EXPORT FormClassWizardGenerationParameters {
+public:
+ // How to embed the Ui::Form class.
+ enum UiClassEmbedding {
+ PointerAggregatedUiClass, // "Ui::Form *m_ui";
+ AggregatedUiClass, // "Ui::Form m_ui";
+ InheritedUiClass // "...private Ui::Form..."
+ };
+
+ FormClassWizardGenerationParameters();
+ ~FormClassWizardGenerationParameters();
+ FormClassWizardGenerationParameters(const FormClassWizardGenerationParameters&);
+ FormClassWizardGenerationParameters &operator=(const FormClassWizardGenerationParameters &);
+
+ void fromSettings(const QSettings *);
+ void toSettings(QSettings *) const;
+
+ UiClassEmbedding embedding() const;
+ void setEmbedding(UiClassEmbedding e);
+
+ bool retranslationSupport() const; // Add handling for language change events
+ void setRetranslationSupport(bool v);
+
+ bool includeQtModule() const; // Include "<QtGui/[Class]>" or just "<[Class]>"
+ void setIncludeQtModule(bool v);
+
+ bool indentNamespace() const;
+ void setIndentNamespace(bool v);
-enum UiClassEmbedding {
- PointerAggregatedUiClass,
- AggregatedUiClass,
- InheritedUiClass
+ bool equals(const FormClassWizardGenerationParameters &rhs) const;
+
+private:
+ QSharedDataPointer<FormClassWizardGenerationParametersPrivate> m_d;
};
-struct FormClassWizardParameters {
- explicit FormClassWizardParameters();
+inline bool operator==(const FormClassWizardGenerationParameters &p1, const FormClassWizardGenerationParameters &p2) { return p1.equals(p2); }
+inline bool operator!=(const FormClassWizardGenerationParameters &p1, const FormClassWizardGenerationParameters &p2) { return !p1.equals(p2); }
+
+// Parameters required to generate the code part of a form class with
+// helpers for XML-processing ui templates.
+class DESIGNER_EXPORT FormClassWizardParameters {
+public:
+ FormClassWizardParameters();
+ ~FormClassWizardParameters();
+ FormClassWizardParameters(const FormClassWizardParameters &);
+ FormClassWizardParameters &operator=(const FormClassWizardParameters &);
+
+ bool generateCpp(const FormClassWizardGenerationParameters &fgp,
+ QString *header, QString *source, int indentation = 4) const;
+
+ // Helper to parse UI XML forms to determine:
+ // 1) The ui class name from "<class>Designer::Internal::FormClassWizardPage</class>"
+ // 2) the base class from: widget class="QWizardPage"...
+ static bool getUIXmlData(const QString &uiXml, QString *formBaseClass, QString *uiClassName);
+ // Helper to change the class name in a UI XML form
+ static QString changeUiClassName(const QString &uiXml, const QString &newUiClassName);
+
+ QString uiTemplate() const;
+ void setUiTemplate(const QString &);
+
+ QString className() const;
+ void setClassName(const QString &);
+
+ QString path() const;
+ void setPath(const QString &);
+
+ QString sourceFile() const;
+ void setSourceFile(const QString &);
- bool generateCpp(QString *header, QString *source, int indentation = 4) const;
+ QString headerFile() const;
+ void setHeaderFile(const QString &);
- UiClassEmbedding embedding;
- bool languageChange; // Add handling for language change events
- QString uiTemplate;
- QString className;
+ QString uiFile() const;
+ void setUiFile(const QString &);
- QString path;
- QString sourceFile;
- QString headerFile;
- QString uiFile;
+private:
+ QSharedDataPointer<FormClassWizardParametersPrivate> m_d;
};
-} // namespace Internal
} // namespace Designer
#endif // FORMCLASSWIZARDPARAMETERS_H
diff --git a/src/plugins/designer/designerconstants.h b/src/plugins/designer/designerconstants.h
index a6c53e0a36..6896c67a4e 100644
--- a/src/plugins/designer/designerconstants.h
+++ b/src/plugins/designer/designerconstants.h
@@ -30,9 +30,14 @@
#ifndef DESIGNERPLUGIN_CONSTANTS_H
#define DESIGNERPLUGIN_CONSTANTS_H
+#include <QtCore/QtGlobal>
+
namespace Designer {
namespace Constants {
+const char * const SETTINGS_CATEGORY = QT_TRANSLATE_NOOP("Designer", "Designer");
+const char * const SETTINGS_CPP_SETTINGS = QT_TRANSLATE_NOOP("Designer", "Class Generation");
+
// context
const char * const C_FORMEDITOR = "FormEditor";
const char * const T_FORMEDITOR = "FormEditor.Toolbar";
diff --git a/src/plugins/designer/formeditorplugin.cpp b/src/plugins/designer/formeditorplugin.cpp
index 40a6276133..3508626fb8 100644
--- a/src/plugins/designer/formeditorplugin.cpp
+++ b/src/plugins/designer/formeditorplugin.cpp
@@ -35,6 +35,7 @@
#ifdef CPP_ENABLED
# include "formclasswizard.h"
# include <cppeditor/cppeditorconstants.h>
+# include "cppsettingspage.h"
#endif
#include "designerconstants.h"
@@ -60,24 +61,12 @@
using namespace Designer::Internal;
using namespace Designer::Constants;
-FormEditorPlugin::FormEditorPlugin() :
- m_factory(0),
- m_formWizard(0),
- m_formClassWizard(0)
+FormEditorPlugin::FormEditorPlugin()
{
}
FormEditorPlugin::~FormEditorPlugin()
{
- if (m_factory)
- removeObject(m_factory);
- if (m_formWizard)
- removeObject(m_formWizard);
- if (m_formClassWizard)
- removeObject(m_formClassWizard);
- delete m_factory;
- delete m_formWizard;
- delete m_formClassWizard;
FormEditorW::deleteInstance();
}
@@ -95,30 +84,28 @@ bool FormEditorPlugin::initialize(const QStringList &arguments, QString *error)
if (!core->mimeDatabase()->addMimeTypes(QLatin1String(":/formeditor/Designer.mimetypes.xml"), error))
return false;
- if (!initializeTemplates(error))
- return false;
+ initializeTemplates();
const int uid = core->uniqueIDManager()->uniqueIdentifier(QLatin1String(C_FORMEDITOR));
const QList<int> context = QList<int>() << uid;
- m_factory = new FormEditorFactory;
- addObject(m_factory);
+ addAutoReleasedObject(new FormEditorFactory);
if (qgetenv("KDE_SESSION_VERSION") == QByteArray("4")) {
// KDE 4, possibly dangerous...
// KDE 4.2.0 had a nasty bug, which resulted in the File/Open Dialog crashing
// so check for that an fully load the plugins
QProcess proc;
- proc.start("kde4-config", QStringList() << "--version");
+ proc.start(QLatin1String("kde4-config"), QStringList(QLatin1String("--version")));
proc.waitForFinished();
- QString output = proc.readAll();
+ const QByteArray output = proc.readAll();
if (output.contains("KDE: 4.2.0"))
FormEditorW::ensureInitStage(FormEditorW::FullyInitialized);
} else {
FormEditorW::ensureInitStage(FormEditorW::RegisterPlugins);
}
- QString locale = qApp->property("qtc_locale").toString();
+ const QString locale = qApp->property("qtc_locale").toString();
if (!locale.isEmpty()) {
QTranslator *qtr = new QTranslator(this);
const QString &creatorTrPath =
@@ -143,26 +130,23 @@ void FormEditorPlugin::extensionsInitialized()
//
////////////////////////////////////////////////////
-bool FormEditorPlugin::initializeTemplates(QString *error)
+void FormEditorPlugin::initializeTemplates()
{
- Q_UNUSED(error);
FormWizard::BaseFileWizardParameters wizardParameters(Core::IWizard::FileWizard);
wizardParameters.setCategory(QLatin1String("Qt"));
wizardParameters.setTrCategory(tr("Qt"));
const QString formFileType = QLatin1String(Constants::FORM_FILE_TYPE);
wizardParameters.setName(tr("Qt Designer Form"));
wizardParameters.setDescription(tr("Creates a Qt Designer form file (.ui)."));
- m_formWizard = new FormWizard(wizardParameters, this);
- addObject(m_formWizard);
+ addAutoReleasedObject(new FormWizard(wizardParameters, this));
#ifdef CPP_ENABLED
wizardParameters.setKind(Core::IWizard::ClassWizard);
wizardParameters.setName(tr("Qt Designer Form Class"));
wizardParameters.setDescription(tr("Creates a Qt Designer form file (.ui) with a matching class."));
- m_formClassWizard = new FormClassWizard(wizardParameters, this);
- addObject(m_formClassWizard);
+ addAutoReleasedObject(new FormClassWizard(wizardParameters, this));
+ addAutoReleasedObject(new CppSettingsPage);
#endif
- return true;
}
Q_EXPORT_PLUGIN(FormEditorPlugin)
diff --git a/src/plugins/designer/formeditorplugin.h b/src/plugins/designer/formeditorplugin.h
index 60fdbee7d4..d9d1fe5096 100644
--- a/src/plugins/designer/formeditorplugin.h
+++ b/src/plugins/designer/formeditorplugin.h
@@ -32,18 +32,9 @@
#include <extensionsystem/iplugin.h>
-namespace Core {
- class IWizard;
- class ICore;
-}
-
namespace Designer {
namespace Internal {
-class FormEditorFactory;
-class FormWizard;
-class FormEditorW;
-
class FormEditorPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
@@ -57,12 +48,7 @@ public:
void extensionsInitialized();
private:
- bool initializeTemplates(QString *error_message);
-
- FormEditorFactory *m_factory;
-
- Core::IWizard *m_formWizard;
- Core::IWizard *m_formClassWizard;
+ void initializeTemplates();
};
} // namespace Internal
diff --git a/src/plugins/designer/formtemplatewizardpage.h b/src/plugins/designer/formtemplatewizardpage.h
index 2c52abd0a6..7ab9c03612 100644
--- a/src/plugins/designer/formtemplatewizardpage.h
+++ b/src/plugins/designer/formtemplatewizardpage.h
@@ -54,7 +54,11 @@ public:
QString templateContents() const { return m_templateContents; }
+ // Parse UI XML forms to determine:
+ // 1) The ui class name from "<class>Designer::Internal::FormClassWizardPage</class>"
+ // 2) the base class from: widget class="QWizardPage"...
static bool getUIXmlData(const QString &uiXml, QString *formBaseClass, QString *uiClassName);
+ // Change the class name in a UI XML form
static QString changeUiClassName(const QString &uiXml, const QString &newUiClassName);
static QString stripNamespaces(const QString &className);
diff --git a/src/plugins/designer/settingspage.cpp b/src/plugins/designer/settingspage.cpp
index 2fdee80d8f..618c3e2078 100644
--- a/src/plugins/designer/settingspage.cpp
+++ b/src/plugins/designer/settingspage.cpp
@@ -28,9 +28,11 @@
**************************************************************************/
#include "settingspage.h"
+#include "designerconstants.h"
#include <extensionsystem/pluginmanager.h>
#include <qt_private/abstractoptionspage_p.h>
+#include <QtCore/QCoreApplication>
using namespace Designer::Internal;
@@ -55,12 +57,12 @@ QString SettingsPage::trName() const
QString SettingsPage::category() const
{
- return QLatin1String("Designer");
+ return QLatin1String(Designer::Constants::SETTINGS_CATEGORY);
}
QString SettingsPage::trCategory() const
{
- return tr("Designer");
+ return QCoreApplication::translate("Designer", Designer::Constants::SETTINGS_CATEGORY);
}
QWidget *SettingsPage::createPage(QWidget *parent)
diff --git a/src/plugins/qt4projectmanager/wizards/guiappwizard.cpp b/src/plugins/qt4projectmanager/wizards/guiappwizard.cpp
index 8dcaeca883..108fd4cb4c 100644
--- a/src/plugins/qt4projectmanager/wizards/guiappwizard.cpp
+++ b/src/plugins/qt4projectmanager/wizards/guiappwizard.cpp
@@ -37,9 +37,12 @@
#include <utils/pathchooser.h>
#include <projectexplorer/projectnodes.h>
#include <cpptools/cppmodelmanagerinterface.h>
+#include <designer/cpp/formclasswizardparameters.h>
+#include <coreplugin/icore.h>
#include <QtCore/QDir>
#include <QtCore/QFile>
+#include <QtCore/QSettings>
#include <QtCore/QByteArray>
#include <QtCore/QDebug>
#include <QtCore/QTextStream>
@@ -89,6 +92,33 @@ QWizard *GuiAppWizard::createWizardDialog(QWidget *parent,
return dialog;
}
+// Use the class generation utils provided by the designer plugin
+static inline bool generateFormClass(const GuiAppParameters &params,
+ const Core::GeneratedFile &uiFile,
+ Core::GeneratedFile *formSource,
+ Core::GeneratedFile *formHeader,
+ QString *errorMessage)
+{
+ // Retrieve parameters from settings
+ Designer::FormClassWizardGenerationParameters fgp;
+ fgp.fromSettings(Core::ICore::instance()->settings());
+ Designer::FormClassWizardParameters fp;
+ fp.setUiTemplate(uiFile.contents());
+ fp.setUiFile(uiFile.path());
+ fp.setClassName(params.className);
+ fp.setSourceFile(params.sourceFileName);
+ fp.setHeaderFile(params.headerFileName);
+ QString headerContents;
+ QString sourceContents;
+ if (!fp.generateCpp(fgp, &headerContents, &sourceContents, 4)) {
+ *errorMessage = QLatin1String("Internal error: Unable to generate the form classes.");
+ return false;
+ }
+ formHeader->setContents(headerContents);
+ formSource->setContents(sourceContents);
+ return true;
+}
+
Core::GeneratedFiles GuiAppWizard::generateFiles(const QWizard *w,
QString *errorMessage) const
{
@@ -108,28 +138,32 @@ Core::GeneratedFiles GuiAppWizard::generateFiles(const QWizard *w,
if (!parametrizeTemplate(templatePath, QLatin1String("main.cpp"), params, &contents, errorMessage))
return Core::GeneratedFiles();
mainSource.setContents(license + contents);
- // Create files: form source
- const QString formSourceTemplate = params.designerForm ? QLatin1String("mywidget_form.cpp") : QLatin1String("mywidget.cpp");
+ // Create files: form source with or without form
const QString formSourceFileName = buildFileName(projectPath, params.sourceFileName, sourceSuffix());
- Core::GeneratedFile formSource(formSourceFileName);
- if (!parametrizeTemplate(templatePath, formSourceTemplate, params, &contents, errorMessage))
- return Core::GeneratedFiles();
- formSource.setContents(license + contents);
- // Create files: form header
const QString formHeaderName = buildFileName(projectPath, params.headerFileName, headerSuffix());
- const QString formHeaderTemplate = params.designerForm ? QLatin1String("mywidget_form.h") : QLatin1String("mywidget.h");
+ Core::GeneratedFile formSource(formSourceFileName);
Core::GeneratedFile formHeader(formHeaderName);
- if (!parametrizeTemplate(templatePath, formHeaderTemplate, params, &contents, errorMessage))
- return Core::GeneratedFiles();
- formHeader.setContents(license + contents);
- // Create files: form
+
QSharedPointer<Core::GeneratedFile> form;
if (params.designerForm) {
+ // Create files: form
const QString formName = buildFileName(projectPath, params.formFileName, formSuffix());
form = QSharedPointer<Core::GeneratedFile>(new Core::GeneratedFile(formName));
if (!parametrizeTemplate(templatePath, QLatin1String("widget.ui"), params, &contents, errorMessage))
return Core::GeneratedFiles();
- form->setContents(contents);
+ form->setContents(contents);
+ if (!generateFormClass(params, *form, &formSource, &formHeader, errorMessage))
+ return Core::GeneratedFiles();
+ } else {
+ const QString formSourceTemplate = QLatin1String("mywidget.cpp");
+ if (!parametrizeTemplate(templatePath, formSourceTemplate, params, &contents, errorMessage))
+ return Core::GeneratedFiles();
+ formSource.setContents(license + contents);
+ // Create files: form header
+ const QString formHeaderTemplate = QLatin1String("mywidget.h");
+ if (!parametrizeTemplate(templatePath, formHeaderTemplate, params, &contents, errorMessage))
+ return Core::GeneratedFiles();
+ formHeader.setContents(license + contents);
}
// Create files: profile
const QString profileName = buildFileName(projectPath, projectParams.name, profileSuffix());