mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-25 05:38:46 -05:00
873b1d1c43
Includes a new settings facility with the highlighting being contrled by a new model class and a modified QListView to display the data for editing. Edits include enable and disable check boxes, a contextual pop-up menu to adjust backkground and foreground colours. Still to be implemented are priorities for highlighting categories. This will be adjustable by drag and drop in the Colors settings panel, it is already implemented by the priority order has no effect on highlighting of decodes yet. The LotW users data file fetch and time since user's last upload is now controled from the settings dialog. This change also drops support for Qt versions before 5.5 so that many workarounds for earlier versions can be removed. Debug trace is slightly modified to make better use of the Qt built in facilities to format and synchronize cross thread messaging.
83 lines
2.0 KiB
C++
83 lines
2.0 KiB
C++
#include "TraceFile.hpp"
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <QDebug>
|
|
#include <QString>
|
|
#include <QFile>
|
|
#include <QTextStream>
|
|
|
|
#include "pimpl_impl.hpp"
|
|
|
|
class TraceFile::impl
|
|
{
|
|
public:
|
|
impl (QString const& trace_file_path);
|
|
~impl ();
|
|
|
|
// no copying
|
|
impl (impl const&) = delete;
|
|
impl& operator = (impl const&) = delete;
|
|
|
|
private:
|
|
// write Qt messages to the diagnostic log file
|
|
static void message_handler (QtMsgType type, QMessageLogContext const& context, QString const& msg);
|
|
|
|
QFile file_;
|
|
QTextStream stream_;
|
|
QTextStream * original_stream_;
|
|
QtMessageHandler original_handler_;
|
|
static QTextStream * current_stream_;
|
|
};
|
|
|
|
QTextStream * TraceFile::impl::current_stream_;
|
|
|
|
|
|
// delegate to implementation class
|
|
TraceFile::TraceFile (QString const& trace_file_path)
|
|
: m_ {trace_file_path}
|
|
{
|
|
}
|
|
|
|
TraceFile::~TraceFile ()
|
|
{
|
|
}
|
|
|
|
|
|
TraceFile::impl::impl (QString const& trace_file_path)
|
|
: file_ {trace_file_path}
|
|
, original_stream_ {current_stream_}
|
|
, original_handler_ {nullptr}
|
|
{
|
|
// if the log file is writeable; initialise diagnostic logging to it
|
|
// for append and hook up the Qt global message handler
|
|
if (file_.open (QFile::WriteOnly | QFile::Append | QFile::Text))
|
|
{
|
|
stream_.setDevice (&file_);
|
|
current_stream_ = &stream_;
|
|
original_handler_ = qInstallMessageHandler (message_handler);
|
|
}
|
|
}
|
|
|
|
TraceFile::impl::~impl ()
|
|
{
|
|
// unhook our message handler before the stream and file are destroyed
|
|
if (original_handler_)
|
|
{
|
|
qInstallMessageHandler (original_handler_);
|
|
}
|
|
current_stream_ = original_stream_; // revert to prior stream
|
|
}
|
|
|
|
// write Qt messages to the diagnostic log file
|
|
void TraceFile::impl::message_handler (QtMsgType type, QMessageLogContext const& context, QString const& msg)
|
|
{
|
|
Q_ASSERT_X (current_stream_, "TraceFile:message_handler", "no stream to write to");
|
|
*current_stream_ << qFormatLogMessage (type, context, msg) << endl;
|
|
|
|
if (QtFatalMsg == type)
|
|
{
|
|
throw std::runtime_error {"Fatal Qt Error"};
|
|
}
|
|
}
|