forked from qt-creator/qt-creator
QmlDesigner: Allow selecting a material at idx via a custom notif
Will be used for opening material editor from a material row in a Quick3DModel's properties sheet. Task-number: QDS-9408 Change-Id: Ia23703c2c1ffb6bd4a17db27b415dbabb2a0c642 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
@@ -452,7 +452,7 @@ void MaterialBrowserView::requestPreviews()
|
||||
m_previewRequests.clear();
|
||||
}
|
||||
|
||||
ModelNode MaterialBrowserView::getMaterialOfModel(const ModelNode &model)
|
||||
ModelNode MaterialBrowserView::getMaterialOfModel(const ModelNode &model, int idx)
|
||||
{
|
||||
QmlObjectNode qmlObjNode(model);
|
||||
QString matExp = qmlObjNode.expression("materials");
|
||||
@@ -463,12 +463,10 @@ ModelNode MaterialBrowserView::getMaterialOfModel(const ModelNode &model)
|
||||
if (mats.isEmpty())
|
||||
return {};
|
||||
|
||||
for (const auto &matId : mats) {
|
||||
ModelNode mat = modelNodeForId(matId);
|
||||
if (mat.isValid())
|
||||
return mat;
|
||||
}
|
||||
return {};
|
||||
ModelNode mat = modelNodeForId(mats.at(idx));
|
||||
QTC_ASSERT(mat.isValid(), return {});
|
||||
|
||||
return mat;
|
||||
}
|
||||
|
||||
void MaterialBrowserView::importsChanged([[maybe_unused]] const QList<Import> &addedImports,
|
||||
@@ -496,7 +494,17 @@ void MaterialBrowserView::customNotification(const AbstractView *view,
|
||||
return;
|
||||
|
||||
if (identifier == "select_material") {
|
||||
int idx = m_widget->materialBrowserModel()->materialIndex(nodeList.first());
|
||||
ModelNode matNode;
|
||||
if (!data.isEmpty() && !m_selectedModels.isEmpty()) {
|
||||
ModelNode model3D = m_selectedModels.at(0);
|
||||
QTC_ASSERT(model3D.isValid(), return);
|
||||
matNode = getMaterialOfModel(model3D, data[0].toInt());
|
||||
} else {
|
||||
matNode = nodeList.first();
|
||||
}
|
||||
QTC_ASSERT(matNode.isValid(), return);
|
||||
|
||||
int idx = m_widget->materialBrowserModel()->materialIndex(matNode);
|
||||
if (idx != -1)
|
||||
m_widget->materialBrowserModel()->selectMaterial(idx);
|
||||
} else if (identifier == "select_texture") {
|
||||
|
@@ -71,7 +71,7 @@ private:
|
||||
void loadPropertyGroups();
|
||||
void requestPreviews();
|
||||
ModelNode resolveSceneEnv();
|
||||
ModelNode getMaterialOfModel(const ModelNode &model);
|
||||
ModelNode getMaterialOfModel(const ModelNode &model, int idx = 0);
|
||||
|
||||
AsynchronousImageCache &m_imageCache;
|
||||
QPointer<MaterialBrowserWidget> m_widget;
|
||||
|
Reference in New Issue
Block a user