Skip to content

Commit

Permalink
chore: silence some deprecation warnings in Qt 6.8 (#5529)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerixyz authored Aug 4, 2024
1 parent aed55ac commit 3257da1
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
- Dev: `FlagsEnum` is now `constexpr`. (#5510)
- Dev: Documented and added tests to RTL handling. (#5473)
- Dev: Refactored a few `#define`s into `const(expr)` and cleaned includes. (#5527)
- Dev: Prepared for Qt 6.8 by addressing some deprecations. (#5529)

## 2.5.1

Expand Down
23 changes: 18 additions & 5 deletions src/controllers/filters/lang/Types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,35 @@ QString possibleTypeToString(const PossibleType &possible);

bool isList(const PossibleType &possibleType);

inline bool variantIs(const QVariant &a, QMetaType::Type type)
inline bool variantIs(const QVariant &a, int type)
{
return static_cast<QMetaType::Type>(a.type()) == type;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return a.typeId() == type;
#else
return a.type() == type;
#endif
}

inline bool variantIsNot(const QVariant &a, QMetaType::Type type)
inline bool variantIsNot(const QVariant &a, int type)
{
return static_cast<QMetaType::Type>(a.type()) != type;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return a.typeId() != type;
#else
return a.type() != type;
#endif
}

inline bool convertVariantTypes(QVariant &a, QVariant &b, int type)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QMetaType ty(type);
return a.convert(ty) && b.convert(ty);
#else
return a.convert(type) && b.convert(type);
#endif
}

inline bool variantTypesMatch(QVariant &a, QVariant &b, QMetaType::Type type)
inline bool variantTypesMatch(QVariant &a, QVariant &b, int type)
{
return variantIs(a, type) && variantIs(b, type);
}
Expand Down
28 changes: 14 additions & 14 deletions src/controllers/filters/lang/expressions/BinaryOperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ QVariant BinaryOperation::execute(const ContextMap &context) const
switch (this->op_)
{
case PLUS:
if (static_cast<QMetaType::Type>(left.type()) ==
QMetaType::QString &&
right.canConvert(QMetaType::QString))
if (variantIs(left, QMetaType::QString) &&
right.canConvert<QString>())
{
return left.toString().append(right.toString());
}
Expand Down Expand Up @@ -143,14 +142,14 @@ QVariant BinaryOperation::execute(const ContextMap &context) const
return false;
case CONTAINS:
if (variantIs(left, QMetaType::QStringList) &&
right.canConvert(QMetaType::QString))
right.canConvert<QString>())
{
return left.toStringList().contains(right.toString(),
Qt::CaseInsensitive);
}

if (variantIs(left, QMetaType::QVariantMap) &&
right.canConvert(QMetaType::QString))
right.canConvert<QString>())
{
return left.toMap().contains(right.toString());
}
Expand All @@ -160,8 +159,7 @@ QVariant BinaryOperation::execute(const ContextMap &context) const
return left.toList().contains(right);
}

if (left.canConvert(QMetaType::QString) &&
right.canConvert(QMetaType::QString))
if (left.canConvert<QString>() && right.canConvert<QString>())
{
return left.toString().contains(right.toString(),
Qt::CaseInsensitive);
Expand All @@ -170,7 +168,7 @@ QVariant BinaryOperation::execute(const ContextMap &context) const
return false;
case STARTS_WITH:
if (variantIs(left, QMetaType::QStringList) &&
right.canConvert(QMetaType::QString))
right.canConvert<QString>())
{
auto list = left.toStringList();
return !list.isEmpty() &&
Expand All @@ -183,8 +181,7 @@ QVariant BinaryOperation::execute(const ContextMap &context) const
return left.toList().startsWith(right);
}

if (left.canConvert(QMetaType::QString) &&
right.canConvert(QMetaType::QString))
if (left.canConvert<QString>() && right.canConvert<QString>())
{
return left.toString().startsWith(right.toString(),
Qt::CaseInsensitive);
Expand All @@ -194,7 +191,7 @@ QVariant BinaryOperation::execute(const ContextMap &context) const

case ENDS_WITH:
if (variantIs(left, QMetaType::QStringList) &&
right.canConvert(QMetaType::QString))
right.canConvert<QString>())
{
auto list = left.toStringList();
return !list.isEmpty() &&
Expand All @@ -207,23 +204,26 @@ QVariant BinaryOperation::execute(const ContextMap &context) const
return left.toList().endsWith(right);
}

if (left.canConvert(QMetaType::QString) &&
right.canConvert(QMetaType::QString))
if (left.canConvert<QString>() && right.canConvert<QString>())
{
return left.toString().endsWith(right.toString(),
Qt::CaseInsensitive);
}

return false;
case MATCH: {
if (!left.canConvert(QMetaType::QString))
if (!left.canConvert<QString>())
{
return false;
}

auto matching = left.toString();

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
switch (static_cast<QMetaType::Type>(right.typeId()))
#else
switch (static_cast<QMetaType::Type>(right.type()))
#endif
{
case QMetaType::QRegularExpression: {
return right.toRegularExpression()
Expand Down
17 changes: 9 additions & 8 deletions src/providers/emoji/Emojis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void parseEmoji(const std::shared_ptr<EmojiData> &emojiData,
const rapidjson::Value &unparsedEmoji,
const QString &shortCode = {})
{
std::vector<uint32_t> unicodeBytes{};
std::vector<char32_t> unicodeBytes{};

struct {
bool apple;
Expand Down Expand Up @@ -82,7 +82,7 @@ void parseEmoji(const std::shared_ptr<EmojiData> &emojiData,
for (const QString &unicodeCharacter : unicodeCharacters)
{
bool ok{false};
unicodeBytes.push_back(QString(unicodeCharacter).toUInt(&ok, 16));
unicodeBytes.push_back(unicodeCharacter.toUInt(&ok, 16));
if (!ok)
{
qCWarning(chatterinoEmoji)
Expand All @@ -92,14 +92,15 @@ void parseEmoji(const std::shared_ptr<EmojiData> &emojiData,
}

// We can safely do a narrowing static cast since unicodeBytes will never be a large number
emojiData->value = QString::fromUcs4(unicodeBytes.data(),
static_cast<int>(unicodeBytes.size()));
emojiData->value =
QString::fromUcs4(unicodeBytes.data(),
static_cast<QString::size_type>(unicodeBytes.size()));

if (!emojiData->nonQualifiedCode.isEmpty())
{
QStringList nonQualifiedCharacters =
emojiData->nonQualifiedCode.toLower().split('-');
std::vector<uint32_t> nonQualifiedBytes{};
std::vector<char32_t> nonQualifiedBytes{};
for (const QString &unicodeCharacter : nonQualifiedCharacters)
{
bool ok{false};
Expand All @@ -115,9 +116,9 @@ void parseEmoji(const std::shared_ptr<EmojiData> &emojiData,
}

// We can safely do a narrowing static cast since unicodeBytes will never be a large number
emojiData->nonQualified =
QString::fromUcs4(nonQualifiedBytes.data(),
static_cast<int>(nonQualifiedBytes.size()));
emojiData->nonQualified = QString::fromUcs4(
nonQualifiedBytes.data(),
static_cast<QString::size_type>(nonQualifiedBytes.size()));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/providers/twitch/TwitchAccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void TwitchAccount::loadUserstateEmotes(std::weak_ptr<Channel> weakChannel)
}

// filter out emote sets from userstate message, which are not in fetched emote set list
for (const auto &emoteSetKey : qAsConst(this->userstateEmoteSets_))
for (const auto &emoteSetKey : this->userstateEmoteSets_)
{
if (!existingEmoteSetKeys.contains(emoteSetKey))
{
Expand Down
4 changes: 4 additions & 0 deletions src/providers/twitch/TwitchMessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,11 @@ void TwitchMessageBuilder::processIgnorePhrases(
QRegularExpression emoteregex(
"\\b" + emote.name.string + "\\b",
QRegularExpression::UseUnicodePropertiesOption);
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
auto match = emoteregex.matchView(midExtendedRef);
#else
auto match = emoteregex.match(midExtendedRef);
#endif
if (match.hasMatch())
{
emote.start = static_cast<int>(from + match.capturedStart());
Expand Down
3 changes: 2 additions & 1 deletion src/providers/twitch/api/Helix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <QJsonObject>
#include <QString>
#include <QStringList>
#include <QTimeZone>
#include <QUrl>
#include <QUrlQuery>

Expand Down Expand Up @@ -722,7 +723,7 @@ struct HelixShieldModeStatus {
, lastActivatedAt(QDateTime::fromString(
json["last_activated_at"].toString(), Qt::ISODate))
{
this->lastActivatedAt.setTimeSpec(Qt::UTC);
this->lastActivatedAt.setTimeZone(QTimeZone::utc());
}
};

Expand Down
3 changes: 2 additions & 1 deletion src/util/IrcHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <IrcMessage>
#include <QString>
#include <QTimeZone>

namespace chatterino {

Expand Down Expand Up @@ -88,7 +89,7 @@ inline QDateTime calculateMessageTime(const Communi::IrcMessage *message)
QString timedate = message->tags().value("time").toString();

auto date = QDateTime::fromString(timedate, Qt::ISODate);
date.setTimeSpec(Qt::TimeSpec::UTC);
date.setTimeZone(QTimeZone::utc());
return date.toLocalTime();
}

Expand Down
4 changes: 4 additions & 0 deletions src/widgets/helper/color/ColorItemDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ void ColorItemDelegate::paint(QPainter *painter,
{
auto data = index.data(Qt::DecorationRole);

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
if (data.typeId() != QMetaType::QColor)
#else
if (data.type() != QVariant::Color)
#endif
{
return QStyledItemDelegate::paint(painter, option, index);
}
Expand Down

0 comments on commit 3257da1

Please sign in to comment.