Commit 7bcd03a5 authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlDesigner.propertyEditor: unifying error messages for invalid nodes

The Navigator and the Property Editor now show the same error
message for invalid nodes

See: BAUHAUS-611
parent b8de523c
......@@ -272,14 +272,9 @@ void NavigatorTreeModel::handleChangedItem(QStandardItem *item)
ItemRow itemRow = itemRowForNode(node);
if (item == itemRow.idItem) {
try {
if (ModelNode::isValidId(item->text()))
node.setId(item->text());
else {
QMessageBox::warning(0,"Invalid Id",tr("Invalid id.\nOnly alphanumeric characters and underscore allowed.\nIds must begin with a lowercase letter."));
item->setText(node.id());
}
} catch (InvalidIdException &) {
QMessageBox::warning(0,"Invalid Id",tr("Item id must be unique."));
node.setId(item->text());
} catch (InvalidIdException &e) {
QMessageBox::warning(0, tr("Invalid Id"), e.description());
item->setText(node.id());
}
} else if (item == itemRow.visibilityItem) {
......
......@@ -166,7 +166,6 @@ void PropertyEditor::NodeType::setValue(const QmlObjectNode & fxObjectNode, cons
void PropertyEditor::NodeType::setup(const QmlObjectNode &fxObjectNode, const QString &stateName, const QUrl &qmlSpecificsFile, PropertyEditor *propertyEditor)
{
if (!fxObjectNode.isValid()) {
qWarning() << "invalid node for setup";
return;
}
......@@ -354,12 +353,10 @@ void PropertyEditor::changeValue(const QString &propertyName)
const QString newId = value->value().toString();
try {
if (ModelNode::isValidId(newId))
m_selectedNode.setId(newId);
else
value->setValue(m_selectedNode.id());
} catch (InvalidIdException &) {
m_selectedNode.setId(newId);
} catch (InvalidIdException &e) {
value->setValue(m_selectedNode.id());
QMessageBox::warning(0, tr("Invalid Id"), e.description());
}
return;
......
......@@ -33,8 +33,10 @@ namespace QmlDesigner {
InvalidIdException::InvalidIdException(int line,
const QString &function,
const QString &file):
InvalidArgumentException(line, function, file, "id")
const QString &file,
const QString &id,
bool duplicate) :
InvalidArgumentException(line, function, file, "id"), m_id(id), m_duplicate(duplicate)
{
}
......@@ -42,4 +44,23 @@ QString InvalidIdException::type() const
{
return "InvalidIdException";
}
QString InvalidIdException::description() const
{
if (m_duplicate)
return duplicateErrorMessage(m_id);
return invalidErrorMessage(m_id);
}
QString InvalidIdException::duplicateErrorMessage(const QString &id)
{
return QObject::tr("Ids have to be unique: ") + id;
}
QString InvalidIdException::invalidErrorMessage(const QString &id)
{
return QObject::tr("Invalid Id: ") + id + QObject::tr("\nOnly alphanumeric characters and underscore allowed.\nIds must begin with a lowercase letter.");
}
}
......@@ -39,9 +39,19 @@ class CORESHARED_EXPORT InvalidIdException : public InvalidArgumentException
public:
InvalidIdException(int line,
const QString &function,
const QString &file);
const QString &file,
const QString &id,
bool duplicate = false);
QString type() const;
QString description() const;
static QString duplicateErrorMessage(const QString &id);
static QString invalidErrorMessage(const QString &id);
private:
QString m_id;
bool m_duplicate;
};
......
......@@ -180,13 +180,13 @@ void ModelNode::setId(const QString& id)
}
if (!isValidId(id))
throw InvalidIdException(__LINE__, __FUNCTION__, __FILE__);
throw InvalidIdException(__LINE__, __FUNCTION__, __FILE__, id);
if (id == ModelNode::id())
return;
if (view()->hasId(id))
throw InvalidIdException(__LINE__, __FUNCTION__, __FILE__);
throw InvalidIdException(__LINE__, __FUNCTION__, __FILE__, id, true);
m_model.data()->m_d->changeNodeId(internalNode(), id);
}
......
Supports Markdown
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