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();
|
m_previewRequests.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
ModelNode MaterialBrowserView::getMaterialOfModel(const ModelNode &model)
|
ModelNode MaterialBrowserView::getMaterialOfModel(const ModelNode &model, int idx)
|
||||||
{
|
{
|
||||||
QmlObjectNode qmlObjNode(model);
|
QmlObjectNode qmlObjNode(model);
|
||||||
QString matExp = qmlObjNode.expression("materials");
|
QString matExp = qmlObjNode.expression("materials");
|
||||||
@@ -463,12 +463,10 @@ ModelNode MaterialBrowserView::getMaterialOfModel(const ModelNode &model)
|
|||||||
if (mats.isEmpty())
|
if (mats.isEmpty())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
for (const auto &matId : mats) {
|
ModelNode mat = modelNodeForId(mats.at(idx));
|
||||||
ModelNode mat = modelNodeForId(matId);
|
QTC_ASSERT(mat.isValid(), return {});
|
||||||
if (mat.isValid())
|
|
||||||
return mat;
|
return mat;
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaterialBrowserView::importsChanged([[maybe_unused]] const QList<Import> &addedImports,
|
void MaterialBrowserView::importsChanged([[maybe_unused]] const QList<Import> &addedImports,
|
||||||
@@ -496,7 +494,17 @@ void MaterialBrowserView::customNotification(const AbstractView *view,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (identifier == "select_material") {
|
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)
|
if (idx != -1)
|
||||||
m_widget->materialBrowserModel()->selectMaterial(idx);
|
m_widget->materialBrowserModel()->selectMaterial(idx);
|
||||||
} else if (identifier == "select_texture") {
|
} else if (identifier == "select_texture") {
|
||||||
|
@@ -71,7 +71,7 @@ private:
|
|||||||
void loadPropertyGroups();
|
void loadPropertyGroups();
|
||||||
void requestPreviews();
|
void requestPreviews();
|
||||||
ModelNode resolveSceneEnv();
|
ModelNode resolveSceneEnv();
|
||||||
ModelNode getMaterialOfModel(const ModelNode &model);
|
ModelNode getMaterialOfModel(const ModelNode &model, int idx = 0);
|
||||||
|
|
||||||
AsynchronousImageCache &m_imageCache;
|
AsynchronousImageCache &m_imageCache;
|
||||||
QPointer<MaterialBrowserWidget> m_widget;
|
QPointer<MaterialBrowserWidget> m_widget;
|
||||||
|
Reference in New Issue
Block a user