Isis 3 Programmer Reference
GuiParameter.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 
8 #include <QFileDialog>
9 #include <QHBoxLayout>
10 #include <QLabel>
11 #include <QLineEdit>
12 #include <QToolButton>
13 
14 #include "GuiParameter.h"
15 
16 #include "Application.h"
17 #include "FileName.h"
18 #include "GuiHelperAction.h"
19 #include "UserInterface.h"
20 
21 #include "GuiFilenameParameter.h"
22 #include "GuiCubeParameter.h"
23 
24 namespace Isis {
26  GuiParameter::GuiParameter(QGridLayout *grid, UserInterface &ui,
27  int group, int param) : QObject() {
28  p_ui = &ui;
29  p_group = group;
30  p_param = param;
31 
32  p_name = ui.ParamName(group, param);
33  p_fileButton = new QToolButton();
34  p_lineEdit = new QLineEdit();
35 
36  p_label = new QLabel(p_name);
37  p_label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
38  p_label->setToolTip(p_ui->ParamBrief(group, param));
39  grid->addWidget(p_label, param, 0, Qt::AlignTop);
40 
41  QString whatsThis;
42  whatsThis = (QString)("<b>Parameter:</b> " + p_ui->ParamName(group, param));
43  whatsThis += (QString)("<p><b>Type:</b> " + p_ui->ParamType(group, param) + "</p>");
44  whatsThis += (QString)("<p><b>Brief:</b> " + p_ui->ParamBrief(group, param) + "</p>");
45  QString def = p_ui->ParamDefault(group, param);
46  if(def == "") def = "None";
47  whatsThis += "<p><b>Default: </b>" + QString(def) + "</p>";
48  QString intdef = p_ui->ParamInternalDefault(group, param);
49  if(intdef != "") {
50  whatsThis += "<p><b>Internal Default: </b> " + QString(intdef) + "</p>";
51  }
52  QString pixtype = p_ui->PixelType(group, param);
53  if(pixtype != "") {
54  whatsThis += "<p><b>Pixel Type: </b> " + QString(pixtype) + "</p>";
55  }
56  QString pmin = p_ui->ParamMinimum(group, param);
57  if(pmin != "") {
58  if(p_ui->ParamMinimumInclusive(group, param) == "YES") {
59  whatsThis += "<p><b>Greater Than Or Equal To: </b>" +
60  QString(pmin) + "</p>";
61  }
62  else {
63  whatsThis += "<p><b>Greater Than: </b>" + QString(pmin) + "</p>";
64  }
65  }
66  QString pmax = p_ui->ParamMaximum(group, param);
67  if(pmax != "") {
68  if(p_ui->ParamMaximumInclusive(group, param) == "YES") {
69  whatsThis += "<p><b>Less Than Or Equal To: </b>" +
70  QString(pmax) + "</p>";
71  }
72  else {
73  whatsThis += "<p><b>Less Than: </b>" + QString(pmax) + "</p>";
74  }
75  }
76  if(p_ui->ParamLessThanSize(group, param) > 0) {
77  whatsThis += "<p><b>Less Than: </b>" +
78  QString(p_ui->ParamLessThan(group, param, 0));
79  for(int l = 1; l < p_ui->ParamLessThanSize(group, param); l++) {
80  whatsThis += ", " + QString(p_ui->ParamLessThan(group, param, l));
81  }
82  whatsThis += "</p>";
83  }
84  if(p_ui->ParamLessThanOrEqualSize(group, param) > 0) {
85  whatsThis += "<p><b>Less Than Or Equal: </b>" +
86  QString(p_ui->ParamLessThanOrEqual(group, param, 0));
87  for(int l = 1; l < p_ui->ParamLessThanOrEqualSize(group, param); l++) {
88  whatsThis += ", " +
89  QString(p_ui->ParamLessThanOrEqual(group, param, l));
90  }
91  whatsThis += "</p>";
92  }
93  if(p_ui->ParamNotEqualSize(group, param) > 0) {
94  whatsThis += "<p><b>Not Equal: </b>" +
95  QString(p_ui->ParamNotEqual(group, param, 0));
96  for(int l = 1; l < p_ui->ParamNotEqualSize(group, param); l++) {
97  whatsThis += ", " + QString(p_ui->ParamNotEqual(group, param, l));
98  }
99  whatsThis += "</p>";
100  }
101  if(p_ui->ParamGreaterThanSize(group, param) > 0) {
102  whatsThis += "<p><b>Greater Than: </b>" +
103  QString(p_ui->ParamGreaterThan(group, param, 0));
104  for(int l = 1; l < p_ui->ParamGreaterThanSize(group, param); l++) {
105  whatsThis += ", " +
106  QString(p_ui->ParamGreaterThan(group, param, l));
107  }
108  whatsThis += "</p>";
109  }
110  if(p_ui->ParamGreaterThanOrEqualSize(group, param) > 0) {
111  whatsThis += "<p><b>Greater Than Or Equal: </b>" +
112  QString(p_ui->ParamGreaterThanOrEqual(group, param, 0));
113  for(int l = 1; l < p_ui->ParamGreaterThanOrEqualSize(group, param); l++) {
114  whatsThis += ", " +
115  QString(p_ui->ParamGreaterThanOrEqual(group, param, l));
116  }
117  whatsThis += "</p>";
118  }
119  if(p_ui->ParamIncludeSize(group, param) > 0) {
120  whatsThis += "<p><b>Inclusions: </b>" +
121  QString(p_ui->ParamInclude(group, param, 0));
122  for(int l = 1; l < p_ui->ParamIncludeSize(group, param); l++) {
123  whatsThis += ", " +
124  QString(p_ui->ParamInclude(group, param, l));
125  }
126  whatsThis += "</p>";
127  }
128  if(p_ui->ParamExcludeSize(group, param) > 0) {
129  whatsThis += "<p><b>Exclusions: </b>" +
130  QString(p_ui->ParamExclude(group, param, 0));
131  for(int l = 1; l < p_ui->ParamExcludeSize(group, param); l++) {
132  whatsThis += ", " +
133  QString(p_ui->ParamExclude(group, param, l));
134  }
135  whatsThis += "</p>";
136  }
137  if(p_ui->ParamOdd(group, param) != "") {
138  whatsThis += "<p><b>Odd: </b>" +
139  QString(p_ui->ParamOdd(group, param)) + "</p>";
140  }
141  p_label->setWhatsThis(whatsThis);
142 
143  p_helperMenu = NULL;
144  }
145 
146 
149  if(p_helperMenu) {
150  delete p_helperMenu;
151  p_helperMenu = NULL;
152  }
153 
154  p_widgetList.clear();
155  }
156 
159  if(p_ui->ParamDefault(p_group, p_param).size() > 0) {
160  Set(p_ui->ParamDefault(p_group, p_param));
161  }
162  else if(p_ui->ParamInternalDefault(p_group, p_param).size() > 0) {
163  Set(p_ui->ParamInternalDefault(p_group, p_param));
164  }
165  else {
166  Set("");
167  }
168  }
169 
172  if(p_ui->WasEntered(p_name)) {
173  Set(p_ui->GetAsString(p_name));
174  }
175  else {
176  SetToDefault();
177  }
178  }
179 
182  if(!IsEnabled()) return false;
183  if(p_ui->ParamDefault(p_group, p_param).size() > 0) {
184  if(Value() == p_ui->ParamDefault(p_group, p_param)) return false;
185  }
186  else if(p_ui->ParamInternalDefault(p_group, p_param).size() > 0) {
187  if(Value() == p_ui->ParamInternalDefault(p_group, p_param)) return false;
188  }
189  else {
190  if(Value() == "") return false;
191  }
192  return true;
193  }
194 
197  if(p_ui->WasEntered(p_name)) {
198  Set(p_ui->GetAsString(p_name));
199  }
200  else if(p_ui->ParamDefault(p_group, p_param).size() > 0) {
201  Set(p_ui->ParamDefault(p_group, p_param));
202  }
203  else if(p_ui->ParamInternalDefault(p_group, p_param).size() > 0) {
204  Set(p_ui->ParamInternalDefault(p_group, p_param));
205  }
206  else {
207  Set("");
208  }
209  }
210 
213  p_widgetList.push_back(w);
214  }
215 
217  void GuiParameter::SetEnabled(bool enabled, bool isParentCombo) {
218  if(p_type != ComboWidget) {
219  p_label->setEnabled(enabled);
220  p_label->setVisible(true);
221  if(isParentCombo && !enabled) {
222  p_label->setVisible(false);
223  }
224  for(int i = 0; i < p_widgetList.size(); i++) {
225  p_widgetList[i]->setEnabled(enabled);
226  p_widgetList[i]->setVisible(true);
227  if(isParentCombo && !enabled) {
228  p_widgetList[i]->setVisible(false);
229  }
230  }
231  }
232  else {
233  p_label->setEnabled(enabled);
234  p_widgetList[0]->setEnabled(enabled);
235  }
236  }
237 
239  std::vector<QString> GuiParameter::Exclusions() {
240  std::vector<QString> list;
241  return list;
242  }
243 
246  // Just make one single helper button
247  if(p_ui->HelpersSize(p_group, p_param) == 1) {
248  GuiHelperAction *action =
249  new GuiHelperAction(lo, p_ui->HelperFunction(p_group, p_param, 0));
250  if(p_ui->HelperIcon(p_group, p_param, 0) != "") {
251  QString file = FileName(
252  p_ui->HelperIcon(p_group, p_param, 0)).expanded();
253  action->setIcon(QIcon(QPixmap(file)));
254  }
255  else {
256  action->setText(p_ui->HelperButtonName(p_group, p_param, 0));
257  }
258  action->setToolTip(p_ui->HelperBrief(p_group, p_param, 0));
259  QString helperText = "<p><b>Function:</b> " +
260  QString(p_ui->HelperDescription(p_group, p_param, 0)) + "</p>";
261  action->setWhatsThis(helperText);
262  connect(action, SIGNAL(trigger(const QString &)), this,
263  SIGNAL(HelperTrigger(const QString &)));
264 
265  QToolButton *helper = new QToolButton();
266  helper->setText(p_ui->HelperButtonName(p_group, p_param, 0));
267  helper->setDefaultAction(action);
268 
269  if(p_ui->HelperIcon(p_group, p_param, 0) != "") {
270  helper->setText("");
271  QString file = FileName(
272  p_ui->HelperIcon(p_group, p_param, 0)).expanded();
273  helper->setIconSize(QSize(22, 22));
274  helper->setIcon(QIcon(QPixmap(file)));
275  }
276  else {
277  helper->setFixedWidth(helper->fontMetrics().width(
278  " " + helper->text() + " "));
279  }
280  RememberWidget(helper);
281  return helper;
282  }
283 
284  // Make a drop down menu of helper buttons
285  else {
286  if(p_helperMenu) {
288  "Can not call GuiParameter::AddHelpers twice",
289  _FILEINFO_);
290  }
291 
292  p_helperMenu = new QMenu();
293 
294  // Create default action item
295  GuiHelperAction *action =
296  new GuiHelperAction(lo, p_ui->HelperFunction(p_group, p_param, 0));
297  if(p_ui->HelperIcon(p_group, p_param, 0) != "") {
298  QString file = FileName(
299  p_ui->HelperIcon(p_group, p_param, 0)).expanded();
300  action->setIcon(QIcon(QPixmap(file)));
301  }
302  else {
303  action->setText(p_ui->HelperButtonName(p_group, p_param, 0));
304  }
305  connect(action, SIGNAL(trigger(const QString &)), this,
306  SIGNAL(HelperTrigger(const QString &)));
307 
308  // Set up helper button
309  QToolButton *helper = new QToolButton();
310  helper->setText(p_ui->HelperButtonName(p_group, p_param, 0));
311 
312  helper->setMenu(p_helperMenu);
313  helper->setPopupMode(QToolButton::MenuButtonPopup);
314  helper->setDefaultAction(action);
315  helper->setToolTip(p_ui->HelperBrief(p_group, p_param, 0));
316  QString text = "<p><b>Function:</b> " +
317  QString(p_ui->HelperDescription(p_group, p_param, 0)) + "</p>" +
318  "<p><b>Hint: </b> Click on the arrow to see more helper functions</p>";
319  helper->setWhatsThis(text);
320 
321  if(p_ui->HelperIcon(p_group, p_param, 0) != "") {
322  helper->setText("");
323  QString file = FileName(
324  p_ui->HelperIcon(p_group, p_param, 0)).expanded();
325  helper->setIconSize(QSize(22, 22));
326  helper->setIcon(QIcon(QPixmap(file)));
327  }
328  else {
329  helper->setFixedWidth(helper->fontMetrics().width(
330  " " + helper->text() + " "));
331  }
332 
333  // Set up default action item in menu list
334  GuiHelperAction *action2 =
335  new GuiHelperAction(lo, p_ui->HelperFunction(p_group, p_param, 0));
336  action2->setText(p_ui->HelperBrief(p_group, p_param, 0));
337  action2->setToolTip(p_ui->HelperBrief(p_group, p_param, 0));
338  QString helperText = "<p><b>Function:</b> " +
339  QString(p_ui->HelperDescription(p_group, p_param, 0)) + "</p>";
340  action2->setWhatsThis(helperText);
341  connect(action2, SIGNAL(trigger(const QString &)), this,
342  SIGNAL(HelperTrigger(const QString &)));
343  p_helperMenu->addAction(action2);
344 
345 
346  // Add each additional helper button to the menu list
347  for(int i = 1; i < p_ui->HelpersSize(p_group, p_param); i++) {
348  GuiHelperAction *helperAction =
349  new GuiHelperAction(lo, p_ui->HelperFunction(p_group, p_param, i));
350  helperAction->setText(p_ui->HelperBrief(p_group, p_param, i));
351  helperAction->setToolTip(p_ui->HelperBrief(p_group, p_param, i));
352  QString helperText = "<p><b>Function:</b> " +
353  QString(p_ui->HelperDescription(p_group, p_param, i)) + "</p>";
354  helperAction->setWhatsThis(helperText);
355  connect(helperAction, SIGNAL(trigger(const QString &)), this,
356  SIGNAL(HelperTrigger(const QString &)));
357  p_helperMenu->addAction(helperAction);
358  }
359  RememberWidget(helper);
360  return helper;
361  }
362  }
363 }
Isis::GuiParameter::RememberWidget
void RememberWidget(QWidget *w)
Add widgets to a list for enabling/disabling.
Definition: GuiParameter.cpp:212
IsisAml::HelperIcon
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:1824
Isis::GuiParameter::Update
void Update()
Update the value on the GUI with the value in the UI.
Definition: GuiParameter.cpp:196
QWidget
Isis::GuiParameter::SetToDefault
void SetToDefault()
Change the parameter to the default value.
Definition: GuiParameter.cpp:158
IsisAml::HelperDescription
QString HelperDescription(const int &group, const int &param, const int &helper) const
Returns the long description of the helper button.
Definition: IsisAml.cpp:1810
Isis::GuiParameter::IsEnabled
bool IsEnabled() const
Is the parameter enabled.
Definition: GuiParameter.h:59
Isis::GuiParameter::GuiParameter
GuiParameter(QGridLayout *grid, UserInterface &ui, int group, int param)
Constructor.
Definition: GuiParameter.cpp:26
IsisAml::GetAsString
QString GetAsString(const QString &paramName) const
Allows the retrieval of a value for a parameter of any type.
Definition: IsisAml.cpp:537
IsisAml::ParamMinimumInclusive
QString ParamMinimumInclusive(const int &group, const int &param) const
Returns whether the minimum value is inclusive or not.
Definition: IsisAml.cpp:1284
Isis::GuiParameter::~GuiParameter
virtual ~GuiParameter()
Destructor.
Definition: GuiParameter.cpp:148
Isis::FileName
File name manipulation and expansion.
Definition: FileName.h:100
QMenu
IsisAml::ParamBrief
QString ParamBrief(const int &group, const int &param) const
Returns the brief description of a parameter in a specified group.
Definition: IsisAml.cpp:1232
IsisAml::ParamGreaterThanOrEqual
QString ParamGreaterThanOrEqual(const int &group, const int &param, const int &great) const
Returns the name of the specified greaterThanOrEqual parameter.
Definition: IsisAml.cpp:1402
IsisAml::HelpersSize
int HelpersSize(const int &group, const int &param) const
Returns the number of helpers the parameter has.
Definition: IsisAml.cpp:1755
Isis::GuiParameter::SetEnabled
void SetEnabled(bool enabled, bool isParentCombo=false)
Enable or disable the parameter.
Definition: GuiParameter.cpp:217
IsisAml::ParamMaximum
QString ParamMaximum(const int &group, const int &param) const
Returns the maximum value of a parameter in a specified group.
Definition: IsisAml.cpp:1271
IsisAml::HelperFunction
QString HelperFunction(const int &group, const int &param, const int &helper) const
Returns the name of the helper function.
Definition: IsisAml.cpp:1782
IsisAml::ParamGreaterThan
QString ParamGreaterThan(const int &group, const int &param, const int &great) const
Returns the name of the specified greaterThan parameter.
Definition: IsisAml.cpp:1387
Isis::GuiParameter::IsModified
virtual bool IsModified()
Return if the parameter value is different from the default value.
Definition: GuiParameter.cpp:181
IsisAml::ParamDefault
QString ParamDefault(const int &group, const int &param) const
Returns the default for a parameter in a specified group.
Definition: IsisAml.cpp:1505
IsisAml::ParamIncludeSize
int ParamIncludeSize(const int &group, const int &param) const
Returns the number of parameters included in this parameter's inclusions.
Definition: IsisAml.cpp:1731
IsisAml::ParamType
QString ParamType(const int &group, const int &param) const
Returns the parameter type of a parameter in a specified group.
Definition: IsisAml.cpp:1492
IsisAml::ParamInternalDefault
QString ParamInternalDefault(const int &group, const int &param) const
Returns the internal default for a parameter in a specified group.
Definition: IsisAml.cpp:1524
Isis::FileName::expanded
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition: FileName.cpp:196
IsisAml::ParamNotEqualSize
int ParamNotEqualSize(const int &group, const int &param) const
Returns the number of values in the not equal list.
Definition: IsisAml.cpp:1374
IsisAml::HelperBrief
QString HelperBrief(const int &group, const int &param, const int &helper) const
Returns the brief description of the helper button.
Definition: IsisAml.cpp:1796
Isis::GuiParameter::Exclusions
virtual std::vector< QString > Exclusions()
Return list of current exclusions.
Definition: GuiParameter.cpp:239
IsisAml::ParamExclude
QString ParamExclude(const int &group, const int &param, const int &exclude) const
Returns the name of the specified excluded parameter.
Definition: IsisAml.cpp:1462
IsisAml::ParamNotEqual
QString ParamNotEqual(const int &group, const int &param, const int &notEq) const
Returns the name of the specified notEqual parameter.
Definition: IsisAml.cpp:1447
IsisAml::ParamMinimum
QString ParamMinimum(const int &group, const int &param) const
Returns the minimum value of a parameter in a specified group.
Definition: IsisAml.cpp:1258
IsisAml::ParamExcludeSize
int ParamExcludeSize(const int &group, const int &param) const
Returns the number of parameters excluded in this parameter's exclusions.
Definition: IsisAml.cpp:1719
IsisAml::ParamInclude
QString ParamInclude(const int &group, const int &param, const int &include) const
Returns the name of the specified included parameter.
Definition: IsisAml.cpp:1477
Isis::GuiParameter::SetToCurrent
void SetToCurrent()
Change the parameter to the current user interface value.
Definition: GuiParameter.cpp:171
Isis::GuiHelperAction
Definition: GuiHelperAction.h:16
Isis::IException
Isis exception class.
Definition: IException.h:91
IsisAml::PixelType
QString PixelType(const int &group, const int &param) const
Returns the default pixel type from the XML.
Definition: IsisAml.cpp:1743
IsisAml::ParamGreaterThanOrEqualSize
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:1336
IsisAml::ParamGreaterThanSize
int ParamGreaterThanSize(const int &group, const int &param) const
Returns the number of values in the parameters greater than list.
Definition: IsisAml.cpp:1324
IsisAml::ParamLessThan
QString ParamLessThan(const int &group, const int &param, const int &great) const
Returns the name of the specified lessThan parameter.
Definition: IsisAml.cpp:1417
IsisAml::WasEntered
bool WasEntered(const QString &paramName) const
Returns a true if the parameter has a value, and false if it does not.
Definition: IsisAml.cpp:1836
IsisAml::ParamLessThanSize
int ParamLessThanSize(const int &group, const int &param) const
Returns the number of values in the parameters less than list.
Definition: IsisAml.cpp:1349
Isis::IException::Programmer
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:146
IsisAml::ParamLessThanOrEqualSize
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:1361
Isis::UserInterface
Command Line and Xml loader, validation, and access.
Definition: UserInterface.h:140
IsisAml::HelperButtonName
QString HelperButtonName(const int &group, const int &param, const int &helper) const
Returns the name of the helper button.
Definition: IsisAml.cpp:1768
IsisAml::ParamLessThanOrEqual
QString ParamLessThanOrEqual(const int &group, const int &param, const int &les) const
Returns the name of the specified lessThanOrEqual parameter.
Definition: IsisAml.cpp:1432
QObject
IsisAml::ParamMaximumInclusive
QString ParamMaximumInclusive(const int &group, const int &param) const
Returns whether the maximum value is inclusive or not.
Definition: IsisAml.cpp:1297
IsisAml::ParamOdd
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:1311
IsisAml::ParamName
QString ParamName(const int &group, const int &param) const
Returns the parameter name.
Definition: IsisAml.cpp:1219
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::GuiParameter::AddHelpers
QWidget * AddHelpers(QObject *lo)
Sets up helper button.
Definition: GuiParameter.cpp:245