refactor: adapt magic_enum to Qt (#5258)

This commit is contained in:
nerix
2024-03-23 12:22:42 +01:00
committed by GitHub
parent 044d457d20
commit ed20e71db4
25 changed files with 603 additions and 80 deletions
+2 -3
View File
@@ -5,6 +5,7 @@
#include "common/network/NetworkResult.hpp"
#include "common/QLogging.hpp"
#include "util/CancellationToken.hpp"
#include "util/QMagicEnum.hpp"
#include <magic_enum/magic_enum.hpp>
#include <QJsonDocument>
@@ -1172,9 +1173,7 @@ void Helix::sendChatAnnouncement(
QJsonObject body;
body.insert("message", message);
const auto colorStr =
std::string{magic_enum::enum_name<HelixAnnouncementColor>(color)};
body.insert("color", QString::fromStdString(colorStr).toLower());
body.insert("color", qmagicenum::enumNameString(color).toLower());
this->makePost("chat/announcements", urlQuery)
.json(body)
@@ -1,5 +1,7 @@
#include "providers/twitch/pubsubmessages/AutoMod.hpp"
#include "util/QMagicEnum.hpp"
namespace chatterino {
PubSubAutoModQueueMessage::PubSubAutoModQueueMessage(const QJsonObject &root)
@@ -7,7 +9,7 @@ PubSubAutoModQueueMessage::PubSubAutoModQueueMessage(const QJsonObject &root)
, data(root.value("data").toObject())
, status(this->data.value("status").toString())
{
auto oType = magic_enum::enum_cast<Type>(this->typeString.toStdString());
auto oType = qmagicenum::enumCast<Type>(this->typeString);
if (oType.has_value())
{
this->type = oType.value();
+3 -1
View File
@@ -1,5 +1,7 @@
#include "providers/twitch/pubsubmessages/Base.hpp"
#include "util/QMagicEnum.hpp"
namespace chatterino {
PubSubMessage::PubSubMessage(QJsonObject _object)
@@ -9,7 +11,7 @@ PubSubMessage::PubSubMessage(QJsonObject _object)
, error(this->object.value("error").toString())
, typeString(this->object.value("type").toString())
{
auto oType = magic_enum::enum_cast<Type>(this->typeString.toStdString());
auto oType = qmagicenum::enumCast<Type>(this->typeString);
if (oType.has_value())
{
this->type = oType.value();
@@ -1,5 +1,7 @@
#include "providers/twitch/pubsubmessages/ChannelPoints.hpp"
#include "util/QMagicEnum.hpp"
namespace chatterino {
PubSubCommunityPointsChannelV1Message::PubSubCommunityPointsChannelV1Message(
@@ -7,7 +9,7 @@ PubSubCommunityPointsChannelV1Message::PubSubCommunityPointsChannelV1Message(
: typeString(root.value("type").toString())
, data(root.value("data").toObject())
{
auto oType = magic_enum::enum_cast<Type>(this->typeString.toStdString());
auto oType = qmagicenum::enumCast<Type>(this->typeString);
if (oType.has_value())
{
this->type = oType.value();
@@ -1,5 +1,7 @@
#include "providers/twitch/pubsubmessages/ChatModeratorAction.hpp"
#include "util/QMagicEnum.hpp"
namespace chatterino {
PubSubChatModeratorActionMessage::PubSubChatModeratorActionMessage(
@@ -7,7 +9,7 @@ PubSubChatModeratorActionMessage::PubSubChatModeratorActionMessage(
: typeString(root.value("type").toString())
, data(root.value("data").toObject())
{
auto oType = magic_enum::enum_cast<Type>(this->typeString.toStdString());
auto oType = qmagicenum::enumCast<Type>(this->typeString);
if (oType.has_value())
{
this->type = oType.value();
@@ -1,5 +1,7 @@
#include "providers/twitch/pubsubmessages/LowTrustUsers.hpp"
#include "util/QMagicEnum.hpp"
#include <QDateTime>
#include <QJsonArray>
@@ -8,8 +10,7 @@ namespace chatterino {
PubSubLowTrustUsersMessage::PubSubLowTrustUsersMessage(const QJsonObject &root)
: typeString(root.value("type").toString())
{
if (const auto oType =
magic_enum::enum_cast<Type>(this->typeString.toStdString());
if (const auto oType = qmagicenum::enumCast<Type>(this->typeString);
oType.has_value())
{
this->type = oType.value();
@@ -75,8 +76,8 @@ PubSubLowTrustUsersMessage::PubSubLowTrustUsersMessage(const QJsonObject &root)
this->updatedByUserDisplayName = updatedBy.value("display_name").toString();
this->treatmentString = data.value("treatment").toString();
if (const auto oTreatment = magic_enum::enum_cast<Treatment>(
this->treatmentString.toStdString());
if (const auto oTreatment =
qmagicenum::enumCast<Treatment>(this->treatmentString);
oTreatment.has_value())
{
this->treatment = oTreatment.value();
@@ -84,8 +85,8 @@ PubSubLowTrustUsersMessage::PubSubLowTrustUsersMessage(const QJsonObject &root)
this->evasionEvaluationString =
data.value("ban_evasion_evaluation").toString();
if (const auto oEvaluation = magic_enum::enum_cast<EvasionEvaluation>(
this->evasionEvaluationString.toStdString());
if (const auto oEvaluation = qmagicenum::enumCast<EvasionEvaluation>(
this->evasionEvaluationString);
oEvaluation.has_value())
{
this->evasionEvaluation = oEvaluation.value();
@@ -93,8 +94,8 @@ PubSubLowTrustUsersMessage::PubSubLowTrustUsersMessage(const QJsonObject &root)
for (const auto &rType : data.value("types").toArray())
{
if (const auto oRestriction = magic_enum::enum_cast<RestrictionType>(
rType.toString().toStdString());
if (const auto oRestriction =
qmagicenum::enumCast<RestrictionType>(rType.toString());
oRestriction.has_value())
{
this->restrictionTypes.set(oRestriction.value());
@@ -1,11 +1,13 @@
#include "providers/twitch/pubsubmessages/Whisper.hpp"
#include "util/QMagicEnum.hpp"
namespace chatterino {
PubSubWhisperMessage::PubSubWhisperMessage(const QJsonObject &root)
: typeString(root.value("type").toString())
{
auto oType = magic_enum::enum_cast<Type>(this->typeString.toStdString());
auto oType = qmagicenum::enumCast<Type>(this->typeString);
if (oType.has_value())
{
this->type = oType.value();