Use model row to express region rather than name string

For some  unknown reason on some  machines the string version  of the
name does not match the model IARURegions names.

git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@7848 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Bill Somerville 2017-07-11 01:59:19 +00:00
parent c35e26ab46
commit 817d4d98c7
4 changed files with 11 additions and 15 deletions

View File

@ -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 ())
{

View File

@ -607,7 +607,7 @@ bool FrequencyList::impl::setData (QModelIndex const& model_index, QVariant cons
case region_column:
if (value.canConvert<Region> ())
{
auto region = IARURegions::value (value.toString ());
auto region = static_cast<Region> (value.toUInt ());
if (region != item.region_)
{
item.region_ = region;

View File

@ -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<int> (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<Region> (p - region_names) : ALL;
if (r < 0 || r + 1 >= SENTINAL) return ALL;
return static_cast<Region> (r);
}
QVariant IARURegions::data (QModelIndex const& index, int role) const

View File

@ -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;