From a25430eec36a4940556a952390183ab4dd05a13a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 22 Jun 2020 23:14:58 -0400 Subject: [PATCH] CEnumProperty: Make use of size_t where applicable --- .../Resource/Script/Property/CEnumProperty.h | 24 ++++++++++--------- src/Editor/PropertyEdit/CPropertyDelegate.cpp | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Core/Resource/Script/Property/CEnumProperty.h b/src/Core/Resource/Script/Property/CEnumProperty.h index 83b47fbf..7d90d996 100644 --- a/src/Core/Resource/Script/Property/CEnumProperty.h +++ b/src/Core/Resource/Script/Property/CEnumProperty.h @@ -108,10 +108,10 @@ public: void AddValue(TString ValueName, uint32 ValueID) { - mValues.push_back( SEnumValue(ValueName, ValueID) ); + mValues.emplace_back(std::move(ValueName), ValueID); } - uint32 NumPossibleValues() const { return mValues.size(); } + size_t NumPossibleValues() const { return mValues.size(); } uint32 ValueIndex(uint32 ID) const { @@ -122,27 +122,29 @@ public: return ValueIdx; } } - return -1; + return UINT32_MAX; } - uint32 ValueID(uint32 Index) const + uint32 ValueID(size_t Index) const { - ASSERT(Index >= 0 && Index < mValues.size()); + ASSERT(Index < mValues.size()); return mValues[Index].ID; } - TString ValueName(uint32 Index) const + TString ValueName(size_t Index) const { - ASSERT(Index >= 0 && Index < mValues.size()); + ASSERT(Index < mValues.size()); return mValues[Index].Name; } bool HasValidValue(void* pPropertyData) { - if (mValues.empty()) return true; - int ID = base::ValueRef(pPropertyData); - uint32 Index = ValueIndex(ID); - return Index >= 0 && Index < mValues.size(); + if (mValues.empty()) + return true; + + const int ID = base::ValueRef(pPropertyData); + const uint32 Index = ValueIndex(ID); + return Index < mValues.size(); } bool OverridesTypeName() const diff --git a/src/Editor/PropertyEdit/CPropertyDelegate.cpp b/src/Editor/PropertyEdit/CPropertyDelegate.cpp index b2b4e80b..10dcea2d 100644 --- a/src/Editor/PropertyEdit/CPropertyDelegate.cpp +++ b/src/Editor/PropertyEdit/CPropertyDelegate.cpp @@ -132,7 +132,7 @@ QWidget* CPropertyDelegate::createEditor(QWidget* pParent, const QStyleOptionVie QComboBox *pComboBox = new QComboBox(pParent); CEnumProperty* pEnum = TPropCast(pProp); - for (uint32 ValueIdx = 0; ValueIdx < pEnum->NumPossibleValues(); ValueIdx++) + for (size_t ValueIdx = 0; ValueIdx < pEnum->NumPossibleValues(); ValueIdx++) pComboBox->addItem(TO_QSTRING(pEnum->ValueName(ValueIdx))); CONNECT_RELAY(pComboBox, rkIndex, currentIndexChanged(int))