diff options
author | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2009-11-02 15:46:51 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2009-11-02 15:46:51 +0100 |
commit | e917392c27a4eacef1aee0b482cec7c6ca17fd5d (patch) | |
tree | f4e2efc080999711c09369992ea17277cf1ada41 | |
parent | e5b4b65d56d101d3558e2e80cfe1287e486e829e (diff) | |
download | qt-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>
-rw-r--r-- | src/libs/utils/newclasswidget.cpp | 39 | ||||
-rw-r--r-- | src/libs/utils/newclasswidget.h | 16 | ||||
-rw-r--r-- | src/libs/utils/newclasswidget.ui | 75 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppclasswizard.cpp | 53 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppclasswizard.h | 2 | ||||
-rw-r--r-- | src/plugins/designer/cpp/formclasswizardpage.cpp | 1 | ||||
-rw-r--r-- | src/plugins/qt4projectmanager/wizards/filespage.cpp | 10 | ||||
-rw-r--r-- | src/plugins/qt4projectmanager/wizards/filespage.h | 4 | ||||
-rw-r--r-- | src/plugins/qt4projectmanager/wizards/guiappwizarddialog.cpp | 1 | ||||
-rw-r--r-- | src/plugins/qt4projectmanager/wizards/librarywizarddialog.cpp | 1 |
10 files changed, 137 insertions, 65 deletions
diff --git a/src/libs/utils/newclasswidget.cpp b/src/libs/utils/newclasswidget.cpp index b3378281a9..0d1168fd9c 100644 --- a/src/libs/utils/newclasswidget.cpp +++ b/src/libs/utils/newclasswidget.cpp @@ -122,6 +122,7 @@ NewClassWidget::NewClassWidget(QWidget *parent) : m_d->m_ui.generateFormCheckBox->setChecked(true); setFormInputCheckable(false, true); + setClassType(NoClassType); } NewClassWidget::~NewClassWidget() @@ -172,17 +173,6 @@ 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); @@ -370,24 +360,35 @@ void NewClassWidget::setAllowDirectories(bool v) } } -bool NewClassWidget::inheritsQObject() const +bool NewClassWidget::lowerCaseFiles() const +{ + return m_d->m_ui.classLineEdit->lowerCaseFileName(); +} + +void NewClassWidget::setLowerCaseFiles(bool v) { - return m_d->m_ui.qobjectCheckBox->isChecked(); + m_d->m_ui.classLineEdit->setLowerCaseFileName(v); } -void NewClassWidget::setInheritsQObject(bool v) +NewClassWidget::ClassType NewClassWidget::classType() const { - m_d->m_ui.qobjectCheckBox->setChecked(v); + return static_cast<ClassType>(m_d->m_ui.classTypeComboBox->currentIndex()); } -bool NewClassWidget::lowerCaseFiles() const +void NewClassWidget::setClassType(ClassType ct) { - return m_d->m_ui.classLineEdit->lowerCaseFileName(); + m_d->m_ui.classTypeComboBox->setCurrentIndex(ct); } -void NewClassWidget::setLowerCaseFiles(bool v) +bool NewClassWidget::isClassTypeComboVisible() const { - m_d->m_ui.classLineEdit->setLowerCaseFileName(v); + return m_d->m_ui.classTypeLabel->isVisible(); +} + +void NewClassWidget::setClassTypeComboVisible(bool v) +{ + m_d->m_ui.classTypeLabel->setVisible(v); + m_d->m_ui.classTypeComboBox->setVisible(v); } void NewClassWidget::slotValidChanged() diff --git a/src/libs/utils/newclasswidget.h b/src/libs/utils/newclasswidget.h index 1a43877761..c8923a3a3e 100644 --- a/src/libs/utils/newclasswidget.h +++ b/src/libs/utils/newclasswidget.h @@ -57,7 +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(bool classTypeComboVisible READ isClassTypeComboVisible WRITE setClassTypeComboVisible 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) @@ -71,11 +71,14 @@ 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) + Q_PROPERTY(ClassType classType READ classType WRITE setClassType) // Utility "USER" property for wizards containing file names. Q_PROPERTY(QStringList files READ files DESIGNABLE false USER true) + Q_ENUMS(ClassType) public: + enum ClassType { NoClassType, ClassInheritsQObject, ClassInheritsQWidget }; + explicit NewClassWidget(QWidget *parent = 0); ~NewClassWidget(); @@ -84,7 +87,6 @@ public: bool isBaseClassEditable() const; bool isFormInputVisible() const; bool isPathInputVisible() const; - bool isQObjectCheckBoxVisible() const; bool formInputCheckable() const; bool formInputChecked() const; @@ -98,9 +100,10 @@ public: QString sourceExtension() const; QString headerExtension() const; QString formExtension() const; - bool inheritsQObject() const; bool allowDirectories() const; bool lowerCaseFiles() const; + ClassType classType() const; + bool isClassTypeComboVisible() const; bool isValid(QString *error = 0) const; @@ -118,7 +121,6 @@ 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 @@ -131,9 +133,10 @@ 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); + void setClassType(ClassType ct); + void setClassTypeComboVisible(bool v); /** * Suggest a class name from the base class by stripping the leading 'Q' @@ -153,7 +156,6 @@ private slots: void classNameEdited(); void slotFormInputChecked(); - private: void setFormInputCheckable(bool checkable, bool force); diff --git a/src/libs/utils/newclasswidget.ui b/src/libs/utils/newclasswidget.ui index bb2e465cc0..2e725644bc 100644 --- a/src/libs/utils/newclasswidget.ui +++ b/src/libs/utils/newclasswidget.ui @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>213</width> - <height>190</height> + <width>418</width> + <height>291</height> </rect> </property> <layout class="QFormLayout" name="formLayout"> @@ -44,6 +44,32 @@ </property> </widget> </item> + <item row="2" column="0"> + <widget class="QLabel" name="classTypeLabel"> + <property name="text"> + <string>Type information:</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QComboBox" name="classTypeComboBox"> + <item> + <property name="text"> + <string>None</string> + </property> + </item> + <item> + <property name="text"> + <string>Inherits QObject</string> + </property> + </item> + <item> + <property name="text"> + <string>Inherits QWidget</string> + </property> + </item> + </widget> + </item> <item row="3" column="0"> <spacer name="verticalSpacer"> <property name="orientation"> @@ -54,8 +80,8 @@ </property> <property name="sizeHint" stdset="0"> <size> - <width>20</width> - <height>20</height> + <width>0</width> + <height>0</height> </size> </property> </spacer> @@ -70,8 +96,8 @@ </property> <property name="sizeHint" stdset="0"> <size> - <width>20</width> - <height>20</height> + <width>0</width> + <height>0</height> </size> </property> </spacer> @@ -103,6 +129,13 @@ </property> </widget> </item> + <item row="6" column="1"> + <widget class="QCheckBox" name="generateFormCheckBox"> + <property name="text"> + <string/> + </property> + </widget> + </item> <item row="7" column="0"> <widget class="QLabel" name="formLabel"> <property name="text"> @@ -121,41 +154,27 @@ </widget> </item> <item row="8" column="1"> - <widget class="Utils::PathChooser" name="pathChooser" native="true"/> - </item> - <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> + <widget class="Utils::PathChooser" name="pathChooser"/> </item> </layout> </widget> <customwidgets> <customwidget> - <class>Utils::PathChooser</class> - <extends>QWidget</extends> - <header location="global">pathchooser.h</header> - <container>1</container> - </customwidget> - <customwidget> <class>Utils::ClassNameValidatingLineEdit</class> <extends>QLineEdit</extends> - <header>classnamevalidatinglineedit.h</header> + <header location="global">utils/classnamevalidatinglineedit.h</header> </customwidget> <customwidget> <class>Utils::FileNameValidatingLineEdit</class> <extends>QLineEdit</extends> <header location="global">utils/filenamevalidatinglineedit.h</header> </customwidget> + <customwidget> + <class>Utils::PathChooser</class> + <extends>QWidget</extends> + <header location="global">utils/pathchooser.h</header> + <container>1</container> + </customwidget> </customwidgets> <resources/> <connections/> 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); diff --git a/src/plugins/cppeditor/cppclasswizard.h b/src/plugins/cppeditor/cppclasswizard.h index 0d2f2ae11f..89d364ace4 100644 --- a/src/plugins/cppeditor/cppclasswizard.h +++ b/src/plugins/cppeditor/cppclasswizard.h @@ -74,7 +74,7 @@ struct CppClassWizardParameters QString sourceFile; QString baseClass; QString path; - bool inheritsQObject; + int classType; }; class CppClassWizardDialog : public QWizard diff --git a/src/plugins/designer/cpp/formclasswizardpage.cpp b/src/plugins/designer/cpp/formclasswizardpage.cpp index 7b7f1336ab..2335f6d0e4 100644 --- a/src/plugins/designer/cpp/formclasswizardpage.cpp +++ b/src/plugins/designer/cpp/formclasswizardpage.cpp @@ -57,6 +57,7 @@ FormClassWizardPage::FormClassWizardPage(QWidget * parent) : m_ui->newClassWidget->setBaseClassInputVisible(false); m_ui->newClassWidget->setNamespacesEnabled(true); m_ui->newClassWidget->setAllowDirectories(true); + m_ui->newClassWidget->setClassTypeComboVisible(false); connect(m_ui->newClassWidget, SIGNAL(validChanged()), this, SLOT(slotValidChanged())); connect(m_ui->settingsToolButton, SIGNAL(clicked()), this, SLOT(slotSettings())); diff --git a/src/plugins/qt4projectmanager/wizards/filespage.cpp b/src/plugins/qt4projectmanager/wizards/filespage.cpp index 6346a409a6..e74a41e335 100644 --- a/src/plugins/qt4projectmanager/wizards/filespage.cpp +++ b/src/plugins/qt4projectmanager/wizards/filespage.cpp @@ -185,5 +185,15 @@ void FilesPage::setLowerCaseFiles(bool l) m_newClassWidget->setLowerCaseFiles(l); } +bool FilesPage::isClassTypeComboVisible() const +{ + return m_newClassWidget->isClassTypeComboVisible(); +} + +void FilesPage::setClassTypeComboVisible(bool v) +{ + m_newClassWidget->setClassTypeComboVisible(v); +} + } // namespace Internal } // namespace Qt4ProjectManager diff --git a/src/plugins/qt4projectmanager/wizards/filespage.h b/src/plugins/qt4projectmanager/wizards/filespage.h index f20e6ce8ab..a12aa88e3c 100644 --- a/src/plugins/qt4projectmanager/wizards/filespage.h +++ b/src/plugins/qt4projectmanager/wizards/filespage.h @@ -66,7 +66,8 @@ public: bool formInputCheckable() const; bool formInputChecked() const; QStringList baseClassChoices() const; - bool lowerCaseFiles() const; + bool lowerCaseFiles() const; + bool isClassTypeComboVisible() const; void setSuffixes(const QString &header, const QString &source, const QString &form = QString()); @@ -79,6 +80,7 @@ public slots: void setFormInputCheckable(bool checkable); void setFormInputChecked(bool checked); void setLowerCaseFiles(bool l); + void setClassTypeComboVisible(bool v); private: Utils::NewClassWidget *m_newClassWidget; diff --git a/src/plugins/qt4projectmanager/wizards/guiappwizarddialog.cpp b/src/plugins/qt4projectmanager/wizards/guiappwizarddialog.cpp index 1ba1edf7da..ab54738fc9 100644 --- a/src/plugins/qt4projectmanager/wizards/guiappwizarddialog.cpp +++ b/src/plugins/qt4projectmanager/wizards/guiappwizarddialog.cpp @@ -74,6 +74,7 @@ GuiAppWizardDialog::GuiAppWizardDialog(const QString &templateName, setPage(ModulesPageId, m_modulesPage); m_filesPage->setFormInputCheckable(true); + m_filesPage->setClassTypeComboVisible(false); setPage(FilesPageId, m_filesPage); foreach (QWizardPage *p, extensionPages) diff --git a/src/plugins/qt4projectmanager/wizards/librarywizarddialog.cpp b/src/plugins/qt4projectmanager/wizards/librarywizarddialog.cpp index 4515954d51..d378de0eaa 100644 --- a/src/plugins/qt4projectmanager/wizards/librarywizarddialog.cpp +++ b/src/plugins/qt4projectmanager/wizards/librarywizarddialog.cpp @@ -169,6 +169,7 @@ LibraryWizardDialog::LibraryWizardDialog(const QString &templateName, m_filesPage->setNamespacesEnabled(true); m_filesPage->setFormFileInputVisible(false); + m_filesPage->setClassTypeComboVisible(false); setPage(FilePageId, m_filesPage); connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(slotCurrentIdChanged(int))); |