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:
@@ -16,6 +16,7 @@ StudioControls.Menu {
|
||||
{
|
||||
this.targetTexture = targetTexture
|
||||
materialBrowserTexturesModel.updateSceneEnvState()
|
||||
materialBrowserTexturesModel.updateModelSelectionState()
|
||||
popup()
|
||||
}
|
||||
|
||||
|
||||
@@ -316,4 +316,9 @@ void MaterialBrowserTexturesModel::applyAsLightProbe(qint64 internalId)
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialBrowserTexturesModel::updateModelSelectionState()
|
||||
{
|
||||
emit updateModelSelectionStateRequested();
|
||||
}
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
||||
@@ -16,8 +16,7 @@ class MaterialBrowserTexturesModel : public QAbstractListModel
|
||||
|
||||
Q_PROPERTY(bool isEmpty MEMBER m_isEmpty NOTIFY isEmptyChanged)
|
||||
Q_PROPERTY(int selectedIndex MEMBER m_selectedIndex NOTIFY selectedIndexChanged)
|
||||
Q_PROPERTY(bool hasSingleModelSelection READ hasSingleModelSelection
|
||||
WRITE setHasSingleModelSelection NOTIFY hasSingleModelSelectionChanged)
|
||||
Q_PROPERTY(bool hasSingleModelSelection READ hasSingleModelSelection NOTIFY hasSingleModelSelectionChanged)
|
||||
Q_PROPERTY(bool hasSceneEnv READ hasSceneEnv NOTIFY hasSceneEnvChanged)
|
||||
|
||||
public:
|
||||
@@ -60,6 +59,7 @@ public:
|
||||
Q_INVOKABLE void applyToSelectedModel(qint64 internalId);
|
||||
Q_INVOKABLE void openTextureEditor();
|
||||
Q_INVOKABLE void updateSceneEnvState();
|
||||
Q_INVOKABLE void updateModelSelectionState();
|
||||
Q_INVOKABLE void applyAsLightProbe(qint64 internalId);
|
||||
|
||||
signals:
|
||||
@@ -71,6 +71,7 @@ signals:
|
||||
void applyToSelectedModelTriggered(const QmlDesigner::ModelNode &texture);
|
||||
void addNewTextureTriggered();
|
||||
void updateSceneEnvStateRequested();
|
||||
void updateModelSelectionStateRequested();
|
||||
void hasSceneEnvChanged();
|
||||
void applyAsLightProbeRequested(const QmlDesigner::ModelNode &texture);
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -70,6 +70,7 @@ private:
|
||||
void loadPropertyGroups();
|
||||
void requestPreviews();
|
||||
ModelNode resolveSceneEnv();
|
||||
ModelNode getMaterialOfModel(const ModelNode &model);
|
||||
|
||||
AsynchronousImageCache &m_imageCache;
|
||||
QPointer<MaterialBrowserWidget> m_widget;
|
||||
|
||||
Reference in New Issue
Block a user