Choose the nearest preset frequency in a band when forced to align

This ensures that an already  selected preset frequency is not changed
when exiting  the settings  dialog.  Probably would  be better  to not
reset  the frequency  when exiting  the  settings dialog  but that  is
buried inside other function calls that are probably necessary.

git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@7268 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Bill Somerville 2016-10-30 22:36:13 +00:00
parent 33c3ba631b
commit 97d9e88614

View File

@ -1,6 +1,8 @@
#include "FrequencyList.hpp"
#include <cstdlib>
#include <utility>
#include <limits>
#include <QMetaType>
#include <QAbstractTableModel>
@ -189,14 +191,22 @@ int FrequencyList::best_working_frequency (Frequency f) const
auto const& target_band = m_->bands_->find (f);
if (!target_band.isEmpty ())
{
Radio::FrequencyDelta delta {std::numeric_limits<Radio::FrequencyDelta>::max ()};
// find a frequency in the same band that is allowed
for (int row = 0; row < rowCount (); ++row)
{
auto const& source_row = mapToSource (index (row, 0)).row ();
auto const& band = m_->bands_->find (m_->frequency_list_[source_row].frequency_);
auto const& candidate_frequency = m_->frequency_list_[source_row].frequency_;
auto const& band = m_->bands_->find (candidate_frequency);
if (band == target_band)
{
return row;
// take closest band match
Radio::FrequencyDelta new_delta = f - candidate_frequency;
if (std::abs (new_delta) < std::abs (delta))
{
delta = new_delta;
result = row;
}
}
}
}