Commit cb61b50a authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlDesigner.propertyEditor: enables caching for WidgetLoader

parent 1b9c1f8b
...@@ -839,7 +839,7 @@ private: ...@@ -839,7 +839,7 @@ private:
QWidget *m_widget; QWidget *m_widget;
QmlComponent *m_component; QmlComponent *m_component;
QVBoxLayout *m_layout; QVBoxLayout *m_layout;
QHash<QString, QWidget*> m_cachedWidgets;
}; };
QUrl WidgetLoader::source() const QUrl WidgetLoader::source() const
...@@ -872,36 +872,41 @@ void WidgetLoader::setSource(const QUrl &source) ...@@ -872,36 +872,41 @@ void WidgetLoader::setSource(const QUrl &source)
return; return;
} }
m_component = new QmlComponent(qmlEngine(this), m_source, this); if (m_cachedWidgets.contains(source.toString())) {
m_widget = m_cachedWidgets.value(source.toString());
if (m_component) { m_widget->show();
emit sourceChanged(); } else {
emit widgetChanged(); m_component = new QmlComponent(qmlEngine(this), m_source, this);
while (m_component->isLoading())
QApplication::processEvents();
if (!m_component->isReady()) { if (m_component) {
if (!m_component->errors().isEmpty())
qWarning() << m_component->errors();
emit sourceChanged(); emit sourceChanged();
return; emit widgetChanged();
}
QmlContext *ctxt = new QmlContext(qmlContext(this)); while (m_component->isLoading())
ctxt->addDefaultObject(this); QApplication::processEvents();
QObject *obj = m_component->create(ctxt); if (!m_component->isReady()) {
if (obj) { if (!m_component->errors().isEmpty())
QWidget *widget = qobject_cast<QWidget *>(obj); qWarning() << m_component->errors();
if (widget) { emit sourceChanged();
m_widget = widget; return;
m_layout->addWidget(m_widget); }
m_widget->show();
QmlContext *ctxt = new QmlContext(qmlContext(this));
ctxt->addDefaultObject(this);
QObject *obj = m_component->create(ctxt);
if (obj) {
QWidget *widget = qobject_cast<QWidget *>(obj);
if (widget) {
m_cachedWidgets.insert(source.toString(), widget);
m_widget = widget;
m_layout->addWidget(m_widget);
m_widget->show();
}
} }
} }
} }
} }
QWidget *WidgetLoader::widget() const QWidget *WidgetLoader::widget() const
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment