mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2025-02-03 09:44:24 -05:00
show which Freqs are preferred; switch to preferred; show description with a separator
This commit is contained in:
parent
eb33b6029f
commit
a39a48d76a
@ -351,7 +351,7 @@ public:
|
|||||||
description_line_edit_.text(), source_line_edit_.text(),
|
description_line_edit_.text(), source_line_edit_.text(),
|
||||||
start_time,
|
start_time,
|
||||||
end_time,
|
end_time,
|
||||||
false
|
preferred_frequency_checkbox_->isChecked()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,6 +448,8 @@ public:
|
|||||||
QStringList mimeTypes () const override;
|
QStringList mimeTypes () const override;
|
||||||
QMimeData * mimeData (QModelIndexList const&) const override;
|
QMimeData * mimeData (QModelIndexList const&) const override;
|
||||||
|
|
||||||
|
void unprefer_all_but(Item & item, int const row, QVector<int> );
|
||||||
|
|
||||||
static int constexpr num_cols {SENTINAL};
|
static int constexpr num_cols {SENTINAL};
|
||||||
static auto constexpr mime_type = "application/wsjt.Frequencies";
|
static auto constexpr mime_type = "application/wsjt.Frequencies";
|
||||||
|
|
||||||
@ -456,6 +458,7 @@ public:
|
|||||||
Region region_filter_;
|
Region region_filter_;
|
||||||
Mode mode_filter_;
|
Mode mode_filter_;
|
||||||
bool filter_on_time_;
|
bool filter_on_time_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
FrequencyList_v2::FrequencyList_v2 (Bands const * bands, QObject * parent)
|
FrequencyList_v2::FrequencyList_v2 (Bands const * bands, QObject * parent)
|
||||||
@ -511,6 +514,11 @@ int FrequencyList_v2::best_working_frequency (Frequency f) const
|
|||||||
auto const& band = m_->bands_->find (candidate_frequency);
|
auto const& band = m_->bands_->find (candidate_frequency);
|
||||||
if (band == target_band)
|
if (band == target_band)
|
||||||
{
|
{
|
||||||
|
// take the preferred one
|
||||||
|
if (m_->frequency_list_[source_row].preferred_)
|
||||||
|
{
|
||||||
|
return row;
|
||||||
|
}
|
||||||
// take closest band match
|
// take closest band match
|
||||||
Radio::FrequencyDelta new_delta = f - candidate_frequency;
|
Radio::FrequencyDelta new_delta = f - candidate_frequency;
|
||||||
if (std::abs (new_delta) < std::abs (delta))
|
if (std::abs (new_delta) < std::abs (delta))
|
||||||
@ -536,7 +544,9 @@ int FrequencyList_v2::best_working_frequency (QString const& target_band) const
|
|||||||
auto const& band = m_->bands_->find (m_->frequency_list_[source_row].frequency_);
|
auto const& band = m_->bands_->find (m_->frequency_list_[source_row].frequency_);
|
||||||
if (band == target_band)
|
if (band == target_band)
|
||||||
{
|
{
|
||||||
return row;
|
if (m_->frequency_list_[source_row].preferred_)
|
||||||
|
return row; // return the preferred one immediately
|
||||||
|
result = row;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -648,6 +658,9 @@ QModelIndex FrequencyList_v2::impl::add (Item f)
|
|||||||
frequency_list_.append (f);
|
frequency_list_.append (f);
|
||||||
endInsertRows ();
|
endInsertRows ();
|
||||||
|
|
||||||
|
// if we added one that had a preferred frequency, unprefer everything else
|
||||||
|
unprefer_all_but(f, row, {Qt::DisplayRole, Qt::CheckStateRole});
|
||||||
|
|
||||||
return index (row, 0);
|
return index (row, 0);
|
||||||
}
|
}
|
||||||
return QModelIndex {};
|
return QModelIndex {};
|
||||||
@ -805,8 +818,14 @@ QVariant FrequencyList_v2::impl::data (QModelIndex const& index, int role) const
|
|||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
{
|
{
|
||||||
auto const& band = bands_->find (frequency_item.frequency_);
|
auto const& band = bands_->find (frequency_item.frequency_);
|
||||||
item = Radio::pretty_frequency_MHz_string (frequency_item.frequency_)
|
QString desc_text;
|
||||||
+ " MHz (" + (band.isEmpty () ? "OOB" : band) + ')';
|
desc_text = frequency_item.description_.isEmpty() ? "" : " \u2016 " + frequency_item.description_;
|
||||||
|
item = (frequency_item.preferred_ ? "\u2055 " : "") +
|
||||||
|
Radio::pretty_frequency_MHz_string(frequency_item.frequency_)
|
||||||
|
+ " MHz (" + (band.isEmpty() ? "OOB" : band) + ")" +
|
||||||
|
(((frequency_item.start_time_.isValid() && !frequency_item.start_time_.isNull()) ||
|
||||||
|
(frequency_item.end_time_.isValid() && !frequency_item.end_time_.isNull())) ? " \u2016 " : "")
|
||||||
|
+ desc_text;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -962,6 +981,30 @@ QVariant FrequencyList_v2::impl::data (QModelIndex const& index, int role) const
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FrequencyList_v2::impl::unprefer_all_but(Item &item, int const item_row, QVector<int> roles)
|
||||||
|
{
|
||||||
|
// un-prefer all of the other frequencies in this band
|
||||||
|
auto const band = bands_->find (item.frequency_);
|
||||||
|
if (band.isEmpty ()) return; // out of any band
|
||||||
|
|
||||||
|
roles << Qt::CheckStateRole;
|
||||||
|
roles << Qt::DisplayRole;
|
||||||
|
|
||||||
|
for (int row = 0; row < rowCount (); ++row)
|
||||||
|
{
|
||||||
|
if (row == item_row) continue;
|
||||||
|
|
||||||
|
Item &i = frequency_list_[row];
|
||||||
|
auto const &iter_band = bands_->find(i.frequency_);
|
||||||
|
|
||||||
|
if (!iter_band.isEmpty() && band == iter_band && (i.region_ == item.region_) && (i.mode_ == item.mode_))
|
||||||
|
{
|
||||||
|
i.preferred_ = false;
|
||||||
|
Q_EMIT dataChanged(index(row,preferred_column), index(row,preferred_column), roles);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool FrequencyList_v2::impl::setData (QModelIndex const& model_index, QVariant const& value, int role)
|
bool FrequencyList_v2::impl::setData (QModelIndex const& model_index, QVariant const& value, int role)
|
||||||
{
|
{
|
||||||
bool changed {false};
|
bool changed {false};
|
||||||
@ -980,7 +1023,11 @@ bool FrequencyList_v2::impl::setData (QModelIndex const& model_index, QVariant c
|
|||||||
if (b_val != item.preferred_)
|
if (b_val != item.preferred_)
|
||||||
{
|
{
|
||||||
item.preferred_ = b_val;
|
item.preferred_ = b_val;
|
||||||
Q_EMIT dataChanged(model_index, model_index, roles);
|
if (item.preferred_)
|
||||||
|
{
|
||||||
|
unprefer_all_but (item, row, roles); // un-prefer all of the other frequencies in this band
|
||||||
|
}
|
||||||
|
Q_EMIT dataChanged(index(row,description_column), index(row,preferred_column), roles);
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user