forked from qt-creator/qt-creator
QmlDesigner: Disable 'add to selected model' option when it's not valid
MaterialBrowserTexturesModel's hasSingleModelSelection property value is now updated at context menu open, as that's the only place using it. This is similar to how hasSceneEnv is handled. Fixes: QDS-8582 Change-Id: I63871a5557c90a06633eee52840b267d808bfe27 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -193,6 +193,13 @@ WidgetInfo MaterialBrowserView::widgetInfo()
|
||||
m_widget->materialBrowserTexturesModel()->setHasSceneEnv(sceneEnvExists);
|
||||
});
|
||||
|
||||
connect(texturesModel, &MaterialBrowserTexturesModel::updateModelSelectionStateRequested, this, [&]() {
|
||||
bool hasModel = false;
|
||||
if (m_selectedModels.size() == 1)
|
||||
hasModel = getMaterialOfModel(m_selectedModels.at(0)).isValid();
|
||||
m_widget->materialBrowserTexturesModel()->setHasSingleModelSelection(hasModel);
|
||||
});
|
||||
|
||||
connect(texturesModel, &MaterialBrowserTexturesModel::applyAsLightProbeRequested, this,
|
||||
[&] (const ModelNode &texture) {
|
||||
executeInTransaction(__FUNCTION__, [&] {
|
||||
@@ -290,7 +297,6 @@ void MaterialBrowserView::selectedNodesChanged(const QList<ModelNode> &selectedN
|
||||
});
|
||||
|
||||
m_widget->materialBrowserModel()->setHasModelSelection(!m_selectedModels.isEmpty());
|
||||
m_widget->materialBrowserTexturesModel()->setHasSingleModelSelection(m_selectedModels.size() == 1);
|
||||
|
||||
// the logic below selects the material of the first selected model if auto selection is on
|
||||
if (!m_autoSelectModelMaterial)
|
||||
@@ -299,13 +305,8 @@ void MaterialBrowserView::selectedNodesChanged(const QList<ModelNode> &selectedN
|
||||
if (selectedNodeList.size() > 1 || m_selectedModels.isEmpty())
|
||||
return;
|
||||
|
||||
QmlObjectNode qmlObjNode(m_selectedModels.at(0));
|
||||
QString matExp = qmlObjNode.expression("materials");
|
||||
if (matExp.isEmpty())
|
||||
return;
|
||||
ModelNode mat = getMaterialOfModel(m_selectedModels.at(0));
|
||||
|
||||
QString matId = matExp.remove('[').remove(']').split(',', Qt::SkipEmptyParts).at(0);
|
||||
ModelNode mat = modelNodeForId(matId);
|
||||
if (!mat.isValid())
|
||||
return;
|
||||
|
||||
@@ -435,6 +436,25 @@ void MaterialBrowserView::requestPreviews()
|
||||
m_previewRequests.clear();
|
||||
}
|
||||
|
||||
ModelNode MaterialBrowserView::getMaterialOfModel(const ModelNode &model)
|
||||
{
|
||||
QmlObjectNode qmlObjNode(model);
|
||||
QString matExp = qmlObjNode.expression("materials");
|
||||
if (matExp.isEmpty())
|
||||
return {};
|
||||
|
||||
const QStringList mats = matExp.remove('[').remove(']').split(',', Qt::SkipEmptyParts);
|
||||
if (mats.isEmpty())
|
||||
return {};
|
||||
|
||||
for (const auto &matId : mats) {
|
||||
ModelNode mat = modelNodeForId(matId);
|
||||
if (mat.isValid())
|
||||
return mat;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void MaterialBrowserView::importsChanged([[maybe_unused]] const QList<Import> &addedImports,
|
||||
[[maybe_unused]] const QList<Import> &removedImports)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user