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_itemLibraryModel = new ItemLibraryModel(this);
QQmlContext *rootContext = m_itemViewQuickWidget->rootContext();
rootContext->setContextProperty(QStringLiteral("itemLibraryModel"), m_itemLibraryModel.data());
rootContext->setContextProperty(QStringLiteral("itemLibraryIconWidth"), m_itemIconSize.width());
rootContext->setContextProperty(QStringLiteral("itemLibraryIconHeight"), m_itemIconSize.height());
rootContext->setContextProperty(QStringLiteral("rootView"), this);
m_itemViewQuickWidget->rootContext()->setContextProperty(QStringLiteral("highlightColor"), Utils::StyleHelper::notTooBrightHighlightColor());
m_itemViewQuickWidget->rootContext()->setContextProperties(
QVector<QQmlContext::PropertyPair>{
{"itemLibraryModel", QVariant::fromValue(m_itemLibraryModel.data())},
{"itemLibraryIconWidth", m_itemIconSize.width()},
{"itemLibraryIconHeight", m_itemIconSize.height()},
{"rootView", QVariant::fromValue(this)},
{"highlightColor", Utils::StyleHelper::notTooBrightHighlightColor()}
}
);
/* create Resources view and its model */
m_resourcesFileSystemModel = new CustomFileSystemModel(this);

View File

@@ -379,9 +379,12 @@ void PropertyEditorQmlBackend::setup(const QmlObjectNode &qmlObjectNode, const Q
// anchors
m_backendAnchorBinding.setup(qmlObjectNode.modelNode());
context()->setContextProperty(QLatin1String("anchorBackend"), &m_backendAnchorBinding);
context()->setContextProperty(QLatin1String("transaction"), m_propertyEditorTransaction.data());
context()->setContextProperties(
QVector<QQmlContext::PropertyPair>{
{"anchorBackend", QVariant::fromValue(&m_backendAnchorBinding)},
{"transaction", QVariant::fromValue(m_propertyEditorTransaction.data())}
}
);
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);
m_backendValuesPropertyMap.insert(QLatin1String("id"), QVariant::fromValue(valueObject));
context()->setContextProperty(QLatin1String("anchorBackend"), &m_backendAnchorBinding);
context()->setContextProperty(QLatin1String("modelNodeBackend"), &m_backendModelNode);
context()->setContextProperty(QLatin1String("transaction"), m_propertyEditorTransaction.data());
context()->setContextProperties(
QVector<QQmlContext::PropertyPair>{
{"anchorBackend", QVariant::fromValue(&m_backendAnchorBinding)},
{"modelNodeBackend", QVariant::fromValue(&m_backendModelNode)},
{"transaction", QVariant::fromValue(m_propertyEditorTransaction.data())}
}
);
contextObject()->setSpecificsUrl(qmlSpecificsFile);

View File

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