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