Isis 3 Programmer Reference
GuiComboBoxParameter.cpp
1
6/* SPDX-License-Identifier: CC0-1.0 */
7#include <QVBoxLayout>
8#include <QComboBox>
9#include <QList>
10
11#include "UserInterface.h"
12
13#include "GuiParameter.h"
14#include "GuiComboBoxParameter.h"
15
16namespace Isis {
17
18 GuiComboBoxParameter::GuiComboBoxParameter(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 // Create a vertical box layout for the combo box and add it to
26 // the grid layout
27 QVBoxLayout *lo = new QVBoxLayout;
28 grid->addLayout(lo, param, 2);
29
30 // Create a combo box
31 p_combo = new QComboBox();
32
33 // Create a menu item in the combo box for each list item and add it
34 // to the layout
35 for(int item = 0; item < ui.ParamListSize(group, param); item++) {
36 QString btext = ui.ParamListBrief(group, param, item);
37 btext += " (";
38 btext += ui.ParamListValue(group, param, item);
39 btext += ")";
40 p_combo->insertItem(item, btext);
41 }
42 lo->addWidget(p_combo);
43 connect(p_combo, SIGNAL(activated(int)),
44 this, SIGNAL(ValueChanged()));
45
46 p_type = ComboWidget;
47 RememberWidget(p_combo);
48 }
49
50
51 GuiComboBoxParameter::~GuiComboBoxParameter() {
52 delete p_combo;
53 }
54
55
56 void GuiComboBoxParameter::Set(QString newValue) {
57 IString value = newValue;
58 value.UpCase();
59
60 int foundAtButton = -1;
61 for(int i = 0; i < p_ui->ParamListSize(p_group, p_param); i++) {
62 IString option = p_ui->ParamListValue(p_group, p_param, i);
63 option.UpCase();
64 //if(option.compare(0, value.size(), value) == 0) foundAtButton = i;
65 if(option == value) foundAtButton = i;
66 }
67
68 if(foundAtButton != -1) {
69 p_combo->setCurrentIndex(foundAtButton);
70 }
71
72 emit ValueChanged();
73 }
74
75
76 QString GuiComboBoxParameter::Value() {
77 return p_ui->ParamListValue(p_group, p_param,
78 p_combo->currentIndex());
79 }
80
81 std::vector<QString> GuiComboBoxParameter::Exclusions() {
82 std::vector<QString> list;
83
84 int index = p_combo->currentIndex();
85
86 for(int i = 0; i < p_ui->ParamListExcludeSize(p_group, p_param, index); i++) {
87 QString s = p_ui->ParamListExclude(p_group, p_param, index, i);
88 list.push_back(s);
89 }
90
91 return list;
92 }
93
94 void GuiComboBoxParameter::setOption (int option) {
95 std::cout << "Combo box option: " << option << std::endl;
96 }
97}
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16