Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for fmtlib 10. #142

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading