diff --git a/Configuration.cpp b/Configuration.cpp index 85c912bbe..164615e0a 100644 --- a/Configuration.cpp +++ b/Configuration.cpp @@ -237,7 +237,7 @@ public: { return {frequency_line_edit_.frequency () , Modes::value (mode_combo_box_.currentText ()) - , IARURegions::value (region_combo_box_.currentText ())}; + , IARURegions::value (region_combo_box_.currentIndex ())}; } private: @@ -1143,7 +1143,7 @@ void Configuration::impl::initialize_models () ui_->PTT_port_combo_box->setCurrentText (rig_params_.ptt_port); } - ui_->region_combo_box->setCurrentText (regions_.name (region_)); + ui_->region_combo_box->setCurrentIndex (region_); next_macros_.setStringList (macros_.stringList ()); next_frequencies_.frequency_list (frequencies_.frequency_list ()); @@ -1848,7 +1848,7 @@ void Configuration::impl::accept () macros_.setStringList (next_macros_.stringList ()); } - region_ = regions_.value (ui_->region_combo_box->currentText ()); + region_ = IARURegions::value (ui_->region_combo_box->currentIndex ()); if (frequencies_.frequency_list () != next_frequencies_.frequency_list ()) { diff --git a/FrequencyList.cpp b/FrequencyList.cpp index 1df6f3462..24aa84925 100644 --- a/FrequencyList.cpp +++ b/FrequencyList.cpp @@ -607,7 +607,7 @@ bool FrequencyList::impl::setData (QModelIndex const& model_index, QVariant cons case region_column: if (value.canConvert ()) { - auto region = IARURegions::value (value.toString ()); + auto region = static_cast (value.toUInt ()); if (region != item.region_) { item.region_ = region; diff --git a/IARURegions.cpp b/IARURegions.cpp index c743ec77a..e326029b8 100644 --- a/IARURegions.cpp +++ b/IARURegions.cpp @@ -24,7 +24,7 @@ namespace IARURegions::IARURegions (QObject * parent) : QAbstractListModel {parent} { - static_assert (region_names_size == REGIONS_END_SENTINAL_AND_COUNT, + static_assert (region_names_size == SENTINAL, "region_names array must match Region enumeration"); } @@ -33,14 +33,10 @@ char const * IARURegions::name (Region r) return region_names[static_cast (r)]; } -auto IARURegions::value (QString const& s) -> Region +auto IARURegions::value (int r) -> Region { - auto end = region_names + region_names_size; - auto p = std::find_if (region_names, end - , [&s] (char const * const name) { - return name == s; - }); - return p != end ? static_cast (p - region_names) : ALL; + if (r < 0 || r + 1 >= SENTINAL) return ALL; + return static_cast (r); } QVariant IARURegions::data (QModelIndex const& index, int role) const diff --git a/IARURegions.hpp b/IARURegions.hpp index 8e353ddbd..00069acff 100644 --- a/IARURegions.hpp +++ b/IARURegions.hpp @@ -43,7 +43,7 @@ public: R1, R2, R3, - REGIONS_END_SENTINAL_AND_COUNT // this must be last + SENTINAL // this must be last }; Q_ENUM (Region) @@ -51,12 +51,12 @@ public: // translate between enumeration and human readable strings static char const * name (Region); - static Region value (QString const&); + static Region value (int); // Implement the QAbstractListModel interface int rowCount (QModelIndex const& parent = QModelIndex {}) const override { - return parent.isValid () ? 0 : REGIONS_END_SENTINAL_AND_COUNT; // Number of regionss in Region enumeration class + return parent.isValid () ? 0 : SENTINAL; // Number of regionss in Region enumeration class } QVariant data (QModelIndex const&, int role = Qt::DisplayRole) const override; QVariant headerData (int section, Qt::Orientation, int = Qt::DisplayRole) const override;