Fix an issue with editing IARU regions in the working frequencies table

git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@8166 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Bill Somerville 2017-10-13 22:34:10 +00:00
parent ac1378daa9
commit a9a1ac1d7a
4 changed files with 27 additions and 25 deletions

View File

@ -237,7 +237,7 @@ public:
{ {
return {frequency_line_edit_.frequency () return {frequency_line_edit_.frequency ()
, Modes::value (mode_combo_box_.currentText ()) , Modes::value (mode_combo_box_.currentText ())
, IARURegions::value (region_combo_box_.currentIndex ())}; , IARURegions::value (region_combo_box_.currentText ())};
} }
private: private:
@ -1851,7 +1851,7 @@ void Configuration::impl::accept ()
macros_.setStringList (next_macros_.stringList ()); macros_.setStringList (next_macros_.stringList ());
} }
region_ = IARURegions::value (ui_->region_combo_box->currentIndex ()); region_ = IARURegions::value (ui_->region_combo_box->currentText ());
if (frequencies_.frequency_list () != next_frequencies_.frequency_list ()) if (frequencies_.frequency_list () != next_frequencies_.frequency_list ())
{ {

View File

@ -610,29 +610,27 @@ bool FrequencyList_v2::impl::setData (QModelIndex const& model_index, QVariant c
switch (model_index.column ()) switch (model_index.column ())
{ {
case region_column: case region_column:
if (value.canConvert<Region> ()) {
{ auto region = IARURegions::value (value.toString ());
auto region = static_cast<Region> (value.toUInt ()); if (region != item.region_)
if (region != item.region_) {
{ item.region_ = region;
item.region_ = region; Q_EMIT dataChanged (model_index, model_index, roles);
Q_EMIT dataChanged (model_index, model_index, roles); changed = true;
changed = true; }
}
} }
break; break;
case mode_column: case mode_column:
if (value.canConvert<Mode> ()) {
{ auto mode = Modes::value (value.toString ());
auto mode = Modes::value (value.toString ()); if (mode != item.mode_)
if (mode != item.mode_) {
{ item.mode_ = mode;
item.mode_ = mode; Q_EMIT dataChanged (model_index, model_index, roles);
Q_EMIT dataChanged (model_index, model_index, roles); changed = true;
changed = true; }
} }
}
break; break;
case frequency_column: case frequency_column:

View File

@ -34,10 +34,14 @@ char const * IARURegions::name (Region r)
return region_names[static_cast<int> (r)]; return region_names[static_cast<int> (r)];
} }
auto IARURegions::value (int r) -> Region auto IARURegions::value (QString const& s) -> Region
{ {
if (r < 0 || r + 1 >= SENTINAL) return ALL; auto end = region_names + region_names_size;
return static_cast<Region> (r); auto p = std::find_if (region_names, end
, [&s] (char const * const name) {
return name == s;
});
return p != end ? static_cast<Region> (p - region_names) : ALL;
} }
QVariant IARURegions::data (QModelIndex const& index, int role) const QVariant IARURegions::data (QModelIndex const& index, int role) const

View File

@ -51,7 +51,7 @@ public:
// translate between enumeration and human readable strings // translate between enumeration and human readable strings
static char const * name (Region); static char const * name (Region);
static Region value (int); static Region value (QString const&);
// Implement the QAbstractListModel interface // Implement the QAbstractListModel interface
int rowCount (QModelIndex const& parent = QModelIndex {}) const override int rowCount (QModelIndex const& parent = QModelIndex {}) const override