forked from qt-creator/qt-creator
QmlDesigner: Disable paste option for the original material
Fixes: QDS-7526 Change-Id: Ifdc220685a4881dc3a397d9148022b9be7b5032a Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -39,6 +39,7 @@ Item {
|
||||
property var currentMaterial: null
|
||||
property int currentMaterialIdx: 0
|
||||
property var currentBundleMaterial: null
|
||||
property int copiedMaterialInternalId: -1
|
||||
|
||||
property var matSectionsModel: []
|
||||
|
||||
@@ -147,15 +148,20 @@ Item {
|
||||
StudioControls.MenuItem {
|
||||
text: modelData
|
||||
enabled: root.currentMaterial
|
||||
onTriggered: materialBrowserModel.copyMaterialProperties(root.currentMaterialIdx, modelData)
|
||||
onTriggered: {
|
||||
root.copiedMaterialInternalId = root.currentMaterial.materialInternalId
|
||||
materialBrowserModel.copyMaterialProperties(root.currentMaterialIdx, modelData)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StudioControls.MenuItem {
|
||||
text: qsTr("Paste properties")
|
||||
enabled: root.currentMaterial && root.currentMaterial.materialType
|
||||
=== materialBrowserModel.copiedMaterialType
|
||||
enabled: root.currentMaterial
|
||||
&& root.copiedMaterialInternalId !== root.currentMaterial.materialInternalId
|
||||
&& root.currentMaterial.materialType === materialBrowserModel.copiedMaterialType
|
||||
&& materialBrowserModel.isCopiedMaterialValid()
|
||||
onTriggered: materialBrowserModel.pasteMaterialProperties(root.currentMaterialIdx)
|
||||
}
|
||||
|
||||
|
@@ -348,8 +348,8 @@ void MaterialBrowserModel::duplicateMaterial(int idx)
|
||||
|
||||
void MaterialBrowserModel::copyMaterialProperties(int idx, const QString §ion)
|
||||
{
|
||||
ModelNode mat = m_materialList.at(idx);
|
||||
QString matType = QString::fromLatin1(mat.type());
|
||||
m_copiedMaterial = m_materialList.at(idx);
|
||||
QString matType = QString::fromLatin1(m_copiedMaterial.type());
|
||||
|
||||
if (matType.startsWith("QtQuick3D."))
|
||||
matType.remove("QtQuick3D.");
|
||||
@@ -358,7 +358,7 @@ void MaterialBrowserModel::copyMaterialProperties(int idx, const QString §io
|
||||
m_allPropsCopied = section == "All";
|
||||
|
||||
if (m_allPropsCopied || m_propertyGroupsObj.empty()) {
|
||||
m_copiedMaterialProps = mat.properties();
|
||||
m_copiedMaterialProps = m_copiedMaterial.properties();
|
||||
} else {
|
||||
QJsonObject propsSpecObj = m_propertyGroupsObj.value(m_copiedMaterialType).toObject();
|
||||
if (propsSpecObj.contains(section)) { // should always be true
|
||||
@@ -366,14 +366,14 @@ void MaterialBrowserModel::copyMaterialProperties(int idx, const QString §io
|
||||
const QJsonArray propNames = propsSpecObj.value(section).toArray();
|
||||
// auto == QJsonValueConstRef after 04dc959d49e5e3 / Qt 6.4, QJsonValueRef before
|
||||
for (const auto &propName : propNames)
|
||||
m_copiedMaterialProps.append(mat.property(propName.toString().toLatin1()));
|
||||
m_copiedMaterialProps.append(m_copiedMaterial.property(propName.toString().toLatin1()));
|
||||
|
||||
if (section == "Base") { // add QtQuick3D.Material base props as well
|
||||
QJsonObject propsMatObj = m_propertyGroupsObj.value("Material").toObject();
|
||||
const QJsonArray propNames = propsMatObj.value("Base").toArray();
|
||||
// auto == QJsonValueConstRef after 04dc959d49e5e3 / Qt 6.4, QJsonValueRef before
|
||||
for (const auto &propName : propNames)
|
||||
m_copiedMaterialProps.append(mat.property(propName.toString().toLatin1()));
|
||||
m_copiedMaterialProps.append(m_copiedMaterial.property(propName.toString().toLatin1()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -381,7 +381,9 @@ void MaterialBrowserModel::copyMaterialProperties(int idx, const QString §io
|
||||
|
||||
void MaterialBrowserModel::pasteMaterialProperties(int idx)
|
||||
{
|
||||
emit pasteMaterialPropertiesTriggered(m_materialList.at(idx), m_copiedMaterialProps, m_allPropsCopied);
|
||||
ModelNode targetMat = m_materialList.at(idx);
|
||||
if (targetMat.isValid() && m_copiedMaterial.isValid() && targetMat != m_copiedMaterial)
|
||||
emit pasteMaterialPropertiesTriggered(targetMat, m_copiedMaterialProps, m_allPropsCopied);
|
||||
}
|
||||
|
||||
void MaterialBrowserModel::deleteMaterial(int idx)
|
||||
@@ -418,4 +420,11 @@ void MaterialBrowserModel::openMaterialEditor()
|
||||
QmlDesignerPlugin::instance()->mainWidget()->showDockWidget("MaterialEditor", true);
|
||||
}
|
||||
|
||||
// This is provided as invokable instead of property, as it is difficult to know when ModelNode
|
||||
// becomes invalid. Much simpler to evaluate this on demand.
|
||||
bool MaterialBrowserModel::isCopiedMaterialValid() const
|
||||
{
|
||||
return m_copiedMaterial.isValid();
|
||||
}
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
@@ -92,6 +92,7 @@ public:
|
||||
Q_INVOKABLE void addNewMaterial();
|
||||
Q_INVOKABLE void applyToSelected(qint64 internalId, bool add = false);
|
||||
Q_INVOKABLE void openMaterialEditor();
|
||||
Q_INVOKABLE bool isCopiedMaterialValid() const;
|
||||
|
||||
signals:
|
||||
void isEmptyChanged();
|
||||
@@ -118,6 +119,7 @@ private:
|
||||
QStringList m_defaultMaterialSections;
|
||||
QStringList m_principledMaterialSections;
|
||||
QStringList m_customMaterialSections;
|
||||
ModelNode m_copiedMaterial;
|
||||
QList<AbstractProperty> m_copiedMaterialProps;
|
||||
QHash<qint32, int> m_materialIndexHash; // internalId -> index
|
||||
QJsonObject m_propertyGroupsObj;
|
||||
|
@@ -110,7 +110,7 @@ WidgetInfo MaterialBrowserView::widgetInfo()
|
||||
|
||||
// apply pasted properties
|
||||
for (const AbstractProperty &prop : props) {
|
||||
if (prop.name() == "objectName")
|
||||
if (prop.name() == "objectName" || !prop.isValid())
|
||||
continue;
|
||||
|
||||
if (prop.isVariantProperty())
|
||||
|
Reference in New Issue
Block a user