2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "formclasswizardparameters.h"
|
|
|
|
|
#include "formtemplatewizardpage.h"
|
|
|
|
|
|
|
|
|
|
#include <utils/codegeneration.h>
|
2009-06-22 16:22:15 +02:00
|
|
|
#include <cpptools/cppmodelmanagerinterface.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include <QtCore/QTextStream>
|
2009-07-01 16:27:40 +02:00
|
|
|
#include <QtCore/QSettings>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtCore/QFileInfo>
|
|
|
|
|
#include <QtCore/QDebug>
|
2009-07-01 16:27:40 +02:00
|
|
|
#include <QtCore/QSharedData>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-07-15 16:19:16 +02:00
|
|
|
static const char *uiMemberC = "ui";
|
2008-12-02 12:01:29 +01:00
|
|
|
static const char *uiNamespaceC = "Ui";
|
|
|
|
|
|
2009-07-01 16:27:40 +02:00
|
|
|
static const char *formClassWizardPageGroupC = "FormClassWizardPage";
|
|
|
|
|
static const char *translationKeyC = "RetranslationSupport";
|
|
|
|
|
static const char *embeddingModeKeyC = "Embedding";
|
|
|
|
|
|
|
|
|
|
// TODO: These 2 are general coding convention settings and
|
|
|
|
|
// should go to CppTools...
|
|
|
|
|
static const char *includeQtModuleKeyC = "IncludeQtModule";
|
|
|
|
|
static const char *indentNamespaceKeyC = "IndentNamespace";
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
namespace Designer {
|
2009-07-01 16:27:40 +02:00
|
|
|
|
|
|
|
|
class FormClassWizardGenerationParametersPrivate : public QSharedData
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
FormClassWizardGenerationParametersPrivate();
|
|
|
|
|
void fromSettings(const QSettings *);
|
|
|
|
|
void toSettings(QSettings *) const;
|
|
|
|
|
bool equals(const FormClassWizardGenerationParametersPrivate &rhs) const;
|
|
|
|
|
|
|
|
|
|
FormClassWizardGenerationParameters::UiClassEmbedding embedding;
|
|
|
|
|
bool retranslationSupport; // Add handling for language change events
|
|
|
|
|
bool includeQtModule; // Include "<QtGui/[Class]>" or just "<[Class]>"
|
|
|
|
|
bool indentNamespace;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
FormClassWizardGenerationParametersPrivate::FormClassWizardGenerationParametersPrivate() :
|
|
|
|
|
embedding(FormClassWizardGenerationParameters::PointerAggregatedUiClass),
|
|
|
|
|
retranslationSupport(true),
|
|
|
|
|
includeQtModule(false),
|
|
|
|
|
indentNamespace(false)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FormClassWizardGenerationParametersPrivate::fromSettings(const QSettings *settings)
|
|
|
|
|
{
|
|
|
|
|
QString key = QLatin1String(formClassWizardPageGroupC);
|
|
|
|
|
key += QLatin1Char('/');
|
|
|
|
|
const int groupLength = key.size();
|
|
|
|
|
|
|
|
|
|
key += QLatin1String(translationKeyC);
|
|
|
|
|
retranslationSupport = settings->value(key, true).toBool();
|
|
|
|
|
|
|
|
|
|
key.truncate(groupLength);
|
|
|
|
|
key += QLatin1String(embeddingModeKeyC);
|
|
|
|
|
embedding = static_cast<FormClassWizardGenerationParameters::UiClassEmbedding>(settings->value(key, int(FormClassWizardGenerationParameters::PointerAggregatedUiClass)).toInt());
|
|
|
|
|
|
|
|
|
|
key.truncate(groupLength);
|
|
|
|
|
key += QLatin1String(includeQtModuleKeyC);
|
|
|
|
|
includeQtModule = settings->value(key, false).toBool();
|
|
|
|
|
|
|
|
|
|
key.truncate(groupLength);
|
|
|
|
|
key += QLatin1String(indentNamespaceKeyC);
|
|
|
|
|
indentNamespace = settings->value(key, false).toBool();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FormClassWizardGenerationParametersPrivate::toSettings(QSettings *settings) const
|
|
|
|
|
{
|
|
|
|
|
settings->beginGroup(QLatin1String(formClassWizardPageGroupC));
|
|
|
|
|
settings->setValue(QLatin1String(translationKeyC), retranslationSupport);
|
|
|
|
|
settings->setValue(QLatin1String(embeddingModeKeyC), embedding);
|
|
|
|
|
settings->setValue(QLatin1String(includeQtModuleKeyC), includeQtModule);
|
|
|
|
|
settings->setValue(QLatin1String(indentNamespaceKeyC), indentNamespace);
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FormClassWizardGenerationParametersPrivate::equals(const FormClassWizardGenerationParametersPrivate &rhs) const
|
|
|
|
|
{
|
|
|
|
|
return embedding == rhs.embedding && retranslationSupport == rhs.retranslationSupport
|
|
|
|
|
&& includeQtModule == rhs.includeQtModule && indentNamespace == rhs.indentNamespace;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FormClassWizardGenerationParameters::FormClassWizardGenerationParameters() :
|
|
|
|
|
m_d(new FormClassWizardGenerationParametersPrivate)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FormClassWizardGenerationParameters::~FormClassWizardGenerationParameters()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FormClassWizardGenerationParameters::FormClassWizardGenerationParameters(const FormClassWizardGenerationParameters &rhs) :
|
|
|
|
|
m_d(rhs.m_d)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FormClassWizardGenerationParameters &FormClassWizardGenerationParameters::operator=(const FormClassWizardGenerationParameters &rhs)
|
|
|
|
|
{
|
|
|
|
|
if (this != &rhs)
|
|
|
|
|
m_d.operator=(rhs.m_d);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FormClassWizardGenerationParameters::equals(const FormClassWizardGenerationParameters &rhs) const
|
|
|
|
|
{
|
|
|
|
|
return m_d->equals(*rhs.m_d.constData());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FormClassWizardGenerationParameters::UiClassEmbedding FormClassWizardGenerationParameters::embedding() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->embedding;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FormClassWizardGenerationParameters::setEmbedding(UiClassEmbedding e)
|
|
|
|
|
{
|
|
|
|
|
m_d->embedding = e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FormClassWizardGenerationParameters::retranslationSupport() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->retranslationSupport;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FormClassWizardGenerationParameters::setRetranslationSupport(bool v)
|
|
|
|
|
{
|
|
|
|
|
m_d->retranslationSupport = v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FormClassWizardGenerationParameters::includeQtModule() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->includeQtModule;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FormClassWizardGenerationParameters::setIncludeQtModule(bool v)
|
|
|
|
|
{
|
|
|
|
|
m_d->includeQtModule = v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FormClassWizardGenerationParameters::indentNamespace() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->indentNamespace;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FormClassWizardGenerationParameters::setIndentNamespace(bool v)
|
|
|
|
|
{
|
|
|
|
|
m_d->indentNamespace = v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FormClassWizardGenerationParameters::fromSettings(const QSettings *settings)
|
|
|
|
|
{
|
|
|
|
|
m_d->fromSettings(settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FormClassWizardGenerationParameters::toSettings(QSettings *settings) const
|
|
|
|
|
{
|
|
|
|
|
m_d->toSettings(settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------
|
|
|
|
|
|
|
|
|
|
class FormClassWizardParametersPrivate : public QSharedData {
|
|
|
|
|
public:
|
|
|
|
|
bool generateCpp(const FormClassWizardGenerationParameters &fgp,
|
|
|
|
|
QString *header, QString *source, int indentation) const;
|
|
|
|
|
|
|
|
|
|
QString uiTemplate;
|
|
|
|
|
QString className;
|
|
|
|
|
|
|
|
|
|
QString path;
|
|
|
|
|
QString sourceFile;
|
|
|
|
|
QString headerFile;
|
|
|
|
|
QString uiFile;
|
|
|
|
|
};
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
FormClassWizardParameters::FormClassWizardParameters() :
|
2009-07-01 16:27:40 +02:00
|
|
|
m_d(new FormClassWizardParametersPrivate)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-01 16:27:40 +02:00
|
|
|
FormClassWizardParameters::~FormClassWizardParameters()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-07-01 16:27:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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(' '));
|
2008-12-02 12:01:29 +01:00
|
|
|
QString formBaseClass;
|
|
|
|
|
QString uiClassName;
|
2009-07-01 16:27:40 +02:00
|
|
|
if (!FormClassWizardParameters::getUIXmlData(uiTemplate, &formBaseClass, &uiClassName)) {
|
2008-12-02 12:01:29 +01:00
|
|
|
qWarning("Unable to determine the form base class from %s.", uiTemplate.toUtf8().constData());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-19 10:34:33 +01:00
|
|
|
// Build the ui class (Ui::Foo) name relative to the namespace (which is the same):
|
2009-07-01 16:27:40 +02:00
|
|
|
const FormClassWizardGenerationParameters::UiClassEmbedding embedding = generationParameters.embedding();
|
2008-12-19 10:34:33 +01:00
|
|
|
const QString colonColon = QLatin1String("::");
|
|
|
|
|
const int lastSeparator = uiClassName.lastIndexOf(colonColon);
|
|
|
|
|
if (lastSeparator != -1)
|
|
|
|
|
uiClassName.remove(0, lastSeparator + colonColon.size());
|
|
|
|
|
uiClassName.insert(0, QLatin1String(uiNamespaceC) + colonColon);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// Do we have namespaces?
|
2008-12-19 10:34:33 +01:00
|
|
|
QStringList namespaceList = className.split(colonColon);
|
2008-12-02 12:01:29 +01:00
|
|
|
if (namespaceList.empty()) // Paranoia!
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
const QString unqualifiedClassName = namespaceList.takeLast();
|
|
|
|
|
|
2009-06-22 16:22:15 +02:00
|
|
|
const QString license = CppTools::AbstractEditorSupport::licenseTemplate();
|
2008-12-02 12:01:29 +01:00
|
|
|
// Include guards
|
2009-03-05 17:12:31 +01:00
|
|
|
const QString guard = Core::Utils::headerGuard(headerFile);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QString uiInclude = QLatin1String("ui_");
|
2009-03-20 16:13:46 +01:00
|
|
|
uiInclude += QFileInfo(uiFile).completeBaseName();
|
2008-12-02 12:01:29 +01:00
|
|
|
uiInclude += QLatin1String(".h");
|
|
|
|
|
|
|
|
|
|
// 1) Header file
|
|
|
|
|
QTextStream headerStr(header);
|
2009-06-22 16:22:15 +02:00
|
|
|
headerStr << license << "#ifndef " << guard
|
2008-12-02 12:01:29 +01:00
|
|
|
<< "\n#define " << guard << '\n' << '\n';
|
|
|
|
|
|
|
|
|
|
// Include 'ui_'
|
2009-07-01 16:27:40 +02:00
|
|
|
if (embedding != FormClassWizardGenerationParameters::PointerAggregatedUiClass) {
|
2008-12-02 12:01:29 +01:00
|
|
|
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'))) {
|
2009-07-01 16:27:40 +02:00
|
|
|
QString baseInclude = formBaseClass;
|
|
|
|
|
if (generationParameters.includeQtModule())
|
|
|
|
|
baseInclude.insert(0, QLatin1String("QtGui/"));
|
2008-12-02 12:01:29 +01:00
|
|
|
Core::Utils::writeIncludeFileDirective(baseInclude, true, headerStr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-01 16:27:40 +02:00
|
|
|
const QString namespaceIndent = Core::Utils::writeOpeningNameSpaces(namespaceList,
|
|
|
|
|
generationParameters.indentNamespace() ? indent : QString(),
|
|
|
|
|
headerStr);
|
2008-12-19 10:34:33 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// Forward-declare the UI class
|
2009-07-01 16:27:40 +02:00
|
|
|
if (embedding == FormClassWizardGenerationParameters::PointerAggregatedUiClass) {
|
2008-12-19 10:34:33 +01:00
|
|
|
headerStr << '\n'
|
|
|
|
|
<< namespaceIndent << "namespace " << uiNamespaceC << " {\n"
|
2009-07-01 16:27:40 +02:00
|
|
|
<< namespaceIndent << indent << "class " << Internal::FormTemplateWizardPage::stripNamespaces(uiClassName) << ";\n"
|
2008-12-19 10:34:33 +01:00
|
|
|
<< namespaceIndent << "}\n";
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Class declaration
|
|
|
|
|
headerStr << '\n' << namespaceIndent << "class " << unqualifiedClassName
|
|
|
|
|
<< " : public " << formBaseClass;
|
2009-07-01 16:27:40 +02:00
|
|
|
if (embedding == FormClassWizardGenerationParameters::InheritedUiClass) {
|
2008-12-19 10:34:33 +01:00
|
|
|
headerStr << ", private " << uiClassName;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
headerStr << " {\n" << namespaceIndent << indent << "Q_OBJECT\n"
|
|
|
|
|
<< namespaceIndent << "public:\n"
|
2009-06-09 15:52:58 +02:00
|
|
|
<< namespaceIndent << indent << unqualifiedClassName << "(QWidget *parent = 0);\n";
|
2009-07-01 16:27:40 +02:00
|
|
|
if (embedding == FormClassWizardGenerationParameters::PointerAggregatedUiClass)
|
2009-06-09 15:52:58 +02:00
|
|
|
headerStr << namespaceIndent << indent << "~" << unqualifiedClassName << "();\n";
|
2008-12-02 12:01:29 +01:00
|
|
|
// retranslation
|
2009-07-01 16:27:40 +02:00
|
|
|
if (generationParameters.retranslationSupport())
|
2008-12-02 12:01:29 +01:00
|
|
|
headerStr << '\n' << namespaceIndent << "protected:\n"
|
2009-06-09 15:52:58 +02:00
|
|
|
<< namespaceIndent << indent << "void changeEvent(QEvent *e);\n";
|
2008-12-02 12:01:29 +01:00
|
|
|
// Member variable
|
2009-07-01 16:27:40 +02:00
|
|
|
if (embedding != FormClassWizardGenerationParameters::InheritedUiClass) {
|
2008-12-02 12:01:29 +01:00
|
|
|
headerStr << '\n' << namespaceIndent << "private:\n"
|
2008-12-19 10:34:33 +01:00
|
|
|
<< namespaceIndent << indent << uiClassName << ' ';
|
2009-07-01 16:27:40 +02:00
|
|
|
if (embedding == FormClassWizardGenerationParameters::PointerAggregatedUiClass)
|
2008-12-02 12:01:29 +01:00
|
|
|
headerStr << '*';
|
|
|
|
|
headerStr << uiMemberC << ";\n";
|
|
|
|
|
}
|
|
|
|
|
headerStr << namespaceIndent << "};\n\n";
|
2009-07-01 16:27:40 +02:00
|
|
|
Core::Utils::writeClosingNameSpaces(namespaceList, generationParameters.indentNamespace() ? indent : QString(), headerStr);
|
2008-12-02 12:01:29 +01:00
|
|
|
headerStr << "#endif // "<< guard << '\n';
|
|
|
|
|
|
|
|
|
|
// 2) Source file
|
|
|
|
|
QTextStream sourceStr(source);
|
2009-06-22 16:22:15 +02:00
|
|
|
sourceStr << license;
|
2008-12-02 12:01:29 +01:00
|
|
|
Core::Utils::writeIncludeFileDirective(headerFile, false, sourceStr);
|
2009-07-01 16:27:40 +02:00
|
|
|
if (embedding == FormClassWizardGenerationParameters::PointerAggregatedUiClass)
|
2008-12-02 12:01:29 +01:00
|
|
|
Core::Utils::writeIncludeFileDirective(uiInclude, false, sourceStr);
|
|
|
|
|
// NameSpaces(
|
2009-07-01 16:27:40 +02:00
|
|
|
Core::Utils::writeOpeningNameSpaces(namespaceList, generationParameters.indentNamespace() ? indent : QString(), sourceStr);
|
2008-12-02 12:01:29 +01:00
|
|
|
// Constructor with setupUi
|
|
|
|
|
sourceStr << '\n' << namespaceIndent << unqualifiedClassName << "::" << unqualifiedClassName << "(QWidget *parent) :\n"
|
|
|
|
|
<< namespaceIndent << indent << formBaseClass << "(parent)";
|
2009-07-01 16:27:40 +02:00
|
|
|
if (embedding == FormClassWizardGenerationParameters::PointerAggregatedUiClass)
|
2008-12-19 10:34:33 +01:00
|
|
|
sourceStr << ",\n" << namespaceIndent << indent << uiMemberC << "(new " << uiClassName << ")\n";
|
2008-12-02 12:01:29 +01:00
|
|
|
sourceStr << namespaceIndent << "{\n" << namespaceIndent << indent;
|
2009-07-01 16:27:40 +02:00
|
|
|
writeUiMemberAccess(generationParameters, sourceStr);
|
|
|
|
|
sourceStr << "setupUi(this);\n" << namespaceIndent << "}\n";
|
2008-12-02 12:01:29 +01:00
|
|
|
// Deleting destructor for ptr
|
2009-07-01 16:27:40 +02:00
|
|
|
if (embedding == FormClassWizardGenerationParameters::PointerAggregatedUiClass) {
|
2008-12-02 12:01:29 +01:00
|
|
|
sourceStr << '\n' << namespaceIndent << unqualifiedClassName << "::~" << unqualifiedClassName
|
|
|
|
|
<< "()\n" << namespaceIndent << "{\n"
|
|
|
|
|
<< namespaceIndent << indent << "delete " << uiMemberC << ";\n"
|
|
|
|
|
<< namespaceIndent << "}\n";
|
|
|
|
|
}
|
|
|
|
|
// retranslation
|
2009-07-01 16:27:40 +02:00
|
|
|
if (generationParameters.retranslationSupport()) {
|
2008-12-02 12:01:29 +01:00
|
|
|
sourceStr << '\n' << namespaceIndent << "void " << unqualifiedClassName << "::" << "changeEvent(QEvent *e)\n"
|
|
|
|
|
<< namespaceIndent << "{\n"
|
2009-03-17 13:50:32 +01:00
|
|
|
<< namespaceIndent << indent << formBaseClass << "::changeEvent(e);\n"
|
2008-12-09 11:07:24 +01:00
|
|
|
<< namespaceIndent << indent << "switch (e->type()) {\n" << namespaceIndent << indent << "case QEvent::LanguageChange:\n"
|
2008-12-02 12:01:29 +01:00
|
|
|
<< namespaceIndent << indent << indent;
|
2009-07-01 16:27:40 +02:00
|
|
|
writeUiMemberAccess(generationParameters, sourceStr);
|
2008-12-02 12:01:29 +01:00
|
|
|
sourceStr << "retranslateUi(this);\n"
|
|
|
|
|
<< namespaceIndent << indent << indent << "break;\n"
|
|
|
|
|
<< namespaceIndent << indent << "default:\n"
|
|
|
|
|
<< namespaceIndent << indent << indent << "break;\n"
|
|
|
|
|
<< namespaceIndent << indent << "}\n"
|
|
|
|
|
<< namespaceIndent << "}\n";
|
|
|
|
|
}
|
2009-07-01 16:27:40 +02:00
|
|
|
Core::Utils::writeClosingNameSpaces(namespaceList, generationParameters.indentNamespace() ? indent : QString(), sourceStr);
|
2008-12-02 12:01:29 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-01 16:27:40 +02:00
|
|
|
bool FormClassWizardParameters::generateCpp(const FormClassWizardGenerationParameters &fgp,
|
|
|
|
|
QString *header, QString *source, int indentation) const
|
|
|
|
|
{
|
|
|
|
|
return m_d->generateCpp(fgp, header, source, indentation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
} // namespace Designer
|