m_d->m_ui.generateFormCheckBox->setChecked(true);
setFormInputCheckable(false, true);
+ setClassType(NoClassType);
}
NewClassWidget::~NewClassWidget()
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);
}
}
-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()
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)
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();
bool isBaseClassEditable() const;
bool isFormInputVisible() const;
bool isPathInputVisible() const;
- bool isQObjectCheckBoxVisible() const;
bool formInputCheckable() const;
bool formInputChecked() const;
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;
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
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'
void classNameEdited();
void slotFormInputChecked();
-
private:
void setFormInputCheckable(bool checkable, bool force);
<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">
</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">
</property>
<property name="sizeHint" stdset="0">
<size>
- <width>20</width>
- <height>20</height>
+ <width>0</width>
+ <height>0</height>
</size>
</property>
</spacer>
</property>
<property name="sizeHint" stdset="0">
<size>
- <width>20</width>
- <height>20</height>
+ <width>0</width>
+ <height>0</height>
</size>
</property>
</spacer>
</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">
</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/>
rc.sourceFile = ncw->sourceFileName();
rc.baseClass = ncw->baseClassName();
rc.path = ncw->path();
- rc.inheritsQObject = ncw->inheritsQObject();
+ rc.classType = ncw->classType();
return rc;
}
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(' '));
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);
// 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);
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);
QString sourceFile;
QString baseClass;
QString path;
- bool inheritsQObject;
+ int classType;
};
class CppClassWizardDialog : public QWizard
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()));
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
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());
void setFormInputCheckable(bool checkable);
void setFormInputChecked(bool checked);
void setLowerCaseFiles(bool l);
+ void setClassTypeComboVisible(bool v);
private:
Utils::NewClassWidget *m_newClassWidget;
setPage(ModulesPageId, m_modulesPage);
m_filesPage->setFormInputCheckable(true);
+ m_filesPage->setClassTypeComboVisible(false);
setPage(FilesPageId, m_filesPage);
foreach (QWizardPage *p, extensionPages)
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)));