diff --git a/src/libs/utils/newclasswidget.cpp b/src/libs/utils/newclasswidget.cpp index 42265a062e1cfb4fc51c49486ab2310f44e16546..b3378281a9d7ae6d83aea33dd4af01aac2856a78 100644 --- a/src/libs/utils/newclasswidget.cpp +++ b/src/libs/utils/newclasswidget.cpp @@ -57,6 +57,7 @@ struct NewClassWidgetPrivate { bool m_baseClassInputVisible; bool m_formInputVisible; bool m_pathInputVisible; + bool m_qobjectCheckBoxVisible; bool m_formInputCheckable; }; @@ -69,7 +70,9 @@ NewClassWidgetPrivate:: NewClassWidgetPrivate() : m_baseClassInputVisible(true), m_formInputVisible(true), m_pathInputVisible(true), + m_qobjectCheckBoxVisible(false), m_formInputCheckable(false) + { } @@ -169,6 +172,17 @@ void NewClassWidget::setBaseClassInputVisible(bool visible) m_d->m_ui.baseClassComboBox->setVisible(visible); } +void NewClassWidget::setQObjectCheckBoxVisible(bool visible) +{ + m_d->m_qobjectCheckBoxVisible = visible; + m_d->m_ui.qobjectCheckBox->setVisible(visible); +} + +bool NewClassWidget::isQObjectCheckBoxVisible() const +{ + return m_d->m_qobjectCheckBoxVisible; +} + void NewClassWidget::setBaseClassEditable(bool editable) { m_d->m_ui.baseClassComboBox->setEditable(editable); @@ -356,6 +370,16 @@ void NewClassWidget::setAllowDirectories(bool v) } } +bool NewClassWidget::inheritsQObject() const +{ + return m_d->m_ui.qobjectCheckBox->isChecked(); +} + +void NewClassWidget::setInheritsQObject(bool v) +{ + m_d->m_ui.qobjectCheckBox->setChecked(v); +} + bool NewClassWidget::lowerCaseFiles() const { return m_d->m_ui.classLineEdit->lowerCaseFileName(); diff --git a/src/libs/utils/newclasswidget.h b/src/libs/utils/newclasswidget.h index 52d03720a8eb487014f056d47d60d4da7f28f6d2..1a43877761c50439aa4d28c95b7acaec32d64337 100644 --- a/src/libs/utils/newclasswidget.h +++ b/src/libs/utils/newclasswidget.h @@ -57,6 +57,7 @@ class QTCREATOR_UTILS_EXPORT NewClassWidget : public QWidget Q_PROPERTY(bool baseClassEditable READ isBaseClassEditable WRITE setBaseClassEditable DESIGNABLE false) Q_PROPERTY(bool formInputVisible READ isFormInputVisible WRITE setFormInputVisible DESIGNABLE true) Q_PROPERTY(bool pathInputVisible READ isPathInputVisible WRITE setPathInputVisible DESIGNABLE true) + Q_PROPERTY(bool qobjectCheckBoxVisible READ isQObjectCheckBoxVisible WRITE setQObjectCheckBoxVisible DESIGNABLE true) Q_PROPERTY(QString className READ className WRITE setClassName DESIGNABLE true) Q_PROPERTY(QString baseClassName READ baseClassName WRITE setBaseClassName DESIGNABLE true) Q_PROPERTY(QString sourceFileName READ sourceFileName DESIGNABLE false) @@ -70,6 +71,7 @@ class QTCREATOR_UTILS_EXPORT NewClassWidget : public QWidget Q_PROPERTY(bool formInputCheckable READ formInputCheckable WRITE setFormInputCheckable DESIGNABLE true) Q_PROPERTY(bool formInputChecked READ formInputChecked WRITE setFormInputChecked DESIGNABLE true) Q_PROPERTY(bool allowDirectories READ allowDirectories WRITE setAllowDirectories) + Q_PROPERTY(bool inheritsQObject READ inheritsQObject WRITE setInheritsQObject) Q_PROPERTY(bool lowerCaseFiles READ lowerCaseFiles WRITE setLowerCaseFiles) // Utility "USER" property for wizards containing file names. Q_PROPERTY(QStringList files READ files DESIGNABLE false USER true) @@ -82,6 +84,7 @@ public: bool isBaseClassEditable() const; bool isFormInputVisible() const; bool isPathInputVisible() const; + bool isQObjectCheckBoxVisible() const; bool formInputCheckable() const; bool formInputChecked() const; @@ -95,6 +98,7 @@ public: QString sourceExtension() const; QString headerExtension() const; QString formExtension() const; + bool inheritsQObject() const; bool allowDirectories() const; bool lowerCaseFiles() const; @@ -114,6 +118,7 @@ public slots: void setPathInputVisible(bool visible); void setFormInputCheckable(bool v); void setFormInputChecked(bool v); + void setQObjectCheckBoxVisible(bool v); /** * The name passed into the new class widget will be reformatted to be a @@ -126,6 +131,7 @@ public slots: void setSourceExtension(const QString &e); void setHeaderExtension(const QString &e); void setFormExtension(const QString &e); + void setInheritsQObject(bool v); void setAllowDirectories(bool v); void setLowerCaseFiles(bool v); diff --git a/src/libs/utils/newclasswidget.ui b/src/libs/utils/newclasswidget.ui index 76a093a76fb37673085abae10cfd0c8b50dfed3c..bb2e465cc011c908cef6bf925366ccceac058b5d 100644 --- a/src/libs/utils/newclasswidget.ui +++ b/src/libs/utils/newclasswidget.ui @@ -2,6 +2,14 @@ <ui version="4.0"> <class>Utils::NewClassWidget</class> <widget class="QWidget" name="Utils::NewClassWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>213</width> + <height>190</height> + </rect> + </property> <layout class="QFormLayout" name="formLayout"> <property name="fieldGrowthPolicy"> <enum>QFormLayout::ExpandingFieldsGrow</enum> @@ -36,7 +44,7 @@ </property> </widget> </item> - <item row="2" column="0"> + <item row="3" column="0"> <spacer name="verticalSpacer"> <property name="orientation"> <enum>Qt::Vertical</enum> @@ -52,7 +60,7 @@ </property> </spacer> </item> - <item row="2" column="1"> + <item row="3" column="1"> <spacer name="verticalSpacer_2"> <property name="orientation"> <enum>Qt::Vertical</enum> @@ -68,60 +76,67 @@ </property> </spacer> </item> - <item row="3" column="0"> + <item row="4" column="0"> <widget class="QLabel" name="headerLabel"> <property name="text"> <string>Header file:</string> </property> </widget> </item> - <item row="3" column="1"> + <item row="4" column="1"> <widget class="Utils::FileNameValidatingLineEdit" name="headerFileLineEdit"/> </item> - <item row="4" column="0"> + <item row="5" column="0"> <widget class="QLabel" name="sourceLabel"> <property name="text"> <string>Source file:</string> </property> </widget> </item> - <item row="4" column="1"> + <item row="5" column="1"> <widget class="Utils::FileNameValidatingLineEdit" name="sourceFileLineEdit"/> </item> - <item row="5" column="0"> + <item row="6" column="0"> <widget class="QLabel" name="generateFormLabel"> <property name="text"> <string>Generate form:</string> </property> </widget> </item> - <item row="6" column="0"> + <item row="7" column="0"> <widget class="QLabel" name="formLabel"> <property name="text"> <string>Form file:</string> </property> </widget> </item> - <item row="6" column="1"> + <item row="7" column="1"> <widget class="Utils::FileNameValidatingLineEdit" name="formFileLineEdit"/> </item> - <item row="7" column="0"> + <item row="8" column="0"> <widget class="QLabel" name="pathLabel"> <property name="text"> <string>Path:</string> </property> </widget> </item> - <item row="7" column="1"> + <item row="8" column="1"> <widget class="Utils::PathChooser" name="pathChooser" native="true"/> </item> - <item row="5" column="1"> + <item row="6" column="1"> <widget class="QCheckBox" name="generateFormCheckBox"> <property name="text"> <string/> </property> </widget> </item> + <item row="2" column="1"> + <widget class="QCheckBox" name="qobjectCheckBox"> + <property name="text"> + <string>Inherits QObject</string> + </property> + </widget> + </item> </layout> </widget> <customwidgets> diff --git a/src/plugins/cppeditor/cppclasswizard.cpp b/src/plugins/cppeditor/cppclasswizard.cpp index 1c994c6ebcb9a58a17a5d2097a6ee25079ddeeb8..02ce50a5e1fd98d58a81aa15b19b8ec5e1628211 100644 --- a/src/plugins/cppeditor/cppclasswizard.cpp +++ b/src/plugins/cppeditor/cppclasswizard.cpp @@ -74,6 +74,7 @@ ClassNamePage::ClassNamePage(QWidget *parent) : m_newClassWidget->setFormInputVisible(false); m_newClassWidget->setNamespacesEnabled(true); m_newClassWidget->setAllowDirectories(true); + m_newClassWidget->setBaseClassInputVisible(true); connect(m_newClassWidget, SIGNAL(validChanged()), this, SLOT(slotValidChanged())); @@ -154,6 +155,7 @@ CppClassWizardParameters CppClassWizardDialog::parameters() const rc.sourceFile = ncw->sourceFileName(); rc.baseClass = ncw->baseClassName(); rc.path = ncw->path(); + rc.inheritsQObject = ncw->inheritsQObject(); return rc; } @@ -253,6 +255,8 @@ bool CppClassWizard::generateHeaderAndSource(const CppClassWizardParameters &par else headerStr << "\n"; headerStr << namespaceIndent << "{\n"; + if (params.inheritsQObject) + headerStr << namespaceIndent << "Q_OBJECT\n"; headerStr << namespaceIndent << "public:\n" << namespaceIndent << indent << unqualifiedClassName << "();\n"; headerStr << namespaceIndent << "};\n"; diff --git a/src/plugins/cppeditor/cppclasswizard.h b/src/plugins/cppeditor/cppclasswizard.h index 1bc26d1b56f942a8ab08d7a871294c2257c89bfa..0d2f2ae11fafcb00820a96ce8f09e04f8742f830 100644 --- a/src/plugins/cppeditor/cppclasswizard.h +++ b/src/plugins/cppeditor/cppclasswizard.h @@ -74,6 +74,7 @@ struct CppClassWizardParameters QString sourceFile; QString baseClass; QString path; + bool inheritsQObject; }; class CppClassWizardDialog : public QWizard