From: Rene Gassmoeller Date: Thu, 30 Mar 2017 19:44:51 +0000 (-0600) Subject: Handle selection parameters with spaces correctly X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe4a461907d5f63a1abb8a20051f2fb59fdb7fcb;p=parameter_gui.git Handle selection parameters with spaces correctly --- diff --git a/parameter_delegate.cpp b/parameter_delegate.cpp index 462486a..7a3dcd8 100644 --- a/parameter_delegate.cpp +++ b/parameter_delegate.cpp @@ -173,33 +173,28 @@ namespace dealii } else if (rx_selection.indexIn (pattern_description) != -1) // and selections { - QComboBox * combo_box = new QComboBox(parent); // we assume, that pattern_desctiption is of the form - // "Type: [Selection item1|item2| ....|item ] " - std::vector choices; // list with the different items - std::string tmp(pattern_description.toStdString()); - - if (tmp.find("[") != std::string::npos) // delete all char before [ - tmp.erase (0, tmp.find("[")+1); - - if (tmp.find("]") != std::string::npos) // delete all char after ] - tmp.erase (tmp.find("]"),tmp.length()); + QComboBox * combo_box = new QComboBox(parent); - if (tmp.find(" ") != std::string::npos) // delete all char before " " - tmp.erase (0, tmp.find(" ")+1); + // we assume, that pattern_description is of the form + // "Type: [Selection item1|item2| ....|item ]". + // Find the first space after the first '[', + // which indicates the start of the first option + int begin_pattern = pattern_description.indexOf("["); + begin_pattern = pattern_description.indexOf(" ",begin_pattern) + 1; - while (tmp.find('|') != std::string::npos) // extract items - { - choices.push_back(std::string(tmp, 0, tmp.find('|'))); - tmp.erase (0, tmp.find('|')+1); - }; + // Find the last ']', which signals the end of the options + const int end_pattern = pattern_description.lastIndexOf("]"); - if (tmp.find(" ") != std::string::npos) // delete " " - tmp.erase (tmp.find(" ")); + // Extract the options from the string + QString pattern = pattern_description.mid(begin_pattern,end_pattern-begin_pattern); - choices.push_back(tmp); // add last item + // Remove trailing whitespaces + while (pattern.endsWith(' ')) + pattern.chop(1); - for (unsigned int i=0; iaddItem (tr(choices[i].c_str()), tr(choices[i].c_str())); + // Split the list + const QStringList choices = pattern.split("|"); + combo_box->addItems(choices); combo_box->setEditable(false);