forked from qt-creator/qt-creator
QmlDesigner: Implement copy/paste material properties
Fixes: QDS-7014 Change-Id: I2a8b779f97de353836a4d506b715720b490c349f Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Samuel Ghinet <samuel.ghinet@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
@@ -24,9 +24,13 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "materialbrowsermodel.h"
|
||||
#include "variantproperty.h"
|
||||
|
||||
#include <bindingproperty.h>
|
||||
#include <designmodewidget.h>
|
||||
#include <qmldesignerplugin.h>
|
||||
#include <qmlobjectnode.h>
|
||||
#include "variantproperty.h"
|
||||
#include "utils/qtcassert.h"
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
@@ -46,24 +50,23 @@ int MaterialBrowserModel::rowCount(const QModelIndex &) const
|
||||
|
||||
QVariant MaterialBrowserModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || index.row() >= m_materialList.count()) {
|
||||
qWarning() << Q_FUNC_INFO << "invalid index requested";
|
||||
return {};
|
||||
}
|
||||
QTC_ASSERT(index.isValid() && index.row() < m_materialList.count(), return {});
|
||||
QTC_ASSERT(roleNames().contains(role), return {});
|
||||
|
||||
if (roleNames().value(role) == "materialName") {
|
||||
QByteArray roleName = roleNames().value(role);
|
||||
if (roleName == "materialName") {
|
||||
QVariant objName = m_materialList.at(index.row()).variantProperty("objectName").value();
|
||||
return objName.isValid() ? objName : "";
|
||||
}
|
||||
|
||||
if (roleNames().value(role) == "materialInternalId")
|
||||
if (roleName == "materialInternalId")
|
||||
return m_materialList.at(index.row()).internalId();
|
||||
|
||||
if (roleNames().value(role) == "materialVisible")
|
||||
if (roleName == "materialVisible")
|
||||
return isMaterialVisible(index.row());
|
||||
|
||||
if (!roleNames().contains(role))
|
||||
qWarning() << Q_FUNC_INFO << "invalid role requested";
|
||||
if (roleName == "materialType")
|
||||
return m_materialList.at(index.row()).type();
|
||||
|
||||
return {};
|
||||
}
|
||||
@@ -88,6 +91,7 @@ QHash<int, QByteArray> MaterialBrowserModel::roleNames() const
|
||||
{Qt::UserRole + 1, "materialName"},
|
||||
{Qt::UserRole + 2, "materialInternalId"},
|
||||
{Qt::UserRole + 3, "materialVisible"},
|
||||
{Qt::UserRole + 4, "materialType"}
|
||||
};
|
||||
return roles;
|
||||
}
|
||||
@@ -120,6 +124,20 @@ void MaterialBrowserModel::setHasModelSelection(bool b)
|
||||
emit hasModelSelectionChanged();
|
||||
}
|
||||
|
||||
TypeName MaterialBrowserModel::copiedMaterialType() const
|
||||
{
|
||||
return m_copiedMaterialType;
|
||||
}
|
||||
|
||||
void MaterialBrowserModel::setCopiedMaterialType(const TypeName &matType)
|
||||
{
|
||||
if (matType == m_copiedMaterialType)
|
||||
return;
|
||||
|
||||
m_copiedMaterialType = matType;
|
||||
emit copiedMaterialTypeChanged();
|
||||
}
|
||||
|
||||
QList<ModelNode> MaterialBrowserModel::materials() const
|
||||
{
|
||||
return m_materialList;
|
||||
@@ -262,6 +280,18 @@ void MaterialBrowserModel::duplicateMaterial(int idx)
|
||||
emit duplicateMaterialTriggered(m_materialList.at(idx));
|
||||
}
|
||||
|
||||
void MaterialBrowserModel::copyMaterialProperties(int idx)
|
||||
{
|
||||
ModelNode mat = m_materialList.at(idx);
|
||||
m_copiedMaterialProps = mat.properties();
|
||||
setCopiedMaterialType(mat.type());
|
||||
}
|
||||
|
||||
void MaterialBrowserModel::pasteMaterialProperties(int idx)
|
||||
{
|
||||
emit pasteMaterialPropertiesTriggered(m_materialList.at(idx), m_copiedMaterialProps);
|
||||
}
|
||||
|
||||
void MaterialBrowserModel::deleteMaterial(int idx)
|
||||
{
|
||||
m_materialList[idx].destroy();
|
||||
|
||||
Reference in New Issue
Block a user