From 2aa55af392f527b9357ca227d853a2ee5e340f35 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Fri, 4 Feb 2011 13:49:09 +1000 Subject: Only ask for name when the user goes on the high score list. Task-number: QTBUG-14714 --- .../declarative/samegame/SamegameCore/samegame.js | 41 +++++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/demos/declarative/samegame/SamegameCore/samegame.js b/demos/declarative/samegame/SamegameCore/samegame.js index e618a10..16c48c4 100755 --- a/demos/declarative/samegame/SamegameCore/samegame.js +++ b/demos/declarative/samegame/SamegameCore/samegame.js @@ -8,6 +8,7 @@ var blockSrc = "SamegameCore/BoomBlock.qml"; var scoresURL = ""; var gameDuration; var component = Qt.createComponent(blockSrc); +var highScoreBar = 0; // Index function used instead of a 2D array function index(column, row) @@ -152,11 +153,15 @@ function victoryCheck() // Checks for game over if (deservesBonus || !(floodMoveCheck(0, maxRow - 1, -1))) { gameDuration = new Date() - gameDuration; - nameInputDialog.show("You won! Please enter your name: "); - nameInputDialog.initialWidth = nameInputDialog.text.width + 20; - if (nameInputDialog.name == "") - nameInputDialog.width = nameInputDialog.initialWidth; - nameInputDialog.text.opacity = 0; // Just a spacer + if(gameCanvas.score > highScoreBar){ + nameInputDialog.show("You won! Please enter your name: "); + nameInputDialog.initialWidth = nameInputDialog.text.width + 20; + if (nameInputDialog.name == "") + nameInputDialog.width = nameInputDialog.initialWidth; + nameInputDialog.text.opacity = 0; // Just a spacer + }else{ + dialog.show("You won!"); + } } } @@ -202,6 +207,30 @@ function createBlock(column,row) return true; } +function initHighScoreBar() +{ + if(scoresURL != "") + return true;//don't query remote scores + var db = openDatabaseSync( + "SameGameScores", + "1.0", + "Local SameGame High Scores", + 100 + ); + db.transaction( + function(tx) { + tx.executeSql('CREATE TABLE IF NOT EXISTS Scores(name TEXT, score NUMBER, gridSize TEXT, time NUMBER)'); + // Only show results for the current grid size + var rs = tx.executeSql('SELECT * FROM Scores WHERE gridSize = "' + + maxColumn + "x" + maxRow + '" ORDER BY score desc LIMIT 10'); + if(rs.rows.length < 10) + highScoreBar = 0; + else + highScoreBar = rs.rows.item(rs.rows.length - 1).score; + } + ); +} + function saveHighScore(name) { if (scoresURL != "") @@ -234,6 +263,8 @@ function saveHighScore(name) + rs.rows.item(i).score + ' points in ' + rs.rows.item(i).time + ' seconds.\n'; } + if(rs.rows.length == 10) + highScoreBar = rs.rows.item(9).score; dialog.show(r); } ); -- cgit v0.12 From b82332fec19ee977eceaf2d533ee027020a474e0 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Fri, 4 Feb 2011 14:02:21 +1000 Subject: Make -no-opengl exist on other platforms Task-Number: QTBUG-15830 --- tools/qml/main.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index 5846ff0..67154dd 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -161,7 +161,9 @@ void usage() qWarning(" -P ........................... prepend to the plugin search path"); #if defined(Q_WS_MAC) qWarning(" -no-opengl ............................... don't use a QGLWidget for the viewport"); + qWarning(" -opengl .................................. use a QGLWidget for the viewport (default)"); #else + qWarning(" -no-opengl ............................... don't use a QGLWidget for the viewport (default)"); qWarning(" -opengl .................................. use a QGLWidget for the viewport"); #endif qWarning(" -script ........................... set the script to use"); @@ -380,13 +382,10 @@ static void parseCommandLineOptions(const QStringList &arguments) } else if (arg == "-translation") { if (lastArg) usage(); opts.translationFile = arguments.at(++i); -#if defined(Q_WS_MAC) } else if (arg == "-no-opengl") { opts.useGL = false; -#else } else if (arg == "-opengl") { opts.useGL = true; -#endif } else if (arg == "-qmlbrowser") { opts.useNativeFileBrowser = false; } else if (arg == "-warnings") { -- cgit v0.12 From ca03f39224fb64775ed7150685df96c6b5b83b23 Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Fri, 25 Feb 2011 14:50:38 +0100 Subject: Fixed QML TextEdit docs Removed non-existent enumeration value from docs. Signed-off-by: Thiago Marcos P. Santos Reviewed-by: Leonardo Sobral Cunha --- src/declarative/graphicsitems/qdeclarativetextedit.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index e2f6265..42ce404 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -271,7 +271,6 @@ void QDeclarativeTextEdit::setText(const QString &text) \o TextEdit.AutoText \o TextEdit.PlainText \o TextEdit.RichText - \o TextEdit.StyledText \endlist The default is TextEdit.AutoText. If the text format is TextEdit.AutoText the text edit -- cgit v0.12 From 9a5f3dd71a7c3bb4e777c92cca09100d077a736a Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Mon, 14 Mar 2011 14:36:52 +1000 Subject: Add Constant and Final flags to QMetaObjectBuilder Change-Id: I25090e833f7ce184bcbf2bc5b9281c27ab05aa2d Reviewed-by: Michael Brasser --- src/declarative/qml/qmetaobjectbuilder.cpp | 57 +++++++++++++++++++++- src/declarative/qml/qmetaobjectbuilder_p.h | 4 ++ .../qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp | 22 ++++++++- 3 files changed, 81 insertions(+), 2 deletions(-) diff --git a/src/declarative/qml/qmetaobjectbuilder.cpp b/src/declarative/qml/qmetaobjectbuilder.cpp index 6a0226f..448797b 100644 --- a/src/declarative/qml/qmetaobjectbuilder.cpp +++ b/src/declarative/qml/qmetaobjectbuilder.cpp @@ -101,7 +101,7 @@ bool isVariantType(const char* type) return qvariant_nameToType(type) != 0; } -// copied from qmetaobject.cpp +// copied from qmetaobject_p.h // do not touch without touching the moc as well enum PropertyFlags { Invalid = 0x00000000, @@ -111,6 +111,8 @@ enum PropertyFlags { EnumOrFlag = 0x00000008, StdCppSet = 0x00000100, // Override = 0x00000200, + Constant = 0x00000400, + Final = 0x00000800, Designable = 0x00001000, ResolveDesignable = 0x00002000, Scriptable = 0x00004000, @@ -618,6 +620,8 @@ QMetaPropertyBuilder QMetaObjectBuilder::addProperty(const QMetaProperty& protot property.setUser(prototype.isUser()); property.setStdCppSet(prototype.hasStdCppSet()); property.setEnumOrFlag(prototype.isEnumType()); + property.setConstant(prototype.isConstant()); + property.setFinal(prototype.isFinal()); if (prototype.hasNotifySignal()) { // Find an existing method for the notify signal, or add a new one. QMetaMethod method = prototype.notifySignal(); @@ -2278,6 +2282,32 @@ bool QMetaPropertyBuilder::isEnumOrFlag() const } /*! + Returns true if the property is constant; otherwise returns false. + The default value is false. +*/ +bool QMetaPropertyBuilder::isConstant() const +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + return d->flag(Constant); + else + return false; +} + +/*! + Returns true if the property is final; otherwise returns false. + The default value is false. +*/ +bool QMetaPropertyBuilder::isFinal() const +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + return d->flag(Final); + else + return false; +} + +/*! Sets this property to readable if \a value is true. \sa isReadable(), setWritable() @@ -2401,6 +2431,31 @@ void QMetaPropertyBuilder::setEnumOrFlag(bool value) } /*! + Sets the \c CONSTANT flag on this property to \a value. + + \sa isConstant() +*/ +void QMetaPropertyBuilder::setConstant(bool value) +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + d->setFlag(Constant, value); +} + +/*! + Sets the \c FINAL flag on this property to \a value. + + \sa isFinal() +*/ +void QMetaPropertyBuilder::setFinal(bool value) +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + d->setFlag(Final, value); +} + + +/*! \class QMetaEnumBuilder \internal \brief The QMetaEnumBuilder class enables modifications to an enumerator definition on a meta object builder. diff --git a/src/declarative/qml/qmetaobjectbuilder_p.h b/src/declarative/qml/qmetaobjectbuilder_p.h index 2678bff..392e13b 100644 --- a/src/declarative/qml/qmetaobjectbuilder_p.h +++ b/src/declarative/qml/qmetaobjectbuilder_p.h @@ -258,6 +258,8 @@ public: bool isUser() const; bool hasStdCppSet() const; bool isEnumOrFlag() const; + bool isConstant() const; + bool isFinal() const; void setReadable(bool value); void setWritable(bool value); @@ -269,6 +271,8 @@ public: void setUser(bool value); void setStdCppSet(bool value); void setEnumOrFlag(bool value); + void setConstant(bool value); + void setFinal(bool value); private: const QMetaObjectBuilder *_mobj; diff --git a/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp b/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp index 06baed8..ff72654 100644 --- a/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp +++ b/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp @@ -546,6 +546,8 @@ void tst_QMetaObjectBuilder::property() QVERIFY(!nullProp.isUser()); QVERIFY(!nullProp.hasStdCppSet()); QVERIFY(!nullProp.isEnumOrFlag()); + QVERIFY(!nullProp.isConstant()); + QVERIFY(!nullProp.isFinal()); QCOMPARE(nullProp.index(), 0); // Add a property and check its attributes. @@ -563,6 +565,8 @@ void tst_QMetaObjectBuilder::property() QVERIFY(!prop1.isUser()); QVERIFY(!prop1.hasStdCppSet()); QVERIFY(!prop1.isEnumOrFlag()); + QVERIFY(!prop1.isConstant()); + QVERIFY(!prop1.isFinal()); QCOMPARE(prop1.index(), 0); QCOMPARE(builder.propertyCount(), 1); @@ -581,6 +585,8 @@ void tst_QMetaObjectBuilder::property() QVERIFY(!prop2.isUser()); QVERIFY(!prop2.hasStdCppSet()); QVERIFY(!prop2.isEnumOrFlag()); + QVERIFY(!prop2.isConstant()); + QVERIFY(!prop2.isFinal()); QCOMPARE(prop2.index(), 1); QCOMPARE(builder.propertyCount(), 2); @@ -602,6 +608,8 @@ void tst_QMetaObjectBuilder::property() prop1.setUser(true); prop1.setStdCppSet(true); prop1.setEnumOrFlag(true); + prop1.setConstant(true); + prop1.setFinal(true); // Check that prop1 is changed, but prop2 is not. QCOMPARE(prop1.name(), QByteArray("foo")); @@ -616,6 +624,8 @@ void tst_QMetaObjectBuilder::property() QVERIFY(prop1.isUser()); QVERIFY(prop1.hasStdCppSet()); QVERIFY(prop1.isEnumOrFlag()); + QVERIFY(prop1.isConstant()); + QVERIFY(prop1.isFinal()); QVERIFY(prop2.isReadable()); QVERIFY(prop2.isWritable()); QCOMPARE(prop2.name(), QByteArray("bar")); @@ -628,6 +638,8 @@ void tst_QMetaObjectBuilder::property() QVERIFY(!prop2.isUser()); QVERIFY(!prop2.hasStdCppSet()); QVERIFY(!prop2.isEnumOrFlag()); + QVERIFY(!prop2.isConstant()); + QVERIFY(!prop2.isFinal()); // Remove prop1 and check that prop2 becomes index 0. builder.removeProperty(0); @@ -643,6 +655,8 @@ void tst_QMetaObjectBuilder::property() QVERIFY(!prop2.isUser()); QVERIFY(!prop2.hasStdCppSet()); QVERIFY(!prop2.isEnumOrFlag()); + QVERIFY(!prop2.isConstant()); + QVERIFY(!prop2.isFinal()); QCOMPARE(prop2.index(), 0); // Perform index-based lookup again. @@ -666,6 +680,8 @@ void tst_QMetaObjectBuilder::property() prop2.setUser(false); \ prop2.setStdCppSet(false); \ prop2.setEnumOrFlag(false); \ + prop2.setConstant(false); \ + prop2.setFinal(false); \ } while (0) #define COUNT_FLAGS() \ ((prop2.isReadable() ? 1 : 0) + \ @@ -677,7 +693,9 @@ void tst_QMetaObjectBuilder::property() (prop2.isEditable() ? 1 : 0) + \ (prop2.isUser() ? 1 : 0) + \ (prop2.hasStdCppSet() ? 1 : 0) + \ - (prop2.isEnumOrFlag() ? 1 : 0)) + (prop2.isEnumOrFlag() ? 1 : 0) + \ + (prop2.isConstant() ? 1 : 0) + \ + (prop2.isFinal() ? 1 : 0)) #define CHECK_FLAG(setFunc,isFunc) \ do { \ CLEAR_FLAGS(); \ @@ -696,6 +714,8 @@ void tst_QMetaObjectBuilder::property() CHECK_FLAG(setUser, isUser); CHECK_FLAG(setStdCppSet, hasStdCppSet); CHECK_FLAG(setEnumOrFlag, isEnumOrFlag); + CHECK_FLAG(setConstant, isConstant); + CHECK_FLAG(setFinal, isFinal); // Check that nothing else changed. QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::Properties)); -- cgit v0.12 From 99512251be8e5814238ec398854a8aa71fa8b25d Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 16 Mar 2011 10:23:06 +1000 Subject: Optimization and benchmark for setting object properties from QML. Change-Id: Ib923e5d3946e99001ef682a9dd8ca6d7788818a3 Reviewed-by: Aaron Kennedy --- .../qml/qdeclarativeobjectscriptclass.cpp | 27 ++++++++++++ .../qdeclarativeecmascript/data/realToInt.qml | 11 +++++ .../tst_qdeclarativeecmascript.cpp | 13 ++++++ tests/benchmarks/declarative/script/tst_script.cpp | 49 +++++++++++++++++++++- 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/realToInt.qml diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp index dc3ecca..e7ab9cd 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp @@ -395,6 +395,33 @@ void QDeclarativeObjectScriptClass::setProperty(QObject *obj, } else if (value.isFunction() && !value.isRegExp()) { // this is handled by the binding creation above } else { + //### expand optimization for other known types + if (lastData->propType == QMetaType::Int && value.isNumber()) { + int rawValue = qRound(value.toNumber()); + int status = -1; + int flags = 0; + void *a[] = { (void *)&rawValue, 0, &status, &flags }; + QMetaObject::metacall(obj, QMetaObject::WriteProperty, + lastData->coreIndex, a); + return; + } else if (lastData->propType == QMetaType::QReal && value.isNumber()) { + qreal rawValue = qreal(value.toNumber()); + int status = -1; + int flags = 0; + void *a[] = { (void *)&rawValue, 0, &status, &flags }; + QMetaObject::metacall(obj, QMetaObject::WriteProperty, + lastData->coreIndex, a); + return; + } else if (lastData->propType == QMetaType::QString && value.isString()) { + const QString &rawValue = value.toString(); + int status = -1; + int flags = 0; + void *a[] = { (void *)&rawValue, 0, &status, &flags }; + QMetaObject::metacall(obj, QMetaObject::WriteProperty, + lastData->coreIndex, a); + return; + } + QVariant v; if (lastData->flags & QDeclarativePropertyCache::Data::IsQList) v = enginePriv->scriptValueToVariant(value, qMetaTypeId >()); diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/realToInt.qml b/tests/auto/declarative/qdeclarativeecmascript/data/realToInt.qml new file mode 100644 index 0000000..cbbbbf9 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/realToInt.qml @@ -0,0 +1,11 @@ +import QtQuick 1.0 +import Qt.test 1.0 + +MyQmlObject { + function test1() { + value = 4.2 + } + function test2() { + value = 7.9 + } +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 40b0e1b..2f5581a 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -176,6 +176,7 @@ private slots: void aliasBindingsOverrideTarget(); void aliasWritesOverrideBindings(); void pushCleanContext(); + void realToInt(); void include(); @@ -3055,6 +3056,18 @@ void tst_qdeclarativeecmascript::pushCleanContext() QCOMPARE(func2.call().toInt32(), 6); } +void tst_qdeclarativeecmascript::realToInt() +{ + QDeclarativeComponent component(&engine, TEST_FILE("realToInt.qml")); + MyQmlObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QMetaObject::invokeMethod(object, "test1"); + QCOMPARE(object->value(), int(4)); + QMetaObject::invokeMethod(object, "test2"); + QCOMPARE(object->value(), int(8)); +} + QTEST_MAIN(tst_qdeclarativeecmascript) #include "tst_qdeclarativeecmascript.moc" diff --git a/tests/benchmarks/declarative/script/tst_script.cpp b/tests/benchmarks/declarative/script/tst_script.cpp index 2020a18..b07ffa1 100644 --- a/tests/benchmarks/declarative/script/tst_script.cpp +++ b/tests/benchmarks/declarative/script/tst_script.cpp @@ -70,6 +70,9 @@ private slots: void property_qobject(); void property_qmlobject(); + void setproperty_js(); + void setproperty_qmlobject(); + void function_js(); void function_cpp(); void function_qobject(); @@ -108,12 +111,13 @@ inline QUrl TEST_FILE(const QString &filename) class TestObject : public QObject { Q_OBJECT - Q_PROPERTY(int x READ x) + Q_PROPERTY(int x READ x WRITE setX) public: TestObject(QObject *parent = 0); int x(); + void setX(int x) { m_x = x; } void emitMySignal() { emit mySignal(); } void emitMySignalWithArgs(int n) { emit mySignalWithArgs(n); } @@ -323,6 +327,49 @@ void tst_script::property_qmlobject() } } +#define SETPROPERTY_PROGRAM \ + "(function(testObject) { return (function() { " \ + " for (var ii = 0; ii < 10000; ++ii) { " \ + " testObject.x = ii; " \ + " } " \ + "}); })" + +void tst_script::setproperty_js() +{ + QScriptEngine engine; + + QScriptValue v = engine.newObject(); + v.setProperty(QLatin1String("x"), 0); + + QScriptValueList args; + args << v; + QScriptValue prog = engine.evaluate(SETPROPERTY_PROGRAM).call(engine.globalObject(), args); + prog.call(); + + QBENCHMARK { + prog.call(); + } +} + +void tst_script::setproperty_qmlobject() +{ + QDeclarativeEngine qmlengine; + + QScriptEngine *engine = QDeclarativeEnginePrivate::getScriptEngine(&qmlengine); + TestObject to; + + QScriptValue v = QDeclarativeEnginePrivate::get(&qmlengine)->objectClass->newQObject(&to); + + QScriptValueList args; + args << v; + QScriptValue prog = engine->evaluate(SETPROPERTY_PROGRAM).call(engine->globalObject(), args); + prog.call(); + + QBENCHMARK { + prog.call(); + } +} + #define FUNCTION_PROGRAM \ "(function(testObject) { return (function() { " \ " var test = 0; " \ -- cgit v0.12 From b3f605aebb90dc651e73a252788a81cb530a74b9 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 18 Feb 2011 16:19:23 +1000 Subject: Stop the animation driver when there are no more animations. Change-Id: If03c9e4539e984db725f7e7d89e8b565890fcbed Reviewed-by: Gunnar Sletta --- src/corelib/animation/qabstractanimation.cpp | 3 ++- src/corelib/animation/qabstractanimation_p.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index 2d5cfab..a562542 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -254,7 +254,8 @@ void QUnifiedTimer::restartAnimationTimer() } else if (!driver->isRunning() || isPauseTimerActive) { driver->start(); isPauseTimerActive = false; - } + } else if (runningLeafAnimations == 0) + driver->stop(); } void QUnifiedTimer::setTimingInterval(int interval) diff --git a/src/corelib/animation/qabstractanimation_p.h b/src/corelib/animation/qabstractanimation_p.h index 1ab05cd..2c0eee7 100644 --- a/src/corelib/animation/qabstractanimation_p.h +++ b/src/corelib/animation/qabstractanimation_p.h @@ -184,6 +184,9 @@ public: void restartAnimationTimer(); void updateAnimationsTime(); + //useful for profiling/debugging + int runningAnimationCount() { return animations.count(); } + protected: void timerEvent(QTimerEvent *); -- cgit v0.12 From 0f5feed7dc260eabe1c2784a168e0b2fcc85e1d8 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 16 Mar 2011 17:20:32 +1000 Subject: Fix QUnifiedTimer bug Pause animations (like Timer) could trigger a jump to the next tick, which meant that other pause animations would have missed the interval skipped by the pause. Change-Id: Idebe4cbe70b2a1536d684288fc1c5d65e4c5df84 Cherry-pick-of: 115d437efb25adc2262460e001c034ea3cd8ba14 Task-number: QTBUG-18126 Reviewed-by: Leo Cunha Reviewed-by: Michael Brasser --- src/corelib/animation/qabstractanimation.cpp | 8 +++++++- src/corelib/animation/qabstractanimation_p.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index a562542..55e511d 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -167,7 +167,7 @@ Q_GLOBAL_STATIC(QThreadStorage, unifiedTimer) QUnifiedTimer::QUnifiedTimer() : QObject(), defaultDriver(this), lastTick(0), timingInterval(DEFAULT_TIMER_INTERVAL), - currentAnimationIdx(0), consistentTiming(false), slowMode(false), + insideTick(false), currentAnimationIdx(0), consistentTiming(false), slowMode(false), slowdownFactor(5.0f), isPauseTimerActive(false), runningLeafAnimations(0) { time.invalidate(); @@ -206,6 +206,10 @@ void QUnifiedTimer::ensureTimerUpdate() void QUnifiedTimer::updateAnimationsTime() { + //setCurrentTime can get this called again while we're the for loop. At least with pauseAnimations + if(insideTick) + return; + qint64 totalElapsed = time.elapsed(); // ignore consistentTiming in case the pause timer is active int delta = (consistentTiming && !isPauseTimerActive) ? @@ -223,12 +227,14 @@ void QUnifiedTimer::updateAnimationsTime() //it might happen in some cases that the time doesn't change because events are delayed //when the CPU load is high if (delta) { + insideTick = true; for (currentAnimationIdx = 0; currentAnimationIdx < animations.count(); ++currentAnimationIdx) { QAbstractAnimation *animation = animations.at(currentAnimationIdx); int elapsed = QAbstractAnimationPrivate::get(animation)->totalCurrentTime + (animation->direction() == QAbstractAnimation::Forward ? delta : -delta); animation->setCurrentTime(elapsed); } + insideTick = false; currentAnimationIdx = 0; } } diff --git a/src/corelib/animation/qabstractanimation_p.h b/src/corelib/animation/qabstractanimation_p.h index 2c0eee7..0ccc502 100644 --- a/src/corelib/animation/qabstractanimation_p.h +++ b/src/corelib/animation/qabstractanimation_p.h @@ -205,6 +205,7 @@ private: qint64 lastTick; int timingInterval; int currentAnimationIdx; + bool insideTick; bool consistentTiming; bool slowMode; -- cgit v0.12 From 6567653a003191508ee5561dcd9896cb97cf3ec3 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Thu, 24 Mar 2011 10:05:07 +1000 Subject: Remove compile warning Change-Id: If209db684878ab734b3265b479c59dfc27b18be1 --- src/corelib/animation/qabstractanimation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index 55e511d..0a1f5d7 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -167,7 +167,7 @@ Q_GLOBAL_STATIC(QThreadStorage, unifiedTimer) QUnifiedTimer::QUnifiedTimer() : QObject(), defaultDriver(this), lastTick(0), timingInterval(DEFAULT_TIMER_INTERVAL), - insideTick(false), currentAnimationIdx(0), consistentTiming(false), slowMode(false), + currentAnimationIdx(0), insideTick(false), consistentTiming(false), slowMode(false), slowdownFactor(5.0f), isPauseTimerActive(false), runningLeafAnimations(0) { time.invalidate(); -- cgit v0.12 From 30d7d4d990f9734ed8cdf418ee5c8361a1633b42 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Wed, 23 Mar 2011 14:51:17 +0100 Subject: QDeclarativeDebug: Handle case where client with ongoing queries is deleted Change-Id: I4be7080af1e7e8a834b927b6c6fc211db8bd90c0 Reviewed-by: Aaron Kennedy --- src/declarative/debugger/qdeclarativedebug.cpp | 46 ++++++++++++++++++++++ .../qdeclarativedebug/tst_qdeclarativedebug.cpp | 28 ++++++++++++- 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/src/declarative/debugger/qdeclarativedebug.cpp b/src/declarative/debugger/qdeclarativedebug.cpp index 62eb8fe..049e05e 100644 --- a/src/declarative/debugger/qdeclarativedebug.cpp +++ b/src/declarative/debugger/qdeclarativedebug.cpp @@ -84,6 +84,7 @@ public: static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugRootContextQuery *); static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugObjectQuery *); static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugExpressionQuery *); + static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugWatch *); QHash enginesQuery; QHash rootContextQuery; @@ -120,6 +121,41 @@ QDeclarativeEngineDebugPrivate::~QDeclarativeEngineDebugPrivate() { if (client) client->priv = 0; + delete client; + + QHash::iterator enginesIter = enginesQuery.begin(); + for (; enginesIter != enginesQuery.end(); ++enginesIter) { + enginesIter.value()->m_client = 0; + if (enginesIter.value()->state() == QDeclarativeDebugQuery::Waiting) + enginesIter.value()->setState(QDeclarativeDebugQuery::Error); + } + + QHash::iterator rootContextIter = rootContextQuery.begin(); + for (; rootContextIter != rootContextQuery.end(); ++rootContextIter) { + rootContextIter.value()->m_client = 0; + if (rootContextIter.value()->state() == QDeclarativeDebugQuery::Waiting) + rootContextIter.value()->setState(QDeclarativeDebugQuery::Error); + } + + QHash::iterator objectIter = objectQuery.begin(); + for (; objectIter != objectQuery.end(); ++objectIter) { + objectIter.value()->m_client = 0; + if (objectIter.value()->state() == QDeclarativeDebugQuery::Waiting) + objectIter.value()->setState(QDeclarativeDebugQuery::Error); + } + + QHash::iterator exprIter = expressionQuery.begin(); + for (; exprIter != expressionQuery.end(); ++exprIter) { + exprIter.value()->m_client = 0; + if (exprIter.value()->state() == QDeclarativeDebugQuery::Waiting) + exprIter.value()->setState(QDeclarativeDebugQuery::Error); + } + + QHash::iterator watchIter = watched.begin(); + for (; watchIter != watched.end(); ++watchIter) { + watchIter.value()->m_client = 0; + watchIter.value()->setState(QDeclarativeDebugWatch::Dead); + } } int QDeclarativeEngineDebugPrivate::getId() @@ -160,6 +196,14 @@ void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclara } } +void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugWatch *w) +{ + if (c && w) { + QDeclarativeEngineDebugPrivate *p = (QDeclarativeEngineDebugPrivate *)QObjectPrivate::get(c); + p->watched.remove(w->m_queryId); + } +} + void QDeclarativeEngineDebugPrivate::decode(QDataStream &ds, QDeclarativeDebugObjectReference &o, bool simple) { @@ -647,6 +691,8 @@ QDeclarativeDebugWatch::QDeclarativeDebugWatch(QObject *parent) QDeclarativeDebugWatch::~QDeclarativeDebugWatch() { + if (m_client && m_queryId != -1) + QDeclarativeEngineDebugPrivate::remove(m_client, this); } int QDeclarativeDebugWatch::queryId() const diff --git a/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp b/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp index 6bcb4eb..4597ab4 100644 --- a/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp +++ b/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp @@ -649,7 +649,13 @@ void tst_QDeclarativeDebug::queryAvailableEngines() QCOMPARE(e.name(), m_engine->objectName()); } + // Make query invalid by deleting client + q_engines = m_dbg->queryAvailableEngines(this); + QCOMPARE(q_engines->state(), QDeclarativeDebugQuery::Waiting); + delete m_dbg; + QCOMPARE(q_engines->state(), QDeclarativeDebugQuery::Error); delete q_engines; + m_dbg = new QDeclarativeEngineDebug(m_conn, this); } void tst_QDeclarativeDebug::queryRootContexts() @@ -657,6 +663,7 @@ void tst_QDeclarativeDebug::queryRootContexts() QDeclarativeDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); waitForQuery(q_engines); int engineId = q_engines->engines()[0].debugId(); + delete q_engines; QDeclarativeDebugRootContextQuery *q_context; @@ -688,8 +695,13 @@ void tst_QDeclarativeDebug::queryRootContexts() QVERIFY(context.contexts()[0].debugId() >= 0); QCOMPARE(context.contexts()[0].name(), QString("tst_QDeclarativeDebug_childContext")); - delete q_engines; + // Make query invalid by deleting client + q_context = m_dbg->queryRootContexts(engineId, this); + QCOMPARE(q_context->state(), QDeclarativeDebugQuery::Waiting); + delete m_dbg; + QCOMPARE(q_context->state(), QDeclarativeDebugQuery::Error); delete q_context; + m_dbg = new QDeclarativeEngineDebug(m_conn, this); } void tst_QDeclarativeDebug::queryObject() @@ -721,7 +733,14 @@ void tst_QDeclarativeDebug::queryObject() delete q_engines; delete q_context; + + // Make query invalid by deleting client + q_obj = recursive ? m_dbg->queryObjectRecursive(rootObject, this) : m_dbg->queryObject(rootObject, this); + QCOMPARE(q_obj->state(), QDeclarativeDebugQuery::Waiting); + delete m_dbg; + QCOMPARE(q_obj->state(), QDeclarativeDebugQuery::Error); delete q_obj; + m_dbg = new QDeclarativeEngineDebug(m_conn, this); // check source as defined in main() QDeclarativeDebugFileReference source = obj.source(); @@ -796,7 +815,14 @@ void tst_QDeclarativeDebug::queryExpressionResult() delete q_engines; delete q_context; + + // Make query invalid by deleting client + q_expr = m_dbg->queryExpressionResult(objectId, expr, this); + QCOMPARE(q_expr->state(), QDeclarativeDebugQuery::Waiting); + delete m_dbg; + QCOMPARE(q_expr->state(), QDeclarativeDebugQuery::Error); delete q_expr; + m_dbg = new QDeclarativeEngineDebug(m_conn, this); } void tst_QDeclarativeDebug::queryExpressionResult_data() -- cgit v0.12 From e442459e15100c2fcff0f101d8004213c2ce6960 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Wed, 30 Mar 2011 13:42:06 +0200 Subject: QDeclarativeDebug: Fix test case --- tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp b/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp index 4597ab4..d3c7032 100644 --- a/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp +++ b/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp @@ -1012,7 +1012,7 @@ void tst_QDeclarativeDebug::setBindingForObject() // set handler // rootObject = findRootObject(); - QCOMPARE(rootObject.children().size(), 3); + QCOMPARE(rootObject.children().size(), 4); // Rectangle, Text, MouseArea, QDeclarativeComponentAttached QDeclarativeDebugObjectReference mouseAreaObject = rootObject.children().at(2); QDeclarativeDebugObjectQuery *q_obj = m_dbg->queryObjectRecursive(mouseAreaObject, this); waitForQuery(q_obj); -- cgit v0.12 From 5d144faf3c524ab557b88f69c4b755e20237e846 Mon Sep 17 00:00:00 2001 From: mae Date: Tue, 26 Apr 2011 15:41:21 +0200 Subject: Fix insert and scroll to bottom case When using QtextCursor::insert() with a large text followed by setting the vertical scrollbar to its maximum value (scroll to bottom), QPlainTextEdit would not behave properly if a document size change was triggered by the insertion due to line wrapping. This was visible in Qt Creator. Auto test included. Reviewed-by: con --- src/gui/widgets/qplaintextedit.cpp | 5 +++++ tests/auto/qplaintextedit/tst_qplaintextedit.cpp | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/gui/widgets/qplaintextedit.cpp b/src/gui/widgets/qplaintextedit.cpp index 7435691..e7761a1 100644 --- a/src/gui/widgets/qplaintextedit.cpp +++ b/src/gui/widgets/qplaintextedit.cpp @@ -648,6 +648,11 @@ void QPlainTextEditPrivate::setTopBlock(int blockNumber, int lineNumber, int dx) } control->topBlock = blockNumber; topLine = lineNumber; + + bool vbarSignalsBlocked = vbar->blockSignals(true); + vbar->setValue(block.firstLineNumber() + lineNumber); + vbar->blockSignals(vbarSignalsBlocked); + if (dx || dy) viewport->scroll(q->isRightToLeft() ? -dx : dx, dy); else diff --git a/tests/auto/qplaintextedit/tst_qplaintextedit.cpp b/tests/auto/qplaintextedit/tst_qplaintextedit.cpp index d3e4fd0..8da5ba5 100644 --- a/tests/auto/qplaintextedit/tst_qplaintextedit.cpp +++ b/tests/auto/qplaintextedit/tst_qplaintextedit.cpp @@ -150,6 +150,7 @@ private slots: void lineWrapProperty(); void selectionChanged(); void blockCountChanged(); + void insertAndScrollToBottom(); private: void createSelection(); @@ -1504,5 +1505,22 @@ void tst_QPlainTextEdit::blockCountChanged() } +void tst_QPlainTextEdit::insertAndScrollToBottom() +{ + ed->setPlainText("First Line"); + ed->show(); + QString text; + for(int i = 0; i < 2000; ++i) { + text += QLatin1String("this is another line of text to be appended. It is quite long and will probably wrap around, meaning the number of lines is larger than the number of blocks in the text.\n"); + } + QTextCursor cursor = ed->textCursor(); + cursor.beginEditBlock(); + cursor.insertText(text); + cursor.endEditBlock(); + ed->verticalScrollBar()->setValue(ed->verticalScrollBar()->maximum()); + QCOMPARE(ed->verticalScrollBar()->value(), ed->verticalScrollBar()->maximum()); +} + + QTEST_MAIN(tst_QPlainTextEdit) #include "tst_qplaintextedit.moc" -- cgit v0.12 From f33b31dcc1b8fd35501ab5b441a4529e2f8570f3 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Mon, 2 May 2011 14:03:35 +0200 Subject: QmlViewer: Translate UI Install translators for the Qt & QmlViewer translations. also add QT_NO_CAST_FROM_ASCII, QT_NO_CAST_TO_ASCII to check for untranslated strings. Reviewed-by: Oswald Buddenhagen Task-number: QTBUG-14848 --- tools/qml/loggerwidget.cpp | 14 ++--- tools/qml/main.cpp | 91 +++++++++++++++++-------------- tools/qml/proxysettings.cpp | 36 ++++++------- tools/qml/proxysettings_maemo5.ui | 6 +-- tools/qml/qdeclarativetester.cpp | 10 ++-- tools/qml/qml.pro | 2 + tools/qml/qmlruntime.cpp | 109 +++++++++++++++++++------------------- translations/translations.pro | 1 + 8 files changed, 143 insertions(+), 126 deletions(-) diff --git a/tools/qml/loggerwidget.cpp b/tools/qml/loggerwidget.cpp index 3f2337a..9a07402 100644 --- a/tools/qml/loggerwidget.cpp +++ b/tools/qml/loggerwidget.cpp @@ -139,10 +139,10 @@ QAction *LoggerWidget::showAction() void LoggerWidget::readSettings() { QSettings settings; - QString warningsPreferences = settings.value("warnings", "hide").toString(); - if (warningsPreferences == "show") { + QString warningsPreferences = settings.value(QLatin1String("warnings"), QLatin1String("hide")).toString(); + if (warningsPreferences == QLatin1String("show")) { m_visibility = ShowWarnings; - } else if (warningsPreferences == "hide") { + } else if (warningsPreferences == QLatin1String("hide")) { m_visibility = HideWarnings; } else { m_visibility = AutoShowWarnings; @@ -154,15 +154,15 @@ void LoggerWidget::saveSettings() if (m_visibilityOrigin != SettingsOrigin) return; - QString value = "autoShow"; + QString value = QLatin1String("autoShow"); if (defaultVisibility() == ShowWarnings) { - value = "show"; + value = QLatin1String("show"); } else if (defaultVisibility() == HideWarnings) { - value = "hide"; + value = QLatin1String("hide"); } QSettings settings; - settings.setValue("warnings", value); + settings.setValue(QLatin1String("warnings"), value); } void LoggerWidget::warningsPreferenceChanged(QAction *action) diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index edd6b04..24a4940 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #include "qdeclarativetester.h" #include @@ -67,7 +68,7 @@ void exitApp(int i) // Debugging output is not visible by default on Windows - // therefore show modal dialog with errors instead. if (!warnings.isEmpty()) { - QMessageBox::warning(0, QApplication::tr("Qt QML Viewer"), warnings); + QMessageBox::warning(0, QApplication::translate("QDeclarativeViewer", "Qt QML Viewer"), warnings); } #endif exit(i); @@ -123,7 +124,7 @@ void myMessageOutput(QtMsgType type, const char *msg) static QDeclarativeViewer* globalViewer = 0; // The qml file that is shown if the user didn't specify a QML file -QString initialFile = "qrc:/startup/startup.qml"; +QString initialFile = QLatin1String("qrc:/startup/startup.qml"); void usage() { @@ -199,7 +200,7 @@ struct ViewerOptions fps(0.0), autorecord_from(0), autorecord_to(0), - dither("none"), + dither(QLatin1String("none")), runScript(false), devkeys(false), cache(0), @@ -336,54 +337,54 @@ static void parseCommandLineOptions(const QStringList &arguments) for (int i = 1; i < arguments.count(); ++i) { bool lastArg = (i == arguments.count() - 1); QString arg = arguments.at(i); - if (arg == "-frameless") { + if (arg == QLatin1String("-frameless")) { opts.frameless = true; - } else if (arg == "-maximized") { + } else if (arg == QLatin1String("-maximized")) { opts.maximized = true; - } else if (arg == "-fullscreen") { + } else if (arg == QLatin1String("-fullscreen")) { opts.fullScreen = true; - } else if (arg == "-stayontop") { + } else if (arg == QLatin1String("-stayontop")) { opts.stayOnTop = true; - } else if (arg == "-netcache") { + } else if (arg == QLatin1String("-netcache")) { if (lastArg) usage(); opts.cache = arguments.at(++i).toInt(); - } else if (arg == "-recordrate") { + } else if (arg == QLatin1String("-recordrate")) { if (lastArg) usage(); opts.fps = arguments.at(++i).toDouble(); - } else if (arg == "-recordfile") { + } else if (arg == QLatin1String("-recordfile")) { if (lastArg) usage(); opts.recordfile = arguments.at(++i); - } else if (arg == "-record") { + } else if (arg == QLatin1String("-record")) { if (lastArg) usage(); opts.recordargs << arguments.at(++i); - } else if (arg == "-recorddither") { + } else if (arg == QLatin1String("-recorddither")) { if (lastArg) usage(); opts.dither = arguments.at(++i); - } else if (arg == "-autorecord") { + } else if (arg == QLatin1String("-autorecord")) { if (lastArg) usage(); QString range = arguments.at(++i); - int dash = range.indexOf('-'); + int dash = range.indexOf(QLatin1Char('-')); if (dash > 0) opts.autorecord_from = range.left(dash).toInt(); opts.autorecord_to = range.mid(dash+1).toInt(); - } else if (arg == "-devicekeys") { + } else if (arg == QLatin1String("-devicekeys")) { opts.devkeys = true; - } else if (arg == "-dragthreshold") { + } else if (arg == QLatin1String("-dragthreshold")) { if (lastArg) usage(); qApp->setStartDragDistance(arguments.at(++i).toInt()); } else if (arg == QLatin1String("-v") || arg == QLatin1String("-version")) { qWarning("Qt QML Viewer version %s", QT_VERSION_STR); exitApp(0); - } else if (arg == "-translation") { + } else if (arg == QLatin1String("-translation")) { if (lastArg) usage(); opts.translationFile = arguments.at(++i); - } else if (arg == "-no-opengl") { + } else if (arg == QLatin1String("-no-opengl")) { opts.useGL = false; - } else if (arg == "-opengl") { + } else if (arg == QLatin1String("-opengl")) { opts.useGL = true; - } else if (arg == "-qmlbrowser") { + } else if (arg == QLatin1String("-qmlbrowser")) { opts.useNativeFileBrowser = false; - } else if (arg == "-warnings") { + } else if (arg == QLatin1String("-warnings")) { if (lastArg) usage(); QString warningsStr = arguments.at(++i); if (warningsStr == QLatin1String("show")) { @@ -393,8 +394,8 @@ static void parseCommandLineOptions(const QStringList &arguments) } else { usage(); } - } else if (arg == "-I" || arg == "-L") { - if (arg == "-L") + } else if (arg == QLatin1String("-I") || arg == QLatin1String("-L")) { + if (arg == QLatin1String("-L")) qWarning("-L option provided for compatibility only, use -I instead"); if (lastArg) { QDeclarativeEngine tmpEngine; @@ -403,32 +404,32 @@ static void parseCommandLineOptions(const QStringList &arguments) exitApp(0); } opts.imports << arguments.at(++i); - } else if (arg == "-P") { + } else if (arg == QLatin1String("-P")) { if (lastArg) usage(); opts.plugins << arguments.at(++i); - } else if (arg == "-script") { + } else if (arg == QLatin1String("-script")) { if (lastArg) usage(); opts.script = arguments.at(++i); - } else if (arg == "-scriptopts") { + } else if (arg == QLatin1String("-scriptopts")) { if (lastArg) usage(); opts.scriptopts = arguments.at(++i); - } else if (arg == "-savescript") { + } else if (arg == QLatin1String("-savescript")) { if (lastArg) usage(); opts.script = arguments.at(++i); opts.runScript = false; - } else if (arg == "-playscript") { + } else if (arg == QLatin1String("-playscript")) { if (lastArg) usage(); opts.script = arguments.at(++i); opts.runScript = true; - } else if (arg == "-sizeviewtorootobject") { + } else if (arg == QLatin1String("-sizeviewtorootobject")) { opts.sizeToView = false; - } else if (arg == "-sizerootobjecttoview") { + } else if (arg == QLatin1String("-sizerootobjecttoview")) { opts.sizeToView = true; - } else if (arg == "-experimentalgestures") { + } else if (arg == QLatin1String("-experimentalgestures")) { opts.experimentalGestures = true; - } else if (!arg.startsWith('-')) { + } else if (!arg.startsWith(QLatin1Char('-'))) { fileNames.append(arg); - } else if (true || arg == "-help") { + } else if (true || arg == QLatin1String("-help")) { usage(); } } @@ -527,29 +528,41 @@ int main(int argc, char ** argv) //### default to using raster graphics backend for now bool gsSpecified = false; for (int i = 0; i < argc; ++i) { - QString arg = argv[i]; - if (arg == "-graphicssystem") { + QString arg = QString::fromAscii(argv[i]); + if (arg == QLatin1String("-graphicssystem")) { gsSpecified = true; break; } } if (!gsSpecified) - QApplication::setGraphicsSystem("raster"); + QApplication::setGraphicsSystem(QLatin1String("raster")); #endif QDeclarativeDebugHelper::enableDebugging(); Application app(argc, argv); - app.setApplicationName("QtQmlViewer"); - app.setOrganizationName("Nokia"); - app.setOrganizationDomain("nokia.com"); + app.setApplicationName(QLatin1String("QtQmlViewer")); + app.setOrganizationName(QLatin1String("Nokia")); + app.setOrganizationDomain(QLatin1String("nokia.com")); QDeclarativeViewer::registerTypes(); QDeclarativeTester::registerTypes(); parseCommandLineOptions(app.arguments()); + QTranslator translator; + QTranslator qtTranslator; + QString sysLocale = QLocale::system().name(); + if (translator.load(QLatin1String("qmlviewer_") + sysLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) { + app.installTranslator(&translator); + if (qtTranslator.load(QLatin1String("qt_") + sysLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) { + app.installTranslator(&qtTranslator); + } else { + app.removeTranslator(&translator); + } + } + QTranslator qmlTranslator; if (!opts.translationFile.isEmpty()) { if (qmlTranslator.load(opts.translationFile)) { diff --git a/tools/qml/proxysettings.cpp b/tools/qml/proxysettings.cpp index c4dc087..78963da 100644 --- a/tools/qml/proxysettings.cpp +++ b/tools/qml/proxysettings.cpp @@ -54,17 +54,17 @@ ProxySettings::ProxySettings (QWidget * parent) #if !defined Q_WS_MAEMO_5 // the onscreen keyboard can't cope with masks - proxyServerEdit->setInputMask ("000.000.000.000;_"); + proxyServerEdit->setInputMask(QLatin1String("000.000.000.000;_")); #endif QIntValidator *validator = new QIntValidator (0, 9999, this); - proxyPortEdit->setValidator (validator); + proxyPortEdit->setValidator(validator); QSettings settings; - proxyCheckBox->setChecked (settings.value ("http_proxy/use", 0).toBool ()); - proxyServerEdit->insert (settings.value ("http_proxy/hostname", "").toString ()); - proxyPortEdit->insert (settings.value ("http_proxy/port", "80").toString ()); - usernameEdit->insert (settings.value ("http_proxy/username", "").toString ()); - passwordEdit->insert (settings.value ("http_proxy/password", "").toString ()); + proxyCheckBox->setChecked(settings.value(QLatin1String("http_proxy/use"), 0).toBool()); + proxyServerEdit->insert(settings.value(QLatin1String("http_proxy/hostname")).toString()); + proxyPortEdit->insert(settings.value(QLatin1String("http_proxy/port"), QLatin1String("80")).toString ()); + usernameEdit->insert(settings.value(QLatin1String("http_proxy/username")).toString ()); + passwordEdit->insert(settings.value(QLatin1String("http_proxy/password")).toString ()); } ProxySettings::~ProxySettings() @@ -75,11 +75,11 @@ void ProxySettings::accept () { QSettings settings; - settings.setValue ("http_proxy/use", proxyCheckBox->isChecked ()); - settings.setValue ("http_proxy/hostname", proxyServerEdit->text ()); - settings.setValue ("http_proxy/port", proxyPortEdit->text ()); - settings.setValue ("http_proxy/username", usernameEdit->text ()); - settings.setValue ("http_proxy/password", passwordEdit->text ()); + settings.setValue(QLatin1String("http_proxy/use"), proxyCheckBox->isChecked()); + settings.setValue(QLatin1String("http_proxy/hostname"), proxyServerEdit->text()); + settings.setValue(QLatin1String("http_proxy/port"), proxyPortEdit->text()); + settings.setValue(QLatin1String("http_proxy/username"), usernameEdit->text()); + settings.setValue(QLatin1String("http_proxy/password"), passwordEdit->text()); QDialog::accept (); } @@ -89,13 +89,13 @@ QNetworkProxy ProxySettings::httpProxy () QSettings settings; QNetworkProxy proxy; - bool proxyInUse = settings.value ("http_proxy/use", 0).toBool (); + bool proxyInUse = settings.value(QLatin1String("http_proxy/use"), 0).toBool(); if (proxyInUse) { proxy.setType (QNetworkProxy::HttpProxy); - proxy.setHostName (settings.value ("http_proxy/hostname", "").toString ());// "192.168.220.5" - proxy.setPort (settings.value ("http_proxy/port", 80).toInt ()); // 8080 - proxy.setUser (settings.value ("http_proxy/username", "").toString ()); - proxy.setPassword (settings.value ("http_proxy/password", "").toString ()); + proxy.setHostName (settings.value(QLatin1String("http_proxy/hostname")).toString());// "192.168.220.5" + proxy.setPort (settings.value(QLatin1String("http_proxy/port"), 80).toInt()); // 8080 + proxy.setUser (settings.value(QLatin1String("http_proxy/username")).toString()); + proxy.setPassword (settings.value(QLatin1String("http_proxy/password")).toString()); //QNetworkProxy::setApplicationProxy (proxy); } else { @@ -107,7 +107,7 @@ QNetworkProxy ProxySettings::httpProxy () bool ProxySettings::httpProxyInUse() { QSettings settings; - return settings.value ("http_proxy/use", 0).toBool (); + return settings.value(QLatin1String("http_proxy/use"), 0).toBool(); } QT_END_NAMESPACE diff --git a/tools/qml/proxysettings_maemo5.ui b/tools/qml/proxysettings_maemo5.ui index 83f0c2a..75875d8 100644 --- a/tools/qml/proxysettings_maemo5.ui +++ b/tools/qml/proxysettings_maemo5.ui @@ -6,8 +6,8 @@ 0 0 - 449 - 164 + 447 + 162 @@ -88,7 +88,7 @@ - 8080 + 8080 diff --git a/tools/qml/qdeclarativetester.cpp b/tools/qml/qdeclarativetester.cpp index 11f81fc..fa8af8f 100644 --- a/tools/qml/qdeclarativetester.cpp +++ b/tools/qml/qdeclarativetester.cpp @@ -205,7 +205,7 @@ void QDeclarativeTester::save() QString filename = m_script + QLatin1String(".qml"); QFileInfo filenameInfo(filename); QDir saveDir = filenameInfo.absoluteDir(); - saveDir.mkpath("."); + saveDir.mkpath(QLatin1String(".")); QFile file(filename); file.open(QIODevice::WriteOnly); @@ -224,8 +224,8 @@ void QDeclarativeTester::save() if (!fe.hash.isEmpty()) { ts << " hash: \"" << fe.hash.toHex() << "\"\n"; } else if (!fe.image.isNull()) { - QString filename = filenameInfo.baseName() + "." + QString::number(imgCount) + ".png"; - fe.image.save(m_script + "." + QString::number(imgCount) + ".png"); + QString filename = filenameInfo.baseName() + QLatin1String(".") + QString::number(imgCount) + QLatin1String(".png"); + fe.image.save(m_script + QLatin1String(".") + QString::number(imgCount) + QLatin1String(".png")); imgCount++; ts << " image: \"" << filename << "\"\n"; } @@ -375,7 +375,7 @@ void QDeclarativeTester::updateCurrentTime(int msec) imagefailure(); } if (goodImage != img) { - QString reject(frame->image().toLocalFile() + ".reject.png"); + QString reject(frame->image().toLocalFile() + QLatin1String(".reject.png")); qWarning() << "QDeclarativeTester(" << m_script << "): Image mismatch. Reject saved to:" << reject; img.save(reject); @@ -393,7 +393,7 @@ void QDeclarativeTester::updateCurrentTime(int msec) } } } - QString diff(frame->image().toLocalFile() + ".diff.png"); + QString diff(frame->image().toLocalFile() + QLatin1String(".diff.png")); diffimg.save(diff); qWarning().nospace() << " Diff (" << diffCount << " pixels differed) saved to: " << diff; } diff --git a/tools/qml/qml.pro b/tools/qml/qml.pro index b1d56ea..9467b70 100644 --- a/tools/qml/qml.pro +++ b/tools/qml/qml.pro @@ -10,6 +10,8 @@ INCLUDEPATH += ../../include/QtDeclarative INCLUDEPATH += ../../src/declarative/util INCLUDEPATH += ../../src/declarative/graphicsitems +DEFINES += QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII + target.path = $$[QT_INSTALL_BINS] INSTALLS += target diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index 36915d1..7422032 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -265,7 +265,7 @@ public: hz->setValidator(new QDoubleValidator(hz)); #endif for (int i=0; ffmpegprofiles[i].name; ++i) { - profile->addItem(ffmpegprofiles[i].name); + profile->addItem(QString::fromAscii(ffmpegprofiles[i].name)); } } @@ -273,9 +273,9 @@ public: { int i; for (i=0; ffmpegprofiles[i].args[0]; ++i) { - if (ffmpegprofiles[i].args == a) { + if (QString::fromAscii(ffmpegprofiles[i].args) == a) { profile->setCurrentIndex(i); - args->setText(QLatin1String(ffmpegprofiles[i].args)); + args->setText(QString::fromAscii(ffmpegprofiles[i].args)); return; } } @@ -465,14 +465,14 @@ private: } } QSettings settings; - settings.setValue("Cookies",data); + settings.setValue(QLatin1String("Cookies"), data); } void load() { QMutexLocker lock(&mutex); QSettings settings; - QByteArray data = settings.value("Cookies").toByteArray(); + QByteArray data = settings.value(QLatin1String("Cookies")).toByteArray(); setAllCookies(QNetworkCookie::parseCookies(data)); } @@ -490,7 +490,7 @@ public: if (proxyDirty) setupProxy(); QString protocolTag = query.protocolTag(); - if (httpProxyInUse && (protocolTag == "http" || protocolTag == "https")) { + if (httpProxyInUse && (protocolTag == QLatin1String("http") || protocolTag == QLatin1String("https"))) { QList ret; ret << httpProxy; return ret; @@ -597,7 +597,7 @@ QString QDeclarativeViewer::getVideoFileName() if (convertAvailable) types += tr("GIF Animation")+QLatin1String(" (*.gif)"); types += tr("Individual PNG frames")+QLatin1String(" (*.png)"); if (ffmpegAvailable) types += tr("All ffmpeg formats (*.*)"); - return QFileDialog::getSaveFileName(this, title, "", types.join(";; ")); + return QFileDialog::getSaveFileName(this, title, QString(), types.join(QLatin1String(";; "))); } QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) @@ -725,18 +725,18 @@ void QDeclarativeViewer::createMenu() connect(reloadAction, SIGNAL(triggered()), this, SLOT(reload())); QAction *snapshotAction = new QAction(tr("&Take Snapshot"), this); - snapshotAction->setShortcut(QKeySequence("F3")); + snapshotAction->setShortcut(QKeySequence(tr("F3"))); connect(snapshotAction, SIGNAL(triggered()), this, SLOT(takeSnapShot())); recordAction = new QAction(tr("Start Recording &Video"), this); - recordAction->setShortcut(QKeySequence("F9")); + recordAction->setShortcut(QKeySequence(tr("F9"))); connect(recordAction, SIGNAL(triggered()), this, SLOT(toggleRecordingWithSelection())); QAction *recordOptions = new QAction(tr("Video &Options..."), this); connect(recordOptions, SIGNAL(triggered()), this, SLOT(chooseRecordingOptions())); QAction *slowAction = new QAction(tr("&Slow Down Animations"), this); - slowAction->setShortcut(QKeySequence("Ctrl+.")); + slowAction->setShortcut(QKeySequence(tr("Ctrl+."))); slowAction->setCheckable(true); connect(slowAction, SIGNAL(triggered(bool)), this, SLOT(setSlowMode(bool))); @@ -755,7 +755,7 @@ void QDeclarativeViewer::createMenu() connect(fullscreenAction, SIGNAL(triggered()), this, SLOT(toggleFullScreen())); rotateAction = new QAction(tr("Rotate orientation"), this); - rotateAction->setShortcut(QKeySequence("Ctrl+T")); + rotateAction->setShortcut(QKeySequence(tr("Ctrl+T"))); connect(rotateAction, SIGNAL(triggered()), this, SLOT(rotateOrientation())); orientation = new QActionGroup(this); @@ -963,7 +963,7 @@ void QDeclarativeViewer::chooseRecordingOptions() // Profile - recdlg->setArguments(record_args.join(" ")); + recdlg->setArguments(record_args.join(QLatin1String(" "))); if (recdlg->exec()) { // File record_file = recdlg->file->text(); @@ -972,7 +972,7 @@ void QDeclarativeViewer::chooseRecordingOptions() // Rate record_rate = recdlg->videoRate(); // Profile - record_args = recdlg->arguments().split(" ",QString::SkipEmptyParts); + record_args = recdlg->arguments().split(QLatin1Char(' '),QString::SkipEmptyParts); } } @@ -983,8 +983,8 @@ void QDeclarativeViewer::toggleRecordingWithSelection() QString fileName = getVideoFileName(); if (fileName.isEmpty()) return; - if (!fileName.contains(QRegExp(".[^\\/]*$"))) - fileName += ".avi"; + if (!fileName.contains(QRegExp(QLatin1String(".[^\\/]*$")))) + fileName += QLatin1String(".avi"); setRecordFile(fileName); } } @@ -1026,7 +1026,7 @@ void QDeclarativeViewer::openFile() { QString cur = canvas->source().toLocalFile(); if (useQmlFileBrowser) { - open("qrc:/browser/Browser.qml"); + open(QLatin1String("qrc:/browser/Browser.qml")); } else { QString fileName = QFileDialog::getOpenFileName(this, tr("Open QML file"), cur, tr("QML Files (*.qml)")); if (!fileName.isEmpty()) { @@ -1072,7 +1072,7 @@ void QDeclarativeViewer::loadTranslationFile(const QString& directory) void QDeclarativeViewer::loadDummyDataFiles(const QString& directory) { - QDir dir(directory+"/dummydata", "*.qml"); + QDir dir(directory + QLatin1String("/dummydata"), QLatin1String("*.qml")); QStringList list = dir.entryList(); for (int i = 0; i < list.size(); ++i) { QString qml = list.at(i); @@ -1114,14 +1114,14 @@ bool QDeclarativeViewer::open(const QString& file_or_url) delete canvas->rootObject(); canvas->engine()->clearComponentCache(); QDeclarativeContext *ctxt = canvas->rootContext(); - ctxt->setContextProperty("qmlViewer", this); + ctxt->setContextProperty(QLatin1String("qmlViewer"), this); #ifdef Q_OS_SYMBIAN - ctxt->setContextProperty("qmlViewerFolder", "E:\\"); // Documents on your S60 phone + ctxt->setContextProperty(QLatin1String("qmlViewerFolder"), QLatin1String("E:\\")); // Documents on your S60 phone #else - ctxt->setContextProperty("qmlViewerFolder", QDir::currentPath()); + ctxt->setContextProperty(QLatin1String("qmlViewerFolder"), QDir::currentPath()); #endif - ctxt->setContextProperty("runtime", Runtime::instance()); + ctxt->setContextProperty(QLatin1String("runtime"), Runtime::instance()); QString fileName = url.toLocalFile(); if (!fileName.isEmpty()) { @@ -1224,26 +1224,26 @@ bool QDeclarativeViewer::event(QEvent *event) void QDeclarativeViewer::senseImageMagick() { QProcess proc; - proc.start("convert", QStringList() << "-h"); + proc.start(QLatin1String("convert"), QStringList() << QLatin1String("-h")); proc.waitForFinished(2000); - QString help = proc.readAllStandardOutput(); - convertAvailable = help.contains("ImageMagick"); + QString help = QString::fromAscii(proc.readAllStandardOutput()); + convertAvailable = help.contains(QLatin1String("ImageMagick")); } void QDeclarativeViewer::senseFfmpeg() { QProcess proc; - proc.start("ffmpeg", QStringList() << "-h"); + proc.start(QLatin1String("ffmpeg"), QStringList() << QLatin1String("-h")); proc.waitForFinished(2000); - QString ffmpegHelp = proc.readAllStandardOutput(); - ffmpegAvailable = ffmpegHelp.contains("-s "); - ffmpegHelp = tr("Video recording uses ffmpeg:")+"\n\n"+ffmpegHelp; + QString ffmpegHelp = QString::fromAscii(proc.readAllStandardOutput()); + ffmpegAvailable = ffmpegHelp.contains(QLatin1String("-s ")); + ffmpegHelp = tr("Video recording uses ffmpeg:") + QLatin1String("\n\n") + ffmpegHelp; QDialog *d = new QDialog(recdlg); QVBoxLayout *l = new QVBoxLayout(d); QTextBrowser *b = new QTextBrowser(d); QFont f = b->font(); - f.setFamily("courier"); + f.setFamily(QLatin1String("courier")); b->setFont(f); b->setText(ffmpegHelp); l->addWidget(b); @@ -1266,7 +1266,7 @@ void QDeclarativeViewer::setRecording(bool on) recordTimer.start(); frame_fmt = record_file.right(4).toLower(); frame = QImage(canvas->width(),canvas->height(),QImage::Format_RGB32); - if (frame_fmt != ".png" && (!convertAvailable || frame_fmt != ".gif")) { + if (frame_fmt != QLatin1String(".png") && (!convertAvailable || frame_fmt != QLatin1String(".gif"))) { // Stream video to ffmpeg QProcess *proc = new QProcess(this); @@ -1274,19 +1274,19 @@ void QDeclarativeViewer::setRecording(bool on) frame_stream = proc; QStringList args; - args << "-y"; - args << "-r" << QString::number(record_rate); - args << "-f" << "rawvideo"; - args << "-pix_fmt" << (frame_fmt == ".gif" ? "rgb24" : "rgb32"); - args << "-s" << QString("%1x%2").arg(canvas->width()).arg(canvas->height()); - args << "-i" << "-"; + args << QLatin1String("-y"); + args << QLatin1String("-r") << QString::number(record_rate); + args << QLatin1String("-f") << QLatin1String("rawvideo"); + args << QLatin1String("-pix_fmt") << (frame_fmt == QLatin1String(".gif") ? QLatin1String("rgb24") : QLatin1String("rgb32")); + args << QLatin1String("-s") << QString::fromAscii("%1x%2").arg(canvas->width()).arg(canvas->height()); + args << QLatin1String("-i") << QLatin1String("-"); if (record_outsize.isValid()) { - args << "-s" << QString("%1x%2").arg(record_outsize.width()).arg(record_outsize.height()); - args << "-aspect" << QString::number(double(canvas->width())/canvas->height()); + args << QLatin1String("-s") << QString::fromAscii("%1x%2").arg(record_outsize.width()).arg(record_outsize.height()); + args << QLatin1String("-aspect") << QString::number(double(canvas->width())/canvas->height()); } args += record_args; args << record_file; - proc->start("ffmpeg",args); + proc->start(QLatin1String("ffmpeg"), args); } else { // Store frames, save to GIF/PNG @@ -1309,14 +1309,14 @@ void QDeclarativeViewer::setRecording(bool on) QString framename; bool png_output = false; - if (record_file.right(4).toLower()==".png") { - if (record_file.contains('%')) + if (record_file.right(4).toLower() == QLatin1String(".png")) { + if (record_file.contains(QLatin1Char('%'))) framename = record_file; else - framename = record_file.left(record_file.length()-4)+"%04d"+record_file.right(4); + framename = record_file.left(record_file.length()-4) + QLatin1String("%04d") + record_file.right(4); png_output = true; } else { - framename = "tmp-frame%04d.png"; + framename = QLatin1String("tmp-frame%04d.png"); png_output = false; } foreach (QImage* img, frames) { @@ -1327,11 +1327,11 @@ void QDeclarativeViewer::setRecording(bool on) name.sprintf(framename.toLocal8Bit(),frame++); if (record_outsize.isValid()) *img = img->scaled(record_outsize,Qt::IgnoreAspectRatio,Qt::SmoothTransformation); - if (record_dither=="ordered") + if (record_dither==QLatin1String("ordered")) img->convertToFormat(QImage::Format_Indexed8,Qt::PreferDither|Qt::OrderedDither).save(name); - else if (record_dither=="threshold") + else if (record_dither==QLatin1String("threshold")) img->convertToFormat(QImage::Format_Indexed8,Qt::PreferDither|Qt::ThresholdDither).save(name); - else if (record_dither=="floyd") + else if (record_dither==QLatin1String("floyd")) img->convertToFormat(QImage::Format_Indexed8,Qt::PreferDither).save(name); else img->save(name); @@ -1341,25 +1341,26 @@ void QDeclarativeViewer::setRecording(bool on) if (!progress.wasCanceled()) { if (png_output) { - framename.replace(QRegExp("%\\d*."),"*"); + framename.replace(QRegExp(QLatin1String("%\\d*.")), QLatin1String("*")); qDebug() << "Wrote frames" << framename; inputs.clear(); // don't remove them } else { // ImageMagick and gifsicle for GIF encoding progress.setLabelText(tr("Converting frames to GIF file...")); QStringList args; - args << "-delay" << QString::number(period/10); + args << QLatin1String("-delay") << QString::number(period/10); args << inputs; args << record_file; qDebug() << "Converting..." << record_file << "(this may take a while)"; - if (0!=QProcess::execute("convert", args)) { + if (0!=QProcess::execute(QLatin1String("convert"), args)) { qWarning() << "Cannot run ImageMagick 'convert' - recorded frames not converted"; inputs.clear(); // don't remove them qDebug() << "Wrote frames tmp-frame*.png"; } else { - if (record_file.right(4).toLower() == ".gif") { + if (record_file.right(4).toLower() == QLatin1String(".gif")) { qDebug() << "Compressing..." << record_file; - if (0!=QProcess::execute("gifsicle", QStringList() << "-O2" << "-o" << record_file << record_file)) + if (0!=QProcess::execute(QLatin1String("gifsicle"), QStringList() << QLatin1String("-O2") + << QLatin1String("-o") << record_file << record_file)) qWarning() << "Cannot run 'gifsicle' - not compressed"; } qDebug() << "Wrote" << record_file; @@ -1410,7 +1411,7 @@ void QDeclarativeViewer::recordFrame() { canvas->QWidget::render(&frame); if (frame_stream) { - if (frame_fmt == ".gif") { + if (frame_fmt == QLatin1String(".gif")) { // ffmpeg can't do 32bpp with gif QImage rgb24 = frame.convertToFormat(QImage::Format_RGB888); frame_stream->write((char*)rgb24.bits(),rgb24.numBytes()); @@ -1541,8 +1542,8 @@ void QDeclarativeViewer::registerTypes() if (!registered) { // registering only for exposing the DeviceOrientation::Orientation enum - qmlRegisterUncreatableType("Qt",4,7,"Orientation",""); - qmlRegisterUncreatableType("QtQuick",1,0,"Orientation",""); + qmlRegisterUncreatableType("Qt", 4, 7, "Orientation", QString()); + qmlRegisterUncreatableType("QtQuick", 1, 0, "Orientation", QString()); registered = true; } } diff --git a/translations/translations.pro b/translations/translations.pro index 311b032..dc99beb 100644 --- a/translations/translations.pro +++ b/translations/translations.pro @@ -55,6 +55,7 @@ addTsTargets(assistant, ../tools/assistant/tools/tools.pro) addTsTargets(qt_help, ../tools/assistant/lib/lib.pro) addTsTargets(qtconfig, ../tools/qtconfig/qtconfig.pro) addTsTargets(qvfb, ../tools/qvfb/qvfb.pro) +addTsTargets(qmlviewer, ../tools/qml/qml.pro) check-ts.commands = (cd $$PWD && perl check-ts.pl) check-ts.depends = ts-all -- cgit v0.12