2016-05-24 06:08:35 -04:00
|
|
|
#include "DecodesModel.hpp"
|
|
|
|
|
|
|
|
#include <QStandardItem>
|
|
|
|
#include <QModelIndex>
|
2020-11-02 16:35:48 -05:00
|
|
|
#include <QVariant>
|
2016-05-24 06:08:35 -04:00
|
|
|
#include <QTime>
|
|
|
|
#include <QString>
|
|
|
|
#include <QFont>
|
|
|
|
#include <QList>
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
char const * const headings[] = {
|
|
|
|
QT_TRANSLATE_NOOP ("DecodesModel", "Client"),
|
|
|
|
QT_TRANSLATE_NOOP ("DecodesModel", "Time"),
|
|
|
|
QT_TRANSLATE_NOOP ("DecodesModel", "Snr"),
|
|
|
|
QT_TRANSLATE_NOOP ("DecodesModel", "DT"),
|
|
|
|
QT_TRANSLATE_NOOP ("DecodesModel", "DF"),
|
|
|
|
QT_TRANSLATE_NOOP ("DecodesModel", "Md"),
|
2017-07-26 17:18:59 -04:00
|
|
|
QT_TRANSLATE_NOOP ("DecodesModel", "Confidence"),
|
2017-09-16 18:20:59 -04:00
|
|
|
QT_TRANSLATE_NOOP ("DecodesModel", "Live"),
|
2017-09-22 18:08:41 -04:00
|
|
|
QT_TRANSLATE_NOOP ("DecodesModel", "Message"),
|
2016-05-24 06:08:35 -04:00
|
|
|
};
|
|
|
|
|
2017-07-26 17:18:59 -04:00
|
|
|
QString confidence_string (bool low_confidence)
|
|
|
|
{
|
|
|
|
return low_confidence ? QT_TRANSLATE_NOOP ("DecodesModel", "low") : QT_TRANSLATE_NOOP ("DecodesModel", "high");
|
|
|
|
}
|
|
|
|
|
2017-09-16 18:20:59 -04:00
|
|
|
QString live_string (bool off_air)
|
|
|
|
{
|
|
|
|
return off_air ? QT_TRANSLATE_NOOP ("DecodesModel", "no") : QT_TRANSLATE_NOOP ("DecodesModel", "yes");
|
|
|
|
}
|
|
|
|
|
2016-05-24 06:08:35 -04:00
|
|
|
QFont text_font {"Courier", 10};
|
|
|
|
|
2020-11-02 16:35:48 -05:00
|
|
|
QList<QStandardItem *> make_row (MessageServer::ClientKey const& key, QTime time, qint32 snr
|
|
|
|
, float delta_time, quint32 delta_frequency, QString const& mode
|
|
|
|
, QString const& message, bool low_confidence, bool off_air, bool is_fast)
|
2016-05-24 06:08:35 -04:00
|
|
|
{
|
2020-11-02 16:35:48 -05:00
|
|
|
auto client_item = new QStandardItem {QString {"%1(%2)"}.arg (key.second).arg (key.first.toString ())};
|
|
|
|
client_item->setData (QVariant::fromValue (key));
|
|
|
|
|
2017-07-07 19:11:49 -04:00
|
|
|
auto time_item = new QStandardItem {time.toString (is_fast || "~" == mode ? "hh:mm:ss" : "hh:mm")};
|
2016-05-24 06:08:35 -04:00
|
|
|
time_item->setData (time);
|
|
|
|
time_item->setTextAlignment (Qt::AlignRight);
|
|
|
|
|
|
|
|
auto snr_item = new QStandardItem {QString::number (snr)};
|
|
|
|
snr_item->setData (snr);
|
|
|
|
snr_item->setTextAlignment (Qt::AlignRight);
|
|
|
|
|
|
|
|
auto dt = new QStandardItem {QString::number (delta_time)};
|
|
|
|
dt->setData (delta_time);
|
|
|
|
dt->setTextAlignment (Qt::AlignRight);
|
|
|
|
|
|
|
|
auto df = new QStandardItem {QString::number (delta_frequency)};
|
|
|
|
df->setData (delta_frequency);
|
|
|
|
df->setTextAlignment (Qt::AlignRight);
|
|
|
|
|
|
|
|
auto md = new QStandardItem {mode};
|
|
|
|
md->setTextAlignment (Qt::AlignHCenter);
|
|
|
|
|
2017-07-26 17:18:59 -04:00
|
|
|
auto confidence = new QStandardItem {confidence_string (low_confidence)};
|
|
|
|
confidence->setTextAlignment (Qt::AlignHCenter);
|
|
|
|
|
2017-09-16 18:20:59 -04:00
|
|
|
auto live = new QStandardItem {live_string (off_air)};
|
|
|
|
live->setTextAlignment (Qt::AlignHCenter);
|
|
|
|
|
2016-05-24 06:08:35 -04:00
|
|
|
QList<QStandardItem *> row {
|
2020-11-02 16:35:48 -05:00
|
|
|
client_item, time_item, snr_item, dt, df, md, confidence, live, new QStandardItem {message}};
|
2016-05-24 06:08:35 -04:00
|
|
|
Q_FOREACH (auto& item, row)
|
|
|
|
{
|
|
|
|
item->setEditable (false);
|
|
|
|
item->setFont (text_font);
|
|
|
|
item->setTextAlignment (item->textAlignment () | Qt::AlignVCenter);
|
|
|
|
}
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DecodesModel::DecodesModel (QObject * parent)
|
2018-12-02 10:09:37 -05:00
|
|
|
: QStandardItemModel {0, sizeof headings / sizeof headings[0], parent}
|
2016-05-24 06:08:35 -04:00
|
|
|
{
|
|
|
|
int column {0};
|
|
|
|
for (auto const& heading : headings)
|
|
|
|
{
|
|
|
|
setHeaderData (column++, Qt::Horizontal, tr (heading));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-02 16:35:48 -05:00
|
|
|
void DecodesModel::add_decode (bool is_new, ClientKey const& key, QTime time, qint32 snr, float delta_time
|
2016-12-16 14:36:21 -05:00
|
|
|
, quint32 delta_frequency, QString const& mode, QString const& message
|
2017-09-16 18:20:59 -04:00
|
|
|
, bool low_confidence, bool off_air, bool is_fast)
|
2016-05-24 06:08:35 -04:00
|
|
|
{
|
|
|
|
if (!is_new)
|
|
|
|
{
|
|
|
|
int target_row {-1};
|
|
|
|
for (auto row = 0; row < rowCount (); ++row)
|
|
|
|
{
|
2020-11-02 16:35:48 -05:00
|
|
|
if (item (row, 0)->data ().value<ClientKey> () == key)
|
2016-05-24 06:08:35 -04:00
|
|
|
{
|
|
|
|
auto row_time = item (row, 1)->data ().toTime ();
|
|
|
|
if (row_time == time
|
|
|
|
&& item (row, 2)->data ().toInt () == snr
|
|
|
|
&& item (row, 3)->data ().toFloat () == delta_time
|
|
|
|
&& item (row, 4)->data ().toUInt () == delta_frequency
|
|
|
|
&& data (index (row, 5)).toString () == mode
|
2017-09-16 18:20:59 -04:00
|
|
|
&& data (index (row, 7)).toString () == confidence_string (low_confidence)
|
2017-09-22 18:08:41 -04:00
|
|
|
&& data (index (row, 6)).toString () == live_string (off_air)
|
|
|
|
&& data (index (row, 8)).toString () == message)
|
2016-05-24 06:08:35 -04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (time <= row_time)
|
|
|
|
{
|
|
|
|
target_row = row; // last row with same time
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (target_row >= 0)
|
|
|
|
{
|
2020-11-02 16:35:48 -05:00
|
|
|
insertRow (target_row + 1, make_row (key, time, snr, delta_time, delta_frequency, mode
|
2017-09-16 18:20:59 -04:00
|
|
|
, message, low_confidence, off_air, is_fast));
|
2016-05-24 06:08:35 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-02 16:35:48 -05:00
|
|
|
appendRow (make_row (key, time, snr, delta_time, delta_frequency, mode, message, low_confidence
|
2017-09-16 18:20:59 -04:00
|
|
|
, off_air, is_fast));
|
2016-05-24 06:08:35 -04:00
|
|
|
}
|
|
|
|
|
2020-11-02 16:35:48 -05:00
|
|
|
void DecodesModel::decodes_cleared (ClientKey const& key)
|
2016-05-24 06:08:35 -04:00
|
|
|
{
|
|
|
|
for (auto row = rowCount () - 1; row >= 0; --row)
|
|
|
|
{
|
2020-11-02 16:35:48 -05:00
|
|
|
if (item (row, 0)->data ().value<ClientKey> () == key)
|
2016-05-24 06:08:35 -04:00
|
|
|
{
|
|
|
|
removeRow (row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-22 11:36:24 -04:00
|
|
|
void DecodesModel::do_reply (QModelIndex const& source, quint8 modifiers)
|
2016-05-24 06:08:35 -04:00
|
|
|
{
|
|
|
|
auto row = source.row ();
|
2020-11-02 16:35:48 -05:00
|
|
|
Q_EMIT reply (item (row, 0)->data ().value<ClientKey> ()
|
2016-05-24 06:08:35 -04:00
|
|
|
, item (row, 1)->data ().toTime ()
|
|
|
|
, item (row, 2)->data ().toInt ()
|
|
|
|
, item (row, 3)->data ().toFloat ()
|
|
|
|
, item (row, 4)->data ().toInt ()
|
|
|
|
, data (index (row, 5)).toString ()
|
2017-09-22 18:08:41 -04:00
|
|
|
, data (index (row, 8)).toString ()
|
2017-09-22 11:36:24 -04:00
|
|
|
, confidence_string (true) == data (index (row, 7)).toString ()
|
|
|
|
, modifiers);
|
2016-05-24 06:08:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "moc_DecodesModel.cpp"
|