Added factory function overloads for QTextEdit, QPlainTextEdit and QObject

Added factory funtion overloads for QTextEdit, QPlainTextEdit and QObject objects
cleaned qt_sink ctor
This commit is contained in:
Muhammed Galib Uludag 2021-07-28 22:35:09 +03:00 committed by GitHub
parent dabec32748
commit fe9cb54e0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,7 +13,6 @@
#include "spdlog/details/synchronous_factory.h"
#include "spdlog/sinks/base_sink.h"
#include <type_traits>
#include <QTextEdit>
#include <QPlainTextEdit>
@ -25,12 +24,8 @@ namespace sinks {
template <typename Mutex> class qt_sink : public base_sink<Mutex> {
public:
qt_sink(QObject *qt_object = nullptr, const std::string &meta_method = "") {
if (qt_object != nullptr) {
qt_object_ = qt_object;
meta_method_ = meta_method;
} else {
throw spdlog_ex("Error opening qt sink");
}
}
~qt_sink() { flush_(); }
@ -60,25 +55,39 @@ using qt_sink_st = qt_sink<spdlog::details::null_mutex>;
//
// Factory functions
//
template <typename T, typename Factory = spdlog::synchronous_factory>
template <typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger>
qt_logger_mt(const std::string &logger_name, T *qt_object = nullptr, const std::string &meta_method = "") {
std::string meta_method_ = meta_method;
if (std::is_base_of<QTextEdit, T>::value)
meta_method_ = "append";
else if (std::is_same<T, QPlainTextEdit>::value)
meta_method_ = "appendPlainText";
return Factory::template create<sinks::qt_sink_mt>(logger_name, qt_object, meta_method_);
qt_logger_mt(const std::string &logger_name, QTextEdit* qt_object, const std::string &meta_method = "append") {
return Factory::template create<sinks::qt_sink_mt>(logger_name, qt_object, meta_method);
}
template <typename T, typename Factory = spdlog::synchronous_factory>
template <typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger>
qt_logger_st(const std::string &logger_name, T *qt_object = nullptr, const std::string &meta_method = "") {
std::string meta_method_ = meta_method;
if (std::is_base_of<QTextEdit, T>::value)
meta_method_ = "append";
else if (std::is_same<T, QPlainTextEdit>::value)
meta_method_ = "appendPlainText";
return Factory::template create<sinks::qt_sink_st>(logger_name, qt_object, meta_method_);
qt_logger_st(const std::string &logger_name, QTextEdit* qt_object, const std::string &meta_method = "append") {
return Factory::template create<sinks::qt_sink_st>(logger_name, qt_object, meta_method);
}
template <typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger>
qt_logger_mt(const std::string &logger_name, QPlainTextEdit* qt_object , const std::string &meta_method = "appendPlainText") {
return Factory::template create<sinks::qt_sink_mt>(logger_name, qt_object, meta_method);
}
template <typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger>
qt_logger_st(const std::string &logger_name, QPlainTextEdit* qt_object, const std::string &meta_method = "appendPlainText") {
return Factory::template create<sinks::qt_sink_st>(logger_name, qt_object, meta_method);
}
template <typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger>
qt_logger_mt(const std::string &logger_name, QObject* qt_object, const std::string &meta_method) {
return Factory::template create<sinks::qt_sink_mt>(logger_name, qt_object, meta_method);
}
template <typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger>
qt_logger_st(const std::string &logger_name, QObject* qt_object, const std::string &meta_method) {
return Factory::template create<sinks::qt_sink_st>(logger_name, qt_object, meta_method);
}
} // namespace spdlog