Skip to content

Commit

Permalink
Clean qt_color_sink
Browse files Browse the repository at this point in the history
  • Loading branch information
gabime committed Jun 17, 2023
1 parent a29cef5 commit da1e671
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions include/spdlog/sinks/qt_sinks.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,26 +157,24 @@ class qt_sink : public base_sink<Mutex>
memory_buf_t formatted;
base_sink<Mutex>::formatter_->format(msg, formatted);

string_view_t str = string_view_t(formatted.data(), formatted.size());
const string_view_t str = string_view_t(formatted.data(), formatted.size());
// apply the color to the color range in the formatted message.
auto payload = QString::fromLatin1(str.data(), static_cast<int>(str.size()));

// if color needed, apply it as
//if (msg.color_range_end > msg.color_range_start)
{
invoke_params params {
max_lines_, // max lines
qt_text_edit_, // text edit to append to
std::move(payload), // text to append
default_color_, // default color
colors_.at(msg.level), // color to apply
msg.color_range_start, // color range start
msg.color_range_end}; // color range end
QMetaObject::invokeMethod(
qt_text_edit_,
[params]() {invoke_method_(params);},
Qt::AutoConnection);
}
invoke_params params {
max_lines_, // max lines
qt_text_edit_, // text edit to append to
std::move(payload), // text to append
default_color_, // default color
colors_.at(msg.level), // color to apply
msg.color_range_start, // color range start
msg.color_range_end}; // color range end

QMetaObject::invokeMethod(
qt_text_edit_,
[params]() {invoke_method_(params);},
Qt::AutoConnection);

}

void flush_() override {}
Expand Down

0 comments on commit da1e671

Please sign in to comment.