Fix #634 plus #534: bound checking in SDRDevices dialog selection

This commit is contained in:
vsonnier 2018-03-21 06:35:13 +01:00
parent 225a795f31
commit 4cd8735014
2 changed files with 32 additions and 3 deletions

View File

@ -361,7 +361,7 @@ void SDRDevicesDialog::OnUseSelected( wxMouseEvent& event) {
wxPGProperty *prop = runtimeProps[arg.key];
if (arg.type == SoapySDR::ArgInfo::STRING && arg.options.size()) {
settingArgs[arg.key] = arg.options[prop->GetChoiceSelection()];
settingArgs[arg.key] = getSelectedChoiceOption(prop, arg);
} else if (arg.type == SoapySDR::ArgInfo::BOOL) {
settingArgs[arg.key] = (prop->GetValueAsString()=="True")?"true":"false";
} else {
@ -378,7 +378,7 @@ void SDRDevicesDialog::OnUseSelected( wxMouseEvent& event) {
wxPGProperty *prop = streamProps[arg.key];
if (arg.type == SoapySDR::ArgInfo::STRING && arg.options.size()) {
streamArgs[arg.key] = arg.options[prop->GetChoiceSelection()];
streamArgs[arg.key] = getSelectedChoiceOption(prop, arg);
} else if (arg.type == SoapySDR::ArgInfo::BOOL) {
streamArgs[arg.key] = (prop->GetValueAsString()=="True")?"true":"false";
} else {
@ -491,6 +491,31 @@ void SDRDevicesDialog::OnRefreshDevices( wxMouseEvent& /* event */) {
doRefreshDevices();
}
std::string SDRDevicesDialog::getSelectedChoiceOption(wxPGProperty* prop, const SoapySDR::ArgInfo& arg) {
std::string optionName = "";
int choiceIndex = prop->GetChoiceSelection();
if (arg.options.size() > 0) {
if (choiceIndex >= 0 && choiceIndex < arg.options.size()) {
//normal selection
optionName = arg.options[choiceIndex];
} else if (choiceIndex >= arg.options.size()) {
//choose the last one of the list:
optionName = arg.options[arg.options.size() - 1];
prop->SetChoiceSelection(arg.options.size() - 1);
} else if (choiceIndex < 0) {
//choose the first one of the list:
optionName = arg.options[0];
prop->SetChoiceSelection(0);
}
}
return optionName;
}
void SDRDevicesDialog::OnPropGridChanged( wxPropertyGridEvent& event ) {
if (event.GetProperty() == devSettings["name"]) {
@ -557,7 +582,7 @@ void SDRDevicesDialog::OnPropGridChanged( wxPropertyGridEvent& event ) {
std::string settingValue = prop->GetValueAsString().ToStdString();
SoapySDR::ArgInfo arg = runtimeArgs[rtp->first];
if (arg.type == SoapySDR::ArgInfo::STRING && arg.options.size()) {
settingValue = arg.options[prop->GetChoiceSelection()];
settingValue = getSelectedChoiceOption(prop, arg);
} else if (arg.type == SoapySDR::ArgInfo::BOOL) {
settingValue = (prop->GetValueAsString()=="True")?"true":"false";
} else {

View File

@ -33,6 +33,10 @@ private:
SDRDeviceInfo *getSelectedDevice(wxTreeItemId selId);
wxPGProperty *addArgInfoProperty(wxPropertyGrid *pg, SoapySDR::ArgInfo arg);
//
std::string getSelectedChoiceOption(wxPGProperty* prop, const SoapySDR::ArgInfo& arg);
bool refresh, failed;
std::map<std::string, std::vector<SDRDeviceInfo *>* > devs;
std::vector<SDRDeviceInfo *>::iterator devs_i;