From c6cbece9baec95d54d85a26f439ed4e7274ca3fd Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Fri, 9 Oct 2009 18:52:01 +0200 Subject: some preliminary work on QScriptProgram --- src/script/api/api.pri | 3 + src/script/api/qscriptengine.cpp | 73 +++++++++++++++++++++ src/script/api/qscriptprogram.cpp | 134 ++++++++++++++++++++++++++++++++++++++ src/script/api/qscriptprogram.h | 74 +++++++++++++++++++++ src/script/api/qscriptprogram_p.h | 88 +++++++++++++++++++++++++ 5 files changed, 372 insertions(+) create mode 100644 src/script/api/qscriptprogram.cpp create mode 100644 src/script/api/qscriptprogram.h create mode 100644 src/script/api/qscriptprogram_p.h diff --git a/src/script/api/api.pri b/src/script/api/api.pri index 17ec9b6..aebadd5 100644 --- a/src/script/api/api.pri +++ b/src/script/api/api.pri @@ -6,6 +6,7 @@ SOURCES += \ $$PWD/qscriptengine.cpp \ $$PWD/qscriptengineagent.cpp \ $$PWD/qscriptextensionplugin.cpp \ + $$PWD/qscriptprogram.cpp \ $$PWD/qscriptstring.cpp \ $$PWD/qscriptvalue.cpp \ $$PWD/qscriptvalueiterator.cpp \ @@ -23,6 +24,8 @@ HEADERS += \ $$PWD/qscriptengineagent_p.h \ $$PWD/qscriptextensioninterface.h \ $$PWD/qscriptextensionplugin.h \ + $$PWD/qscriptprogram.h \ + $$PWD/qscriptprogram_p.h \ $$PWD/qscriptstring.h \ $$PWD/qscriptstring_p.h \ $$PWD/qscriptvalue.h \ diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index b1f36be..b11c276 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -51,6 +51,8 @@ #include "qscriptvalue_p.h" #include "qscriptvalueiterator.h" #include "qscriptclass.h" +#include "qscriptprogram.h" +#include "qscriptprogram_p.h" #include "qdebug.h" #include @@ -2214,6 +2216,77 @@ QScriptValue QScriptEngine::evaluate(const QString &program, const QString &file return d->scriptValueFromJSCValue(result); } +QScriptProgram QScriptEngine::compile(const QString &program, const QString &fileName, int lineNumber) +{ + Q_D(QScriptEngine); + JSC::UString jscProgram = program; + JSC::UString jscFileName = fileName; + WTF::PassRefPtr provider + = QScript::UStringSourceProviderWithFeedback::create(jscProgram, jscFileName, lineNumber, d); + JSC::SourceCode source(provider, lineNumber); //after construction of SourceCode provider variable will be null. + + JSC::ExecState* exec = d->currentFrame; + exec->clearException(); + JSC::DynamicGlobalObjectScope dynamicGlobalObjectScope(exec, exec->scopeChain()->globalObject()); + + JSC::EvalExecutable *executable = new JSC::EvalExecutable(exec, source); + JSC::JSObject* error = executable->compile(exec, exec->scopeChain()); + if (error != 0) { + delete executable; + return QScriptProgram(); + } + return QScriptProgramPrivate::create(d, executable, provider->asID()); +} + +QScriptValue QScriptEngine::evaluate(const QScriptProgram &program) +{ + Q_D(QScriptEngine); + QScriptProgramPrivate *program_d = QScriptProgramPrivate::get(program); + if (!program_d || !program_d->engine || !program_d->executable) + return QScriptValue(); + + JSC::ExecState* exec = d->currentFrame; + exec->clearException(); + JSC::DynamicGlobalObjectScope dynamicGlobalObjectScope(exec, exec->scopeChain()->globalObject()); + + intptr_t sourceId = program_d->sourceId; + JSC::Debugger* debugger = d->originalGlobalObject()->debugger(); + if (debugger) + debugger->evaluateStart(sourceId); + + JSC::JSValue thisValue = d->thisForContext(exec); + JSC::JSObject* thisObject = (!thisValue || thisValue.isUndefinedOrNull()) ? exec->dynamicGlobalObject() : thisValue.toObject(exec); + JSC::JSValue exceptionValue; + d->timeoutChecker()->setShouldAbort(false); + if (d->processEventsInterval > 0) + d->timeoutChecker()->reset(); + JSC::JSValue result = exec->interpreter()->execute(program_d->executable, exec, thisObject, exec->scopeChain(), &exceptionValue); + + if (d->timeoutChecker()->shouldAbort()) { + if (d->abortResult.isError()) + exec->setException(d->scriptValueToJSCValue(d->abortResult)); + + if (debugger) + debugger->evaluateStop(d->scriptValueToJSCValue(d->abortResult), sourceId); + + return d->abortResult; + } + + if (exceptionValue) { + exec->setException(exceptionValue); + + if (debugger) + debugger->evaluateStop(exceptionValue, sourceId); + + return d->scriptValueFromJSCValue(exceptionValue); + } + + if (debugger) + debugger->evaluateStop(result, sourceId); + + Q_ASSERT(!exec->hadException()); + return d->scriptValueFromJSCValue(result); +} /*! Returns the current context. diff --git a/src/script/api/qscriptprogram.cpp b/src/script/api/qscriptprogram.cpp new file mode 100644 index 0000000..2746c44 --- /dev/null +++ b/src/script/api/qscriptprogram.cpp @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtScript module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qscriptprogram.h" +#include "qscriptprogram_p.h" +#include "qscriptengine.h" +#include "qscriptengine_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \since 4.6 + \class QScriptProgram + + \brief The QScriptProgram class ... + + \ingroup script + +*/ + +QScriptProgramPrivate::QScriptProgramPrivate(QScriptEnginePrivate *e, + JSC::EvalExecutable *x, + intptr_t id) + : engine(e), executable(x), sourceId(id) +{ + ref = 0; +} + +QScriptProgramPrivate::~QScriptProgramPrivate() +{ +} + +QScriptProgramPrivate *QScriptProgramPrivate::get(const QScriptProgram &q) +{ + return const_cast(q.d_func()); +} + +QScriptProgram QScriptProgramPrivate::create(QScriptEnginePrivate *engine, + JSC::EvalExecutable *executable, + intptr_t sourceId) +{ + QScriptProgramPrivate *d = new QScriptProgramPrivate(engine, executable, sourceId); + QScriptProgram result; + result.d_ptr = d; + return result; +} + +/*! + Constructs an invalid QScriptProgram. +*/ +QScriptProgram::QScriptProgram() + : d_ptr(0) +{ +} + +/*! + Constructs a new QScriptProgram that is a copy of \a other. +*/ +QScriptProgram::QScriptProgram(const QScriptProgram &other) + : d_ptr(other.d_ptr) +{ +} + +/*! + Destroys this QScriptProgram. +*/ +QScriptProgram::~QScriptProgram() +{ + Q_D(QScriptProgram); + // if (d->engine && (d->ref == 1)) + // d->engine->unregisterScriptProgram(d); +} + +/*! + Assigns the \a other value to this QScriptProgram. +*/ +QScriptProgram &QScriptProgram::operator=(const QScriptProgram &other) +{ + // if (d_func() && d_func()->engine && (d_func()->ref == 1)) + // d_func()->engine->unregisterScriptProgram(d_func()); + // } + d_ptr = other.d_ptr; + return *this; +} + +/*! + Returns true if this QScriptProgram is valid; otherwise + returns false. +*/ +bool QScriptProgram::isValid() const +{ + Q_D(const QScriptProgram); + return (d && d->engine); +} + +QT_END_NAMESPACE diff --git a/src/script/api/qscriptprogram.h b/src/script/api/qscriptprogram.h new file mode 100644 index 0000000..6c2ba47 --- /dev/null +++ b/src/script/api/qscriptprogram.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtScript module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSCRIPTPROGRAM_H +#define QSCRIPTPROGRAM_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Script) + +class QScriptProgramPrivate; +class Q_SCRIPT_EXPORT QScriptProgram +{ +public: + QScriptProgram(); + QScriptProgram(const QScriptProgram &other); + ~QScriptProgram(); + + QScriptProgram &operator=(const QScriptProgram &other); + + bool isValid() const; + +private: + QExplicitlySharedDataPointer d_ptr; + Q_DECLARE_PRIVATE(QScriptProgram) +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QSCRIPTPROGRAM_H diff --git a/src/script/api/qscriptprogram_p.h b/src/script/api/qscriptprogram_p.h new file mode 100644 index 0000000..fe06b38 --- /dev/null +++ b/src/script/api/qscriptprogram_p.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtScript module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSCRIPTPROGRAM_P_H +#define QSCRIPTPROGRAM_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include + +namespace JSC +{ + class EvalExecutable; +} + +QT_BEGIN_NAMESPACE + +class QScriptEnginePrivate; + +class QScriptProgramPrivate +{ +public: + QScriptProgramPrivate(QScriptEnginePrivate*, + JSC::EvalExecutable*, + intptr_t); + ~QScriptProgramPrivate(); + + static QScriptProgramPrivate *get(const QScriptProgram &q); + static QScriptProgram create(QScriptEnginePrivate*, + JSC::EvalExecutable*, + intptr_t); + + QBasicAtomicInt ref; + QScriptEnginePrivate *engine; + JSC::EvalExecutable *executable; + intptr_t sourceId; +}; + +QT_END_NAMESPACE + +#endif -- cgit v0.12 From d0f965f1bde20babbb0574007f9cf8439b955a9b Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 22 Oct 2009 11:51:59 +1000 Subject: Allow canvas sizehint to be configurable and fix signal-slot connections in engine.cpp --- tools/qmldebugger/canvasframerate.cpp | 18 ++++++++++++------ tools/qmldebugger/canvasframerate.h | 4 ++++ tools/qmldebugger/engine.cpp | 4 ++-- tools/qmldebugger/objecttree.cpp | 1 + tools/qmldebugger/qmldebugger.cpp | 1 + 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/tools/qmldebugger/canvasframerate.cpp b/tools/qmldebugger/canvasframerate.cpp index 0d23050..7c5d089 100644 --- a/tools/qmldebugger/canvasframerate.cpp +++ b/tools/qmldebugger/canvasframerate.cpp @@ -32,7 +32,6 @@ public slots: protected: virtual void paintEvent(QPaintEvent *); - virtual QSize sizeHint() const; private slots: void scrollbarChanged(int); @@ -57,6 +56,8 @@ private: QLineGraph::QLineGraph(QWidget *parent) : QWidget(parent), sb(Qt::Horizontal, this), position(-1), samplesPerWidth(99), resolutionForHeight(50), ignoreScroll(false) { + setMinimumHeight(180); + sb.setMaximum(0); sb.setMinimum(0); sb.setSingleStep(1); @@ -68,11 +69,6 @@ QLineGraph::QLineGraph(QWidget *parent) QObject::connect(&sb, SIGNAL(valueChanged(int)), this, SLOT(scrollbarChanged(int))); } -QSize QLineGraph::sizeHint() const -{ - return QSize(800, 600); -} - void QLineGraph::scrollbarChanged(int v) { if(ignoreScroll) @@ -291,6 +287,16 @@ CanvasFrameRate::CanvasFrameRate(QmlDebugConnection *client, QWidget *parent) newTab(); } +void CanvasFrameRate::setSizeHint(const QSize &size) +{ + m_sizeHint = size; +} + +QSize CanvasFrameRate::sizeHint() const +{ + return m_sizeHint; +} + void CanvasFrameRate::newTab() { if (m_tabs->count()) { diff --git a/tools/qmldebugger/canvasframerate.h b/tools/qmldebugger/canvasframerate.h index cef267d..aa275aa 100644 --- a/tools/qmldebugger/canvasframerate.h +++ b/tools/qmldebugger/canvasframerate.h @@ -14,6 +14,9 @@ class CanvasFrameRate : public QWidget public: CanvasFrameRate(QmlDebugConnection *, QWidget *parent = 0); + void setSizeHint(const QSize &); + virtual QSize sizeHint() const; + private slots: void newTab(); void stateChanged(int); @@ -22,6 +25,7 @@ private: QTabWidget *m_tabs; QSpinBox *m_spin; QObject *m_plugin; + QSize m_sizeHint; }; QT_END_NAMESPACE diff --git a/tools/qmldebugger/engine.cpp b/tools/qmldebugger/engine.cpp index fac10f3..3cf5165 100644 --- a/tools/qmldebugger/engine.cpp +++ b/tools/qmldebugger/engine.cpp @@ -71,7 +71,7 @@ EnginePane::EnginePane(QmlDebugConnection *conn, QWidget *parent) WatchTableHeaderView *header = new WatchTableHeaderView(m_watchTableModel); m_watchTableView->setHorizontalHeader(header); - connect(m_objTree, SIGNAL(objectSelected(QmlDebugObjectReference)), + connect(m_objTree, SIGNAL(currentObjectChanged(QmlDebugObjectReference)), m_propertiesView, SLOT(reload(QmlDebugObjectReference))); connect(m_objTree, SIGNAL(expressionWatchRequested(QmlDebugObjectReference,QString)), m_watchTableModel, SLOT(expressionWatchRequested(QmlDebugObjectReference,QString))); @@ -83,7 +83,7 @@ EnginePane::EnginePane(QmlDebugConnection *conn, QWidget *parent) m_propertiesView, SLOT(watchCreated(QmlDebugWatch*))); connect(m_watchTableView, SIGNAL(objectActivated(int)), - m_objTree, SLOT(selectObject(int))); + m_objTree, SLOT(setCurrentObject(int))); m_tabs = new QTabWidget(this); m_tabs->addTab(m_propertiesView, tr("Properties")); diff --git a/tools/qmldebugger/objecttree.cpp b/tools/qmldebugger/objecttree.cpp index 0b92ceb..1254ae7 100644 --- a/tools/qmldebugger/objecttree.cpp +++ b/tools/qmldebugger/objecttree.cpp @@ -18,6 +18,7 @@ ObjectTree::ObjectTree(QmlEngineDebug *client, QWidget *parent) m_query(0) { setHeaderHidden(true); + setMinimumWidth(250); connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(currentItemChanged(QTreeWidgetItem *))); diff --git a/tools/qmldebugger/qmldebugger.cpp b/tools/qmldebugger/qmldebugger.cpp index e0a76b6..2828026 100644 --- a/tools/qmldebugger/qmldebugger.cpp +++ b/tools/qmldebugger/qmldebugger.cpp @@ -46,6 +46,7 @@ QmlDebugger::QmlDebugger(QWidget *parent) layout->addWidget(m_tabs); CanvasFrameRate *cfr = new CanvasFrameRate(&client, this); + cfr->setSizeHint(QSize(800, 600)); m_tabs->addTab(cfr, tr("Frame Rate")); m_enginePane = new EnginePane(&client, this); -- cgit v0.12 From 9c1e8178aca83e2a9e3c7aa8a9a9c91a6fa4ec71 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Fri, 23 Oct 2009 09:37:46 +0200 Subject: add compile() and evaluate() functions to public api --- src/script/api/qscriptengine.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/script/api/qscriptengine.h b/src/script/api/qscriptengine.h index 701f9c6..c58bb7c 100644 --- a/src/script/api/qscriptengine.h +++ b/src/script/api/qscriptengine.h @@ -67,6 +67,7 @@ class QDateTime; class QScriptClass; class QScriptEngineAgent; class QScriptEnginePrivate; +class QScriptProgram; #ifndef QT_NO_QOBJECT @@ -166,6 +167,9 @@ public: QScriptValue evaluate(const QString &program, const QString &fileName = QString(), int lineNumber = 1); + QScriptProgram compile(const QString &program, const QString &fileName = QString(), int lineNumber = 1); + QScriptValue evaluate(const QScriptProgram &program); + bool isEvaluating() const; void abortEvaluation(const QScriptValue &result = QScriptValue()); -- cgit v0.12 From 3c2f239b974a776c05ab0886925db1c8dca19d4d Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Fri, 23 Oct 2009 09:38:56 +0200 Subject: delete the executable when the program is destroyed --- src/script/api/qscriptprogram.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/script/api/qscriptprogram.cpp b/src/script/api/qscriptprogram.cpp index 2746c44..96760ba 100644 --- a/src/script/api/qscriptprogram.cpp +++ b/src/script/api/qscriptprogram.cpp @@ -44,14 +44,16 @@ #include "qscriptengine.h" #include "qscriptengine_p.h" +#include "Executable.h" + QT_BEGIN_NAMESPACE /*! + \internal + \since 4.6 \class QScriptProgram - \brief The QScriptProgram class ... - \ingroup script */ @@ -66,6 +68,7 @@ QScriptProgramPrivate::QScriptProgramPrivate(QScriptEnginePrivate *e, QScriptProgramPrivate::~QScriptProgramPrivate() { + delete executable; } QScriptProgramPrivate *QScriptProgramPrivate::get(const QScriptProgram &q) -- cgit v0.12 From 980291d7d79022c31f900f67e0422da1a8abb0a0 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Fri, 23 Oct 2009 09:39:14 +0200 Subject: separate the logic shared by evaluate(QString) and evaluate(QScriptProgram) Introduce helper function evaluateHelper(). --- src/script/api/qscriptengine.cpp | 124 ++++++++++++++++++--------------------- src/script/api/qscriptengine_p.h | 4 ++ 2 files changed, 60 insertions(+), 68 deletions(-) diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index b11c276..25f815f 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -1188,6 +1188,45 @@ void QScriptEnginePrivate::agentDeleted(QScriptEngineAgent *agent) } } +QScriptValue QScriptEnginePrivate::evaluateHelper(JSC::ExecState *exec, JSC::Debugger* debugger, + intptr_t sourceId, JSC::EvalExecutable *executable) +{ + JSC::JSValue thisValue = thisForContext(exec); + JSC::JSObject* thisObject = (!thisValue || thisValue.isUndefinedOrNull()) + ? exec->dynamicGlobalObject() : thisValue.toObject(exec); + JSC::JSValue exceptionValue; + timeoutChecker()->setShouldAbort(false); + if (processEventsInterval > 0) + timeoutChecker()->reset(); + + JSC::JSValue result = exec->interpreter()->execute(executable, exec, thisObject, exec->scopeChain(), &exceptionValue); + + if (timeoutChecker()->shouldAbort()) { + if (abortResult.isError()) + exec->setException(scriptValueToJSCValue(abortResult)); + + if (debugger) + debugger->evaluateStop(scriptValueToJSCValue(abortResult), sourceId); + + return abortResult; + } + + if (exceptionValue) { + exec->setException(exceptionValue); + + if (debugger) + debugger->evaluateStop(exceptionValue, sourceId); + + return scriptValueFromJSCValue(exceptionValue); + } + + if (debugger) + debugger->evaluateStop(result, sourceId); + + Q_ASSERT(!exec->hadException()); + return scriptValueFromJSCValue(result); +} + #ifndef QT_NO_QOBJECT JSC::JSValue QScriptEnginePrivate::newQObject( @@ -2153,8 +2192,6 @@ QScriptValue QScriptEngine::evaluate(const QString &program, const QString &file QBoolBlocker inEval(d->inEval, true); currentContext()->activationObject(); //force the creation of a context for native function; - JSC::Debugger* debugger = d->originalGlobalObject()->debugger(); - JSC::UString jscProgram = program; JSC::UString jscFileName = fileName; JSC::ExecState* exec = d->currentFrame; @@ -2163,6 +2200,7 @@ QScriptValue QScriptEngine::evaluate(const QString &program, const QString &file intptr_t sourceId = provider->asID(); JSC::SourceCode source(provider, lineNumber); //after construction of SourceCode provider variable will be null. + JSC::Debugger* debugger = d->originalGlobalObject()->debugger(); if (debugger) debugger->evaluateStart(sourceId); @@ -2182,40 +2220,13 @@ QScriptValue QScriptEngine::evaluate(const QString &program, const QString &file return d->scriptValueFromJSCValue(error); } - JSC::JSValue thisValue = d->thisForContext(exec); - JSC::JSObject* thisObject = (!thisValue || thisValue.isUndefinedOrNull()) ? exec->dynamicGlobalObject() : thisValue.toObject(exec); - JSC::JSValue exceptionValue; - d->timeoutChecker()->setShouldAbort(false); - if (d->processEventsInterval > 0) - d->timeoutChecker()->reset(); - JSC::JSValue result = exec->interpreter()->execute(&executable, exec, thisObject, exec->scopeChain(), &exceptionValue); - - if (d->timeoutChecker()->shouldAbort()) { - if (d->abortResult.isError()) - exec->setException(d->scriptValueToJSCValue(d->abortResult)); - - if (debugger) - debugger->evaluateStop(d->scriptValueToJSCValue(d->abortResult), sourceId); - - return d->abortResult; - } - - if (exceptionValue) { - exec->setException(exceptionValue); - - if (debugger) - debugger->evaluateStop(exceptionValue, sourceId); - - return d->scriptValueFromJSCValue(exceptionValue); - } - - if (debugger) - debugger->evaluateStop(result, sourceId); - - Q_ASSERT(!exec->hadException()); - return d->scriptValueFromJSCValue(result); + return d->evaluateHelper(exec, debugger, sourceId, &executable); } +/*! + \internal + \since 4.6 +*/ QScriptProgram QScriptEngine::compile(const QString &program, const QString &fileName, int lineNumber) { Q_D(QScriptEngine); @@ -2238,6 +2249,10 @@ QScriptProgram QScriptEngine::compile(const QString &program, const QString &fil return QScriptProgramPrivate::create(d, executable, provider->asID()); } +/*! + \internal + \since 4.6 +*/ QScriptValue QScriptEngine::evaluate(const QScriptProgram &program) { Q_D(QScriptEngine); @@ -2245,47 +2260,20 @@ QScriptValue QScriptEngine::evaluate(const QScriptProgram &program) if (!program_d || !program_d->engine || !program_d->executable) return QScriptValue(); - JSC::ExecState* exec = d->currentFrame; - exec->clearException(); - JSC::DynamicGlobalObjectScope dynamicGlobalObjectScope(exec, exec->scopeChain()->globalObject()); + JSC::JSLock lock(false); + QBoolBlocker inEval(d->inEval, true); + currentContext()->activationObject(); //force the creation of a context for native function; intptr_t sourceId = program_d->sourceId; JSC::Debugger* debugger = d->originalGlobalObject()->debugger(); if (debugger) debugger->evaluateStart(sourceId); - JSC::JSValue thisValue = d->thisForContext(exec); - JSC::JSObject* thisObject = (!thisValue || thisValue.isUndefinedOrNull()) ? exec->dynamicGlobalObject() : thisValue.toObject(exec); - JSC::JSValue exceptionValue; - d->timeoutChecker()->setShouldAbort(false); - if (d->processEventsInterval > 0) - d->timeoutChecker()->reset(); - JSC::JSValue result = exec->interpreter()->execute(program_d->executable, exec, thisObject, exec->scopeChain(), &exceptionValue); - - if (d->timeoutChecker()->shouldAbort()) { - if (d->abortResult.isError()) - exec->setException(d->scriptValueToJSCValue(d->abortResult)); - - if (debugger) - debugger->evaluateStop(d->scriptValueToJSCValue(d->abortResult), sourceId); - - return d->abortResult; - } - - if (exceptionValue) { - exec->setException(exceptionValue); - - if (debugger) - debugger->evaluateStop(exceptionValue, sourceId); - - return d->scriptValueFromJSCValue(exceptionValue); - } - - if (debugger) - debugger->evaluateStop(result, sourceId); + JSC::ExecState* exec = d->currentFrame; + exec->clearException(); + JSC::DynamicGlobalObjectScope dynamicGlobalObjectScope(exec, exec->scopeChain()->globalObject()); - Q_ASSERT(!exec->hadException()); - return d->scriptValueFromJSCValue(result); + return d->evaluateHelper(exec, debugger, sourceId, program_d->executable); } /*! diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h index f1fc135..c7e9f2a 100644 --- a/src/script/api/qscriptengine_p.h +++ b/src/script/api/qscriptengine_p.h @@ -70,6 +70,7 @@ namespace JSC { + class EvalExecutable; class ExecState; typedef ExecState CallFrame; class JSCell; @@ -196,6 +197,9 @@ public: const QByteArray &targetType, void **result); + QScriptValue evaluateHelper(JSC::ExecState *exec, JSC::Debugger* debugger, + intptr_t sourceId, JSC::EvalExecutable *executable); + QScript::QObjectData *qobjectData(QObject *object); void disposeQObject(QObject *object); void emitSignalHandlerException(); -- cgit v0.12 From e1ae391b679c188f8f9c86dd4af0c26300b14bd6 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Fri, 23 Oct 2009 10:21:37 +0200 Subject: add getter functions and comparison operators to QScriptProgram --- src/script/api/qscriptprogram.cpp | 53 +++++++++++++++++++++++++++++++++++++++ src/script/api/qscriptprogram.h | 7 ++++++ 2 files changed, 60 insertions(+) diff --git a/src/script/api/qscriptprogram.cpp b/src/script/api/qscriptprogram.cpp index 96760ba..9f88363 100644 --- a/src/script/api/qscriptprogram.cpp +++ b/src/script/api/qscriptprogram.cpp @@ -134,4 +134,57 @@ bool QScriptProgram::isValid() const return (d && d->engine); } +/*! + Returns the source code of this program. +*/ +QString QScriptProgram::sourceCode() const +{ + Q_D(const QScriptProgram); + if (!d) + return QString(); + return d->executable->source().toString(); +} + +/*! + Returns the filename associated with this program. +*/ +QString QScriptProgram::fileName() const +{ + Q_D(const QScriptProgram); + if (!d) + return QString(); + return d->executable->sourceURL(); +} + +/*! + Returns the line number associated with this program. +*/ +int QScriptProgram::lineNumber() const +{ + Q_D(const QScriptProgram); + if (!d) + return -1; + return d->executable->lineNo(); +} + +/*! + Returns true if this QScriptProgram is equal to \a other; + otherwise returns false. +*/ +bool QScriptProgram::operator==(const QScriptProgram &other) const +{ + return (sourceCode() == other.sourceCode()) + && (fileName() == other.fileName()) + && (lineNumber() == other.lineNumber()); +} + +/*! + Returns true if this QScriptProgram is not equal to \a other; + otherwise returns false. +*/ +bool QScriptProgram::operator!=(const QScriptProgram &other) const +{ + return !operator==(other); +} + QT_END_NAMESPACE diff --git a/src/script/api/qscriptprogram.h b/src/script/api/qscriptprogram.h index 6c2ba47..b6782b8 100644 --- a/src/script/api/qscriptprogram.h +++ b/src/script/api/qscriptprogram.h @@ -62,6 +62,13 @@ public: bool isValid() const; + QString sourceCode() const; + QString fileName() const; + int lineNumber() const; + + bool operator==(const QScriptProgram &other) const; + bool operator!=(const QScriptProgram &other) const; + private: QExplicitlySharedDataPointer d_ptr; Q_DECLARE_PRIVATE(QScriptProgram) -- cgit v0.12 From b824fc37d618e55bd128bacebb78dc3770c73264 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Fri, 23 Oct 2009 10:22:08 +0200 Subject: add some autotests for QScriptProgram --- tests/auto/qscriptengine/tst_qscriptengine.cpp | 81 ++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index 25ee00f..c00bde6 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -44,6 +44,7 @@ #include #include +#include #include #include #include @@ -151,6 +152,7 @@ private slots: void installTranslatorFunctions(); void functionScopes(); void nativeFunctionScopes(); + void compileAndEvaluate(); void qRegExpInport_data(); void qRegExpInport(); @@ -4289,6 +4291,85 @@ void tst_QScriptEngine::nativeFunctionScopes() } } +void tst_QScriptEngine::compileAndEvaluate() +{ + QScriptEngine eng; + + { + QString code("1 + 2"); + QString fileName("hello.js"); + int lineNumber(123); + QScriptProgram program = eng.compile(code, fileName, lineNumber); + QVERIFY(program.isValid()); + QCOMPARE(program.sourceCode(), code); + QCOMPARE(program.fileName(), fileName); + QCOMPARE(program.lineNumber(), lineNumber); + + QScriptValue expected = eng.evaluate(code); + QScriptValue ret = eng.evaluate(program); + QVERIFY(ret.equals(expected)); + } + + // Program that accesses variable in the scope + { + QScriptProgram program = eng.compile("a"); + QVERIFY(program.isValid()); + { + QScriptValue ret = eng.evaluate(program); + QVERIFY(ret.isError()); + QCOMPARE(ret.toString(), QString::fromLatin1("ReferenceError: Can't find variable: a")); + } + + QScriptValue obj = eng.newObject(); + obj.setProperty("a", 123); + QScriptContext *ctx = eng.currentContext(); + ctx->pushScope(obj); + { + QScriptValue ret = eng.evaluate(program); + QVERIFY(!ret.isError()); + QVERIFY(ret.equals(obj.property("a"))); + } + + obj.setProperty("a", QScriptValue()); + { + QScriptValue ret = eng.evaluate(program); + QVERIFY(ret.isError()); + } + + QScriptValue obj2 = eng.newObject(); + obj2.setProperty("a", 456); + ctx->pushScope(obj2); + { + QScriptValue ret = eng.evaluate(program); + QVERIFY(!ret.isError()); + QVERIFY(ret.equals(obj2.property("a"))); + } + + ctx->popScope(); + } + + // Program that creates closure + { + QScriptProgram program = eng.compile("(function() { var count = 0; return function() { return count++; }; })"); + QVERIFY(program.isValid()); + QScriptValue createCounter = eng.evaluate(program); + QVERIFY(createCounter.isFunction()); + QScriptValue counter = createCounter.call(); + QVERIFY(counter.isFunction()); + { + QScriptValue ret = counter.call(); + QVERIFY(ret.isNumber()); + } + QScriptValue counter2 = createCounter.call(); + QVERIFY(counter2.isFunction()); + QVERIFY(!counter2.equals(counter)); + { + QScriptValue ret = counter2.call(); + QVERIFY(ret.isNumber()); + } + } +} + static QRegExp minimal(QRegExp r) { r.setMinimal(true); return r; } void tst_QScriptEngine::qRegExpInport_data() -- cgit v0.12 From c21d3a0094b0692f2f888b04e258229234200e3c Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Fri, 23 Oct 2009 14:45:13 +0200 Subject: Refactor QScriptProgram and related API Get rid of QScriptEngine::compile(); you pass arguments to the QScriptProgram constructor instead. evaluate() will lazily compile the program the first time it is evaluated, then use the cached, compiled form on subsequent calls. --- src/script/api/qscriptengine.cpp | 118 ++++++++------------- src/script/api/qscriptengine.h | 1 - src/script/api/qscriptengine_p.h | 5 +- src/script/api/qscriptprogram.cpp | 61 +++++++---- src/script/api/qscriptprogram.h | 7 +- src/script/api/qscriptprogram_p.h | 21 ++-- tests/auto/qscriptengine/tst_qscriptengine.cpp | 45 ++++++-- .../qscriptengineagent/tst_qscriptengineagent.cpp | 87 +++++++++++++++ 8 files changed, 231 insertions(+), 114 deletions(-) diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index 25f815f..9bc4d6b 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -1188,9 +1188,36 @@ void QScriptEnginePrivate::agentDeleted(QScriptEngineAgent *agent) } } -QScriptValue QScriptEnginePrivate::evaluateHelper(JSC::ExecState *exec, JSC::Debugger* debugger, - intptr_t sourceId, JSC::EvalExecutable *executable) +JSC::JSValue QScriptEnginePrivate::evaluateHelper(JSC::ExecState *exec, intptr_t sourceId, + JSC::EvalExecutable *executable, + bool &compile) { + JSC::JSLock lock(false); // ### hmmm + QBoolBlocker inEvalBlocker(inEval, true); + q_func()->currentContext()->activationObject(); //force the creation of a context for native function; + + JSC::Debugger* debugger = originalGlobalObject()->debugger(); + if (debugger) + debugger->evaluateStart(sourceId); + + exec->clearException(); + JSC::DynamicGlobalObjectScope dynamicGlobalObjectScope(exec, exec->scopeChain()->globalObject()); + + if (compile) { + JSC::JSObject* error = executable->compile(exec, exec->scopeChain()); + if (error) { + compile = false; + exec->setException(error); + + if (debugger) { + debugger->exceptionThrow(JSC::DebuggerCallFrame(exec, error), sourceId, false); + debugger->evaluateStop(error, sourceId); + } + + return error; + } + } + JSC::JSValue thisValue = thisForContext(exec); JSC::JSObject* thisObject = (!thisValue || thisValue.isUndefinedOrNull()) ? exec->dynamicGlobalObject() : thisValue.toObject(exec); @@ -1208,7 +1235,7 @@ QScriptValue QScriptEnginePrivate::evaluateHelper(JSC::ExecState *exec, JSC::Deb if (debugger) debugger->evaluateStop(scriptValueToJSCValue(abortResult), sourceId); - return abortResult; + return scriptValueToJSCValue(abortResult); } if (exceptionValue) { @@ -1217,14 +1244,14 @@ QScriptValue QScriptEnginePrivate::evaluateHelper(JSC::ExecState *exec, JSC::Deb if (debugger) debugger->evaluateStop(exceptionValue, sourceId); - return scriptValueFromJSCValue(exceptionValue); + return exceptionValue; } if (debugger) debugger->evaluateStop(result, sourceId); Q_ASSERT(!exec->hadException()); - return scriptValueFromJSCValue(result); + return result; } #ifndef QT_NO_QOBJECT @@ -2187,66 +2214,15 @@ QScriptSyntaxCheckResult QScriptEnginePrivate::checkSyntax(const QString &progra QScriptValue QScriptEngine::evaluate(const QString &program, const QString &fileName, int lineNumber) { Q_D(QScriptEngine); - - JSC::JSLock lock(false); // ### hmmm - QBoolBlocker inEval(d->inEval, true); - currentContext()->activationObject(); //force the creation of a context for native function; - - JSC::UString jscProgram = program; - JSC::UString jscFileName = fileName; - JSC::ExecState* exec = d->currentFrame; WTF::PassRefPtr provider - = QScript::UStringSourceProviderWithFeedback::create(jscProgram, jscFileName, lineNumber, d); + = QScript::UStringSourceProviderWithFeedback::create(program, fileName, lineNumber, d); intptr_t sourceId = provider->asID(); JSC::SourceCode source(provider, lineNumber); //after construction of SourceCode provider variable will be null. - JSC::Debugger* debugger = d->originalGlobalObject()->debugger(); - if (debugger) - debugger->evaluateStart(sourceId); - - exec->clearException(); - JSC::DynamicGlobalObjectScope dynamicGlobalObjectScope(exec, exec->scopeChain()->globalObject()); - - JSC::EvalExecutable executable(exec, source); - JSC::JSObject* error = executable.compile(exec, exec->scopeChain()); - if (error) { - exec->setException(error); - - if (debugger) { - debugger->exceptionThrow(JSC::DebuggerCallFrame(exec, error), sourceId, false); - debugger->evaluateStop(error, sourceId); - } - - return d->scriptValueFromJSCValue(error); - } - - return d->evaluateHelper(exec, debugger, sourceId, &executable); -} - -/*! - \internal - \since 4.6 -*/ -QScriptProgram QScriptEngine::compile(const QString &program, const QString &fileName, int lineNumber) -{ - Q_D(QScriptEngine); - JSC::UString jscProgram = program; - JSC::UString jscFileName = fileName; - WTF::PassRefPtr provider - = QScript::UStringSourceProviderWithFeedback::create(jscProgram, jscFileName, lineNumber, d); - JSC::SourceCode source(provider, lineNumber); //after construction of SourceCode provider variable will be null. - JSC::ExecState* exec = d->currentFrame; - exec->clearException(); - JSC::DynamicGlobalObjectScope dynamicGlobalObjectScope(exec, exec->scopeChain()->globalObject()); - - JSC::EvalExecutable *executable = new JSC::EvalExecutable(exec, source); - JSC::JSObject* error = executable->compile(exec, exec->scopeChain()); - if (error != 0) { - delete executable; - return QScriptProgram(); - } - return QScriptProgramPrivate::create(d, executable, provider->asID()); + JSC::EvalExecutable executable(exec, source); + bool compile = true; + return d->scriptValueFromJSCValue(d->evaluateHelper(exec, sourceId, &executable, compile)); } /*! @@ -2257,23 +2233,17 @@ QScriptValue QScriptEngine::evaluate(const QScriptProgram &program) { Q_D(QScriptEngine); QScriptProgramPrivate *program_d = QScriptProgramPrivate::get(program); - if (!program_d || !program_d->engine || !program_d->executable) + if (!program_d) return QScriptValue(); - JSC::JSLock lock(false); - QBoolBlocker inEval(d->inEval, true); - currentContext()->activationObject(); //force the creation of a context for native function; - - intptr_t sourceId = program_d->sourceId; - JSC::Debugger* debugger = d->originalGlobalObject()->debugger(); - if (debugger) - debugger->evaluateStart(sourceId); - JSC::ExecState* exec = d->currentFrame; - exec->clearException(); - JSC::DynamicGlobalObjectScope dynamicGlobalObjectScope(exec, exec->scopeChain()->globalObject()); - - return d->evaluateHelper(exec, debugger, sourceId, program_d->executable); + JSC::EvalExecutable *executable = program_d->executable(exec, d); + bool compile = !program_d->isCompiled; + JSC::JSValue result = d->evaluateHelper(exec, program_d->sourceId, + executable, compile); + if (compile) + program_d->isCompiled = true; + return d->scriptValueFromJSCValue(result); } /*! diff --git a/src/script/api/qscriptengine.h b/src/script/api/qscriptengine.h index c58bb7c..3f438da 100644 --- a/src/script/api/qscriptengine.h +++ b/src/script/api/qscriptengine.h @@ -167,7 +167,6 @@ public: QScriptValue evaluate(const QString &program, const QString &fileName = QString(), int lineNumber = 1); - QScriptProgram compile(const QString &program, const QString &fileName = QString(), int lineNumber = 1); QScriptValue evaluate(const QScriptProgram &program); bool isEvaluating() const; diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h index c7e9f2a..22de29c 100644 --- a/src/script/api/qscriptengine_p.h +++ b/src/script/api/qscriptengine_p.h @@ -197,8 +197,9 @@ public: const QByteArray &targetType, void **result); - QScriptValue evaluateHelper(JSC::ExecState *exec, JSC::Debugger* debugger, - intptr_t sourceId, JSC::EvalExecutable *executable); + JSC::JSValue evaluateHelper(JSC::ExecState *exec, intptr_t sourceId, + JSC::EvalExecutable *executable, + bool &compile); QScript::QObjectData *qobjectData(QObject *object); void disposeQObject(QObject *object); diff --git a/src/script/api/qscriptprogram.cpp b/src/script/api/qscriptprogram.cpp index 9f88363..3ea4fa7 100644 --- a/src/script/api/qscriptprogram.cpp +++ b/src/script/api/qscriptprogram.cpp @@ -58,17 +58,18 @@ QT_BEGIN_NAMESPACE */ -QScriptProgramPrivate::QScriptProgramPrivate(QScriptEnginePrivate *e, - JSC::EvalExecutable *x, - intptr_t id) - : engine(e), executable(x), sourceId(id) +QScriptProgramPrivate::QScriptProgramPrivate(const QString &src, + const QString &fn, + int ln) + : sourceCode(src), fileName(fn), lineNumber(ln), + engine(0), _executable(0), sourceId(-1), isCompiled(false) { ref = 0; } QScriptProgramPrivate::~QScriptProgramPrivate() { - delete executable; + delete _executable; } QScriptProgramPrivate *QScriptProgramPrivate::get(const QScriptProgram &q) @@ -76,18 +77,26 @@ QScriptProgramPrivate *QScriptProgramPrivate::get(const QScriptProgram &q) return const_cast(q.d_func()); } -QScriptProgram QScriptProgramPrivate::create(QScriptEnginePrivate *engine, - JSC::EvalExecutable *executable, - intptr_t sourceId) +JSC::EvalExecutable *QScriptProgramPrivate::executable(JSC::ExecState *exec, + QScriptEnginePrivate *eng) { - QScriptProgramPrivate *d = new QScriptProgramPrivate(engine, executable, sourceId); - QScriptProgram result; - result.d_ptr = d; - return result; + if (_executable) { + if (eng == engine) + return _executable; + delete _executable; + } + WTF::PassRefPtr provider + = QScript::UStringSourceProviderWithFeedback::create(sourceCode, fileName, lineNumber, eng); + sourceId = provider->asID(); + JSC::SourceCode source(provider, lineNumber); //after construction of SourceCode provider variable will be null. + _executable = new JSC::EvalExecutable(exec, source); + engine = eng; + isCompiled = false; + return _executable; } /*! - Constructs an invalid QScriptProgram. + Constructs a null QScriptProgram. */ QScriptProgram::QScriptProgram() : d_ptr(0) @@ -95,6 +104,17 @@ QScriptProgram::QScriptProgram() } /*! + Constructs a new QScriptProgram with the given \a sourceCode, \a + fileName and \a lineNumber. +*/ +QScriptProgram::QScriptProgram(const QString &sourceCode, + const QString fileName, + int lineNumber) + : d_ptr(new QScriptProgramPrivate(sourceCode, fileName, lineNumber)) +{ +} + +/*! Constructs a new QScriptProgram that is a copy of \a other. */ QScriptProgram::QScriptProgram(const QScriptProgram &other) @@ -125,13 +145,13 @@ QScriptProgram &QScriptProgram::operator=(const QScriptProgram &other) } /*! - Returns true if this QScriptProgram is valid; otherwise + Returns true if this QScriptProgram is null; otherwise returns false. */ -bool QScriptProgram::isValid() const +bool QScriptProgram::isNull() const { Q_D(const QScriptProgram); - return (d && d->engine); + return (d == 0); } /*! @@ -142,7 +162,7 @@ QString QScriptProgram::sourceCode() const Q_D(const QScriptProgram); if (!d) return QString(); - return d->executable->source().toString(); + return d->sourceCode; } /*! @@ -153,7 +173,7 @@ QString QScriptProgram::fileName() const Q_D(const QScriptProgram); if (!d) return QString(); - return d->executable->sourceURL(); + return d->fileName; } /*! @@ -164,7 +184,7 @@ int QScriptProgram::lineNumber() const Q_D(const QScriptProgram); if (!d) return -1; - return d->executable->lineNo(); + return d->lineNumber; } /*! @@ -173,6 +193,9 @@ int QScriptProgram::lineNumber() const */ bool QScriptProgram::operator==(const QScriptProgram &other) const { + Q_D(const QScriptProgram); + if (d == other.d_func()) + return true; return (sourceCode() == other.sourceCode()) && (fileName() == other.fileName()) && (lineNumber() == other.lineNumber()); diff --git a/src/script/api/qscriptprogram.h b/src/script/api/qscriptprogram.h index b6782b8..6ab56dc 100644 --- a/src/script/api/qscriptprogram.h +++ b/src/script/api/qscriptprogram.h @@ -44,6 +44,8 @@ #include +#include + QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -55,12 +57,15 @@ class Q_SCRIPT_EXPORT QScriptProgram { public: QScriptProgram(); + QScriptProgram(const QString &sourceCode, + const QString fileName = QString(), + int lineNumber = 1); QScriptProgram(const QScriptProgram &other); ~QScriptProgram(); QScriptProgram &operator=(const QScriptProgram &other); - bool isValid() const; + bool isNull() const; QString sourceCode() const; QString fileName() const; diff --git a/src/script/api/qscriptprogram_p.h b/src/script/api/qscriptprogram_p.h index fe06b38..861ef32 100644 --- a/src/script/api/qscriptprogram_p.h +++ b/src/script/api/qscriptprogram_p.h @@ -58,6 +58,7 @@ namespace JSC { class EvalExecutable; + class ExecState; } QT_BEGIN_NAMESPACE @@ -67,20 +68,26 @@ class QScriptEnginePrivate; class QScriptProgramPrivate { public: - QScriptProgramPrivate(QScriptEnginePrivate*, - JSC::EvalExecutable*, - intptr_t); + QScriptProgramPrivate(const QString &sourceCode, + const QString &fileName, + int lineNumber); ~QScriptProgramPrivate(); static QScriptProgramPrivate *get(const QScriptProgram &q); - static QScriptProgram create(QScriptEnginePrivate*, - JSC::EvalExecutable*, - intptr_t); + + JSC::EvalExecutable *executable(JSC::ExecState *exec, + QScriptEnginePrivate *engine); QBasicAtomicInt ref; + + QString sourceCode; + QString fileName; + int lineNumber; + QScriptEnginePrivate *engine; - JSC::EvalExecutable *executable; + JSC::EvalExecutable *_executable; intptr_t sourceId; + bool isCompiled; }; QT_END_NAMESPACE diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index c00bde6..062cbfa 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -152,7 +152,7 @@ private slots: void installTranslatorFunctions(); void functionScopes(); void nativeFunctionScopes(); - void compileAndEvaluate(); + void evaluateProgram(); void qRegExpInport_data(); void qRegExpInport(); @@ -4291,7 +4291,7 @@ void tst_QScriptEngine::nativeFunctionScopes() } } -void tst_QScriptEngine::compileAndEvaluate() +void tst_QScriptEngine::evaluateProgram() { QScriptEngine eng; @@ -4299,21 +4299,23 @@ void tst_QScriptEngine::compileAndEvaluate() QString code("1 + 2"); QString fileName("hello.js"); int lineNumber(123); - QScriptProgram program = eng.compile(code, fileName, lineNumber); - QVERIFY(program.isValid()); + QScriptProgram program(code, fileName, lineNumber); + QVERIFY(!program.isNull()); QCOMPARE(program.sourceCode(), code); QCOMPARE(program.fileName(), fileName); QCOMPARE(program.lineNumber(), lineNumber); QScriptValue expected = eng.evaluate(code); - QScriptValue ret = eng.evaluate(program); - QVERIFY(ret.equals(expected)); + for (int x = 0; x < 10; ++x) { + QScriptValue ret = eng.evaluate(program); + QVERIFY(ret.equals(expected)); + } } // Program that accesses variable in the scope { - QScriptProgram program = eng.compile("a"); - QVERIFY(program.isValid()); + QScriptProgram program("a"); + QVERIFY(!program.isNull()); { QScriptValue ret = eng.evaluate(program); QVERIFY(ret.isError()); @@ -4350,8 +4352,8 @@ void tst_QScriptEngine::compileAndEvaluate() // Program that creates closure { - QScriptProgram program = eng.compile("(function() { var count = 0; return function() { return count++; }; })"); - QVERIFY(program.isValid()); + QScriptProgram program("(function() { var count = 0; return function() { return count++; }; })"); + QVERIFY(!program.isNull()); QScriptValue createCounter = eng.evaluate(program); QVERIFY(createCounter.isFunction()); QScriptValue counter = createCounter.call(); @@ -4368,6 +4370,29 @@ void tst_QScriptEngine::compileAndEvaluate() QVERIFY(ret.isNumber()); } } + + // Same program run in different engines + { + QString code("1 + 2"); + QScriptProgram program(code); + QVERIFY(!program.isNull()); + double expected = eng.evaluate(program).toNumber(); + for (int x = 0; x < 2; ++x) { + QScriptEngine eng2; + for (int y = 0; y < 2; ++y) { + double ret = eng2.evaluate(program).toNumber(); + QCOMPARE(ret, expected); + } + } + } + + // No program + { + QScriptProgram program; + QVERIFY(program.isNull()); + QScriptValue ret = eng.evaluate(program); + QVERIFY(!ret.isValid()); + } } static QRegExp minimal(QRegExp r) { r.setMinimal(true); return r; } diff --git a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp index 283e489..bdb0414 100644 --- a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp +++ b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp @@ -44,6 +44,7 @@ #include #include +#include #include //TESTED_CLASS= @@ -109,6 +110,9 @@ private slots: void extension_invoctaion(); void extension(); void isEvaluatingInExtension(); + void evaluateProgram(); + void evaluateProgram_SyntaxError(); + void evaluateNullProgram(); private: double m_testProperty; @@ -2182,5 +2186,88 @@ void tst_QScriptEngineAgent::isEvaluatingInExtension() QVERIFY(spy->wasEvaluating); } +void tst_QScriptEngineAgent::evaluateProgram() +{ + QScriptEngine eng; + QScriptProgram program("1 + 2", "foo.js", 123); + ScriptEngineSpy *spy = new ScriptEngineSpy(&eng); + qint64 scriptId = -1; + for (int x = 0; x < 10; ++x) { + spy->clear(); + (void)eng.evaluate(program); + QCOMPARE(spy->count(), (x == 0) ? 4 : 3); + + if (x == 0) { + // script is only loaded on first execution + QCOMPARE(spy->at(0).type, ScriptEngineEvent::ScriptLoad); + scriptId = spy->at(0).scriptId; + QVERIFY(scriptId != -1); + QCOMPARE(spy->at(0).script, program.sourceCode()); + QCOMPARE(spy->at(0).fileName, program.fileName()); + QCOMPARE(spy->at(0).lineNumber, program.lineNumber()); + spy->removeFirst(); + } + + QCOMPARE(spy->at(0).type, ScriptEngineEvent::FunctionEntry); // evaluate() + QCOMPARE(spy->at(0).scriptId, scriptId); + + QCOMPARE(spy->at(1).type, ScriptEngineEvent::PositionChange); + QCOMPARE(spy->at(1).scriptId, scriptId); + QCOMPARE(spy->at(1).lineNumber, program.lineNumber()); + + QCOMPARE(spy->at(2).type, ScriptEngineEvent::FunctionExit); // evaluate() + QCOMPARE(spy->at(2).scriptId, scriptId); + QVERIFY(spy->at(2).value.isNumber()); + QCOMPARE(spy->at(2).value.toNumber(), qsreal(3)); + } +} + +void tst_QScriptEngineAgent::evaluateProgram_SyntaxError() +{ + QScriptEngine eng; + QScriptProgram program("this is not valid syntax", "foo.js", 123); + ScriptEngineSpy *spy = new ScriptEngineSpy(&eng); + qint64 scriptId = -1; + for (int x = 0; x < 10; ++x) { + spy->clear(); + (void)eng.evaluate(program); + QCOMPARE(spy->count(), (x == 0) ? 8 : 7); + + if (x == 0) { + // script is only loaded on first execution + QCOMPARE(spy->at(0).type, ScriptEngineEvent::ScriptLoad); + scriptId = spy->at(0).scriptId; + QVERIFY(scriptId != -1); + QCOMPARE(spy->at(0).script, program.sourceCode()); + QCOMPARE(spy->at(0).fileName, program.fileName()); + QCOMPARE(spy->at(0).lineNumber, program.lineNumber()); + spy->removeFirst(); + } + + QCOMPARE(spy->at(0).type, ScriptEngineEvent::FunctionEntry); // evaluate() + QCOMPARE(spy->at(0).scriptId, scriptId); + + QCOMPARE(spy->at(1).type, ScriptEngineEvent::ContextPush); // SyntaxError constructor + QCOMPARE(spy->at(2).type, ScriptEngineEvent::FunctionEntry); // SyntaxError constructor + QCOMPARE(spy->at(3).type, ScriptEngineEvent::FunctionExit); // SyntaxError constructor + QCOMPARE(spy->at(4).type, ScriptEngineEvent::ContextPop); // SyntaxError constructor + + QCOMPARE(spy->at(5).type, ScriptEngineEvent::ExceptionThrow); + QVERIFY(spy->at(5).value.isError()); + QCOMPARE(spy->at(5).value.toString(), QString::fromLatin1("SyntaxError: Parse error")); + + QCOMPARE(spy->at(6).type, ScriptEngineEvent::FunctionExit); // evaluate() + QCOMPARE(spy->at(6).scriptId, scriptId); + } +} + +void tst_QScriptEngineAgent::evaluateNullProgram() +{ + QScriptEngine eng; + ScriptEngineSpy *spy = new ScriptEngineSpy(&eng); + (void)eng.evaluate(QScriptProgram()); + QCOMPARE(spy->count(), 0); +} + QTEST_MAIN(tst_QScriptEngineAgent) #include "tst_qscriptengineagent.moc" -- cgit v0.12 From 6cd67bb07271950cca86dcad764b8581da588a51 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Fri, 23 Oct 2009 15:14:41 +0200 Subject: add benchmark for QScriptEngine::evaluate(QScriptProgram) --- tests/benchmarks/qscriptengine/tst_qscriptengine.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/benchmarks/qscriptengine/tst_qscriptengine.cpp b/tests/benchmarks/qscriptengine/tst_qscriptengine.cpp index 4f011c4..8d5f6e6 100644 --- a/tests/benchmarks/qscriptengine/tst_qscriptengine.cpp +++ b/tests/benchmarks/qscriptengine/tst_qscriptengine.cpp @@ -60,6 +60,8 @@ private slots: void constructor(); void evaluate_data(); void evaluate(); + void evaluateProgram_data(); + void evaluateProgram(); void connectAndDisconnect(); void newObject(); void newQObject(); @@ -153,6 +155,22 @@ void tst_QScriptEngine::connectAndDisconnect() } } +void tst_QScriptEngine::evaluateProgram_data() +{ + evaluate_data(); +} + +void tst_QScriptEngine::evaluateProgram() +{ + QFETCH(QString, code); + QScriptEngine engine; + QScriptProgram program(code); + + QBENCHMARK { + (void)engine.evaluate(program); + } +} + void tst_QScriptEngine::newObject() { QScriptEngine engine; @@ -241,6 +259,5 @@ void tst_QScriptEngine::nativeCall() } } - QTEST_MAIN(tst_QScriptEngine) #include "tst_qscriptengine.moc" -- cgit v0.12 From 0d6104d763f4cb32ac6117b3f951afcb73fc50e6 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Mon, 26 Oct 2009 10:33:38 +1000 Subject: Make compile on X11 systems where qreal == float Reviewed-by: Sarah Smith --- src/gui/text/qfontdatabase_x11.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/text/qfontdatabase_x11.cpp b/src/gui/text/qfontdatabase_x11.cpp index b582e4a..f184811 100644 --- a/src/gui/text/qfontdatabase_x11.cpp +++ b/src/gui/text/qfontdatabase_x11.cpp @@ -1456,7 +1456,7 @@ void qt_addPatternProps(FcPattern *pattern, int screen, int script, const QFontD slant_value = FC_SLANT_OBLIQUE; FcPatternAddInteger(pattern, FC_SLANT, slant_value); - double size_value = qMax(1., request.pixelSize); + double size_value = qMax(qreal(1.), request.pixelSize); FcPatternAddDouble(pattern, FC_PIXEL_SIZE, size_value); int stretch = request.stretch; -- cgit v0.12 From 1a299a9631a2d1b4e07cedfece7af5318a766fe6 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Mon, 26 Oct 2009 10:36:45 +1000 Subject: Optimize QGraphicsRotation's use of QMatrix4x4 Previous code was creating a full 3D rotation matrix and then projecting back to 2D. This change combines the two steps into one to avoid calculating matrix components that will be dropped. Reviewed-by: Sarah Smith --- src/gui/graphicsview/qgraphicstransform.cpp | 4 +- src/gui/math3d/qmatrix4x4.cpp | 108 ++++++++++++++++++++- src/gui/math3d/qmatrix4x4.h | 4 + .../qgraphicstransform/tst_qgraphicstransform.cpp | 69 ++++++++++++- 4 files changed, 179 insertions(+), 6 deletions(-) diff --git a/src/gui/graphicsview/qgraphicstransform.cpp b/src/gui/graphicsview/qgraphicstransform.cpp index a0b5493..93dc196 100644 --- a/src/gui/graphicsview/qgraphicstransform.cpp +++ b/src/gui/graphicsview/qgraphicstransform.cpp @@ -547,9 +547,7 @@ void QGraphicsRotation::applyTo(QMatrix4x4 *matrix) const return; matrix->translate(d->origin); - QMatrix4x4 m; - m.rotate(d->angle, d->axis.x(), d->axis.y(), d->axis.z()); - *matrix *= m.toTransform(1024.0f); // Project back to 2D. + matrix->projectedRotate(d->angle, d->axis.x(), d->axis.y(), d->axis.z()); matrix->translate(-d->origin); } diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp index 00e8f15..fa3826f 100644 --- a/src/gui/math3d/qmatrix4x4.cpp +++ b/src/gui/math3d/qmatrix4x4.cpp @@ -58,6 +58,8 @@ QT_BEGIN_NAMESPACE \sa QVector3D, QGenericMatrix */ +static const qreal inv_dist_to_plane = 1. / 1024.; + /*! \fn QMatrix4x4::QMatrix4x4() @@ -1103,6 +1105,110 @@ QMatrix4x4& QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z) return *this; } +/*! + \internal +*/ +QMatrix4x4& QMatrix4x4::projectedRotate(qreal angle, qreal x, qreal y, qreal z) +{ + // Used by QGraphicsRotation::applyTo() to perform a rotation + // and projection back to 2D in a single step. + if (angle == 0.0f) + return *this; + QMatrix4x4 m(1); // The "1" says to not load the identity. + qreal c, s, ic; + if (angle == 90.0f || angle == -270.0f) { + s = 1.0f; + c = 0.0f; + } else if (angle == -90.0f || angle == 270.0f) { + s = -1.0f; + c = 0.0f; + } else if (angle == 180.0f || angle == -180.0f) { + s = 0.0f; + c = -1.0f; + } else { + qreal a = angle * M_PI / 180.0f; + c = qCos(a); + s = qSin(a); + } + bool quick = false; + if (x == 0.0f) { + if (y == 0.0f) { + if (z != 0.0f) { + // Rotate around the Z axis. + m.setIdentity(); + m.m[0][0] = c; + m.m[1][1] = c; + if (z < 0.0f) { + m.m[1][0] = s; + m.m[0][1] = -s; + } else { + m.m[1][0] = -s; + m.m[0][1] = s; + } + m.flagBits = General; + quick = true; + } + } else if (z == 0.0f) { + // Rotate around the Y axis. + m.setIdentity(); + m.m[0][0] = c; + m.m[2][2] = 1.0f; + if (y < 0.0f) { + m.m[0][3] = -s * inv_dist_to_plane; + } else { + m.m[0][3] = s * inv_dist_to_plane; + } + m.flagBits = General; + quick = true; + } + } else if (y == 0.0f && z == 0.0f) { + // Rotate around the X axis. + m.setIdentity(); + m.m[1][1] = c; + m.m[2][2] = 1.0f; + if (x < 0.0f) { + m.m[1][3] = s * inv_dist_to_plane; + } else { + m.m[1][3] = -s * inv_dist_to_plane; + } + m.flagBits = General; + quick = true; + } + if (!quick) { + qreal len = x * x + y * y + z * z; + if (!qFuzzyIsNull(len - 1.0f) && !qFuzzyIsNull(len)) { + len = qSqrt(len); + x /= len; + y /= len; + z /= len; + } + ic = 1.0f - c; + m.m[0][0] = x * x * ic + c; + m.m[1][0] = x * y * ic - z * s; + m.m[2][0] = 0.0f; + m.m[3][0] = 0.0f; + m.m[0][1] = y * x * ic + z * s; + m.m[1][1] = y * y * ic + c; + m.m[2][1] = 0.0f; + m.m[3][1] = 0.0f; + m.m[0][2] = 0.0f; + m.m[1][2] = 0.0f; + m.m[2][2] = 1.0f; + m.m[3][2] = 0.0f; + m.m[0][3] = (x * z * ic - y * s) * -inv_dist_to_plane; + m.m[1][3] = (y * z * ic + x * s) * -inv_dist_to_plane; + m.m[2][3] = 0.0f; + m.m[3][3] = 1.0f; + } + int flags = flagBits; + *this *= m; + if (flags != Identity) + flagBits = flags | Rotation; + else + flagBits = Rotation; + return *this; +} + #ifndef QT_NO_VECTOR4D /*! @@ -1448,8 +1554,6 @@ QTransform QMatrix4x4::toTransform() const m[3][0], m[3][1], m[3][3]); } -static const qreal inv_dist_to_plane = 1. / 1024.; - /*! Returns the conventional Qt 2D transformation matrix that corresponds to this matrix. diff --git a/src/gui/math3d/qmatrix4x4.h b/src/gui/math3d/qmatrix4x4.h index 42d992e..ba74b89 100644 --- a/src/gui/math3d/qmatrix4x4.h +++ b/src/gui/math3d/qmatrix4x4.h @@ -207,6 +207,10 @@ private: QMatrix4x4(int) { flagBits = General; } QMatrix4x4 orthonormalInverse() const; + + QMatrix4x4& projectedRotate(qreal angle, qreal x, qreal y, qreal z); + + friend class QGraphicsRotation; }; inline QMatrix4x4::QMatrix4x4 diff --git a/tests/auto/qgraphicstransform/tst_qgraphicstransform.cpp b/tests/auto/qgraphicstransform/tst_qgraphicstransform.cpp index eb5c099..d8ab06e 100644 --- a/tests/auto/qgraphicstransform/tst_qgraphicstransform.cpp +++ b/tests/auto/qgraphicstransform/tst_qgraphicstransform.cpp @@ -59,6 +59,8 @@ private slots: void rotation(); void rotation3d_data(); void rotation3d(); + void rotation3dArbitraryAxis_data(); + void rotation3dArbitraryAxis(); }; @@ -88,7 +90,7 @@ static QTransform transform2D(const QGraphicsTransform& t) { QMatrix4x4 m; t.applyTo(&m); - return m.toTransform(0); + return m.toTransform(); } void tst_QGraphicsTransform::scale() @@ -255,6 +257,19 @@ void tst_QGraphicsTransform::rotation3d() QVERIFY(fuzzyCompare(transform2D(rotation), expected)); + // Check that "rotation" produces the 4x4 form of the 3x3 matrix. + // i.e. third row and column are 0 0 1 0. + t.setIdentity(); + rotation.applyTo(&t); + QMatrix4x4 r(expected); + if (sizeof(qreal) == sizeof(float) && angle == 268) { + // This test fails, on only this angle, when qreal == float + // because the deg2rad value in QTransform is not accurate + // enough to match what QMatrix4x4 is doing. + } else { + QVERIFY(qFuzzyCompare(t, r)); + } + //now let's check that a null vector will not change the transform rotation.setAxis(QVector3D(0, 0, 0)); rotation.setOrigin(QVector3D(10, 10, 0)); @@ -276,6 +291,58 @@ void tst_QGraphicsTransform::rotation3d() QVERIFY(transform2D(rotation).isIdentity()); } +void tst_QGraphicsTransform::rotation3dArbitraryAxis_data() +{ + QTest::addColumn("axis"); + QTest::addColumn("angle"); + + QVector3D axis1 = QVector3D(1.0f, 1.0f, 1.0f); + QVector3D axis2 = QVector3D(2.0f, -3.0f, 0.5f); + QVector3D axis3 = QVector3D(-2.0f, 0.0f, -0.5f); + QVector3D axis4 = QVector3D(0.0001f, 0.0001f, 0.0001f); + QVector3D axis5 = QVector3D(0.01f, 0.01f, 0.01f); + + for (int angle = 0; angle <= 360; angle++) { + QTest::newRow("test rotation on (1, 1, 1)") << axis1 << qreal(angle); + QTest::newRow("test rotation on (2, -3, .5)") << axis2 << qreal(angle); + QTest::newRow("test rotation on (-2, 0, -.5)") << axis3 << qreal(angle); + QTest::newRow("test rotation on (.0001, .0001, .0001)") << axis4 << qreal(angle); + QTest::newRow("test rotation on (.01, .01, .01)") << axis5 << qreal(angle); + } +} + +void tst_QGraphicsTransform::rotation3dArbitraryAxis() +{ + QFETCH(QVector3D, axis); + QFETCH(qreal, angle); + + QGraphicsRotation rotation; + rotation.setAxis(axis); + + QMatrix4x4 t; + rotation.applyTo(&t); + + QVERIFY(t.isIdentity()); + QVERIFY(transform2D(rotation).isIdentity()); + + rotation.setAngle(angle); + + // Compute the expected answer using QMatrix4x4 and a projection. + // These two steps are performed in one hit by QGraphicsRotation. + QMatrix4x4 exp; + exp.rotate(angle, axis); + QTransform expected = exp.toTransform(1024.0f); + + QVERIFY(fuzzyCompare(transform2D(rotation), expected)); + + // Check that "rotation" produces the 4x4 form of the 3x3 matrix. + // i.e. third row and column are 0 0 1 0. + t.setIdentity(); + rotation.applyTo(&t); + QMatrix4x4 r(expected); + QVERIFY(qFuzzyCompare(t, r)); +} + QTEST_MAIN(tst_QGraphicsTransform) #include "tst_qgraphicstransform.moc" -- cgit v0.12 From e7c6757f53f81442c138f4354db958a893d9e611 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Mon, 26 Oct 2009 11:19:12 +1000 Subject: Fix ifdef around QMatrix4x4::rotate(QQuaternion) Reviewed-by: trustme --- src/gui/math3d/qmatrix4x4.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp index fa3826f..5d624d8 100644 --- a/src/gui/math3d/qmatrix4x4.cpp +++ b/src/gui/math3d/qmatrix4x4.cpp @@ -1209,7 +1209,7 @@ QMatrix4x4& QMatrix4x4::projectedRotate(qreal angle, qreal x, qreal y, qreal z) return *this; } -#ifndef QT_NO_VECTOR4D +#ifndef QT_NO_QUATERNION /*! Multiples this matrix by another that rotates coordinates according -- cgit v0.12 From fe23e4f9aeb782c6278ef5b6ff9375182325a7f1 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 26 Oct 2009 11:19:39 +1000 Subject: Avoid unnecessary trademark. --- examples/declarative/follow/pong.qml | 74 -------------------------------- examples/declarative/follow/tvtennis.qml | 74 ++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 74 deletions(-) delete mode 100644 examples/declarative/follow/pong.qml create mode 100644 examples/declarative/follow/tvtennis.qml diff --git a/examples/declarative/follow/pong.qml b/examples/declarative/follow/pong.qml deleted file mode 100644 index d39e913..0000000 --- a/examples/declarative/follow/pong.qml +++ /dev/null @@ -1,74 +0,0 @@ -import Qt 4.6 - -Rectangle { - id: page - width: 640; height: 480 - color: "Black" - - // Make a ball to bounce - Rectangle { - // Add a property for the target y coordinate - property var targetY : page.height - 10 - property var direction : "right" - - id: ball - color: "Lime" - x: 20; width: 20; height: 20; z: 1 - - // Move the ball to the right and back to the left repeatedly - x: SequentialAnimation { - running: true; repeat: true - NumberAnimation { to: page.width - 40; duration: 2000 } - ScriptAction { script: Qt.playSound('paddle.wav') } - PropertyAction { target: ball; property: "direction"; value: "left" } - NumberAnimation { to: 20; duration: 2000 } - ScriptAction { script: Qt.playSound('paddle.wav') } - PropertyAction { target: ball; property: "direction"; value: "right" } - } - - // Make y follow the target y coordinate, with a velocity of 200 - y: SpringFollow { source: ball.targetY; velocity: 200 } - - // Detect the ball hitting the top or bottom of the view and bounce it - onYChanged: { - if (y <= 0) { - Qt.playSound('click.wav'); - targetY = page.height - 20; - } else if (y >= page.height - 20) { - Qt.playSound('click.wav'); - targetY = 0; - } - } - } - - // Place bats to the left and right of the view, following the y - // coordinates of the ball. - Rectangle { - id: leftBat - color: "Lime" - x: 2; width: 20; height: 90 - y: SpringFollow { - source: ball.y - 45; velocity: 300 - enabled: ball.direction == 'left' - } - } - Rectangle { - id: rightBat - color: "Lime" - x: page.width - 22; width: 20; height: 90 - y: SpringFollow { - source: ball.y-45; velocity: 300 - enabled: ball.direction == 'right' - } - } - - // The rest, to make it look realistic, if neither ever scores... - Rectangle { color: "Lime"; x: page.width/2-80; y: 0; width: 40; height: 60 } - Rectangle { color: "Black"; x: page.width/2-70; y: 10; width: 20; height: 40 } - Rectangle { color: "Lime"; x: page.width/2+40; y: 0; width: 40; height: 60 } - Rectangle { color: "Black"; x: page.width/2+50; y: 10; width: 20; height: 40 } - Repeater { - model: page.height / 20 - Rectangle { color: "Lime"; x: page.width/2-5; y: index * 20; width: 10; height: 10 } - } -} diff --git a/examples/declarative/follow/tvtennis.qml b/examples/declarative/follow/tvtennis.qml new file mode 100644 index 0000000..d39e913 --- /dev/null +++ b/examples/declarative/follow/tvtennis.qml @@ -0,0 +1,74 @@ +import Qt 4.6 + +Rectangle { + id: page + width: 640; height: 480 + color: "Black" + + // Make a ball to bounce + Rectangle { + // Add a property for the target y coordinate + property var targetY : page.height - 10 + property var direction : "right" + + id: ball + color: "Lime" + x: 20; width: 20; height: 20; z: 1 + + // Move the ball to the right and back to the left repeatedly + x: SequentialAnimation { + running: true; repeat: true + NumberAnimation { to: page.width - 40; duration: 2000 } + ScriptAction { script: Qt.playSound('paddle.wav') } + PropertyAction { target: ball; property: "direction"; value: "left" } + NumberAnimation { to: 20; duration: 2000 } + ScriptAction { script: Qt.playSound('paddle.wav') } + PropertyAction { target: ball; property: "direction"; value: "right" } + } + + // Make y follow the target y coordinate, with a velocity of 200 + y: SpringFollow { source: ball.targetY; velocity: 200 } + + // Detect the ball hitting the top or bottom of the view and bounce it + onYChanged: { + if (y <= 0) { + Qt.playSound('click.wav'); + targetY = page.height - 20; + } else if (y >= page.height - 20) { + Qt.playSound('click.wav'); + targetY = 0; + } + } + } + + // Place bats to the left and right of the view, following the y + // coordinates of the ball. + Rectangle { + id: leftBat + color: "Lime" + x: 2; width: 20; height: 90 + y: SpringFollow { + source: ball.y - 45; velocity: 300 + enabled: ball.direction == 'left' + } + } + Rectangle { + id: rightBat + color: "Lime" + x: page.width - 22; width: 20; height: 90 + y: SpringFollow { + source: ball.y-45; velocity: 300 + enabled: ball.direction == 'right' + } + } + + // The rest, to make it look realistic, if neither ever scores... + Rectangle { color: "Lime"; x: page.width/2-80; y: 0; width: 40; height: 60 } + Rectangle { color: "Black"; x: page.width/2-70; y: 10; width: 20; height: 40 } + Rectangle { color: "Lime"; x: page.width/2+40; y: 0; width: 40; height: 60 } + Rectangle { color: "Black"; x: page.width/2+50; y: 10; width: 20; height: 40 } + Repeater { + model: page.height / 20 + Rectangle { color: "Lime"; x: page.width/2-5; y: index * 20; width: 10; height: 10 } + } +} -- cgit v0.12 From 5d7f9e852a1de2c949ad6ca866d11a33b4152d29 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 26 Oct 2009 11:24:40 +1000 Subject: Fix assert with non-integer Rectangle radius. --- src/declarative/fx/qfxrect.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/declarative/fx/qfxrect.cpp b/src/declarative/fx/qfxrect.cpp index f35fe3d..d4207a6 100644 --- a/src/declarative/fx/qfxrect.cpp +++ b/src/declarative/fx/qfxrect.cpp @@ -43,6 +43,7 @@ #include "qfxrect_p.h" #include +#include QT_BEGIN_NAMESPACE QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Pen,QFxPen) @@ -338,7 +339,8 @@ void QFxRect::generateRoundedRect() Q_D(QFxRect); if (d->rectImage.isNull()) { const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; - d->rectImage = QPixmap(d->radius*2 + 3 + pw*2, d->radius*2 + 3 + pw*2); + const int radius = qCeil(d->radius); //ensure odd numbered width/height so we get 1-pixel center + d->rectImage = QPixmap(radius*2 + 3 + pw*2, radius*2 + 3 + pw*2); d->rectImage.fill(Qt::transparent); QPainter p(&(d->rectImage)); p.setRenderHint(QPainter::Antialiasing); @@ -361,7 +363,7 @@ void QFxRect::generateBorderedRect() Q_D(QFxRect); if (d->rectImage.isNull()) { const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; - d->rectImage = QPixmap(d->getPen()->width()*2 + 3 + pw*2, d->getPen()->width()*2 + 3 + pw*2); + d->rectImage = QPixmap(pw*2 + 3, pw*2 + 3); d->rectImage.fill(Qt::transparent); QPainter p(&(d->rectImage)); p.setRenderHint(QPainter::Antialiasing); @@ -439,6 +441,7 @@ void QFxRect::drawRect(QPainter &p) QMargins margins(xOffset, yOffset, xOffset, yOffset); QTileRules rules(Qt::StretchTile, Qt::StretchTile); + //NOTE: even though our item may have qreal-based width and height, qDrawBorderPixmap only supports QRects qDrawBorderPixmap(&p, QRect(-pw/2, -pw/2, width()+pw, height()+pw), margins, d->rectImage, d->rectImage.rect(), margins, rules); if (d->smooth) { -- cgit v0.12 From 4fbd2ad6c90fa4946595c715dedf712d77350fb8 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 26 Oct 2009 11:25:17 +1000 Subject: Doc. --- doc/src/declarative/pics/3d-rotation-axis.png | Bin 14304 -> 11078 bytes doc/src/declarative/pics/axisrotation.png | Bin 3425 -> 8891 bytes doc/src/snippets/declarative/rotation.qml | 16 ++++++----- src/declarative/fx/qfxitem.cpp | 37 +++++++++++++++----------- 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/doc/src/declarative/pics/3d-rotation-axis.png b/doc/src/declarative/pics/3d-rotation-axis.png index 1b17261..b940215 100644 Binary files a/doc/src/declarative/pics/3d-rotation-axis.png and b/doc/src/declarative/pics/3d-rotation-axis.png differ diff --git a/doc/src/declarative/pics/axisrotation.png b/doc/src/declarative/pics/axisrotation.png index 409a9e9..4cddcdf 100644 Binary files a/doc/src/declarative/pics/axisrotation.png and b/doc/src/declarative/pics/axisrotation.png differ diff --git a/doc/src/snippets/declarative/rotation.qml b/doc/src/snippets/declarative/rotation.qml index aaaebee..4a67dcb 100644 --- a/doc/src/snippets/declarative/rotation.qml +++ b/doc/src/snippets/declarative/rotation.qml @@ -4,25 +4,29 @@ Rectangle { width: 360; height: 80 color: "white" //! [0] - HorizontalLayout { - margin: 10 + Row { + x: 10; y: 10 spacing: 10 Image { source: "pics/qt.png" } Image { source: "pics/qt.png" - transform: Rotation { origin.x: 30; axis.y: 60; axis.z: 0 angle: 18 } + transform: Rotation { origin.x: 30; origin.y: 30; axis { x: 0; y: 1; z: 0 } angle: 18 } + smooth: true } Image { source: "pics/qt.png" - transform: Rotation { origin.x: 30; axis.y: 60; axis.z: 0 angle: 36 } + transform: Rotation { origin.x: 30; origin.y: 30; axis { x: 0; y: 1; z: 0 } angle: 36 } + smooth: true } Image { source: "pics/qt.png" - transform: Rotation { origin.x: 30; axis.y: 60; axis.z: 0; angle: 54 } + transform: Rotation { origin.x: 30; origin.y: 30; axis { x: 0; y: 1; z: 0 } angle: 54 } + smooth: true } Image { source: "pics/qt.png" - transform: Rotation { origin.x: 30; axis.y: 60; axis.z: 0; angle: 72 } + transform: Rotation { origin.x: 30; origin.y: 30; axis { x: 0; y: 1; z: 0 } angle: 72 } + smooth: true } } //! [0] diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index 317a284..b82a38d 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -79,15 +79,10 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Rotation,QGraphicsRotation) #include "qfxeffects.cpp" /*! - \qmlclass Transform - \brief A transformation. -*/ - -/*! \qmlclass Scale - \brief A Scale object provides a way to scale an Item. + \brief The Scale object provides a way to scale an Item. - The scale object gives more control over scaling than using Item's scale property. Specifically, + The Scale object gives more control over scaling than using Item's scale property. Specifically, it allows a different scale for the x and y axes, and allows the scale to be relative to an arbitrary point. @@ -105,13 +100,14 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Rotation,QGraphicsRotation) \qmlproperty real Scale::origin.x \qmlproperty real Scale::origin.y - The origin point for the scale. The scale will be relative to this point. + The point that the item is scaled from (i.e., the point that stays fixed relative to the parent as + the rest of the item grows). By default the origin is 0, 0. */ /*! \qmlproperty real Scale::xScale - The scaling factor for the X axis. + The scaling factor for the X axis. */ /*! @@ -122,7 +118,10 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Rotation,QGraphicsRotation) /*! \qmlclass Rotation - \brief A Rotation object provides a way to rotate an Item around a point using an axis in 3D space. + \brief The Rotation object provides a way to rotate an Item. + + The Rotation object gives more control over rotation than using Item's rotation property. + Specifically, it allows (z axis) rotation to be relative to an arbitrary point. The following example rotates a Rectangle around its interior point 25, 25: \qml @@ -133,7 +132,10 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Rotation,QGraphicsRotation) } \endqml - Here is an example of various rotations applied to an \l Image. + Rotation also provides a way to specify 3D-like rotations for Items. For these types of + rotations you must specify the axis to rotate around in addition to the origin point. + + The following example shows various 3D-like rotations applied to an \l Image. \snippet doc/src/snippets/declarative/rotation.qml 0 \image axisrotation.png @@ -143,7 +145,8 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Rotation,QGraphicsRotation) \qmlproperty real Rotation::origin.x \qmlproperty real Rotation::origin.y - The point to rotate around. + The origin point of the rotation (i.e., the point that stays fixed relative to the parent as + the rest of the item rotates). By default the origin is 0, 0. */ /*! @@ -151,16 +154,18 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Rotation,QGraphicsRotation) \qmlproperty real Rotation::axis.y \qmlproperty real Rotation::axis.z - A rotation axis is specified by a vector in 3D space By default the vector defines a rotation around the z-Axis. + The axis to rotate around. For simple (2D) rotation around a point, you do not need to specify an axis, + as the default axis is the z axis (\c{ axis { x: 0; y: 0; z: 0 } }). - \image 3d-rotation-axis.png + For a typical 3D-like rotation you will usually specify both the origin and the axis. + \image 3d-rotation-axis.png */ /*! \qmlproperty real Rotation::angle - The angle, in degrees, to rotate. + The angle to rotate, in degrees clockwise. */ @@ -2113,7 +2118,7 @@ void QFxItem::setBaselineOffset(qreal offset) /*! \qmlproperty real Item::rotation - This property holds the rotation of the item in degrees. + This property holds the rotation of the item in degrees clockwise. This specifies how many degrees to rotate the item around its transformOrigin. The default rotation is 0 degrees (i.e. not rotated at all). -- cgit v0.12 From 2b0cf3b6a2f1c49f40d6f50b4d24bdd87a4807fa Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Mon, 26 Oct 2009 11:36:00 +1000 Subject: Ensure cleanup happens before the destruction of QScriptEngine This was causing crashes on windows. --- src/declarative/qml/qml.pri | 2 + src/declarative/qml/qmlcleanup.cpp | 82 ++++++++++++++++++++++++++++++++ src/declarative/qml/qmlcleanup_p.h | 79 ++++++++++++++++++++++++++++++ src/declarative/qml/qmlengine.cpp | 11 ++++- src/declarative/qml/qmlengine_p.h | 4 ++ src/declarative/qml/qmlintegercache.cpp | 10 +++- src/declarative/qml/qmlintegercache_p.h | 7 ++- src/declarative/qml/qmlpropertycache.cpp | 14 +++++- src/declarative/qml/qmlpropertycache_p.h | 8 +++- src/declarative/qml/qmltypenamecache.cpp | 10 +++- src/declarative/qml/qmltypenamecache_p.h | 6 ++- 11 files changed, 224 insertions(+), 9 deletions(-) create mode 100644 src/declarative/qml/qmlcleanup.cpp create mode 100644 src/declarative/qml/qmlcleanup_p.h diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri index b6e86a8..cbc2f85 100644 --- a/src/declarative/qml/qml.pri +++ b/src/declarative/qml/qml.pri @@ -37,6 +37,7 @@ SOURCES += qml/qmlparser.cpp \ qml/qmetaobjectbuilder.cpp \ qml/qmlwatcher.cpp \ qml/qmlscript.cpp \ + qml/qmlcleanup.cpp \ qml/qmlpropertycache.cpp \ qml/qmlintegercache.cpp \ qml/qmltypenamecache.cpp \ @@ -100,6 +101,7 @@ HEADERS += qml/qmlparser_p.h \ qml/qmlsqldatabase_p.h \ qml/qmetaobjectbuilder_p.h \ qml/qmlwatcher_p.h \ + qml/qmlcleanup_p.h \ qml/qmlpropertycache_p.h \ qml/qmlintegercache_p.h \ qml/qmltypenamecache_p.h \ diff --git a/src/declarative/qml/qmlcleanup.cpp b/src/declarative/qml/qmlcleanup.cpp new file mode 100644 index 0000000..7799cfc --- /dev/null +++ b/src/declarative/qml/qmlcleanup.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmlcleanup_p.h" +#include + +/*! +\internal +\class QmlCleanup +\brief The QmlCleanup provides a callback when a QmlEngine is deleted. + +Any object that needs cleanup to occur before the QmlEngine's QScriptEngine is +destroyed should inherit from QmlCleanup. The clear() virtual method will be +called by QmlEngine just before it deletes the QScriptEngine. +*/ + +/*! +\internal + +Create a QmlCleanup for \a engine +*/ +QmlCleanup::QmlCleanup(QmlEngine *engine) +: prev(0), next(0) +{ + Q_ASSERT(engine); + QmlEnginePrivate *p = QmlEnginePrivate::get(engine); + + if (p->cleanup) next = p->cleanup; + p->cleanup = this; + prev = &p->cleanup; + if (next) next->prev = &next; +} + +/*! +\internal +*/ +QmlCleanup::~QmlCleanup() +{ + if (prev) *prev = next; + if (next) next->prev = prev; + prev = 0; + next = 0; +} + diff --git a/src/declarative/qml/qmlcleanup_p.h b/src/declarative/qml/qmlcleanup_p.h new file mode 100644 index 0000000..e9196a3 --- /dev/null +++ b/src/declarative/qml/qmlcleanup_p.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLCLEANUP_P_H +#define QMLCLEANUP_P_H + +#include + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +QT_BEGIN_NAMESPACE + +class QmlEngine; +class QmlCleanup +{ +public: + QmlCleanup(QmlEngine *); + virtual ~QmlCleanup(); + +protected: + virtual void clear() = 0; + +private: + friend class QmlEnginePrivate; + QmlCleanup **prev; + QmlCleanup *next; +}; + +QT_END_NAMESPACE + +#endif // QMLCLEANUP_P_H + diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 354114a..4f3b2ba 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -128,7 +128,7 @@ static QString userLocalDataPath(const QString& app) QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) : rootContext(0), currentExpression(0), isDebugging(false), contextClass(0), objectClass(0), valueTypeClass(0), globalClass(0), - nodeListClass(0), namedNodeMapClass(0), sqlQueryClass(0), scriptEngine(this), + nodeListClass(0), namedNodeMapClass(0), sqlQueryClass(0), cleanup(0), scriptEngine(this), componentAttacheds(0), rootComponent(0), networkAccessManager(0), typeManager(e), uniqueId(1) { QScriptValue qtObject = @@ -168,6 +168,15 @@ QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) QmlEnginePrivate::~QmlEnginePrivate() { + while (cleanup) { + QmlCleanup *c = cleanup; + cleanup = c->next; + if (cleanup) cleanup->prev = &cleanup; + c->next = 0; + c->prev = 0; + c->clear(); + } + delete rootContext; rootContext = 0; delete contextClass; diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index a74854d..29621c0 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -97,6 +97,7 @@ class QmlTypeNameScriptClass; class QmlTypeNameCache; class QmlComponentAttached; class QmlListScriptClass; +class QmlCleanup; class QmlEnginePrivate : public QObjectPrivate { @@ -139,6 +140,9 @@ public: // Used by SQL database API QScriptClass *sqlQueryClass; + // Registered cleanup handlers + QmlCleanup *cleanup; + struct QmlScriptEngine : public QScriptEngine { QmlScriptEngine(QmlEnginePrivate *priv) diff --git a/src/declarative/qml/qmlintegercache.cpp b/src/declarative/qml/qmlintegercache.cpp index 89a18a1..06955c7 100644 --- a/src/declarative/qml/qmlintegercache.cpp +++ b/src/declarative/qml/qmlintegercache.cpp @@ -46,13 +46,21 @@ QT_BEGIN_NAMESPACE QmlIntegerCache::QmlIntegerCache(QmlEngine *e) -: engine(e) +: QmlCleanup(e), engine(e) { } QmlIntegerCache::~QmlIntegerCache() { + clear(); +} + +void QmlIntegerCache::clear() +{ qDeleteAll(stringCache); + stringCache.clear(); + identifierCache.clear(); + engine = 0; } void QmlIntegerCache::add(const QString &id, int value) diff --git a/src/declarative/qml/qmlintegercache_p.h b/src/declarative/qml/qmlintegercache_p.h index e11e0be..6e9fadd 100644 --- a/src/declarative/qml/qmlintegercache_p.h +++ b/src/declarative/qml/qmlintegercache_p.h @@ -55,13 +55,14 @@ #include #include +#include #include QT_BEGIN_NAMESPACE class QmlType; class QmlEngine; -class QmlIntegerCache : public QmlRefCount +class QmlIntegerCache : public QmlRefCount, public QmlCleanup { public: QmlIntegerCache(QmlEngine *); @@ -73,6 +74,10 @@ public: inline int value(const QScriptDeclarativeClass::Identifier &id) const; static QmlIntegerCache *createForEnums(QmlType *, QmlEngine *); + +protected: + virtual void clear(); + private: struct Data : public QScriptDeclarativeClass::PersistentIdentifier { Data(const QScriptDeclarativeClass::PersistentIdentifier &i, int v) diff --git a/src/declarative/qml/qmlpropertycache.cpp b/src/declarative/qml/qmlpropertycache.cpp index e00126f..3ede341 100644 --- a/src/declarative/qml/qmlpropertycache.cpp +++ b/src/declarative/qml/qmlpropertycache.cpp @@ -86,12 +86,18 @@ void QmlPropertyCache::Data::load(const QMetaMethod &m) } -QmlPropertyCache::QmlPropertyCache() +QmlPropertyCache::QmlPropertyCache(QmlEngine *engine) +: QmlCleanup(engine) { } QmlPropertyCache::~QmlPropertyCache() { + clear(); +} + +void QmlPropertyCache::clear() +{ for (int ii = 0; ii < indexCache.count(); ++ii) indexCache.at(ii)->release(); @@ -102,6 +108,10 @@ QmlPropertyCache::~QmlPropertyCache() for (IdentifierCache::ConstIterator iter = identifierCache.begin(); iter != identifierCache.end(); ++iter) (*iter)->release(); + + indexCache.clear(); + stringCache.clear(); + identifierCache.clear(); } QmlPropertyCache::Data QmlPropertyCache::create(const QMetaObject *metaObject, @@ -141,7 +151,7 @@ QmlPropertyCache *QmlPropertyCache::create(QmlEngine *engine, const QMetaObject Q_ASSERT(engine); Q_ASSERT(metaObject); - QmlPropertyCache *cache = new QmlPropertyCache; + QmlPropertyCache *cache = new QmlPropertyCache(engine); QmlEnginePrivate *enginePriv = QmlEnginePrivate::get(engine); diff --git a/src/declarative/qml/qmlpropertycache_p.h b/src/declarative/qml/qmlpropertycache_p.h index 91b0c53..6c3142a 100644 --- a/src/declarative/qml/qmlpropertycache_p.h +++ b/src/declarative/qml/qmlpropertycache_p.h @@ -55,16 +55,17 @@ #include #include +#include #include QT_BEGIN_NAMESPACE class QmlEngine; class QMetaProperty; -class QmlPropertyCache : public QmlRefCount +class QmlPropertyCache : public QmlRefCount, public QmlCleanup { public: - QmlPropertyCache(); + QmlPropertyCache(QmlEngine *); virtual ~QmlPropertyCache(); struct Data { @@ -112,6 +113,9 @@ public: Data *property(const QString &) const; Data *property(int) const; +protected: + virtual void clear(); + private: struct RData : public Data, public QmlRefCount { QScriptDeclarativeClass::PersistentIdentifier identifier; diff --git a/src/declarative/qml/qmltypenamecache.cpp b/src/declarative/qml/qmltypenamecache.cpp index aa1c938..d706c63 100644 --- a/src/declarative/qml/qmltypenamecache.cpp +++ b/src/declarative/qml/qmltypenamecache.cpp @@ -45,13 +45,21 @@ QT_BEGIN_NAMESPACE QmlTypeNameCache::QmlTypeNameCache(QmlEngine *e) -: engine(e) +: QmlCleanup(e), engine(e) { } QmlTypeNameCache::~QmlTypeNameCache() { + clear(); +} + +void QmlTypeNameCache::clear() +{ qDeleteAll(stringCache); + stringCache.clear(); + identifierCache.clear(); + engine = 0; } void QmlTypeNameCache::add(const QString &name, QmlType *type) diff --git a/src/declarative/qml/qmltypenamecache_p.h b/src/declarative/qml/qmltypenamecache_p.h index f11fe68..ec1e79d 100644 --- a/src/declarative/qml/qmltypenamecache_p.h +++ b/src/declarative/qml/qmltypenamecache_p.h @@ -55,12 +55,13 @@ #include #include +#include QT_BEGIN_NAMESPACE class QmlType; class QmlEngine; -class QmlTypeNameCache : public QmlRefCount +class QmlTypeNameCache : public QmlRefCount, public QmlCleanup { public: QmlTypeNameCache(QmlEngine *); @@ -79,6 +80,9 @@ public: Data *data(const QString &) const; inline Data *data(const QScriptDeclarativeClass::Identifier &id) const; +protected: + virtual void clear(); + private: struct RData : public Data { QScriptDeclarativeClass::PersistentIdentifier identifier; -- cgit v0.12 From 05d3e827565d635e75cfd49e46b3ba72903a1e6f Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Mon, 26 Oct 2009 11:39:41 +1000 Subject: Flip around perspective origin --- demos/declarative/flickr/common/ImageDetails.qml | 1 + 1 file changed, 1 insertion(+) diff --git a/demos/declarative/flickr/common/ImageDetails.qml b/demos/declarative/flickr/common/ImageDetails.qml index b8b7d29..cc00773 100644 --- a/demos/declarative/flickr/common/ImageDetails.qml +++ b/demos/declarative/flickr/common/ImageDetails.qml @@ -20,6 +20,7 @@ Flipable { transform: Rotation { id: detailsRotation + origin.y: container.height / 2; origin.x: container.width / 2; axis.y: 1; axis.z: 0 } -- cgit v0.12 From 91462fa3ac02aa88e3aeeacfa9fc4d4dbb8fe2a1 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Mon, 26 Oct 2009 11:47:54 +1000 Subject: Optimize concatenation of partial shaders Reviewed-by: Sarah Smith --- src/opengl/qglshaderprogram.cpp | 123 ++++++++++++++++++++++++++++++---------- src/opengl/qglshaderprogram.h | 2 + 2 files changed, 95 insertions(+), 30 deletions(-) diff --git a/src/opengl/qglshaderprogram.cpp b/src/opengl/qglshaderprogram.cpp index 34114e4..ecb2566 100644 --- a/src/opengl/qglshaderprogram.cpp +++ b/src/opengl/qglshaderprogram.cpp @@ -444,7 +444,8 @@ bool QGLShader::compile(const char *source) d->hasPartialSource = true; return d->compile(this); } else if (d->shaderGuard.id()) { - QVarLengthArray src; + QVarLengthArray src; + QVarLengthArray srclen; int headerLen = 0; while (source && source[headerLen] == '#') { // Skip #version and #extension directives at the start of @@ -459,21 +460,24 @@ bool QGLShader::compile(const char *source) if (source[headerLen] == '\n') ++headerLen; } - QByteArray header; if (headerLen > 0) { - header = QByteArray(source, headerLen); - src.append(header.constData()); + src.append(source); + srclen.append(GLint(headerLen)); } #ifdef QGL_DEFINE_QUALIFIERS src.append(qualifierDefines); + srclen.append(GLint(sizeof(qualifierDefines) - 1)); #endif #ifdef QGL_REDEFINE_HIGHP if (d->shaderType == FragmentShader || - d->shaderType == PartialFragmentShader) + d->shaderType == PartialFragmentShader) { src.append(redefineHighp); + srclen.append(GLint(sizeof(redefineHighp) - 1)); + } #endif src.append(source + headerLen); - glShaderSource(d->shaderGuard.id(), src.size(), src.data(), 0); + srclen.append(GLint(qstrlen(source + headerLen))); + glShaderSource(d->shaderGuard.id(), src.size(), src.data(), srclen.data()); return d->compile(this); } else { return false; @@ -481,6 +485,60 @@ bool QGLShader::compile(const char *source) } /*! + \internal +*/ +bool QGLShader::compile + (const QList& shaders, QGLShader::ShaderType type) +{ + QVarLengthArray src; + QVarLengthArray srclen; + if (!d->shaderGuard.id()) + return false; + foreach (QGLShader *shader, shaders) { + if (shader->shaderType() != type) + continue; + const char *source = shader->d->partialSource.constData(); + int headerLen = 0; + if (src.isEmpty()) { + // First shader: handle the #version and #extension tags + // plus the precision qualifiers. + while (source && source[headerLen] == '#') { + // Skip #version and #extension directives at the start of + // the shader code. We need to insert the qualifierDefines + // and redefineHighp just after them. + if (qstrncmp(source + headerLen, "#version", 8) != 0 && + qstrncmp(source + headerLen, "#extension", 10) != 0) { + break; + } + while (source[headerLen] != '\0' && source[headerLen] != '\n') + ++headerLen; + if (source[headerLen] == '\n') + ++headerLen; + } + if (headerLen > 0) { + src.append(source); + srclen.append(GLint(headerLen)); + } +#ifdef QGL_DEFINE_QUALIFIERS + src.append(qualifierDefines); + srclen.append(GLint(sizeof(qualifierDefines) - 1)); +#endif +#ifdef QGL_REDEFINE_HIGHP + if (d->shaderType == FragmentShader || + d->shaderType == PartialFragmentShader) { + src.append(redefineHighp); + srclen.append(GLint(sizeof(redefineHighp) - 1)); + } +#endif + } + src.append(source + headerLen); + srclen.append(GLint(qstrlen(source + headerLen))); + } + glShaderSource(d->shaderGuard.id(), src.size(), src.data(), srclen.data()); + return d->compile(this); +} + +/*! \overload Sets the \a source code for this shader and compiles it. @@ -713,6 +771,8 @@ public: QList anonShaders; QGLShader *vertexShader; QGLShader *fragmentShader; + + bool hasShader(QGLShader::ShaderType type) const; }; QGLShaderProgramPrivate::~QGLShaderProgramPrivate() @@ -723,6 +783,15 @@ QGLShaderProgramPrivate::~QGLShaderProgramPrivate() } } +bool QGLShaderProgramPrivate::hasShader(QGLShader::ShaderType type) const +{ + foreach (QGLShader *shader, shaders) { + if (shader->shaderType() == type) + return true; + } + return false; +} + #undef ctx #define ctx d->programGuard.context() @@ -1118,47 +1187,41 @@ bool QGLShaderProgram::link() return false; if (d->hasPartialShaders) { // Compile the partial vertex and fragment shaders. - QByteArray vertexSource; - QByteArray fragmentSource; - foreach (QGLShader *shader, d->shaders) { - if (shader->shaderType() == QGLShader::PartialVertexShader) - vertexSource += shader->sourceCode(); - else if (shader->shaderType() == QGLShader::PartialFragmentShader) - fragmentSource += shader->sourceCode(); - } - if (vertexSource.isEmpty()) { - if (d->vertexShader) { - glDetachShader(program, d->vertexShader->d->shaderGuard.id()); - delete d->vertexShader; - d->vertexShader = 0; - } - } else { + if (d->hasShader(QGLShader::PartialVertexShader)) { if (!d->vertexShader) { d->vertexShader = new QGLShader(QGLShader::VertexShader, this); } - if (!d->vertexShader->compile(vertexSource)) { + if (!d->vertexShader->compile + (d->shaders, QGLShader::PartialVertexShader)) { d->log = d->vertexShader->log(); return false; } glAttachShader(program, d->vertexShader->d->shaderGuard.id()); - } - if (fragmentSource.isEmpty()) { - if (d->fragmentShader) { - glDetachShader(program, d->fragmentShader->d->shaderGuard.id()); - delete d->fragmentShader; - d->fragmentShader = 0; - } } else { + if (d->vertexShader) { + glDetachShader(program, d->vertexShader->d->shaderGuard.id()); + delete d->vertexShader; + d->vertexShader = 0; + } + } + if (d->hasShader(QGLShader::PartialFragmentShader)) { if (!d->fragmentShader) { d->fragmentShader = new QGLShader(QGLShader::FragmentShader, this); } - if (!d->fragmentShader->compile(fragmentSource)) { + if (!d->fragmentShader->compile + (d->shaders, QGLShader::PartialFragmentShader)) { d->log = d->fragmentShader->log(); return false; } glAttachShader(program, d->fragmentShader->d->shaderGuard.id()); + } else { + if (d->fragmentShader) { + glDetachShader(program, d->fragmentShader->d->shaderGuard.id()); + delete d->fragmentShader; + d->fragmentShader = 0; + } } } glLinkProgram(program); diff --git a/src/opengl/qglshaderprogram.h b/src/opengl/qglshaderprogram.h index f2d70fa..2848b5f 100644 --- a/src/opengl/qglshaderprogram.h +++ b/src/opengl/qglshaderprogram.h @@ -106,6 +106,8 @@ private: friend class QGLShaderProgram; Q_DISABLE_COPY(QGLShader) + + bool compile(const QList& shaders, QGLShader::ShaderType type); }; Q_DECLARE_OPERATORS_FOR_FLAGS(QGLShader::ShaderType) -- cgit v0.12 From 24498457049f0504d0b09935dea6ca6a5634bb2d Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 26 Oct 2009 11:57:45 +1000 Subject: Fix crash. --- src/declarative/util/qmlpropertychanges.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/declarative/util/qmlpropertychanges.cpp b/src/declarative/util/qmlpropertychanges.cpp index a112245..bed27fe 100644 --- a/src/declarative/util/qmlpropertychanges.cpp +++ b/src/declarative/util/qmlpropertychanges.cpp @@ -85,7 +85,8 @@ class QmlReplaceSignalHandler : public ActionEvent public: QmlReplaceSignalHandler() : expression(0), reverseExpression(0), ownedExpression(0) {} ~QmlReplaceSignalHandler() { - delete ownedExpression; + if (ownedExpression) + delete ownedExpression; } virtual QString typeName() const { return QLatin1String("ReplaceSignalHandler"); } @@ -93,7 +94,7 @@ public: QmlMetaProperty property; QmlExpression *expression; QmlExpression *reverseExpression; - QmlExpression *ownedExpression; + QGuard ownedExpression; virtual void execute() { ownedExpression = property.setSignalExpression(expression); @@ -272,7 +273,6 @@ QmlPropertyChanges::~QmlPropertyChanges() delete d->expressions.at(ii).second; for(int ii = 0; ii < d->signalReplacements.count(); ++ii) delete d->signalReplacements.at(ii); - } QObject *QmlPropertyChanges::object() const -- cgit v0.12 From a161143b81d8b4cfce06d2566dbbd129a2e1b0e1 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Mon, 26 Oct 2009 12:14:58 +1000 Subject: Use QObjectPrivate within QGLShaderPrivate and QGLShaderProgramPrivate Reviewed-by: Sarah Smith --- src/opengl/qglshaderprogram.cpp | 175 ++++++++++++++++++++++++++++++---------- src/opengl/qglshaderprogram.h | 6 +- 2 files changed, 134 insertions(+), 47 deletions(-) diff --git a/src/opengl/qglshaderprogram.cpp b/src/opengl/qglshaderprogram.cpp index ecb2566..7fcd6f7 100644 --- a/src/opengl/qglshaderprogram.cpp +++ b/src/opengl/qglshaderprogram.cpp @@ -42,6 +42,7 @@ #include "qglshaderprogram.h" #include "qglextensions_p.h" #include "qgl_p.h" +#include #include #include #include @@ -200,8 +201,9 @@ QT_BEGIN_NAMESPACE #define GL_NUM_SHADER_BINARY_FORMATS 0x8DF9 #endif -class QGLShaderPrivate +class QGLShaderPrivate : public QObjectPrivate { + Q_DECLARE_PUBLIC(QGLShader) public: QGLShaderPrivate(const QGLContext *context, QGLShader::ShaderType type) : shaderGuard(context) @@ -211,6 +213,7 @@ public: , hasPartialSource(false) { } + ~QGLShaderPrivate(); QGLSharedResourceGuard shaderGuard; QGLShader::ShaderType shaderType; @@ -227,6 +230,14 @@ public: #define ctx shaderGuard.context() +QGLShaderPrivate::~QGLShaderPrivate() +{ + if (shaderGuard.id()) { + QGLShareContextScope scope(shaderGuard.context()); + glDeleteShader(shaderGuard.id()); + } +} + bool QGLShaderPrivate::create() { const QGLContext *context = shaderGuard.context(); @@ -306,9 +317,9 @@ void QGLShaderPrivate::deleteShader() \sa compile(), compileFile() */ QGLShader::QGLShader(QGLShader::ShaderType type, QObject *parent) - : QObject(parent) + : QObject(*new QGLShaderPrivate(QGLContext::currentContext(), type), parent) { - d = new QGLShaderPrivate(QGLContext::currentContext(), type); + Q_D(QGLShader); d->create(); } @@ -323,13 +334,21 @@ QGLShader::QGLShader(QGLShader::ShaderType type, QObject *parent) */ QGLShader::QGLShader (const QString& fileName, QGLShader::ShaderType type, QObject *parent) - : QObject(parent) + : QObject(*new QGLShaderPrivate(QGLContext::currentContext(), type), parent) { - d = new QGLShaderPrivate(QGLContext::currentContext(), type); + Q_D(QGLShader); if (d->create() && !compileFile(fileName)) d->deleteShader(); } +static inline const QGLContext *contextOrCurrent(const QGLContext *context) +{ + if (context) + return context; + else + return QGLContext::currentContext(); +} + /*! Constructs a new QGLShader object of the specified \a type and attaches it to \a parent. If shader programs are not supported, @@ -343,14 +362,12 @@ QGLShader::QGLShader \sa compile(), compileFile() */ QGLShader::QGLShader(QGLShader::ShaderType type, const QGLContext *context, QObject *parent) - : QObject(parent) + : QObject(*new QGLShaderPrivate(contextOrCurrent(context), type), parent) { - if (!context) - context = QGLContext::currentContext(); - d = new QGLShaderPrivate(context, type); + Q_D(QGLShader); #ifndef QT_NO_DEBUG if (context && !QGLContext::areSharing(context, QGLContext::currentContext())) { - qWarning("QGLShader::QGLShader: \'context\' must be the currect context or sharing with it."); + qWarning("QGLShader::QGLShader: \'context\' must be the current context or sharing with it."); return; } #endif @@ -368,14 +385,12 @@ QGLShader::QGLShader(QGLShader::ShaderType type, const QGLContext *context, QObj */ QGLShader::QGLShader (const QString& fileName, QGLShader::ShaderType type, const QGLContext *context, QObject *parent) - : QObject(parent) + : QObject(*new QGLShaderPrivate(contextOrCurrent(context), type), parent) { - if (!context) - context = QGLContext::currentContext(); - d = new QGLShaderPrivate(context, type); + Q_D(QGLShader); #ifndef QT_NO_DEBUG if (context && !QGLContext::areSharing(context, QGLContext::currentContext())) { - qWarning("QGLShader::QGLShader: \'context\' must be currect context or sharing with it."); + qWarning("QGLShader::QGLShader: \'context\' must be current context or sharing with it."); return; } #endif @@ -390,11 +405,6 @@ QGLShader::QGLShader */ QGLShader::~QGLShader() { - if (d->shaderGuard.id()) { - QGLShareContextScope scope(d->shaderGuard.context()); - glDeleteShader(d->shaderGuard.id()); - } - delete d; } /*! @@ -402,6 +412,7 @@ QGLShader::~QGLShader() */ QGLShader::ShaderType QGLShader::shaderType() const { + Q_D(const QGLShader); return d->shaderType; } @@ -439,6 +450,7 @@ static const char redefineHighp[] = */ bool QGLShader::compile(const char *source) { + Q_D(QGLShader); if (d->isPartial) { d->partialSource = QByteArray(source); d->hasPartialSource = true; @@ -490,6 +502,7 @@ bool QGLShader::compile(const char *source) bool QGLShader::compile (const QList& shaders, QGLShader::ShaderType type) { + Q_D(QGLShader); QVarLengthArray src; QVarLengthArray srclen; if (!d->shaderGuard.id()) @@ -497,7 +510,7 @@ bool QGLShader::compile foreach (QGLShader *shader, shaders) { if (shader->shaderType() != type) continue; - const char *source = shader->d->partialSource.constData(); + const char *source = shader->d_func()->partialSource.constData(); int headerLen = 0; if (src.isEmpty()) { // First shader: handle the #version and #extension tags @@ -613,6 +626,7 @@ bool QGLShader::compileFile(const QString& fileName) */ bool QGLShader::setShaderBinary(GLenum format, const void *binary, int length) { + Q_D(QGLShader); #if !defined(QT_OPENGL_ES_2) if (!glShaderBinary) return false; @@ -646,21 +660,22 @@ bool QGLShader::setShaderBinary(GLenum format, const void *binary, int length) bool QGLShader::setShaderBinary (QGLShader& otherShader, GLenum format, const void *binary, int length) { + Q_D(QGLShader); #if !defined(QT_OPENGL_ES_2) if (!glShaderBinary) return false; #endif if (d->isPartial || !d->shaderGuard.id()) return false; - if (otherShader.d->isPartial || !otherShader.d->shaderGuard.id()) + if (otherShader.d_func()->isPartial || !otherShader.d_func()->shaderGuard.id()) return false; glGetError(); // Clear error state. GLuint shaders[2]; shaders[0] = d->shaderGuard.id(); - shaders[1] = otherShader.d->shaderGuard.id(); + shaders[1] = otherShader.d_func()->shaderGuard.id(); glShaderBinary(2, shaders, format, binary, length); d->compiled = (glGetError() == GL_NO_ERROR); - otherShader.d->compiled = d->compiled; + otherShader.d_func()->compiled = d->compiled; return d->compiled; } @@ -692,6 +707,7 @@ QList QGLShader::shaderBinaryFormats() */ QByteArray QGLShader::sourceCode() const { + Q_D(const QGLShader); if (d->isPartial) return d->partialSource; GLuint shader = d->shaderGuard.id(); @@ -716,6 +732,7 @@ QByteArray QGLShader::sourceCode() const */ bool QGLShader::isCompiled() const { + Q_D(const QGLShader); return d->compiled; } @@ -726,6 +743,7 @@ bool QGLShader::isCompiled() const */ QString QGLShader::log() const { + Q_D(const QGLShader); return d->log; } @@ -740,14 +758,16 @@ QString QGLShader::log() const */ GLuint QGLShader::shaderId() const { + Q_D(const QGLShader); return d->shaderGuard.id(); } #undef ctx #define ctx programGuard.context() -class QGLShaderProgramPrivate +class QGLShaderProgramPrivate : public QObjectPrivate { + Q_DECLARE_PUBLIC(QGLShaderProgram) public: QGLShaderProgramPrivate(const QGLContext *context) : programGuard(context) @@ -804,9 +824,8 @@ bool QGLShaderProgramPrivate::hasShader(QGLShader::ShaderType type) const \sa addShader() */ QGLShaderProgram::QGLShaderProgram(QObject *parent) - : QObject(parent) + : QObject(*new QGLShaderProgramPrivate(QGLContext::currentContext()), parent) { - d = new QGLShaderProgramPrivate(QGLContext::currentContext()); } /*! @@ -818,9 +837,8 @@ QGLShaderProgram::QGLShaderProgram(QObject *parent) \sa addShader() */ QGLShaderProgram::QGLShaderProgram(const QGLContext *context, QObject *parent) - : QObject(parent) + : QObject(*new QGLShaderProgramPrivate(context), parent) { - d = new QGLShaderProgramPrivate(context); } /*! @@ -828,11 +846,11 @@ QGLShaderProgram::QGLShaderProgram(const QGLContext *context, QObject *parent) */ QGLShaderProgram::~QGLShaderProgram() { - delete d; } bool QGLShaderProgram::init() { + Q_D(QGLShaderProgram); if (d->programGuard.id() || d->inited) return true; d->inited = true; @@ -870,22 +888,23 @@ bool QGLShaderProgram::init() */ bool QGLShaderProgram::addShader(QGLShader *shader) { + Q_D(QGLShaderProgram); if (!init()) return false; if (d->shaders.contains(shader)) return true; // Already added to this shader program. if (d->programGuard.id() && shader) { - if (!QGLContext::areSharing(shader->d->shaderGuard.context(), + if (!QGLContext::areSharing(shader->d_func()->shaderGuard.context(), d->programGuard.context())) { qWarning("QGLShaderProgram::addShader: Program and shader are not associated with same context."); return false; } - if (!shader->d->compiled) + if (!shader->d_func()->compiled) return false; - if (!shader->d->isPartial) { - if (!shader->d->shaderGuard.id()) + if (!shader->d_func()->isPartial) { + if (!shader->d_func()->shaderGuard.id()) return false; - glAttachShader(d->programGuard.id(), shader->d->shaderGuard.id()); + glAttachShader(d->programGuard.id(), shader->d_func()->shaderGuard.id()); } else { d->hasPartialShaders = true; } @@ -912,6 +931,7 @@ bool QGLShaderProgram::addShader(QGLShader *shader) */ bool QGLShaderProgram::addShader(QGLShader::ShaderType type, const char *source) { + Q_D(QGLShaderProgram); if (!init()) return false; QGLShader *shader = new QGLShader(type, this); @@ -977,6 +997,7 @@ bool QGLShaderProgram::addShader(QGLShader::ShaderType type, const QString& sour bool QGLShaderProgram::addShaderFromFile (QGLShader::ShaderType type, const QString& fileName) { + Q_D(QGLShaderProgram); if (!init()) return false; QGLShader *shader = new QGLShader(type, this); @@ -996,9 +1017,10 @@ bool QGLShaderProgram::addShaderFromFile */ void QGLShaderProgram::removeShader(QGLShader *shader) { - if (d->programGuard.id() && shader && shader->d->shaderGuard.id()) { + Q_D(QGLShaderProgram); + if (d->programGuard.id() && shader && shader->d_func()->shaderGuard.id()) { QGLShareContextScope scope(d->programGuard.context()); - glDetachShader(d->programGuard.id(), shader->d->shaderGuard.id()); + glDetachShader(d->programGuard.id(), shader->d_func()->shaderGuard.id()); } d->linked = false; // Program needs to be relinked. if (shader) { @@ -1016,6 +1038,7 @@ void QGLShaderProgram::removeShader(QGLShader *shader) */ QList QGLShaderProgram::shaders() const { + Q_D(const QGLShaderProgram); return d->shaders; } @@ -1029,10 +1052,11 @@ QList QGLShaderProgram::shaders() const */ void QGLShaderProgram::removeAllShaders() { + Q_D(QGLShaderProgram); d->removingShaders = true; foreach (QGLShader *shader, d->shaders) { - if (d->programGuard.id() && shader && shader->d->shaderGuard.id()) - glDetachShader(d->programGuard.id(), shader->d->shaderGuard.id()); + if (d->programGuard.id() && shader && shader->d_func()->shaderGuard.id()) + glDetachShader(d->programGuard.id(), shader->d_func()->shaderGuard.id()); } foreach (QGLShader *shader, d->anonShaders) { // Delete shader objects that were created anonymously. @@ -1078,6 +1102,7 @@ void QGLShaderProgram::removeAllShaders() QByteArray QGLShaderProgram::programBinary(int *format) const { #if defined(QT_OPENGL_ES_2) + Q_D(const QGLShaderProgram); if (!isLinked()) return QByteArray(); @@ -1113,6 +1138,7 @@ bool QGLShaderProgram::setProgramBinary(int format, const QByteArray& binary) { #if defined(QT_OPENGL_ES_2) // Load the binary and check that it was linked correctly. + Q_D(const QGLShaderProgram); GLuint program = d->programGuard.id(); if (!program) return false; @@ -1182,6 +1208,7 @@ QList QGLShaderProgram::programBinaryFormats() */ bool QGLShaderProgram::link() { + Q_D(QGLShaderProgram); GLuint program = d->programGuard.id(); if (!program) return false; @@ -1197,10 +1224,10 @@ bool QGLShaderProgram::link() d->log = d->vertexShader->log(); return false; } - glAttachShader(program, d->vertexShader->d->shaderGuard.id()); + glAttachShader(program, d->vertexShader->d_func()->shaderGuard.id()); } else { if (d->vertexShader) { - glDetachShader(program, d->vertexShader->d->shaderGuard.id()); + glDetachShader(program, d->vertexShader->d_func()->shaderGuard.id()); delete d->vertexShader; d->vertexShader = 0; } @@ -1215,10 +1242,10 @@ bool QGLShaderProgram::link() d->log = d->fragmentShader->log(); return false; } - glAttachShader(program, d->fragmentShader->d->shaderGuard.id()); + glAttachShader(program, d->fragmentShader->d_func()->shaderGuard.id()); } else { if (d->fragmentShader) { - glDetachShader(program, d->fragmentShader->d->shaderGuard.id()); + glDetachShader(program, d->fragmentShader->d_func()->shaderGuard.id()); delete d->fragmentShader; d->fragmentShader = 0; } @@ -1253,6 +1280,7 @@ bool QGLShaderProgram::link() */ bool QGLShaderProgram::isLinked() const { + Q_D(const QGLShaderProgram); return d->linked; } @@ -1264,6 +1292,7 @@ bool QGLShaderProgram::isLinked() const */ QString QGLShaderProgram::log() const { + Q_D(const QGLShaderProgram); return d->log; } @@ -1277,6 +1306,7 @@ QString QGLShaderProgram::log() const */ bool QGLShaderProgram::enable() { + Q_D(QGLShaderProgram); GLuint program = d->programGuard.id(); if (!program) return false; @@ -1315,6 +1345,7 @@ void QGLShaderProgram::disable() */ GLuint QGLShaderProgram::programId() const { + Q_D(const QGLShaderProgram); return d->programGuard.id(); } @@ -1328,6 +1359,7 @@ GLuint QGLShaderProgram::programId() const */ void QGLShaderProgram::bindAttributeLocation(const char *name, int location) { + Q_D(QGLShaderProgram); if (!d->linked) { glBindAttribLocation(d->programGuard.id(), location, name); } else { @@ -1375,6 +1407,7 @@ void QGLShaderProgram::bindAttributeLocation(const QString& name, int location) */ int QGLShaderProgram::attributeLocation(const char *name) const { + Q_D(const QGLShaderProgram); if (d->linked) { return glGetAttribLocation(d->programGuard.id(), name); } else { @@ -1419,6 +1452,7 @@ int QGLShaderProgram::attributeLocation(const QString& name) const */ void QGLShaderProgram::setAttributeValue(int location, GLfloat value) { + Q_D(QGLShaderProgram); if (location != -1) glVertexAttrib1fv(location, &value); } @@ -1443,6 +1477,7 @@ void QGLShaderProgram::setAttributeValue(const char *name, GLfloat value) */ void QGLShaderProgram::setAttributeValue(int location, GLfloat x, GLfloat y) { + Q_D(QGLShaderProgram); if (location != -1) { GLfloat values[2] = {x, y}; glVertexAttrib2fv(location, values); @@ -1471,6 +1506,7 @@ void QGLShaderProgram::setAttributeValue(const char *name, GLfloat x, GLfloat y) void QGLShaderProgram::setAttributeValue (int location, GLfloat x, GLfloat y, GLfloat z) { + Q_D(QGLShaderProgram); if (location != -1) { GLfloat values[3] = {x, y, z}; glVertexAttrib3fv(location, values); @@ -1500,6 +1536,7 @@ void QGLShaderProgram::setAttributeValue void QGLShaderProgram::setAttributeValue (int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w) { + Q_D(QGLShaderProgram); if (location != -1) { GLfloat values[4] = {x, y, z, w}; glVertexAttrib4fv(location, values); @@ -1527,6 +1564,7 @@ void QGLShaderProgram::setAttributeValue */ void QGLShaderProgram::setAttributeValue(int location, const QVector2D& value) { + Q_D(QGLShaderProgram); if (location != -1) glVertexAttrib2fv(location, reinterpret_cast(&value)); } @@ -1550,6 +1588,7 @@ void QGLShaderProgram::setAttributeValue(const char *name, const QVector2D& valu */ void QGLShaderProgram::setAttributeValue(int location, const QVector3D& value) { + Q_D(QGLShaderProgram); if (location != -1) glVertexAttrib3fv(location, reinterpret_cast(&value)); } @@ -1573,6 +1612,7 @@ void QGLShaderProgram::setAttributeValue(const char *name, const QVector3D& valu */ void QGLShaderProgram::setAttributeValue(int location, const QVector4D& value) { + Q_D(QGLShaderProgram); if (location != -1) glVertexAttrib4fv(location, reinterpret_cast(&value)); } @@ -1596,6 +1636,7 @@ void QGLShaderProgram::setAttributeValue(const char *name, const QVector4D& valu */ void QGLShaderProgram::setAttributeValue(int location, const QColor& value) { + Q_D(QGLShaderProgram); if (location != -1) { GLfloat values[4] = {value.redF(), value.greenF(), value.blueF(), value.alphaF()}; glVertexAttrib4fv(location, values); @@ -1626,6 +1667,7 @@ void QGLShaderProgram::setAttributeValue(const char *name, const QColor& value) void QGLShaderProgram::setAttributeValue (int location, const GLfloat *values, int columns, int rows) { + Q_D(QGLShaderProgram); if (rows < 1 || rows > 4) { qWarning() << "QGLShaderProgram::setAttributeValue: rows" << rows << "not supported"; return; @@ -1675,6 +1717,7 @@ void QGLShaderProgram::setAttributeValue void QGLShaderProgram::setAttributeArray (int location, const GLfloat *values, int size, int stride) { + Q_D(QGLShaderProgram); if (location != -1) { glVertexAttribPointer(location, size, GL_FLOAT, GL_FALSE, stride, values); @@ -1693,6 +1736,7 @@ void QGLShaderProgram::setAttributeArray void QGLShaderProgram::setAttributeArray (int location, const QVector2D *values, int stride) { + Q_D(QGLShaderProgram); if (location != -1) { glVertexAttribPointer(location, 2, GL_FLOAT, GL_FALSE, stride, values); @@ -1711,6 +1755,7 @@ void QGLShaderProgram::setAttributeArray void QGLShaderProgram::setAttributeArray (int location, const QVector3D *values, int stride) { + Q_D(QGLShaderProgram); if (location != -1) { glVertexAttribPointer(location, 3, GL_FLOAT, GL_FALSE, stride, values); @@ -1729,6 +1774,7 @@ void QGLShaderProgram::setAttributeArray void QGLShaderProgram::setAttributeArray (int location, const QVector4D *values, int stride) { + Q_D(QGLShaderProgram); if (location != -1) { glVertexAttribPointer(location, 4, GL_FLOAT, GL_FALSE, stride, values); @@ -1809,6 +1855,7 @@ void QGLShaderProgram::setAttributeArray */ void QGLShaderProgram::disableAttributeArray(int location) { + Q_D(QGLShaderProgram); if (location != -1) glDisableVertexAttribArray(location); } @@ -1835,6 +1882,7 @@ void QGLShaderProgram::disableAttributeArray(const char *name) */ int QGLShaderProgram::uniformLocation(const char *name) const { + Q_D(const QGLShaderProgram); if (d->linked) { return glGetUniformLocation(d->programGuard.id(), name); } else { @@ -1879,6 +1927,7 @@ int QGLShaderProgram::uniformLocation(const QString& name) const */ void QGLShaderProgram::setUniformValue(int location, GLfloat value) { + Q_D(QGLShaderProgram); if (location != -1) glUniform1fv(location, 1, &value); } @@ -1903,6 +1952,7 @@ void QGLShaderProgram::setUniformValue(const char *name, GLfloat value) */ void QGLShaderProgram::setUniformValue(int location, GLint value) { + Q_D(QGLShaderProgram); if (location != -1) glUniform1i(location, value); } @@ -1928,6 +1978,7 @@ void QGLShaderProgram::setUniformValue(const char *name, GLint value) */ void QGLShaderProgram::setUniformValue(int location, GLuint value) { + Q_D(QGLShaderProgram); if (location != -1) glUniform1i(location, value); } @@ -1953,6 +2004,7 @@ void QGLShaderProgram::setUniformValue(const char *name, GLuint value) */ void QGLShaderProgram::setUniformValue(int location, GLfloat x, GLfloat y) { + Q_D(QGLShaderProgram); if (location != -1) { GLfloat values[2] = {x, y}; glUniform2fv(location, 1, values); @@ -1981,6 +2033,7 @@ void QGLShaderProgram::setUniformValue(const char *name, GLfloat x, GLfloat y) void QGLShaderProgram::setUniformValue (int location, GLfloat x, GLfloat y, GLfloat z) { + Q_D(QGLShaderProgram); if (location != -1) { GLfloat values[3] = {x, y, z}; glUniform3fv(location, 1, values); @@ -2010,6 +2063,7 @@ void QGLShaderProgram::setUniformValue void QGLShaderProgram::setUniformValue (int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w) { + Q_D(QGLShaderProgram); if (location != -1) { GLfloat values[4] = {x, y, z, w}; glUniform4fv(location, 1, values); @@ -2037,6 +2091,7 @@ void QGLShaderProgram::setUniformValue */ void QGLShaderProgram::setUniformValue(int location, const QVector2D& value) { + Q_D(QGLShaderProgram); if (location != -1) glUniform2fv(location, 1, reinterpret_cast(&value)); } @@ -2061,6 +2116,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QVector2D& value) */ void QGLShaderProgram::setUniformValue(int location, const QVector3D& value) { + Q_D(QGLShaderProgram); if (location != -1) glUniform3fv(location, 1, reinterpret_cast(&value)); } @@ -2085,6 +2141,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QVector3D& value) */ void QGLShaderProgram::setUniformValue(int location, const QVector4D& value) { + Q_D(QGLShaderProgram); if (location != -1) glUniform4fv(location, 1, reinterpret_cast(&value)); } @@ -2110,6 +2167,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QVector4D& value) */ void QGLShaderProgram::setUniformValue(int location, const QColor& color) { + Q_D(QGLShaderProgram); if (location != -1) { GLfloat values[4] = {color.redF(), color.greenF(), color.blueF(), color.alphaF()}; glUniform4fv(location, 1, values); @@ -2137,6 +2195,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QColor& color) */ void QGLShaderProgram::setUniformValue(int location, const QPoint& point) { + Q_D(QGLShaderProgram); if (location != -1) { GLfloat values[4] = {point.x(), point.y()}; glUniform2fv(location, 1, values); @@ -2164,6 +2223,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QPoint& point) */ void QGLShaderProgram::setUniformValue(int location, const QPointF& point) { + Q_D(QGLShaderProgram); if (location != -1) { GLfloat values[4] = {point.x(), point.y()}; glUniform2fv(location, 1, values); @@ -2191,6 +2251,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QPointF& point) */ void QGLShaderProgram::setUniformValue(int location, const QSize& size) { + Q_D(QGLShaderProgram); if (location != -1) { GLfloat values[4] = {size.width(), size.width()}; glUniform2fv(location, 1, values); @@ -2218,6 +2279,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QSize& size) */ void QGLShaderProgram::setUniformValue(int location, const QSizeF& size) { + Q_D(QGLShaderProgram); if (location != -1) { GLfloat values[4] = {size.width(), size.height()}; glUniform2fv(location, 1, values); @@ -2297,6 +2359,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QSizeF& size) */ void QGLShaderProgram::setUniformValue(int location, const QMatrix2x2& value) { + Q_D(QGLShaderProgram); setUniformMatrix(glUniformMatrix2fv, location, value, 2, 2); } @@ -2321,6 +2384,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix2x2& value */ void QGLShaderProgram::setUniformValue(int location, const QMatrix2x3& value) { + Q_D(QGLShaderProgram); setUniformGenericMatrix (glUniformMatrix2x3fv, glUniform3fv, location, value, 2, 3); } @@ -2346,6 +2410,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix2x3& value */ void QGLShaderProgram::setUniformValue(int location, const QMatrix2x4& value) { + Q_D(QGLShaderProgram); setUniformGenericMatrix (glUniformMatrix2x4fv, glUniform4fv, location, value, 2, 4); } @@ -2371,6 +2436,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix2x4& value */ void QGLShaderProgram::setUniformValue(int location, const QMatrix3x2& value) { + Q_D(QGLShaderProgram); setUniformGenericMatrix (glUniformMatrix3x2fv, glUniform2fv, location, value, 3, 2); } @@ -2396,6 +2462,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix3x2& value */ void QGLShaderProgram::setUniformValue(int location, const QMatrix3x3& value) { + Q_D(QGLShaderProgram); setUniformMatrix(glUniformMatrix3fv, location, value, 3, 3); } @@ -2420,6 +2487,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix3x3& value */ void QGLShaderProgram::setUniformValue(int location, const QMatrix3x4& value) { + Q_D(QGLShaderProgram); setUniformGenericMatrix (glUniformMatrix3x4fv, glUniform4fv, location, value, 3, 4); } @@ -2445,6 +2513,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix3x4& value */ void QGLShaderProgram::setUniformValue(int location, const QMatrix4x2& value) { + Q_D(QGLShaderProgram); setUniformGenericMatrix (glUniformMatrix4x2fv, glUniform2fv, location, value, 4, 2); } @@ -2470,6 +2539,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix4x2& value */ void QGLShaderProgram::setUniformValue(int location, const QMatrix4x3& value) { + Q_D(QGLShaderProgram); setUniformGenericMatrix (glUniformMatrix4x3fv, glUniform3fv, location, value, 4, 3); } @@ -2495,6 +2565,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix4x3& value */ void QGLShaderProgram::setUniformValue(int location, const QMatrix4x4& value) { + Q_D(QGLShaderProgram); setUniformMatrix(glUniformMatrix4fv, location, value, 4, 4); } @@ -2522,6 +2593,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix4x4& value */ void QGLShaderProgram::setUniformValue(int location, const GLfloat value[4][4]) { + Q_D(QGLShaderProgram); if (location != -1) glUniformMatrix4fv(location, 1, GL_FALSE, value[0]); } @@ -2549,6 +2621,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const GLfloat value[4][ */ void QGLShaderProgram::setUniformValue(int location, const QTransform& value) { + Q_D(QGLShaderProgram); if (location != -1) { GLfloat mat[3][3] = { {value.m11(), value.m12(), value.m13()}, @@ -2582,6 +2655,7 @@ void QGLShaderProgram::setUniformValue */ void QGLShaderProgram::setUniformValueArray(int location, const GLint *values, int count) { + Q_D(QGLShaderProgram); if (location != -1) glUniform1iv(location, count, values); } @@ -2609,6 +2683,7 @@ void QGLShaderProgram::setUniformValueArray */ void QGLShaderProgram::setUniformValueArray(int location, const GLuint *values, int count) { + Q_D(QGLShaderProgram); if (location != -1) glUniform1iv(location, count, reinterpret_cast(values)); } @@ -2637,6 +2712,7 @@ void QGLShaderProgram::setUniformValueArray */ void QGLShaderProgram::setUniformValueArray(int location, const GLfloat *values, int count, int size) { + Q_D(QGLShaderProgram); if (location != -1) { if (size == 1) glUniform1fv(location, count, values); @@ -2674,6 +2750,7 @@ void QGLShaderProgram::setUniformValueArray */ void QGLShaderProgram::setUniformValueArray(int location, const QVector2D *values, int count) { + Q_D(QGLShaderProgram); if (location != -1) glUniform2fv(location, count, reinterpret_cast(values)); } @@ -2699,6 +2776,7 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QVector2D *v */ void QGLShaderProgram::setUniformValueArray(int location, const QVector3D *values, int count) { + Q_D(QGLShaderProgram); if (location != -1) glUniform3fv(location, count, reinterpret_cast(values)); } @@ -2724,6 +2802,7 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QVector3D *v */ void QGLShaderProgram::setUniformValueArray(int location, const QVector4D *values, int count) { + Q_D(QGLShaderProgram); if (location != -1) glUniform4fv(location, count, reinterpret_cast(values)); } @@ -2810,6 +2889,7 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QVector4D *v */ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix2x2 *values, int count) { + Q_D(QGLShaderProgram); setUniformMatrixArray (glUniformMatrix2fv, location, values, count, QMatrix2x2, 2, 2); } @@ -2835,6 +2915,7 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix2x2 * */ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix2x3 *values, int count) { + Q_D(QGLShaderProgram); setUniformGenericMatrixArray (glUniformMatrix2x3fv, glUniform3fv, location, values, count, QMatrix2x3, 2, 3); @@ -2861,6 +2942,7 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix2x3 * */ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix2x4 *values, int count) { + Q_D(QGLShaderProgram); setUniformGenericMatrixArray (glUniformMatrix2x4fv, glUniform4fv, location, values, count, QMatrix2x4, 2, 4); @@ -2887,6 +2969,7 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix2x4 * */ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix3x2 *values, int count) { + Q_D(QGLShaderProgram); setUniformGenericMatrixArray (glUniformMatrix3x2fv, glUniform2fv, location, values, count, QMatrix3x2, 3, 2); @@ -2913,6 +2996,7 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix3x2 * */ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix3x3 *values, int count) { + Q_D(QGLShaderProgram); setUniformMatrixArray (glUniformMatrix3fv, location, values, count, QMatrix3x3, 3, 3); } @@ -2938,6 +3022,7 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix3x3 * */ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix3x4 *values, int count) { + Q_D(QGLShaderProgram); setUniformGenericMatrixArray (glUniformMatrix3x4fv, glUniform4fv, location, values, count, QMatrix3x4, 3, 4); @@ -2964,6 +3049,7 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix3x4 * */ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix4x2 *values, int count) { + Q_D(QGLShaderProgram); setUniformGenericMatrixArray (glUniformMatrix4x2fv, glUniform2fv, location, values, count, QMatrix4x2, 4, 2); @@ -2990,6 +3076,7 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix4x2 * */ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix4x3 *values, int count) { + Q_D(QGLShaderProgram); setUniformGenericMatrixArray (glUniformMatrix4x3fv, glUniform3fv, location, values, count, QMatrix4x3, 4, 3); @@ -3016,6 +3103,7 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix4x3 * */ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix4x4 *values, int count) { + Q_D(QGLShaderProgram); setUniformMatrixArray (glUniformMatrix4fv, location, values, count, QMatrix4x4, 4, 4); } @@ -3061,6 +3149,7 @@ bool QGLShaderProgram::hasShaderPrograms(const QGLContext *context) */ void QGLShaderProgram::shaderDestroyed() { + Q_D(QGLShaderProgram); QGLShader *shader = qobject_cast(sender()); if (shader && !d->removingShaders) removeShader(shader); diff --git a/src/opengl/qglshaderprogram.h b/src/opengl/qglshaderprogram.h index 2848b5f..d8b9a0c 100644 --- a/src/opengl/qglshaderprogram.h +++ b/src/opengl/qglshaderprogram.h @@ -101,11 +101,10 @@ public: GLuint shaderId() const; private: - QGLShaderPrivate *d; - friend class QGLShaderProgram; Q_DISABLE_COPY(QGLShader) + Q_DECLARE_PRIVATE(QGLShader) bool compile(const QList& shaders, QGLShader::ShaderType type); }; @@ -288,9 +287,8 @@ private Q_SLOTS: void shaderDestroyed(); private: - QGLShaderProgramPrivate *d; - Q_DISABLE_COPY(QGLShaderProgram) + Q_DECLARE_PRIVATE(QGLShaderProgram) bool init(); }; -- cgit v0.12 From 60b8fc37ac04b9247481e5f03d1d7fa9ae059a07 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 26 Oct 2009 12:35:48 +1000 Subject: Doc. --- src/declarative/fx/qfxitem.cpp | 13 +++++++++++++ src/declarative/fx/qfxpainteditem.cpp | 2 +- src/declarative/qml/qmlmetaproperty.cpp | 1 + src/declarative/qml/qmlpropertyvalueinterceptor.cpp | 1 + src/declarative/qml/qmlpropertyvaluesource.cpp | 1 + 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index b82a38d..51575cc 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -1198,6 +1198,19 @@ QFxKeysAttached *QFxKeysAttached::qmlAttachedProperties(QObject *obj) } /*! + \class QFxItem + \brief QFxItem is the most basic of all visual items in QML. + + All visual items in Qt Declarative inherit from QFxItem. Although QFxItem + has no visual appearance, it defines all the properties that are + common across visual items - such as the x and y position, the + width and height, \l {anchor-layout}{anchoring} and key handling. + + You can subclass QFxItem to provide your own custom visual item that inherits + these features. +*/ + +/*! \qmlclass Item QFxItem \brief The Item is the most basic of all visual items in QML. diff --git a/src/declarative/fx/qfxpainteditem.cpp b/src/declarative/fx/qfxpainteditem.cpp index 05fcc93..e0ef99f 100644 --- a/src/declarative/fx/qfxpainteditem.cpp +++ b/src/declarative/fx/qfxpainteditem.cpp @@ -55,7 +55,7 @@ QT_BEGIN_NAMESPACE /*! \class QFxPaintedItem \brief The QFxPaintedItem class is an abstract base class for QmlView items that want cached painting. - \ingroup group_coreitems + \internal This is a convenience class for implementing items that paint their contents using a QPainter. The contents of the item are cached behind the scenes. diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index baef71f..edec988 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -61,6 +61,7 @@ QT_BEGIN_NAMESPACE /*! \class QmlMetaProperty \brief The QmlMetaProperty class abstracts accessing QML properties. + \internal */ /*! diff --git a/src/declarative/qml/qmlpropertyvalueinterceptor.cpp b/src/declarative/qml/qmlpropertyvalueinterceptor.cpp index 86905e6..9a9aba8 100644 --- a/src/declarative/qml/qmlpropertyvalueinterceptor.cpp +++ b/src/declarative/qml/qmlpropertyvalueinterceptor.cpp @@ -47,6 +47,7 @@ QT_BEGIN_NAMESPACE /*! \class QmlPropertyValueInterceptor \brief The QmlPropertyValueInterceptor class is inherited by property interceptors such as Behavior. + \internal This class intercepts property writes, allowing for custom handling. For example, Behavior uses this interception to provide a default animation for all changes to a property's value. diff --git a/src/declarative/qml/qmlpropertyvaluesource.cpp b/src/declarative/qml/qmlpropertyvaluesource.cpp index 529ce37..3317289 100644 --- a/src/declarative/qml/qmlpropertyvaluesource.cpp +++ b/src/declarative/qml/qmlpropertyvaluesource.cpp @@ -47,6 +47,7 @@ QT_BEGIN_NAMESPACE /*! \class QmlPropertyValueSource \brief The QmlPropertyValueSource class is inherited by property value sources such as animations and bindings. + \internal */ /*! -- cgit v0.12 From f97cbb44be9e6195ee5a15a687a963ea5bb2f547 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Mon, 26 Oct 2009 12:41:19 +1000 Subject: Fix OpenGL/ES 2.0 bug in previous QGLShaderProgram check-in --- src/opengl/qglshaderprogram.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/opengl/qglshaderprogram.cpp b/src/opengl/qglshaderprogram.cpp index 7fcd6f7..b20c6e9 100644 --- a/src/opengl/qglshaderprogram.cpp +++ b/src/opengl/qglshaderprogram.cpp @@ -1138,7 +1138,7 @@ bool QGLShaderProgram::setProgramBinary(int format, const QByteArray& binary) { #if defined(QT_OPENGL_ES_2) // Load the binary and check that it was linked correctly. - Q_D(const QGLShaderProgram); + Q_D(QGLShaderProgram); GLuint program = d->programGuard.id(); if (!program) return false; -- cgit v0.12 From ded1dbb7e898364dd1cd2b1b129673569805a786 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Mon, 26 Oct 2009 13:02:06 +1000 Subject: Suppress warnings under OpenGL/ES 2.0 in QGLShaderProgram --- src/opengl/qglshaderprogram.cpp | 55 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/opengl/qglshaderprogram.cpp b/src/opengl/qglshaderprogram.cpp index b20c6e9..d028522 100644 --- a/src/opengl/qglshaderprogram.cpp +++ b/src/opengl/qglshaderprogram.cpp @@ -1453,6 +1453,7 @@ int QGLShaderProgram::attributeLocation(const QString& name) const void QGLShaderProgram::setAttributeValue(int location, GLfloat value) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glVertexAttrib1fv(location, &value); } @@ -1478,6 +1479,7 @@ void QGLShaderProgram::setAttributeValue(const char *name, GLfloat value) void QGLShaderProgram::setAttributeValue(int location, GLfloat x, GLfloat y) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat values[2] = {x, y}; glVertexAttrib2fv(location, values); @@ -1507,6 +1509,7 @@ void QGLShaderProgram::setAttributeValue (int location, GLfloat x, GLfloat y, GLfloat z) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat values[3] = {x, y, z}; glVertexAttrib3fv(location, values); @@ -1537,6 +1540,7 @@ void QGLShaderProgram::setAttributeValue (int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat values[4] = {x, y, z, w}; glVertexAttrib4fv(location, values); @@ -1565,6 +1569,7 @@ void QGLShaderProgram::setAttributeValue void QGLShaderProgram::setAttributeValue(int location, const QVector2D& value) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glVertexAttrib2fv(location, reinterpret_cast(&value)); } @@ -1589,6 +1594,7 @@ void QGLShaderProgram::setAttributeValue(const char *name, const QVector2D& valu void QGLShaderProgram::setAttributeValue(int location, const QVector3D& value) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glVertexAttrib3fv(location, reinterpret_cast(&value)); } @@ -1613,6 +1619,7 @@ void QGLShaderProgram::setAttributeValue(const char *name, const QVector3D& valu void QGLShaderProgram::setAttributeValue(int location, const QVector4D& value) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glVertexAttrib4fv(location, reinterpret_cast(&value)); } @@ -1637,6 +1644,7 @@ void QGLShaderProgram::setAttributeValue(const char *name, const QVector4D& valu void QGLShaderProgram::setAttributeValue(int location, const QColor& value) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat values[4] = {value.redF(), value.greenF(), value.blueF(), value.alphaF()}; glVertexAttrib4fv(location, values); @@ -1668,6 +1676,7 @@ void QGLShaderProgram::setAttributeValue (int location, const GLfloat *values, int columns, int rows) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (rows < 1 || rows > 4) { qWarning() << "QGLShaderProgram::setAttributeValue: rows" << rows << "not supported"; return; @@ -1718,6 +1727,7 @@ void QGLShaderProgram::setAttributeArray (int location, const GLfloat *values, int size, int stride) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { glVertexAttribPointer(location, size, GL_FLOAT, GL_FALSE, stride, values); @@ -1737,6 +1747,7 @@ void QGLShaderProgram::setAttributeArray (int location, const QVector2D *values, int stride) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { glVertexAttribPointer(location, 2, GL_FLOAT, GL_FALSE, stride, values); @@ -1756,6 +1767,7 @@ void QGLShaderProgram::setAttributeArray (int location, const QVector3D *values, int stride) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { glVertexAttribPointer(location, 3, GL_FLOAT, GL_FALSE, stride, values); @@ -1775,6 +1787,7 @@ void QGLShaderProgram::setAttributeArray (int location, const QVector4D *values, int stride) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { glVertexAttribPointer(location, 4, GL_FLOAT, GL_FALSE, stride, values); @@ -1856,6 +1869,7 @@ void QGLShaderProgram::setAttributeArray void QGLShaderProgram::disableAttributeArray(int location) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glDisableVertexAttribArray(location); } @@ -1883,6 +1897,7 @@ void QGLShaderProgram::disableAttributeArray(const char *name) int QGLShaderProgram::uniformLocation(const char *name) const { Q_D(const QGLShaderProgram); + Q_UNUSED(d); if (d->linked) { return glGetUniformLocation(d->programGuard.id(), name); } else { @@ -1928,6 +1943,7 @@ int QGLShaderProgram::uniformLocation(const QString& name) const void QGLShaderProgram::setUniformValue(int location, GLfloat value) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glUniform1fv(location, 1, &value); } @@ -1953,6 +1969,7 @@ void QGLShaderProgram::setUniformValue(const char *name, GLfloat value) void QGLShaderProgram::setUniformValue(int location, GLint value) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glUniform1i(location, value); } @@ -1979,6 +1996,7 @@ void QGLShaderProgram::setUniformValue(const char *name, GLint value) void QGLShaderProgram::setUniformValue(int location, GLuint value) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glUniform1i(location, value); } @@ -2005,6 +2023,7 @@ void QGLShaderProgram::setUniformValue(const char *name, GLuint value) void QGLShaderProgram::setUniformValue(int location, GLfloat x, GLfloat y) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat values[2] = {x, y}; glUniform2fv(location, 1, values); @@ -2034,6 +2053,7 @@ void QGLShaderProgram::setUniformValue (int location, GLfloat x, GLfloat y, GLfloat z) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat values[3] = {x, y, z}; glUniform3fv(location, 1, values); @@ -2064,6 +2084,7 @@ void QGLShaderProgram::setUniformValue (int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat values[4] = {x, y, z, w}; glUniform4fv(location, 1, values); @@ -2092,6 +2113,7 @@ void QGLShaderProgram::setUniformValue void QGLShaderProgram::setUniformValue(int location, const QVector2D& value) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glUniform2fv(location, 1, reinterpret_cast(&value)); } @@ -2117,6 +2139,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QVector2D& value) void QGLShaderProgram::setUniformValue(int location, const QVector3D& value) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glUniform3fv(location, 1, reinterpret_cast(&value)); } @@ -2142,6 +2165,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QVector3D& value) void QGLShaderProgram::setUniformValue(int location, const QVector4D& value) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glUniform4fv(location, 1, reinterpret_cast(&value)); } @@ -2168,6 +2192,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QVector4D& value) void QGLShaderProgram::setUniformValue(int location, const QColor& color) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat values[4] = {color.redF(), color.greenF(), color.blueF(), color.alphaF()}; glUniform4fv(location, 1, values); @@ -2196,6 +2221,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QColor& color) void QGLShaderProgram::setUniformValue(int location, const QPoint& point) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat values[4] = {point.x(), point.y()}; glUniform2fv(location, 1, values); @@ -2224,6 +2250,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QPoint& point) void QGLShaderProgram::setUniformValue(int location, const QPointF& point) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat values[4] = {point.x(), point.y()}; glUniform2fv(location, 1, values); @@ -2252,6 +2279,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QPointF& point) void QGLShaderProgram::setUniformValue(int location, const QSize& size) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat values[4] = {size.width(), size.width()}; glUniform2fv(location, 1, values); @@ -2280,6 +2308,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QSize& size) void QGLShaderProgram::setUniformValue(int location, const QSizeF& size) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat values[4] = {size.width(), size.height()}; glUniform2fv(location, 1, values); @@ -2360,6 +2389,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QSizeF& size) void QGLShaderProgram::setUniformValue(int location, const QMatrix2x2& value) { Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformMatrix(glUniformMatrix2fv, location, value, 2, 2); } @@ -2385,6 +2415,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix2x2& value void QGLShaderProgram::setUniformValue(int location, const QMatrix2x3& value) { Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformGenericMatrix (glUniformMatrix2x3fv, glUniform3fv, location, value, 2, 3); } @@ -2411,6 +2442,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix2x3& value void QGLShaderProgram::setUniformValue(int location, const QMatrix2x4& value) { Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformGenericMatrix (glUniformMatrix2x4fv, glUniform4fv, location, value, 2, 4); } @@ -2437,6 +2469,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix2x4& value void QGLShaderProgram::setUniformValue(int location, const QMatrix3x2& value) { Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformGenericMatrix (glUniformMatrix3x2fv, glUniform2fv, location, value, 3, 2); } @@ -2463,6 +2496,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix3x2& value void QGLShaderProgram::setUniformValue(int location, const QMatrix3x3& value) { Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformMatrix(glUniformMatrix3fv, location, value, 3, 3); } @@ -2488,6 +2522,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix3x3& value void QGLShaderProgram::setUniformValue(int location, const QMatrix3x4& value) { Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformGenericMatrix (glUniformMatrix3x4fv, glUniform4fv, location, value, 3, 4); } @@ -2514,6 +2549,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix3x4& value void QGLShaderProgram::setUniformValue(int location, const QMatrix4x2& value) { Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformGenericMatrix (glUniformMatrix4x2fv, glUniform2fv, location, value, 4, 2); } @@ -2540,6 +2576,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix4x2& value void QGLShaderProgram::setUniformValue(int location, const QMatrix4x3& value) { Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformGenericMatrix (glUniformMatrix4x3fv, glUniform3fv, location, value, 4, 3); } @@ -2566,6 +2603,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix4x3& value void QGLShaderProgram::setUniformValue(int location, const QMatrix4x4& value) { Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformMatrix(glUniformMatrix4fv, location, value, 4, 4); } @@ -2594,6 +2632,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix4x4& value void QGLShaderProgram::setUniformValue(int location, const GLfloat value[4][4]) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glUniformMatrix4fv(location, 1, GL_FALSE, value[0]); } @@ -2622,6 +2661,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const GLfloat value[4][ void QGLShaderProgram::setUniformValue(int location, const QTransform& value) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat mat[3][3] = { {value.m11(), value.m12(), value.m13()}, @@ -2656,6 +2696,7 @@ void QGLShaderProgram::setUniformValue void QGLShaderProgram::setUniformValueArray(int location, const GLint *values, int count) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glUniform1iv(location, count, values); } @@ -2684,6 +2725,7 @@ void QGLShaderProgram::setUniformValueArray void QGLShaderProgram::setUniformValueArray(int location, const GLuint *values, int count) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glUniform1iv(location, count, reinterpret_cast(values)); } @@ -2713,6 +2755,7 @@ void QGLShaderProgram::setUniformValueArray void QGLShaderProgram::setUniformValueArray(int location, const GLfloat *values, int count, int size) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { if (size == 1) glUniform1fv(location, count, values); @@ -2751,6 +2794,7 @@ void QGLShaderProgram::setUniformValueArray void QGLShaderProgram::setUniformValueArray(int location, const QVector2D *values, int count) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glUniform2fv(location, count, reinterpret_cast(values)); } @@ -2777,6 +2821,7 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QVector2D *v void QGLShaderProgram::setUniformValueArray(int location, const QVector3D *values, int count) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glUniform3fv(location, count, reinterpret_cast(values)); } @@ -2803,6 +2848,7 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QVector3D *v void QGLShaderProgram::setUniformValueArray(int location, const QVector4D *values, int count) { Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glUniform4fv(location, count, reinterpret_cast(values)); } @@ -2890,6 +2936,7 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QVector4D *v void QGLShaderProgram::setUniformValueArray(int location, const QMatrix2x2 *values, int count) { Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformMatrixArray (glUniformMatrix2fv, location, values, count, QMatrix2x2, 2, 2); } @@ -2916,6 +2963,7 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix2x2 * void QGLShaderProgram::setUniformValueArray(int location, const QMatrix2x3 *values, int count) { Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformGenericMatrixArray (glUniformMatrix2x3fv, glUniform3fv, location, values, count, QMatrix2x3, 2, 3); @@ -2943,6 +2991,7 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix2x3 * void QGLShaderProgram::setUniformValueArray(int location, const QMatrix2x4 *values, int count) { Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformGenericMatrixArray (glUniformMatrix2x4fv, glUniform4fv, location, values, count, QMatrix2x4, 2, 4); @@ -2970,6 +3019,7 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix2x4 * void QGLShaderProgram::setUniformValueArray(int location, const QMatrix3x2 *values, int count) { Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformGenericMatrixArray (glUniformMatrix3x2fv, glUniform2fv, location, values, count, QMatrix3x2, 3, 2); @@ -2997,6 +3047,7 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix3x2 * void QGLShaderProgram::setUniformValueArray(int location, const QMatrix3x3 *values, int count) { Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformMatrixArray (glUniformMatrix3fv, location, values, count, QMatrix3x3, 3, 3); } @@ -3023,6 +3074,7 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix3x3 * void QGLShaderProgram::setUniformValueArray(int location, const QMatrix3x4 *values, int count) { Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformGenericMatrixArray (glUniformMatrix3x4fv, glUniform4fv, location, values, count, QMatrix3x4, 3, 4); @@ -3050,6 +3102,7 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix3x4 * void QGLShaderProgram::setUniformValueArray(int location, const QMatrix4x2 *values, int count) { Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformGenericMatrixArray (glUniformMatrix4x2fv, glUniform2fv, location, values, count, QMatrix4x2, 4, 2); @@ -3077,6 +3130,7 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix4x2 * void QGLShaderProgram::setUniformValueArray(int location, const QMatrix4x3 *values, int count) { Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformGenericMatrixArray (glUniformMatrix4x3fv, glUniform3fv, location, values, count, QMatrix4x3, 4, 3); @@ -3104,6 +3158,7 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix4x3 * void QGLShaderProgram::setUniformValueArray(int location, const QMatrix4x4 *values, int count) { Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformMatrixArray (glUniformMatrix4fv, location, values, count, QMatrix4x4, 4, 4); } -- cgit v0.12 From 35c8033ff51ab6d0567e786b790b8cc49852803b Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Mon, 26 Oct 2009 13:09:05 +1000 Subject: Suppress warnings in QtOpenGL code --- src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp | 1 + src/opengl/qwindowsurface_gl.cpp | 2 +- src/opengl/qwindowsurface_x11gl.cpp | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index bcc6bdb..a0810bc 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -1263,6 +1263,7 @@ void QGL2PaintEngineEx::stroke(const QVectorPath &path, const QPen &pen) QGLContext *ctx = d->ctx; + Q_UNUSED(ctx); if (opaque) { d->prepareForDraw(opaque); diff --git a/src/opengl/qwindowsurface_gl.cpp b/src/opengl/qwindowsurface_gl.cpp index 4547416..42e1c1e 100644 --- a/src/opengl/qwindowsurface_gl.cpp +++ b/src/opengl/qwindowsurface_gl.cpp @@ -364,7 +364,7 @@ void QGLWindowSurface::hijackWindow(QWidget *widget) if (ctxpriv->eglSurface == EGL_NO_SURFACE) { qWarning() << "hijackWindow() could not create EGL surface"; } - qDebug("QGLWindowSurface - using EGLConfig %d", ctxpriv->eglContext->config()); + qDebug("QGLWindowSurface - using EGLConfig %d", reinterpret_cast(ctxpriv->eglContext->config())); #endif widgetPrivate->extraData()->glContext = ctx; diff --git a/src/opengl/qwindowsurface_x11gl.cpp b/src/opengl/qwindowsurface_x11gl.cpp index 8ef239d..db81be2 100644 --- a/src/opengl/qwindowsurface_x11gl.cpp +++ b/src/opengl/qwindowsurface_x11gl.cpp @@ -124,6 +124,9 @@ void QX11GLWindowSurface::setGeometry(const QRect &rect) bool QX11GLWindowSurface::scroll(const QRegion &area, int dx, int dy) { + Q_UNUSED(area); + Q_UNUSED(dx); + Q_UNUSED(dy); return false; } -- cgit v0.12 From c5315a322a65971d636bd73e2444cdd8565e00f4 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 26 Oct 2009 13:33:29 +1000 Subject: Fix accessing QmlList data as a model. --- src/declarative/fx/qfxvisualitemmodel.cpp | 15 ++++++++++----- src/declarative/util/qmllistaccessor.cpp | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/declarative/fx/qfxvisualitemmodel.cpp b/src/declarative/fx/qfxvisualitemmodel.cpp index a078da6..e1ac246 100644 --- a/src/declarative/fx/qfxvisualitemmodel.cpp +++ b/src/declarative/fx/qfxvisualitemmodel.cpp @@ -102,7 +102,7 @@ QHash QFxVisualItemModelAttached::attache class QFxVisualItemModelPrivate : public QObjectPrivate { - Q_DECLARE_PUBLIC(QFxVisualItemModel); + Q_DECLARE_PUBLIC(QFxVisualItemModel) public: QFxVisualItemModelPrivate() : QObjectPrivate(), children(this) {} @@ -143,7 +143,7 @@ public: \code Item { VisualItemModel { - id: ItemModel + id: itemModel Rectangle { height: 30; width: 80; color: "red" } Rectangle { height: 30; width: 80; color: "green" } Rectangle { height: 30; width: 80; color: "blue" } @@ -151,7 +151,7 @@ public: ListView { anchors.fill: parent - model: ItemModel + model: itemModel } } \endcode @@ -416,8 +416,13 @@ int QFxVisualDataModelDataMetaObject::createProperty(const char *name, const cha if ((!model->m_listModelInterface || !model->m_abstractItemModel) && model->m_listAccessor) { model->ensureRoles(); - if (model->m_roleNames.contains(QString::fromUtf8(name))) + if (model->m_roleNames.contains(QString::fromUtf8(name))) { return QmlOpenMetaObject::createProperty(name, type); + } else if (model->m_listAccessor->type() == QmlListAccessor::QmlList) { + QObject *object = model->m_listAccessor->at(data->m_index).value(); + if (object && object->property(name).isValid()) + return QmlOpenMetaObject::createProperty(name, type); + } } else { model->ensureRoles(); QString sname = QString::fromUtf8(name); @@ -448,7 +453,7 @@ QFxVisualDataModelDataMetaObject::propertyCreated(int, QMetaPropertyBuilder &pro return model->m_listAccessor->at(data->m_index); } else { // return any property of a single object instance. - QObject *object = model->m_listAccessor->at(0).value(); + QObject *object = model->m_listAccessor->at(data->m_index).value(); return object->property(prop.name()); } } else if (model->m_listModelInterface) { diff --git a/src/declarative/util/qmllistaccessor.cpp b/src/declarative/util/qmllistaccessor.cpp index 578646b..21007d6 100644 --- a/src/declarative/util/qmllistaccessor.cpp +++ b/src/declarative/util/qmllistaccessor.cpp @@ -136,7 +136,7 @@ QVariant QmlListAccessor::at(int idx) const QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); void *ptr[1]; li->at(idx, ptr); - return QmlMetaType::fromObject((QObject*)ptr[0], li->type()); //XXX only handles QObject-derived types + return QVariant::fromValue((QObject*)ptr[0]); } case QList: return QmlMetaType::listAt(d, idx); -- cgit v0.12 From afbbd1a5d23ab649c37e19225011831a9dbec486 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Mon, 26 Oct 2009 13:55:04 +1000 Subject: Improve states & transitions examples. --- examples/declarative/states/states.qml | 54 ++++++++++++++-------------- examples/declarative/states/transitions.qml | 54 ++++++++++++++-------------- examples/declarative/states/user.png | Bin 0 -> 4886 bytes 3 files changed, 56 insertions(+), 52 deletions(-) create mode 100644 examples/declarative/states/user.png diff --git a/examples/declarative/states/states.qml b/examples/declarative/states/states.qml index acab2f0..6f6b40f 100644 --- a/examples/declarative/states/states.qml +++ b/examples/declarative/states/states.qml @@ -2,47 +2,49 @@ import Qt 4.6 Rectangle { id: page - width: 300; height: 300; color: "white" - // A target region. Clicking in here sets the state to '' - the default state + width: 640; height: 480; color: "#343434" + + // A target region. Clicking in here sets the state to the default state Rectangle { - x: 0; y: 0; width: 50; height: 50 - color: "transparent"; border.color: "black" - MouseRegion { anchors.fill: parent; onClicked: { page.state='' } } + id: initialPosition + anchors { left: parent.left; top: parent.top; leftMargin: 10; topMargin: 20 } + width: 64; height: 64; radius: 6 + color: "Transparent"; border.color: "Gray" + MouseRegion { anchors.fill: parent; onClicked: page.state = '' } } + // Another target region. Clicking in here sets the state to 'Position1' Rectangle { - x: 150; y: 50; width: 50; height: 50 - color: "transparent"; border.color: "black" - MouseRegion { anchors.fill: parent; onClicked: { page.state='Position1' } } + id: position1 + anchors { right: parent.right; verticalCenter: parent.verticalCenter; rightMargin: 20 } + width: 64; height: 64; radius: 6 + color: "Transparent"; border.color: "Gray" + MouseRegion { anchors.fill: parent; onClicked: page.state = 'Position1' } } + // Another target region. Clicking in here sets the state to 'Position2' Rectangle { - x: 0; y: 200; width: 50; height: 50 - color: "transparent"; border.color: "black" - MouseRegion { anchors.fill: parent; onClicked: { page.state='Position2' } } + id: position2 + anchors { left: parent.left; bottom: parent.bottom; leftMargin: 10; bottomMargin: 20 } + width: 64; height: 64; radius: 6 + color: "Transparent"; border.color: "Gray" + MouseRegion { anchors.fill: parent; onClicked: page.state = 'Position2' } } - // Rect which will be moved when my state changes - Rectangle { id: myrect; width: 50; height: 50; color: "red" } + + // The image which will be moved when my state changes + Image { id: user; source: "user.png"; x: initialPosition.x; y: initialPosition.y } states: [ - // In state 'Position1', change the 'myrect' item x, y to 150, 50. + // In state 'Position1', change the 'user' item position to rect2's position. State { name: "Position1" - PropertyChanges { - target: myrect - x: 150 - y: 50 - } + PropertyChanges { target: user; x: position1.x; y: position1.y } }, - // In state 'Position2', change y to 100. We do not specify 'x' here - - // it will therefore be restored to its default value of 0, if it - // had been changed. + + // In state 'Position2', change the 'user' item position to rect3's position. State { name: "Position2" - PropertyChanges { - target: myrect - y: 200 - } + PropertyChanges { target: user; x: position2.x; y: position2.y } } ] } diff --git a/examples/declarative/states/transitions.qml b/examples/declarative/states/transitions.qml index cc6894d..ba97d9be 100644 --- a/examples/declarative/states/transitions.qml +++ b/examples/declarative/states/transitions.qml @@ -2,47 +2,49 @@ import Qt 4.6 Rectangle { id: page - width: 300; height: 300; color: "white" - // A target region. Clicking in here sets the state to '' - the default state + width: 640; height: 480; color: "#343434" + + // A target region. Clicking in here sets the state to the default state Rectangle { - x: 0; y: 0; width: 50; height: 50 - color: "transparent"; border.color: "black" - MouseRegion { anchors.fill: parent; onClicked: { page.state='' } } + id: initialPosition + anchors { left: parent.left; top: parent.top; leftMargin: 10; topMargin: 20 } + width: 64; height: 64; radius: 6 + color: "Transparent"; border.color: "Gray" + MouseRegion { anchors.fill: parent; onClicked: page.state = '' } } + // Another target region. Clicking in here sets the state to 'Position1' Rectangle { - x: 150; y: 50; width: 50; height: 50 - color: "transparent"; border.color: "black" - MouseRegion { anchors.fill: parent; onClicked: { page.state='Position1' } } + id: position1 + anchors { right: parent.right; verticalCenter: parent.verticalCenter; rightMargin: 20 } + width: 64; height: 64; radius: 6 + color: "Transparent"; border.color: "Gray" + MouseRegion { anchors.fill: parent; onClicked: page.state = 'Position1' } } + // Another target region. Clicking in here sets the state to 'Position2' Rectangle { - x: 0; y: 200; width: 50; height: 50 - color: "transparent"; border.color: "black" - MouseRegion { anchors.fill: parent; onClicked: { page.state='Position2' } } + id: position2 + anchors { left: parent.left; bottom: parent.bottom; leftMargin: 10; bottomMargin: 20 } + width: 64; height: 64; radius: 6 + color: "Transparent"; border.color: "Gray" + MouseRegion { anchors.fill: parent; onClicked: page.state = 'Position2' } } - // Rect which will be moved when my state changes - Rectangle { id: myrect; width: 50; height: 50; color: "red" } + + // The image which will be moved when my state changes + Image { id: user; source: "user.png"; x: initialPosition.x; y: initialPosition.y } states: [ - // In state 'Position1', change the 'myrect' item x, y to 150, 50. + // In state 'Position1', change the 'user' item position to rect2's position. State { name: "Position1" - PropertyChanges { - target: myrect - x: 150 - y: 50 - } + PropertyChanges { target: user; x: position1.x; y: position1.y } }, - // In state 'Position2', change y to 100. We do not specify 'x' here - - // it will therefore be restored to its default value of 0, if it - // had been changed. + + // In state 'Position2', change the 'user' item position to rect3's position. State { name: "Position2" - PropertyChanges { - target: myrect - y: 200 - } + PropertyChanges { target: user; x: position2.x; y: position2.y } } ] diff --git a/examples/declarative/states/user.png b/examples/declarative/states/user.png new file mode 100644 index 0000000..dd7d7a2 Binary files /dev/null and b/examples/declarative/states/user.png differ -- cgit v0.12 From 8c1bffc7fa73e5249046bae949069bf8df23b78d Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 26 Oct 2009 13:55:18 +1000 Subject: Docs. --- doc/src/declarative/extending.qdoc | 15 +++++++++++++-- doc/src/declarative/qtdeclarative.qdoc | 1 + examples/declarative/extending/attached/birthdayparty.h | 8 +++++--- examples/declarative/extending/binding/birthdayparty.h | 8 +++++--- examples/declarative/extending/signal/birthdayparty.h | 8 +++++--- .../declarative/extending/valuesource/birthdayparty.h | 8 +++++--- src/declarative/fx/qfxgridview.cpp | 5 ++--- src/declarative/fx/qfxlistview.cpp | 5 ++--- 8 files changed, 38 insertions(+), 20 deletions(-) diff --git a/doc/src/declarative/extending.qdoc b/doc/src/declarative/extending.qdoc index db35961..b872632 100644 --- a/doc/src/declarative/extending.qdoc +++ b/doc/src/declarative/extending.qdoc @@ -300,11 +300,22 @@ attachment object are those that become available for use as the attached property block. Any QML type can become an attaching type by declaring the -\c qmlAttachedProperties() public function: +\c qmlAttachedProperties() public function and declaring that the class has +QML_HAS_ATTACHED_PROPERTIES: \quotation \code -static AttachedPropertiesType *qmlAttachedProperties(QObject *object) +class MyType : public QObject { + Q_OBJECT +public: + + ... + + static AttachedPropertiesType *qmlAttachedProperties(QObject *object); +}; + +QML_DECLARE_TYPEINFO(MyType, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPE(MyType) \endcode Return an attachment object, of type \a AttachedPropertiesType, for the attachee \a object instance. It is customary, though not strictly required, for diff --git a/doc/src/declarative/qtdeclarative.qdoc b/doc/src/declarative/qtdeclarative.qdoc index 7be98db..ba2d70e 100644 --- a/doc/src/declarative/qtdeclarative.qdoc +++ b/doc/src/declarative/qtdeclarative.qdoc @@ -84,6 +84,7 @@ completely new applications. QML is fully \l {Extending QML}{extensible from C+ \o \l {QML Documents} \o \l {Property Binding} \o \l {ECMAScript Blocks} +\o \l {QML Scope} \o \l {Network Transparency} \o \l {qmlmodels}{Data Models} \o \l {anchor-layout}{Anchor-based Layout} diff --git a/examples/declarative/extending/attached/birthdayparty.h b/examples/declarative/extending/attached/birthdayparty.h index 8249af5..2ea065c 100644 --- a/examples/declarative/extending/attached/birthdayparty.h +++ b/examples/declarative/extending/attached/birthdayparty.h @@ -9,7 +9,7 @@ class BirthdayPartyAttached : public QObject { Q_OBJECT -Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp); +Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp) public: BirthdayPartyAttached(QObject *object); @@ -19,7 +19,7 @@ public: private: QDate m_rsvp; }; -QML_DECLARE_TYPE(BirthdayPartyAttached); +QML_DECLARE_TYPE(BirthdayPartyAttached) class BirthdayParty : public QObject { @@ -40,6 +40,8 @@ private: Person *m_celebrant; QmlConcreteList m_guests; }; -QML_DECLARE_TYPE(BirthdayParty); + +QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPE(BirthdayParty) #endif // BIRTHDAYPARTY_H diff --git a/examples/declarative/extending/binding/birthdayparty.h b/examples/declarative/extending/binding/birthdayparty.h index 6905746..2757561 100644 --- a/examples/declarative/extending/binding/birthdayparty.h +++ b/examples/declarative/extending/binding/birthdayparty.h @@ -10,7 +10,7 @@ class BirthdayPartyAttached : public QObject { Q_OBJECT -Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp NOTIFY rsvpChanged); +Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp NOTIFY rsvpChanged) public: BirthdayPartyAttached(QObject *object); @@ -23,7 +23,7 @@ signals: private: QDate m_rsvp; }; -QML_DECLARE_TYPE(BirthdayPartyAttached); +QML_DECLARE_TYPE(BirthdayPartyAttached) class BirthdayParty : public QObject { @@ -56,6 +56,8 @@ private: Person *m_celebrant; QmlConcreteList m_guests; }; -QML_DECLARE_TYPE(BirthdayParty); + +QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPE(BirthdayParty) #endif // BIRTHDAYPARTY_H diff --git a/examples/declarative/extending/signal/birthdayparty.h b/examples/declarative/extending/signal/birthdayparty.h index 14d7c29..5dea2e8 100644 --- a/examples/declarative/extending/signal/birthdayparty.h +++ b/examples/declarative/extending/signal/birthdayparty.h @@ -9,7 +9,7 @@ class BirthdayPartyAttached : public QObject { Q_OBJECT -Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp); +Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp) public: BirthdayPartyAttached(QObject *object); @@ -19,7 +19,7 @@ public: private: QDate m_rsvp; }; -QML_DECLARE_TYPE(BirthdayPartyAttached); +QML_DECLARE_TYPE(BirthdayPartyAttached) class BirthdayParty : public QObject { @@ -47,6 +47,8 @@ private: Person *m_celebrant; QmlConcreteList m_guests; }; -QML_DECLARE_TYPE(BirthdayParty); + +QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPE(BirthdayParty) #endif // BIRTHDAYPARTY_H diff --git a/examples/declarative/extending/valuesource/birthdayparty.h b/examples/declarative/extending/valuesource/birthdayparty.h index fd25f28..75a2477 100644 --- a/examples/declarative/extending/valuesource/birthdayparty.h +++ b/examples/declarative/extending/valuesource/birthdayparty.h @@ -10,7 +10,7 @@ class BirthdayPartyAttached : public QObject { Q_OBJECT -Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp); +Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp) public: BirthdayPartyAttached(QObject *object); @@ -20,7 +20,7 @@ public: private: QDate m_rsvp; }; -QML_DECLARE_TYPE(BirthdayPartyAttached); +QML_DECLARE_TYPE(BirthdayPartyAttached) class BirthdayParty : public QObject { @@ -52,6 +52,8 @@ private: Person *m_celebrant; QmlConcreteList m_guests; }; -QML_DECLARE_TYPE(BirthdayParty); + +QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPE(BirthdayParty) #endif // BIRTHDAYPARTY_H diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp index 36c06a4..0b2a935 100644 --- a/src/declarative/fx/qfxgridview.cpp +++ b/src/declarative/fx/qfxgridview.cpp @@ -736,14 +736,13 @@ QFxGridView::~QFxGridView() \endcode */ -//XXX change to \qmlattachedsignal when it exists. /*! - \qmlattachedproperty void GridView::onAdd + \qmlattachedsignal GridView::onAdd() This attached handler is called immediately after an item is added to the view. */ /*! - \qmlattachedproperty void GridView::onRemove + \qmlattachedsignal GridView::onRemove() This attached handler is called immediately before an item is removed from the view. */ diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 23bf573..1a4a60c 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -926,14 +926,13 @@ QFxListView::~QFxListView() \endcode */ -//XXX change to \qmlattachedsignal when it exists. /*! - \qmlattachedproperty void ListView::onAdd + \qmlattachedsignal ListView::onAdd() This attached handler is called immediately after an item is added to the view. */ /*! - \qmlattachedproperty void ListView::onRemove + \qmlattachedsignal ListView::onRemove() This attached handler is called immediately before an item is removed from the view. */ -- cgit v0.12 From 90a883796acb961a572c90d53c0505110a466a8a Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Mon, 26 Oct 2009 14:11:32 +1000 Subject: Fix to show expression query widget and allow QmlEngineDebug values for widgets to be changed after construction. --- tools/qmldebugger/engine.cpp | 17 ++++++++++++++--- tools/qmldebugger/engine.h | 5 +++-- tools/qmldebugger/expressionquerywidget.cpp | 27 ++++++++++++++++----------- tools/qmldebugger/expressionquerywidget.h | 7 +++++-- tools/qmldebugger/objectpropertiesview.cpp | 9 ++++++++- tools/qmldebugger/objectpropertiesview.h | 5 ++++- tools/qmldebugger/objecttree.cpp | 8 ++++++++ tools/qmldebugger/objecttree.h | 5 ++++- tools/qmldebugger/watchtable.cpp | 13 ++++++++++++- tools/qmldebugger/watchtable.h | 5 ++++- 10 files changed, 78 insertions(+), 23 deletions(-) diff --git a/tools/qmldebugger/engine.cpp b/tools/qmldebugger/engine.cpp index 3cf5165..a1fd009 100644 --- a/tools/qmldebugger/engine.cpp +++ b/tools/qmldebugger/engine.cpp @@ -12,6 +12,7 @@ #include "engine.h" #include "objectpropertiesview.h" +#include "expressionquerywidget.h" #include "objecttree.h" #include "watchtable.h" @@ -37,7 +38,7 @@ private: }; EnginePane::EnginePane(QmlDebugConnection *conn, QWidget *parent) -: QWidget(parent), m_client(new QmlEngineDebug(conn, this)), m_engines(0), m_context(0), m_watchTableModel(0) +: QWidget(parent), m_client(new QmlEngineDebug(conn, this)), m_engines(0), m_context(0), m_watchTableModel(0), m_exprQueryWidget(0) { QVBoxLayout *layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); @@ -84,9 +85,19 @@ EnginePane::EnginePane(QmlDebugConnection *conn, QWidget *parent) connect(m_watchTableView, SIGNAL(objectActivated(int)), m_objTree, SLOT(setCurrentObject(int))); - + + m_exprQueryWidget = new ExpressionQueryWidget(m_client); + connect(m_objTree, SIGNAL(currentObjectChanged(QmlDebugObjectReference)), + m_exprQueryWidget, SLOT(setCurrentObject(QmlDebugObjectReference))); + + QSplitter *propertiesTab = new QSplitter(Qt::Vertical); + propertiesTab->addWidget(m_propertiesView); + propertiesTab->addWidget(m_exprQueryWidget); + propertiesTab->setStretchFactor(0, 2); + propertiesTab->setStretchFactor(1, 1); + m_tabs = new QTabWidget(this); - m_tabs->addTab(m_propertiesView, tr("Properties")); + m_tabs->addTab(propertiesTab, tr("Properties")); m_tabs->addTab(m_watchTableView, tr("Watched")); splitter->addWidget(m_objTree); diff --git a/tools/qmldebugger/engine.h b/tools/qmldebugger/engine.h index 8e8c0f2..a3ebe46 100644 --- a/tools/qmldebugger/engine.h +++ b/tools/qmldebugger/engine.h @@ -17,6 +17,7 @@ class QmlDebugWatch; class ObjectTree; class WatchTableModel; class WatchTableView; +class ExpressionQueryWidget; class QTabWidget; @@ -45,12 +46,12 @@ private: ObjectTree *m_objTree; QTabWidget *m_tabs; WatchTableView *m_watchTableView; + WatchTableModel *m_watchTableModel; + ExpressionQueryWidget *m_exprQueryWidget; QmlView *m_engineView; QList m_engineItems; - WatchTableModel *m_watchTableModel; - ObjectPropertiesView *m_propertiesView; }; diff --git a/tools/qmldebugger/expressionquerywidget.cpp b/tools/qmldebugger/expressionquerywidget.cpp index b29b465..53ede3a 100644 --- a/tools/qmldebugger/expressionquerywidget.cpp +++ b/tools/qmldebugger/expressionquerywidget.cpp @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -14,25 +16,21 @@ ExpressionQueryWidget::ExpressionQueryWidget(QmlEngineDebug *client, QWidget *pa m_style(Compact), m_client(client), m_query(0), - m_groupBox(0), m_textEdit(new QTextEdit), m_lineEdit(0), m_button(0) { m_prompt = QLatin1String(">> "); - m_groupBox = new QGroupBox; - QVBoxLayout *vbox = new QVBoxLayout(m_groupBox); - vbox->addWidget(m_textEdit); - QVBoxLayout *layout = new QVBoxLayout(this); - layout->addWidget(m_groupBox); + layout->setMargin(0); + layout->addWidget(m_textEdit); updateTitle(); if (m_style == Compact) { QHBoxLayout *hbox = new QHBoxLayout; - m_button = new QPushButton(tr("Execute")); + m_button = new QPushButton(tr("Query")); m_button->setEnabled(false); connect(m_button, SIGNAL(clicked()), SLOT(executeExpression())); m_lineEdit = new QLineEdit; @@ -41,7 +39,7 @@ ExpressionQueryWidget::ExpressionQueryWidget(QmlEngineDebug *client, QWidget *pa hbox->addWidget(new QLabel(tr("Expression:"))); hbox->addWidget(m_lineEdit); hbox->addWidget(m_button); - vbox->addLayout(hbox); + layout->addLayout(hbox); m_textEdit->setReadOnly(true); m_lineEdit->installEventFilter(this); @@ -50,17 +48,21 @@ ExpressionQueryWidget::ExpressionQueryWidget(QmlEngineDebug *client, QWidget *pa } } +void ExpressionQueryWidget::setEngineDebug(QmlEngineDebug *client) +{ + m_client = client; +} + void ExpressionQueryWidget::updateTitle() { if (m_currObject.debugId() < 0) { - m_groupBox->setTitle(tr("Expression queries")); + m_title = tr("Expression queries"); } else { QString desc = QLatin1String("<") + m_currObject.className() + QLatin1String(": ") + (m_currObject.name().isEmpty() ? QLatin1String("") : m_currObject.name()) + QLatin1String(">"); - m_groupBox->setTitle(tr("Expression queries (using context for %1)" - , "Selected object").arg(desc)); + m_title = tr("Expression queries (using context for %1)" , "Selected object").arg(desc); } } @@ -103,6 +105,9 @@ void ExpressionQueryWidget::showCurrentContext() void ExpressionQueryWidget::executeExpression() { + if (!m_client) + return; + if (m_style == Compact) m_expr = m_lineEdit->text().trimmed(); else diff --git a/tools/qmldebugger/expressionquerywidget.h b/tools/qmldebugger/expressionquerywidget.h index 8db8f9f..3d9b580 100644 --- a/tools/qmldebugger/expressionquerywidget.h +++ b/tools/qmldebugger/expressionquerywidget.h @@ -21,7 +21,9 @@ public: Shell }; - ExpressionQueryWidget(QmlEngineDebug *client, QWidget *parent = 0); + ExpressionQueryWidget(QmlEngineDebug *client = 0, QWidget *parent = 0); + + void setEngineDebug(QmlEngineDebug *client); protected: bool eventFilter(QObject *obj, QEvent *event); @@ -44,7 +46,6 @@ private: QmlEngineDebug *m_client; QmlDebugExpressionQuery *m_query; - QGroupBox *m_groupBox; QTextEdit *m_textEdit; QLineEdit *m_lineEdit; QPushButton *m_button; @@ -52,6 +53,8 @@ private: QString m_expr; QString m_lastExpr; + QString m_title; + QmlDebugObjectReference m_currObject; QmlDebugObjectReference m_objectAtLastFocus; }; diff --git a/tools/qmldebugger/objectpropertiesview.cpp b/tools/qmldebugger/objectpropertiesview.cpp index 61afe3f..274552a 100644 --- a/tools/qmldebugger/objectpropertiesview.cpp +++ b/tools/qmldebugger/objectpropertiesview.cpp @@ -53,8 +53,15 @@ ObjectPropertiesView::ObjectPropertiesView(QmlEngineDebug *client, QWidget *pare layout->addWidget(m_tree); } +void ObjectPropertiesView::setEngineDebug(QmlEngineDebug *client) +{ + m_client = client; +} + void ObjectPropertiesView::reload(const QmlDebugObjectReference &obj) { + if (!m_client) + return; if (m_query) delete m_query; @@ -68,7 +75,7 @@ void ObjectPropertiesView::reload(const QmlDebugObjectReference &obj) void ObjectPropertiesView::queryFinished() { - if (!m_query) + if (!m_client || !m_query) return; QmlDebugObjectReference obj = m_query->object(); diff --git a/tools/qmldebugger/objectpropertiesview.h b/tools/qmldebugger/objectpropertiesview.h index 0f72ff4..d555940 100644 --- a/tools/qmldebugger/objectpropertiesview.h +++ b/tools/qmldebugger/objectpropertiesview.h @@ -9,13 +9,16 @@ QT_BEGIN_NAMESPACE class QTreeWidget; class QTreeWidgetItem; +class QmlDebugConnection; class ObjectPropertiesView : public QWidget { Q_OBJECT public: - ObjectPropertiesView(QmlEngineDebug *client, QWidget *parent = 0); + ObjectPropertiesView(QmlEngineDebug *client = 0, QWidget *parent = 0); + void setEngineDebug(QmlEngineDebug *client); + signals: void activated(const QmlDebugObjectReference &, const QmlDebugPropertyReference &); diff --git a/tools/qmldebugger/objecttree.cpp b/tools/qmldebugger/objecttree.cpp index 1254ae7..981a80b 100644 --- a/tools/qmldebugger/objecttree.cpp +++ b/tools/qmldebugger/objecttree.cpp @@ -24,8 +24,16 @@ ObjectTree::ObjectTree(QmlEngineDebug *client, QWidget *parent) this, SLOT(currentItemChanged(QTreeWidgetItem *))); } +void ObjectTree::setEngineDebug(QmlEngineDebug *client) +{ + m_client = client; +} + void ObjectTree::reload(int objectDebugId) { + if (!m_client) + return; + if (m_query) { delete m_query; m_query = 0; diff --git a/tools/qmldebugger/objecttree.h b/tools/qmldebugger/objecttree.h index 3c0a5c6..95820f3 100644 --- a/tools/qmldebugger/objecttree.h +++ b/tools/qmldebugger/objecttree.h @@ -11,14 +11,17 @@ class QmlEngineDebug; class QmlDebugObjectReference; class QmlDebugObjectQuery; class QmlDebugContextReference; +class QmlDebugConnection; class ObjectTree : public QTreeWidget { Q_OBJECT public: - ObjectTree(QmlEngineDebug *client, QWidget *parent = 0); + ObjectTree(QmlEngineDebug *client = 0, QWidget *parent = 0); + void setEngineDebug(QmlEngineDebug *client); + signals: void currentObjectChanged(const QmlDebugObjectReference &); void expressionWatchRequested(const QmlDebugObjectReference &, const QString &); diff --git a/tools/qmldebugger/watchtable.cpp b/tools/qmldebugger/watchtable.cpp index 512bfb2..774727b 100644 --- a/tools/qmldebugger/watchtable.cpp +++ b/tools/qmldebugger/watchtable.cpp @@ -23,6 +23,11 @@ WatchTableModel::~WatchTableModel() delete m_columns[i].watch; } +void WatchTableModel::setEngineDebug(QmlEngineDebug *client) +{ + m_client = client; +} + void WatchTableModel::addWatch(QmlDebugWatch *watch, const QString &title) { QString property; @@ -193,7 +198,7 @@ void WatchTableModel::addValue(int column, const QVariant &value) void WatchTableModel::togglePropertyWatch(const QmlDebugObjectReference &object, const QmlDebugPropertyReference &property) { - if (!property.hasNotifySignal()) + if (!m_client || !property.hasNotifySignal()) return; QmlDebugWatch *watch = findWatch(object.debugId(), property.name()); @@ -228,6 +233,9 @@ void WatchTableModel::watchedValueChanged(const QByteArray &propertyName, const void WatchTableModel::expressionWatchRequested(const QmlDebugObjectReference &obj, const QString &expr) { + if (!m_client) + return; + QmlDebugWatch *watch = m_client->addWatch(obj, expr, this); if (watch->state() == QmlDebugWatch::Dead) { @@ -241,6 +249,9 @@ void WatchTableModel::expressionWatchRequested(const QmlDebugObjectReference &ob void WatchTableModel::stopWatching(int column) { + if (!m_client) + return; + QmlDebugWatch *watch = findWatch(column); if (watch) { m_client->removeWatch(watch); diff --git a/tools/qmldebugger/watchtable.h b/tools/qmldebugger/watchtable.h index abada2b..772142c 100644 --- a/tools/qmldebugger/watchtable.h +++ b/tools/qmldebugger/watchtable.h @@ -13,6 +13,7 @@ QT_BEGIN_NAMESPACE class QmlDebugWatch; class QmlEngineDebug; +class QmlDebugConnection; class QmlDebugPropertyReference; class QmlDebugObjectReference; @@ -20,9 +21,11 @@ class WatchTableModel : public QAbstractTableModel { Q_OBJECT public: - WatchTableModel(QmlEngineDebug *client, QObject *parent = 0); + WatchTableModel(QmlEngineDebug *client = 0, QObject *parent = 0); ~WatchTableModel(); + void setEngineDebug(QmlEngineDebug *client); + QmlDebugWatch *findWatch(int column) const; int columnForWatch(QmlDebugWatch *watch) const; -- cgit v0.12 From 9159ddc77750ce46a36995b8818cd5edcf7e1877 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 26 Oct 2009 14:18:40 +1000 Subject: unwarn --- src/declarative/fx/qfxanchors.cpp | 1 - src/declarative/qml/qbitfield_p.h | 4 ++-- src/declarative/qml/qmlcomponent_p.h | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/declarative/fx/qfxanchors.cpp b/src/declarative/fx/qfxanchors.cpp index 737aa63..8d4a8b8 100644 --- a/src/declarative/fx/qfxanchors.cpp +++ b/src/declarative/fx/qfxanchors.cpp @@ -181,7 +181,6 @@ void QFxAnchorsPrivate::centerInChanged() void QFxAnchorsPrivate::clearItem(QFxItem *item) { - Q_Q(QFxAnchors); if (!item) return; if (fill == item) diff --git a/src/declarative/qml/qbitfield_p.h b/src/declarative/qml/qbitfield_p.h index 70d5041..9804a18 100644 --- a/src/declarative/qml/qbitfield_p.h +++ b/src/declarative/qml/qbitfield_p.h @@ -139,11 +139,11 @@ QBitField QBitField::united(const QBitField &o) rv.data = rv.ownData + 1; if (bits > o.bits) { ::memcpy((quint32 *)rv.data, data, length * sizeof(quint32)); - for (quint32 ii = 0; ii < (o.bits + 31) / 32; ++ii) + for (quint32 ii = 0; ii < quint32(o.bits + 31) / 32; ++ii) ((quint32 *)rv.data)[ii] |= o.data[ii]; } else { ::memcpy((quint32 *)rv.data, o.data, length * sizeof(quint32)); - for (quint32 ii = 0; ii < (bits + 31) / 32; ++ii) + for (quint32 ii = 0; ii < quint32(bits + 31) / 32; ++ii) ((quint32 *)rv.data)[ii] |= data[ii]; } return rv; diff --git a/src/declarative/qml/qmlcomponent_p.h b/src/declarative/qml/qmlcomponent_p.h index 7eedfbd..f90502f 100644 --- a/src/declarative/qml/qmlcomponent_p.h +++ b/src/declarative/qml/qmlcomponent_p.h @@ -76,7 +76,7 @@ class QmlComponentPrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QmlComponent) public: - QmlComponentPrivate() : typeData(0), progress(0.), start(-1), count(-1), cc(0), completePending(false), componentAttacheds(0), engine(0) {} + QmlComponentPrivate() : typeData(0), progress(0.), start(-1), count(-1), cc(0), componentAttacheds(0), completePending(false), engine(0) {} QObject *create(QmlContext *context, const QBitField &); -- cgit v0.12 From ab235f522d22f4940e40aa3114fface354fbb611 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 26 Oct 2009 14:23:33 +1000 Subject: Work again for URLs. --- tools/qmlviewer/qmlviewer.cpp | 85 ++++++++++++++++++++++--------------------- tools/qmlviewer/qmlviewer.h | 3 +- 2 files changed, 45 insertions(+), 43 deletions(-) diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index 60fa13a..73aae44 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -600,14 +600,17 @@ void QmlViewer::addLibraryPath(const QString& lib) void QmlViewer::reload() { - openQml(currentFileName); + openQml(canvas->url()); } void QmlViewer::open() { - QString fileName = QFileDialog::getOpenFileName(this, tr("Open QML file"), currentFileName, tr("QML Files (*.qml)")); - if (!fileName.isEmpty()) - openQml(fileName); + QString cur = canvas->url().toLocalFile(); + QString fileName = QFileDialog::getOpenFileName(this, tr("Open QML file"), cur, tr("QML Files (*.qml)")); + if (!fileName.isEmpty()) { + QFileInfo fi(fileName); + openQml(QUrl::fromLocalFile(fi.absoluteFilePath())); + } } void QmlViewer::executeErrors() @@ -615,55 +618,55 @@ void QmlViewer::executeErrors() if (tester) tester->executefailure(); } -void QmlViewer::openQml(const QString& fileName) +void QmlViewer::openQml(const QUrl& url) { - setWindowTitle(tr("%1 - Qt Declarative UI Viewer").arg(fileName)); + QString fileName = url.toLocalFile(); + setWindowTitle(tr("%1 - Qt Declarative UI Viewer").arg(fileName.isEmpty() ? url.toString() : fileName)); if (!m_script.isEmpty()) tester = new QFxTester(m_script, m_scriptOptions, canvas); canvas->reset(); - currentFileName = fileName; - QUrl url(fileName); - QFileInfo fi(fileName); - if (fi.exists()) { - if (fi.suffix().toLower() != QLatin1String("qml")) { - qWarning() << "qmlviewer cannot open non-QML file" << fileName; - return; - } + if (!fileName.isEmpty()) { + QFileInfo fi(fileName); + if (fi.exists()) { + if (fi.suffix().toLower() != QLatin1String("qml")) { + qWarning() << "qmlviewer cannot open non-QML file" << fileName; + return; + } - url = QUrl::fromLocalFile(fi.absoluteFilePath()); - QmlContext *ctxt = canvas->rootContext(); - QDir dir(fi.path()+"/dummydata", "*.qml"); - QStringList list = dir.entryList(); - for (int i = 0; i < list.size(); ++i) { - QString qml = list.at(i); - QFile f(dir.filePath(qml)); - f.open(QIODevice::ReadOnly); - QByteArray data = f.readAll(); - QmlComponent comp(canvas->engine()); - comp.setData(data, QUrl()); - QObject *dummyData = comp.create(); - - if(comp.isError()) { - QList errors = comp.errors(); - foreach (const QmlError &error, errors) { - qWarning() << error; + QmlContext *ctxt = canvas->rootContext(); + QDir dir(fi.path()+"/dummydata", "*.qml"); + QStringList list = dir.entryList(); + for (int i = 0; i < list.size(); ++i) { + QString qml = list.at(i); + QFile f(dir.filePath(qml)); + f.open(QIODevice::ReadOnly); + QByteArray data = f.readAll(); + QmlComponent comp(canvas->engine()); + comp.setData(data, QUrl()); + QObject *dummyData = comp.create(); + + if(comp.isError()) { + QList errors = comp.errors(); + foreach (const QmlError &error, errors) { + qWarning() << error; + } + if (tester) tester->executefailure(); } - if (tester) tester->executefailure(); - } - if (dummyData) { - qWarning() << "Loaded dummy data:" << dir.filePath(qml); - qml.truncate(qml.length()-4); - ctxt->setContextProperty(qml, dummyData); - dummyData->setParent(this); + if (dummyData) { + qWarning() << "Loaded dummy data:" << dir.filePath(qml); + qml.truncate(qml.length()-4); + ctxt->setContextProperty(qml, dummyData); + dummyData->setParent(this); + } } + } else { + qWarning() << "qmlviewer cannot find file:" << fileName; + return; } - } else { - qWarning() << "qmlviewer cannot find file:" << fileName; - return; } canvas->setUrl(url); diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h index 7f9dca0..f0578eb 100644 --- a/tools/qmlviewer/qmlviewer.h +++ b/tools/qmlviewer/qmlviewer.h @@ -63,7 +63,7 @@ public: public slots: void sceneResized(QSize size); - void openQml(const QString& fileName); + void openQml(const QUrl&); void open(); void reload(); void takeSnapShot(); @@ -93,7 +93,6 @@ private: void setupProxy(); QString getVideoFileName(); - QString currentFileName; PreviewDeviceSkin *skin; QSize skinscreensize; QmlView *canvas; -- cgit v0.12 From 0478559cd1ec393c1a2e098822858a2b989ed81f Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 26 Oct 2009 14:24:06 +1000 Subject: Wait for qmldir remote content so that imports work remotely. --- src/declarative/qml/qmlcompositetypedata_p.h | 3 +- src/declarative/qml/qmlcompositetypemanager.cpp | 131 ++++++++++++++++-------- src/declarative/qml/qmlcompositetypemanager_p.h | 1 + src/declarative/qml/qmlengine.cpp | 65 ++++++------ src/declarative/qml/qmlengine_p.h | 2 +- src/declarative/qml/qmlscriptparser.cpp | 3 + 6 files changed, 131 insertions(+), 74 deletions(-) diff --git a/src/declarative/qml/qmlcompositetypedata_p.h b/src/declarative/qml/qmlcompositetypedata_p.h index fa11137..ffcef4c 100644 --- a/src/declarative/qml/qmlcompositetypedata_p.h +++ b/src/declarative/qml/qmlcompositetypedata_p.h @@ -69,7 +69,8 @@ public: Invalid, Complete, Error, - Waiting + Waiting, + WaitingResources }; Status status; enum ErrorType { diff --git a/src/declarative/qml/qmlcompositetypemanager.cpp b/src/declarative/qml/qmlcompositetypemanager.cpp index 3c76344..9444a22 100644 --- a/src/declarative/qml/qmlcompositetypemanager.cpp +++ b/src/declarative/qml/qmlcompositetypemanager.cpp @@ -352,18 +352,6 @@ void QmlCompositeTypeManager::setData(QmlCompositeTypeData *unit, if (!unit->data.parse(data, url)) { ok = false; unit->errors << unit->data.errors(); - } else { - foreach (QmlScriptParser::Import imp, unit->data.imports()) { - int dot = imp.version.indexOf(QLatin1Char('.')); - if (dot < 0) dot = imp.version.length(); - if (!QmlEnginePrivate::get(engine)->addToImport(&unit->imports, imp.uri, imp.qualifier, imp.version.left(dot).toInt(), imp.version.mid(dot+1).toInt(), imp.type)) { - QmlError error; - error.setUrl(url); - error.setDescription(tr("Import %1 unavailable").arg(imp.uri)); - unit->errors << error; - ok = false; - } - } } if (ok) { @@ -400,25 +388,11 @@ void QmlCompositeTypeManager::doComplete(QmlCompositeTypeResource *resource) void QmlCompositeTypeManager::checkComplete(QmlCompositeTypeData *unit) { - if (unit->status != QmlCompositeTypeData::Waiting) + if (unit->status != QmlCompositeTypeData::Waiting + && unit->status != QmlCompositeTypeData::WaitingResources) return; int waiting = 0; - for (int ii = 0; ii < unit->types.count(); ++ii) { - QmlCompositeTypeData *u = unit->types.at(ii).unit; - - if (!u) - continue; - - if (u->status == QmlCompositeTypeData::Error) { - unit->status = QmlCompositeTypeData::Error; - unit->errors = u->errors; - doComplete(unit); - return; - } else if (u->status == QmlCompositeTypeData::Waiting) { - waiting++; - } - } for (int ii = 0; ii < unit->resources.count(); ++ii) { QmlCompositeTypeResource *r = unit->resources.at(ii); @@ -429,28 +403,84 @@ void QmlCompositeTypeManager::checkComplete(QmlCompositeTypeData *unit) unit->status = QmlCompositeTypeData::Error; QmlError error; error.setUrl(unit->imports.baseUrl()); - error.setDescription(QLatin1String("Resource ") + r->url + - QLatin1String(" unavailable")); + error.setDescription(tr("Resource %1 unavailable").arg(r->url)); unit->errors << error; doComplete(unit); return; - } else if (r->status == QmlCompositeTypeData::Waiting) { + } else if (r->status == QmlCompositeTypeResource::Waiting) { waiting++; } } + if (waiting == 0) { + if (unit->status == QmlCompositeTypeData::WaitingResources) { + waiting += resolveTypes(unit); + if (unit->status != QmlCompositeTypeData::Error) { + if (waiting) + unit->status = QmlCompositeTypeData::Waiting; + } else { + return; + } + } else { + for (int ii = 0; ii < unit->types.count(); ++ii) { + QmlCompositeTypeData *u = unit->types.at(ii).unit; + + if (!u) + continue; + + if (u->status == QmlCompositeTypeData::Error) { + unit->status = QmlCompositeTypeData::Error; + unit->errors = u->errors; + doComplete(unit); + return; + } else if (u->status == QmlCompositeTypeData::Waiting) { + waiting++; + } + } + } + } + if (!waiting) { unit->status = QmlCompositeTypeData::Complete; doComplete(unit); } } -// ### Check ref counting in here -void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit) +int QmlCompositeTypeManager::resolveTypes(QmlCompositeTypeData *unit) { - QList types = unit->data.referencedTypes(); + // not called until all resources are loaded (they include import URLs) int waiting = 0; + + foreach (QmlScriptParser::Import imp, unit->data.imports()) { + int dot = imp.version.indexOf(QLatin1Char('.')); + if (dot < 0) dot = imp.version.length(); + QString qmldir; + if (imp.type == QmlScriptParser::Import::File) { + QUrl importUrl = unit->imports.baseUrl().resolved(QUrl(imp.uri + QLatin1String("/qmldir"))); + for (int ii = 0; ii < unit->resources.count(); ++ii) { + if (unit->resources.at(ii)->url == importUrl) { + qmldir = QString::fromUtf8(unit->resources.at(ii)->data); + break; + } + } + } + if (!QmlEnginePrivate::get(engine)->addToImport( + &unit->imports, qmldir, imp.uri, imp.qualifier, imp.version.left(dot).toInt(), imp.version.mid(dot+1).toInt(), imp.type)) + { + QmlError error; + error.setUrl(unit->imports.baseUrl()); + error.setDescription(tr("Import %1 unavailable").arg(imp.uri)); + unit->status = QmlCompositeTypeData::Error; + unit->errorType = QmlCompositeTypeData::GeneralError; + unit->errors << error; + doComplete(unit); + return 0; + } + } + + QList types = unit->data.referencedTypes(); + for (int ii = 0; ii < types.count(); ++ii) { QmlScriptParser::TypeReference *parserRef = types.at(ii); QByteArray typeName = parserRef->name.toUtf8(); @@ -478,7 +508,7 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit) unit->errorType = QmlCompositeTypeData::GeneralError; unit->errors << error; doComplete(unit); - return; + return 0; } if (ref.type) { @@ -521,12 +551,13 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit) if (urlUnit->errorType != QmlCompositeTypeData::AccessError) unit->errors << urlUnit->errors; doComplete(unit); - return; + return 0; case QmlCompositeTypeData::Complete: break; case QmlCompositeTypeData::Waiting: + case QmlCompositeTypeData::WaitingResources: unit->addref(); ref.unit->dependants << unit; waiting++; @@ -535,6 +566,13 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit) unit->types << ref; } + return waiting; +} + +// ### Check ref counting in here +void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit) +{ + int waiting = 0; QList resourceList = unit->data.referencedResources(); for (int ii = 0; ii < resourceList.count(); ++ii) { @@ -551,6 +589,9 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit) loadResource(resource); } + if (!url.toLocalFile().isEmpty() && url.path().endsWith("/qmldir") && resource->status==QmlCompositeTypeResource::Error) + continue; // ignore - can use filesystem dir instead + switch(resource->status) { case QmlCompositeTypeResource::Invalid: case QmlCompositeTypeResource::Error: @@ -558,8 +599,7 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit) { QmlError error; error.setUrl(unit->imports.baseUrl()); - error.setDescription(QLatin1String("Resource ") + resource->url + - QLatin1String(" unavailable")); + error.setDescription(tr("Resource %1 unavailable").arg(resource->url)); unit->errors << error; } doComplete(unit); @@ -579,11 +619,18 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit) unit->resources << resource; } - if (waiting) { - unit->status = QmlCompositeTypeData::Waiting; + if (waiting == 0) { + waiting += resolveTypes(unit); + if (unit->status != QmlCompositeTypeData::Error) { + if (!waiting) { + unit->status = QmlCompositeTypeData::Complete; + doComplete(unit); + } else { + unit->status = QmlCompositeTypeData::Waiting; + } + } } else { - unit->status = QmlCompositeTypeData::Complete; - doComplete(unit); + unit->status = QmlCompositeTypeData::WaitingResources; } } diff --git a/src/declarative/qml/qmlcompositetypemanager_p.h b/src/declarative/qml/qmlcompositetypemanager_p.h index 843a9cf..b6f84db 100644 --- a/src/declarative/qml/qmlcompositetypemanager_p.h +++ b/src/declarative/qml/qmlcompositetypemanager_p.h @@ -101,6 +101,7 @@ private: void doComplete(QmlCompositeTypeData *); void doComplete(QmlCompositeTypeResource *); void checkComplete(QmlCompositeTypeData *); + int resolveTypes(QmlCompositeTypeData *); QmlEngine *engine; typedef QHash Components; diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 354114a..a3fb363 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -1027,6 +1027,7 @@ struct QmlEnginePrivate::ImportedNamespace { QList minversions; QList isLibrary; QList isBuiltin; + QList qmlDirContent; bool find(const QByteArray& type, int *vmajor, int *vminor, QmlType** type_return, QUrl* url_return) const { @@ -1048,36 +1049,39 @@ struct QmlEnginePrivate::ImportedNamespace { } } else { QUrl url = QUrl(urls.at(i) + QLatin1String("/") + QString::fromUtf8(type) + QLatin1String(".qml")); - if (vmaj || vmin) { + QString qmldircontent = qmlDirContent.at(i); + if (vmaj || vmin || !qmldircontent.isEmpty()) { // Check version file - XXX cache these in QmlEngine! - QFile qmldir(toLocalFileOrQrc(QUrl(urls.at(i)+QLatin1String("/qmldir")))); - if (qmldir.open(QIODevice::ReadOnly)) { - do { - QByteArray lineba = qmldir.readLine(); - if (lineba.at(0) == '#') - continue; - int space1 = lineba.indexOf(' '); - if (qstrncmp(lineba,type,space1)==0) { - // eg. 1.2-5 - QString line = QString::fromUtf8(lineba); - space1 = line.indexOf(QLatin1Char(' ')); // refind in Unicode - int space2 = space1 >=0 ? line.indexOf(QLatin1Char(' '),space1+1) : -1; - QString mapversions = line.mid(space1+1,space2<0?line.length()-space1-2:space2-space1-1); - int dot = mapversions.indexOf(QLatin1Char('.')); - int dash = mapversions.indexOf(QLatin1Char('-')); - int mapvmaj = mapversions.left(dot).toInt(); - if (mapvmaj==vmaj) { - int mapvmin_from = (dash <= 0 ? mapversions.mid(dot+1) : mapversions.mid(dot+1,dash-dot-1)).toInt(); - int mapvmin_to = dash <= 0 ? mapvmin_from : mapversions.mid(dash+1).toInt(); - if (vmin >= mapvmin_from && vmin <= mapvmin_to) { - QStringRef mapfile = space2<0 ? QStringRef() : line.midRef(space2+1,line.length()-space2-2); - if (url_return) - *url_return = url.resolved(mapfile.toString()); - return true; - } + if (qmldircontent.isEmpty()) { + QFile qmldir(toLocalFileOrQrc(QUrl(urls.at(i)+QLatin1String("/qmldir")))); + if (qmldir.open(QIODevice::ReadOnly)) { + qmldircontent = QString::fromUtf8(qmldir.readAll()); + } + } + QString typespace = QString::fromUtf8(type)+QLatin1Char(' '); + QStringList lines = qmldircontent.split(QLatin1Char('\n')); + foreach (QString line, lines) { + if (line.isEmpty() || line.at(0) == QLatin1Char('#')) + continue; + if (line.startsWith(typespace)) { + // eg. 1.2-5 + int space1 = line.indexOf(QLatin1Char(' ')); + int space2 = space1 >=0 ? line.indexOf(QLatin1Char(' '),space1+1) : -1; + QString mapversions = line.mid(space1+1,space2<0?line.length()-space1-1:space2-space1-1); + int dot = mapversions.indexOf(QLatin1Char('.')); + int dash = mapversions.indexOf(QLatin1Char('-')); + int mapvmaj = mapversions.left(dot).toInt(); + if (mapvmaj==vmaj) { + int mapvmin_from = (dash <= 0 ? mapversions.mid(dot+1) : mapversions.mid(dot+1,dash-dot-1)).toInt(); + int mapvmin_to = dash <= 0 ? mapvmin_from : mapversions.mid(dash+1).toInt(); + if (vmin >= mapvmin_from && vmin <= mapvmin_to) { + QStringRef mapfile = space2<0 ? QStringRef() : line.midRef(space2+1,line.length()-space2-1); + if (url_return) + *url_return = url.resolved(mapfile.toString()); + return true; } } - } while (!qmldir.atEnd()); + } } } else { // XXX search non-files too! (eg. zip files, see QT-524) @@ -1106,7 +1110,7 @@ public: delete s; } - bool add(const QUrl& base, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType, const QStringList& importPath) + bool add(const QUrl& base, const QString& qmldircontent, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType, const QStringList& importPath) { QmlEnginePrivate::ImportedNamespace *s; if (prefix.isEmpty()) { @@ -1142,6 +1146,7 @@ public: s->minversions.prepend(vmin); s->isLibrary.prepend(importType == QmlScriptParser::Import::Library); s->isBuiltin.prepend(isbuiltin); + s->qmlDirContent.prepend(qmldircontent); return true; } @@ -1366,9 +1371,9 @@ QString QmlEngine::offlineStoragePath() const The base URL must already have been set with Import::setBaseUrl(). */ -bool QmlEnginePrivate::addToImport(Imports* imports, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType) const +bool QmlEnginePrivate::addToImport(Imports* imports, const QString& qmldircontent, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType) const { - bool ok = imports->d->add(imports->d->base,uri,prefix,vmaj,vmin,importType,fileImportPath); + bool ok = imports->d->add(imports->d->base,qmldircontent,uri,prefix,vmaj,vmin,importType,fileImportPath); if (qmlImportTrace()) qDebug() << "QmlEngine::addToImport(" << imports << uri << prefix << vmaj << "." << vmin << (importType==QmlScriptParser::Import::Library? "Library" : "File") << ": " << ok; return ok; diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index a74854d..bd1cab2 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -223,7 +223,7 @@ public: QmlImportsPrivate *d; }; - bool addToImport(Imports*, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType) const; + bool addToImport(Imports*, const QString& qmlDirContent,const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType) const; bool resolveType(const Imports&, const QByteArray& type, QmlType** type_return, QUrl* url_return, int *version_major, int *version_minor, diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp index fb84651..b61ffaa 100644 --- a/src/declarative/qml/qmlscriptparser.cpp +++ b/src/declarative/qml/qmlscriptparser.cpp @@ -424,6 +424,9 @@ bool ProcessAST::visit(AST::UiImport *node) if (node->fileName) { import.type = QmlScriptParser::Import::File; uri = node->fileName->asString(); + QUrl ref(uri); + ref.setPath(ref.path()+QLatin1String("/qmldir")); + _parser->_refUrls << ref; } else { import.type = QmlScriptParser::Import::Library; uri = asString(node->importUri); -- cgit v0.12 From d51e31dbbef822f8d48e4d2c4a7c7c03766c5cc7 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Mon, 26 Oct 2009 14:39:34 +1000 Subject: use enums rather than strings in examples --- examples/declarative/animation/color-animation.qml | 6 +++--- examples/declarative/animation/property-animation.qml | 2 +- examples/declarative/progressbar/ProgressBar.qml | 2 +- examples/declarative/snow/ImageBatch.qml | 2 +- examples/declarative/snow/Loading.qml | 2 +- examples/declarative/tutorials/helloworld/tutorial3.qml | 2 +- src/declarative/fx/qfxitem.cpp | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/declarative/animation/color-animation.qml b/examples/declarative/animation/color-animation.qml index 0cf8a44..edb0659 100644 --- a/examples/declarative/animation/color-animation.qml +++ b/examples/declarative/animation/color-animation.qml @@ -30,18 +30,18 @@ Item { // the sun, moon, and stars Item { width: parent.width; height: 2 * parent.height - transformOrigin: "Center" + transformOrigin: Item.Center rotation: SequentialAnimation { running: true; repeat: true NumberAnimation { from: 0; to: 360; duration: 10000 } } Image { source: "images/sun.png"; y: 10; anchors.horizontalCenter: parent.horizontalCenter - transformOrigin: "Center"; rotation: -3 * parent.rotation + transformOrigin: Item.Center; rotation: -3 * parent.rotation } Image { source: "images/moon.png"; y: parent.height - 74; anchors.horizontalCenter: parent.horizontalCenter - transformOrigin: "Center"; rotation: -parent.rotation + transformOrigin: Item.Center; rotation: -parent.rotation } Particles { x: 0; y: parent.height/2; width: parent.width; height: parent.height/2 diff --git a/examples/declarative/animation/property-animation.qml b/examples/declarative/animation/property-animation.qml index 4e0f6f4..0256137 100644 --- a/examples/declarative/animation/property-animation.qml +++ b/examples/declarative/animation/property-animation.qml @@ -26,7 +26,7 @@ Item { Image { anchors.horizontalCenter: parent.horizontalCenter source: "images/shadow.png"; y: smiley.minHeight + 58 - transformOrigin: "Center" + transformOrigin: Item.Center // The scale property depends on the y position of the smiley face. scale: smiley.y * 0.5 / (smiley.minHeight - smiley.maxHeight) diff --git a/examples/declarative/progressbar/ProgressBar.qml b/examples/declarative/progressbar/ProgressBar.qml index 48346ac..302caa9 100644 --- a/examples/declarative/progressbar/ProgressBar.qml +++ b/examples/declarative/progressbar/ProgressBar.qml @@ -21,7 +21,7 @@ Item { id: highlight; radius: 2 anchors.left: parent.left; anchors.top: parent.top; anchors.bottom: parent.bottom anchors.leftMargin: 3; anchors.topMargin: 3; anchors.bottomMargin: 3 - width: EaseFollow { source: highlight.widthDest; duration: 100 } + width: EaseFollow { source: highlight.widthDest; duration: 1000 } gradient: Gradient { GradientStop { id: g1; position: 0.0 } GradientStop { id: g2; position: 1.0 } diff --git a/examples/declarative/snow/ImageBatch.qml b/examples/declarative/snow/ImageBatch.qml index 3945087..dfe2a46 100644 --- a/examples/declarative/snow/ImageBatch.qml +++ b/examples/declarative/snow/ImageBatch.qml @@ -38,7 +38,7 @@ GridView { delegate: Item { id: root property bool isSelected: GridView.isCurrentItem && grid.isSelected - transformOrigin: "Center" + transformOrigin: Item.Center width: grid.imageWidth; height: grid.imageHeight; Image { id: flickrImage; source: url; fillMode: "PreserveAspectFit"; smooth: true; anchors.fill: parent; diff --git a/examples/declarative/snow/Loading.qml b/examples/declarative/snow/Loading.qml index 054656a..238d9c7 100644 --- a/examples/declarative/snow/Loading.qml +++ b/examples/declarative/snow/Loading.qml @@ -1,7 +1,7 @@ import Qt 4.6 Image { - id: loading; source: "pics/loading.png"; transformOrigin: "Center" + id: loading; source: "pics/loading.png"; transformOrigin: Item.Center rotation: NumberAnimation { id: rotationAnimation; from: 0; to: 360; running: loading.visible == true; repeat: true; duration: 900 } diff --git a/examples/declarative/tutorials/helloworld/tutorial3.qml b/examples/declarative/tutorials/helloworld/tutorial3.qml index d641eba..534d663 100644 --- a/examples/declarative/tutorials/helloworld/tutorial3.qml +++ b/examples/declarative/tutorials/helloworld/tutorial3.qml @@ -11,7 +11,7 @@ Rectangle { text: "Hello world!" font.pointSize: 24; font.bold: true y: 30; anchors.horizontalCenter: page.horizontalCenter - transformOrigin: "Center" + transformOrigin: Item.Center //![1] MouseRegion { id: mouseRegion; anchors.fill: parent } diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index 51575cc..9c668ac 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -1377,7 +1377,7 @@ QFxItem::~QFxItem() \qml Image { source: "myimage.png" - transformOrigin: "Center" + transformOrigin: Item.Center scale: 4 } \endqml -- cgit v0.12 From 5b44f14b564bb6a4ba94d49593a0557995acc79b Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 26 Oct 2009 14:42:45 +1000 Subject: Move knowledge of qmldir out of QmlScriptParser. --- src/declarative/qml/qmlcompositetypemanager.cpp | 14 +++++++++++--- src/declarative/qml/qmlscriptparser.cpp | 3 --- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/declarative/qml/qmlcompositetypemanager.cpp b/src/declarative/qml/qmlcompositetypemanager.cpp index 9444a22..b956c1e 100644 --- a/src/declarative/qml/qmlcompositetypemanager.cpp +++ b/src/declarative/qml/qmlcompositetypemanager.cpp @@ -575,6 +575,17 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit) int waiting = 0; QList resourceList = unit->data.referencedResources(); + + foreach (QmlScriptParser::Import imp, unit->data.imports()) { + if (imp.type == QmlScriptParser::Import::File) { + QUrl importUrl = unit->imports.baseUrl().resolved(QUrl(imp.uri + QLatin1String("/qmldir"))); + if (toLocalFileOrQrc(importUrl).isEmpty()) { + // Import requires remote qmldir + resourceList.prepend(importUrl); + } + } + } + for (int ii = 0; ii < resourceList.count(); ++ii) { QUrl url = unit->imports.baseUrl().resolved(resourceList.at(ii)); @@ -589,9 +600,6 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit) loadResource(resource); } - if (!url.toLocalFile().isEmpty() && url.path().endsWith("/qmldir") && resource->status==QmlCompositeTypeResource::Error) - continue; // ignore - can use filesystem dir instead - switch(resource->status) { case QmlCompositeTypeResource::Invalid: case QmlCompositeTypeResource::Error: diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp index b61ffaa..fb84651 100644 --- a/src/declarative/qml/qmlscriptparser.cpp +++ b/src/declarative/qml/qmlscriptparser.cpp @@ -424,9 +424,6 @@ bool ProcessAST::visit(AST::UiImport *node) if (node->fileName) { import.type = QmlScriptParser::Import::File; uri = node->fileName->asString(); - QUrl ref(uri); - ref.setPath(ref.path()+QLatin1String("/qmldir")); - _parser->_refUrls << ref; } else { import.type = QmlScriptParser::Import::Library; uri = asString(node->importUri); -- cgit v0.12 From 570fa7aece0ce149c22f7b804093f70c7cb1c999 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 26 Oct 2009 14:46:32 +1000 Subject: Allow flickr demo to be remote. --- demos/declarative/flickr/common/qmldir | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 demos/declarative/flickr/common/qmldir diff --git a/demos/declarative/flickr/common/qmldir b/demos/declarative/flickr/common/qmldir new file mode 100644 index 0000000..0c94f60 --- /dev/null +++ b/demos/declarative/flickr/common/qmldir @@ -0,0 +1,10 @@ +ImageDetails 0.0 ImageDetails.qml +LikeOMeter 0.0 LikeOMeter.qml +Loading 0.0 Loading.qml +MediaButton 0.0 MediaButton.qml +MediaLineEdit 0.0 MediaLineEdit.qml +Progress 0.0 Progress.qml +RssModel 0.0 RssModel.qml +ScrollBar 0.0 ScrollBar.qml +Slider 0.0 Slider.qml +Star 0.0 Star.qml -- cgit v0.12 From f7accb884e45ddf241991ef29ee8d34731e0211a Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 26 Oct 2009 14:50:29 +1000 Subject: Add support for value interceptors to the DOM. --- src/declarative/qml/qmldom.cpp | 96 ++++++++++++++++++++++++++++ src/declarative/qml/qmldom.h | 20 ++++++ tests/auto/declarative/qmldom/tst_qmldom.cpp | 30 ++++++++- 3 files changed, 143 insertions(+), 3 deletions(-) diff --git a/src/declarative/qml/qmldom.cpp b/src/declarative/qml/qmldom.cpp index a0601d7..21eeb7c 100644 --- a/src/declarative/qml/qmldom.cpp +++ b/src/declarative/qml/qmldom.cpp @@ -1181,6 +1181,75 @@ QmlDomObject QmlDomValueValueSource::object() const return rv; } +/*! + \class QmlDomValueValueInterceptor + \internal + \brief The QmlDomValueValueInterceptor class represents a value interceptor assignment value. + + In QML, value interceptor are special write-intercepting types that may be + assigned to properties. Value interceptor inherit the QmlPropertyValueInterceptor + class. In the example below, the "x" property is being assigned the + Behavior value interceptor. + + \qml +Rectangle { + x: Behavior { NumberAnimation { duration: 500 } } +} + \endqml +*/ + +/*! + Construct an empty QmlDomValueValueInterceptor. +*/ +QmlDomValueValueInterceptor::QmlDomValueValueInterceptor(): + d(new QmlDomBasicValuePrivate) +{ +} + +/*! + Create a copy of \a other QmlDomValueValueInterceptor. +*/ +QmlDomValueValueInterceptor::QmlDomValueValueInterceptor(const QmlDomValueValueInterceptor &other) +: d(other.d) +{ +} + +/*! + Destroy the QmlDomValueValueInterceptor. +*/ +QmlDomValueValueInterceptor::~QmlDomValueValueInterceptor() +{ +} + +/*! + Assign \a other to this QmlDomValueValueInterceptor. +*/ +QmlDomValueValueInterceptor &QmlDomValueValueInterceptor::operator=(const QmlDomValueValueInterceptor &other) +{ + d = other.d; + return *this; +} + +/*! + Return the value interceptor object. + + In the example below, an object representing the Behavior will be + returned. + \qml +Rectangle { + x: Behavior { NumberAnimation { duration: 500 } } +} + \endqml +*/ +QmlDomObject QmlDomValueValueInterceptor::object() const +{ + QmlDomObject rv; + if (d->value) { + rv.d->object = d->value->object; + rv.d->object->addref(); + } + return rv; +} QmlDomValuePrivate::QmlDomValuePrivate() : property(0), value(0) @@ -1286,6 +1355,7 @@ QmlDomValue &QmlDomValue::operator=(const QmlDomValue &other) \value Literal The QmlDomValue is a literal value assignment. Use QmlDomValue::toLiteral() to access the type instance. \value PropertyBinding The QmlDomValue is a property binding. Use QmlDomValue::toBinding() to access the type instance. \value ValueSource The QmlDomValue is a property value source. Use QmlDomValue::toValueSource() to access the type instance. + \value ValueInterceptor The QmlDomValue is a property value interceptor. Use QmlDomValue::toValueInterceptor() to access the type instance. \value Object The QmlDomValue is an object assignment. Use QmlDomValue::toObject() to access the type instnace. \value List The QmlDomValue is a list of other values. Use QmlDomValue::toList() to access the type instance. */ @@ -1314,6 +1384,8 @@ QmlDomValue::Type QmlDomValue::type() const return PropertyBinding; case QmlParser::Value::ValueSource: return ValueSource; + case QmlParser::Value::ValueInterceptor: + return ValueInterceptor; case QmlParser::Value::CreatedObject: return Object; case QmlParser::Value::SignalObject: @@ -1359,6 +1431,14 @@ bool QmlDomValue::isValueSource() const } /*! + Returns true if this is a value interceptor value, otherwise false. +*/ +bool QmlDomValue::isValueInterceptor() const +{ + return type() == ValueInterceptor; +} + +/*! Returns true if this is an object value, otherwise false. */ bool QmlDomValue::isObject() const @@ -1423,6 +1503,22 @@ QmlDomValueValueSource QmlDomValue::toValueSource() const } /*! + Returns a QmlDomValueValueInterceptor if this value is a property value interceptor + type, otherwise returns an invalid QmlDomValueValueInterceptor. + + \sa QmlDomValue::type() +*/ +QmlDomValueValueInterceptor QmlDomValue::toValueInterceptor() const +{ + QmlDomValueValueInterceptor rv; + if (type() == ValueInterceptor) { + rv.d->value = d->value; + rv.d->value->addref(); + } + return rv; +} + +/*! Returns a QmlDomObject if this value is an object assignment type, otherwise returns an invalid QmlDomObject. diff --git a/src/declarative/qml/qmldom.h b/src/declarative/qml/qmldom.h index f344bb2..5816780 100644 --- a/src/declarative/qml/qmldom.h +++ b/src/declarative/qml/qmldom.h @@ -175,6 +175,7 @@ private: friend class QmlDomComponent; friend class QmlDomValue; friend class QmlDomValueValueSource; + friend class QmlDomValueValueInterceptor; QSharedDataPointer d; }; @@ -225,6 +226,22 @@ private: QSharedDataPointer d; }; +class Q_DECLARATIVE_EXPORT QmlDomValueValueInterceptor +{ +public: + QmlDomValueValueInterceptor(); + QmlDomValueValueInterceptor(const QmlDomValueValueInterceptor &); + ~QmlDomValueValueInterceptor(); + QmlDomValueValueInterceptor &operator=(const QmlDomValueValueInterceptor &); + + QmlDomObject object() const; + +private: + friend class QmlDomValue; + QSharedDataPointer d; +}; + + class Q_DECLARATIVE_EXPORT QmlDomComponent : public QmlDomObject { public: @@ -244,6 +261,7 @@ public: Literal, PropertyBinding, ValueSource, + ValueInterceptor, Object, List }; @@ -259,12 +277,14 @@ public: bool isLiteral() const; bool isBinding() const; bool isValueSource() const; + bool isValueInterceptor() const; bool isObject() const; bool isList() const; QmlDomValueLiteral toLiteral() const; QmlDomValueBinding toBinding() const; QmlDomValueValueSource toValueSource() const; + QmlDomValueValueInterceptor toValueInterceptor() const; QmlDomObject toObject() const; QmlDomList toList() const; diff --git a/tests/auto/declarative/qmldom/tst_qmldom.cpp b/tests/auto/declarative/qmldom/tst_qmldom.cpp index 77c13c3..8079a23 100644 --- a/tests/auto/declarative/qmldom/tst_qmldom.cpp +++ b/tests/auto/declarative/qmldom/tst_qmldom.cpp @@ -20,6 +20,7 @@ private slots: void loadImports(); void testValueSource(); + void testValueInterceptor(); private: QmlEngine engine; @@ -30,7 +31,6 @@ void tst_qmldom::loadSimple() { QByteArray qml = "import Qt 4.6\n" "Item {}"; - //QByteArray qml = ""; QmlDomDocument document; QVERIFY(document.load(&engine, qml)); @@ -49,7 +49,6 @@ void tst_qmldom::loadProperties() { QByteArray qml = "import Qt 4.6\n" "Item { id : item; x : 300; visible : true }"; - //QByteArray qml = ""; QmlDomDocument document; QVERIFY(document.load(&engine, qml)); @@ -74,7 +73,6 @@ void tst_qmldom::loadChildObject() { QByteArray qml = "import Qt 4.6\n" "Item { Item {} }"; - //QByteArray qml = " "; QmlDomDocument document; QVERIFY(document.load(&engine, qml)); @@ -148,6 +146,32 @@ void tst_qmldom::testValueSource() QVERIFY(sourceValue.toBinding().binding() == "Math.min(Math.max(-130, value*2.2 - 130), 133)"); } +void tst_qmldom::testValueInterceptor() +{ + QByteArray qml = "import Qt 4.6\n" + "Rectangle { height: Behavior { NumberAnimation { duration: 100 } } }"; + + QmlEngine freshEngine; + QmlDomDocument document; + QVERIFY(document.load(&freshEngine, qml)); + + QmlDomObject rootItem = document.rootObject(); + QVERIFY(rootItem.isValid()); + QmlDomProperty heightProperty = rootItem.properties().at(0); + QVERIFY(heightProperty.propertyName() == "height"); + QVERIFY(heightProperty.value().isValueInterceptor()); + + const QmlDomValueValueInterceptor valueInterceptor = heightProperty.value().toValueInterceptor(); + QmlDomObject valueInterceptorObject = valueInterceptor.object(); + QVERIFY(valueInterceptorObject.isValid()); + + QVERIFY(valueInterceptorObject.objectType() == "Qt/Behavior"); + + const QmlDomValue animationValue = valueInterceptorObject.property("animation").value(); + QVERIFY(!animationValue.isInvalid()); + QVERIFY(animationValue.isObject()); +} + void tst_qmldom::loadImports() { QByteArray qml = "import Qt 4.6\n" -- cgit v0.12 From 5c8ff2a392478a74edf1aa1bc12236fea83bf89f Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 26 Oct 2009 14:51:08 +1000 Subject: Silence warnings. --- src/declarative/qml/qbitfield_p.h | 4 ++-- src/declarative/qml/qmlcomponent.cpp | 2 -- src/declarative/qml/qmlcomponent_p.h | 2 +- src/declarative/qml/qmlcompositetypemanager.cpp | 2 +- src/declarative/qml/qmlxmlhttprequest.cpp | 9 +++++++++ 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/declarative/qml/qbitfield_p.h b/src/declarative/qml/qbitfield_p.h index 70d5041..a8cc9dc 100644 --- a/src/declarative/qml/qbitfield_p.h +++ b/src/declarative/qml/qbitfield_p.h @@ -139,11 +139,11 @@ QBitField QBitField::united(const QBitField &o) rv.data = rv.ownData + 1; if (bits > o.bits) { ::memcpy((quint32 *)rv.data, data, length * sizeof(quint32)); - for (quint32 ii = 0; ii < (o.bits + 31) / 32; ++ii) + for (quint32 ii = 0; ii < (o.bits + quint32(31)) / 32; ++ii) ((quint32 *)rv.data)[ii] |= o.data[ii]; } else { ::memcpy((quint32 *)rv.data, o.data, length * sizeof(quint32)); - for (quint32 ii = 0; ii < (bits + 31) / 32; ++ii) + for (quint32 ii = 0; ii < (bits + quint32(31)) / 32; ++ii) ((quint32 *)rv.data)[ii] |= data[ii]; } return rv; diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp index 12fb120..0894758 100644 --- a/src/declarative/qml/qmlcomponent.cpp +++ b/src/declarative/qml/qmlcomponent.cpp @@ -390,8 +390,6 @@ valid for components created directly from QML. */ QmlContext *QmlComponent::creationContext() const { - Q_D(const QmlComponent); - QmlDeclarativeData *ddata = QmlDeclarativeData::get(this); if (ddata) return ddata->context; diff --git a/src/declarative/qml/qmlcomponent_p.h b/src/declarative/qml/qmlcomponent_p.h index 7eedfbd..f90502f 100644 --- a/src/declarative/qml/qmlcomponent_p.h +++ b/src/declarative/qml/qmlcomponent_p.h @@ -76,7 +76,7 @@ class QmlComponentPrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QmlComponent) public: - QmlComponentPrivate() : typeData(0), progress(0.), start(-1), count(-1), cc(0), completePending(false), componentAttacheds(0), engine(0) {} + QmlComponentPrivate() : typeData(0), progress(0.), start(-1), count(-1), cc(0), componentAttacheds(0), completePending(false), engine(0) {} QObject *create(QmlContext *context, const QBitField &); diff --git a/src/declarative/qml/qmlcompositetypemanager.cpp b/src/declarative/qml/qmlcompositetypemanager.cpp index 3c76344..7c22a5f 100644 --- a/src/declarative/qml/qmlcompositetypemanager.cpp +++ b/src/declarative/qml/qmlcompositetypemanager.cpp @@ -434,7 +434,7 @@ void QmlCompositeTypeManager::checkComplete(QmlCompositeTypeData *unit) unit->errors << error; doComplete(unit); return; - } else if (r->status == QmlCompositeTypeData::Waiting) { + } else if (r->status == QmlCompositeTypeResource::Waiting) { waiting++; } } diff --git a/src/declarative/qml/qmlxmlhttprequest.cpp b/src/declarative/qml/qmlxmlhttprequest.cpp index 5117a00..eb7235b 100644 --- a/src/declarative/qml/qmlxmlhttprequest.cpp +++ b/src/declarative/qml/qmlxmlhttprequest.cpp @@ -1102,6 +1102,7 @@ void QmlXMLHttpRequest::abort() void QmlXMLHttpRequest::downloadProgress(qint64 bytes) { + Q_UNUSED(bytes) m_status = m_network->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); m_statusText = @@ -1124,6 +1125,7 @@ void QmlXMLHttpRequest::downloadProgress(qint64 bytes) void QmlXMLHttpRequest::error(QNetworkReply::NetworkError error) { + Q_UNUSED(error) m_status = m_network->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); m_statusText = @@ -1315,6 +1317,7 @@ static QScriptValue qmlxmlhttprequest_abort(QScriptContext *context, QScriptEngi static QScriptValue qmlxmlhttprequest_getResponseHeader(QScriptContext *context, QScriptEngine *engine) { + Q_UNUSED(engine) QmlXMLHttpRequest *request = qobject_cast(context->thisObject().data().toQObject()); if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); @@ -1333,6 +1336,7 @@ static QScriptValue qmlxmlhttprequest_getResponseHeader(QScriptContext *context, static QScriptValue qmlxmlhttprequest_getAllResponseHeaders(QScriptContext *context, QScriptEngine *engine) { + Q_UNUSED(engine) QmlXMLHttpRequest *request = qobject_cast(context->thisObject().data().toQObject()); if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); @@ -1350,6 +1354,7 @@ static QScriptValue qmlxmlhttprequest_getAllResponseHeaders(QScriptContext *cont // XMLHttpRequest properties static QScriptValue qmlxmlhttprequest_readyState(QScriptContext *context, QScriptEngine *engine) { + Q_UNUSED(engine) QmlXMLHttpRequest *request = qobject_cast(context->thisObject().data().toQObject()); if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); @@ -1358,6 +1363,7 @@ static QScriptValue qmlxmlhttprequest_readyState(QScriptContext *context, QScrip static QScriptValue qmlxmlhttprequest_status(QScriptContext *context, QScriptEngine *engine) { + Q_UNUSED(engine) QmlXMLHttpRequest *request = qobject_cast(context->thisObject().data().toQObject()); if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); @@ -1373,6 +1379,7 @@ static QScriptValue qmlxmlhttprequest_status(QScriptContext *context, QScriptEng static QScriptValue qmlxmlhttprequest_statusText(QScriptContext *context, QScriptEngine *engine) { + Q_UNUSED(engine) QmlXMLHttpRequest *request = qobject_cast(context->thisObject().data().toQObject()); if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); @@ -1388,6 +1395,7 @@ static QScriptValue qmlxmlhttprequest_statusText(QScriptContext *context, QScrip static QScriptValue qmlxmlhttprequest_responseText(QScriptContext *context, QScriptEngine *engine) { + Q_UNUSED(engine) QmlXMLHttpRequest *request = qobject_cast(context->thisObject().data().toQObject()); if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); @@ -1412,6 +1420,7 @@ static QScriptValue qmlxmlhttprequest_responseXML(QScriptContext *context, QScri static QScriptValue qmlxmlhttprequest_onreadystatechange(QScriptContext *context, QScriptEngine *engine) { + Q_UNUSED(engine) QmlXMLHttpRequest *request = qobject_cast(context->thisObject().data().toQObject()); if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); -- cgit v0.12 From de3b541e40d9fdb01bc46f472c6032e2a9f45c95 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 26 Oct 2009 15:41:32 +1000 Subject: qmldir not needed if types are qualified. --- src/declarative/qml/qmlcompositetypemanager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/declarative/qml/qmlcompositetypemanager.cpp b/src/declarative/qml/qmlcompositetypemanager.cpp index b956c1e..b335d31 100644 --- a/src/declarative/qml/qmlcompositetypemanager.cpp +++ b/src/declarative/qml/qmlcompositetypemanager.cpp @@ -456,7 +456,7 @@ int QmlCompositeTypeManager::resolveTypes(QmlCompositeTypeData *unit) int dot = imp.version.indexOf(QLatin1Char('.')); if (dot < 0) dot = imp.version.length(); QString qmldir; - if (imp.type == QmlScriptParser::Import::File) { + if (imp.type == QmlScriptParser::Import::File && imp.qualifier.isEmpty()) { QUrl importUrl = unit->imports.baseUrl().resolved(QUrl(imp.uri + QLatin1String("/qmldir"))); for (int ii = 0; ii < unit->resources.count(); ++ii) { if (unit->resources.at(ii)->url == importUrl) { @@ -577,7 +577,7 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit) QList resourceList = unit->data.referencedResources(); foreach (QmlScriptParser::Import imp, unit->data.imports()) { - if (imp.type == QmlScriptParser::Import::File) { + if (imp.type == QmlScriptParser::Import::File && imp.qualifier.isEmpty()) { QUrl importUrl = unit->imports.baseUrl().resolved(QUrl(imp.uri + QLatin1String("/qmldir"))); if (toLocalFileOrQrc(importUrl).isEmpty()) { // Import requires remote qmldir -- cgit v0.12 From 91be655a7e893d34fdbdb71aa5a329b641c80992 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 26 Oct 2009 15:41:51 +1000 Subject: Fix "initial" size for remote content. --- src/declarative/util/qmlview.cpp | 12 +++++++++++- src/declarative/util/qmlview.h | 1 + tools/qmlviewer/qmlviewer.cpp | 8 +++++++- tools/qmlviewer/qmlviewer.h | 1 + 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/declarative/util/qmlview.cpp b/src/declarative/util/qmlview.cpp index 14f8279..f91d0db 100644 --- a/src/declarative/util/qmlview.cpp +++ b/src/declarative/util/qmlview.cpp @@ -360,6 +360,8 @@ void QmlView::continueExecute() emit sceneResized(sz); resize(sz); } + updateGeometry(); + emit initialSize(d->initialSize); } else if (QWidget *wid = qobject_cast(obj)) { window()->setAttribute(Qt::WA_OpaquePaintEvent, false); window()->setAttribute(Qt::WA_NoSystemBackground, false); @@ -374,6 +376,7 @@ void QmlView::continueExecute() } layout()->addWidget(wid); emit sceneResized(wid->size()); + emit initialSize(wid->size()); } } } @@ -382,6 +385,10 @@ void QmlView::continueExecute() This signal is emitted when the view is resized to \a size. */ +/*! \fn void QmlView::initialSize(QSize size) + This signal is emitted when the initial size of the root item is known. + */ + /*! \fn void QmlView::errors(const QList &errors) This signal is emitted when the qml loaded contains \a errors. */ @@ -425,7 +432,10 @@ void QmlView::timerEvent(QTimerEvent* e) automatically resize the root item. Regardless of this property, the sizeHint of the view - is the initial size of the root item. + is the initial size of the root item. Note though that + since QML may load dynamically, that size may change. + + \sa initialSize() */ void QmlView::setContentResizable(bool on) diff --git a/src/declarative/util/qmlview.h b/src/declarative/util/qmlview.h index faf2564..822827a 100644 --- a/src/declarative/util/qmlview.h +++ b/src/declarative/util/qmlview.h @@ -88,6 +88,7 @@ public: QSize sizeHint() const; Q_SIGNALS: + void initialSize(QSize size); void sceneResized(QSize size); void errors(const QList &error); diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index 73aae44..b115abb 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -310,6 +310,7 @@ QmlViewer::QmlViewer(QWidget *parent, Qt::WindowFlags flags) canvas->setFocus(); QObject::connect(canvas, SIGNAL(sceneResized(QSize)), this, SLOT(sceneResized(QSize))); + QObject::connect(canvas, SIGNAL(initialSize(QSize)), this, SLOT(adjustSizeSlot())); QObject::connect(canvas, SIGNAL(errors(QList)), this, SLOT(executeErrors())); if (!(flags & Qt::FramelessWindowHint)) @@ -335,6 +336,11 @@ QmlViewer::QmlViewer(QWidget *parent, Qt::WindowFlags flags) recordTimer.setRepeating(true); } +void QmlViewer::adjustSizeSlot() +{ + adjustSize(); +} + QMenuBar *QmlViewer::menuBar() const { if (!mb) @@ -680,7 +686,7 @@ void QmlViewer::openQml(const QUrl& url) canvas->updateGeometry(); if (mb) mb->updateGeometry(); - resize(sizeHint()); + adjustSize(); } else { if (scaleSkin) canvas->resize(canvas->sizeHint()); diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h index f0578eb..50495db 100644 --- a/tools/qmlviewer/qmlviewer.h +++ b/tools/qmlviewer/qmlviewer.h @@ -88,6 +88,7 @@ private slots: void chooseRecordingOptions(); void pickRecordingFile(); void setScaleSkin(); + void adjustSizeSlot(); private: void setupProxy(); -- cgit v0.12 From 7eddab2dc75c79b05d86e2e4b48ac9f4cf102406 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 26 Oct 2009 15:01:04 +1000 Subject: Don't need this check. --- src/declarative/util/qmlpropertychanges.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/declarative/util/qmlpropertychanges.cpp b/src/declarative/util/qmlpropertychanges.cpp index bed27fe..7e1f15c 100644 --- a/src/declarative/util/qmlpropertychanges.cpp +++ b/src/declarative/util/qmlpropertychanges.cpp @@ -85,8 +85,7 @@ class QmlReplaceSignalHandler : public ActionEvent public: QmlReplaceSignalHandler() : expression(0), reverseExpression(0), ownedExpression(0) {} ~QmlReplaceSignalHandler() { - if (ownedExpression) - delete ownedExpression; + delete ownedExpression; } virtual QString typeName() const { return QLatin1String("ReplaceSignalHandler"); } -- cgit v0.12 From ee0c9c7003dc020113886070b5c04dc0a7529bf4 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 26 Oct 2009 15:47:12 +1000 Subject: Fix more warnings. --- src/declarative/extra/qmlbehavior.h | 1 + src/declarative/qml/qmlcontext.cpp | 4 +--- src/declarative/qml/qmlcontext_p.h | 2 +- src/declarative/qml/qmlenginedebug.cpp | 4 ++-- src/declarative/qml/qmlglobalscriptclass.cpp | 9 +++++++++ src/declarative/qml/qmlobjectscriptclass.cpp | 1 - src/declarative/qml/qmlpropertycache.cpp | 2 +- src/declarative/qml/qmlrewrite.cpp | 12 ++++++------ src/declarative/qml/qmlvme.cpp | 2 +- src/declarative/qml/qmlvmemetaobject.cpp | 2 +- src/declarative/util/qmlanimation.h | 1 + src/declarative/util/qmllistaccessor.cpp | 2 +- 12 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/declarative/extra/qmlbehavior.h b/src/declarative/extra/qmlbehavior.h index 994d85c..6508455 100644 --- a/src/declarative/extra/qmlbehavior.h +++ b/src/declarative/extra/qmlbehavior.h @@ -60,6 +60,7 @@ class Q_DECLARATIVE_EXPORT QmlBehavior : public QObject, public QmlPropertyValue Q_OBJECT Q_DECLARE_PRIVATE(QmlBehavior) + Q_INTERFACES(QmlPropertyValueInterceptor) Q_CLASSINFO("DefaultProperty", "animation") Q_PROPERTY(QmlAbstractAnimation *animation READ animation WRITE setAnimation) diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp index 31d4e1f..7ba3544 100644 --- a/src/declarative/qml/qmlcontext.cpp +++ b/src/declarative/qml/qmlcontext.cpp @@ -396,8 +396,7 @@ void QmlContext::setContextProperty(const QString &name, const QVariant &value) } } -void QmlContextPrivate::setIdProperty(const QString &name, int idx, - QObject *obj) +void QmlContextPrivate::setIdProperty(int idx, QObject *obj) { if (notifyIndex == -1) { Q_Q(QmlContext); @@ -487,7 +486,6 @@ void QmlContext::setBaseUrl(const QUrl &baseUrl) */ QUrl QmlContext::baseUrl() const { - Q_D(const QmlContext); const QmlContext* p = this; while (p && p->d_func()->url.isEmpty()) { p = p->parentContext(); diff --git a/src/declarative/qml/qmlcontext_p.h b/src/declarative/qml/qmlcontext_p.h index 9a77e94..be7bf1d 100644 --- a/src/declarative/qml/qmlcontext_p.h +++ b/src/declarative/qml/qmlcontext_p.h @@ -129,7 +129,7 @@ public: }; ContextGuard *idValues; int idValueCount; - void setIdProperty(const QString &, int, QObject *); + void setIdProperty(int, QObject *); void setIdPropertyData(QmlIntegerCache *); void destroyed(ContextGuard *); diff --git a/src/declarative/qml/qmlenginedebug.cpp b/src/declarative/qml/qmlenginedebug.cpp index 7178e6c..664ca3f 100644 --- a/src/declarative/qml/qmlenginedebug.cpp +++ b/src/declarative/qml/qmlenginedebug.cpp @@ -104,7 +104,7 @@ QmlEngineDebugServer::propertyData(QObject *obj, int propIdx) rv.type = QmlObjectProperty::Unknown; rv.valueTypeName = QString::fromUtf8(prop.typeName()); - rv.name = prop.name(); + rv.name = QString::fromUtf8(prop.name()); rv.hasNotifySignal = prop.hasNotifySignal(); QmlAbstractBinding *binding = QmlMetaProperty(obj, rv.name).binding(); if (binding) @@ -229,7 +229,7 @@ QmlEngineDebugServer::objectData(QObject *object) } rv.objectName = object->objectName(); - rv.objectType = object->metaObject()->className(); + rv.objectType = QString::fromUtf8(object->metaObject()->className()); rv.objectId = QmlDebugService::idForObject(object); rv.contextId = QmlDebugService::idForObject(qmlContext(object)); diff --git a/src/declarative/qml/qmlglobalscriptclass.cpp b/src/declarative/qml/qmlglobalscriptclass.cpp index 0ade5ee..91187c7 100644 --- a/src/declarative/qml/qmlglobalscriptclass.cpp +++ b/src/declarative/qml/qmlglobalscriptclass.cpp @@ -70,6 +70,10 @@ QmlGlobalScriptClass::queryProperty(const QScriptValue &object, const QScriptString &name, QueryFlags flags, uint *id) { + Q_UNUSED(object) + Q_UNUSED(name) + Q_UNUSED(flags) + Q_UNUSED(id) return HandlesReadAccess | HandlesWriteAccess; } @@ -78,6 +82,9 @@ QmlGlobalScriptClass::property(const QScriptValue &object, const QScriptString &name, uint id) { + Q_UNUSED(object) + Q_UNUSED(name) + Q_UNUSED(id) return engine()->undefinedValue(); } @@ -85,6 +92,8 @@ void QmlGlobalScriptClass::setProperty(QScriptValue &object, const QScriptString &name, uint id, const QScriptValue &value) { + Q_UNUSED(object) + Q_UNUSED(value) QString error = QLatin1String("Invalid write to global property \"") + name.toString() + QLatin1String("\""); engine()->currentContext()->throwError(error); diff --git a/src/declarative/qml/qmlobjectscriptclass.cpp b/src/declarative/qml/qmlobjectscriptclass.cpp index a6edd3b..eac354d 100644 --- a/src/declarative/qml/qmlobjectscriptclass.cpp +++ b/src/declarative/qml/qmlobjectscriptclass.cpp @@ -134,7 +134,6 @@ QmlObjectScriptClass::queryProperty(QObject *obj, const Identifier &name, return 0; QmlEnginePrivate *enginePrivate = QmlEnginePrivate::get(engine); - QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); QmlPropertyCache *cache = 0; QmlDeclarativeData *ddata = QmlDeclarativeData::get(obj); diff --git a/src/declarative/qml/qmlpropertycache.cpp b/src/declarative/qml/qmlpropertycache.cpp index 3ede341..4c24cdd 100644 --- a/src/declarative/qml/qmlpropertycache.cpp +++ b/src/declarative/qml/qmlpropertycache.cpp @@ -48,7 +48,7 @@ QT_BEGIN_NAMESPACE void QmlPropertyCache::Data::load(const QMetaProperty &p) { propType = p.userType(); - if (propType == QVariant::LastType) + if (QVariant::Type(propType) == QVariant::LastType) propType = qMetaTypeId(); coreIndex = p.propertyIndex(); notifyIndex = p.notifySignalIndex(); diff --git a/src/declarative/qml/qmlrewrite.cpp b/src/declarative/qml/qmlrewrite.cpp index 43b2529..7cf8888 100644 --- a/src/declarative/qml/qmlrewrite.cpp +++ b/src/declarative/qml/qmlrewrite.cpp @@ -120,7 +120,7 @@ bool RewriteBinding::visit(AST::ExpressionStatement *ast) return false; } -bool RewriteBinding::visit(AST::DoWhileStatement *ast) +bool RewriteBinding::visit(AST::DoWhileStatement *) { ++_inLoop; return true; @@ -131,7 +131,7 @@ void RewriteBinding::endVisit(AST::DoWhileStatement *) --_inLoop; } -bool RewriteBinding::visit(AST::WhileStatement *ast) +bool RewriteBinding::visit(AST::WhileStatement *) { ++_inLoop; return true; @@ -142,7 +142,7 @@ void RewriteBinding::endVisit(AST::WhileStatement *) --_inLoop; } -bool RewriteBinding::visit(AST::ForStatement *ast) +bool RewriteBinding::visit(AST::ForStatement *) { ++_inLoop; return true; @@ -153,7 +153,7 @@ void RewriteBinding::endVisit(AST::ForStatement *) --_inLoop; } -bool RewriteBinding::visit(AST::LocalForStatement *ast) +bool RewriteBinding::visit(AST::LocalForStatement *) { ++_inLoop; return true; @@ -164,7 +164,7 @@ void RewriteBinding::endVisit(AST::LocalForStatement *) --_inLoop; } -bool RewriteBinding::visit(AST::ForEachStatement *ast) +bool RewriteBinding::visit(AST::ForEachStatement *) { ++_inLoop; return true; @@ -175,7 +175,7 @@ void RewriteBinding::endVisit(AST::ForEachStatement *) --_inLoop; } -bool RewriteBinding::visit(AST::LocalForEachStatement *ast) +bool RewriteBinding::visit(AST::LocalForEachStatement *) { ++_inLoop; return true; diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp index 802a78f..b986b60 100644 --- a/src/declarative/qml/qmlvme.cpp +++ b/src/declarative/qml/qmlvme.cpp @@ -225,7 +225,7 @@ QObject *QmlVME::run(QStack &stack, QmlContext *ctxt, { QObject *target = stack.top(); // ctxt->setContextProperty(primitives.at(instr.setId.value), target); - cp->setIdProperty(primitives.at(instr.setId.value), instr.setId.index, target); + cp->setIdProperty(instr.setId.index, target); } break; diff --git a/src/declarative/qml/qmlvmemetaobject.cpp b/src/declarative/qml/qmlvmemetaobject.cpp index a627bf9..3e1d931 100644 --- a/src/declarative/qml/qmlvmemetaobject.cpp +++ b/src/declarative/qml/qmlvmemetaobject.cpp @@ -278,7 +278,7 @@ int QmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) QMetaMethod m = method(_id); QList names = m.parameterNames(); for (int ii = 0; ii < names.count(); ++ii) - newCtxt.setContextProperty(names.at(ii), *(QVariant *)a[ii + 1]); + newCtxt.setContextProperty(QString::fromLatin1(names.at(ii)), *(QVariant *)a[ii + 1]); QmlExpression expr(&newCtxt, code, object); expr.setTrackChange(false); expr.value(); diff --git a/src/declarative/util/qmlanimation.h b/src/declarative/util/qmlanimation.h index 7898980..f4f9f38 100644 --- a/src/declarative/util/qmlanimation.h +++ b/src/declarative/util/qmlanimation.h @@ -65,6 +65,7 @@ class Q_AUTOTEST_EXPORT QmlAbstractAnimation : public QObject, public QmlPropert Q_DECLARE_PRIVATE(QmlAbstractAnimation) Q_INTERFACES(QmlParserStatus) + Q_INTERFACES(QmlPropertyValueSource) Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged) Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged) Q_PROPERTY(bool alwaysRunToEnd READ alwaysRunToEnd WRITE setAlwaysRunToEnd NOTIFY alwaysRunToEndChanged()) diff --git a/src/declarative/util/qmllistaccessor.cpp b/src/declarative/util/qmllistaccessor.cpp index 21007d6..3e4cb64 100644 --- a/src/declarative/util/qmllistaccessor.cpp +++ b/src/declarative/util/qmllistaccessor.cpp @@ -73,7 +73,7 @@ void QmlListAccessor::setList(const QVariant &v, QmlEngine *engine) m_type = Invalid; } else if (d.type() == QVariant::StringList) { m_type = StringList; - } else if (d.type() == QMetaType::QVariantList) { + } else if (d.type() == (QVariant::Type)QMetaType::QVariantList) { m_type = VariantList; } else if (d.canConvert(QVariant::Int)) { m_type = Integer; -- cgit v0.12 From 28cd6e0ed60df6f86a9d736b71ed00e26c224cdb Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Mon, 26 Oct 2009 15:56:49 +1000 Subject: fix anchors --- examples/declarative/animation/easing.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/declarative/animation/easing.qml b/examples/declarative/animation/easing.qml index 9e0a0d6..59e9b17 100644 --- a/examples/declarative/animation/easing.qml +++ b/examples/declarative/animation/easing.qml @@ -92,7 +92,7 @@ Rectangle { anchors.fill: parent; viewportHeight: layout.height Column { id: layout - anchors.left: window.left; anchors.right: window.right + anchors.left: parent.left; anchors.right: parent.right Repeater { model: easingTypes; delegate: delegate } } } -- cgit v0.12 From de892b03e4d1ec11215c2817578415be311eab29 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Mon, 26 Oct 2009 15:57:11 +1000 Subject: Use QScriptProgram under windows --- src/declarative/qml/qmlexpression.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/declarative/qml/qmlexpression.cpp b/src/declarative/qml/qmlexpression.cpp index e3ac5bf..3b89a23 100644 --- a/src/declarative/qml/qmlexpression.cpp +++ b/src/declarative/qml/qmlexpression.cpp @@ -110,7 +110,7 @@ void QmlExpressionPrivate::init(QmlContext *ctxt, void *expr, QmlRefCount *rc, QmlEngine *engine = ctxt->engine(); QmlEnginePrivate *ep = QmlEnginePrivate::get(engine); QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); -#if !defined(Q_OS_SYMBIAN) && !defined(Q_OS_WIN32) //XXX Why doesn't this work? +#if !defined(Q_OS_SYMBIAN) //XXX Why doesn't this work? if (!dd->programs.at(progIdx)) { dd->programs[progIdx] = new QScriptProgram(data->expression, data->fileName, data->line); @@ -120,7 +120,7 @@ void QmlExpressionPrivate::init(QmlContext *ctxt, void *expr, QmlRefCount *rc, QScriptContext *scriptContext = scriptEngine->pushCleanContext(); scriptContext->pushScope(ep->contextClass->newContext(ctxt, me)); -#if !defined(Q_OS_SYMBIAN) && !defined(Q_OS_WIN32) +#if !defined(Q_OS_SYMBIAN) data->expressionFunction = scriptEngine->evaluate(*dd->programs[progIdx]); #else data->expressionFunction = scriptEngine->evaluate(data->expression); -- cgit v0.12 From 5cb74c426a4d3da018dd00a494e4953c162a47da Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Mon, 26 Oct 2009 15:57:36 +1000 Subject: Doc --- doc/src/declarative/animation.qdoc | 1 - doc/src/declarative/qmlreference.qdoc | 2 +- doc/src/declarative/qtdeclarative.qdoc | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/src/declarative/animation.qdoc b/doc/src/declarative/animation.qdoc index 2d98322..ef18de3 100644 --- a/doc/src/declarative/animation.qdoc +++ b/doc/src/declarative/animation.qdoc @@ -41,7 +41,6 @@ /*! \page qmlanimation.html -\target qmlanimation \title QML Animation Animation in QML is done by animating properties of objects. Properties of type diff --git a/doc/src/declarative/qmlreference.qdoc b/doc/src/declarative/qmlreference.qdoc index 76269c3..6a874b6 100644 --- a/doc/src/declarative/qmlreference.qdoc +++ b/doc/src/declarative/qmlreference.qdoc @@ -74,7 +74,7 @@ \o \l {qmlmodels}{Data Models} \o \l {anchor-layout}{Anchor-based Layout} \o \l {qmlstates}{States} - \o \l {qmlanimation}{Animation} + \o \l {qmlanimation.html}{Animation} \o \l {qmlmodules.html}{Modules} \o \l {qmlfocus}{Keyboard Focus} \o \l {Extending types from QML} diff --git a/doc/src/declarative/qtdeclarative.qdoc b/doc/src/declarative/qtdeclarative.qdoc index 7be98db..ab952e7 100644 --- a/doc/src/declarative/qtdeclarative.qdoc +++ b/doc/src/declarative/qtdeclarative.qdoc @@ -88,7 +88,7 @@ completely new applications. QML is fully \l {Extending QML}{extensible from C+ \o \l {qmlmodels}{Data Models} \o \l {anchor-layout}{Anchor-based Layout} \o \l {qmlstates}{States} -\o \l {qmlanimation}{Animation} +\o \l {qmlanimation.html}{Animation} \o \l {qmlmodules.html}{Modules} \o \l {qmlfocus}{Keyboard Focus} \o \l {Extending types from QML} -- cgit v0.12 From 33071ea2211633df29fe14c5d196785d163253a6 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Mon, 26 Oct 2009 15:57:41 +1000 Subject: improve connections example. --- examples/declarative/connections/Button.qml | 12 +++++++ examples/declarative/connections/bg1.jpg | Bin 0 -> 23771 bytes examples/declarative/connections/connections.qml | 42 +++++++++++----------- examples/declarative/connections/rotate-left.png | Bin 0 -> 3061 bytes examples/declarative/connections/rotate-right.png | Bin 0 -> 3115 bytes 5 files changed, 32 insertions(+), 22 deletions(-) create mode 100644 examples/declarative/connections/Button.qml create mode 100644 examples/declarative/connections/bg1.jpg create mode 100644 examples/declarative/connections/rotate-left.png create mode 100644 examples/declarative/connections/rotate-right.png diff --git a/examples/declarative/connections/Button.qml b/examples/declarative/connections/Button.qml new file mode 100644 index 0000000..1d46acc --- /dev/null +++ b/examples/declarative/connections/Button.qml @@ -0,0 +1,12 @@ +import Qt 4.6 + +Item { + id: button + width: 48; height: 48 + + property alias image: icon.source + signal clicked + + Image { id: icon } + MouseRegion { anchors.fill: icon; onClicked: button.clicked() } +} diff --git a/examples/declarative/connections/bg1.jpg b/examples/declarative/connections/bg1.jpg new file mode 100644 index 0000000..dfc7cee Binary files /dev/null and b/examples/declarative/connections/bg1.jpg differ diff --git a/examples/declarative/connections/connections.qml b/examples/declarative/connections/connections.qml index b693b7e..5dc211e 100644 --- a/examples/declarative/connections/connections.qml +++ b/examples/declarative/connections/connections.qml @@ -1,32 +1,30 @@ import Qt 4.6 Rectangle { - id: rect - color: "blue" - width: 40 - height: 30 + id: window; color: "#343434" + width: 640; height: 480 - Rectangle { - id: dot - color: "red" - width: 3 - height: 3 - x: rect.width/2 - y: rect.height/2 + function turnLeft() { + image.rotation -= 90 + } + function turnRight() { + image.rotation += 90 } - MouseRegion { - id: mr - anchors.fill: rect + Image { + id: image; source: "bg1.jpg"; anchors.centerIn: parent; transformOrigin: Item.Center + rotation: Behavior { NumberAnimation { easing: "easeOutCubic"; duration: 300 } } } - Connection { - sender: mr - signal: "clicked(mouse)" - script: { - color = "green"; - dot.x = mouse.x-1; - dot.y = mouse.y-1; - } + Button { + id: leftButton; image: "rotate-left.png" + anchors { left: parent.left; bottom: parent.bottom; leftMargin: 10; bottomMargin: 10 } + } + Button { + id: rightButton; image: "rotate-right.png" + anchors { right: parent.right; bottom: parent.bottom; rightMargin: 10; bottomMargin: 10 } } + + Connection { sender: leftButton; signal: "clicked()"; script: window.turnLeft() } + Connection { sender: rightButton; signal: "clicked()"; script: window.turnRight() } } diff --git a/examples/declarative/connections/rotate-left.png b/examples/declarative/connections/rotate-left.png new file mode 100644 index 0000000..c30387e Binary files /dev/null and b/examples/declarative/connections/rotate-left.png differ diff --git a/examples/declarative/connections/rotate-right.png b/examples/declarative/connections/rotate-right.png new file mode 100644 index 0000000..1b05674 Binary files /dev/null and b/examples/declarative/connections/rotate-right.png differ -- cgit v0.12