forked from qt-creator/qt-creator
JsonWizard: Enable validators for lineedits on Fields pages
Make use of a validator when entering C++ class names. Change-Id: Id7f9c8c2e1fe036397a337595cbe7aa7fd9589d5 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
@@ -46,6 +46,8 @@
|
||||
#include <QFormLayout>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QRegularExpression>
|
||||
#include <QRegularExpressionValidator>
|
||||
#include <QTextEdit>
|
||||
#include <QVariant>
|
||||
#include <QVariantMap>
|
||||
@@ -263,9 +265,14 @@ QWidget *JsonFieldPage::SpacerField::widget(const QString &displayName)
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
JsonFieldPage::LineEditField::LineEditField() :
|
||||
m_isModified(false)
|
||||
m_validatorRegExp(0), m_isModified(false)
|
||||
{ }
|
||||
|
||||
JsonFieldPage::LineEditField::~LineEditField()
|
||||
{
|
||||
delete m_validatorRegExp;
|
||||
}
|
||||
|
||||
bool JsonFieldPage::LineEditField::parseData(const QVariant &data, QString *errorMessage)
|
||||
{
|
||||
if (data.isNull())
|
||||
@@ -282,6 +289,18 @@ bool JsonFieldPage::LineEditField::parseData(const QVariant &data, QString *erro
|
||||
m_defaultText = JsonWizardFactory::localizedString(tmp.value(QLatin1String("trText")).toString());
|
||||
m_disabledText = JsonWizardFactory::localizedString(tmp.value(QLatin1String("trDisabledText")).toString());
|
||||
m_placeholderText = JsonWizardFactory::localizedString(tmp.value(QLatin1String("trPlaceholder")).toString());
|
||||
QString pattern = tmp.value(QLatin1String("validator")).toString();
|
||||
if (!pattern.isEmpty()) {
|
||||
m_validatorRegExp = new QRegularExpression(pattern);
|
||||
if (!m_validatorRegExp->isValid()) {
|
||||
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
||||
"Invalid regular expression \"%1\" in \"validator\".")
|
||||
.arg(pattern);
|
||||
delete m_validatorRegExp;
|
||||
m_validatorRegExp = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -293,6 +312,9 @@ QWidget *JsonFieldPage::LineEditField::widget(const QString &displayName)
|
||||
QLineEdit *w = new QLineEdit;
|
||||
connect(w, &QLineEdit::textEdited, [this](){ m_isModified = true; });
|
||||
|
||||
if (m_validatorRegExp)
|
||||
w->setValidator(new QRegularExpressionValidator(*m_validatorRegExp, w));
|
||||
|
||||
m_widget = w;
|
||||
return m_widget;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user