Initial import

This commit is contained in:
con
2008-12-02 12:01:29 +01:00
commit 05c35356ab
1675 changed files with 229938 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
INCLUDEPATH+=$$PWD
DEFINES+=CPP_ENABLED
HEADERS+=$$PWD/formclasswizardpage.h \
$$PWD/formclasswizarddialog.h \
$$PWD/formclasswizard.h \
$$PWD/formclasswizardparameters.h
SOURCES+=$$PWD/formclasswizardpage.cpp \
$$PWD/formclasswizarddialog.cpp \
$$PWD/formclasswizard.cpp \
$$PWD/formclasswizardparameters.cpp
FORMS+=$$PWD/formclasswizardpage.ui

View File

@@ -0,0 +1,117 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "formclasswizard.h"
#include "formclasswizarddialog.h"
#include "designerconstants.h"
#include "formwindoweditor.h"
#include <coreplugin/icore.h>
#include <cppeditor/cppeditorconstants.h>
#include <QtCore/QFile>
#include <QtCore/QDir>
#include <QtCore/QDebug>
enum { debugFormClassWizard = 0 };
using namespace Designer;
using namespace Designer::Internal;
FormClassWizard::FormClassWizard(const BaseFileWizardParameters &parameters, Core::ICore *core, QObject *parent) :
Core::BaseFileWizard(parameters, core, parent)
{
}
QString FormClassWizard::headerSuffix() const
{
return preferredSuffix(QLatin1String(CppEditor::Constants::CPP_HEADER_MIMETYPE));
}
QString FormClassWizard::sourceSuffix() const
{
return preferredSuffix(QLatin1String(CppEditor::Constants::CPP_SOURCE_MIMETYPE));
}
QString FormClassWizard::formSuffix() const
{
return preferredSuffix(QLatin1String(Constants::FORM_MIMETYPE));
}
QWizard *FormClassWizard::createWizardDialog(QWidget *parent,
const QString &defaultPath,
const WizardPageList &extensionPages) const
{
FormClassWizardDialog *wizardDialog = new FormClassWizardDialog(extensionPages,
parent);
wizardDialog->setSuffixes(headerSuffix(), sourceSuffix(), formSuffix());
wizardDialog->setPath(defaultPath);
return wizardDialog;
}
Core::GeneratedFiles FormClassWizard::generateFiles(const QWizard *w, QString *errorMessage) const
{
const FormClassWizardDialog *wizardDialog = qobject_cast<const FormClassWizardDialog *>(w);
const FormClassWizardParameters params = wizardDialog->parameters();
if (params.uiTemplate.isEmpty()) {
*errorMessage = tr("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());
Core::GeneratedFile headerFile(headerFileName);
headerFile.setEditorKind(QLatin1String(CppEditor::Constants::CPPEDITOR_KIND));
// Source
Core::GeneratedFile sourceFile(sourceFileName);
sourceFile.setEditorKind(QLatin1String(CppEditor::Constants::CPPEDITOR_KIND));
// UI
Core::GeneratedFile uiFile(formFileName);
uiFile.setContents(params.uiTemplate);
uiFile.setEditorKind(QLatin1String(Constants::C_FORMEDITOR));
QString source, header;
params.generateCpp(&header, &source);
sourceFile.setContents(source);
headerFile.setContents(header);
if (debugFormClassWizard)
qDebug() << Q_FUNC_INFO << '\n' << header << '\n' << source;
return Core::GeneratedFiles() << headerFile << sourceFile << uiFile;
}

View File

@@ -0,0 +1,77 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef FORMCLASSWIZARD_H
#define FORMCLASSWIZARD_H
#include "formclasswizardparameters.h"
#include <coreplugin/basefilewizard.h>
QT_BEGIN_NAMESPACE
class QWizard;
QT_END_NAMESPACE
namespace Designer {
namespace Internal {
struct FormClassWizardParameters;
class FormClassWizard : public Core::BaseFileWizard
{
Q_DISABLE_COPY(FormClassWizard)
Q_OBJECT
public:
typedef Core::BaseFileWizardParameters BaseFileWizardParameters;
FormClassWizard(const BaseFileWizardParameters &parameters, Core::ICore *core, QObject *parent);
QString headerSuffix() const;
QString sourceSuffix() const;
QString formSuffix() const;
protected:
virtual QWizard *createWizardDialog(QWidget *parent,
const QString &defaultPath,
const WizardPageList &extensionPages) const;
virtual Core::GeneratedFiles generateFiles(const QWizard *w,
QString *errorMessage) const;
private:
};
} // namespace Internal
} // namespace Designer
#endif // FORMCLASSWIZARD_H

View File

@@ -0,0 +1,114 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "formclasswizarddialog.h"
#include "formtemplatewizardpage.h"
#include "formclasswizardpage.h"
#include "formclasswizardparameters.h"
#include <coreplugin/icore.h>
#include <QtCore/QDebug>
#include <QtGui/QAbstractButton>
enum { FormPageId, ClassPageId };
namespace Designer {
namespace Internal {
// ----------------- FormClassWizardDialog
FormClassWizardDialog::FormClassWizardDialog(const WizardPageList &extensionPages,
QWidget *parent) :
QWizard(parent),
m_formPage(new FormTemplateWizardPagePage),
m_classPage(new FormClassWizardPage)
{
setWindowTitle(tr("Qt Designer Form Class"));
setPage(FormPageId, m_formPage);
connect(m_formPage, SIGNAL(templateActivated()),
button(QWizard::NextButton), SLOT(animateClick()));
setPage(ClassPageId, m_classPage);
foreach (QWizardPage *p, extensionPages)
addPage(p);
connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(slotCurrentIdChanged(int)));
}
void FormClassWizardDialog::setSuffixes(const QString &header, const QString &source, const QString &form)
{
m_classPage->setSuffixes(header, source, form);
}
QString FormClassWizardDialog::path() const
{
return m_classPage->path();
}
void FormClassWizardDialog::setPath(const QString &p)
{
m_classPage->setPath(p);
}
bool FormClassWizardDialog::validateCurrentPage()
{
return QWizard::validateCurrentPage();
}
void FormClassWizardDialog::slotCurrentIdChanged(int id)
{
// Switching from form to class page: store XML template and set a suitable
// class name in the class page based on the form base class
if (id == ClassPageId) {
QString formBaseClass;
QString uiClassName;
m_rawFormTemplate = m_formPage->templateContents();
// Strip namespaces from the ui class and suggest it as a new class
// name
if (FormTemplateWizardPagePage::getUIXmlData(m_rawFormTemplate, &formBaseClass, &uiClassName))
m_classPage->setClassName(FormTemplateWizardPagePage::stripNamespaces(uiClassName));
}
}
FormClassWizardParameters FormClassWizardDialog::parameters() const
{
FormClassWizardParameters rc;
m_classPage->getParameters(&rc);
// Name the ui class in the Ui namespace after the class specified
rc.uiTemplate = FormTemplateWizardPagePage::changeUiClassName(m_rawFormTemplate, rc.className);
return rc;
}
} // namespace Internal
} // namespace Designer

View File

@@ -0,0 +1,83 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef FORMCLASSWIZARDDIALOG_H
#define FORMCLASSWIZARDDIALOG_H
#include <QtGui/QWizard>
namespace Core {
class ICore;
}
namespace Designer {
namespace Internal {
struct FormClassWizardParameters;
class FormClassWizardPage;
class FormTemplateWizardPagePage;
class FormClassWizardDialog : public QWizard
{
Q_DISABLE_COPY(FormClassWizardDialog)
Q_OBJECT
public:
typedef QList<QWizardPage *> WizardPageList;
explicit FormClassWizardDialog(const WizardPageList &extensionPages,
QWidget *parent = 0);
void setSuffixes(const QString &header, const QString &source, const QString &form);
QString path() const;
FormClassWizardParameters parameters() const;
bool validateCurrentPage();
public slots:
void setPath(const QString &);
private slots:
void slotCurrentIdChanged(int id);
private:
FormTemplateWizardPagePage *m_formPage;
FormClassWizardPage *m_classPage;
QString m_rawFormTemplate;
};
} // namespace Internal
} // namespace Designer
#endif // FORMCLASSWIZARDDIALOG_H

View File

@@ -0,0 +1,209 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "formclasswizardpage.h"
#include "ui_formclasswizardpage.h"
#include "formclasswizardparameters.h"
#include <coreplugin/icore.h>
#include <cppeditor/cppeditorconstants.h>
#include <QtCore/QDebug>
#include <QtCore/QDir>
#include <QtCore/QSettings>
#include <QtGui/QMessageBox>
#include <QtGui/QAbstractButton>
static const char *formClassWizardPageGroupC = "FormClassWizardPage";
static const char *translationKeyC = "RetranslationSupport";
static const char *embeddingModeKeyC = "Embedding";
namespace Designer {
namespace Internal {
// ----------------- FormClassWizardPage
FormClassWizardPage::FormClassWizardPage(QWidget * parent) :
QWizardPage(parent),
m_ui(new Ui::FormClassWizardPage),
m_isValid(false)
{
m_ui->setupUi(this);
m_ui->newClassWidget->setBaseClassInputVisible(false);
m_ui->newClassWidget->setNamespacesEnabled(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)));
restoreSettings();
}
FormClassWizardPage::~FormClassWizardPage()
{
delete m_ui;
}
void FormClassWizardPage::setSuffixes(const QString &header, const QString &source, const QString &form)
{
m_ui->newClassWidget->setSourceExtension(source);
m_ui->newClassWidget->setHeaderExtension(header);
m_ui->newClassWidget->setFormExtension(form);
}
void FormClassWizardPage::setClassName(const QString &suggestedClassName)
{
// Is it valid, now?
m_ui->newClassWidget->setClassName(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();
}
void FormClassWizardPage::setPath(const QString &p)
{
m_ui->newClassWidget->setPath(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();
}
void FormClassWizardPage::slotValidChanged()
{
const bool validNow = m_ui->newClassWidget->isValid();
if (m_isValid != validNow) {
m_isValid = validNow;
emit completeChanged();
}
}
bool FormClassWizardPage::isComplete() const
{
return m_isValid;
}
bool FormClassWizardPage::validatePage()
{
QString errorMessage;
const bool rc = m_ui->newClassWidget->isValid(&errorMessage);
if (rc) {
saveSettings();
} else {
QMessageBox::critical(this, tr("%1 - Error").arg(title()), errorMessage);
}
return rc;
}
void FormClassWizardPage::saveSettings()
{
Core::ICore *core = ExtensionSystem::PluginManager::instance()->getObject<Core::ICore>();
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 = ExtensionSystem::PluginManager::instance()->getObject<Core::ICore>();
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

View File

@@ -0,0 +1,87 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef FORMCLASSWIZARDPAGE_H
#define FORMCLASSWIZARDPAGE_H
#include <QtGui/QWizardPage>
namespace Designer {
namespace Internal {
namespace Ui {
class FormClassWizardPage;
}
struct FormClassWizardParameters;
class FormClassWizardPage : public QWizardPage
{
Q_DISABLE_COPY(FormClassWizardPage)
Q_OBJECT
public:
explicit FormClassWizardPage(QWidget * parent = 0);
~FormClassWizardPage();
void setSuffixes(const QString &header, const QString &source, const QString &form);
virtual bool isComplete () const;
virtual bool validatePage();
int uiClassEmbedding() const;
bool hasRetranslationSupport() const;
QString path() const;
// Fill out applicable parameters
void getParameters(FormClassWizardParameters *) const;
public slots:
void setClassName(const QString &suggestedClassName);
void setPath(const QString &);
void setRetranslationSupport(bool);
void setUiClassEmbedding(int v);
private slots:
void slotValidChanged();
private:
void saveSettings();
void restoreSettings();
Ui::FormClassWizardPage *m_ui;
bool m_isValid;
};
} // namespace Internal
} // namespace Designer
#endif //FORMCLASSWIZARDPAGE_H

View File

@@ -0,0 +1,167 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Designer::Internal::FormClassWizardPage</class>
<widget class="QWizardPage" name="Designer::Internal::FormClassWizardPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>552</width>
<height>498</height>
</rect>
</property>
<property name="title">
<string>Choose a class name</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QGroupBox" name="classGroupBox">
<property name="title">
<string>Class</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="Core::Utils::NewClassWidget" name="newClassWidget" native="true"/>
</item>
</layout>
</widget>
</item>
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout_4">
<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>
<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>buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="aggregationButton">
<property name="text">
<string>Aggregation</string>
</property>
<attribute name="buttonGroup">
<string>buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="multipleInheritanceButton">
<property name="text">
<string>Multiple Inheritance</string>
</property>
<attribute name="buttonGroup">
<string>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>
<customwidget>
<class>Core::Utils::NewClassWidget</class>
<extends>QWidget</extends>
<header location="global">utils/newclasswidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
<buttongroups>
<buttongroup name="buttonGroup"/>
</buttongroups>
</ui>

View File

@@ -0,0 +1,174 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "formclasswizardparameters.h"
#include "formtemplatewizardpage.h"
#include <utils/codegeneration.h>
#include <QtCore/QTextStream>
#include <QtCore/QFileInfo>
#include <QtCore/QDebug>
static const char *uiMemberC = "m_ui";
static const char *uiNamespaceC = "Ui";
namespace Designer {
namespace Internal {
FormClassWizardParameters::FormClassWizardParameters() :
embedding(PointerAggregatedUiClass),
languageChange(true)
{
}
bool FormClassWizardParameters::generateCpp(QString *header, QString *source, int indentation) const
{
const QString indent = QString(indentation, QLatin1Char(' '));
QString formBaseClass;
QString uiClassName;
if (!FormTemplateWizardPagePage::getUIXmlData(uiTemplate, &formBaseClass, &uiClassName)) {
qWarning("Unable to determine the form base class from %s.", uiTemplate.toUtf8().constData());
return false;
}
// Do we have namespaces?
QStringList namespaceList = className.split(QLatin1String("::"));
if (namespaceList.empty()) // Paranoia!
return false;
const QString unqualifiedClassName = namespaceList.takeLast();
// Include guards
const QString guard = Core::Utils::headerGuard(unqualifiedClassName);
QString uiInclude = QLatin1String("ui_");
uiInclude += QFileInfo(uiFile).baseName();
uiInclude += QLatin1String(".h");
// 1) Header file
QTextStream headerStr(header);
headerStr << "#ifndef " << guard
<< "\n#define " << guard << '\n' << '\n';
// Include 'ui_'
if (embedding != 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;
Core::Utils::writeIncludeFileDirective(baseInclude, true, headerStr);
}
}
// Forward-declare the UI class
if (embedding == PointerAggregatedUiClass) {
headerStr << "\nnamespace " << uiNamespaceC << " {\n"
<< indent << "class " << uiClassName << ";\n}\n";
}
const QString namespaceIndent = Core::Utils::writeOpeningNameSpaces(namespaceList, indent, headerStr);
// Class declaration
headerStr << '\n' << namespaceIndent << "class " << unqualifiedClassName
<< " : public " << formBaseClass;
if (embedding == InheritedUiClass) {
headerStr << ", private " << uiNamespaceC << "::" << uiClassName;
}
headerStr << " {\n" << namespaceIndent << indent << "Q_OBJECT\n"
<< namespaceIndent << indent << "Q_DISABLE_COPY(" << unqualifiedClassName << ")\n"
<< namespaceIndent << "public:\n"
<< namespaceIndent << indent << "explicit " << unqualifiedClassName << "(QWidget *parent = 0);\n";
if (embedding == PointerAggregatedUiClass)
headerStr << namespaceIndent << indent << "virtual ~" << unqualifiedClassName << "();\n";
// retranslation
if (languageChange)
headerStr << '\n' << namespaceIndent << "protected:\n"
<< namespaceIndent << indent << "virtual void changeEvent(QEvent *e);\n";
// Member variable
if (embedding != InheritedUiClass) {
headerStr << '\n' << namespaceIndent << "private:\n"
<< namespaceIndent << indent << uiNamespaceC << "::" << uiClassName << ' ';
if (embedding == PointerAggregatedUiClass)
headerStr << '*';
headerStr << uiMemberC << ";\n";
}
headerStr << namespaceIndent << "};\n\n";
Core::Utils::writeClosingNameSpaces(namespaceList, indent, headerStr);
headerStr << "#endif // "<< guard << '\n';
// 2) Source file
QTextStream sourceStr(source);
Core::Utils::writeIncludeFileDirective(headerFile, false, sourceStr);
if (embedding == PointerAggregatedUiClass)
Core::Utils::writeIncludeFileDirective(uiInclude, false, sourceStr);
// NameSpaces(
Core::Utils::writeOpeningNameSpaces(namespaceList, indent, sourceStr);
// Constructor with setupUi
sourceStr << '\n' << namespaceIndent << unqualifiedClassName << "::" << unqualifiedClassName << "(QWidget *parent) :\n"
<< namespaceIndent << indent << formBaseClass << "(parent)";
if (embedding == PointerAggregatedUiClass)
sourceStr << ",\n" << namespaceIndent << indent << uiMemberC << "(new " << uiNamespaceC << "::" << uiClassName << ")\n";
sourceStr << namespaceIndent << "{\n" << namespaceIndent << indent;
if (embedding != InheritedUiClass)
sourceStr << uiMemberC << (embedding == PointerAggregatedUiClass ? "->" : ".");
sourceStr << "setupUi(this);\n" << namespaceIndent << "}\n";
// Deleting destructor for ptr
if (embedding == PointerAggregatedUiClass) {
sourceStr << '\n' << namespaceIndent << unqualifiedClassName << "::~" << unqualifiedClassName
<< "()\n" << namespaceIndent << "{\n"
<< namespaceIndent << indent << "delete " << uiMemberC << ";\n"
<< namespaceIndent << "}\n";
}
// retranslation
if (languageChange) {
sourceStr << '\n' << namespaceIndent << "void " << unqualifiedClassName << "::" << "changeEvent(QEvent *e)\n"
<< namespaceIndent << "{\n"
<< namespaceIndent << indent << "switch(e->type()) {\n" << namespaceIndent << indent << "case QEvent::LanguageChange:\n"
<< namespaceIndent << indent << indent;
if (embedding != InheritedUiClass)
sourceStr << uiMemberC << (embedding == PointerAggregatedUiClass ? "->" : ".");
sourceStr << "retranslateUi(this);\n"
<< namespaceIndent << indent << indent << "break;\n"
<< namespaceIndent << indent << "default:\n"
<< namespaceIndent << indent << indent << "break;\n"
<< namespaceIndent << indent << "}\n"
<< namespaceIndent << "}\n";
}
Core::Utils::writeClosingNameSpaces(namespaceList, indent, sourceStr);
return true;
}
} // namespace Internal
} // namespace Designer

View File

@@ -0,0 +1,67 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef FORMCLASSWIZARDPARAMETERS_H
#define FORMCLASSWIZARDPARAMETERS_H
#include <QtCore/QString>
namespace Designer {
namespace Internal {
enum UiClassEmbedding {
PointerAggregatedUiClass,
AggregatedUiClass,
InheritedUiClass
};
struct FormClassWizardParameters {
explicit FormClassWizardParameters();
bool generateCpp(QString *header, QString *source, int indentation = 4) const;
UiClassEmbedding embedding;
bool languageChange; // Add handling for language change events
QString uiTemplate;
QString className;
QString path;
QString sourceFile;
QString headerFile;
QString uiFile;
};
} // namespace Internal
} // namespace Designer
#endif // FORMCLASSWIZARDPARAMETERS_H