forked from qt-creator/qt-creator
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
This commit is contained in:
@@ -5,11 +5,14 @@ DEFINES+=CPP_ENABLED
|
|||||||
HEADERS+=$$PWD/formclasswizardpage.h \
|
HEADERS+=$$PWD/formclasswizardpage.h \
|
||||||
$$PWD/formclasswizarddialog.h \
|
$$PWD/formclasswizarddialog.h \
|
||||||
$$PWD/formclasswizard.h \
|
$$PWD/formclasswizard.h \
|
||||||
$$PWD/formclasswizardparameters.h
|
$$PWD/formclasswizardparameters.h \
|
||||||
|
$$PWD/cppsettingspage.h
|
||||||
|
|
||||||
SOURCES+=$$PWD/formclasswizardpage.cpp \
|
SOURCES+=$$PWD/formclasswizardpage.cpp \
|
||||||
$$PWD/formclasswizarddialog.cpp \
|
$$PWD/formclasswizarddialog.cpp \
|
||||||
$$PWD/formclasswizard.cpp \
|
$$PWD/formclasswizard.cpp \
|
||||||
$$PWD/formclasswizardparameters.cpp
|
$$PWD/formclasswizardparameters.cpp \
|
||||||
|
$$PWD/cppsettingspage.cpp
|
||||||
|
|
||||||
FORMS+=$$PWD/formclasswizardpage.ui
|
FORMS+=$$PWD/formclasswizardpage.ui \
|
||||||
|
$$PWD/cppsettingspagewidget.ui
|
||||||
|
|||||||
136
src/plugins/designer/cpp/cppsettingspage.cpp
Normal file
136
src/plugins/designer/cpp/cppsettingspage.cpp
Normal file
@@ -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
|
||||||
81
src/plugins/designer/cpp/cppsettingspage.h
Normal file
81
src/plugins/designer/cpp/cppsettingspage.h
Normal file
@@ -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
|
||||||
110
src/plugins/designer/cpp/cppsettingspagewidget.ui
Normal file
110
src/plugins/designer/cpp/cppsettingspagewidget.ui
Normal file
@@ -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>
|
||||||
@@ -87,17 +87,17 @@ QWizard *FormClassWizard::createWizardDialog(QWidget *parent,
|
|||||||
Core::GeneratedFiles FormClassWizard::generateFiles(const QWizard *w, QString *errorMessage) const
|
Core::GeneratedFiles FormClassWizard::generateFiles(const QWizard *w, QString *errorMessage) const
|
||||||
{
|
{
|
||||||
const FormClassWizardDialog *wizardDialog = qobject_cast<const FormClassWizardDialog *>(w);
|
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");
|
*errorMessage = QLatin1String("Internal error: FormClassWizard::generateFiles: empty template contents");
|
||||||
return Core::GeneratedFiles();
|
return Core::GeneratedFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
// header
|
// header
|
||||||
const QString formFileName = buildFileName(params.path, params.uiFile, formSuffix());
|
const QString formFileName = buildFileName(params.path(), params.uiFile(), formSuffix());
|
||||||
const QString headerFileName = buildFileName(params.path, params.headerFile, headerSuffix());
|
const QString headerFileName = buildFileName(params.path(), params.headerFile(), headerSuffix());
|
||||||
const QString sourceFileName = buildFileName(params.path, params.sourceFile, sourceSuffix());
|
const QString sourceFileName = buildFileName(params.path(), params.sourceFile(), sourceSuffix());
|
||||||
|
|
||||||
Core::GeneratedFile headerFile(headerFileName);
|
Core::GeneratedFile headerFile(headerFileName);
|
||||||
headerFile.setEditorKind(QLatin1String(CppEditor::Constants::CPPEDITOR_KIND));
|
headerFile.setEditorKind(QLatin1String(CppEditor::Constants::CPPEDITOR_KIND));
|
||||||
@@ -108,11 +108,13 @@ Core::GeneratedFiles FormClassWizard::generateFiles(const QWizard *w, QString *e
|
|||||||
|
|
||||||
// UI
|
// UI
|
||||||
Core::GeneratedFile uiFile(formFileName);
|
Core::GeneratedFile uiFile(formFileName);
|
||||||
uiFile.setContents(params.uiTemplate);
|
uiFile.setContents(params.uiTemplate());
|
||||||
uiFile.setEditorKind(QLatin1String(Constants::C_FORMEDITOR));
|
uiFile.setEditorKind(QLatin1String(Constants::C_FORMEDITOR));
|
||||||
|
|
||||||
QString source, header;
|
QString source, header;
|
||||||
params.generateCpp(&header, &source);
|
Designer::FormClassWizardGenerationParameters generationParameters;
|
||||||
|
generationParameters.fromSettings(Core::ICore::instance()->settings());
|
||||||
|
params.generateCpp(generationParameters, &header, &source);
|
||||||
sourceFile.setContents(source);
|
sourceFile.setContents(source);
|
||||||
headerFile.setContents(header);
|
headerFile.setContents(header);
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ FormClassWizardParameters FormClassWizardDialog::parameters() const
|
|||||||
FormClassWizardParameters rc;
|
FormClassWizardParameters rc;
|
||||||
m_classPage->getParameters(&rc);
|
m_classPage->getParameters(&rc);
|
||||||
// Name the ui class in the Ui namespace after the class specified
|
// 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;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,9 +37,12 @@ namespace Core {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace Designer {
|
namespace Designer {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
struct FormClassWizardParameters;
|
struct FormClassWizardParameters;
|
||||||
|
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
|
||||||
class FormClassWizardPage;
|
class FormClassWizardPage;
|
||||||
class FormTemplateWizardPage;
|
class FormTemplateWizardPage;
|
||||||
|
|
||||||
@@ -56,7 +59,7 @@ public:
|
|||||||
|
|
||||||
QString path() const;
|
QString path() const;
|
||||||
|
|
||||||
FormClassWizardParameters parameters() const;
|
Designer::FormClassWizardParameters parameters() const;
|
||||||
|
|
||||||
bool validateCurrentPage();
|
bool validateCurrentPage();
|
||||||
|
|
||||||
|
|||||||
@@ -43,10 +43,6 @@
|
|||||||
#include <QtGui/QAbstractButton>
|
#include <QtGui/QAbstractButton>
|
||||||
#include <QtGui/QMessageBox>
|
#include <QtGui/QMessageBox>
|
||||||
|
|
||||||
static const char *formClassWizardPageGroupC = "FormClassWizardPage";
|
|
||||||
static const char *translationKeyC = "RetranslationSupport";
|
|
||||||
static const char *embeddingModeKeyC = "Embedding";
|
|
||||||
|
|
||||||
namespace Designer {
|
namespace Designer {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -64,13 +60,7 @@ FormClassWizardPage::FormClassWizardPage(QWidget * parent) :
|
|||||||
m_ui->newClassWidget->setAllowDirectories(true);
|
m_ui->newClassWidget->setAllowDirectories(true);
|
||||||
|
|
||||||
connect(m_ui->newClassWidget, SIGNAL(validChanged()), this, SLOT(slotValidChanged()));
|
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()));
|
connect(m_ui->settingsToolButton, SIGNAL(clicked()), this, SLOT(slotSettings()));
|
||||||
|
|
||||||
restoreSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FormClassWizardPage::~FormClassWizardPage()
|
FormClassWizardPage::~FormClassWizardPage()
|
||||||
@@ -79,13 +69,13 @@ FormClassWizardPage::~FormClassWizardPage()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve settings of CppTools plugin.
|
// 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);
|
QString lowerCaseSettingsKey = QLatin1String(CppTools::Constants::CPPTOOLS_SETTINGSGROUP);
|
||||||
camelCaseSettingsKey += QLatin1Char('/');
|
lowerCaseSettingsKey += QLatin1Char('/');
|
||||||
camelCaseSettingsKey += QLatin1String(CppTools::Constants::LOWERCASE_CPPFILES_KEY);
|
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
|
// Set up new class widget from settings
|
||||||
@@ -115,40 +105,6 @@ void FormClassWizardPage::setClassName(const QString &suggestedClassName)
|
|||||||
slotValidChanged();
|
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
|
QString FormClassWizardPage::path() const
|
||||||
{
|
{
|
||||||
return m_ui->newClassWidget->path();
|
return m_ui->newClassWidget->path();
|
||||||
@@ -161,13 +117,11 @@ void FormClassWizardPage::setPath(const QString &p)
|
|||||||
|
|
||||||
void FormClassWizardPage::getParameters(FormClassWizardParameters *p) const
|
void FormClassWizardPage::getParameters(FormClassWizardParameters *p) const
|
||||||
{
|
{
|
||||||
p->embedding = static_cast<UiClassEmbedding>(uiClassEmbedding());
|
p->setClassName(m_ui->newClassWidget->className());
|
||||||
p->languageChange = m_ui->retranslateCheckBox->isChecked();
|
p->setPath(path());
|
||||||
p->className = m_ui->newClassWidget->className();
|
p->setSourceFile(m_ui->newClassWidget->sourceFileName());
|
||||||
p->path = path();
|
p->setHeaderFile(m_ui->newClassWidget->headerFileName());
|
||||||
p->sourceFile = m_ui->newClassWidget->sourceFileName();
|
p->setUiFile(m_ui->newClassWidget-> formFileName());
|
||||||
p->headerFile = m_ui->newClassWidget->headerFileName();
|
|
||||||
p->uiFile = m_ui->newClassWidget-> formFileName();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormClassWizardPage::slotValidChanged()
|
void FormClassWizardPage::slotValidChanged()
|
||||||
@@ -188,47 +142,11 @@ bool FormClassWizardPage::validatePage()
|
|||||||
{
|
{
|
||||||
QString errorMessage;
|
QString errorMessage;
|
||||||
const bool rc = m_ui->newClassWidget->isValid(&errorMessage);
|
const bool rc = m_ui->newClassWidget->isValid(&errorMessage);
|
||||||
if (rc) {
|
if (!rc) {
|
||||||
saveSettings();
|
|
||||||
} else {
|
|
||||||
QMessageBox::critical(this, tr("%1 - Error").arg(title()), errorMessage);
|
QMessageBox::critical(this, tr("%1 - Error").arg(title()), errorMessage);
|
||||||
}
|
}
|
||||||
return rc;
|
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 Internal
|
||||||
} // namespace Designer
|
} // namespace Designer
|
||||||
|
|||||||
@@ -33,13 +33,16 @@
|
|||||||
#include <QtGui/QWizardPage>
|
#include <QtGui/QWizardPage>
|
||||||
|
|
||||||
namespace Designer {
|
namespace Designer {
|
||||||
|
|
||||||
|
struct FormClassWizardParameters;
|
||||||
|
struct FormClassWizardGenerationParameters;
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class FormClassWizardPage;
|
class FormClassWizardPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FormClassWizardParameters;
|
|
||||||
|
|
||||||
class FormClassWizardPage : public QWizardPage
|
class FormClassWizardPage : public QWizardPage
|
||||||
{
|
{
|
||||||
@@ -52,18 +55,17 @@ public:
|
|||||||
virtual bool isComplete () const;
|
virtual bool isComplete () const;
|
||||||
virtual bool validatePage();
|
virtual bool validatePage();
|
||||||
|
|
||||||
int uiClassEmbedding() const;
|
|
||||||
bool hasRetranslationSupport() const;
|
|
||||||
QString path() const;
|
QString path() const;
|
||||||
|
|
||||||
// Fill out applicable parameters
|
// Fill out applicable parameters
|
||||||
void getParameters(FormClassWizardParameters *) const;
|
void getParameters(FormClassWizardParameters *) const;
|
||||||
|
|
||||||
|
FormClassWizardGenerationParameters generationParameters() const;
|
||||||
|
void setGenerationParameters(const FormClassWizardGenerationParameters &gp);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setClassName(const QString &suggestedClassName);
|
void setClassName(const QString &suggestedClassName);
|
||||||
void setPath(const QString &);
|
void setPath(const QString &);
|
||||||
void setRetranslationSupport(bool);
|
|
||||||
void setUiClassEmbedding(int v);
|
|
||||||
void slotSettings();
|
void slotSettings();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
@@ -71,8 +73,6 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void initParameters();
|
void initParameters();
|
||||||
void saveSettings();
|
|
||||||
void restoreSettings();
|
|
||||||
|
|
||||||
Ui::FormClassWizardPage *m_ui;
|
Ui::FormClassWizardPage *m_ui;
|
||||||
bool m_isValid;
|
bool m_isValid;
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>552</width>
|
<width>542</width>
|
||||||
<height>498</height>
|
<height>267</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="title">
|
<property name="title">
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="Core::Utils::NewClassWidget" name="newClassWidget" native="true"/>
|
<widget class="Core::Utils::NewClassWidget" name="newClassWidget"/>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
@@ -48,114 +48,8 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QToolButton" name="moreButton">
|
|
||||||
<property name="text">
|
|
||||||
<string>More</string>
|
|
||||||
</property>
|
|
||||||
<property name="checkable">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
|
|||||||
@@ -34,32 +34,298 @@
|
|||||||
#include <cpptools/cppmodelmanagerinterface.h>
|
#include <cpptools/cppmodelmanagerinterface.h>
|
||||||
|
|
||||||
#include <QtCore/QTextStream>
|
#include <QtCore/QTextStream>
|
||||||
|
#include <QtCore/QSettings>
|
||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
|
#include <QtCore/QSharedData>
|
||||||
|
|
||||||
static const char *uiMemberC = "m_ui";
|
static const char *uiMemberC = "m_ui";
|
||||||
static const char *uiNamespaceC = "Ui";
|
static const char *uiNamespaceC = "Ui";
|
||||||
|
|
||||||
namespace Designer {
|
static const char *formClassWizardPageGroupC = "FormClassWizardPage";
|
||||||
namespace Internal {
|
static const char *translationKeyC = "RetranslationSupport";
|
||||||
|
static const char *embeddingModeKeyC = "Embedding";
|
||||||
|
|
||||||
FormClassWizardParameters::FormClassWizardParameters() :
|
// TODO: These 2 are general coding convention settings and
|
||||||
embedding(PointerAggregatedUiClass),
|
// should go to CppTools...
|
||||||
languageChange(true)
|
static const char *includeQtModuleKeyC = "IncludeQtModule";
|
||||||
|
static const char *indentNamespaceKeyC = "IndentNamespace";
|
||||||
|
|
||||||
|
namespace Designer {
|
||||||
|
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FormClassWizardParameters::generateCpp(QString *header, QString *source, int indentation) const
|
void FormClassWizardGenerationParametersPrivate::fromSettings(const QSettings *settings)
|
||||||
{
|
{
|
||||||
const QString indent = QString(indentation, QLatin1Char(' '));
|
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() :
|
||||||
|
m_d(new FormClassWizardParametersPrivate)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
FormClassWizardParameters::~FormClassWizardParameters()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
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 formBaseClass;
|
||||||
QString uiClassName;
|
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());
|
qWarning("Unable to determine the form base class from %s.", uiTemplate.toUtf8().constData());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the ui class (Ui::Foo) name relative to the namespace (which is the same):
|
// 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 QString colonColon = QLatin1String("::");
|
||||||
const int lastSeparator = uiClassName.lastIndexOf(colonColon);
|
const int lastSeparator = uiClassName.lastIndexOf(colonColon);
|
||||||
if (lastSeparator != -1)
|
if (lastSeparator != -1)
|
||||||
@@ -87,88 +353,89 @@ bool FormClassWizardParameters::generateCpp(QString *header, QString *source, in
|
|||||||
<< "\n#define " << guard << '\n' << '\n';
|
<< "\n#define " << guard << '\n' << '\n';
|
||||||
|
|
||||||
// Include 'ui_'
|
// Include 'ui_'
|
||||||
if (embedding != PointerAggregatedUiClass) {
|
if (embedding != FormClassWizardGenerationParameters::PointerAggregatedUiClass) {
|
||||||
Core::Utils::writeIncludeFileDirective(uiInclude, false, headerStr);
|
Core::Utils::writeIncludeFileDirective(uiInclude, false, headerStr);
|
||||||
} else {
|
} else {
|
||||||
// Todo: Can we obtain the header from the code model for custom widgets?
|
// Todo: Can we obtain the header from the code model for custom widgets?
|
||||||
// Alternatively, from Designer.
|
// Alternatively, from Designer.
|
||||||
if (formBaseClass.startsWith(QLatin1Char('Q'))) {
|
if (formBaseClass.startsWith(QLatin1Char('Q'))) {
|
||||||
QString baseInclude = QLatin1String("QtGui/");
|
QString baseInclude = formBaseClass;
|
||||||
baseInclude += formBaseClass;
|
if (generationParameters.includeQtModule())
|
||||||
|
baseInclude.insert(0, QLatin1String("QtGui/"));
|
||||||
Core::Utils::writeIncludeFileDirective(baseInclude, true, headerStr);
|
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
|
// Forward-declare the UI class
|
||||||
if (embedding == PointerAggregatedUiClass) {
|
if (embedding == FormClassWizardGenerationParameters::PointerAggregatedUiClass) {
|
||||||
headerStr << '\n'
|
headerStr << '\n'
|
||||||
<< namespaceIndent << "namespace " << uiNamespaceC << " {\n"
|
<< namespaceIndent << "namespace " << uiNamespaceC << " {\n"
|
||||||
<< namespaceIndent << indent << "class " << FormTemplateWizardPage::stripNamespaces(uiClassName) << ";\n"
|
<< namespaceIndent << indent << "class " << Internal::FormTemplateWizardPage::stripNamespaces(uiClassName) << ";\n"
|
||||||
<< namespaceIndent << "}\n";
|
<< namespaceIndent << "}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Class declaration
|
// Class declaration
|
||||||
headerStr << '\n' << namespaceIndent << "class " << unqualifiedClassName
|
headerStr << '\n' << namespaceIndent << "class " << unqualifiedClassName
|
||||||
<< " : public " << formBaseClass;
|
<< " : public " << formBaseClass;
|
||||||
if (embedding == InheritedUiClass) {
|
if (embedding == FormClassWizardGenerationParameters::InheritedUiClass) {
|
||||||
headerStr << ", private " << uiClassName;
|
headerStr << ", private " << uiClassName;
|
||||||
}
|
}
|
||||||
headerStr << " {\n" << namespaceIndent << indent << "Q_OBJECT\n"
|
headerStr << " {\n" << namespaceIndent << indent << "Q_OBJECT\n"
|
||||||
<< namespaceIndent << "public:\n"
|
<< namespaceIndent << "public:\n"
|
||||||
<< namespaceIndent << indent << unqualifiedClassName << "(QWidget *parent = 0);\n";
|
<< namespaceIndent << indent << unqualifiedClassName << "(QWidget *parent = 0);\n";
|
||||||
if (embedding == PointerAggregatedUiClass)
|
if (embedding == FormClassWizardGenerationParameters::PointerAggregatedUiClass)
|
||||||
headerStr << namespaceIndent << indent << "~" << unqualifiedClassName << "();\n";
|
headerStr << namespaceIndent << indent << "~" << unqualifiedClassName << "();\n";
|
||||||
// retranslation
|
// retranslation
|
||||||
if (languageChange)
|
if (generationParameters.retranslationSupport())
|
||||||
headerStr << '\n' << namespaceIndent << "protected:\n"
|
headerStr << '\n' << namespaceIndent << "protected:\n"
|
||||||
<< namespaceIndent << indent << "void changeEvent(QEvent *e);\n";
|
<< namespaceIndent << indent << "void changeEvent(QEvent *e);\n";
|
||||||
// Member variable
|
// Member variable
|
||||||
if (embedding != InheritedUiClass) {
|
if (embedding != FormClassWizardGenerationParameters::InheritedUiClass) {
|
||||||
headerStr << '\n' << namespaceIndent << "private:\n"
|
headerStr << '\n' << namespaceIndent << "private:\n"
|
||||||
<< namespaceIndent << indent << uiClassName << ' ';
|
<< namespaceIndent << indent << uiClassName << ' ';
|
||||||
if (embedding == PointerAggregatedUiClass)
|
if (embedding == FormClassWizardGenerationParameters::PointerAggregatedUiClass)
|
||||||
headerStr << '*';
|
headerStr << '*';
|
||||||
headerStr << uiMemberC << ";\n";
|
headerStr << uiMemberC << ";\n";
|
||||||
}
|
}
|
||||||
headerStr << namespaceIndent << "};\n\n";
|
headerStr << namespaceIndent << "};\n\n";
|
||||||
Core::Utils::writeClosingNameSpaces(namespaceList, indent, headerStr);
|
Core::Utils::writeClosingNameSpaces(namespaceList, generationParameters.indentNamespace() ? indent : QString(), headerStr);
|
||||||
headerStr << "#endif // "<< guard << '\n';
|
headerStr << "#endif // "<< guard << '\n';
|
||||||
|
|
||||||
// 2) Source file
|
// 2) Source file
|
||||||
QTextStream sourceStr(source);
|
QTextStream sourceStr(source);
|
||||||
sourceStr << license;
|
sourceStr << license;
|
||||||
Core::Utils::writeIncludeFileDirective(headerFile, false, sourceStr);
|
Core::Utils::writeIncludeFileDirective(headerFile, false, sourceStr);
|
||||||
if (embedding == PointerAggregatedUiClass)
|
if (embedding == FormClassWizardGenerationParameters::PointerAggregatedUiClass)
|
||||||
Core::Utils::writeIncludeFileDirective(uiInclude, false, sourceStr);
|
Core::Utils::writeIncludeFileDirective(uiInclude, false, sourceStr);
|
||||||
// NameSpaces(
|
// NameSpaces(
|
||||||
Core::Utils::writeOpeningNameSpaces(namespaceList, indent, sourceStr);
|
Core::Utils::writeOpeningNameSpaces(namespaceList, generationParameters.indentNamespace() ? indent : QString(), sourceStr);
|
||||||
// Constructor with setupUi
|
// Constructor with setupUi
|
||||||
sourceStr << '\n' << namespaceIndent << unqualifiedClassName << "::" << unqualifiedClassName << "(QWidget *parent) :\n"
|
sourceStr << '\n' << namespaceIndent << unqualifiedClassName << "::" << unqualifiedClassName << "(QWidget *parent) :\n"
|
||||||
<< namespaceIndent << indent << formBaseClass << "(parent)";
|
<< namespaceIndent << indent << formBaseClass << "(parent)";
|
||||||
if (embedding == PointerAggregatedUiClass)
|
if (embedding == FormClassWizardGenerationParameters::PointerAggregatedUiClass)
|
||||||
sourceStr << ",\n" << namespaceIndent << indent << uiMemberC << "(new " << uiClassName << ")\n";
|
sourceStr << ",\n" << namespaceIndent << indent << uiMemberC << "(new " << uiClassName << ")\n";
|
||||||
sourceStr << namespaceIndent << "{\n" << namespaceIndent << indent;
|
sourceStr << namespaceIndent << "{\n" << namespaceIndent << indent;
|
||||||
if (embedding != InheritedUiClass)
|
writeUiMemberAccess(generationParameters, sourceStr);
|
||||||
sourceStr << uiMemberC << (embedding == PointerAggregatedUiClass ? "->" : ".");
|
sourceStr << "setupUi(this);\n" << namespaceIndent << "}\n";
|
||||||
sourceStr << "setupUi(this);\n" << namespaceIndent << "}\n";
|
|
||||||
// Deleting destructor for ptr
|
// Deleting destructor for ptr
|
||||||
if (embedding == PointerAggregatedUiClass) {
|
if (embedding == FormClassWizardGenerationParameters::PointerAggregatedUiClass) {
|
||||||
sourceStr << '\n' << namespaceIndent << unqualifiedClassName << "::~" << unqualifiedClassName
|
sourceStr << '\n' << namespaceIndent << unqualifiedClassName << "::~" << unqualifiedClassName
|
||||||
<< "()\n" << namespaceIndent << "{\n"
|
<< "()\n" << namespaceIndent << "{\n"
|
||||||
<< namespaceIndent << indent << "delete " << uiMemberC << ";\n"
|
<< namespaceIndent << indent << "delete " << uiMemberC << ";\n"
|
||||||
<< namespaceIndent << "}\n";
|
<< namespaceIndent << "}\n";
|
||||||
}
|
}
|
||||||
// retranslation
|
// retranslation
|
||||||
if (languageChange) {
|
if (generationParameters.retranslationSupport()) {
|
||||||
sourceStr << '\n' << namespaceIndent << "void " << unqualifiedClassName << "::" << "changeEvent(QEvent *e)\n"
|
sourceStr << '\n' << namespaceIndent << "void " << unqualifiedClassName << "::" << "changeEvent(QEvent *e)\n"
|
||||||
<< namespaceIndent << "{\n"
|
<< namespaceIndent << "{\n"
|
||||||
<< namespaceIndent << indent << formBaseClass << "::changeEvent(e);\n"
|
<< namespaceIndent << indent << formBaseClass << "::changeEvent(e);\n"
|
||||||
<< namespaceIndent << indent << "switch (e->type()) {\n" << namespaceIndent << indent << "case QEvent::LanguageChange:\n"
|
<< namespaceIndent << indent << "switch (e->type()) {\n" << namespaceIndent << indent << "case QEvent::LanguageChange:\n"
|
||||||
<< namespaceIndent << indent << indent;
|
<< namespaceIndent << indent << indent;
|
||||||
if (embedding != InheritedUiClass)
|
writeUiMemberAccess(generationParameters, sourceStr);
|
||||||
sourceStr << uiMemberC << (embedding == PointerAggregatedUiClass ? "->" : ".");
|
|
||||||
sourceStr << "retranslateUi(this);\n"
|
sourceStr << "retranslateUi(this);\n"
|
||||||
<< namespaceIndent << indent << indent << "break;\n"
|
<< namespaceIndent << indent << indent << "break;\n"
|
||||||
<< namespaceIndent << indent << "default:\n"
|
<< namespaceIndent << indent << "default:\n"
|
||||||
@@ -176,9 +443,15 @@ bool FormClassWizardParameters::generateCpp(QString *header, QString *source, in
|
|||||||
<< namespaceIndent << indent << "}\n"
|
<< namespaceIndent << indent << "}\n"
|
||||||
<< namespaceIndent << "}\n";
|
<< namespaceIndent << "}\n";
|
||||||
}
|
}
|
||||||
Core::Utils::writeClosingNameSpaces(namespaceList, indent, sourceStr);
|
Core::Utils::writeClosingNameSpaces(namespaceList, generationParameters.indentNamespace() ? indent : QString(), sourceStr);
|
||||||
return true;
|
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
|
} // namespace Designer
|
||||||
|
|||||||
@@ -30,35 +30,99 @@
|
|||||||
#ifndef FORMCLASSWIZARDPARAMETERS_H
|
#ifndef FORMCLASSWIZARDPARAMETERS_H
|
||||||
#define FORMCLASSWIZARDPARAMETERS_H
|
#define FORMCLASSWIZARDPARAMETERS_H
|
||||||
|
|
||||||
|
#include "../designer_export.h"
|
||||||
#include <QtCore/QString>
|
#include <QtCore/QString>
|
||||||
|
#include <QtCore/QSharedDataPointer>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QSettings;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Designer {
|
namespace Designer {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
|
class FormClassWizardGenerationParametersPrivate;
|
||||||
|
class FormClassWizardParametersPrivate;
|
||||||
|
|
||||||
enum UiClassEmbedding {
|
// Parameters influencing the code generation.
|
||||||
PointerAggregatedUiClass,
|
class DESIGNER_EXPORT FormClassWizardGenerationParameters {
|
||||||
AggregatedUiClass,
|
public:
|
||||||
InheritedUiClass
|
// 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);
|
||||||
|
|
||||||
|
bool equals(const FormClassWizardGenerationParameters &rhs) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QSharedDataPointer<FormClassWizardGenerationParametersPrivate> m_d;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FormClassWizardParameters {
|
inline bool operator==(const FormClassWizardGenerationParameters &p1, const FormClassWizardGenerationParameters &p2) { return p1.equals(p2); }
|
||||||
explicit FormClassWizardParameters();
|
inline bool operator!=(const FormClassWizardGenerationParameters &p1, const FormClassWizardGenerationParameters &p2) { return !p1.equals(p2); }
|
||||||
|
|
||||||
bool generateCpp(QString *header, QString *source, int indentation = 4) const;
|
// 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 &);
|
||||||
|
|
||||||
UiClassEmbedding embedding;
|
bool generateCpp(const FormClassWizardGenerationParameters &fgp,
|
||||||
bool languageChange; // Add handling for language change events
|
QString *header, QString *source, int indentation = 4) const;
|
||||||
QString uiTemplate;
|
|
||||||
QString className;
|
|
||||||
|
|
||||||
QString path;
|
// Helper to parse UI XML forms to determine:
|
||||||
QString sourceFile;
|
// 1) The ui class name from "<class>Designer::Internal::FormClassWizardPage</class>"
|
||||||
QString headerFile;
|
// 2) the base class from: widget class="QWizardPage"...
|
||||||
QString uiFile;
|
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 &);
|
||||||
|
|
||||||
|
QString headerFile() const;
|
||||||
|
void setHeaderFile(const QString &);
|
||||||
|
|
||||||
|
QString uiFile() const;
|
||||||
|
void setUiFile(const QString &);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QSharedDataPointer<FormClassWizardParametersPrivate> m_d;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace Designer
|
} // namespace Designer
|
||||||
|
|
||||||
#endif // FORMCLASSWIZARDPARAMETERS_H
|
#endif // FORMCLASSWIZARDPARAMETERS_H
|
||||||
|
|||||||
@@ -30,9 +30,14 @@
|
|||||||
#ifndef DESIGNERPLUGIN_CONSTANTS_H
|
#ifndef DESIGNERPLUGIN_CONSTANTS_H
|
||||||
#define DESIGNERPLUGIN_CONSTANTS_H
|
#define DESIGNERPLUGIN_CONSTANTS_H
|
||||||
|
|
||||||
|
#include <QtCore/QtGlobal>
|
||||||
|
|
||||||
namespace Designer {
|
namespace Designer {
|
||||||
namespace Constants {
|
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
|
// context
|
||||||
const char * const C_FORMEDITOR = "FormEditor";
|
const char * const C_FORMEDITOR = "FormEditor";
|
||||||
const char * const T_FORMEDITOR = "FormEditor.Toolbar";
|
const char * const T_FORMEDITOR = "FormEditor.Toolbar";
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
#ifdef CPP_ENABLED
|
#ifdef CPP_ENABLED
|
||||||
# include "formclasswizard.h"
|
# include "formclasswizard.h"
|
||||||
# include <cppeditor/cppeditorconstants.h>
|
# include <cppeditor/cppeditorconstants.h>
|
||||||
|
# include "cppsettingspage.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "designerconstants.h"
|
#include "designerconstants.h"
|
||||||
@@ -60,24 +61,12 @@
|
|||||||
using namespace Designer::Internal;
|
using namespace Designer::Internal;
|
||||||
using namespace Designer::Constants;
|
using namespace Designer::Constants;
|
||||||
|
|
||||||
FormEditorPlugin::FormEditorPlugin() :
|
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();
|
FormEditorW::deleteInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,30 +84,28 @@ bool FormEditorPlugin::initialize(const QStringList &arguments, QString *error)
|
|||||||
if (!core->mimeDatabase()->addMimeTypes(QLatin1String(":/formeditor/Designer.mimetypes.xml"), error))
|
if (!core->mimeDatabase()->addMimeTypes(QLatin1String(":/formeditor/Designer.mimetypes.xml"), error))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!initializeTemplates(error))
|
initializeTemplates();
|
||||||
return false;
|
|
||||||
|
|
||||||
const int uid = core->uniqueIDManager()->uniqueIdentifier(QLatin1String(C_FORMEDITOR));
|
const int uid = core->uniqueIDManager()->uniqueIdentifier(QLatin1String(C_FORMEDITOR));
|
||||||
const QList<int> context = QList<int>() << uid;
|
const QList<int> context = QList<int>() << uid;
|
||||||
|
|
||||||
m_factory = new FormEditorFactory;
|
addAutoReleasedObject(new FormEditorFactory);
|
||||||
addObject(m_factory);
|
|
||||||
|
|
||||||
if (qgetenv("KDE_SESSION_VERSION") == QByteArray("4")) {
|
if (qgetenv("KDE_SESSION_VERSION") == QByteArray("4")) {
|
||||||
// KDE 4, possibly dangerous...
|
// KDE 4, possibly dangerous...
|
||||||
// KDE 4.2.0 had a nasty bug, which resulted in the File/Open Dialog crashing
|
// 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
|
// so check for that an fully load the plugins
|
||||||
QProcess proc;
|
QProcess proc;
|
||||||
proc.start("kde4-config", QStringList() << "--version");
|
proc.start(QLatin1String("kde4-config"), QStringList(QLatin1String("--version")));
|
||||||
proc.waitForFinished();
|
proc.waitForFinished();
|
||||||
QString output = proc.readAll();
|
const QByteArray output = proc.readAll();
|
||||||
if (output.contains("KDE: 4.2.0"))
|
if (output.contains("KDE: 4.2.0"))
|
||||||
FormEditorW::ensureInitStage(FormEditorW::FullyInitialized);
|
FormEditorW::ensureInitStage(FormEditorW::FullyInitialized);
|
||||||
} else {
|
} else {
|
||||||
FormEditorW::ensureInitStage(FormEditorW::RegisterPlugins);
|
FormEditorW::ensureInitStage(FormEditorW::RegisterPlugins);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString locale = qApp->property("qtc_locale").toString();
|
const QString locale = qApp->property("qtc_locale").toString();
|
||||||
if (!locale.isEmpty()) {
|
if (!locale.isEmpty()) {
|
||||||
QTranslator *qtr = new QTranslator(this);
|
QTranslator *qtr = new QTranslator(this);
|
||||||
const QString &creatorTrPath =
|
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);
|
FormWizard::BaseFileWizardParameters wizardParameters(Core::IWizard::FileWizard);
|
||||||
wizardParameters.setCategory(QLatin1String("Qt"));
|
wizardParameters.setCategory(QLatin1String("Qt"));
|
||||||
wizardParameters.setTrCategory(tr("Qt"));
|
wizardParameters.setTrCategory(tr("Qt"));
|
||||||
const QString formFileType = QLatin1String(Constants::FORM_FILE_TYPE);
|
const QString formFileType = QLatin1String(Constants::FORM_FILE_TYPE);
|
||||||
wizardParameters.setName(tr("Qt Designer Form"));
|
wizardParameters.setName(tr("Qt Designer Form"));
|
||||||
wizardParameters.setDescription(tr("Creates a Qt Designer form file (.ui)."));
|
wizardParameters.setDescription(tr("Creates a Qt Designer form file (.ui)."));
|
||||||
m_formWizard = new FormWizard(wizardParameters, this);
|
addAutoReleasedObject(new FormWizard(wizardParameters, this));
|
||||||
addObject(m_formWizard);
|
|
||||||
|
|
||||||
#ifdef CPP_ENABLED
|
#ifdef CPP_ENABLED
|
||||||
wizardParameters.setKind(Core::IWizard::ClassWizard);
|
wizardParameters.setKind(Core::IWizard::ClassWizard);
|
||||||
wizardParameters.setName(tr("Qt Designer Form Class"));
|
wizardParameters.setName(tr("Qt Designer Form Class"));
|
||||||
wizardParameters.setDescription(tr("Creates a Qt Designer form file (.ui) with a matching class."));
|
wizardParameters.setDescription(tr("Creates a Qt Designer form file (.ui) with a matching class."));
|
||||||
m_formClassWizard = new FormClassWizard(wizardParameters, this);
|
addAutoReleasedObject(new FormClassWizard(wizardParameters, this));
|
||||||
addObject(m_formClassWizard);
|
addAutoReleasedObject(new CppSettingsPage);
|
||||||
#endif
|
#endif
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_EXPORT_PLUGIN(FormEditorPlugin)
|
Q_EXPORT_PLUGIN(FormEditorPlugin)
|
||||||
|
|||||||
@@ -32,18 +32,9 @@
|
|||||||
|
|
||||||
#include <extensionsystem/iplugin.h>
|
#include <extensionsystem/iplugin.h>
|
||||||
|
|
||||||
namespace Core {
|
|
||||||
class IWizard;
|
|
||||||
class ICore;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Designer {
|
namespace Designer {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class FormEditorFactory;
|
|
||||||
class FormWizard;
|
|
||||||
class FormEditorW;
|
|
||||||
|
|
||||||
class FormEditorPlugin : public ExtensionSystem::IPlugin
|
class FormEditorPlugin : public ExtensionSystem::IPlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -57,12 +48,7 @@ public:
|
|||||||
void extensionsInitialized();
|
void extensionsInitialized();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool initializeTemplates(QString *error_message);
|
void initializeTemplates();
|
||||||
|
|
||||||
FormEditorFactory *m_factory;
|
|
||||||
|
|
||||||
Core::IWizard *m_formWizard;
|
|
||||||
Core::IWizard *m_formClassWizard;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -54,7 +54,11 @@ public:
|
|||||||
|
|
||||||
QString templateContents() const { return m_templateContents; }
|
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);
|
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 changeUiClassName(const QString &uiXml, const QString &newUiClassName);
|
||||||
static QString stripNamespaces(const QString &className);
|
static QString stripNamespaces(const QString &className);
|
||||||
|
|
||||||
|
|||||||
@@ -28,9 +28,11 @@
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#include "settingspage.h"
|
#include "settingspage.h"
|
||||||
|
#include "designerconstants.h"
|
||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
#include <qt_private/abstractoptionspage_p.h>
|
#include <qt_private/abstractoptionspage_p.h>
|
||||||
|
#include <QtCore/QCoreApplication>
|
||||||
|
|
||||||
using namespace Designer::Internal;
|
using namespace Designer::Internal;
|
||||||
|
|
||||||
@@ -55,12 +57,12 @@ QString SettingsPage::trName() const
|
|||||||
|
|
||||||
QString SettingsPage::category() const
|
QString SettingsPage::category() const
|
||||||
{
|
{
|
||||||
return QLatin1String("Designer");
|
return QLatin1String(Designer::Constants::SETTINGS_CATEGORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SettingsPage::trCategory() const
|
QString SettingsPage::trCategory() const
|
||||||
{
|
{
|
||||||
return tr("Designer");
|
return QCoreApplication::translate("Designer", Designer::Constants::SETTINGS_CATEGORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *SettingsPage::createPage(QWidget *parent)
|
QWidget *SettingsPage::createPage(QWidget *parent)
|
||||||
|
|||||||
@@ -37,9 +37,12 @@
|
|||||||
#include <utils/pathchooser.h>
|
#include <utils/pathchooser.h>
|
||||||
#include <projectexplorer/projectnodes.h>
|
#include <projectexplorer/projectnodes.h>
|
||||||
#include <cpptools/cppmodelmanagerinterface.h>
|
#include <cpptools/cppmodelmanagerinterface.h>
|
||||||
|
#include <designer/cpp/formclasswizardparameters.h>
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
#include <QtCore/QDir>
|
#include <QtCore/QDir>
|
||||||
#include <QtCore/QFile>
|
#include <QtCore/QFile>
|
||||||
|
#include <QtCore/QSettings>
|
||||||
#include <QtCore/QByteArray>
|
#include <QtCore/QByteArray>
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
#include <QtCore/QTextStream>
|
#include <QtCore/QTextStream>
|
||||||
@@ -89,6 +92,33 @@ QWizard *GuiAppWizard::createWizardDialog(QWidget *parent,
|
|||||||
return dialog;
|
return dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use the class generation utils provided by the designer plugin
|
||||||
|
static inline bool generateFormClass(const GuiAppParameters ¶ms,
|
||||||
|
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,
|
Core::GeneratedFiles GuiAppWizard::generateFiles(const QWizard *w,
|
||||||
QString *errorMessage) const
|
QString *errorMessage) const
|
||||||
{
|
{
|
||||||
@@ -108,28 +138,32 @@ Core::GeneratedFiles GuiAppWizard::generateFiles(const QWizard *w,
|
|||||||
if (!parametrizeTemplate(templatePath, QLatin1String("main.cpp"), params, &contents, errorMessage))
|
if (!parametrizeTemplate(templatePath, QLatin1String("main.cpp"), params, &contents, errorMessage))
|
||||||
return Core::GeneratedFiles();
|
return Core::GeneratedFiles();
|
||||||
mainSource.setContents(license + contents);
|
mainSource.setContents(license + contents);
|
||||||
// Create files: form source
|
// Create files: form source with or without form
|
||||||
const QString formSourceTemplate = params.designerForm ? QLatin1String("mywidget_form.cpp") : QLatin1String("mywidget.cpp");
|
|
||||||
const QString formSourceFileName = buildFileName(projectPath, params.sourceFileName, sourceSuffix());
|
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 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);
|
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;
|
QSharedPointer<Core::GeneratedFile> form;
|
||||||
if (params.designerForm) {
|
if (params.designerForm) {
|
||||||
|
// Create files: form
|
||||||
const QString formName = buildFileName(projectPath, params.formFileName, formSuffix());
|
const QString formName = buildFileName(projectPath, params.formFileName, formSuffix());
|
||||||
form = QSharedPointer<Core::GeneratedFile>(new Core::GeneratedFile(formName));
|
form = QSharedPointer<Core::GeneratedFile>(new Core::GeneratedFile(formName));
|
||||||
if (!parametrizeTemplate(templatePath, QLatin1String("widget.ui"), params, &contents, errorMessage))
|
if (!parametrizeTemplate(templatePath, QLatin1String("widget.ui"), params, &contents, errorMessage))
|
||||||
return Core::GeneratedFiles();
|
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
|
// Create files: profile
|
||||||
const QString profileName = buildFileName(projectPath, projectParams.name, profileSuffix());
|
const QString profileName = buildFileName(projectPath, projectParams.name, profileSuffix());
|
||||||
|
|||||||
Reference in New Issue
Block a user