Skip to content
Snippets Groups Projects
Commit e917392c authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

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: default avatarcon <qtc-committer@nokia.com>
parent e5b4b65d
No related branches found
No related tags found
No related merge requests found
......@@ -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()
......
......@@ -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);
......
......@@ -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/>
......
......@@ -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);
......
......@@ -74,7 +74,7 @@ struct CppClassWizardParameters
QString sourceFile;
QString baseClass;
QString path;
bool inheritsQObject;
int classType;
};
class CppClassWizardDialog : public QWizard
......
......@@ -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()));
......
......@@ -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
......@@ -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;
......
......@@ -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)
......
......@@ -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)));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment