2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 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 "cppclasswizard.h"
|
|
|
|
|
#include "cppeditorconstants.h"
|
|
|
|
|
|
2009-03-18 16:43:01 +01:00
|
|
|
#include <cpptools/cpptoolsconstants.h>
|
2009-06-22 16:22:15 +02:00
|
|
|
#include <cpptools/cppmodelmanagerinterface.h>
|
2009-03-18 16:43:01 +01:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/mimedatabase.h>
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <utils/codegeneration.h>
|
|
|
|
|
#include <utils/newclasswidget.h>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include <QtCore/QDebug>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <QtCore/QDir>
|
|
|
|
|
#include <QtCore/QTextStream>
|
2009-03-18 16:43:01 +01:00
|
|
|
#include <QtCore/QSettings>
|
2008-12-09 15:25:01 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtGui/QVBoxLayout>
|
2009-03-18 16:43:01 +01:00
|
|
|
#include <QtGui/QHBoxLayout>
|
|
|
|
|
#include <QtGui/QPushButton>
|
|
|
|
|
#include <QtGui/QToolButton>
|
|
|
|
|
#include <QtGui/QSpacerItem>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtGui/QWizard>
|
|
|
|
|
|
|
|
|
|
using namespace CppEditor;
|
|
|
|
|
using namespace CppEditor::Internal;
|
|
|
|
|
|
|
|
|
|
// ========= ClassNamePage =========
|
|
|
|
|
|
2009-03-18 16:43:01 +01:00
|
|
|
ClassNamePage::ClassNamePage(QWidget *parent) :
|
2008-12-02 12:01:29 +01:00
|
|
|
QWizardPage(parent),
|
|
|
|
|
m_isValid(false)
|
|
|
|
|
{
|
|
|
|
|
setTitle(tr("Enter class name"));
|
|
|
|
|
setSubTitle(tr("The header and source file names will be derived from the class name"));
|
|
|
|
|
|
2009-10-05 11:06:05 +02:00
|
|
|
m_newClassWidget = new Utils::NewClassWidget;
|
2008-12-02 12:01:29 +01:00
|
|
|
// Order, set extensions first before suggested name is derived
|
|
|
|
|
m_newClassWidget->setBaseClassInputVisible(true);
|
|
|
|
|
m_newClassWidget->setBaseClassChoices(QStringList() << QString()
|
|
|
|
|
<< QLatin1String("QObject")
|
|
|
|
|
<< QLatin1String("QWidget")
|
|
|
|
|
<< QLatin1String("QMainWindow"));
|
|
|
|
|
m_newClassWidget->setBaseClassEditable(true);
|
|
|
|
|
m_newClassWidget->setFormInputVisible(false);
|
|
|
|
|
m_newClassWidget->setNamespacesEnabled(true);
|
2008-12-05 10:39:08 +01:00
|
|
|
m_newClassWidget->setAllowDirectories(true);
|
2009-10-21 17:06:15 +02:00
|
|
|
m_newClassWidget->setBaseClassInputVisible(true);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-03-18 16:43:01 +01:00
|
|
|
connect(m_newClassWidget, SIGNAL(validChanged()), this, SLOT(slotValidChanged()));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-01-29 21:33:57 +01:00
|
|
|
QVBoxLayout *pageLayout = new QVBoxLayout(this);
|
2008-12-02 12:01:29 +01:00
|
|
|
pageLayout->addWidget(m_newClassWidget);
|
2009-03-18 16:43:01 +01:00
|
|
|
QSpacerItem *vSpacer = new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::Expanding);
|
|
|
|
|
pageLayout->addItem(vSpacer);
|
|
|
|
|
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
|
|
|
|
pageLayout->addLayout(buttonLayout);
|
|
|
|
|
QSpacerItem *hSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Ignored);
|
|
|
|
|
buttonLayout->addItem(hSpacer);
|
|
|
|
|
QToolButton *settingsButton = new QToolButton;
|
|
|
|
|
settingsButton->setText(tr("Configure..."));
|
|
|
|
|
connect(settingsButton, SIGNAL(clicked()), this, SLOT(slotSettings()));
|
|
|
|
|
buttonLayout->addWidget(settingsButton);
|
|
|
|
|
initParameters();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Retrieve settings of CppTools plugin.
|
|
|
|
|
static inline bool lowerCaseFiles(const Core::ICore *core)
|
|
|
|
|
{
|
2009-03-18 17:05:48 +01:00
|
|
|
QString lowerCaseSettingsKey = QLatin1String(CppTools::Constants::CPPTOOLS_SETTINGSGROUP);
|
|
|
|
|
lowerCaseSettingsKey += QLatin1Char('/');
|
|
|
|
|
lowerCaseSettingsKey += QLatin1String(CppTools::Constants::LOWERCASE_CPPFILES_KEY);
|
|
|
|
|
const bool lowerCaseDefault = CppTools::Constants::lowerCaseFilesDefault;
|
|
|
|
|
return core->settings()->value(lowerCaseSettingsKey, QVariant(lowerCaseDefault)).toBool();
|
2009-03-18 16:43:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set up new class widget from settings
|
|
|
|
|
void ClassNamePage::initParameters()
|
|
|
|
|
{
|
|
|
|
|
Core::ICore *core = Core::ICore::instance();
|
|
|
|
|
const Core::MimeDatabase *mdb = core->mimeDatabase();
|
|
|
|
|
m_newClassWidget->setHeaderExtension(mdb->preferredSuffixByType(QLatin1String(Constants::CPP_HEADER_MIMETYPE)));
|
|
|
|
|
m_newClassWidget->setSourceExtension(mdb->preferredSuffixByType(QLatin1String(Constants::CPP_SOURCE_MIMETYPE)));
|
|
|
|
|
m_newClassWidget->setLowerCaseFiles(lowerCaseFiles(core));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClassNamePage::slotSettings()
|
|
|
|
|
{
|
|
|
|
|
const QString id = QLatin1String(CppTools::Constants::CPP_SETTINGS_ID);
|
|
|
|
|
const QString cat = QLatin1String(CppTools::Constants::CPP_SETTINGS_CATEGORY);
|
|
|
|
|
if (Core::ICore::instance()->showOptionsDialog(cat, id, this)) {
|
|
|
|
|
initParameters();
|
|
|
|
|
m_newClassWidget->triggerUpdateFileNames();
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClassNamePage::slotValidChanged()
|
|
|
|
|
{
|
|
|
|
|
const bool validNow = m_newClassWidget->isValid();
|
|
|
|
|
if (m_isValid != validNow) {
|
|
|
|
|
m_isValid = validNow;
|
|
|
|
|
emit completeChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-18 16:43:01 +01:00
|
|
|
CppClassWizardDialog::CppClassWizardDialog(QWidget *parent) :
|
2008-12-02 12:01:29 +01:00
|
|
|
QWizard(parent),
|
2009-03-18 16:43:01 +01:00
|
|
|
m_classNamePage(new ClassNamePage(this))
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
Core::BaseFileWizard::setupWizard(this);
|
|
|
|
|
setWindowTitle(tr("C++ Class Wizard"));
|
|
|
|
|
addPage(m_classNamePage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppClassWizardDialog::setPath(const QString &path)
|
|
|
|
|
{
|
|
|
|
|
m_classNamePage->newClassWidget()->setPath(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CppClassWizardParameters CppClassWizardDialog::parameters() const
|
|
|
|
|
{
|
|
|
|
|
CppClassWizardParameters rc;
|
2009-10-05 11:06:05 +02:00
|
|
|
const Utils::NewClassWidget *ncw = m_classNamePage->newClassWidget();
|
2008-12-02 12:01:29 +01:00
|
|
|
rc.className = ncw->className();
|
|
|
|
|
rc.headerFile = ncw->headerFileName();
|
|
|
|
|
rc.sourceFile = ncw->sourceFileName();
|
|
|
|
|
rc.baseClass = ncw->baseClassName();
|
|
|
|
|
rc.path = ncw->path();
|
2009-11-02 15:46:51 +01:00
|
|
|
rc.classType = ncw->classType();
|
2008-12-02 12:01:29 +01:00
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ========= CppClassWizard =========
|
|
|
|
|
|
|
|
|
|
CppClassWizard::CppClassWizard(const Core::BaseFileWizardParameters ¶meters,
|
2009-01-20 15:31:33 +01:00
|
|
|
QObject *parent)
|
|
|
|
|
: Core::BaseFileWizard(parameters, parent)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CppClassWizard::sourceSuffix() const
|
|
|
|
|
{
|
|
|
|
|
return preferredSuffix(QLatin1String(Constants::CPP_SOURCE_MIMETYPE));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CppClassWizard::headerSuffix() const
|
|
|
|
|
{
|
|
|
|
|
return preferredSuffix(QLatin1String(Constants::CPP_HEADER_MIMETYPE));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWizard *CppClassWizard::createWizardDialog(QWidget *parent,
|
|
|
|
|
const QString &defaultPath,
|
|
|
|
|
const WizardPageList &extensionPages) const
|
|
|
|
|
{
|
2009-03-18 16:43:01 +01:00
|
|
|
CppClassWizardDialog *wizard = new CppClassWizardDialog(parent);
|
2008-12-02 12:01:29 +01:00
|
|
|
foreach (QWizardPage *p, extensionPages)
|
|
|
|
|
wizard->addPage(p);
|
|
|
|
|
wizard->setPath(defaultPath);
|
|
|
|
|
return wizard;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::GeneratedFiles CppClassWizard::generateFiles(const QWizard *w, QString *errorMessage) const
|
|
|
|
|
{
|
|
|
|
|
const CppClassWizardDialog *wizard = qobject_cast<const CppClassWizardDialog *>(w);
|
|
|
|
|
const CppClassWizardParameters params = wizard->parameters();
|
|
|
|
|
|
|
|
|
|
const QString sourceFileName = Core::BaseFileWizard::buildFileName(params.path, params.sourceFile, sourceSuffix());
|
|
|
|
|
const QString headerFileName = Core::BaseFileWizard::buildFileName(params.path, params.headerFile, headerSuffix());
|
|
|
|
|
|
|
|
|
|
Core::GeneratedFile sourceFile(sourceFileName);
|
2010-01-07 18:17:24 +01:00
|
|
|
sourceFile.setEditorId(QLatin1String(Constants::CPPEDITOR_ID));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
Core::GeneratedFile headerFile(headerFileName);
|
2010-01-07 18:17:24 +01:00
|
|
|
headerFile.setEditorId(QLatin1String(Constants::CPPEDITOR_ID));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QString header, source;
|
|
|
|
|
if (!generateHeaderAndSource(params, &header, &source)) {
|
|
|
|
|
*errorMessage = tr("Error while generating file contents.");
|
|
|
|
|
return Core::GeneratedFiles();
|
|
|
|
|
}
|
|
|
|
|
headerFile.setContents(header);
|
|
|
|
|
sourceFile.setContents(source);
|
|
|
|
|
return Core::GeneratedFiles() << headerFile << sourceFile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool CppClassWizard::generateHeaderAndSource(const CppClassWizardParameters ¶ms,
|
|
|
|
|
QString *header, QString *source)
|
|
|
|
|
{
|
|
|
|
|
// TODO:
|
2009-11-02 15:46:51 +01:00
|
|
|
// Quite a bit of this code has been copied from FormClassWizardParameters::generateCpp
|
|
|
|
|
// and is duplicated in the library wizard.
|
2009-10-05 11:06:05 +02:00
|
|
|
// Maybe more of it could be merged into Utils.
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
const QString indent = QString(4, QLatin1Char(' '));
|
|
|
|
|
|
|
|
|
|
// Do we have namespaces?
|
|
|
|
|
QStringList namespaceList = params.className.split(QLatin1String("::"));
|
|
|
|
|
if (namespaceList.empty()) // Paranoia!
|
|
|
|
|
return false;
|
|
|
|
|
|
2009-06-22 16:22:15 +02:00
|
|
|
const QString license = CppTools::AbstractEditorSupport::licenseTemplate();
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
const QString unqualifiedClassName = namespaceList.takeLast();
|
2009-10-05 11:06:05 +02:00
|
|
|
const QString guard = Utils::headerGuard(params.headerFile);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// == Header file ==
|
|
|
|
|
QTextStream headerStr(header);
|
2009-06-22 16:22:15 +02:00
|
|
|
headerStr << license << "#ifndef " << guard
|
2009-03-20 17:01:16 +01:00
|
|
|
<< "\n#define " << guard << '\n';
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
const QRegExp qtClassExpr(QLatin1String("^Q[A-Z3].+"));
|
2008-12-09 15:25:01 +01:00
|
|
|
QTC_ASSERT(qtClassExpr.isValid(), /**/);
|
2009-11-02 15:46:51 +01:00
|
|
|
// Determine parent QObject type for Qt types. Provide base
|
|
|
|
|
// class in case the user did not specify one.
|
|
|
|
|
QString parentQObjectClass;
|
|
|
|
|
bool defineQObjectMacro = false;
|
|
|
|
|
switch(params.classType) {
|
|
|
|
|
case Utils::NewClassWidget::ClassInheritsQObject:
|
|
|
|
|
parentQObjectClass = QLatin1String("QObject");
|
|
|
|
|
defineQObjectMacro = true;
|
|
|
|
|
break;
|
|
|
|
|
case Utils::NewClassWidget::ClassInheritsQWidget:
|
|
|
|
|
parentQObjectClass = QLatin1String("QWidget");
|
|
|
|
|
defineQObjectMacro = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
const QString baseClass = params.baseClass.isEmpty()
|
|
|
|
|
&& params.classType != Utils::NewClassWidget::NoClassType ?
|
|
|
|
|
parentQObjectClass : params.baseClass;
|
|
|
|
|
const bool superIsQtClass = qtClassExpr.exactMatch(baseClass);
|
2008-12-02 12:01:29 +01:00
|
|
|
if (superIsQtClass) {
|
|
|
|
|
headerStr << '\n';
|
2009-11-02 15:46:51 +01:00
|
|
|
Utils::writeIncludeFileDirective(baseClass, true, headerStr);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-12-01 16:17:45 +01:00
|
|
|
if (params.classType == Utils::NewClassWidget::SharedDataClass) {
|
|
|
|
|
headerStr << '\n';
|
|
|
|
|
Utils::writeIncludeFileDirective(QLatin1String("QSharedDataPointer"), true, headerStr);
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-10-05 11:06:05 +02:00
|
|
|
const QString namespaceIndent = Utils::writeOpeningNameSpaces(namespaceList, QString(), headerStr);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-12-01 16:17:45 +01:00
|
|
|
const QString sharedDataClass = unqualifiedClassName + QLatin1String("Data");
|
|
|
|
|
|
|
|
|
|
if (params.classType == Utils::NewClassWidget::SharedDataClass)
|
|
|
|
|
headerStr << '\n' << "class " << sharedDataClass << ";\n";
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// Class declaration
|
2009-12-01 16:17:45 +01:00
|
|
|
headerStr << '\n' << namespaceIndent << "class " << unqualifiedClassName;
|
2009-11-02 15:46:51 +01:00
|
|
|
if (!baseClass.isEmpty())
|
|
|
|
|
headerStr << " : public " << baseClass << "\n";
|
2008-12-02 12:01:29 +01:00
|
|
|
else
|
|
|
|
|
headerStr << "\n";
|
|
|
|
|
headerStr << namespaceIndent << "{\n";
|
2009-11-02 15:46:51 +01:00
|
|
|
if (defineQObjectMacro)
|
2009-10-21 17:06:15 +02:00
|
|
|
headerStr << namespaceIndent << "Q_OBJECT\n";
|
2008-12-02 12:01:29 +01:00
|
|
|
headerStr << namespaceIndent << "public:\n"
|
2009-11-02 15:46:51 +01:00
|
|
|
<< namespaceIndent << indent;
|
|
|
|
|
// Constructor
|
|
|
|
|
if (parentQObjectClass.isEmpty()) {
|
|
|
|
|
headerStr << unqualifiedClassName << "();\n";
|
|
|
|
|
} else {
|
|
|
|
|
headerStr << "explicit " << unqualifiedClassName << '(' << parentQObjectClass
|
|
|
|
|
<< " *parent = 0);\n";
|
|
|
|
|
}
|
2009-12-01 16:17:45 +01:00
|
|
|
// Copy/Assignment for shared data classes.
|
|
|
|
|
if (params.classType == Utils::NewClassWidget::SharedDataClass) {
|
|
|
|
|
headerStr << namespaceIndent << indent
|
2009-12-01 16:25:27 +01:00
|
|
|
<< unqualifiedClassName << "(const " << unqualifiedClassName << " &);\n"
|
2009-12-01 16:17:45 +01:00
|
|
|
<< namespaceIndent << indent
|
2009-12-01 16:25:27 +01:00
|
|
|
<< unqualifiedClassName << " &operator=(const " << unqualifiedClassName << " &);\n"
|
2009-12-01 16:17:45 +01:00
|
|
|
<< namespaceIndent << indent
|
|
|
|
|
<< '~' << unqualifiedClassName << "();\n";
|
|
|
|
|
}
|
2009-11-02 15:46:51 +01:00
|
|
|
if (defineQObjectMacro)
|
|
|
|
|
headerStr << '\n' << namespaceIndent << "signals:\n\n" << namespaceIndent << "public slots:\n\n";
|
2009-12-01 16:17:45 +01:00
|
|
|
if (params.classType == Utils::NewClassWidget::SharedDataClass) {
|
|
|
|
|
headerStr << '\n' << namespaceIndent << "private:\n"
|
|
|
|
|
<< namespaceIndent << indent << "QSharedDataPointer<" << sharedDataClass << "> data;\n";
|
|
|
|
|
}
|
2009-03-20 17:01:16 +01:00
|
|
|
headerStr << namespaceIndent << "};\n";
|
|
|
|
|
|
2009-10-05 11:06:05 +02:00
|
|
|
Utils::writeClosingNameSpaces(namespaceList, QString(), headerStr);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-03-20 17:01:16 +01:00
|
|
|
headerStr << '\n';
|
2008-12-02 12:01:29 +01:00
|
|
|
headerStr << "#endif // "<< guard << '\n';
|
|
|
|
|
|
|
|
|
|
// == Source file ==
|
|
|
|
|
QTextStream sourceStr(source);
|
2009-06-22 16:22:15 +02:00
|
|
|
sourceStr << license;
|
2009-10-05 11:06:05 +02:00
|
|
|
Utils::writeIncludeFileDirective(params.headerFile, false, sourceStr);
|
2009-12-01 16:17:45 +01:00
|
|
|
if (params.classType == Utils::NewClassWidget::SharedDataClass)
|
|
|
|
|
Utils::writeIncludeFileDirective(QLatin1String("QSharedData"), true, sourceStr);
|
|
|
|
|
|
2009-10-05 11:06:05 +02:00
|
|
|
Utils::writeOpeningNameSpaces(namespaceList, QString(), sourceStr);
|
2009-12-01 16:17:45 +01:00
|
|
|
// Private class:
|
|
|
|
|
if (params.classType == Utils::NewClassWidget::SharedDataClass) {
|
|
|
|
|
sourceStr << '\n' << namespaceIndent << "class " << sharedDataClass
|
|
|
|
|
<< " : public QSharedData {\n"
|
|
|
|
|
<< namespaceIndent << "public:\n"
|
|
|
|
|
<< namespaceIndent << "};\n";
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// Constructor
|
2009-12-01 16:17:45 +01:00
|
|
|
sourceStr << '\n' << namespaceIndent;
|
2009-11-02 15:46:51 +01:00
|
|
|
if (parentQObjectClass.isEmpty()) {
|
2009-12-01 16:17:45 +01:00
|
|
|
sourceStr << unqualifiedClassName << "::" << unqualifiedClassName << "()";
|
|
|
|
|
if (params.classType == Utils::NewClassWidget::SharedDataClass)
|
|
|
|
|
sourceStr << " : data(new " << sharedDataClass << ')';
|
|
|
|
|
sourceStr << '\n';
|
2009-11-02 15:46:51 +01:00
|
|
|
} else {
|
|
|
|
|
sourceStr << unqualifiedClassName << "::" << unqualifiedClassName
|
|
|
|
|
<< '(' << parentQObjectClass << " *parent) :\n"
|
|
|
|
|
<< namespaceIndent << indent << baseClass << "(parent)\n";
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
sourceStr << namespaceIndent << "{\n" << namespaceIndent << "}\n";
|
2009-12-01 16:17:45 +01:00
|
|
|
if (params.classType == Utils::NewClassWidget::SharedDataClass) {
|
|
|
|
|
// Copy
|
|
|
|
|
sourceStr << '\n' << namespaceIndent << unqualifiedClassName << "::" << unqualifiedClassName << "(const "
|
|
|
|
|
<< unqualifiedClassName << " &rhs) : data(rhs.data)\n"
|
|
|
|
|
<< namespaceIndent << "{\n" << namespaceIndent << "}\n\n";
|
|
|
|
|
// Assignment
|
|
|
|
|
sourceStr << namespaceIndent << unqualifiedClassName << " &"
|
|
|
|
|
<< unqualifiedClassName << "::operator=(const " << unqualifiedClassName << " &rhs)\n"
|
|
|
|
|
<< namespaceIndent << "{\n"
|
|
|
|
|
<< namespaceIndent << indent << "if (this != &rhs)\n"
|
|
|
|
|
<< namespaceIndent << indent << indent << "data.operator=(rhs.data);\n"
|
|
|
|
|
<< namespaceIndent << indent << "return *this;\n"
|
|
|
|
|
<< namespaceIndent << "}\n\n";
|
|
|
|
|
// Destructor
|
|
|
|
|
sourceStr << namespaceIndent << unqualifiedClassName << "::~"
|
|
|
|
|
<< unqualifiedClassName << "()\n"
|
|
|
|
|
<< namespaceIndent << "{\n"
|
|
|
|
|
<< namespaceIndent << "}\n";
|
|
|
|
|
}
|
2009-10-05 11:06:05 +02:00
|
|
|
Utils::writeClosingNameSpaces(namespaceList, QString(), sourceStr);
|
2008-12-02 12:01:29 +01:00
|
|
|
return true;
|
|
|
|
|
}
|