summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-09-25 02:04:55 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-09-25 02:04:55 (GMT)
commit7b94225ae26abcca8f2e8706cee8ed4843f5a53b (patch)
tree9b8ffb070a498ab1ef8586e31e6d92eac1e3b6de /src
parenta7ee91c6db7dfeb38769c4828f5db926fbd37330 (diff)
parent6a297d3626c1779047812965a12f32e143e63b7d (diff)
downloadQt-7b94225ae26abcca8f2e8706cee8ed4843f5a53b.zip
Qt-7b94225ae26abcca8f2e8706cee8ed4843f5a53b.tar.gz
Qt-7b94225ae26abcca8f2e8706cee8ed4843f5a53b.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src')
-rw-r--r--src/declarative/fx/qfxtextedit.cpp1
-rw-r--r--src/declarative/qml/qmlsqldatabase.cpp118
-rw-r--r--src/declarative/util/qmlview.cpp2
-rw-r--r--src/src.pro1
4 files changed, 116 insertions, 6 deletions
diff --git a/src/declarative/fx/qfxtextedit.cpp b/src/declarative/fx/qfxtextedit.cpp
index ce06348..935ccb7 100644
--- a/src/declarative/fx/qfxtextedit.cpp
+++ b/src/declarative/fx/qfxtextedit.cpp
@@ -1053,6 +1053,7 @@ void QFxTextEdit::updateSize()
newWidth += cursorWidth;
if(!d->document->isEmpty())
newWidth += 3;// ### Need a better way of accounting for space between char and cursor
+ // ### Setting the implicitWidth triggers another updateSize(), and unless there are bindings nothing has changed.
setImplicitWidth(newWidth);
setImplicitHeight(d->text.isEmpty() ? fm.height() : (int)d->document->size().height());
diff --git a/src/declarative/qml/qmlsqldatabase.cpp b/src/declarative/qml/qmlsqldatabase.cpp
index 5869a56..b132c55 100644
--- a/src/declarative/qml/qmlsqldatabase.cpp
+++ b/src/declarative/qml/qmlsqldatabase.cpp
@@ -46,6 +46,7 @@
#include <QtScript/qscriptvalueiterator.h>
#include <QtScript/qscriptcontext.h>
#include <QtScript/qscriptengine.h>
+#include <QtScript/qscriptclasspropertyiterator.h>
#include <QtSql/qsqldatabase.h>
#include <QtSql/qsqlquery.h>
#include <QtSql/qsqlerror.h>
@@ -62,12 +63,14 @@
Q_DECLARE_METATYPE(QSqlDatabase)
Q_DECLARE_METATYPE(QSqlQuery)
+class QmlSqlQueryScriptClassPropertyIterator;
+
class QmlSqlQueryScriptClass: public QScriptClass {
public:
QmlSqlQueryScriptClass(QScriptEngine *engine) : QScriptClass(engine)
{
str_length = engine->toStringHandle(QLatin1String("length"));
- str_forwardOnly = engine->toStringHandle(QLatin1String("forwardOnly")); // not in HTML5 (optimization)
+ str_forwardOnly = engine->toStringHandle(QLatin1String("forwardOnly")); // not in HTML5 (an optimization)
}
QueryFlags queryProperty(const QScriptValue &object,
@@ -112,12 +115,11 @@ public:
} else if (name == str_forwardOnly) {
return query.isForwardOnly();
} else {
- if (query.at() == id || query.seek(id)) { // Qt 4.6 doesn't optimize at()==id
+ if ((uint)query.at() == id || query.seek(id)) { // Qt 4.6 doesn't optimize seek(at())
QSqlRecord r = query.record();
- QScriptValue row = engine()->newArray(r.count());
+ QScriptValue row = engine()->newObject();
for (int j=0; j<r.count(); ++j) {
- // XXX only strings
- row.setProperty(j, QScriptValue(engine(),r.value(j).toString()));
+ row.setProperty(r.fieldName(j), QScriptValue(engine(),r.value(j).toString())); // XXX only strings
}
return row;
}
@@ -134,11 +136,108 @@ public:
}
}
+ QScriptValue::PropertyFlags propertyFlags(const QScriptValue &/*object*/, const QScriptString &name, uint /*id*/)
+ {
+ if (name == str_length) {
+ return QScriptValue::Undeletable
+ | QScriptValue::SkipInEnumeration;
+ }
+ 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();
+ }
+
+ ~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);
+}
+
+
+
+static QScriptValue qmlsqldatabase_item(QScriptContext *context, QScriptEngine *engine)
+{
+ QSqlQuery query = qscriptvalue_cast<QSqlQuery>(context->thisObject().data());
+ int i = context->argument(0).toNumber();
+ if (query.at() == i || query.seek(i)) { // 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();
+}
+
static QScriptValue qmlsqldatabase_executeSql(QScriptContext *context, QScriptEngine *engine)
{
QSqlDatabase db = qscriptvalue_cast<QSqlDatabase>(context->thisObject());
@@ -163,6 +262,7 @@ static QScriptValue qmlsqldatabase_executeSql(QScriptContext *context, QScriptEn
QmlEnginePrivate::get(engine)->sqlQueryClass= new QmlSqlQueryScriptClass(engine);
QScriptValue rows = engine->newObject(QmlEnginePrivate::get(engine)->sqlQueryClass);
rows.setData(engine->newVariant(qVariantFromValue(query)));
+ rows.setProperty(QLatin1String("item"), engine->newFunction(qmlsqldatabase_item,1), QScriptValue::SkipInEnumeration);
rs.setProperty(QLatin1String("rows"),rows);
rs.setProperty(QLatin1String("rowsAffected"),query.numRowsAffected());
rs.setProperty(QLatin1String("insertId"),query.lastInsertId().toString()); // XXX only string
@@ -234,7 +334,7 @@ static QScriptValue qmlsqldatabase_open(QScriptContext *context, QScriptEngine *
database = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"), dbid);
}
if (!database.isOpen()) {
- QString basename = QmlEnginePrivate::get(engine)->offlineStoragePath + "/Databases/";
+ QString basename = QmlEnginePrivate::get(engine)->offlineStoragePath + QLatin1String("/Databases/");
QDir().mkpath(basename);
basename += dbid;
database.setDatabaseName(basename+QLatin1String(".sqllite"));
@@ -257,3 +357,9 @@ void qt_add_qmlsqldatabase(QScriptEngine *engine)
engine->globalObject().setProperty(QLatin1String("openDatabase"), openDatabase);
}
+/*
+HTML5 "spec" says "rs.rows[n]", but WebKit only impelments "rs.rows.item(n)". We do both (and property iterator).
+We add a "forwardOnly" property that stops Qt caching results (code promises to only go forward
+through the data.
+*/
+
diff --git a/src/declarative/util/qmlview.cpp b/src/declarative/util/qmlview.cpp
index 7cce2da..805612e 100644
--- a/src/declarative/util/qmlview.cpp
+++ b/src/declarative/util/qmlview.cpp
@@ -340,6 +340,8 @@ void QmlView::continueExecute()
d->initialSize.setWidth(d->root->width());
if (d->initialSize.height() <= 0 && d->root->height() > 0)
d->initialSize.setHeight(d->root->height());
+ resize(d->initialSize);
+
if (d->resizable) {
d->root->setWidth(width());
d->root->setHeight(height());
diff --git a/src/src.pro b/src/src.pro
index 40f744b..f7ace8d 100644
--- a/src/src.pro
+++ b/src/src.pro
@@ -126,6 +126,7 @@ src_declarative.target = sub-declarative
contains(QT_CONFIG, webkit) {
src_webkit.depends = src_gui src_sql src_network src_xml
contains(QT_CONFIG, phonon):src_webkit.depends += src_phonon
+ contains(QT_CONFIG, declarative):src_declarative.depends += src_webkit
#exists($$QT_SOURCE_TREE/src/3rdparty/webkit/JavaScriptCore/JavaScriptCore.pro): src_webkit.depends += src_javascriptcore
}
contains(QT_CONFIG, qt3support): src_plugins.depends += src_qt3support