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.
This commit is contained in:
Lioncache
2025-12-09 15:55:18 -05:00
parent 4c5d15c1c0
commit cb21f39516
2 changed files with 8 additions and 7 deletions

View File

@@ -109,7 +109,7 @@ IProperty* CPropertyModel::PropertyForIndex(const QModelIndex& rkIndex, bool Han
return mProperties[Index].pProperty; 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 // 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. // 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); ASSERT(pProp != nullptr && pProp->Type() == EPropertyType::Array);
} }
if (pProp == mpRootProperty) return QModelIndex(); if (pProp == mpRootProperty)
return QModelIndex();
const int ID = mPropertyToIDMap[pProp]; const int ID = mPropertyToIDMap[pProp];
ASSERT(ID >= 0); ASSERT(ID >= 0);
@@ -405,7 +406,7 @@ QVariant CPropertyModel::data(const QModelIndex& rkIndex, int Role) const
if (!(rkIndex.internalId() & 0x80000000)) if (!(rkIndex.internalId() & 0x80000000))
{ {
// Add name // Add name
IProperty *pProp = PropertyForIndex(rkIndex, false); const IProperty* pProp = PropertyForIndex(rkIndex, false);
const QString DisplayText = data(rkIndex, Qt::DisplayRole).toString(); const QString DisplayText = data(rkIndex, Qt::DisplayRole).toString();
const QString TypeName = QString::fromUtf8(pProp->HashableTypeName()); const QString TypeName = QString::fromUtf8(pProp->HashableTypeName());
QString Text = tr("<b>%1</b> <i>(%2)</i>").arg(DisplayText).arg(TypeName); QString Text = tr("<b>%1</b> <i>(%2)</i>").arg(DisplayText).arg(TypeName);
@@ -518,7 +519,7 @@ Qt::ItemFlags CPropertyModel::flags(const QModelIndex& rkIndex) const
return Qt::ItemIsEnabled | Qt::ItemIsEditable; return Qt::ItemIsEnabled | Qt::ItemIsEditable;
} }
void CPropertyModel::NotifyPropertyModified(class CScriptObject*, IProperty* pProp) void CPropertyModel::NotifyPropertyModified(CScriptObject*, IProperty* pProp)
{ {
NotifyPropertyModified(IndexForProperty(pProp)); NotifyPropertyModified(IndexForProperty(pProp));
} }

View File

@@ -20,7 +20,7 @@ class CPropertyModel : public QAbstractItemModel
std::vector<int> ChildIDs; std::vector<int> ChildIDs;
}; };
QList<SProperty> mProperties; QList<SProperty> mProperties;
QMap<IProperty*, int> mPropertyToIDMap; QMap<const IProperty*, int> mPropertyToIDMap;
int mFirstUnusedID = -1; int mFirstUnusedID = -1;
CGameProject* mpProject = nullptr; CGameProject* mpProject = nullptr;
@@ -40,7 +40,7 @@ public:
void ConfigureIntrinsic(CGameProject* pProject, IProperty* pRootProperty, void* pPropertyData); void ConfigureIntrinsic(CGameProject* pProject, IProperty* pRootProperty, void* pPropertyData);
void ConfigureScript(CGameProject* pProject, IProperty* pRootProperty, CScriptObject* pObject); void ConfigureScript(CGameProject* pProject, IProperty* pRootProperty, CScriptObject* pObject);
IProperty* PropertyForIndex(const QModelIndex& rkIndex, bool HandleFlaggedIndices) const; 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; void* DataPointerForIndex(const QModelIndex& rkIndex) const;
int columnCount(const QModelIndex& rkParent) const override; int columnCount(const QModelIndex& rkParent) const override;
@@ -63,7 +63,7 @@ public:
CScriptObject* GetScriptObject() const { return mpObject; } CScriptObject* GetScriptObject() const { return mpObject; }
public slots: public slots:
void NotifyPropertyModified(class CScriptObject *pInst, IProperty *pProp); void NotifyPropertyModified(CScriptObject *pInst, IProperty *pProp);
void NotifyPropertyModified(const QModelIndex& rkIndex); void NotifyPropertyModified(const QModelIndex& rkIndex);
signals: signals: