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:
@@ -33,7 +33,8 @@
|
|||||||
"name": "Class",
|
"name": "Class",
|
||||||
"trDisplayName": "Class name:",
|
"trDisplayName": "Class name:",
|
||||||
"mandatory": true,
|
"mandatory": true,
|
||||||
"type": "LineEdit"
|
"type": "LineEdit",
|
||||||
|
"data": { "validator": "(?:(?:[a-zA-Z_][a-zA-Z_0-9]*::)+[a-zA-Z_][a-zA-Z_0-9]*|)" }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "BaseCB",
|
"name": "BaseCB",
|
||||||
|
|||||||
@@ -46,6 +46,8 @@
|
|||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
#include <QRegularExpressionValidator>
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QVariantMap>
|
#include <QVariantMap>
|
||||||
@@ -263,9 +265,14 @@ QWidget *JsonFieldPage::SpacerField::widget(const QString &displayName)
|
|||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
|
||||||
JsonFieldPage::LineEditField::LineEditField() :
|
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)
|
bool JsonFieldPage::LineEditField::parseData(const QVariant &data, QString *errorMessage)
|
||||||
{
|
{
|
||||||
if (data.isNull())
|
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_defaultText = JsonWizardFactory::localizedString(tmp.value(QLatin1String("trText")).toString());
|
||||||
m_disabledText = JsonWizardFactory::localizedString(tmp.value(QLatin1String("trDisabledText")).toString());
|
m_disabledText = JsonWizardFactory::localizedString(tmp.value(QLatin1String("trDisabledText")).toString());
|
||||||
m_placeholderText = JsonWizardFactory::localizedString(tmp.value(QLatin1String("trPlaceholder")).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;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -293,6 +312,9 @@ QWidget *JsonFieldPage::LineEditField::widget(const QString &displayName)
|
|||||||
QLineEdit *w = new QLineEdit;
|
QLineEdit *w = new QLineEdit;
|
||||||
connect(w, &QLineEdit::textEdited, [this](){ m_isModified = true; });
|
connect(w, &QLineEdit::textEdited, [this](){ m_isModified = true; });
|
||||||
|
|
||||||
|
if (m_validatorRegExp)
|
||||||
|
w->setValidator(new QRegularExpressionValidator(*m_validatorRegExp, w));
|
||||||
|
|
||||||
m_widget = w;
|
m_widget = w;
|
||||||
return m_widget;
|
return m_widget;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ QT_BEGIN_NAMESPACE
|
|||||||
class QFormLayout;
|
class QFormLayout;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
|
class QRegularExpression;
|
||||||
class QTextEdit;
|
class QTextEdit;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
@@ -127,6 +128,7 @@ public:
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LineEditField();
|
LineEditField();
|
||||||
|
~LineEditField();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool parseData(const QVariant &data, QString *errorMessage);
|
bool parseData(const QVariant &data, QString *errorMessage);
|
||||||
@@ -140,6 +142,7 @@ public:
|
|||||||
QString m_placeholderText;
|
QString m_placeholderText;
|
||||||
QString m_defaultText;
|
QString m_defaultText;
|
||||||
QString m_disabledText;
|
QString m_disabledText;
|
||||||
|
QRegularExpression *m_validatorRegExp;
|
||||||
|
|
||||||
bool m_isModified;
|
bool m_isModified;
|
||||||
mutable QString m_currentText;
|
mutable QString m_currentText;
|
||||||
|
|||||||
Reference in New Issue
Block a user