diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-10-28 04:57:16 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-10-28 04:57:16 (GMT) |
commit | d42846123ec17641d1e8a8082fab0d04ce93e8a1 (patch) | |
tree | cb3e89e38a1a441870e1bc89c9f732a57449b7c5 /src/declarative/qml/qmlbinding.cpp | |
parent | eaab2a271f0d73d5a413902169efe32741208c42 (diff) | |
download | Qt-d42846123ec17641d1e8a8082fab0d04ce93e8a1.zip Qt-d42846123ec17641d1e8a8082fab0d04ce93e8a1.tar.gz Qt-d42846123ec17641d1e8a8082fab0d04ce93e8a1.tar.bz2 |
Do not display transient binding errors
During QML startup, it is common to have "errors" in bindings as the apps
state stabilizes. These are not real errors, but just a consequence of
implementing a declarative UI in an imperative world. Now during startup,
the display of errors is delayed until the startup completes, and then only
bindings that are still in an error state are displayed.
QT-2373
Diffstat (limited to 'src/declarative/qml/qmlbinding.cpp')
-rw-r--r-- | src/declarative/qml/qmlbinding.cpp | 62 |
1 files changed, 55 insertions, 7 deletions
diff --git a/src/declarative/qml/qmlbinding.cpp b/src/declarative/qml/qmlbinding.cpp index ab4343c..317a4b3 100644 --- a/src/declarative/qml/qmlbinding.cpp +++ b/src/declarative/qml/qmlbinding.cpp @@ -58,10 +58,46 @@ QT_BEGIN_NAMESPACE QML_DEFINE_NOCREATE_TYPE(QmlBinding); QmlBindingData::QmlBindingData() -: updating(false), enabled(false) +: updating(false), enabled(false), nextError(0), prevError(0) { } +QmlBindingData::~QmlBindingData() +{ + removeError(); +} + +void QmlBindingData::removeError() +{ + if (!prevError) return; + + if (nextError) nextError->prevError = prevError; + *prevError = nextError; + nextError = 0; + prevError = 0; +} + +bool QmlBindingData::addError() +{ + if (prevError) return false; + + QmlContext *c = context(); + if (!c) return false; + QmlEngine *e = c->engine(); + if (!e) return false; + + QmlEnginePrivate *p = QmlEnginePrivate::get(e); + + if (p->inProgressCreations == 0) return false; // Not in construction + + prevError = &p->erroredBindings; + nextError = p->erroredBindings; + p->erroredBindings = this; + if (nextError) nextError->prevError = &nextError; + + return true; +} + QmlBindingPrivate::QmlBindingPrivate() : QmlExpressionPrivate(new QmlBindingData) { @@ -131,9 +167,9 @@ void QmlBinding::update(QmlMetaProperty::WriteFlags flags) bool isUndefined = false; QVariant value = this->value(&isUndefined); - if (this->hasError()) { - qWarning().nospace() << qPrintable(this->error().toString()); - } else if (!isUndefined && data->property.object() && !data->property.write(value, flags)) { + if (!isUndefined && data->property.object() && + !data->property.write(value, flags)) { + QString fileName = data->fileName; int line = data->line; if (fileName.isEmpty()) fileName = QLatin1String("<Unknown File>"); @@ -141,9 +177,21 @@ void QmlBinding::update(QmlMetaProperty::WriteFlags flags) const char *valueType = 0; if (value.userType() == QVariant::Invalid) valueType = "null"; else valueType = QMetaType::typeName(value.userType()); - qWarning().nospace() << qPrintable(fileName) << ":" << line - << " Unable to assign " << valueType << " to " - << QMetaType::typeName(data->property.propertyType()); + + data->error.setUrl(fileName); + data->error.setLine(line); + data->error.setColumn(-1); + data->error.setDescription(QLatin1String("Unable to assign ") + + QLatin1String(valueType) + + QLatin1String(" to ") + + QLatin1String(QMetaType::typeName(data->property.propertyType()))); + } + + if (data->error.isValid()) { + if (!data->addError()) + qWarning().nospace() << qPrintable(this->error().toString()); + } else { + data->removeError(); } } |