Isis 3 Programmer Reference
GuiInputAttribute.cpp
Go to the documentation of this file.
1 
24 #include <iostream>
25 #include <string>
26 
27 #include <QDebug>
28 #include <QRadioButton>
29 #include <QPushButton>
30 #include <QButtonGroup>
31 #include <QGridLayout>
32 #include <QHBoxLayout>
33 #include <QVBoxLayout>
34 
35 #include "CubeAttribute.h"
36 #include "FileName.h"
37 #include "GuiInputAttribute.h"
38 
39 namespace Isis {
41  int GuiInputAttribute::GetAttributes(const QString &defaultAttribute,
42  QString &newAttribute,
43  const QString &title,
44  QWidget *parent) {
45  // Construct dialog if necessary
46  static GuiInputAttribute *p_dialog = 0;
47  if(p_dialog == 0) {
48  p_dialog = new GuiInputAttribute(parent);
49  }
50  p_dialog->setWindowTitle(title);
51 
52  // Load default attributes and then get the new ones
53  p_dialog->SetAttributes(defaultAttribute);
54  if(p_dialog->exec() == QDialog::Accepted) {
55  newAttribute = p_dialog->GetAttributes();
56  return 1;
57  }
58  newAttribute = defaultAttribute;
59  return 0;
60  }
61 
64  // Create the two radio buttons
65  QRadioButton *allBands = new QRadioButton("&All Bands");
66  allBands->setToolTip("Select all bands from the input cube");
67 
68  QRadioButton *listBands = new QRadioButton("&Band List");
69  listBands->setToolTip("Select any bands from the input cube");
70 
71  // Create the button group for the radio buttons
72  p_buttonGroup = new QButtonGroup();
73  p_buttonGroup->addButton(allBands);
74  p_buttonGroup->addButton(listBands);
75  p_buttonGroup->setExclusive(true);
76 
77  // Create the text field for list toggle button
78  p_lineEdit = new QLineEdit();
79  connect(allBands, SIGNAL(toggled(bool)), p_lineEdit, SLOT(setDisabled(bool)));
80  allBands->setChecked(true);
81 
82  // Put the buttons and text field in a gridlayout
83  QGridLayout *gridLayout = new QGridLayout();
84  gridLayout->addWidget(allBands, 0, 0);
85  gridLayout->addWidget(listBands, 1, 0);
86  gridLayout->addWidget(p_lineEdit, 1, 1);
87 
88  // Create the action buttons
89  QPushButton *okButton = new QPushButton("Ok");
90  connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
91 
92  QPushButton *cancelButton = new QPushButton("Cancel");
93  connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
94 
95 #if 0
96  // Add them to a button group
97  QButtonGroup *actionGroup = new QButtonGroup();
98  actionGroup->addButton(okButton);
99  actionGroup->addButton(cancelButton);
100 #endif
101 
102  // Put the buttons in a horizontal orientation
103  QHBoxLayout *actionLayout = new QHBoxLayout();
104  actionLayout->addWidget(okButton);
105  actionLayout->addWidget(cancelButton);
106 
107  // Put the grid layout and action layout on the dialog
108  QVBoxLayout *dialogLayout = new QVBoxLayout(this);
109  dialogLayout->addLayout(gridLayout);
110  dialogLayout->addLayout(actionLayout);
111  }
112 
113 
114  // Destructor
115  GuiInputAttribute::~GuiInputAttribute() {}
116 
117 
118  // Return the attributes in the dialog
119  QString GuiInputAttribute::GetAttributes() {
120  QString attStr("");
121  if(p_lineEdit->isEnabled()) {
122  attStr = p_lineEdit->text().simplified();
123  attStr = attStr.remove(QRegExp("^[+]*"));
124  if (attStr.length() > 0) {
125  if (attStr.left(1) != "+") attStr.prepend('+');
126  }
127  }
128  return attStr;
129  }
130 
131 
132  // Set the attributes in the dialog
133  void GuiInputAttribute::SetAttributes(const QString &value) {
134  Isis::CubeAttributeInput att(value);
135  std::vector<QString> bands = att.bands();
136  if(bands.size() == 0) {
137  p_buttonGroup->buttons()[0]->setChecked(true);
138  p_lineEdit->setText("");
139  }
140  else {
141  p_buttonGroup->buttons()[1]->setChecked(true);
142  p_lineEdit->setText(att.toString());
143  }
144  }
145 }
146 
Manipulate and parse attributes of input cube filenames.
GuiInputAttribute(QWidget *parent=0)
Constuctor.
GUI interface for input cube file attributes.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31