#include <QtGui/qmatrix.h>
#include <QtGui/qcolor.h>
#include <QtGui/qvector3d.h>
+#include <QtGui/QFont>
#include <QtGui/QPixmap>
#include <QtCore/qdatetime.h>
+#include <QtCore/qjsonarray.h>
+#include <QtCore/qjsonobject.h>
+#include <QtCore/qjsonvalue.h>
#include <QtQml/qjsvalue.h>
#include <QtQml/qqmlscriptstring.h>
#include <QtQml/qqmlcomponent.h>
int m_value2;
};
+class MyEnumContainer : public QObject
+{
+ Q_OBJECT
+ Q_ENUMS(RelatedEnum)
+
+public:
+ enum RelatedEnum { RelatedInvalid = -1, RelatedValue = 42, MultiplyDefined = 666 };
+};
+
class MyQmlObject : public QObject
{
Q_OBJECT
Q_ENUMS(MyEnum)
Q_ENUMS(MyEnum2)
+ Q_ENUMS(MyEnum3)
+ Q_ENUMS(MyEnumContainer::RelatedEnum)
Q_PROPERTY(int deleteOnSet READ deleteOnSet WRITE setDeleteOnSet)
Q_PROPERTY(bool trueProperty READ trueProperty CONSTANT)
Q_PROPERTY(bool falseProperty READ falseProperty CONSTANT)
Q_PROPERTY(QRegExp regExp READ regExp WRITE setRegExp)
Q_PROPERTY(int nonscriptable READ nonscriptable WRITE setNonscriptable SCRIPTABLE false)
Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty NOTIFY intChanged)
+ Q_PROPERTY(QJSValue qjsvalue READ qjsvalue WRITE setQJSValue NOTIFY qjsvalueChanged)
+ Q_PROPERTY(QJSValue qjsvalueWithReset READ qjsvalue WRITE setQJSValue RESET resetQJSValue NOTIFY qjsvalueChanged)
+ Q_PROPERTY(MyEnum enumProperty READ enumProperty WRITE setEnumProperty)
+ Q_PROPERTY(MyEnumContainer::RelatedEnum relatedEnumProperty READ relatedEnumProperty WRITE setRelatedEnumProperty)
+ Q_PROPERTY(MyEnumContainer::RelatedEnum unrelatedEnumProperty READ unrelatedEnumProperty WRITE setUnrelatedEnumProperty)
+ Q_PROPERTY(MyEnum qtEnumProperty READ qtEnumProperty WRITE setQtEnumProperty)
public:
- MyQmlObject(): myinvokableObject(0), m_methodCalled(false), m_methodIntCalled(false), m_object(0), m_value(0), m_resetProperty(13), m_intProperty(0) {}
+ MyQmlObject(): myinvokableObject(0), m_methodCalled(false), m_methodIntCalled(false), m_object(0), m_value(0), m_resetProperty(13), m_intProperty(0), m_buttons(0) {}
enum MyEnum { EnumValue1 = 0, EnumValue2 = 1 };
- enum MyEnum2 { EnumValue3 = 2, EnumValue4 = 3 };
+ enum MyEnum2 { EnumValue3 = 2, EnumValue4 = 3, EnumValue5 = -1 };
+ enum MyEnum3 { MultiplyDefined = 333 };
bool trueProperty() const { return true; }
bool falseProperty() const { return false; }
struct MyType {
int value;
};
+ struct MyOtherType {
+ int value;
+ };
QVariant variant() const { return m_variant; }
QJSValue qjsvalue() const { return m_qjsvalue; }
+ void setQJSValue(const QJSValue &value) { m_qjsvalue = value; emit qjsvalueChanged(); }
+ void resetQJSValue() { m_qjsvalue = QJSValue(QLatin1String("Reset!")); emit qjsvalueChanged(); }
+
+ Qt::MouseButtons buttons() const { return m_buttons; }
int intProperty() const { return m_intProperty; }
void setIntProperty(int i) { m_intProperty = i; emit intChanged(); }
+ Q_INVOKABLE MyEnum2 getEnumValue() const { return EnumValue4; }
+
+ MyEnum enumPropertyValue;
+ MyEnum enumProperty() const {
+ return enumPropertyValue;
+ }
+ void setEnumProperty(MyEnum v) {
+ enumPropertyValue = v;
+ }
+
+ MyEnumContainer::RelatedEnum relatedEnumPropertyValue;
+ MyEnumContainer::RelatedEnum relatedEnumProperty() const {
+ return relatedEnumPropertyValue;
+ }
+ void setRelatedEnumProperty(MyEnumContainer::RelatedEnum v) {
+ relatedEnumPropertyValue = v;
+ }
+
+ MyEnumContainer::RelatedEnum unrelatedEnumPropertyValue;
+ MyEnumContainer::RelatedEnum unrelatedEnumProperty() const {
+ return unrelatedEnumPropertyValue;
+ }
+ void setUnrelatedEnumProperty(MyEnumContainer::RelatedEnum v) {
+ unrelatedEnumPropertyValue = v;
+ }
+
+ MyEnum qtEnumPropertyValue;
+ MyEnum qtEnumProperty() const {
+ return qtEnumPropertyValue;
+ }
+ void setQtEnumProperty(MyEnum v) {
+ qtEnumPropertyValue = v;
+ }
+
signals:
void basicSignal();
void argumentSignal(int a, QString b, qreal c, MyEnum2 d, Qt::MouseButtons e);
void anotherBasicSignal();
void thirdBasicSignal();
void signalWithUnknownType(const MyQmlObject::MyType &arg);
+ void signalWithCompletelyUnknownType(const MyQmlObject::MyOtherType &arg);
void signalWithVariant(const QVariant &arg);
void signalWithQJSValue(const QJSValue &arg);
void signalWithGlobalName(int parseInt);
void intChanged();
+ void qjsvalueChanged();
public slots:
void deleteMe() { delete this; }
void variantMethod(const QVariant &v) { m_variant = v; }
void qjsvalueMethod(const QJSValue &v) { m_qjsvalue = v; }
void v8function(QQmlV8Function*);
+ void registeredFlagMethod(Qt::MouseButtons v) { m_buttons = v; }
private:
friend class tst_qqmlecmascript;
QVariant m_variant;
QJSValue m_qjsvalue;
int m_intProperty;
+ Qt::MouseButtons m_buttons;
};
QML_DECLARE_TYPEINFO(MyQmlObject, QML_HAS_ATTACHED_PROPERTIES)
{
Q_OBJECT
Q_ENUMS(MyEnum)
+ Q_ENUMS(MyEnumContainer::RelatedEnum)
Q_FLAGS(MyFlags)
Q_PROPERTY(QString id READ id WRITE setId)
Q_PROPERTY(QQmlComponent *componentProperty READ componentProperty WRITE setComponentProperty)
Q_PROPERTY(MyFlags flagProperty READ flagProperty WRITE setFlagProperty)
Q_PROPERTY(MyEnum enumProperty READ enumProperty WRITE setEnumProperty)
+ Q_PROPERTY(MyEnumContainer::RelatedEnum relatedEnumProperty READ relatedEnumProperty WRITE setRelatedEnumProperty)
Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty)
Q_PROPERTY(uint uintProperty READ uintProperty WRITE setUintProperty)
Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty)
Q_PROPERTY(QDate dateProperty READ dateProperty WRITE setDateProperty)
Q_PROPERTY(QTime timeProperty READ timeProperty WRITE setTimeProperty)
Q_PROPERTY(QDateTime dateTimeProperty READ dateTimeProperty WRITE setDateTimeProperty)
+ Q_PROPERTY(QDateTime dateTimeProperty2 READ dateTimeProperty2 WRITE setDateTimeProperty2)
Q_PROPERTY(QPoint pointProperty READ pointProperty WRITE setPointProperty)
Q_PROPERTY(QPointF pointFProperty READ pointFProperty WRITE setPointFProperty)
Q_PROPERTY(QSize sizeProperty READ sizeProperty WRITE setSizeProperty)
enumPropertyValue = v;
}
+ MyEnumContainer::RelatedEnum relatedEnumPropertyValue;
+ MyEnumContainer::RelatedEnum relatedEnumProperty() const {
+ return relatedEnumPropertyValue;
+ }
+ void setRelatedEnumProperty(MyEnumContainer::RelatedEnum v) {
+ relatedEnumPropertyValue = v;
+ }
+
QString stringPropertyValue;
QString stringProperty() const {
return stringPropertyValue;
dateTimePropertyValue = v;
}
+ QDateTime dateTimePropertyValue2;
+ QDateTime dateTimeProperty2() const {
+ return dateTimePropertyValue2;
+ }
+ void setDateTimeProperty2(const QDateTime &v) {
+ dateTimePropertyValue2 = v;
+ }
+
QPoint pointPropertyValue;
QPoint pointProperty() const {
return pointPropertyValue;
Q_INVOKABLE void method_QVariant(QVariant a, QVariant b = QVariant()) { invoke(21); m_actuals << a << b; }
+ Q_INVOKABLE void method_QJsonObject(const QJsonObject &a) { invoke(22); m_actuals << QVariant::fromValue(a); }
+ Q_INVOKABLE void method_QJsonArray(const QJsonArray &a) { invoke(23); m_actuals << QVariant::fromValue(a); }
+ Q_INVOKABLE void method_QJsonValue(const QJsonValue &a) { invoke(24); m_actuals << QVariant::fromValue(a); }
+
+ Q_INVOKABLE void method_overload(const QJsonObject &a) { invoke(25); m_actuals << QVariant::fromValue(a); }
+ Q_INVOKABLE void method_overload(const QJsonArray &a) { invoke(26); m_actuals << QVariant::fromValue(a); }
+ Q_INVOKABLE void method_overload(const QJsonValue &a) { invoke(27); m_actuals << QVariant::fromValue(a); }
+
+ Q_INVOKABLE void method_unknown(MyInvokableObject *) { invoke(28); }
+
private:
friend class MyInvokableBaseObject;
void invoke(int idx) { if (m_invoked != -1) m_invokedError = true; m_invoked = idx;}
Q_INVOKABLE void setTrackedObjectProperty(const QString &propName) const { m_trackedObject->setProperty(qPrintable(propName), QVariant(5)); }
Q_INVOKABLE QVariant trackedObjectProperty(const QString &propName) const { return m_trackedObject->property(qPrintable(propName)); }
+ Q_INVOKABLE void setSpecificProperty(QObject *obj, const QString & propName, const QVariant & v) const { obj->setProperty(qPrintable(propName), v); }
+ Q_INVOKABLE void changeQObjectParent(QObject *obj) { obj->setParent(this); }
+
int qobjectTestProperty() const { return m_testProperty; }
void setQObjectTestProperty(int tp) { m_testProperty = tp; emit qobjectTestPropertyChanged(tp); }
int qobjectTestWritableFinalProperty() const { return m_testWritableFinalProperty; }
void setQObjectTestWritableFinalProperty(int tp) { m_testWritableFinalProperty = tp; emit qobjectTestWritableFinalPropertyChanged(); }
+ Q_INVOKABLE bool trackedObjectHasJsOwnership() {
+ QObject * object = m_trackedObject;
+
+ if (!object)
+ return false;
+
+ QQmlData *ddata = QQmlData::get(object, false);
+ if (!ddata)
+ return false;
+ else
+ return ddata->indestructible?false:true;
+ }
+
+ Q_INVOKABLE void deleteQObject(QObject *obj) { delete obj; }
+
signals:
void qobjectTestPropertyChanged(int testProperty);
void qobjectTestWritablePropertyChanged(int testWritableProperty);
QObject *m_trackedObject;
};
+class testQObjectApiTwo : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int twoTestProperty READ twoTestProperty WRITE setTwoTestProperty NOTIFY twoTestPropertyChanged)
+
+public:
+ testQObjectApiTwo(QObject *parent = 0) : QObject(parent), m_ttp(42) {}
+ ~testQObjectApiTwo() {}
+
+ void setTwoTestProperty(int v) { m_ttp = v; emit twoTestPropertyChanged(); }
+ int twoTestProperty() const { return m_ttp; }
+
+signals:
+ void twoTestPropertyChanged();
+
+private:
+ int m_ttp;
+};
+
+class testImportOrderApi : public QObject
+{
+ Q_OBJECT
+
+public:
+ testImportOrderApi(int value, QObject *parent = 0) : QObject(parent), m_value(value) {}
+
+ Q_PROPERTY(int value READ value)
+
+ int value() const { return m_value; }
+
+private:
+ int m_value;
+};
+
class CircularReferenceObject : public QObject,
public QV8GCCallback::Node
{
m_referenced.MakeWeak(static_cast<void*>(this), wrcallback);
}
- static void wrcallback(v8::Persistent<v8::Value> handle, void *params)
+ static void wrcallback(v8::Persistent<v8::Value> handle, void *)
{
- CircularReferenceHandle *crh = static_cast<CircularReferenceHandle*>(params);
qPersistentDispose(handle);
- crh->m_referenced.Clear();
}
static void gccallback(QV8GCCallback::Node *n)
Q_INVOKABLE QList<QString> generateStringSequence() const { QList<QString> retn; retn << "one" << "two" << "three"; return retn; }
Q_INVOKABLE QList<QUrl> generateUrlSequence() const { QList<QUrl> retn; retn << QUrl("http://www.example1.com") << QUrl("http://www.example2.com") << QUrl("http://www.example3.com"); return retn; }
Q_INVOKABLE QStringList generateQStringSequence() const { QStringList retn; retn << "one" << "two" << "three"; return retn; }
+ Q_INVOKABLE bool parameterEqualsGeneratedIntSequence(const QList<int>& param) const { return (param == generateIntSequence()); }
// "reference resource" underlying qobject deletion test:
Q_INVOKABLE MySequenceConversionObject *generateTestObject() const { return new MySequenceConversionObject; }
MyQmlObject *m_nestedObject;
};
+class DateTimeExporter : public QObject
+{
+ Q_OBJECT
+
+public:
+ DateTimeExporter(const QDateTime &dt) : m_datetime(dt), m_offset(0), m_timespec("UTC")
+ {
+ switch (m_datetime.timeSpec()) {
+ case Qt::LocalTime:
+ {
+ QDateTime utc(m_datetime.toUTC());
+ utc.setTimeSpec(Qt::LocalTime);
+ m_offset = m_datetime.secsTo(utc) / 60;
+ m_timespec = "LocalTime";
+ }
+ break;
+ case Qt::OffsetFromUTC:
+ m_offset = m_datetime.utcOffset() / 60;
+ m_timespec = QString("%1%2:%3").arg(m_offset < 0 ? '-' : '+')
+ .arg(abs(m_offset) / 60)
+ .arg(abs(m_offset) % 60);
+ default:
+ break;
+ }
+ }
+
+ Q_INVOKABLE QDate getDate() const { return m_datetime.date(); }
+ Q_INVOKABLE QDateTime getDateTime() const { return m_datetime; }
+ Q_INVOKABLE int getDateTimeOffset() const { return m_offset; }
+ Q_INVOKABLE QString getTimeSpec() const { return m_timespec; }
+
+private:
+ QDateTime m_datetime;
+ int m_offset;
+ QString m_timespec;
+};
+
+class MyWorkerObject : public QObject
+{
+ Q_OBJECT
+
+public Q_SLOTS:
+ void doIt();
+
+Q_SIGNALS:
+ void done(const QString &result);
+};
+
+class MyUnregisteredEnumTypeObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(MyEnum enumProperty READ enumProperty WRITE setEnumProperty)
+
+public:
+ MyUnregisteredEnumTypeObject() : QObject(), m_ev(FirstValue) {}
+ ~MyUnregisteredEnumTypeObject() {}
+
+ enum MyEnum {
+ FirstValue = 1,
+ SecondValue = 2
+ };
+
+ MyEnum enumProperty() const { return m_ev; }
+ void setEnumProperty(MyEnum v) { m_ev = v; }
+
+private:
+ MyEnum m_ev;
+};
+
+class FallbackBindingsObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY (int test READ test NOTIFY testChanged)
+public:
+ FallbackBindingsObject(QObject* parent = 0)
+ : QObject(parent), m_test(100)
+ {
+ }
+
+ int test() const { return m_test; }
+
+Q_SIGNALS:
+ void testChanged();
+
+private:
+ int m_test;
+};
+
+class FallbackBindingsDerived : public FallbackBindingsObject
+{
+ Q_OBJECT
+ Q_PROPERTY (QString test READ test NOTIFY testChanged)
+public:
+ FallbackBindingsDerived(QObject* parent = 0)
+ : FallbackBindingsObject(parent), m_test("hello")
+ {
+ }
+
+ QString test() const { return m_test; }
+
+Q_SIGNALS:
+ void testChanged();
+
+private:
+ QString m_test;
+};
+
+class FallbackBindingsAttachedObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY (int test READ test NOTIFY testChanged)
+public:
+ FallbackBindingsAttachedObject(QObject *parent) : QObject(parent), m_test(100) {}
+
+ int test() const { return m_test; }
+
+Q_SIGNALS:
+ void testChanged();
+
+private:
+ int m_test;
+};
+
+class FallbackBindingsAttachedDerived : public FallbackBindingsAttachedObject
+{
+ Q_OBJECT
+ Q_PROPERTY (QString test READ test NOTIFY testChanged)
+public:
+ FallbackBindingsAttachedDerived(QObject* parent = 0)
+ : FallbackBindingsAttachedObject(parent), m_test("hello")
+ {
+ }
+
+ QString test() const { return m_test; }
+
+Q_SIGNALS:
+ void testChanged();
+
+private:
+ QString m_test;
+};
+
+class FallbackBindingsTypeObject : public QObject
+{
+ Q_OBJECT
+public:
+ FallbackBindingsTypeObject() : QObject() {}
+
+ static FallbackBindingsAttachedObject *qmlAttachedProperties(QObject *o) {
+ return new FallbackBindingsAttachedObject(o);
+ }
+};
+
+class FallbackBindingsTypeDerived : public QObject
+{
+ Q_OBJECT
+public:
+ FallbackBindingsTypeDerived() : QObject() {}
+
+ static FallbackBindingsAttachedObject *qmlAttachedProperties(QObject *o) {
+ return new FallbackBindingsAttachedDerived(o);
+ }
+};
+
+QML_DECLARE_TYPEINFO(FallbackBindingsTypeObject, QML_HAS_ATTACHED_PROPERTIES)
+QML_DECLARE_TYPEINFO(FallbackBindingsTypeDerived, QML_HAS_ATTACHED_PROPERTIES)
+
void registerTypes();
#endif // TESTTYPES_H