1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-04-11 00:44:33 +00:00

Show UniversalId value for all argument types in reports

This commit is contained in:
elsid 2023-05-22 02:44:21 +02:00
parent 7ba397da7d
commit 292983d57a
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625
4 changed files with 56 additions and 3 deletions

View File

@ -59,10 +59,19 @@ QVariant CSMTools::ReportModel::data(const QModelIndex& index, int role) const
{ {
CSMWorld::UniversalId id = mRows.at(index.row()).mId; CSMWorld::UniversalId id = mRows.at(index.row()).mId;
if (id.getArgumentType() == CSMWorld::UniversalId::ArgumentType_Id) switch (id.getArgumentType())
return QString::fromUtf8(id.getId().c_str()); {
case CSMWorld::UniversalId::ArgumentType_None:
return QString("-");
case CSMWorld::UniversalId::ArgumentType_Index:
return QString::number(id.getIndex());
case CSMWorld::UniversalId::ArgumentType_Id:
return QString::fromStdString(id.getId());
case CSMWorld::UniversalId::ArgumentType_RefId:
return QString::fromStdString(id.getRefId().toString());
}
return QString("-"); return QString("unsupported");
} }
case Column_Hint: case Column_Hint:

View File

@ -201,6 +201,23 @@ namespace
return sIdArg; return sIdArg;
} }
}; };
std::string toString(CSMWorld::UniversalId::ArgumentType value)
{
switch (value)
{
case CSMWorld::UniversalId::ArgumentType_None:
return "None";
case CSMWorld::UniversalId::ArgumentType_Id:
return "Id";
case CSMWorld::UniversalId::ArgumentType_Index:
return "Index";
case CSMWorld::UniversalId::ArgumentType_RefId:
return "RefId";
}
return std::to_string(value);
}
} }
CSMWorld::UniversalId::UniversalId(const std::string& universalId) CSMWorld::UniversalId::UniversalId(const std::string& universalId)
@ -354,6 +371,14 @@ int CSMWorld::UniversalId::getIndex() const
throw std::logic_error("invalid access to index of non-index UniversalId"); throw std::logic_error("invalid access to index of non-index UniversalId");
} }
ESM::RefId CSMWorld::UniversalId::getRefId() const
{
if (const ESM::RefId* result = std::get_if<ESM::RefId>(&mValue))
return *result;
throw std::logic_error("invalid access to RefId of " + ::toString(getArgumentType()) + " UniversalId");
}
std::string CSMWorld::UniversalId::getTypeName() const std::string CSMWorld::UniversalId::getTypeName() const
{ {
const std::span<const TypeData> typeData = std::visit(GetTypeData{}, mValue); const std::span<const TypeData> typeData = std::visit(GetTypeData{}, mValue);

View File

@ -170,6 +170,8 @@ namespace CSMWorld
int getIndex() const; int getIndex() const;
///< Calling this function for a non-index type will throw an exception. ///< Calling this function for a non-index type will throw an exception.
ESM::RefId getRefId() const;
std::string getTypeName() const; std::string getTypeName() const;
std::string toString() const; std::string toString() const;

View File

@ -27,6 +27,11 @@ namespace CSMWorld
EXPECT_THROW(UniversalId(UniversalId::Type_Activator, 42), std::logic_error); EXPECT_THROW(UniversalId(UniversalId::Type_Activator, 42), std::logic_error);
} }
TEST(CSMWorldUniversalIdTest, shouldFailToConstructFromRefIdWithInvalidType)
{
EXPECT_THROW(UniversalId(UniversalId::Type_Search, ESM::RefId()), std::logic_error);
}
TEST(CSMWorldUniversalIdTest, shouldFailToConstructFromInvalidUniversalIdString) TEST(CSMWorldUniversalIdTest, shouldFailToConstructFromInvalidUniversalIdString)
{ {
EXPECT_THROW(UniversalId("invalid"), std::runtime_error); EXPECT_THROW(UniversalId("invalid"), std::runtime_error);
@ -62,6 +67,18 @@ namespace CSMWorld
EXPECT_EQ(id.getId(), "a"); EXPECT_EQ(id.getId(), "a");
} }
TEST(CSMWorldUniversalIdTest, getRefIdShouldThrowExceptionForDefaultConstructed)
{
const UniversalId id;
EXPECT_THROW(id.getRefId(), std::logic_error);
}
TEST(CSMWorldUniversalIdTest, getRefIdShouldReturnValueForConstructedFromRefId)
{
const UniversalId id(UniversalId::Type_Skill, ESM::IndexRefId(ESM::REC_SKIL, 42));
EXPECT_EQ(id.getRefId(), ESM::IndexRefId(ESM::REC_SKIL, 42));
}
struct Params struct Params
{ {
UniversalId mId; UniversalId mId;