Skip to content

Commit

Permalink
Fixes for fmtlib 10.
Browse files Browse the repository at this point in the history
  • Loading branch information
Holt59 committed May 18, 2024
1 parent 6012dbb commit dc39090
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
27 changes: 25 additions & 2 deletions src/log.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include <QColor>
#include <QFlag>
#include <QFlags>
#include <QList>
#include <QRect>
#include <QSize>
Expand Down Expand Up @@ -108,6 +110,18 @@ struct QDLLEXPORT converter<QVariant>
static std::string convert(const QVariant& v);
};

template <>
struct QDLLEXPORT converter<QFlag>
{
static int convert(const QFlag& v) { return v; }
};

template <typename T>
struct QDLLEXPORT converter<QFlags<T>>
{
static auto convert(const QFlags<T>& v) { return v.toInt(); }
};

// custom converter for enum and enum class that seems to not work with latest fmt
template <typename T>
struct QDLLEXPORT converter<T, std::enable_if_t<std::is_enum_v<T>>>
Expand All @@ -133,9 +147,18 @@ void doLog(spdlog::logger& logger, Levels lv,
if constexpr (sizeof...(Args) == 0) {
s = fmt::format("{}", std::forward<F>(format));
} else {
// fmt::make_format_args takes lvalue-reference, so we cannot pass the converted
// arguments directly, instead, converted values are stored in a tuple<> and
// std::apply is used to call make_format_args
//
const auto converted_args = std::make_tuple(
converter<std::decay_t<Args>>::convert(std::forward<Args>(args))...);
s = fmt::vformat(std::forward<F>(format),
fmt::make_format_args(converter<std::decay_t<Args>>::convert(
std::forward<Args>(args))...));
std::apply(
[](auto&... values) {
return fmt::make_format_args(values...);
},
converted_args));
}

// check the blacklist
Expand Down
5 changes: 3 additions & 2 deletions src/report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,9 @@ QPixmap TaskDialog::standardIcon(QMessageBox::Icon icon) const
break;
case QMessageBox::Question:
i = s->standardIcon(QStyle::SP_MessageBoxQuestion, 0, m_dialog.get());

case QMessageBox::NoIcon: // fall-through
break;
case QMessageBox::NoIcon:
[[fallthrough]];
default:
break;
}
Expand Down
10 changes: 1 addition & 9 deletions src/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,15 +715,7 @@ bool copyFileRecursive(const QString& source, const QString& baseDir,

std::wstring ToWString(const QString& source)
{
// FIXME
// why not source.toStdWString() ?
wchar_t* buffer = new wchar_t[static_cast<std::size_t>(source.count()) + 1];
source.toWCharArray(buffer);
buffer[source.count()] = L'\0';
std::wstring result(buffer);
delete[] buffer;

return result;
return source.toStdWString();
}

std::string ToString(const QString& source, bool utf8)
Expand Down

0 comments on commit dc39090

Please sign in to comment.