summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2009-11-23 23:17:06 (GMT)
committerMartin Jones <martin.jones@nokia.com>2009-11-23 23:17:06 (GMT)
commit31540e4b5177073d71b98e296ad7d59faf63b383 (patch)
tree6eaf3e50b1a351171db3d47b8e39e0ee7478bc54 /src/declarative/qml
parent7d93b0762aff8bcd9cb22f12ebc88beb242f2a97 (diff)
parent8d263b7cbf6b0bd17deeb8b56c90e0232057b832 (diff)
downloadQt-31540e4b5177073d71b98e296ad7d59faf63b383.zip
Qt-31540e4b5177073d71b98e296ad7d59faf63b383.tar.gz
Qt-31540e4b5177073d71b98e296ad7d59faf63b383.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/declarative/qml')
-rw-r--r--src/declarative/qml/parser/qmljsast_p.h2
-rw-r--r--src/declarative/qml/qmlengine.cpp27
-rw-r--r--src/declarative/qml/qmlengine_p.h1
-rw-r--r--src/declarative/qml/qmlsqldatabase.cpp148
4 files changed, 59 insertions, 119 deletions
diff --git a/src/declarative/qml/parser/qmljsast_p.h b/src/declarative/qml/parser/qmljsast_p.h
index b5f7264..388bc12 100644
--- a/src/declarative/qml/parser/qmljsast_p.h
+++ b/src/declarative/qml/parser/qmljsast_p.h
@@ -2653,7 +2653,7 @@ public:
{ kind = K; }
virtual SourceLocation firstSourceLocation() const
- { return lbracketToken; }
+ { return qualifiedId->identifierToken; }
virtual SourceLocation lastSourceLocation() const
{ return rbracketToken; }
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index e292e5c..0a00092 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -145,6 +145,12 @@ QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e)
qtObject.setProperty(QLatin1String("openUrlExternally"),scriptEngine.newFunction(desktopOpenUrl, 1));
qtObject.setProperty(QLatin1String("md5"),scriptEngine.newFunction(md5, 1));
+ //firebug/webkit compat
+ QScriptValue consoleObject = scriptEngine.newObject();
+ consoleObject.setProperty(QLatin1String("log"),scriptEngine.newFunction(consoleLog, 1));
+ consoleObject.setProperty(QLatin1String("debug"),scriptEngine.newFunction(consoleLog, 1));
+ scriptEngine.globalObject().setProperty(QLatin1String("console"), consoleObject);
+
scriptEngine.globalObject().setProperty(QLatin1String("createQmlObject"),
scriptEngine.newFunction(QmlEnginePrivate::createQmlObject, 1));
scriptEngine.globalObject().setProperty(QLatin1String("createComponent"),
@@ -800,7 +806,7 @@ QScriptValue QmlEnginePrivate::desktopOpenUrl(QScriptContext *ctxt, QScriptEngin
return e->newVariant(QVariant(ret));
}
-QScriptValue QmlEnginePrivate::md5(QScriptContext *ctxt, QScriptEngine *e)
+QScriptValue QmlEnginePrivate::md5(QScriptContext *ctxt, QScriptEngine *)
{
QByteArray data;
@@ -812,6 +818,25 @@ QScriptValue QmlEnginePrivate::md5(QScriptContext *ctxt, QScriptEngine *e)
return QScriptValue(QLatin1String(result.toHex()));
}
+QScriptValue QmlEnginePrivate::consoleLog(QScriptContext *ctxt, QScriptEngine *e)
+{
+ if(ctxt->argumentCount() < 1)
+ return e->newVariant(QVariant(false));
+
+ QByteArray msg;
+
+ for (int i=0; i<ctxt->argumentCount(); ++i) {
+ if (!msg.isEmpty()) msg += ' ';
+ msg += ctxt->argument(i).toString().toLocal8Bit();
+ // does not support firebug "%[a-z]" formatting, since firebug really
+ // does just ignore the format letter, which makes it pointless.
+ }
+
+ qDebug("%s",msg.data());
+
+ return e->newVariant(QVariant(true));
+}
+
QScriptValue QmlEnginePrivate::closestAngle(QScriptContext *ctxt, QScriptEngine *e)
{
if(ctxt->argumentCount() < 2)
diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h
index 2f41651..c11a399 100644
--- a/src/declarative/qml/qmlengine_p.h
+++ b/src/declarative/qml/qmlengine_p.h
@@ -269,6 +269,7 @@ public:
static QScriptValue playSound(QScriptContext*, QScriptEngine*);
static QScriptValue desktopOpenUrl(QScriptContext*, QScriptEngine*);
static QScriptValue md5(QScriptContext*, QScriptEngine*);
+ static QScriptValue consoleLog(QScriptContext*, QScriptEngine*);
static QScriptEngine *getScriptEngine(QmlEngine *e) { return &e->d_func()->scriptEngine; }
static QmlEngine *getEngine(QScriptEngine *e) { return static_cast<QmlScriptEngine*>(e)->p->q_func(); }
diff --git a/src/declarative/qml/qmlsqldatabase.cpp b/src/declarative/qml/qmlsqldatabase.cpp
index 9e4c198..d11e3cb 100644
--- a/src/declarative/qml/qmlsqldatabase.cpp
+++ b/src/declarative/qml/qmlsqldatabase.cpp
@@ -63,8 +63,6 @@
Q_DECLARE_METATYPE(QSqlDatabase)
Q_DECLARE_METATYPE(QSqlQuery)
-class QmlSqlQueryScriptClassPropertyIterator;
-
class QmlSqlQueryScriptClass: public QScriptClass {
public:
QmlSqlQueryScriptClass(QScriptEngine *engine) : QScriptClass(engine)
@@ -75,22 +73,13 @@ public:
QueryFlags queryProperty(const QScriptValue &object,
const QScriptString &name,
- QueryFlags flags, uint *id)
+ QueryFlags flags, uint *)
{
if (flags & HandlesReadAccess) {
if (name == str_length) {
return HandlesReadAccess;
} else if (name == str_forwardOnly) {
return flags;
- } else {
- bool ok;
- qint32 pos = name.toString().toInt(&ok);
- if (pos < 0 || !ok)
- return 0;
- QSqlQuery query = qscriptvalue_cast<QSqlQuery>(object.data());
- *id = pos;
- if (*id < (uint)query.size())
- return HandlesReadAccess;
}
}
if (flags & HandlesWriteAccess)
@@ -100,29 +89,23 @@ public:
}
QScriptValue property(const QScriptValue &object,
- const QScriptString &name, uint id)
+ const QScriptString &name, uint)
{
QSqlQuery query = qscriptvalue_cast<QSqlQuery>(object.data());
if (name == str_length) {
int s = query.size();
if (s<0) {
// Inefficient.
- query.last();
- return query.at()+1;
+ if (query.last()) {
+ return query.at()+1;
+ } else {
+ return 0;
+ }
} else {
return s;
}
} else if (name == str_forwardOnly) {
return query.isForwardOnly();
- } else {
- if ((uint)query.at() == id || query.seek(id)) { // Qt 4.6 doesn't optimize seek(at())
- QSqlRecord r = query.record();
- QScriptValue row = engine()->newObject();
- for (int j=0; j<r.count(); ++j) {
- row.setProperty(r.fieldName(j), QScriptValue(engine(),r.value(j).toString()));
- }
- return row;
- }
}
return engine()->undefinedValue();
}
@@ -145,81 +128,15 @@ public:
return QScriptValue::Undeletable;
}
- QScriptClassPropertyIterator *newIterator(const QScriptValue &object);
-
private:
QScriptString str_length;
QScriptString str_forwardOnly;
};
-class QmlSqlQueryScriptClassPropertyIterator : public QScriptClassPropertyIterator
-{
-public:
- QmlSqlQueryScriptClassPropertyIterator(const QScriptValue &object)
- : QScriptClassPropertyIterator(object)
- {
- toFront();
- }
+// If the spec changes to allow iteration, check git history...
+// class QmlSqlQueryScriptClassPropertyIterator : public QScriptClassPropertyIterator
- ~QmlSqlQueryScriptClassPropertyIterator()
- {
- }
-
- bool hasNext() const
- {
- QSqlQuery query = qscriptvalue_cast<QSqlQuery>(object().data());
- return query.at() == m_index || query.seek(m_index); // Qt 4.6 doesn't optimize seek(at())
- }
- void next()
- {
- m_last = m_index;
- ++m_index;
- }
-
- bool hasPrevious() const
- {
- return (m_index > 0);
- }
-
- void previous()
- {
- --m_index;
- m_last = m_index;
- }
-
- void toFront()
- {
- m_index = 0;
- m_last = -1;
- }
-
- void toBack()
- {
- QSqlQuery query = qscriptvalue_cast<QSqlQuery>(object().data());
- m_index = query.size();
- m_last = -1;
- }
-
- QScriptString name() const
- {
- return object().engine()->toStringHandle(QString::number(m_last));
- }
-
- uint id() const
- {
- return m_last;
- }
-
-private:
- int m_index;
- int m_last;
-};
-
-QScriptClassPropertyIterator *QmlSqlQueryScriptClass::newIterator(const QScriptValue &object)
-{
- return new QmlSqlQueryScriptClassPropertyIterator(object);
-}
enum SqlException {
UNKNOWN_ERR,
@@ -323,11 +240,10 @@ static QScriptValue qmlsqldatabase_executeSql_readonly(QScriptContext *context,
{
QString sql = context->argument(0).toString();
if (sql.startsWith(QLatin1String("SELECT"),Qt::CaseInsensitive)) {
- qmlsqldatabase_executeSql(context,engine);
+ return qmlsqldatabase_executeSql(context,engine);
} else {
THROW_SQL(SYNTAX_ERR,QmlEngine::tr("Read-only Transaction"))
}
- return engine->undefinedValue();
}
static QScriptValue qmlsqldatabase_change_version(QScriptContext *context, QScriptEngine *engine)
@@ -349,7 +265,9 @@ static QScriptValue qmlsqldatabase_change_version(QScriptContext *context, QScri
return engine->undefinedValue();
}
+ bool ok = true;
if (callback.isFunction()) {
+ ok = false;
db.transaction();
callback.call(QScriptValue(), QScriptValueList() << tx);
if (engine->hasUncaughtException()) {
@@ -359,17 +277,21 @@ static QScriptValue qmlsqldatabase_change_version(QScriptContext *context, QScri
db.rollback();
THROW_SQL(0,QmlEngine::tr("SQL transaction failed"));
} else {
- context->thisObject().setProperty(QLatin1String("version"), to_version, QScriptValue::ReadOnly);
- QSettings ini(databaseFile(db.connectionName(),engine)+QLatin1String(".ini"),QSettings::IniFormat);
- ini.setValue(QLatin1String("Version"), to_version);
+ ok = true;
}
}
}
+ if (ok) {
+ context->thisObject().setProperty(QLatin1String("version"), to_version, QScriptValue::ReadOnly);
+ QSettings ini(databaseFile(db.connectionName(),engine)+QLatin1String(".ini"),QSettings::IniFormat);
+ ini.setValue(QLatin1String("Version"), to_version);
+ }
+
return engine->undefinedValue();
}
-static QScriptValue qmlsqldatabase_transaction(QScriptContext *context, QScriptEngine *engine)
+static QScriptValue qmlsqldatabase_transaction_shared(QScriptContext *context, QScriptEngine *engine, bool readOnly)
{
QSqlDatabase db = qscriptvalue_cast<QSqlDatabase>(context->thisObject());
QScriptValue callback = context->argument(0);
@@ -377,7 +299,8 @@ static QScriptValue qmlsqldatabase_transaction(QScriptContext *context, QScriptE
THROW_SQL(UNKNOWN_ERR,QmlEngine::tr("transaction: missing callback"));
QScriptValue instance = engine->newObject();
- instance.setProperty(QLatin1String("executeSql"), engine->newFunction(qmlsqldatabase_executeSql,1));
+ instance.setProperty(QLatin1String("executeSql"),
+ engine->newFunction(readOnly ? qmlsqldatabase_executeSql_readonly : qmlsqldatabase_executeSql,1));
QScriptValue tx = engine->newVariant(instance,qVariantFromValue(db));
db.transaction();
@@ -391,26 +314,13 @@ static QScriptValue qmlsqldatabase_transaction(QScriptContext *context, QScriptE
return engine->undefinedValue();
}
+static QScriptValue qmlsqldatabase_transaction(QScriptContext *context, QScriptEngine *engine)
+{
+ return qmlsqldatabase_transaction_shared(context,engine,false);
+}
static QScriptValue qmlsqldatabase_read_transaction(QScriptContext *context, QScriptEngine *engine)
{
- QSqlDatabase db = qscriptvalue_cast<QSqlDatabase>(context->thisObject());
- QScriptValue callback = context->argument(0);
- if (!callback.isFunction())
- return engine->undefinedValue();
-
- QScriptValue instance = engine->newObject();
- instance.setProperty(QLatin1String("executeSql"), engine->newFunction(qmlsqldatabase_executeSql_readonly,1));
- QScriptValue tx = engine->newVariant(instance,qVariantFromValue(db));
-
- db.transaction();
- callback.call(QScriptValue(), QScriptValueList() << tx);
- if (engine->hasUncaughtException()) {
- db.rollback();
- } else {
- if (!db.commit())
- db.rollback();
- }
- return engine->undefinedValue();
+ return qmlsqldatabase_transaction_shared(context,engine,true);
}
/*
@@ -439,6 +349,9 @@ static QScriptValue qmlsqldatabase_open_sync(QScriptContext *context, QScriptEng
if (QSqlDatabase::connectionNames().contains(dbid)) {
database = QSqlDatabase::database(dbid);
+ version = ini.value(QLatin1String("Version")).toString();
+ if (version != dbversion && !dbversion.isEmpty() && !version.isEmpty())
+ THROW_SQL(VERSION_ERR,QmlEngine::tr("SQL: database version mismatch"));
} else {
created = !QFile::exists(basename+QLatin1String(".sqlite"));
database = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"), dbid);
@@ -456,6 +369,7 @@ static QScriptValue qmlsqldatabase_open_sync(QScriptContext *context, QScriptEng
// Incompatible
THROW_SQL(VERSION_ERR,QmlEngine::tr("SQL: database version mismatch"));
}
+ version = ini.value("Version").toString();
}
database.setDatabaseName(basename+QLatin1String(".sqlite"));
}