summaryrefslogtreecommitdiff
path: root/src/plugins/cppeditor/cppclasswizard.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>2009-11-02 15:46:51 +0100
committerFriedemann Kleint <Friedemann.Kleint@nokia.com>2009-11-02 15:46:51 +0100
commite917392c27a4eacef1aee0b482cec7c6ca17fd5d (patch)
treef4e2efc080999711c09369992ea17277cf1ada41 /src/plugins/cppeditor/cppclasswizard.cpp
parente5b4b65d56d101d3558e2e80cfe1287e486e829e (diff)
downloadqt-creator-e917392c27a4eacef1aee0b482cec7c6ca17fd5d.tar.gz
Class wizard: Replace "inherits QObject" by type information combo.
Remove the setting from where it does not make sense (library/form class wizard, etc). Reviewed-by: con <qtc-committer@nokia.com>
Diffstat (limited to 'src/plugins/cppeditor/cppclasswizard.cpp')
-rw-r--r--src/plugins/cppeditor/cppclasswizard.cpp53
1 files changed, 44 insertions, 9 deletions
diff --git a/src/plugins/cppeditor/cppclasswizard.cpp b/src/plugins/cppeditor/cppclasswizard.cpp
index 02ce50a5e1..199f56573c 100644
--- a/src/plugins/cppeditor/cppclasswizard.cpp
+++ b/src/plugins/cppeditor/cppclasswizard.cpp
@@ -155,7 +155,7 @@ CppClassWizardParameters CppClassWizardDialog::parameters() const
rc.sourceFile = ncw->sourceFileName();
rc.baseClass = ncw->baseClassName();
rc.path = ncw->path();
- rc.inheritsQObject = ncw->inheritsQObject();
+ rc.classType = ncw->classType();
return rc;
}
@@ -217,7 +217,8 @@ bool CppClassWizard::generateHeaderAndSource(const CppClassWizardParameters &par
QString *header, QString *source)
{
// TODO:
- // Quite a bit of this code has been copied from FormClassWizardParameters::generateCpp.
+ // Quite a bit of this code has been copied from FormClassWizardParameters::generateCpp
+ // and is duplicated in the library wizard.
// Maybe more of it could be merged into Utils.
const QString indent = QString(4, QLatin1Char(' '));
@@ -239,10 +240,27 @@ bool CppClassWizard::generateHeaderAndSource(const CppClassWizardParameters &par
const QRegExp qtClassExpr(QLatin1String("^Q[A-Z3].+"));
QTC_ASSERT(qtClassExpr.isValid(), /**/);
- const bool superIsQtClass = qtClassExpr.exactMatch(params.baseClass);
+ // 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);
if (superIsQtClass) {
headerStr << '\n';
- Utils::writeIncludeFileDirective(params.baseClass, true, headerStr);
+ Utils::writeIncludeFileDirective(baseClass, true, headerStr);
}
const QString namespaceIndent = Utils::writeOpeningNameSpaces(namespaceList, QString(), headerStr);
@@ -250,15 +268,24 @@ bool CppClassWizard::generateHeaderAndSource(const CppClassWizardParameters &par
// Class declaration
headerStr << '\n';
headerStr << namespaceIndent << "class " << unqualifiedClassName;
- if (!params.baseClass.isEmpty())
- headerStr << " : public " << params.baseClass << "\n";
+ if (!baseClass.isEmpty())
+ headerStr << " : public " << baseClass << "\n";
else
headerStr << "\n";
headerStr << namespaceIndent << "{\n";
- if (params.inheritsQObject)
+ if (defineQObjectMacro)
headerStr << namespaceIndent << "Q_OBJECT\n";
headerStr << namespaceIndent << "public:\n"
- << namespaceIndent << indent << unqualifiedClassName << "();\n";
+ << namespaceIndent << indent;
+ // Constructor
+ if (parentQObjectClass.isEmpty()) {
+ headerStr << unqualifiedClassName << "();\n";
+ } else {
+ headerStr << "explicit " << unqualifiedClassName << '(' << parentQObjectClass
+ << " *parent = 0);\n";
+ }
+ if (defineQObjectMacro)
+ headerStr << '\n' << namespaceIndent << "signals:\n\n" << namespaceIndent << "public slots:\n\n";
headerStr << namespaceIndent << "};\n";
Utils::writeClosingNameSpaces(namespaceList, QString(), headerStr);
@@ -274,7 +301,15 @@ bool CppClassWizard::generateHeaderAndSource(const CppClassWizardParameters &par
Utils::writeOpeningNameSpaces(namespaceList, QString(), sourceStr);
// Constructor
- sourceStr << '\n' << namespaceIndent << unqualifiedClassName << "::" << unqualifiedClassName << "()\n";
+ sourceStr << '\n' << namespaceIndent ;
+ if (parentQObjectClass.isEmpty()) {
+ sourceStr << unqualifiedClassName << "::" << unqualifiedClassName << "()\n";
+ } else {
+ sourceStr << unqualifiedClassName << "::" << unqualifiedClassName
+ << '(' << parentQObjectClass << " *parent) :\n"
+ << namespaceIndent << indent << baseClass << "(parent)\n";
+ }
+
sourceStr << namespaceIndent << "{\n" << namespaceIndent << "}\n";
Utils::writeClosingNameSpaces(namespaceList, QString(), sourceStr);