diff --git a/USER_MANUAL.md b/USER_MANUAL.md index d6f4f7cde..3e086517e 100644 --- a/USER_MANUAL.md +++ b/USER_MANUAL.md @@ -899,6 +899,8 @@ LDPC | Low Density Parity Check Codes - a family of powerful FEC codes 1. Bugfixes: * Revert BETA back to prior 1.9.0 value for waterfall. (PR #503) + * Optimize FreeDV Reporter window logic to reduce likelihood of waterfall stuttering. (PR #505) + * Fix intermittent crash during FreeDV Reporter updates. (PR #505) ## V1.9.0 August 2023 diff --git a/src/freedv_reporter.cpp b/src/freedv_reporter.cpp index 0c2653f07..05337bf25 100644 --- a/src/freedv_reporter.cpp +++ b/src/freedv_reporter.cpp @@ -558,48 +558,6 @@ wxString FreeDVReporterDialog::makeValidTime_(std::string timeStr) } } -void FreeDVReporterDialog::checkColumnsAndResize_() -{ - std::map shouldResize; - - // Process all data in table and determine which columns now have longer text - // (and thus should be auto-resized). - for (int index = 0; index < m_listSpots->GetItemCount(); index++) - { - for (int col = 0; col < NUM_COLS; col++) - { - auto str = m_listSpots->GetItemText(index, col); - auto itemFont = m_listSpots->GetItemFont(index); - int textWidth = 0; - int textHeight = 0; // Note: unused - - // Note: if the font is invalid we should just use the default. - if (itemFont.IsOk()) - { - GetTextExtent(str, &textWidth, &textHeight, nullptr, nullptr, &itemFont); - } - else - { - GetTextExtent(str, &textWidth, &textHeight); - } - - if (textWidth > columnLengths_[col]) - { - shouldResize[col] = true; - columnLengths_[col] = textWidth; - } - } - } - - // Trigger auto-resize for columns as needed - for (auto& kvp : shouldResize) - { - // Note: we don't add anything to shouldResize that is false, so - // no need to check for shouldResize == true here. - m_listSpots->SetColumnWidth(kvp.first, wxLIST_AUTOSIZE_USEHEADER); - } -} - void FreeDVReporterDialog::addOrUpdateListIfNotFiltered_(ReporterData* data) { bool filtered = isFiltered_(data->frequency); @@ -617,10 +575,7 @@ void FreeDVReporterDialog::addOrUpdateListIfNotFiltered_(ReporterData* data) if (itemIndex >= 0 && filtered) { - // Remove as it has been filtered out. - delete allReporterData_[data->sid]; - allReporterData_.erase(data->sid); - + // Remove as it has been filtered out. delete (std::string*)m_listSpots->GetItemData(itemIndex); m_listSpots->DeleteItem(itemIndex); @@ -637,16 +592,16 @@ void FreeDVReporterDialog::addOrUpdateListIfNotFiltered_(ReporterData* data) return; } - m_listSpots->SetItem(itemIndex, 1, data->gridSquare); - m_listSpots->SetItem(itemIndex, 2, data->version); - m_listSpots->SetItem(itemIndex, 3, data->freqString); - m_listSpots->SetItem(itemIndex, 4, data->status); - m_listSpots->SetItem(itemIndex, 5, data->txMode); - m_listSpots->SetItem(itemIndex, 6, data->lastTx); - m_listSpots->SetItem(itemIndex, 7, data->lastRxCallsign); - m_listSpots->SetItem(itemIndex, 8, data->lastRxMode); - m_listSpots->SetItem(itemIndex, 9, data->snr); - m_listSpots->SetItem(itemIndex, 10, data->lastUpdate); + setColumnForRow_(itemIndex, 1, data->gridSquare); + setColumnForRow_(itemIndex, 2, data->version); + setColumnForRow_(itemIndex, 3, data->freqString); + setColumnForRow_(itemIndex, 4, data->status); + setColumnForRow_(itemIndex, 5, data->txMode); + setColumnForRow_(itemIndex, 6, data->lastTx); + setColumnForRow_(itemIndex, 7, data->lastRxCallsign); + setColumnForRow_(itemIndex, 8, data->lastRxMode); + setColumnForRow_(itemIndex, 9, data->snr); + setColumnForRow_(itemIndex, 10, data->lastUpdate); if (data->transmitting) { @@ -659,8 +614,36 @@ void FreeDVReporterDialog::addOrUpdateListIfNotFiltered_(ReporterData* data) m_listSpots->SetItemBackgroundColour(itemIndex, wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX)); m_listSpots->SetItemTextColour(itemIndex, wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOXTEXT)); } +} + +void FreeDVReporterDialog::setColumnForRow_(int row, int col, wxString val) +{ + auto oldText = m_listSpots->GetItemText(row, col); + + if (oldText != val) + { + m_listSpots->SetItem(row, col, val); + + auto itemFont = m_listSpots->GetItemFont(row); + int textWidth = 0; + int textHeight = 0; // Note: unused + + // Note: if the font is invalid we should just use the default. + if (itemFont.IsOk()) + { + GetTextExtent(val, &textWidth, &textHeight, nullptr, nullptr, &itemFont); + } + else + { + GetTextExtent(val, &textWidth, &textHeight); + } - checkColumnsAndResize_(); + if (textWidth > columnLengths_[col]) + { + columnLengths_[col] = textWidth; + m_listSpots->SetColumnWidth(col, wxLIST_AUTOSIZE_USEHEADER); + } + } } bool FreeDVReporterDialog::isFiltered_(uint64_t freq) @@ -720,4 +703,4 @@ bool FreeDVReporterDialog::isFiltered_(uint64_t freq) { return bandForFreq != currentBandFilter_; } -} \ No newline at end of file +} diff --git a/src/freedv_reporter.h b/src/freedv_reporter.h index 0c85585c1..05796ee89 100644 --- a/src/freedv_reporter.h +++ b/src/freedv_reporter.h @@ -129,10 +129,10 @@ class FreeDVReporterDialog : public wxDialog wxString makeValidTime_(std::string timeStr); - void checkColumnsAndResize_(); - void addOrUpdateListIfNotFiltered_(ReporterData* data); bool isFiltered_(uint64_t freq); + + void setColumnForRow_(int row, int col, wxString val); }; #endif // __FREEDV_REPORTER_DIALOG__