Skip to content

Commit

Permalink
v4: Get rid of dependency on QQuickAnchorLine type
Browse files Browse the repository at this point in the history
Delegate the meta-type id query and value comparison to
QDeclarativeMetaType.

Register a comparison function for QQuickAnchorLine in
QQuickItemsModule, so that not even QDeclarativeMetaType needs to
know the type declaration. (This is needed in order to be able to
move the items to a separate library.)

Change-Id: I6404d01b74143946ae0a79fa18d1777b675e4194
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
  • Loading branch information
Kent Hansen authored and Qt by Nokia committed Nov 23, 2011
1 parent 23a6a1c commit 384fd7c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 13 deletions.
9 changes: 9 additions & 0 deletions src/declarative/items/qquickitemsmodule.cpp
Expand Up @@ -81,6 +81,7 @@
#include "qquickdrag_p.h"
#include "qquickdroparea_p.h"
#include "qquickmultipointtoucharea_p.h"
#include <private/qdeclarativemetatype_p.h>

static QDeclarativePrivate::AutoParentResult qquickitem_autoParent(QObject *obj, QObject *parent)
{
Expand All @@ -96,6 +97,13 @@ static QDeclarativePrivate::AutoParentResult qquickitem_autoParent(QObject *obj,
return QDeclarativePrivate::Parented;
}

static bool compareQQuickAnchorLines(const void *p1, const void *p2)
{
const QQuickAnchorLine &l1 = *static_cast<const QQuickAnchorLine*>(p1);
const QQuickAnchorLine &l2 = *static_cast<const QQuickAnchorLine*>(p2);
return l1 == l2;
}

static void qt_quickitems_defineModule(const char *uri, int major, int minor)
{
QDeclarativePrivate::RegisterAutoParent autoparent = { 0, &qquickitem_autoParent };
Expand Down Expand Up @@ -168,6 +176,7 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor)
qmlRegisterType<QQuickPen>();
qmlRegisterType<QQuickFlickableVisibleArea>();
qRegisterMetaType<QQuickAnchorLine>("QQuickAnchorLine");
QDeclarativeMetaType::setQQuickAnchorLineCompareFunction(compareQQuickAnchorLines);

qmlRegisterUncreatableType<QQuickKeyNavigationAttached>(uri,major,minor,"KeyNavigation",QQuickKeyNavigationAttached::tr("KeyNavigation is only available via attached properties"));
qmlRegisterUncreatableType<QQuickKeysAttached>(uri,major,minor,"Keys",QQuickKeysAttached::tr("Keys is only available via attached properties"));
Expand Down
23 changes: 23 additions & 0 deletions src/declarative/qml/qdeclarativemetatype.cpp
Expand Up @@ -1894,4 +1894,27 @@ bool QDeclarativeMetaType::copy(int type, void *data, const void *copy)
return false;
}

int QDeclarativeMetaType::QQuickAnchorLineMetaTypeId()
{
static int id = 0;
if (!id) {
id = QMetaType::type("QQuickAnchorLine");
Q_ASSERT(id != 0);
}
return id;
}

QDeclarativeMetaType::CompareFunction QDeclarativeMetaType::anchorLineCompareFunction = 0;

void QDeclarativeMetaType::setQQuickAnchorLineCompareFunction(CompareFunction fun)
{
anchorLineCompareFunction = fun;
}

bool QDeclarativeMetaType::QQuickAnchorLineCompare(const void *p1, const void *p2)
{
Q_ASSERT(anchorLineCompareFunction != 0);
return anchorLineCompareFunction(p1, p2);
}

QT_END_NAMESPACE
8 changes: 8 additions & 0 deletions src/declarative/qml/qdeclarativemetatype_p.h
Expand Up @@ -111,6 +111,11 @@ class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeMetaType

static QList<QDeclarativePrivate::AutoParentFunction> parentFunctions();

static int QQuickAnchorLineMetaTypeId();
typedef bool (*CompareFunction)(const void *, const void *);
static void setQQuickAnchorLineCompareFunction(CompareFunction);
static bool QQuickAnchorLineCompare(const void *p1, const void *p2);

struct ModuleApiInstance {
ModuleApiInstance()
: scriptCallback(0), qobjectCallback(0), qobjectApi(0) {}
Expand All @@ -130,6 +135,9 @@ class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeMetaType
};
static ModuleApi moduleApi(const QString &, int, int);
static QHash<QString, QList<ModuleApi> > moduleApis();

private:
static CompareFunction anchorLineCompareFunction;
};

class QHashedStringRef;
Expand Down
13 changes: 5 additions & 8 deletions src/declarative/qml/v4/qv4bindings.cpp
Expand Up @@ -48,7 +48,7 @@

