diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-05-25 05:27:24 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-05-25 05:27:24 (GMT) |
commit | 8abe00029fddc0f54c2c5afeda488a76182fd95c (patch) | |
tree | 1982261606862535481b083f68eac1ba795cc614 /src | |
parent | 55664a0ef4b88b67c9931c7d2f6853e5fa0a9716 (diff) | |
parent | d982ded10a3dd5219ae40a5a3574b63ac7bdda3f (diff) | |
download | Qt-8abe00029fddc0f54c2c5afeda488a76182fd95c.zip Qt-8abe00029fddc0f54c2c5afeda488a76182fd95c.tar.gz Qt-8abe00029fddc0f54c2c5afeda488a76182fd95c.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/qt-qml:
Always pass context to QObject script class
Reading/writing a non-existent property throws an exception
Fix
geolocation (untested)
Doc
License header.
Example of a simple TextEditor look-and-feel.
Fix benchmark warnings on symbian.
Fix TextEdit implicit height.
Integrate some QML examples and demos into qtdemo
Fix typo
Diffstat (limited to 'src')
9 files changed, 44 insertions, 40 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index 7b00d2f..e34bb3d 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -80,6 +80,14 @@ TextEdit { \image declarative-textedit.gif + Note that the TextEdit does not implement scrolling, following the cursor, or other behaviors specific + to a look-and-feel. For example, to add flickable scrolling that follows the cursor: + + \snippet snippets/declarative/texteditor.qml 0 + + A particular look-and-feel might use smooth scrolling (eg. using SmoothedFollow), might have a visible + scrollbar, or a scrollbar that fades in to show location, etc. + \sa Text */ @@ -574,7 +582,7 @@ void QDeclarativeTextEdit::setCursorDelegate(QDeclarativeComponent* c) disconnect(d->control, SIGNAL(cursorPositionChanged()), this, SLOT(moveCursorDelegate())); d->control->setCursorWidth(-1); - dirtyCache(cursorRect()); + dirtyCache(cursorRectangle()); delete d->cursor; d->cursor = 0; } @@ -601,7 +609,7 @@ void QDeclarativeTextEdit::loadCursorDelegate() connect(d->control, SIGNAL(cursorPositionChanged()), this, SLOT(moveCursorDelegate())); d->control->setCursorWidth(0); - dirtyCache(cursorRect()); + dirtyCache(cursorRectangle()); QDeclarative_setParent_noEvent(d->cursor, this); d->cursor->setParentItem(this); d->cursor->setHeight(QFontMetrics(d->font).height()); @@ -854,10 +862,12 @@ Qt::TextInteractionFlags QDeclarativeTextEdit::textInteractionFlags() const } /*! - Returns the rectangle where the text cursor is rendered - within the text edit. + \qmlproperty rectangle TextEdit::cursorRectangle + + The rectangle where the text cursor is rendered + within the text edit. Read-only. */ -QRect QDeclarativeTextEdit::cursorRect() const +QRect QDeclarativeTextEdit::cursorRectangle() const { Q_D(const QDeclarativeTextEdit); return d->control->cursorRect().toRect().translated(0,-d->yoff); @@ -1076,6 +1086,7 @@ void QDeclarativeTextEditPrivate::init() QObject::connect(control, SIGNAL(selectionChanged()), q, SLOT(updateSelectionMarkers())); QObject::connect(control, SIGNAL(cursorPositionChanged()), q, SLOT(updateSelectionMarkers())); QObject::connect(control, SIGNAL(cursorPositionChanged()), q, SIGNAL(cursorPositionChanged())); + QObject::connect(control, SIGNAL(cursorPositionChanged()), q, SIGNAL(cursorRectangleChanged())); document = control->document(); document->setDefaultFont(font); @@ -1170,7 +1181,7 @@ void QDeclarativeTextEdit::updateSize() newWidth += 3;// ### Need a better way of accounting for space between char and cursor // ### Setting the implicitWidth triggers another updateSize(), and unless there are bindings nothing has changed. setImplicitWidth(newWidth); - setImplicitHeight(d->text.isEmpty() ? fm.height() : (int)d->document->size().height()); + setImplicitHeight(d->document->isEmpty() ? fm.height() : (int)d->document->size().height()); setContentsSize(QSize(width(), height())); } else { diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p.h index 8848d47..891b868 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextedit_p.h @@ -78,6 +78,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeTextEdit : public QDeclarativePaintedItem Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged) Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged) Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged) + Q_PROPERTY(QRect cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged) Q_PROPERTY(QDeclarativeComponent* cursorDelegate READ cursorDelegate WRITE setCursorDelegate NOTIFY cursorDelegateChanged) Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged) Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged) @@ -180,13 +181,14 @@ public: void setTextInteractionFlags(Qt::TextInteractionFlags flags); Qt::TextInteractionFlags textInteractionFlags() const; - QRect cursorRect() const; + QRect cursorRectangle() const; QVariant inputMethodQuery(Qt::InputMethodQuery property) const; Q_SIGNALS: void textChanged(const QString &); void cursorPositionChanged(); + void cursorRectangleChanged(); void selectionStartChanged(); void selectionEndChanged(); void selectionChanged(); diff --git a/src/declarative/qml/qdeclarativecontextscriptclass.cpp b/src/declarative/qml/qdeclarativecontextscriptclass.cpp index 1ebedbb..03a1f6a 100644 --- a/src/declarative/qml/qdeclarativecontextscriptclass.cpp +++ b/src/declarative/qml/qdeclarativecontextscriptclass.cpp @@ -270,7 +270,7 @@ QDeclarativeContextScriptClass::property(Object *object, const Identifier &name) if (lastScopeObject) { - return ep->objectClass->property(lastScopeObject, name); + return ep->objectClass->property(lastScopeObject, name, context()); } else if (lastData) { diff --git a/src/declarative/qml/qdeclarativeglobalscriptclass.cpp b/src/declarative/qml/qdeclarativeglobalscriptclass.cpp index 6e107fb..35cb2b4 100644 --- a/src/declarative/qml/qdeclarativeglobalscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeglobalscriptclass.cpp @@ -98,7 +98,9 @@ QDeclarativeGlobalScriptClass::property(const QScriptValue &object, Q_UNUSED(object); Q_UNUSED(name); Q_UNUSED(id); - return engine()->undefinedValue(); + QString error = QLatin1String("Cannot access non-existent property \"") + + name.toString() + QLatin1Char('\"'); + return engine()->currentContext()->throwError(error); } void QDeclarativeGlobalScriptClass::setProperty(QScriptValue &object, @@ -113,24 +115,5 @@ void QDeclarativeGlobalScriptClass::setProperty(QScriptValue &object, engine()->currentContext()->throwError(error); } -/* This method is for the use of tst_qdeclarativeecmascript::callQtInvokables() only */ -void QDeclarativeGlobalScriptClass::explicitSetProperty(const QString &name, const QScriptValue &value) -{ - QScriptValue globalObject = engine()->globalObject(); - - QScriptValue v = engine()->newObject(); - - QScriptValueIterator iter(v); - while (iter.hasNext()) { - iter.next(); - v.setProperty(iter.scriptName(), iter.value()); - } - - v.setProperty(name, value); - v.setScriptClass(this); - - engine()->setGlobalObject(v); -} - QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativeglobalscriptclass_p.h b/src/declarative/qml/qdeclarativeglobalscriptclass_p.h index 7690edd..3fe766f 100644 --- a/src/declarative/qml/qdeclarativeglobalscriptclass_p.h +++ b/src/declarative/qml/qdeclarativeglobalscriptclass_p.h @@ -73,8 +73,6 @@ public: virtual void setProperty(QScriptValue &object, const QScriptString &name, uint id, const QScriptValue &value); - void explicitSetProperty(const QString &, const QScriptValue &); - const QScriptValue &globalObject() const { return m_globalObject; } const QSet<QString> &illegalNames() const { return m_illegalNames; } diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp index aca01b2..7c818a6 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp @@ -93,6 +93,7 @@ QDeclarativeObjectScriptClass::QDeclarativeObjectScriptClass(QDeclarativeEngine m_destroyId = createPersistentIdentifier(QLatin1String("destroy")); m_toString = scriptEngine->newFunction(tostring); m_toStringId = createPersistentIdentifier(QLatin1String("toString")); + m_valueOfId = createPersistentIdentifier(QLatin1String("valueOf")); } QDeclarativeObjectScriptClass::~QDeclarativeObjectScriptClass() @@ -157,7 +158,8 @@ QDeclarativeObjectScriptClass::queryProperty(QObject *obj, const Identifier &nam lastTNData = 0; if (name == m_destroyId.identifier || - name == m_toStringId.identifier) + name == m_toStringId.identifier || + name == m_valueOfId.identifier) return QScriptClass::HandlesReadAccess; if (!obj) @@ -201,21 +203,27 @@ QDeclarativeObjectScriptClass::queryProperty(QObject *obj, const Identifier &nam QDeclarativeObjectScriptClass::Value QDeclarativeObjectScriptClass::property(Object *object, const Identifier &name) { - return property(toQObject(object), name); + return property(toQObject(object), name, context()); } QDeclarativeObjectScriptClass::Value -QDeclarativeObjectScriptClass::property(QObject *obj, const Identifier &name) +QDeclarativeObjectScriptClass::property(QObject *obj, const Identifier &name, QScriptContext *context) { + Q_ASSERT(context); + QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine); if (name == m_destroyId.identifier) return Value(scriptEngine, m_destroy); - else if (name == m_toStringId.identifier) + else if (name == m_toStringId.identifier || + name == m_valueOfId.identifier) return Value(scriptEngine, m_toString); - if (lastData && !lastData->isValid()) - return Value(); + if (lastData && !lastData->isValid()) { + QString error = QLatin1String("Cannot access non-existent property \"") + + toString(name) + QLatin1Char('\"'); + return Value(scriptEngine, context->throwError(error)); + } Q_ASSERT(obj); diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass_p.h b/src/declarative/qml/qdeclarativeobjectscriptclass_p.h index 4b27e53..61fa586 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass_p.h +++ b/src/declarative/qml/qdeclarativeobjectscriptclass_p.h @@ -113,10 +113,11 @@ public: QDeclarativeContextData *evalContext, QueryHints hints = 0); - Value property(QObject *, const Identifier &); + Value property(QObject *, const Identifier &, QScriptContext *context); void setProperty(QObject *, const Identifier &name, const QScriptValue &, QScriptContext *context, QDeclarativeContextData *evalContext = 0); + virtual QStringList propertyNames(Object *); virtual bool compare(Object *, Object *); @@ -139,6 +140,7 @@ private: PersistentIdentifier m_destroyId; PersistentIdentifier m_toStringId; + PersistentIdentifier m_valueOfId; QScriptValue m_destroy; QScriptValue m_toString; diff --git a/src/declarative/qml/qdeclarativetypenamescriptclass.cpp b/src/declarative/qml/qdeclarativetypenamescriptclass.cpp index 2a3417a..b512387 100644 --- a/src/declarative/qml/qdeclarativetypenamescriptclass.cpp +++ b/src/declarative/qml/qdeclarativetypenamescriptclass.cpp @@ -147,7 +147,7 @@ QDeclarativeTypeNameScriptClass::property(Object *obj, const Identifier &name) if (type) { return Value(scriptEngine, newObject(((TypeNameData *)obj)->object, type, ((TypeNameData *)obj)->mode)); } else if (object) { - return ep->objectClass->property(object, name); + return ep->objectClass->property(object, name, context()); } else { return Value(scriptEngine, enumValue); } diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp index 80ae5f5..99f163e 100644 --- a/src/declarative/util/qdeclarativestateoperations.cpp +++ b/src/declarative/util/qdeclarativestateoperations.cpp @@ -1128,8 +1128,8 @@ void QDeclarativeAnchorChanges::setObject(QDeclarativeItem *target) \qml AnchorChanges { target: myItem - left: undefined //remove myItem's left anchor - right: otherItem.right + anchors.left: undefined //remove myItem's left anchor + anchors.right: otherItem.right } \endqml */ |