Fixed jumping of band activity and call activity tables on update

This commit is contained in:
Jordan Sherer 2018-08-15 23:24:16 -04:00
parent 9815c4dde9
commit 5fad5497d2

View File

@ -1275,14 +1275,17 @@ void MainWindow::not_GA_warning_message ()
"and carry a responsiblity to report any problems to:\n" "and carry a responsiblity to report any problems to:\n"
"Jordan Sherer (KN4CRD) kn4crd@gmail.com\n\n").arg(QApplication::applicationName()).arg(eol.toString())); "Jordan Sherer (KN4CRD) kn4crd@gmail.com\n\n").arg(QApplication::applicationName()).arg(eol.toString()));
#if 0
for(int i = 0; i < 13; i++){
CallDetail cd; CallDetail cd;
cd.call = "KN4CRD"; cd.call = QString("KN%1CRD").arg(i);
cd.freq = 1200; cd.freq = 1200;
cd.bits = Varicode::FT8CallLast; cd.bits = Varicode::FT8CallLast;
cd.utcTimestamp = QDateTime::currentDateTimeUtc(); cd.utcTimestamp = QDateTime::currentDateTimeUtc();
logCallActivity(cd, false); logCallActivity(cd, false);
m_rxDirty = true; m_rxDirty = true;
}
#endif
} }
void MainWindow::initialize_fonts () void MainWindow::initialize_fonts ()
@ -8965,119 +8968,131 @@ void MainWindow::displayBandActivity() {
selectedOffset = selectedItems.first()->text().toInt(); selectedOffset = selectedItems.first()->text().toInt();
} }
// Clear the table ui->tableWidgetRXAll->setUpdatesEnabled(false);
clearTableWidget(ui->tableWidgetRXAll); {
// Scroll Position
auto currentScrollPos = ui->tableWidgetRXAll->verticalScrollBar()->value();
// Sort directed & recent messages first // Clear the table
QList < int > keys = m_bandActivity.keys(); clearTableWidget(ui->tableWidgetRXAll);
qSort(keys.begin(), keys.end(), [this](const int left, int right) {
if (m_rxDirectedCache.contains(left / 10 * 10)) {
return true;
}
if (m_rxDirectedCache.contains(right / 10 * 10)) {
return false;
}
if (m_rxRecentCache.contains(left / 10 * 10)) {
return true;
}
if (m_rxRecentCache.contains(right / 10 * 10)) {
return false;
}
return left < right;
});
// Build the table // Sort directed & recent messages first
foreach(int offset, keys) { QList < int > keys = m_bandActivity.keys();
QList < ActivityDetail > items = m_bandActivity[offset]; qSort(keys.begin(), keys.end(), [this](const int left, int right) {
if (items.length() > 0) {
QStringList text;
QString age;
int snr = 0;
int activityAging = m_config.activity_aging();
foreach(ActivityDetail item, items) {
if (activityAging && item.utcTimestamp.secsTo(now) / 60 >= activityAging) {
continue;
}
if (item.text.isEmpty()) {
continue;
}
#if 0 #if 0
if (item.isCompound || (item.isDirected && item.text.contains("<....>"))){ if (m_rxDirectedCache.contains(left / 10 * 10)) {
//continue; return true;
item.text = "[...]"; }
} if (m_rxDirectedCache.contains(right / 10 * 10)) {
return false;
}
if (m_rxRecentCache.contains(left / 10 * 10)) {
return true;
}
if (m_rxRecentCache.contains(right / 10 * 10)) {
return false;
}
#endif #endif
if (item.isLowConfidence) { return left < right;
item.text = QString("[%1]").arg(item.text); });
// Build the table
foreach(int offset, keys) {
QList < ActivityDetail > items = m_bandActivity[offset];
if (items.length() > 0) {
QStringList text;
QString age;
int snr = 0;
int activityAging = m_config.activity_aging();
foreach(ActivityDetail item, items) {
if (activityAging && item.utcTimestamp.secsTo(now) / 60 >= activityAging) {
continue;
}
if (item.text.isEmpty()) {
continue;
}
#if 0
if (item.isCompound || (item.isDirected && item.text.contains("<....>"))){
//continue;
item.text = "[...]";
}
#endif
if (item.isLowConfidence) {
item.text = QString("[%1]").arg(item.text);
}
if ((item.bits & Varicode::FT8CallLast) == Varicode::FT8CallLast) {
// can also use \u0004 \u2666 \u2404
item.text = QString("%1 \u2301 ").arg(item.text);
}
text.append(item.text);
snr = item.snr;
age = since(item.utcTimestamp);
} }
if ((item.bits & Varicode::FT8CallLast) == Varicode::FT8CallLast) {
// can also use \u0004 \u2666 \u2404 auto joined = text.join(" ");
item.text = QString("%1 \u2301 ").arg(item.text); if (joined.isEmpty()) {
continue;
} }
text.append(item.text);
snr = item.snr;
age = since(item.utcTimestamp);
}
auto joined = text.join(" "); ui->tableWidgetRXAll->insertRow(ui->tableWidgetRXAll->rowCount());
if (joined.isEmpty()) {
continue;
}
ui->tableWidgetRXAll->insertRow(ui->tableWidgetRXAll->rowCount()); auto offsetItem = new QTableWidgetItem(QString("%1").arg(offset));
offsetItem->setData(Qt::UserRole, QVariant(offset));
ui->tableWidgetRXAll->setItem(ui->tableWidgetRXAll->rowCount() - 1, 0, offsetItem);
auto offsetItem = new QTableWidgetItem(QString("%1").arg(offset)); auto ageItem = new QTableWidgetItem(QString("(%1)").arg(age));
offsetItem->setData(Qt::UserRole, QVariant(offset)); ageItem->setTextAlignment(Qt::AlignCenter | Qt::AlignVCenter);
ui->tableWidgetRXAll->setItem(ui->tableWidgetRXAll->rowCount() - 1, 0, offsetItem); ui->tableWidgetRXAll->setItem(ui->tableWidgetRXAll->rowCount() - 1, 1, ageItem);
auto ageItem = new QTableWidgetItem(QString("(%1)").arg(age)); auto snrItem = new QTableWidgetItem(QString("%1").arg(Varicode::formatSNR(snr)));
ageItem->setTextAlignment(Qt::AlignCenter | Qt::AlignVCenter); snrItem->setTextAlignment(Qt::AlignCenter | Qt::AlignVCenter);
ui->tableWidgetRXAll->setItem(ui->tableWidgetRXAll->rowCount() - 1, 1, ageItem); ui->tableWidgetRXAll->setItem(ui->tableWidgetRXAll->rowCount() - 1, 2, snrItem);
auto snrItem = new QTableWidgetItem(QString("%1").arg(Varicode::formatSNR(snr))); // align right if eliding...
snrItem->setTextAlignment(Qt::AlignCenter | Qt::AlignVCenter); int colWidth = ui->tableWidgetRXAll->columnWidth(3);
ui->tableWidgetRXAll->setItem(ui->tableWidgetRXAll->rowCount() - 1, 2, snrItem); auto textItem = new QTableWidgetItem(joined);
QFontMetrics fm(textItem->font());
auto elidedText = fm.elidedText(joined, Qt::ElideLeft, colWidth);
auto flag = Qt::AlignLeft | Qt::AlignVCenter;
if (elidedText != joined) {
flag = Qt::AlignRight | Qt::AlignVCenter;
textItem->setText(joined);
}
textItem->setTextAlignment(flag);
// align right if eliding... if (text.last().contains(QRegularExpression {
int colWidth = ui->tableWidgetRXAll->columnWidth(3); "\\b(CQCQCQ|BEACON)\\b"
auto textItem = new QTableWidgetItem(joined); })) {
QFontMetrics fm(textItem->font()); offsetItem->setBackground(QBrush(m_config.color_CQ()));
auto elidedText = fm.elidedText(joined, Qt::ElideLeft, colWidth); ageItem->setBackground(QBrush(m_config.color_CQ()));
auto flag = Qt::AlignLeft | Qt::AlignVCenter; snrItem->setBackground(QBrush(m_config.color_CQ()));
if (elidedText != joined) { textItem->setBackground(QBrush(m_config.color_CQ()));
flag = Qt::AlignRight | Qt::AlignVCenter; }
textItem->setText(joined);
}
textItem->setTextAlignment(flag);
if (text.last().contains(QRegularExpression { if (isDirectedOffset(offset)) {
"\\b(CQCQCQ|BEACON)\\b" offsetItem->setBackground(QBrush(m_config.color_MyCall()));
})) { ageItem->setBackground(QBrush(m_config.color_MyCall()));
offsetItem->setBackground(QBrush(m_config.color_CQ())); snrItem->setBackground(QBrush(m_config.color_MyCall()));
ageItem->setBackground(QBrush(m_config.color_CQ())); textItem->setBackground(QBrush(m_config.color_MyCall()));
snrItem->setBackground(QBrush(m_config.color_CQ())); }
textItem->setBackground(QBrush(m_config.color_CQ()));
}
if (m_rxDirectedCache.contains(offset / 10 * 10)) { ui->tableWidgetRXAll->setItem(ui->tableWidgetRXAll->rowCount() - 1, 3, textItem);
offsetItem->setBackground(QBrush(m_config.color_MyCall()));
ageItem->setBackground(QBrush(m_config.color_MyCall()));
snrItem->setBackground(QBrush(m_config.color_MyCall()));
textItem->setBackground(QBrush(m_config.color_MyCall()));
}
ui->tableWidgetRXAll->setItem(ui->tableWidgetRXAll->rowCount() - 1, 3, textItem); if (offset == selectedOffset) {
ui->tableWidgetRXAll->selectRow(ui->tableWidgetRXAll->rowCount() - 1);
if (offset == selectedOffset) { }
ui->tableWidgetRXAll->selectRow(ui->tableWidgetRXAll->rowCount() - 1);
} }
} }
}
// Resize the table columns // Resize the table columns
ui->tableWidgetRXAll->resizeColumnToContents(0); ui->tableWidgetRXAll->resizeColumnToContents(0);
ui->tableWidgetRXAll->resizeColumnToContents(1); ui->tableWidgetRXAll->resizeColumnToContents(1);
ui->tableWidgetRXAll->resizeColumnToContents(2); ui->tableWidgetRXAll->resizeColumnToContents(2);
// Reset the scroll position
ui->tableWidgetRXAll->verticalScrollBar()->setValue(currentScrollPos);
}
ui->tableWidgetRXAll->setUpdatesEnabled(true);
} }
void MainWindow::displayCallActivity() { void MainWindow::displayCallActivity() {
@ -9086,54 +9101,63 @@ void MainWindow::displayCallActivity() {
// Selected callsign // Selected callsign
QString selectedCall = callsignSelected(); QString selectedCall = callsignSelected();
// Clear the table ui->tableWidgetCalls->setUpdatesEnabled(false);
clearTableWidget(ui->tableWidgetCalls); {
auto currentScrollPos = ui->tableWidgetCalls->verticalScrollBar()->value();
// Create the ALLCALL item // Clear the table
auto item = new QTableWidgetItem("ALLCALL"); clearTableWidget(ui->tableWidgetCalls);
ui->tableWidgetCalls->insertRow(ui->tableWidgetCalls->rowCount());
item->setData(Qt::UserRole, QVariant("ALLCALL"));
ui->tableWidgetCalls->setItem(ui->tableWidgetCalls->rowCount() - 1, 0, item);
ui->tableWidgetCalls->setSpan(ui->tableWidgetCalls->rowCount() - 1, 0, 1, ui->tableWidgetCalls->columnCount());
if (isAllCallIncluded(selectedCall)) {
ui->tableWidgetCalls->selectRow(ui->tableWidgetCalls->rowCount() - 1);
}
// Build the table
QList < QString > calls = m_callActivity.keys();
qSort(calls.begin(), calls.end());
int callsignAging = m_config.callsign_aging();
foreach(QString call, calls) {
CallDetail d = m_callActivity[call];
if (callsignAging && d.utcTimestamp.secsTo(now) / 60 >= callsignAging) {
continue;
}
// Create the ALLCALL item
auto item = new QTableWidgetItem("ALLCALL");
ui->tableWidgetCalls->insertRow(ui->tableWidgetCalls->rowCount()); ui->tableWidgetCalls->insertRow(ui->tableWidgetCalls->rowCount());
item->setData(Qt::UserRole, QVariant("ALLCALL"));
QString displayCall = d.through.isEmpty() ? d.call : QString("%1 | %2").arg(d.through).arg(d.call); ui->tableWidgetCalls->setItem(ui->tableWidgetCalls->rowCount() - 1, 0, item);
auto displayItem = new QTableWidgetItem(displayCall); ui->tableWidgetCalls->setSpan(ui->tableWidgetCalls->rowCount() - 1, 0, 1, ui->tableWidgetCalls->columnCount());
displayItem->setData(Qt::UserRole, QVariant((d.call))); if (isAllCallIncluded(selectedCall)) {
ui->tableWidgetCalls->setItem(ui->tableWidgetCalls->rowCount() - 1, 0, displayItem);
ui->tableWidgetCalls->setItem(ui->tableWidgetCalls->rowCount() - 1, 1, new QTableWidgetItem(QString("(%1)").arg(since(d.utcTimestamp))));
ui->tableWidgetCalls->setItem(ui->tableWidgetCalls->rowCount() - 1, 2, new QTableWidgetItem(QString("%1").arg(Varicode::formatSNR(d.snr))));
ui->tableWidgetCalls->setItem(ui->tableWidgetCalls->rowCount() - 1, 3, new QTableWidgetItem(QString("%1").arg(d.grid)));
auto distanceItem = new QTableWidgetItem(calculateDistance(d.grid));
distanceItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
ui->tableWidgetCalls->setItem(ui->tableWidgetCalls->rowCount() - 1, 4, distanceItem);
if (call == selectedCall) {
ui->tableWidgetCalls->selectRow(ui->tableWidgetCalls->rowCount() - 1); ui->tableWidgetCalls->selectRow(ui->tableWidgetCalls->rowCount() - 1);
} }
}
// Resize the table columns // Build the table
ui->tableWidgetCalls->resizeColumnToContents(0); QList < QString > calls = m_callActivity.keys();
ui->tableWidgetCalls->resizeColumnToContents(1); qSort(calls.begin(), calls.end());
ui->tableWidgetCalls->resizeColumnToContents(2); int callsignAging = m_config.callsign_aging();
ui->tableWidgetCalls->resizeColumnToContents(3); foreach(QString call, calls) {
CallDetail d = m_callActivity[call];
if (callsignAging && d.utcTimestamp.secsTo(now) / 60 >= callsignAging) {
continue;
}
ui->tableWidgetCalls->insertRow(ui->tableWidgetCalls->rowCount());
QString displayCall = d.through.isEmpty() ? d.call : QString("%1 | %2").arg(d.through).arg(d.call);
auto displayItem = new QTableWidgetItem(displayCall);
displayItem->setData(Qt::UserRole, QVariant((d.call)));
ui->tableWidgetCalls->setItem(ui->tableWidgetCalls->rowCount() - 1, 0, displayItem);
ui->tableWidgetCalls->setItem(ui->tableWidgetCalls->rowCount() - 1, 1, new QTableWidgetItem(QString("(%1)").arg(since(d.utcTimestamp))));
ui->tableWidgetCalls->setItem(ui->tableWidgetCalls->rowCount() - 1, 2, new QTableWidgetItem(QString("%1").arg(Varicode::formatSNR(d.snr))));
ui->tableWidgetCalls->setItem(ui->tableWidgetCalls->rowCount() - 1, 3, new QTableWidgetItem(QString("%1").arg(d.grid)));
auto distanceItem = new QTableWidgetItem(calculateDistance(d.grid));
distanceItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
ui->tableWidgetCalls->setItem(ui->tableWidgetCalls->rowCount() - 1, 4, distanceItem);
if (call == selectedCall) {
ui->tableWidgetCalls->selectRow(ui->tableWidgetCalls->rowCount() - 1);
}
}
// Resize the table columns
ui->tableWidgetCalls->resizeColumnToContents(0);
ui->tableWidgetCalls->resizeColumnToContents(1);
ui->tableWidgetCalls->resizeColumnToContents(2);
ui->tableWidgetCalls->resizeColumnToContents(3);
// Reset the scroll position
ui->tableWidgetCalls->verticalScrollBar()->setValue(currentScrollPos);
}
ui->tableWidgetCalls->setUpdatesEnabled(true);
} }
void MainWindow::postWSPRDecode (bool is_new, QStringList parts) void MainWindow::postWSPRDecode (bool is_new, QStringList parts)