Show UniversalId value for all argument types in reports

simplify_debugging
elsid 1 year ago
parent 7ba397da7d
commit 292983d57a
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -59,10 +59,19 @@ QVariant CSMTools::ReportModel::data(const QModelIndex& index, int role) const
{
CSMWorld::UniversalId id = mRows.at(index.row()).mId;
if (id.getArgumentType() == CSMWorld::UniversalId::ArgumentType_Id)
return QString::fromUtf8(id.getId().c_str());
return QString("-");
switch (id.getArgumentType())
{
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("unsupported");
}
case Column_Hint:

@ -201,6 +201,23 @@ namespace
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)
@ -354,6 +371,14 @@ int CSMWorld::UniversalId::getIndex() const
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
{
const std::span<const TypeData> typeData = std::visit(GetTypeData{}, mValue);

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

@ -27,6 +27,11 @@ namespace CSMWorld
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)
{
EXPECT_THROW(UniversalId("invalid"), std::runtime_error);
@ -62,6 +67,18 @@ namespace CSMWorld
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
{
UniversalId mId;

Loading…
Cancel
Save