Isis 3 Programmer Reference
GuiListParameter.cpp
1 #include <QVBoxLayout>
2 #include <QRadioButton>
3 #include <QAbstractButton>
4 #include <QList>
5 
6 #include "UserInterface.h"
7 
8 #include "GuiListParameter.h"
9 
10 namespace Isis {
11 
12  GuiListParameter::GuiListParameter(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 
20  // Create a vertical box layout for the radio buttons and add it to
21  // the grid layout
22  QVBoxLayout *lo = new QVBoxLayout;
23  grid->addLayout(lo, param, 2);
24 
25  // Create a button group so these buttons don't react to other buttons
26  // with the same parent
27  p_buttonGroup = new QButtonGroup();
28 
29  // Create a button for each list item and add each to a button group and
30  // to the layout
31  for(int item = 0; item < ui.ParamListSize(group, param); item++) {
32  QString btext = ui.ParamListBrief(group, param, item);
33  btext += " (";
34  btext += ui.ParamListValue(group, param, item);
35  btext += ")";
36 
37  // If there's helper buttons, they need to be added with the 1st value in
38  // the list
39  if((item == 0) && (p_ui->HelpersSize(group, param) != 0)) {
40  // Create Horizontal layout box
41  QHBoxLayout *hlo = new QHBoxLayout;
42  lo->addLayout(hlo);
43 
44  // Create radio button & add to horizontal layout
45  QRadioButton *rb = new QRadioButton(btext);
46  hlo->addWidget(rb);
47  p_buttonGroup->addButton(rb);
48 
49  // Get helpers and add to horizontal layout
50  QWidget *helper = AddHelpers(p_buttonGroup);
51  hlo->addWidget(helper);
52 
53  RememberWidget(rb);
54  RememberWidget(helper);
55  }
56  else {
57  QRadioButton *rb = new QRadioButton(btext);
58  lo->addWidget(rb);
59  p_buttonGroup->addButton(rb);
60  RememberWidget(rb);
61  }
62  }
63  connect(p_buttonGroup, SIGNAL(buttonClicked(QAbstractButton *)),
64  this, SIGNAL(ValueChanged()));
65 
66  p_type = ListWidget;
67  }
68 
69 
70  GuiListParameter::~GuiListParameter() {
71  delete p_buttonGroup;
72  }
73 
74 
75  void GuiListParameter::Set(QString newValue) {
76  QString value = newValue.toUpper();
77 
78  int foundAtButton = -1;
79  for(int i = 0; i < p_ui->ParamListSize(p_group, p_param); i++) {
80  QString option = p_ui->ParamListValue(p_group, p_param, i).toUpper();
81  //if(option.compare(0, value.size(), value) == 0) foundAtButton = i;
82  if(option == value) foundAtButton = i;
83  }
84 
85  if(foundAtButton != -1) {
86  p_buttonGroup->buttons()[foundAtButton]->setChecked(true);
87  }
88 
89  emit ValueChanged();
90  }
91 
92 
93  QString GuiListParameter::Value() {
94  if(p_buttonGroup->checkedButton() == 0) {
95  return "";
96  }
97 
98  return p_ui->ParamListValue(p_group, p_param,
99  p_buttonGroup->buttons().indexOf(p_buttonGroup->checkedButton()));
100  }
101 
102  std::vector<QString> GuiListParameter::Exclusions() {
103  std::vector<QString> list;
104 
105  if(p_buttonGroup->checkedButton() == 0) return list;
106  int index = p_buttonGroup->buttons().indexOf(p_buttonGroup->checkedButton());
107 
108  for(int i = 0; i < p_ui->ParamListExcludeSize(p_group, p_param, index); i++) {
109  QString s = p_ui->ParamListExclude(p_group, p_param, index, i);
110  list.push_back(s);
111  }
112 
113  return list;
114  }
115 }
116 
virtual std::vector< QString > Exclusions()
Return list of current exclusions.
QWidget * AddHelpers(QObject *lo)
Sets up helper button.
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 HelpersSize(const int &group, const int &param) const
Returns the number of helpers the parameter has.
Definition: IsisAml.cpp:1771
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.
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