#include <private/qdeclarativefastproperties_p.h>
#include <private/qdeclarativedebugtrace_p.h>
#include <private/qquickanchors_p_p.h> // For AnchorLine
#include <private/qdeclarativemetatype_p.h>

#include <QtDeclarative/qdeclarativeinfo.h>
#include <QtCore/qnumeric.h>
Expand Down Expand Up @@ -450,11 +450,8 @@ static bool testCompareVariants(const QVariant &qtscriptRaw, const QVariant &v4)
QDeclarative1AnchorLine ra = qvariant_cast<QDeclarative1AnchorLine>(v4);

return la == ra;
} else if (type == qMetaTypeId<QQuickAnchorLine>()) {
QQuickAnchorLine la = qvariant_cast<QQuickAnchorLine>(qtscript);
QQuickAnchorLine ra = qvariant_cast<QQuickAnchorLine>(v4);

return la == ra;
} else if (type == QDeclarativeMetaType::QQuickAnchorLineMetaTypeId()) {
return QDeclarativeMetaType::QQuickAnchorLineCompare(qtscript.constData(), v4.constData());
} else if (type == QMetaType::Double) {

double la = qvariant_cast<double>(qtscript);
Expand Down Expand Up @@ -535,8 +532,8 @@ static void testBindingResult(const QString &binding, int line, int column,
default:
if (resultType == qMetaTypeId<QDeclarative1AnchorLine>()) {
v4value = qVariantFromValue<QDeclarative1AnchorLine>(*(QDeclarative1AnchorLine *)result.typeDataPtr());
} else if (resultType == qMetaTypeId<QQuickAnchorLine>()) {
v4value = qVariantFromValue<QQuickAnchorLine>(*(QQuickAnchorLine *)result.typeDataPtr());
} else if (resultType == QDeclarativeMetaType::QQuickAnchorLineMetaTypeId()) {
v4value = QVariant(QDeclarativeMetaType::QQuickAnchorLineMetaTypeId(), result.typeDataPtr());
} else {
iserror = true;
v4Result = "Unknown V4 type";
Expand Down
5 changes: 2 additions & 3 deletions src/declarative/qml/v4/qv4compiler.cpp
Expand Up @@ -48,7 +48,6 @@
#include <private/qdeclarativejsast_p.h>
#include <private/qdeclarativefastproperties_p.h>
#include <private/qdeclarativejsengine_p.h>
#include <private/qquickanchors_p_p.h> // For AnchorLine

QT_BEGIN_NAMESPACE

Expand Down Expand Up @@ -346,7 +345,7 @@ void QV4CompilerPrivate::visitName(IR::Name *e)
default:
if (propTy == qMetaTypeId<QDeclarative1AnchorLine>()) {
regType = PODValueType;
} else if (propTy == qMetaTypeId<QQuickAnchorLine>()) {
} else if (propTy == QDeclarativeMetaType::QQuickAnchorLineMetaTypeId()) {
regType = PODValueType;
} else if (QDeclarativeMetaType::isQObject(propTy)) {
regType = QObjectStarType;
Expand Down Expand Up @@ -945,7 +944,7 @@ void QV4CompilerPrivate::visitRet(IR::Ret *s)
test.regType = qMetaTypeId<QDeclarative1AnchorLine>();
break;
case IR::SGAnchorLineType:
test.regType = qMetaTypeId<QQuickAnchorLine>();
test.regType = QDeclarativeMetaType::QQuickAnchorLineMetaTypeId();
break;
case IR::ObjectType:
test.regType = QMetaType::QObjectStar;
Expand Down
4 changes: 2 additions & 2 deletions src/declarative/qml/v4/qv4irbuilder.cpp
Expand Up @@ -42,7 +42,7 @@
#include "qv4irbuilder_p.h"
#include "qv4compiler_p_p.h"

#include <private/qquickanchors_p_p.h> // For AnchorLine
#include <private/qdeclarativemetatype_p.h>
#include <private/qdeclarativetypenamecache_p.h>

DEFINE_BOOL_CONFIG_OPTION(qmlVerboseCompiler, QML_VERBOSE_COMPILER)
Expand Down Expand Up @@ -72,7 +72,7 @@ static IR::Type irTypeFromVariantType(int t, QDeclarativeEnginePrivate *engine,
default:
if (t == qMetaTypeId<QDeclarative1AnchorLine>())
return IR::AnchorLineType;
else if (t == qMetaTypeId<QQuickAnchorLine>())
else if (t == QDeclarativeMetaType::QQuickAnchorLineMetaTypeId())
return IR::SGAnchorLineType;
else if (engine->metaObjectForType(t)) {
return IR::ObjectType;
Expand Down

0 comments on commit 384fd7c

Please sign in to comment.