Make settings trace output human readable

This commit is contained in:
Bill Somerville 2020-10-11 00:03:10 +01:00
parent 477b99ea45
commit b12e9004bb
No known key found for this signature in database
GPG Key ID: D864B06D1E81618F

View File

@ -28,6 +28,10 @@
#include <QSqlDatabase> #include <QSqlDatabase>
#include <QSqlQuery> #include <QSqlQuery>
#include <QSqlError> #include <QSqlError>
#include <QVariant>
#include <QByteArray>
#include <QBitArray>
#include <QMetaType>
#include "ExceptionCatchingApplication.hpp" #include "ExceptionCatchingApplication.hpp"
#include "Logger.hpp" #include "Logger.hpp"
@ -68,23 +72,24 @@ namespace
void safe_stream_QVariant (boost::log::record_ostream& os, QVariant const& v) void safe_stream_QVariant (boost::log::record_ostream& os, QVariant const& v)
{ {
if (QMetaType::QByteArray == static_cast<QMetaType::Type> (v.type ())) switch (static_cast<QMetaType::Type> (v.type ()))
{ {
auto const& a =v.toByteArray (); case QMetaType::QByteArray:
std::ios::fmtflags f (os.flags ()); os << "0x" << v.toByteArray ().toHex (':').toStdString ();
os << std::hex << std::showbase; break;
for (auto p = a.begin (); p != a.end (); )
case QMetaType::QBitArray:
{ {
os << static_cast<int8_t> (*p++); auto const& bits = v.toBitArray ();
if (p != a.end ()) os << "0b";
for (int i = 0; i < bits.size (); ++ i)
{ {
os << ' '; os << (bits[i] ? '1' : '0');
} }
} }
os.flags (f); break;
}
else default:
{
os << v.toString (); os << v.toString ();
} }
} }