summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/qml')
-rw-r--r--src/declarative/qml/qdeclarative.h11
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp53
-rw-r--r--src/declarative/qml/qdeclarativeengine_p.h11
-rw-r--r--src/declarative/qml/qdeclarativeenginedebug.cpp22
-rw-r--r--src/declarative/qml/qdeclarativeenginedebug_p.h2
5 files changed, 69 insertions, 30 deletions
diff --git a/src/declarative/qml/qdeclarative.h b/src/declarative/qml/qdeclarative.h
index 5da7901..28a6be4 100644
--- a/src/declarative/qml/qdeclarative.h
+++ b/src/declarative/qml/qdeclarative.h
@@ -405,6 +405,17 @@ QObject *qmlAttachedPropertiesObject(const QObject *obj, bool create = true)
return qmlAttachedPropertiesObject(&idx, obj, &T::staticMetaObject, create);
}
+// Enable debugging before any QDeclarativeEngine is created
+struct Q_DECLARATIVE_EXPORT QDeclarativeDebuggingEnabler
+{
+ QDeclarativeDebuggingEnabler();
+};
+
+// Execute code in constructor before first QDeclarativeEngine is instantiated
+#if defined(QT_DECLARATIVE_DEBUG)
+static QDeclarativeDebuggingEnabler qmlEnableDebuggingHelper;
+#endif
+
QT_END_NAMESPACE
QML_DECLARE_TYPE(QObject)
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index 9fde18c..aa4bcd4 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -71,6 +71,7 @@
#include "private/qdeclarativenotifier_p.h"
#include "private/qdeclarativedebugtrace_p.h"
#include "private/qdeclarativeapplication_p.h"
+#include "private/qjsdebugservice_p.h"
#include <QtCore/qmetaobject.h>
#include <QScriptClass>
@@ -123,7 +124,7 @@ QT_BEGIN_NAMESPACE
\brief The QtObject element is the most basic element in QML.
The QtObject element is a non-visual element which contains only the
- objectName property.
+ objectName property.
It can be useful to create a QtObject if you need an extremely
lightweight element to enclose a set of custom properties:
@@ -138,7 +139,7 @@ QT_BEGIN_NAMESPACE
This property holds the QObject::objectName for this specific object instance.
This allows a C++ application to locate an item within a QML component
- using the QObject::findChild() method. For example, the following C++
+ using the QObject::findChild() method. For example, the following C++
application locates the child \l Rectangle item and dynamically changes its
\c color value:
@@ -152,7 +153,7 @@ QT_BEGIN_NAMESPACE
Rectangle {
anchors.fill: parent
- color: "red"
+ color: "red"
objectName: "myRect"
}
}
@@ -166,7 +167,7 @@ QT_BEGIN_NAMESPACE
view.show();
QDeclarativeItem *item = view.rootObject()->findChild<QDeclarativeItem*>("myRect");
- if (item)
+ if (item)
item->setProperty("color", QColor(Qt::yellow));
\endcode
*/
@@ -202,7 +203,7 @@ void QDeclarativeEnginePrivate::defineModule()
\keyword QmlGlobalQtObject
-\brief The \c Qt object provides useful enums and functions from Qt, for use in all QML files.
+\brief The \c Qt object provides useful enums and functions from Qt, for use in all QML files.
The \c Qt object is a global object with utility functions, properties and enums.
@@ -583,6 +584,7 @@ void QDeclarativeEnginePrivate::init()
QDeclarativeEngineDebugServer::isDebuggingEnabled()) {
isDebugging = true;
QDeclarativeEngineDebugServer::instance()->addEngine(q);
+ QJSDebugService::instance()->addEngine(q);
}
}
@@ -645,8 +647,10 @@ QDeclarativeEngine::QDeclarativeEngine(QObject *parent)
QDeclarativeEngine::~QDeclarativeEngine()
{
Q_D(QDeclarativeEngine);
- if (d->isDebugging)
+ if (d->isDebugging) {
QDeclarativeEngineDebugServer::instance()->remEngine(this);
+ QJSDebugService::instance()->removeEngine(this);
+ }
}
/*! \fn void QDeclarativeEngine::quit()
@@ -757,7 +761,7 @@ QNetworkAccessManager *QDeclarativeEngine::networkAccessManager() const
/*!
Sets the \a provider to use for images requested via the \e
- image: url scheme, with host \a providerId. The QDeclarativeEngine
+ image: url scheme, with host \a providerId. The QDeclarativeEngine
takes ownership of \a provider.
Image providers enable support for pixmap and threaded image
@@ -1066,7 +1070,7 @@ QObject *qmlAttachedPropertiesObjectById(int id, const QObject *object, bool cre
rv = pf(const_cast<QObject *>(object));
- if (rv)
+ if (rv)
data->attachedProperties()->insert(id, rv);
return rv;
@@ -1084,6 +1088,17 @@ QObject *qmlAttachedPropertiesObject(int *idCache, const QObject *object,
return qmlAttachedPropertiesObjectById(*idCache, object, create);
}
+QDeclarativeDebuggingEnabler::QDeclarativeDebuggingEnabler()
+{
+#ifndef QDECLARATIVE_NO_DEBUG_PROTOCOL
+ if (!QDeclarativeEnginePrivate::qml_debugging_enabled) {
+ qWarning("Qml debugging is enabled. Only use this in a safe environment!");
+ }
+ QDeclarativeEnginePrivate::qml_debugging_enabled = true;
+#endif
+}
+
+
class QDeclarativeDataExtended {
public:
QDeclarativeDataExtended();
@@ -1258,7 +1273,7 @@ Returns a \l Component object created using the QML file at the specified \a url
or \c null if an empty string was given.
The returned component's \l Component::status property indicates whether the
-component was successfully created. If the status is \c Component.Error,
+component was successfully created. If the status is \c Component.Error,
see \l Component::errorString() for an error description.
Call \l {Component::createObject()}{Component.createObject()} on the returned
@@ -1311,6 +1326,8 @@ Example (where \c parentItem is the id of an existing QML item):
In the case of an error, a QtScript Error object is thrown. This object has an additional property,
\c qmlErrors, which is an array of the errors encountered.
Each object in this array has the members \c lineNumber, \c columnNumber, \c fileName and \c message.
+For example, if the above snippet had misspelled color as 'colro' then the array would contain an object like the following:
+{ "lineNumber" : 1, "columnNumber" : 32, "fileName" : "dynamicSnippet1", "message" : "Cannot assign to non-existent property \"colro\""}.
Note that this function returns immediately, and therefore may not work if
the \a qml string loads new components (that is, external QML files that have not yet been loaded).
@@ -1618,7 +1635,7 @@ QScriptValue QDeclarativeEnginePrivate::formatDateTime(QScriptContext*ctxt, QScr
return engine->newVariant(QVariant::fromValue(date.toString(format)));
} else if (formatArg.isNumber()) {
enumFormat = Qt::DateFormat(formatArg.toUInt32());
- } else {
+ } else {
return ctxt->throwError(QLatin1String("Qt.formatDateTime(): Invalid datetime format"));
}
}
@@ -1683,7 +1700,7 @@ QScriptValue QDeclarativeEnginePrivate::hsla(QScriptContext *ctxt, QScriptEngine
}
/*!
-\qmlmethod rect Qt::rect(int x, int y, int width, int height)
+\qmlmethod rect Qt::rect(int x, int y, int width, int height)
Returns a \c rect with the top-left corner at \c x, \c y and the specified \c width and \c height.
@@ -1855,7 +1872,7 @@ Binary to ASCII - this function returns a base64 encoding of \c data.
*/
QScriptValue QDeclarativeEnginePrivate::btoa(QScriptContext *ctxt, QScriptEngine *)
{
- if (ctxt->argumentCount() != 1)
+ if (ctxt->argumentCount() != 1)
return ctxt->throwError(QLatin1String("Qt.btoa(): Invalid arguments"));
QByteArray data = ctxt->argument(0).toString().toUtf8();
@@ -1870,7 +1887,7 @@ ASCII to binary - this function returns a base64 decoding of \c data.
QScriptValue QDeclarativeEnginePrivate::atob(QScriptContext *ctxt, QScriptEngine *)
{
- if (ctxt->argumentCount() != 1)
+ if (ctxt->argumentCount() != 1)
return ctxt->throwError(QLatin1String("Qt.atob(): Invalid arguments"));
QByteArray data = ctxt->argument(0).toString().toUtf8();
@@ -2289,7 +2306,7 @@ QDeclarativePropertyCache *QDeclarativeEnginePrivate::createCache(const QMetaObj
}
}
-QDeclarativePropertyCache *QDeclarativeEnginePrivate::createCache(QDeclarativeType *type, int minorVersion,
+QDeclarativePropertyCache *QDeclarativeEnginePrivate::createCache(QDeclarativeType *type, int minorVersion,
QDeclarativeError &error)
{
QList<QDeclarativeType *> types;
@@ -2298,7 +2315,7 @@ QDeclarativePropertyCache *QDeclarativeEnginePrivate::createCache(QDeclarativeTy
const QMetaObject *metaObject = type->metaObject();
while (metaObject) {
- QDeclarativeType *t = QDeclarativeMetaType::qmlType(metaObject, type->module(),
+ QDeclarativeType *t = QDeclarativeMetaType::qmlType(metaObject, type->module(),
type->majorVersion(), minorVersion);
if (t) {
maxMinorVersion = qMax(maxMinorVersion, t->minorVersion());
@@ -2342,7 +2359,7 @@ QDeclarativePropertyCache *QDeclarativeEnginePrivate::createCache(QDeclarativeTy
// Signals override:
// * other signals and methods of the same name.
- // * properties named on<Signal Name>
+ // * properties named on<Signal Name>
// * automatic <property name>Changed notify signals
// Methods override:
@@ -2367,7 +2384,7 @@ QDeclarativePropertyCache *QDeclarativeEnginePrivate::createCache(QDeclarativeTy
QDeclarativePropertyCache::Data *current = d;
while (!overloadError && current) {
current = d->overrideData(current);
- if (current && raw->isAllowedInRevision(current))
+ if (current && raw->isAllowedInRevision(current))
overloadError = true;
}
}
@@ -2375,7 +2392,7 @@ QDeclarativePropertyCache *QDeclarativeEnginePrivate::createCache(QDeclarativeTy
if (overloadError) {
if (hasCopied) raw->release();
-
+
error.setDescription(QLatin1String("Type ") + QString::fromUtf8(type->qmlTypeName()) + QLatin1String(" ") + QString::number(type->majorVersion()) + QLatin1String(".") + QString::number(minorVersion) + QLatin1String(" contains an illegal property \"") + overloadName + QLatin1String("\". This is an error in the type's implementation."));
return 0;
}
diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h
index 88b4e80..fd851f7 100644
--- a/src/declarative/qml/qdeclarativeengine_p.h
+++ b/src/declarative/qml/qdeclarativeengine_p.h
@@ -95,7 +95,6 @@ class QDeclarativeImportDatabase;
class QDeclarativeObjectScriptClass;
class QDeclarativeTypeNameScriptClass;
class QDeclarativeValueTypeScriptClass;
-class QScriptEngineDebugger;
class QNetworkReply;
class QNetworkAccessManager;
class QDeclarativeNetworkAccessManagerFactory;
@@ -332,14 +331,14 @@ public:
/*!
Returns a QDeclarativePropertyCache for \a obj if one is available.
-If \a obj is null, being deleted or contains a dynamic meta object 0
+If \a obj is null, being deleted or contains a dynamic meta object 0
is returned.
The returned cache is not referenced, so if it is to be stored, call addref().
*/
-QDeclarativePropertyCache *QDeclarativeEnginePrivate::cache(QObject *obj)
+QDeclarativePropertyCache *QDeclarativeEnginePrivate::cache(QObject *obj)
{
- if (!obj || QObjectPrivate::get(obj)->metaObject || QObjectPrivate::get(obj)->wasDeleted)
+ if (!obj || QObjectPrivate::get(obj)->metaObject || QObjectPrivate::get(obj)->wasDeleted)
return 0;
const QMetaObject *mo = obj->metaObject();
@@ -349,10 +348,10 @@ QDeclarativePropertyCache *QDeclarativeEnginePrivate::cache(QObject *obj)
}
/*!
-Returns a QDeclarativePropertyCache for \a metaObject.
+Returns a QDeclarativePropertyCache for \a metaObject.
As the cache is persisted for the life of the engine, \a metaObject must be
-a static "compile time" meta-object, or a meta-object that is otherwise known to
+a static "compile time" meta-object, or a meta-object that is otherwise known to
exist for the lifetime of the QDeclarativeEngine.
The returned cache is not referenced, so if it is to be stored, call addref().
diff --git a/src/declarative/qml/qdeclarativeenginedebug.cpp b/src/declarative/qml/qdeclarativeenginedebug.cpp
index b2a05c3..b7b88c9 100644
--- a/src/declarative/qml/qdeclarativeenginedebug.cpp
+++ b/src/declarative/qml/qdeclarativeenginedebug.cpp
@@ -524,8 +524,13 @@ void QDeclarativeEngineDebugServer::messageReceived(const QByteArray &message)
QString propertyName;
QVariant expr;
bool isLiteralValue;
+ QString filename;
+ int line;
ds >> objectId >> propertyName >> expr >> isLiteralValue;
- setBinding(objectId, propertyName, expr, isLiteralValue);
+ if (!ds.atEnd()) { // backward compatibility from 2.1, 2.2
+ ds >> filename >> line;
+ }
+ setBinding(objectId, propertyName, expr, isLiteralValue, filename, line);
} else if (type == "RESET_BINDING") {
int objectId;
QString propertyName;
@@ -543,7 +548,9 @@ void QDeclarativeEngineDebugServer::messageReceived(const QByteArray &message)
void QDeclarativeEngineDebugServer::setBinding(int objectId,
const QString &propertyName,
const QVariant &expression,
- bool isLiteralValue)
+ bool isLiteralValue,
+ QString filename,
+ int line)
{
QObject *object = objectForId(objectId);
QDeclarativeContext *context = qmlContext(object);
@@ -565,6 +572,7 @@ void QDeclarativeEngineDebugServer::setBinding(int objectId,
newBinding = new QDeclarativeBinding(expression.toString(), object, context);
newBinding->setTarget(property);
newBinding->setNotifyOnValueChanged(true);
+ newBinding->setSourceLocation(filename, line);
}
state->changeBindingInRevertList(object, propertyName, newBinding);
@@ -580,11 +588,12 @@ void QDeclarativeEngineDebugServer::setBinding(int objectId,
property.write(expression);
} else if (hasValidSignal(object, propertyName)) {
QDeclarativeExpression *declarativeExpression = new QDeclarativeExpression(context, object, expression.toString());
- QDeclarativeExpression *oldExpression = QDeclarativePropertyPrivate::setSignalExpression(property, declarativeExpression);
- declarativeExpression->setSourceLocation(oldExpression->sourceFile(), oldExpression->lineNumber());
+ QDeclarativePropertyPrivate::setSignalExpression(property, declarativeExpression);
+ declarativeExpression->setSourceLocation(filename, line);
} else if (property.isProperty()) {
QDeclarativeBinding *binding = new QDeclarativeBinding(expression.toString(), object, context);
binding->setTarget(property);
+ binding->setSourceLocation(filename, line);
binding->setNotifyOnValueChanged(true);
QDeclarativeAbstractBinding *oldBinding = QDeclarativePropertyPrivate::setBinding(property, binding);
if (oldBinding)
@@ -644,7 +653,10 @@ void QDeclarativeEngineDebugServer::resetBinding(int objectId, const QString &pr
}
}
}
- } else {
+ } else if (hasValidSignal(object, propertyName)) {
+ QDeclarativeProperty property(object, propertyName, context);
+ QDeclarativePropertyPrivate::setSignalExpression(property, 0);
+ } else {
if (QDeclarativePropertyChanges *propertyChanges = qobject_cast<QDeclarativePropertyChanges *>(object)) {
propertyChanges->removeProperty(propertyName);
}
diff --git a/src/declarative/qml/qdeclarativeenginedebug_p.h b/src/declarative/qml/qdeclarativeenginedebug_p.h
index e95676c..64b2724 100644
--- a/src/declarative/qml/qdeclarativeenginedebug_p.h
+++ b/src/declarative/qml/qdeclarativeenginedebug_p.h
@@ -115,7 +115,7 @@ private:
QDeclarativeObjectData objectData(QObject *);
QDeclarativeObjectProperty propertyData(QObject *, int);
QVariant valueContents(const QVariant &defaultValue) const;
- void setBinding(int objectId, const QString &propertyName, const QVariant &expression, bool isLiteralValue);
+ void setBinding(int objectId, const QString &propertyName, const QVariant &expression, bool isLiteralValue, QString filename = QString(), int line = -1);
void resetBinding(int objectId, const QString &propertyName);
void setMethodBody(int objectId, const QString &method, const QString &body);