Isis 3 Programmer Reference
GuiComboBoxParameter.cpp
1 #include <QVBoxLayout>
2 #include <QComboBox>
3 #include <QList>
4 
5 #include "UserInterface.h"
6 
7 #include "GuiParameter.h"
8 #include "GuiComboBoxParameter.h"
9 
10 namespace Isis {
11 
12  GuiComboBoxParameter::GuiComboBoxParameter(QGridLayout *grid, UserInterface &ui,
13  int group, int param) :
14  GuiParameter(grid, ui, group, param) {
15 
16  // Reset the default alignment of the label
17  p_label->setAlignment(Qt::AlignRight | Qt::AlignTop);
18 
19  // Create a vertical box layout for the combo box and add it to
20  // the grid layout
21  QVBoxLayout *lo = new QVBoxLayout;
22  grid->addLayout(lo, param, 2);
23 
24  // Create a combo box
25  p_combo = new QComboBox();
26 
27  // Create a menu item in the combo box for each list item and add it
28  // to the layout
29  for(int item = 0; item < ui.ParamListSize(group, param); item++) {
30  QString btext = ui.ParamListBrief(group, param, item);
31  btext += " (";
32  btext += ui.ParamListValue(group, param, item);
33  btext += ")";
34  p_combo->insertItem(item, btext);
35  }
36  lo->addWidget(p_combo);
37  connect(p_combo, SIGNAL(activated(int)),
38  this, SIGNAL(ValueChanged()));
39 
40  p_type = ComboWidget;
41  RememberWidget(p_combo);
42  }
43 
44 
45  GuiComboBoxParameter::~GuiComboBoxParameter() {
46  delete p_combo;
47  }
48 
49 
50  void GuiComboBoxParameter::Set(QString newValue) {
51  IString value = newValue;
52  value.UpCase();
53 
54  int foundAtButton = -1;
55  for(int i = 0; i < p_ui->ParamListSize(p_group, p_param); i++) {
56  IString option = p_ui->ParamListValue(p_group, p_param, i);
57  option.UpCase();
58  //if(option.compare(0, value.size(), value) == 0) foundAtButton = i;
59  if(option == value) foundAtButton = i;
60  }
61 
62  if(foundAtButton != -1) {
63  p_combo->setCurrentIndex(foundAtButton);
64  }
65 
66  emit ValueChanged();
67  }
68 
69 
70  QString GuiComboBoxParameter::Value() {
71  return p_ui->ParamListValue(p_group, p_param,
72  p_combo->currentIndex());
73  }
74 
75  std::vector<QString> GuiComboBoxParameter::Exclusions() {
76  std::vector<QString> list;
77 
78  int index = p_combo->currentIndex();
79 
80  for(int i = 0; i < p_ui->ParamListExcludeSize(p_group, p_param, index); i++) {
81  QString s = p_ui->ParamListExclude(p_group, p_param, index, i);
82  list.push_back(s);
83  }
84 
85  return list;
86  }
87 
88  void GuiComboBoxParameter::setOption (int option) {
89  std::cout << "Combo box option: " << option << std::endl;
90  }
91 }
int ParamListSize(const int &group, const int &param) const
Returns the number of options in the specified parameter&#39;s list.
Definition: IsisAml.cpp:1617
int ParamListExcludeSize(const int &group, const int &param, const int &option) const
Returns the number of items in a parameters list exclude section.
Definition: IsisAml.cpp:1676
QString ParamListExclude(const int &group, const int &param, const int &option, const int &exclude) const
Returns the parameter name to be excluded if this option is selected.
Definition: IsisAml.cpp:1691
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
void RememberWidget(QWidget *w)
Add widgets to a list for enabling/disabling.
virtual std::vector< QString > Exclusions()
Return list of current exclusions.
QString ParamListValue(const int &group, const int &param, const int &option) const
Returns the option value for a specific option to a parameter.
Definition: IsisAml.cpp:1631