, metaObject(0)
, groupNames(groupNames)
{
+ initializeMetaObject();
+}
+
+QQuickVisualDataModelItemMetaType::~QQuickVisualDataModelItemMetaType()
+{
+ free(metaObject);
+ qPersistentDispose(constructor);
+}
+
+void QQuickVisualDataModelItemMetaType::initializeMetaObject()
+{
QMetaObjectBuilder builder;
builder.setFlags(QMetaObjectBuilder::DynamicMetaObject);
builder.setClassName(QQuickVisualDataModelAttached::staticMetaObject.className());
builder.setSuperClass(&QQuickVisualDataModelAttached::staticMetaObject);
- v8::HandleScope handleScope;
- v8::Context::Scope contextScope(engine->context());
-
- constructor = qPersistentNew(v8::ObjectTemplate::New());
-
- constructor->SetHasExternalResource(true);
- constructor->SetAccessor(v8::String::New("model"), get_model);
- constructor->SetAccessor(v8::String::New("groups"), get_groups, set_groups);
- constructor->SetAccessor(v8::String::New("isUnresolved"), get_member, 0, v8::Int32::New(30));
-
int notifierId = 0;
for (int i = 0; i < groupNames.count(); ++i, ++notifierId) {
QString propertyName = QStringLiteral("in") + groupNames.at(i);
QMetaPropertyBuilder propertyBuilder = builder.addProperty(
propertyName.toUtf8(), "bool", notifierId);
propertyBuilder.setWritable(true);
-
- constructor->SetAccessor(
- engine->toString(propertyName), get_member, set_member, v8::Int32::New(i + 1));
}
for (int i = 0; i < groupNames.count(); ++i, ++notifierId) {
const QString propertyName = groupNames.at(i) + QStringLiteral("Index");
QMetaPropertyBuilder propertyBuilder = builder.addProperty(
propertyName.toUtf8(), "int", notifierId);
propertyBuilder.setWritable(true);
-
- constructor->SetAccessor(
- engine->toString(propertyName), get_index, 0, v8::Int32::New(i + 1));
}
metaObject = builder.toMetaObject();
}
-QQuickVisualDataModelItemMetaType::~QQuickVisualDataModelItemMetaType()
+void QQuickVisualDataModelItemMetaType::initializeConstructor()
{
- free(metaObject);
- qPersistentDispose(constructor);
+ v8::HandleScope handleScope;
+ v8::Context::Scope contextScope(v8Engine->context());
+
+ constructor = qPersistentNew(v8::ObjectTemplate::New());
+
+ constructor->SetHasExternalResource(true);
+ constructor->SetAccessor(v8::String::New("model"), get_model);
+ constructor->SetAccessor(v8::String::New("groups"), get_groups, set_groups);
+ constructor->SetAccessor(v8::String::New("isUnresolved"), get_member, 0, v8::Int32::New(30));
+
+ int notifierId = 0;
+ for (int i = 0; i < groupNames.count(); ++i, ++notifierId) {
+ QString propertyName = QStringLiteral("in") + groupNames.at(i);
+ propertyName.replace(2, 1, propertyName.at(2).toUpper());
+ constructor->SetAccessor(
+ v8Engine->toString(propertyName), get_member, set_member, v8::Int32::New(i + 1));
+ }
+ for (int i = 0; i < groupNames.count(); ++i, ++notifierId) {
+ const QString propertyName = groupNames.at(i) + QStringLiteral("Index");
+ constructor->SetAccessor(
+ v8Engine->toString(propertyName), get_index, 0, v8::Int32::New(i + 1));
+ }
}
int QQuickVisualDataModelItemMetaType::parseGroups(const QStringList &groups) const
}
if (cacheItem->indexHandle.IsEmpty()) {
+ if (model->m_cacheMetaType->constructor.IsEmpty())
+ model->m_cacheMetaType->initializeConstructor();
cacheItem->indexHandle = qPersistentNew(model->m_cacheMetaType->constructor->NewInstance());
cacheItem->indexHandle->SetExternalResource(cacheItem);
cacheItem->indexHandle.MakeWeak(cacheItem, QQuickVisualDataModelItemMetaType::release_index);