Isis 3.0 Object Programmers' Reference |
Home |
00001 #include <QVBoxLayout> 00002 #include <QRadioButton> 00003 #include <QAbstractButton> 00004 #include <QList> 00005 00006 #include "UserInterface.h" 00007 00008 #include "GuiListParameter.h" 00009 00010 namespace Isis { 00011 00012 GuiListParameter::GuiListParameter(QGridLayout *grid, UserInterface &ui, 00013 int group, int param) : 00014 GuiParameter(grid, ui, group, param) { 00015 00016 // Reset the default alignment of the label 00017 p_label->setAlignment(Qt::AlignRight | Qt::AlignTop); 00018 00019 00020 // Create a vertical box layout for the radio buttons and add it to 00021 // the grid layout 00022 QVBoxLayout *lo = new QVBoxLayout; 00023 grid->addLayout(lo, param, 2); 00024 00025 // Create a button group so these buttons don't react to other buttons 00026 // with the same parent 00027 p_buttonGroup = new QButtonGroup (); 00028 00029 // Create a button for each list item and add each to a button group and 00030 // to the layout 00031 for (int item=0; item<ui.ParamListSize(group, param); item++) { 00032 iString btext = ui.ParamListBrief(group, param, item); 00033 btext += " ("; 00034 btext += ui.ParamListValue(group, param, item); 00035 btext += ")"; 00036 00037 // If there's helper buttons, they need to be added with the 1st value in 00038 // the list 00039 if ((item == 0) && (p_ui->HelpersSize(group,param) != 0)) { 00040 // Create Horizontal layout box 00041 QHBoxLayout *hlo = new QHBoxLayout; 00042 lo->addLayout(hlo); 00043 00044 // Create radio button & add to horizontal layout 00045 QRadioButton *rb = new QRadioButton ((iString)btext); 00046 hlo->addWidget(rb); 00047 p_buttonGroup->addButton(rb); 00048 00049 // Get helpers and add to horizontal layout 00050 QWidget *helper = AddHelpers(p_buttonGroup); 00051 hlo->addWidget(helper); 00052 00053 RememberWidget(rb); 00054 RememberWidget(helper); 00055 } 00056 else { 00057 QRadioButton *rb = new QRadioButton ((iString)btext); 00058 lo->addWidget(rb); 00059 p_buttonGroup->addButton(rb); 00060 RememberWidget(rb); 00061 } 00062 } 00063 connect(p_buttonGroup,SIGNAL(buttonClicked(QAbstractButton *)), 00064 this,SIGNAL(ValueChanged())); 00065 00066 p_type = ListWidget; 00067 } 00068 00069 00070 GuiListParameter::~GuiListParameter() { 00071 delete p_buttonGroup; 00072 } 00073 00074 00075 void GuiListParameter::Set (iString newValue) { 00076 iString value = newValue; 00077 value.UpCase(); 00078 00079 int foundAtButton = -1; 00080 for (int i=0; i<p_ui->ParamListSize(p_group,p_param); i++) { 00081 iString option = p_ui->ParamListValue(p_group, p_param, i); 00082 option.UpCase(); 00083 if (option.compare(0,value.size(),value) == 0) foundAtButton = i; 00084 } 00085 00086 if (foundAtButton != -1) { 00087 p_buttonGroup->buttons()[foundAtButton]->setChecked(true); 00088 } 00089 00090 emit ValueChanged(); 00091 } 00092 00093 00094 iString GuiListParameter::Value () { 00095 if (p_buttonGroup->checkedButton() == 0) { 00096 return ""; 00097 } 00098 00099 return (iString)p_ui->ParamListValue(p_group, p_param, 00100 p_buttonGroup->buttons().indexOf(p_buttonGroup->checkedButton())); 00101 } 00102 00103 std::vector<std::string> GuiListParameter::Exclusions() { 00104 std::vector<std::string> list; 00105 00106 if (p_buttonGroup->checkedButton() == 0) return list; 00107 int index = p_buttonGroup->buttons().indexOf(p_buttonGroup->checkedButton()); 00108 00109 for (int i=0; i<p_ui->ParamListExcludeSize(p_group,p_param,index); i++) { 00110 std::string s = p_ui->ParamListExclude(p_group,p_param,index,i); 00111 list.push_back(s); 00112 } 00113 00114 return list; 00115 } 00116 } 00117