Commit 948d8d7b authored by Sergey Shambir's avatar Sergey Shambir

Utils: made NewClassWidget more extensible

1) Customizable namespaces delimiter

2) Header file and Source file inputs can be invisible

Changes required to use NewClassWidget for python class wizard, but also
can be used for C++ interface or template class wizards.

Old (abandonned) change is here:

https://codereview.qt-project.org/#change,29869

Change-Id: I980706963e60c3bd8e5863cc5682b97e1336bdba
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent 7043a7e0
......@@ -151,9 +151,9 @@ QString ClassNameValidatingLineEdit::fixInputString(const QString &string)
void ClassNameValidatingLineEdit::updateRegExp() const
{
QString identifierPatter(QLatin1String("[a-zA-Z_][a-zA-Z0-9_]*"));
QString pattern(QLatin1String("%1(%2%1)*"));
d->m_nameRegexp.setPattern(pattern.arg(identifierPatter).arg(d->m_namespaceDelimiter));
const QString pattern(QLatin1String("%1(%2%1)*"));
d->m_nameRegexp.setPattern(pattern.arg(QLatin1String("[a-zA-Z_][a-zA-Z0-9_]*"))
.arg(QRegExp::escape(d->m_namespaceDelimiter)));
}
QString ClassNameValidatingLineEdit::createClassName(const QString &name)
......
......@@ -61,9 +61,12 @@ struct NewClassWidgetPrivate {
// fooled by a temporarily hidden widget
bool m_baseClassInputVisible;
bool m_formInputVisible;
bool m_headerInputVisible;
bool m_sourceInputVisible;
bool m_pathInputVisible;
bool m_qobjectCheckBoxVisible;
bool m_formInputCheckable;
QRegExp m_classNameValidator;
};
NewClassWidgetPrivate:: NewClassWidgetPrivate() :
......@@ -74,6 +77,8 @@ NewClassWidgetPrivate:: NewClassWidgetPrivate() :
m_classEdited(false),
m_baseClassInputVisible(true),
m_formInputVisible(true),
m_headerInputVisible(true),
m_sourceInputVisible(true),
m_pathInputVisible(true),
m_qobjectCheckBoxVisible(false),
m_formInputCheckable(false)
......@@ -90,6 +95,8 @@ NewClassWidget::NewClassWidget(QWidget *parent) :
d->m_ui.baseClassComboBox->setEditable(false);
setNamesDelimiter(QLatin1String("::"));
connect(d->m_ui.classLineEdit, SIGNAL(updateFileName(QString)),
this, SLOT(slotUpdateFileNames(QString)));
connect(d->m_ui.classLineEdit, SIGNAL(textEdited(QString)),
......@@ -208,6 +215,30 @@ bool NewClassWidget::isFormInputVisible() const
return d->m_formInputVisible;
}
void NewClassWidget::setHeaderInputVisible(bool visible)
{
d->m_headerInputVisible = visible;
d->m_ui.headerLabel->setVisible(visible);
d->m_ui.headerFileLineEdit->setVisible(visible);
}
bool NewClassWidget::isHeaderInputVisible() const
{
return d->m_headerInputVisible;
}
void NewClassWidget::setSourceInputVisible(bool visible)
{
d->m_sourceInputVisible = visible;
d->m_ui.sourceLabel->setVisible(visible);
d->m_ui.sourceFileLineEdit->setVisible(visible);
}
bool NewClassWidget::isSourceInputVisible() const
{
return d->m_sourceInputVisible;
}
void NewClassWidget::setFormInputCheckable(bool checkable)
{
setFormInputCheckable(checkable, false);
......@@ -383,11 +414,25 @@ NewClassWidget::ClassType NewClassWidget::classType() const
return static_cast<ClassType>(d->m_ui.classTypeComboBox->currentIndex());
}
QString NewClassWidget::namesDelimiter() const
{
return d->m_ui.classLineEdit->namespaceDelimiter();
}
void NewClassWidget::setClassType(ClassType ct)
{
d->m_ui.classTypeComboBox->setCurrentIndex(ct);
}
void NewClassWidget::setNamesDelimiter(const QString &delimiter)
{
d->m_ui.classLineEdit->setNamespaceDelimiter(delimiter);
const QString escaped = QRegExp::escape(delimiter);
d->m_classNameValidator = QRegExp(QLatin1String("[a-zA-Z_][a-zA-Z0-9_]*(")
+ escaped
+ QLatin1String("[a-zA-Z_][a-zA-Z0-9_]*)*"));
}
bool NewClassWidget::isClassTypeComboVisible() const
{
return d->m_ui.classTypeLabel->isVisible();
......@@ -447,23 +492,21 @@ bool NewClassWidget::isValid(QString *error) const
}
if (isBaseClassInputVisible() && isBaseClassEditable()) {
// TODO: Should this be a ClassNameValidatingComboBox?
QRegExp classNameValidator(QLatin1String("[a-zA-Z_][a-zA-Z0-9_]*(::[a-zA-Z_][a-zA-Z0-9_]*)*"));
const QString baseClass = d->m_ui.baseClassComboBox->currentText().trimmed();
if (!baseClass.isEmpty() && !classNameValidator.exactMatch(baseClass)) {
if (!baseClass.isEmpty() && !d->m_classNameValidator.exactMatch(baseClass)) {
if (error)
*error = tr("Invalid base class name");
return false;
}
}
if (!d->m_ui.headerFileLineEdit->isValid()) {
if (isHeaderInputVisible() && !d->m_ui.headerFileLineEdit->isValid()) {
if (error)
*error = tr("Invalid header file name: '%1'").arg(d->m_ui.headerFileLineEdit->errorMessage());
return false;
}
if (!d->m_ui.sourceFileLineEdit->isValid()) {
if (isSourceInputVisible() && !d->m_ui.sourceFileLineEdit->isValid()) {
if (error)
*error = tr("Invalid source file name: '%1'").arg(d->m_ui.sourceFileLineEdit->errorMessage());
return false;
......@@ -540,8 +583,10 @@ QStringList NewClassWidget::files() const
{
QStringList rc;
const QDir dir = QDir(path());
rc.push_back(expandFileName(dir, headerFileName(), headerExtension()));
rc.push_back(expandFileName(dir, sourceFileName(), sourceExtension()));
if (isHeaderInputVisible())
rc.push_back(expandFileName(dir, headerFileName(), headerExtension()));
if (isSourceInputVisible())
rc.push_back(expandFileName(dir, sourceFileName(), sourceExtension()));
if (isFormInputVisible())
rc.push_back(expandFileName(dir, formFileName(), formExtension()));
return rc;
......
......@@ -49,6 +49,8 @@ class QTCREATOR_UTILS_EXPORT NewClassWidget : public QWidget
Q_PROPERTY(bool baseClassInputVisible READ isBaseClassInputVisible WRITE setBaseClassInputVisible DESIGNABLE true)
Q_PROPERTY(bool baseClassEditable READ isBaseClassEditable WRITE setBaseClassEditable DESIGNABLE false)
Q_PROPERTY(bool formInputVisible READ isFormInputVisible WRITE setFormInputVisible DESIGNABLE true)
Q_PROPERTY(bool headerInputVisible READ isHeaderInputVisible WRITE setHeaderInputVisible DESIGNABLE true)
Q_PROPERTY(bool sourceInputVisible READ isSourceInputVisible WRITE setSourceInputVisible DESIGNABLE true)
Q_PROPERTY(bool pathInputVisible READ isPathInputVisible WRITE setPathInputVisible DESIGNABLE true)
Q_PROPERTY(bool classTypeComboVisible READ isClassTypeComboVisible WRITE setClassTypeComboVisible DESIGNABLE true)
Q_PROPERTY(QString className READ className WRITE setClassName DESIGNABLE true)
......@@ -61,6 +63,7 @@ class QTCREATOR_UTILS_EXPORT NewClassWidget : public QWidget
Q_PROPERTY(QString sourceExtension READ sourceExtension WRITE setSourceExtension DESIGNABLE true)
Q_PROPERTY(QString headerExtension READ headerExtension WRITE setHeaderExtension DESIGNABLE true)
Q_PROPERTY(QString formExtension READ formExtension WRITE setFormExtension DESIGNABLE true)
Q_PROPERTY(QString namesDelimiter READ namesDelimiter WRITE setNamesDelimiter)
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)
......@@ -86,6 +89,8 @@ public:
bool isBaseClassInputVisible() const;
bool isBaseClassEditable() const;
bool isFormInputVisible() const;
bool isHeaderInputVisible() const;
bool isSourceInputVisible() const;
bool isPathInputVisible() const;
bool formInputCheckable() const;
bool formInputChecked() const;
......@@ -103,6 +108,7 @@ public:
bool allowDirectories() const;
bool lowerCaseFiles() const;
ClassType classType() const;
QString namesDelimiter() const;
bool isClassTypeComboVisible() const;
bool isValid(QString *error = 0) const;
......@@ -118,6 +124,8 @@ public slots:
void setBaseClassInputVisible(bool visible);
void setBaseClassEditable(bool editable);
void setFormInputVisible(bool visible);
void setHeaderInputVisible(bool visible);
void setSourceInputVisible(bool visible);
void setPathInputVisible(bool visible);
void setFormInputCheckable(bool v);
void setFormInputChecked(bool v);
......@@ -136,6 +144,7 @@ public slots:
void setAllowDirectories(bool v);
void setLowerCaseFiles(bool v);
void setClassType(ClassType ct);
void setNamesDelimiter(const QString &delimiter);
void setClassTypeComboVisible(bool v);
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment