forked from qt-creator/qt-creator
QmlDesigner: Provide a descriptive message for invalid IDs
Fixes: QDS-5044 Change-Id: I12f78851f5200e417fe6f323a0773587400cd90f Reviewed-by: Johanna Vanhatapio <johanna.vanhatapio@qt.io> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -163,8 +163,9 @@ void PropertyEditorView::changeValue(const QString &name)
|
|||||||
m_locked = true;
|
m_locked = true;
|
||||||
value->setValue(m_selectedNode.id());
|
value->setValue(m_selectedNode.id());
|
||||||
m_locked = false;
|
m_locked = false;
|
||||||
if (!QmlDesigner::ModelNode::isValidId(newId))
|
QString errMsg = QmlDesigner::ModelNode::getIdValidityErrorMessage(newId);
|
||||||
Core::AsynchronousMessageBox::warning(tr("Invalid ID"), tr("%1 is an invalid ID.").arg(newId));
|
if (!errMsg.isEmpty())
|
||||||
|
Core::AsynchronousMessageBox::warning(tr("Invalid ID"), errMsg.arg(newId));
|
||||||
else
|
else
|
||||||
Core::AsynchronousMessageBox::warning(tr("Invalid ID"), tr("%1 already exists.").arg(newId));
|
Core::AsynchronousMessageBox::warning(tr("Invalid ID"), tr("%1 already exists.").arg(newId));
|
||||||
}
|
}
|
||||||
|
@@ -168,6 +168,8 @@ public:
|
|||||||
void setIdWithRefactoring(const QString &id);
|
void setIdWithRefactoring(const QString &id);
|
||||||
void setIdWithoutRefactoring(const QString &id);
|
void setIdWithoutRefactoring(const QString &id);
|
||||||
static bool isValidId(const QString &id);
|
static bool isValidId(const QString &id);
|
||||||
|
static QString getIdValidityErrorMessage(const QString &id);
|
||||||
|
|
||||||
bool hasId() const;
|
bool hasId() const;
|
||||||
|
|
||||||
Model *model() const;
|
Model *model() const;
|
||||||
|
@@ -212,6 +212,29 @@ bool ModelNode::isValidId(const QString &id)
|
|||||||
return id.isEmpty() || (!idContainsWrongLetter(id) && !idIsQmlKeyWord(id) && !isIdToAvoid(id));
|
return id.isEmpty() || (!idContainsWrongLetter(id) && !idIsQmlKeyWord(id) && !isIdToAvoid(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ModelNode::getIdValidityErrorMessage(const QString &id)
|
||||||
|
{
|
||||||
|
if (isValidId(id))
|
||||||
|
return {}; // valid
|
||||||
|
|
||||||
|
if (id.at(0).isUpper())
|
||||||
|
return QObject::tr("ID cannot start with an uppercase character.");
|
||||||
|
|
||||||
|
if (id.at(0).isDigit())
|
||||||
|
return QObject::tr("ID cannot start with a number.");
|
||||||
|
|
||||||
|
if (id.contains(' '))
|
||||||
|
return QObject::tr("ID cannot include whitespace.");
|
||||||
|
|
||||||
|
if (idIsQmlKeyWord(id))
|
||||||
|
return QObject::tr("%1 is a reserved QML keyword.");
|
||||||
|
|
||||||
|
if (isIdToAvoid(id))
|
||||||
|
return QObject::tr("%1 is a reserved property keyword.");
|
||||||
|
|
||||||
|
return QObject::tr("ID includes invalid characters.");
|
||||||
|
}
|
||||||
|
|
||||||
bool ModelNode::hasId() const
|
bool ModelNode::hasId() const
|
||||||
{
|
{
|
||||||
if (!isValid())
|
if (!isValid())
|
||||||
|
Reference in New Issue
Block a user