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 var currentMaterial: null
|
||||||
property int currentMaterialIdx: 0
|
property int currentMaterialIdx: 0
|
||||||
property var currentBundleMaterial: null
|
property var currentBundleMaterial: null
|
||||||
|
property int copiedMaterialInternalId: -1
|
||||||
|
|
||||||
property var matSectionsModel: []
|
property var matSectionsModel: []
|
||||||
|
|
||||||
@@ -147,15 +148,20 @@ Item {
|
|||||||
StudioControls.MenuItem {
|
StudioControls.MenuItem {
|
||||||
text: modelData
|
text: modelData
|
||||||
enabled: root.currentMaterial
|
enabled: root.currentMaterial
|
||||||
onTriggered: materialBrowserModel.copyMaterialProperties(root.currentMaterialIdx, modelData)
|
onTriggered: {
|
||||||
|
root.copiedMaterialInternalId = root.currentMaterial.materialInternalId
|
||||||
|
materialBrowserModel.copyMaterialProperties(root.currentMaterialIdx, modelData)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StudioControls.MenuItem {
|
StudioControls.MenuItem {
|
||||||
text: qsTr("Paste properties")
|
text: qsTr("Paste properties")
|
||||||
enabled: root.currentMaterial && root.currentMaterial.materialType
|
enabled: root.currentMaterial
|
||||||
=== materialBrowserModel.copiedMaterialType
|
&& root.copiedMaterialInternalId !== root.currentMaterial.materialInternalId
|
||||||
|
&& root.currentMaterial.materialType === materialBrowserModel.copiedMaterialType
|
||||||
|
&& materialBrowserModel.isCopiedMaterialValid()
|
||||||
onTriggered: materialBrowserModel.pasteMaterialProperties(root.currentMaterialIdx)
|
onTriggered: materialBrowserModel.pasteMaterialProperties(root.currentMaterialIdx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -348,8 +348,8 @@ void MaterialBrowserModel::duplicateMaterial(int idx)
|
|||||||
|
|
||||||
void MaterialBrowserModel::copyMaterialProperties(int idx, const QString §ion)
|
void MaterialBrowserModel::copyMaterialProperties(int idx, const QString §ion)
|
||||||
{
|
{
|
||||||
ModelNode mat = m_materialList.at(idx);
|
m_copiedMaterial = m_materialList.at(idx);
|
||||||
QString matType = QString::fromLatin1(mat.type());
|
QString matType = QString::fromLatin1(m_copiedMaterial.type());
|
||||||
|
|
||||||
if (matType.startsWith("QtQuick3D."))
|
if (matType.startsWith("QtQuick3D."))
|
||||||
matType.remove("QtQuick3D.");
|
matType.remove("QtQuick3D.");
|
||||||
@@ -358,7 +358,7 @@ void MaterialBrowserModel::copyMaterialProperties(int idx, const QString §io
|
|||||||
m_allPropsCopied = section == "All";
|
m_allPropsCopied = section == "All";
|
||||||
|
|
||||||
if (m_allPropsCopied || m_propertyGroupsObj.empty()) {
|
if (m_allPropsCopied || m_propertyGroupsObj.empty()) {
|
||||||
m_copiedMaterialProps = mat.properties();
|
m_copiedMaterialProps = m_copiedMaterial.properties();
|
||||||
} else {
|
} else {
|
||||||
QJsonObject propsSpecObj = m_propertyGroupsObj.value(m_copiedMaterialType).toObject();
|
QJsonObject propsSpecObj = m_propertyGroupsObj.value(m_copiedMaterialType).toObject();
|
||||||
if (propsSpecObj.contains(section)) { // should always be true
|
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();
|
const QJsonArray propNames = propsSpecObj.value(section).toArray();
|
||||||
// auto == QJsonValueConstRef after 04dc959d49e5e3 / Qt 6.4, QJsonValueRef before
|
// auto == QJsonValueConstRef after 04dc959d49e5e3 / Qt 6.4, QJsonValueRef before
|
||||||
for (const auto &propName : propNames)
|
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
|
if (section == "Base") { // add QtQuick3D.Material base props as well
|
||||||
QJsonObject propsMatObj = m_propertyGroupsObj.value("Material").toObject();
|
QJsonObject propsMatObj = m_propertyGroupsObj.value("Material").toObject();
|
||||||
const QJsonArray propNames = propsMatObj.value("Base").toArray();
|
const QJsonArray propNames = propsMatObj.value("Base").toArray();
|
||||||
// auto == QJsonValueConstRef after 04dc959d49e5e3 / Qt 6.4, QJsonValueRef before
|
// auto == QJsonValueConstRef after 04dc959d49e5e3 / Qt 6.4, QJsonValueRef before
|
||||||
for (const auto &propName : propNames)
|
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)
|
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)
|
void MaterialBrowserModel::deleteMaterial(int idx)
|
||||||
@@ -418,4 +420,11 @@ void MaterialBrowserModel::openMaterialEditor()
|
|||||||
QmlDesignerPlugin::instance()->mainWidget()->showDockWidget("MaterialEditor", true);
|
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
|
} // namespace QmlDesigner
|
||||||
|
@@ -92,6 +92,7 @@ public:
|
|||||||
Q_INVOKABLE void addNewMaterial();
|
Q_INVOKABLE void addNewMaterial();
|
||||||
Q_INVOKABLE void applyToSelected(qint64 internalId, bool add = false);
|
Q_INVOKABLE void applyToSelected(qint64 internalId, bool add = false);
|
||||||
Q_INVOKABLE void openMaterialEditor();
|
Q_INVOKABLE void openMaterialEditor();
|
||||||
|
Q_INVOKABLE bool isCopiedMaterialValid() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void isEmptyChanged();
|
void isEmptyChanged();
|
||||||
@@ -118,6 +119,7 @@ private:
|
|||||||
QStringList m_defaultMaterialSections;
|
QStringList m_defaultMaterialSections;
|
||||||
QStringList m_principledMaterialSections;
|
QStringList m_principledMaterialSections;
|
||||||
QStringList m_customMaterialSections;
|
QStringList m_customMaterialSections;
|
||||||
|
ModelNode m_copiedMaterial;
|
||||||
QList<AbstractProperty> m_copiedMaterialProps;
|
QList<AbstractProperty> m_copiedMaterialProps;
|
||||||
QHash<qint32, int> m_materialIndexHash; // internalId -> index
|
QHash<qint32, int> m_materialIndexHash; // internalId -> index
|
||||||
QJsonObject m_propertyGroupsObj;
|
QJsonObject m_propertyGroupsObj;
|
||||||
|
@@ -110,7 +110,7 @@ WidgetInfo MaterialBrowserView::widgetInfo()
|
|||||||
|
|
||||||
// apply pasted properties
|
// apply pasted properties
|
||||||
for (const AbstractProperty &prop : props) {
|
for (const AbstractProperty &prop : props) {
|
||||||
if (prop.name() == "objectName")
|
if (prop.name() == "objectName" || !prop.isValid())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (prop.isVariantProperty())
|
if (prop.isVariantProperty())
|
||||||
|
Reference in New Issue
Block a user