summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2010-03-29 04:47:53 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2010-03-29 04:48:58 (GMT)
commitd6817c59b664b1ce08e45bed902f17b58160a30f (patch)
tree8a0c8736a0c26446756976f8dfd1212345ab847e /src/declarative/qml
parente3ec89ed31439a83c10a2fc2d770283f4f10f31a (diff)
downloadQt-d6817c59b664b1ce08e45bed902f17b58160a30f.zip
Qt-d6817c59b664b1ce08e45bed902f17b58160a30f.tar.gz
Qt-d6817c59b664b1ce08e45bed902f17b58160a30f.tar.bz2
Use QDateTime when specifying a "date" property in QML
QT-718
Diffstat (limited to 'src/declarative/qml')
-rw-r--r--src/declarative/qml/qdeclarativecompiler.cpp8
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp5
-rw-r--r--src/declarative/qml/qdeclarativeparser_p.h2
-rw-r--r--src/declarative/qml/qdeclarativescriptparser.cpp8
-rw-r--r--src/declarative/qml/qdeclarativevmemetaobject.cpp24
5 files changed, 43 insertions, 4 deletions
diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp
index a9d90f3..f1a673f 100644
--- a/src/declarative/qml/qdeclarativecompiler.cpp
+++ b/src/declarative/qml/qdeclarativecompiler.cpp
@@ -2428,10 +2428,18 @@ bool QDeclarativeCompiler::buildDynamicMeta(QDeclarativeParser::Object *obj, Dyn
propertyType = QVariant::Color;
type = "QColor";
break;
+ case Object::DynamicProperty::Time:
+ propertyType = QVariant::Time;
+ type = "QTime";
+ break;
case Object::DynamicProperty::Date:
propertyType = QVariant::Date;
type = "QDate";
break;
+ case Object::DynamicProperty::DateTime:
+ propertyType = QVariant::DateTime;
+ type = "QDateTime";
+ break;
}
((QDeclarativeVMEMetaData *)dynamicData.data())->propertyCount++;
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index a153f8f..5335b8c 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -1306,13 +1306,14 @@ QScriptValue QDeclarativeEnginePrivate::tint(QScriptContext *ctxt, QScriptEngine
QScriptValue QDeclarativeEnginePrivate::scriptValueFromVariant(const QVariant &val)
{
if (val.userType() == qMetaTypeId<QDeclarativeListReference>()) {
- QDeclarativeListReferencePrivate *p = QDeclarativeListReferencePrivate::get((QDeclarativeListReference*)val.constData());
+ QDeclarativeListReferencePrivate *p =
+ QDeclarativeListReferencePrivate::get((QDeclarativeListReference*)val.constData());
if (p->object) {
return listClass->newList(p->property, p->propertyType);
} else {
return scriptEngine.nullValue();
}
- }
+ }
bool objOk;
QObject *obj = QDeclarativeMetaType::toQObject(val, &objOk);
diff --git a/src/declarative/qml/qdeclarativeparser_p.h b/src/declarative/qml/qdeclarativeparser_p.h
index 476b027..f432024 100644
--- a/src/declarative/qml/qdeclarativeparser_p.h
+++ b/src/declarative/qml/qdeclarativeparser_p.h
@@ -203,7 +203,7 @@ namespace QDeclarativeParser
DynamicProperty();
DynamicProperty(const DynamicProperty &);
- enum Type { Variant, Int, Bool, Real, String, Url, Color, Date, Alias, Custom, CustomList };
+ enum Type { Variant, Int, Bool, Real, String, Url, Color, Time, Date, DateTime, Alias, Custom, CustomList };
bool isDefaultProperty;
Type type;
diff --git a/src/declarative/qml/qdeclarativescriptparser.cpp b/src/declarative/qml/qdeclarativescriptparser.cpp
index 49bd3b7..ed35fed 100644
--- a/src/declarative/qml/qdeclarativescriptparser.cpp
+++ b/src/declarative/qml/qdeclarativescriptparser.cpp
@@ -528,7 +528,13 @@ bool ProcessAST::visit(AST::UiPublicMember *node)
{ "string", Object::DynamicProperty::String, "QString" },
{ "url", Object::DynamicProperty::Url, "QUrl" },
{ "color", Object::DynamicProperty::Color, "QColor" },
- { "date", Object::DynamicProperty::Date, "QDate" },
+ // Internally QTime, QDate and QDateTime are all supported.
+ // To be more consistent with JavaScript we expose only
+ // QDateTime as it matches closely with the Date JS type.
+ // We also call it "date" to match.
+ // { "time", Object::DynamicProperty::Time, "QTime" },
+ // { "date", Object::DynamicProperty::Date, "QDate" },
+ { "date", Object::DynamicProperty::DateTime, "QDateTime" },
{ "var", Object::DynamicProperty::Variant, "QVariant" },
{ "variant", Object::DynamicProperty::Variant, "QVariant" }
};
diff --git a/src/declarative/qml/qdeclarativevmemetaobject.cpp b/src/declarative/qml/qdeclarativevmemetaobject.cpp
index 2404fdd..721e1f1 100644
--- a/src/declarative/qml/qdeclarativevmemetaobject.cpp
+++ b/src/declarative/qml/qdeclarativevmemetaobject.cpp
@@ -69,6 +69,7 @@ public:
inline const QString &asQString();
inline const QUrl &asQUrl();
inline const QColor &asQColor();
+ inline const QTime &asQTime();
inline const QDate &asQDate();
inline const QDateTime &asQDateTime();
inline const QScriptValue &asQScriptValue();
@@ -81,6 +82,7 @@ public:
inline void setValue(const QString &);
inline void setValue(const QUrl &);
inline void setValue(const QColor &);
+ inline void setValue(const QTime &);
inline void setValue(const QDate &);
inline void setValue(const QDateTime &);
inline void setValue(const QScriptValue &);
@@ -119,6 +121,9 @@ void QDeclarativeVMEVariant::cleanup()
} else if (type == QMetaType::QColor) {
((QColor *)dataPtr())->~QColor();
type = QVariant::Invalid;
+ } else if (type == QMetaType::QTime) {
+ ((QTime *)dataPtr())->~QTime();
+ type = QVariant::Invalid;
} else if (type == QMetaType::QDate) {
((QDate *)dataPtr())->~QDate();
type = QVariant::Invalid;
@@ -214,6 +219,14 @@ const QColor &QDeclarativeVMEVariant::asQColor()
return *(QColor *)(dataPtr());
}
+const QTime &QDeclarativeVMEVariant::asQTime()
+{
+ if (type != QMetaType::QTime)
+ setValue(QTime());
+
+ return *(QTime *)(dataPtr());
+}
+
const QDate &QDeclarativeVMEVariant::asQDate()
{
if (type != QMetaType::QDate)
@@ -318,6 +331,17 @@ void QDeclarativeVMEVariant::setValue(const QColor &v)
}
}
+void QDeclarativeVMEVariant::setValue(const QTime &v)
+{
+ if (type != QMetaType::QTime) {
+ cleanup();
+ type = QMetaType::QTime;
+ new (dataPtr()) QTime(v);
+ } else {
+ *(QTime *)(dataPtr()) = v;
+ }
+}
+
void QDeclarativeVMEVariant::setValue(const QDate &v)
{
if (type != QMetaType::QDate) {