QmlDesigner: Parse material library on model attach

Parsing has to happen so material in an old project are correctly
appearing in the material views. Using a timer to wait until it is ok
to create the material editor node. Otherwise errors happen.

Change-Id: I54b532211f8a865c5183fab0fd8c12e5f15b983a
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Mahmoud Badri
2022-06-15 16:54:31 +03:00
parent 568004e121
commit d080e6331f
2 changed files with 13 additions and 2 deletions

View File

@@ -73,6 +73,13 @@ MaterialEditorView::MaterialEditorView(QWidget *parent)
m_updateShortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F7), m_stackedWidget); m_updateShortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F7), m_stackedWidget);
connect(m_updateShortcut, &QShortcut::activated, this, &MaterialEditorView::reloadQml); connect(m_updateShortcut, &QShortcut::activated, this, &MaterialEditorView::reloadQml);
m_ensureMatLibTimer.callOnTimeout([this] {
if (model() && model()->rewriterView() && !model()->rewriterView()->hasIncompleteTypeInformation()) {
materialLibraryNode(); // create the material library node
m_ensureMatLibTimer.stop();
}
});
m_stackedWidget->setStyleSheet(Theme::replaceCssColors( m_stackedWidget->setStyleSheet(Theme::replaceCssColors(
QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css")))); QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css"))));
m_stackedWidget->setMinimumWidth(250); m_stackedWidget->setMinimumWidth(250);
@@ -524,6 +531,11 @@ void MaterialEditorView::modelAttached(Model *model)
m_hasQuick3DImport = model->hasImport("QtQuick3D"); m_hasQuick3DImport = model->hasImport("QtQuick3D");
// Creating the material library node on model attach causes errors as long as the type information
// not complete yet, so we keep checking until type info is complete.
if (m_hasQuick3DImport)
m_ensureMatLibTimer.start(500);
if (!m_setupCompleted) { if (!m_setupCompleted) {
reloadQml(); reloadQml();
m_setupCompleted = true; m_setupCompleted = true;
@@ -537,8 +549,6 @@ void MaterialEditorView::modelAboutToBeDetached(Model *model)
{ {
AbstractView::modelAboutToBeDetached(model); AbstractView::modelAboutToBeDetached(model);
m_qmlBackEnd->materialEditorTransaction()->end(); m_qmlBackEnd->materialEditorTransaction()->end();
} }
void MaterialEditorView::propertiesRemoved(const QList<AbstractProperty> &propertyList) void MaterialEditorView::propertiesRemoved(const QList<AbstractProperty> &propertyList)

View File

@@ -114,6 +114,7 @@ private:
bool noValidSelection() const; bool noValidSelection() const;
ModelNode m_selectedMaterial; ModelNode m_selectedMaterial;
QTimer m_ensureMatLibTimer;
QShortcut *m_updateShortcut = nullptr; QShortcut *m_updateShortcut = nullptr;
int m_timerId = 0; int m_timerId = 0;
QStackedWidget *m_stackedWidget = nullptr; QStackedWidget *m_stackedWidget = nullptr;