Isis 3 Programmer Reference
GuiParameter.cpp
Go to the documentation of this file.
1 
24 #include <QFileDialog>
25 #include <QHBoxLayout>
26 #include <QLabel>
27 #include <QLineEdit>
28 #include <QToolButton>
29 
30 #include "GuiParameter.h"
31 
32 #include "Application.h"
33 #include "FileName.h"
34 #include "GuiHelperAction.h"
35 #include "UserInterface.h"
36 
37 #include "GuiFilenameParameter.h"
38 #include "GuiCubeParameter.h"
39 
40 namespace Isis {
42  GuiParameter::GuiParameter(QGridLayout *grid, UserInterface &ui,
43  int group, int param) : QObject() {
44  p_ui = &ui;
45  p_group = group;
46  p_param = param;
47 
48  p_name = ui.ParamName(group, param);
49  p_fileButton = new QToolButton();
50  p_lineEdit = new QLineEdit();
51 
52  p_label = new QLabel(p_name);
53  p_label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
54  p_label->setToolTip(p_ui->ParamBrief(group, param));
55  grid->addWidget(p_label, param, 0, Qt::AlignCenter);
56 
57  QString whatsThis;
58  whatsThis = (QString)("<b>Parameter:</b> " + p_ui->ParamName(group, param));
59  whatsThis += (QString)("<p><b>Type:</b> " + p_ui->ParamType(group, param) + "</p>");
60  whatsThis += (QString)("<p><b>Brief:</b> " + p_ui->ParamBrief(group, param) + "</p>");
61  QString def = p_ui->ParamDefault(group, param);
62  if(def == "") def = "None";
63  whatsThis += "<p><b>Default: </b>" + QString(def) + "</p>";
64  QString intdef = p_ui->ParamInternalDefault(group, param);
65  if(intdef != "") {
66  whatsThis += "<p><b>Internal Default: </b> " + QString(intdef) + "</p>";
67  }
68  QString pixtype = p_ui->PixelType(group, param);
69  if(pixtype != "") {
70  whatsThis += "<p><b>Pixel Type: </b> " + QString(pixtype) + "</p>";
71  }
72  QString pmin = p_ui->ParamMinimum(group, param);
73  if(pmin != "") {
74  if(p_ui->ParamMinimumInclusive(group, param) == "YES") {
75  whatsThis += "<p><b>Greater Than Or Equal To: </b>" +
76  QString(pmin) + "</p>";
77  }
78  else {
79  whatsThis += "<p><b>Greater Than: </b>" + QString(pmin) + "</p>";
80  }
81  }
82  QString pmax = p_ui->ParamMaximum(group, param);
83  if(pmax != "") {
84  if(p_ui->ParamMaximumInclusive(group, param) == "YES") {
85  whatsThis += "<p><b>Less Than Or Equal To: </b>" +
86  QString(pmax) + "</p>";
87  }
88  else {
89  whatsThis += "<p><b>Less Than: </b>" + QString(pmax) + "</p>";
90  }
91  }
92  if(p_ui->ParamLessThanSize(group, param) > 0) {
93  whatsThis += "<p><b>Less Than: </b>" +
94  QString(p_ui->ParamLessThan(group, param, 0));
95  for(int l = 1; l < p_ui->ParamLessThanSize(group, param); l++) {
96  whatsThis += ", " + QString(p_ui->ParamLessThan(group, param, l));
97  }
98  whatsThis += "</p>";
99  }
100  if(p_ui->ParamLessThanOrEqualSize(group, param) > 0) {
101  whatsThis += "<p><b>Less Than Or Equal: </b>" +
102  QString(p_ui->ParamLessThanOrEqual(group, param, 0));
103  for(int l = 1; l < p_ui->ParamLessThanOrEqualSize(group, param); l++) {
104  whatsThis += ", " +
105  QString(p_ui->ParamLessThanOrEqual(group, param, l));
106  }
107  whatsThis += "</p>";
108  }
109  if(p_ui->ParamNotEqualSize(group, param) > 0) {
110  whatsThis += "<p><b>Not Equal: </b>" +
111  QString(p_ui->ParamNotEqual(group, param, 0));
112  for(int l = 1; l < p_ui->ParamNotEqualSize(group, param); l++) {
113  whatsThis += ", " + QString(p_ui->ParamNotEqual(group, param, l));
114  }
115  whatsThis += "</p>";
116  }
117  if(p_ui->ParamGreaterThanSize(group, param) > 0) {
118  whatsThis += "<p><b>Greater Than: </b>" +
119  QString(p_ui->ParamGreaterThan(group, param, 0));
120  for(int l = 1; l < p_ui->ParamGreaterThanSize(group, param); l++) {
121  whatsThis += ", " +
122  QString(p_ui->ParamGreaterThan(group, param, l));
123  }
124  whatsThis += "</p>";
125  }
126  if(p_ui->ParamGreaterThanOrEqualSize(group, param) > 0) {
127  whatsThis += "<p><b>Greater Than Or Equal: </b>" +
128  QString(p_ui->ParamGreaterThanOrEqual(group, param, 0));
129  for(int l = 1; l < p_ui->ParamGreaterThanOrEqualSize(group, param); l++) {
130  whatsThis += ", " +
131  QString(p_ui->ParamGreaterThanOrEqual(group, param, l));
132  }
133  whatsThis += "</p>";
134  }
135  if(p_ui->ParamIncludeSize(group, param) > 0) {
136  whatsThis += "<p><b>Inclusions: </b>" +
137  QString(p_ui->ParamInclude(group, param, 0));
138  for(int l = 1; l < p_ui->ParamIncludeSize(group, param); l++) {
139  whatsThis += ", " +
140  QString(p_ui->ParamInclude(group, param, l));
141  }
142  whatsThis += "</p>";
143  }
144  if(p_ui->ParamExcludeSize(group, param) > 0) {
145  whatsThis += "<p><b>Exclusions: </b>" +
146  QString(p_ui->ParamExclude(group, param, 0));
147  for(int l = 1; l < p_ui->ParamExcludeSize(group, param); l++) {
148  whatsThis += ", " +
149  QString(p_ui->ParamExclude(group, param, l));
150  }
151  whatsThis += "</p>";
152  }
153  if(p_ui->ParamOdd(group, param) != "") {
154  whatsThis += "<p><b>Odd: </b>" +
155  QString(p_ui->ParamOdd(group, param)) + "</p>";
156  }
157  p_label->setWhatsThis(whatsThis);
158 
159  p_helperMenu = NULL;
160  }
161 
162 
165  if(p_helperMenu) {
166  delete p_helperMenu;
167  p_helperMenu = NULL;
168  }
169 
170  p_widgetList.clear();
171  }
172 
175  if(p_ui->ParamDefault(p_group, p_param).size() > 0) {
176  Set(p_ui->ParamDefault(p_group, p_param));
177  }
178  else if(p_ui->ParamInternalDefault(p_group, p_param).size() > 0) {
179  Set(p_ui->ParamInternalDefault(p_group, p_param));
180  }
181  else {
182  Set("");
183  }
184  }
185 
188  if(p_ui->WasEntered(p_name)) {
189  Set(p_ui->GetAsString(p_name));
190  }
191  else {
192  SetToDefault();
193  }
194  }
195 
198  if(!IsEnabled()) return false;
199  if(p_ui->ParamDefault(p_group, p_param).size() > 0) {
200  if(Value() == p_ui->ParamDefault(p_group, p_param)) return false;
201  }
202  else if(p_ui->ParamInternalDefault(p_group, p_param).size() > 0) {
203  if(Value() == p_ui->ParamInternalDefault(p_group, p_param)) return false;
204  }
205  else {
206  if(Value() == "") return false;
207  }
208  return true;
209  }
210 
213  if(p_ui->WasEntered(p_name)) {
214  Set(p_ui->GetAsString(p_name));
215  }
216  else if(p_ui->ParamDefault(p_group, p_param).size() > 0) {
217  Set(p_ui->ParamDefault(p_group, p_param));
218  }
219  else if(p_ui->ParamInternalDefault(p_group, p_param).size() > 0) {
220  Set(p_ui->ParamInternalDefault(p_group, p_param));
221  }
222  else {
223  Set("");
224  }
225  }
226 
229  p_widgetList.push_back(w);
230  }
231 
233  void GuiParameter::SetEnabled(bool enabled, bool isParentCombo) {
234  if(p_type != ComboWidget) {
235  p_label->setEnabled(enabled);
236  p_label->setVisible(true);
237  if(isParentCombo && !enabled) {
238  p_label->setVisible(false);
239  }
240  for(int i = 0; i < p_widgetList.size(); i++) {
241  p_widgetList[i]->setEnabled(enabled);
242  p_widgetList[i]->setVisible(true);
243  if(isParentCombo && !enabled) {
244  p_widgetList[i]->setVisible(false);
245  }
246  }
247  }
248  else {
249  p_label->setEnabled(enabled);
250  p_widgetList[0]->setEnabled(enabled);
251  }
252  }
253 
255  std::vector<QString> GuiParameter::Exclusions() {
256  std::vector<QString> list;
257  return list;
258  }
259 
262  // Just make one single helper button
263  if(p_ui->HelpersSize(p_group, p_param) == 1) {
264  GuiHelperAction *action =
265  new GuiHelperAction(lo, p_ui->HelperFunction(p_group, p_param, 0));
266  if(p_ui->HelperIcon(p_group, p_param, 0) != "") {
267  QString file = FileName(
268  p_ui->HelperIcon(p_group, p_param, 0)).expanded();
269  action->setIcon(QIcon(QPixmap(file)));
270  }
271  else {
272  action->setText(p_ui->HelperButtonName(p_group, p_param, 0));
273  }
274  action->setToolTip(p_ui->HelperBrief(p_group, p_param, 0));
275  QString helperText = "<p><b>Function:</b> " +
276  QString(p_ui->HelperDescription(p_group, p_param, 0)) + "</p>";
277  action->setWhatsThis(helperText);
278  connect(action, SIGNAL(trigger(const QString &)), this,
279  SIGNAL(HelperTrigger(const QString &)));
280 
281  QToolButton *helper = new QToolButton();
282  helper->setText(p_ui->HelperButtonName(p_group, p_param, 0));
283  helper->setDefaultAction(action);
284 
285  if(p_ui->HelperIcon(p_group, p_param, 0) != "") {
286  helper->setText("");
287  QString file = FileName(
288  p_ui->HelperIcon(p_group, p_param, 0)).expanded();
289  helper->setIconSize(QSize(22, 22));
290  helper->setIcon(QIcon(QPixmap(file)));
291  }
292  else {
293  helper->setFixedWidth(helper->fontMetrics().width(
294  " " + helper->text() + " "));
295  }
296  RememberWidget(helper);
297  return helper;
298  }
299 
300  // Make a drop down menu of helper buttons
301  else {
302  if(p_helperMenu) {
304  "Can not call GuiParameter::AddHelpers twice",
305  _FILEINFO_);
306  }
307 
308  p_helperMenu = new QMenu();
309 
310  // Create default action item
311  GuiHelperAction *action =
312  new GuiHelperAction(lo, p_ui->HelperFunction(p_group, p_param, 0));
313  if(p_ui->HelperIcon(p_group, p_param, 0) != "") {
314  QString file = FileName(
315  p_ui->HelperIcon(p_group, p_param, 0)).expanded();
316  action->setIcon(QIcon(QPixmap(file)));
317  }
318  else {
319  action->setText(p_ui->HelperButtonName(p_group, p_param, 0));
320  }
321  connect(action, SIGNAL(trigger(const QString &)), this,
322  SIGNAL(HelperTrigger(const QString &)));
323 
324  // Set up helper button
325  QToolButton *helper = new QToolButton();
326  helper->setText(p_ui->HelperButtonName(p_group, p_param, 0));
327 
328  helper->setMenu(p_helperMenu);
329  helper->setPopupMode(QToolButton::MenuButtonPopup);
330  helper->setDefaultAction(action);
331  helper->setToolTip(p_ui->HelperBrief(p_group, p_param, 0));
332  QString text = "<p><b>Function:</b> " +
333  QString(p_ui->HelperDescription(p_group, p_param, 0)) + "</p>" +
334  "<p><b>Hint: </b> Click on the arrow to see more helper functions</p>";
335  helper->setWhatsThis(text);
336 
337  if(p_ui->HelperIcon(p_group, p_param, 0) != "") {
338  helper->setText("");
339  QString file = FileName(
340  p_ui->HelperIcon(p_group, p_param, 0)).expanded();
341  helper->setIconSize(QSize(22, 22));
342  helper->setIcon(QIcon(QPixmap(file)));
343  }
344  else {
345  helper->setFixedWidth(helper->fontMetrics().width(
346  " " + helper->text() + " "));
347  }
348 
349  // Set up default action item in menu list
350  GuiHelperAction *action2 =
351  new GuiHelperAction(lo, p_ui->HelperFunction(p_group, p_param, 0));
352  action2->setText(p_ui->HelperBrief(p_group, p_param, 0));
353  action2->setToolTip(p_ui->HelperBrief(p_group, p_param, 0));
354  QString helperText = "<p><b>Function:</b> " +
355  QString(p_ui->HelperDescription(p_group, p_param, 0)) + "</p>";
356  action2->setWhatsThis(helperText);
357  connect(action2, SIGNAL(trigger(const QString &)), this,
358  SIGNAL(HelperTrigger(const QString &)));
359  p_helperMenu->addAction(action2);
360 
361 
362  // Add each additional helper button to the menu list
363  for(int i = 1; i < p_ui->HelpersSize(p_group, p_param); i++) {
364  GuiHelperAction *helperAction =
365  new GuiHelperAction(lo, p_ui->HelperFunction(p_group, p_param, i));
366  helperAction->setText(p_ui->HelperBrief(p_group, p_param, i));
367  helperAction->setToolTip(p_ui->HelperBrief(p_group, p_param, i));
368  QString helperText = "<p><b>Function:</b> " +
369  QString(p_ui->HelperDescription(p_group, p_param, i)) + "</p>";
370  helperAction->setWhatsThis(helperText);
371  connect(helperAction, SIGNAL(trigger(const QString &)), this,
372  SIGNAL(HelperTrigger(const QString &)));
373  p_helperMenu->addAction(helperAction);
374  }
375  RememberWidget(helper);
376  return helper;
377  }
378  }
379 }
virtual ~GuiParameter()
Destructor.
int ParamLessThanOrEqualSize(const int &group, const int &param) const
Returns the number of values in the parameters less than or equal list.
Definition: IsisAml.cpp:1377
void SetEnabled(bool enabled, bool isParentCombo=false)
Enable or disable the parameter.
File name manipulation and expansion.
Definition: FileName.h:116
QWidget * AddHelpers(QObject *lo)
Sets up helper button.
int ParamGreaterThanSize(const int &group, const int &param) const
Returns the number of values in the parameters greater than list.
Definition: IsisAml.cpp:1340
int HelpersSize(const int &group, const int &param) const
Returns the number of helpers the parameter has.
Definition: IsisAml.cpp:1771
QString ParamMaximum(const int &group, const int &param) const
Returns the maximum value of a parameter in a specified group.
Definition: IsisAml.cpp:1287
QString GetAsString(const QString &paramName) const
Allows the retrieval of a value for a parameter of any type.
Definition: IsisAml.cpp:553
bool IsEnabled() const
Is the parameter enabled.
Definition: GuiParameter.h:75
void Update()
Update the value on the GUI with the value in the UI.
void SetToDefault()
Change the parameter to the default value.
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:162
int ParamIncludeSize(const int &group, const int &param) const
Returns the number of parameters included in this parameter&#39;s inclusions.
Definition: IsisAml.cpp:1747
QString ParamType(const int &group, const int &param) const
Returns the parameter type of a parameter in a specified group.
Definition: IsisAml.cpp:1508
GuiParameter(QGridLayout *grid, UserInterface &ui, int group, int param)
Constructor.
QString ParamInternalDefault(const int &group, const int &param) const
Returns the internal default for a parameter in a specified group.
Definition: IsisAml.cpp:1540
QString PixelType(const int &group, const int &param) const
Returns the default pixel type from the XML.
Definition: IsisAml.cpp:1759
QString ParamGreaterThanOrEqual(const int &group, const int &param, const int &great) const
Returns the name of the specified greaterThanOrEqual parameter.
Definition: IsisAml.cpp:1418
QString ParamNotEqual(const int &group, const int &param, const int &notEq) const
Returns the name of the specified notEqual parameter.
Definition: IsisAml.cpp:1463
QString HelperButtonName(const int &group, const int &param, const int &helper) const
Returns the name of the helper button.
Definition: IsisAml.cpp:1784
QString ParamOdd(const int &group, const int &param) const
Returns whether the selected parameter has a restriction on odd values or not.
Definition: IsisAml.cpp:1327
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
QString HelperDescription(const int &group, const int &param, const int &helper) const
Returns the long description of the helper button.
Definition: IsisAml.cpp:1826
QString HelperFunction(const int &group, const int &param, const int &helper) const
Returns the name of the helper function.
Definition: IsisAml.cpp:1798
virtual bool IsModified()
Return if the parameter value is different from the default value.
int ParamLessThanSize(const int &group, const int &param) const
Returns the number of values in the parameters less than list.
Definition: IsisAml.cpp:1365
QString ParamMaximumInclusive(const int &group, const int &param) const
Returns whether the maximum value is inclusive or not.
Definition: IsisAml.cpp:1313
QString ParamMinimum(const int &group, const int &param) const
Returns the minimum value of a parameter in a specified group.
Definition: IsisAml.cpp:1274
int ParamExcludeSize(const int &group, const int &param) const
Returns the number of parameters excluded in this parameter&#39;s exclusions.
Definition: IsisAml.cpp:1735
int ParamGreaterThanOrEqualSize(const int &group, const int &param) const
Returns the number of values in the parameters greater than or equal list.
Definition: IsisAml.cpp:1352
void SetToCurrent()
Change the parameter to the current user interface value.
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
virtual std::vector< QString > Exclusions()
Return list of current exclusions.
Command Line and Xml loader, validation, and access.
QString ParamDefault(const int &group, const int &param) const
Returns the default for a parameter in a specified group.
Definition: IsisAml.cpp:1521
QString ParamLessThanOrEqual(const int &group, const int &param, const int &les) const
Returns the name of the specified lessThanOrEqual parameter.
Definition: IsisAml.cpp:1448
void RememberWidget(QWidget *w)
Add widgets to a list for enabling/disabling.
QString ParamMinimumInclusive(const int &group, const int &param) const
Returns whether the minimum value is inclusive or not.
Definition: IsisAml.cpp:1300
QString ParamBrief(const int &group, const int &param) const
Returns the brief description of a parameter in a specified group.
Definition: IsisAml.cpp:1248
QString ParamGreaterThan(const int &group, const int &param, const int &great) const
Returns the name of the specified greaterThan parameter.
Definition: IsisAml.cpp:1403
QString ParamName(const int &group, const int &param) const
Returns the parameter name.
Definition: IsisAml.cpp:1235
QString ParamLessThan(const int &group, const int &param, const int &great) const
Returns the name of the specified lessThan parameter.
Definition: IsisAml.cpp:1433
QString ParamExclude(const int &group, const int &param, const int &exclude) const
Returns the name of the specified excluded parameter.
Definition: IsisAml.cpp:1478
bool WasEntered(const QString &paramName) const
Returns a true if the parameter has a value, and false if it does not.
Definition: IsisAml.cpp:1852
int ParamNotEqualSize(const int &group, const int &param) const
Returns the number of values in the not equal list.
Definition: IsisAml.cpp:1390
QString ParamInclude(const int &group, const int &param, const int &include) const
Returns the name of the specified included parameter.
Definition: IsisAml.cpp:1493
QString HelperBrief(const int &group, const int &param, const int &helper) const
Returns the brief description of the helper button.
Definition: IsisAml.cpp:1812
QString HelperIcon(const int &group, const int &param, const int &helper) const
Returns the name of the icon for the helper button.
Definition: IsisAml.cpp:1840