From cb21f39516d61816a152498dd00b148b69ec3346 Mon Sep 17 00:00:00 2001 From: Lioncache Date: Tue, 9 Dec 2025 15:55:18 -0500 Subject: [PATCH] CPropertyModel: Pass by const in IndexForProperty() This doesn't need to be so overly restrictive, since it's only being used to query a map. --- src/Editor/PropertyEdit/CPropertyModel.cpp | 9 +++++---- src/Editor/PropertyEdit/CPropertyModel.h | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Editor/PropertyEdit/CPropertyModel.cpp b/src/Editor/PropertyEdit/CPropertyModel.cpp index fb17d9c8..d9b4b239 100644 --- a/src/Editor/PropertyEdit/CPropertyModel.cpp +++ b/src/Editor/PropertyEdit/CPropertyModel.cpp @@ -109,7 +109,7 @@ IProperty* CPropertyModel::PropertyForIndex(const QModelIndex& rkIndex, bool Han return mProperties[Index].pProperty; } -QModelIndex CPropertyModel::IndexForProperty(IProperty *pProp) const +QModelIndex CPropertyModel::IndexForProperty(const IProperty* pProp) const { // Array archetype properties cannot be associated with a single index because the same IProperty // is used for every element of the array. So instead fetch the index for the array itself. @@ -121,7 +121,8 @@ QModelIndex CPropertyModel::IndexForProperty(IProperty *pProp) const ASSERT(pProp != nullptr && pProp->Type() == EPropertyType::Array); } - if (pProp == mpRootProperty) return QModelIndex(); + if (pProp == mpRootProperty) + return QModelIndex(); const int ID = mPropertyToIDMap[pProp]; ASSERT(ID >= 0); @@ -405,7 +406,7 @@ QVariant CPropertyModel::data(const QModelIndex& rkIndex, int Role) const if (!(rkIndex.internalId() & 0x80000000)) { // Add name - IProperty *pProp = PropertyForIndex(rkIndex, false); + const IProperty* pProp = PropertyForIndex(rkIndex, false); const QString DisplayText = data(rkIndex, Qt::DisplayRole).toString(); const QString TypeName = QString::fromUtf8(pProp->HashableTypeName()); QString Text = tr("%1 (%2)").arg(DisplayText).arg(TypeName); @@ -518,7 +519,7 @@ Qt::ItemFlags CPropertyModel::flags(const QModelIndex& rkIndex) const return Qt::ItemIsEnabled | Qt::ItemIsEditable; } -void CPropertyModel::NotifyPropertyModified(class CScriptObject*, IProperty* pProp) +void CPropertyModel::NotifyPropertyModified(CScriptObject*, IProperty* pProp) { NotifyPropertyModified(IndexForProperty(pProp)); } diff --git a/src/Editor/PropertyEdit/CPropertyModel.h b/src/Editor/PropertyEdit/CPropertyModel.h index 165f9b2b..315f4c08 100644 --- a/src/Editor/PropertyEdit/CPropertyModel.h +++ b/src/Editor/PropertyEdit/CPropertyModel.h @@ -20,7 +20,7 @@ class CPropertyModel : public QAbstractItemModel std::vector ChildIDs; }; QList mProperties; - QMap mPropertyToIDMap; + QMap mPropertyToIDMap; int mFirstUnusedID = -1; CGameProject* mpProject = nullptr; @@ -40,7 +40,7 @@ public: void ConfigureIntrinsic(CGameProject* pProject, IProperty* pRootProperty, void* pPropertyData); void ConfigureScript(CGameProject* pProject, IProperty* pRootProperty, CScriptObject* pObject); IProperty* PropertyForIndex(const QModelIndex& rkIndex, bool HandleFlaggedIndices) const; - QModelIndex IndexForProperty(IProperty *pProp) const; + QModelIndex IndexForProperty(const IProperty* pProp) const; void* DataPointerForIndex(const QModelIndex& rkIndex) const; int columnCount(const QModelIndex& rkParent) const override; @@ -63,7 +63,7 @@ public: CScriptObject* GetScriptObject() const { return mpObject; } public slots: - void NotifyPropertyModified(class CScriptObject *pInst, IProperty *pProp); + void NotifyPropertyModified(CScriptObject *pInst, IProperty *pProp); void NotifyPropertyModified(const QModelIndex& rkIndex); signals: