QmlDesigner: use setContextProperties

should be faster

Change-Id: I3f491237746856c00f13947dfa9e8464a2bd5c25
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Tim Jenssen
2020-04-23 01:33:42 +02:00
parent 49626f7ea9
commit 8d868d8bbb
3 changed files with 28 additions and 16 deletions

View File

@@ -101,13 +101,15 @@ ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) :
m_itemViewQuickWidget->engine()->addImportPath(propertyEditorResourcesPath() + "/imports"); m_itemViewQuickWidget->engine()->addImportPath(propertyEditorResourcesPath() + "/imports");
m_itemLibraryModel = new ItemLibraryModel(this); m_itemLibraryModel = new ItemLibraryModel(this);
QQmlContext *rootContext = m_itemViewQuickWidget->rootContext(); m_itemViewQuickWidget->rootContext()->setContextProperties(
rootContext->setContextProperty(QStringLiteral("itemLibraryModel"), m_itemLibraryModel.data()); QVector<QQmlContext::PropertyPair>{
rootContext->setContextProperty(QStringLiteral("itemLibraryIconWidth"), m_itemIconSize.width()); {"itemLibraryModel", QVariant::fromValue(m_itemLibraryModel.data())},
rootContext->setContextProperty(QStringLiteral("itemLibraryIconHeight"), m_itemIconSize.height()); {"itemLibraryIconWidth", m_itemIconSize.width()},
rootContext->setContextProperty(QStringLiteral("rootView"), this); {"itemLibraryIconHeight", m_itemIconSize.height()},
{"rootView", QVariant::fromValue(this)},
m_itemViewQuickWidget->rootContext()->setContextProperty(QStringLiteral("highlightColor"), Utils::StyleHelper::notTooBrightHighlightColor()); {"highlightColor", Utils::StyleHelper::notTooBrightHighlightColor()}
}
);
/* create Resources view and its model */ /* create Resources view and its model */
m_resourcesFileSystemModel = new CustomFileSystemModel(this); m_resourcesFileSystemModel = new CustomFileSystemModel(this);

View File

@@ -379,9 +379,12 @@ void PropertyEditorQmlBackend::setup(const QmlObjectNode &qmlObjectNode, const Q
// anchors // anchors
m_backendAnchorBinding.setup(qmlObjectNode.modelNode()); m_backendAnchorBinding.setup(qmlObjectNode.modelNode());
context()->setContextProperty(QLatin1String("anchorBackend"), &m_backendAnchorBinding); context()->setContextProperties(
QVector<QQmlContext::PropertyPair>{
context()->setContextProperty(QLatin1String("transaction"), m_propertyEditorTransaction.data()); {"anchorBackend", QVariant::fromValue(&m_backendAnchorBinding)},
{"transaction", QVariant::fromValue(m_propertyEditorTransaction.data())}
}
);
qCInfo(propertyEditorBenchmark) << "anchors:" << time.elapsed(); qCInfo(propertyEditorBenchmark) << "anchors:" << time.elapsed();
@@ -457,9 +460,13 @@ void PropertyEditorQmlBackend::initialSetup(const TypeName &typeName, const QUrl
QObject::connect(valueObject, &PropertyEditorValue::valueChanged, &backendValuesPropertyMap(), &DesignerPropertyMap::valueChanged); QObject::connect(valueObject, &PropertyEditorValue::valueChanged, &backendValuesPropertyMap(), &DesignerPropertyMap::valueChanged);
m_backendValuesPropertyMap.insert(QLatin1String("id"), QVariant::fromValue(valueObject)); m_backendValuesPropertyMap.insert(QLatin1String("id"), QVariant::fromValue(valueObject));
context()->setContextProperty(QLatin1String("anchorBackend"), &m_backendAnchorBinding); context()->setContextProperties(
context()->setContextProperty(QLatin1String("modelNodeBackend"), &m_backendModelNode); QVector<QQmlContext::PropertyPair>{
context()->setContextProperty(QLatin1String("transaction"), m_propertyEditorTransaction.data()); {"anchorBackend", QVariant::fromValue(&m_backendAnchorBinding)},
{"modelNodeBackend", QVariant::fromValue(&m_backendModelNode)},
{"transaction", QVariant::fromValue(m_propertyEditorTransaction.data())}
}
);
contextObject()->setSpecificsUrl(qmlSpecificsFile); contextObject()->setSpecificsUrl(qmlSpecificsFile);

View File

@@ -102,9 +102,12 @@ StatesEditorWidget::StatesEditorWidget(StatesEditorView *statesEditorView, State
setResizeMode(QQuickWidget::SizeRootObjectToView); setResizeMode(QQuickWidget::SizeRootObjectToView);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
rootContext()->setContextProperty(QStringLiteral("statesEditorModel"), statesEditorModel); rootContext()->setContextProperties(
QVector<QQmlContext::PropertyPair>{
rootContext()->setContextProperty(QLatin1String("canAddNewStates"), true); {"statesEditorModel", QVariant::fromValue(statesEditorModel)},
{"canAddNewStates", true}
}
);
Theme::setupTheme(engine()); Theme::setupTheme(engine());