|
Isis 3.0 Object Programmers' Reference |
Home |
00001 #include <QVBoxLayout> 00002 #include <QComboBox> 00003 #include <QList> 00004 00005 #include "UserInterface.h" 00006 00007 #include "GuiParameter.h" 00008 #include "GuiComboBoxParameter.h" 00009 00010 namespace Isis { 00011 00012 GuiComboBoxParameter::GuiComboBoxParameter(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 // Create a vertical box layout for the combo box and add it to 00020 // the grid layout 00021 QVBoxLayout *lo = new QVBoxLayout; 00022 grid->addLayout(lo, param, 2); 00023 00024 // Create a combo box 00025 p_combo = new QComboBox(); 00026 00027 // Create a menu item in the combo box for each list item and add it 00028 // to the layout 00029 for(int item = 0; item < ui.ParamListSize(group, param); item++) { 00030 QString btext = ui.ParamListBrief(group, param, item); 00031 btext += " ("; 00032 btext += ui.ParamListValue(group, param, item); 00033 btext += ")"; 00034 p_combo->insertItem(item, btext); 00035 } 00036 lo->addWidget(p_combo); 00037 connect(p_combo, SIGNAL(activated(int)), 00038 this, SIGNAL(ValueChanged())); 00039 00040 p_type = ComboWidget; 00041 RememberWidget(p_combo); 00042 } 00043 00044 00045 GuiComboBoxParameter::~GuiComboBoxParameter() { 00046 delete p_combo; 00047 } 00048 00049 00050 void GuiComboBoxParameter::Set(QString newValue) { 00051 IString value = newValue; 00052 value.UpCase(); 00053 00054 int foundAtButton = -1; 00055 for(int i = 0; i < p_ui->ParamListSize(p_group, p_param); i++) { 00056 IString option = p_ui->ParamListValue(p_group, p_param, i); 00057 option.UpCase(); 00058 //if(option.compare(0, value.size(), value) == 0) foundAtButton = i; 00059 if(option == value) foundAtButton = i; 00060 } 00061 00062 if(foundAtButton != -1) { 00063 p_combo->setCurrentIndex(foundAtButton); 00064 } 00065 00066 emit ValueChanged(); 00067 } 00068 00069 00070 QString GuiComboBoxParameter::Value() { 00071 return p_ui->ParamListValue(p_group, p_param, 00072 p_combo->currentIndex()); 00073 } 00074 00075 std::vector<QString> GuiComboBoxParameter::Exclusions() { 00076 std::vector<QString> list; 00077 00078 int index = p_combo->currentIndex(); 00079 00080 for(int i = 0; i < p_ui->ParamListExcludeSize(p_group, p_param, index); i++) { 00081 QString s = p_ui->ParamListExclude(p_group, p_param, index, i); 00082 list.push_back(s); 00083 } 00084 00085 return list; 00086 } 00087 00088 void GuiComboBoxParameter::setOption (int option) { 00089 std::cout << "Combo box option: " << option << std::endl; 00090 } 00091 }