forked from qt-creator/qt-creator
Add "Inherits QObject" checkbox to Class Wizard.
For now it is dumb, but it can be improved over time.
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -74,6 +74,7 @@ struct CppClassWizardParameters
|
||||
QString sourceFile;
|
||||
QString baseClass;
|
||||
QString path;
|
||||
bool inheritsQObject;
|
||||
};
|
||||
|
||||
class CppClassWizardDialog : public QWizard
|
||||
|
||||
Reference in New Issue
Block a user