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
24namespace Isis {
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}
File name manipulation and expansion.
Definition FileName.h:100
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition FileName.cpp:196
void Update()
Update the value on the GUI with the value in the UI.
bool IsEnabled() const
Is the parameter enabled.
virtual bool IsModified()
Return if the parameter value is different from the default value.
void RememberWidget(QWidget *w)
Add widgets to a list for enabling/disabling.
void SetToDefault()
Change the parameter to the default value.
virtual std::vector< QString > Exclusions()
Return list of current exclusions.
void SetEnabled(bool enabled, bool isParentCombo=false)
Enable or disable the parameter.
GuiParameter(QGridLayout *grid, UserInterface &ui, int group, int param)
Constructor.
void SetToCurrent()
Change the parameter to the current user interface value.
QWidget * AddHelpers(QObject *lo)
Sets up helper button.
virtual ~GuiParameter()
Destructor.
Isis exception class.
Definition IException.h:91
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
Command Line and Xml loader, validation, and access.
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:1461
int ParamExcludeSize(const int &group, const int &param) const
Returns the number of parameters excluded in this parameter's exclusions.
Definition IsisAml.cpp:1894
QString ParamLessThan(const int &group, const int &param, const int &great) const
Returns the name of the specified lessThan parameter.
Definition IsisAml.cpp:1575
QString ParamLessThanOrEqual(const int &group, const int &param, const int &les) const
Returns the name of the specified lessThanOrEqual parameter.
Definition IsisAml.cpp:1591
QString ParamBrief(const int &group, const int &param) const
Returns the brief description of a parameter in a specified group.
Definition IsisAml.cpp:1376
bool WasEntered(const QString &paramName) const
Returns a true if the parameter has a value, and false if it does not.
Definition IsisAml.cpp:2020
QString PixelType(const int &group, const int &param) const
Returns the default pixel type from the XML.
Definition IsisAml.cpp:1920
int ParamGreaterThanSize(const int &group, const int &param) const
Returns the number of values in the parameters greater than list.
Definition IsisAml.cpp:1475
QString ParamNotEqual(const int &group, const int &param, const int &notEq) const
Returns the name of the specified notEqual parameter.
Definition IsisAml.cpp:1607
int HelpersSize(const int &group, const int &param) const
Returns the number of helpers the parameter has.
Definition IsisAml.cpp:1933
QString ParamGreaterThanOrEqual(const int &group, const int &param, const int &great) const
Returns the name of the specified greaterThanOrEqual parameter.
Definition IsisAml.cpp:1559
QString ParamMaximumInclusive(const int &group, const int &param) const
Returns whether the maximum value is inclusive or not.
Definition IsisAml.cpp:1446
QString ParamType(const int &group, const int &param) const
Returns the parameter type of a parameter in a specified group.
Definition IsisAml.cpp:1654
QString ParamExclude(const int &group, const int &param, const int &exclude) const
Returns the name of the specified excluded parameter.
Definition IsisAml.cpp:1623
QString HelperFunction(const int &group, const int &param, const int &helper) const
Returns the name of the helper function.
Definition IsisAml.cpp:1962
QString HelperButtonName(const int &group, const int &param, const int &helper) const
Returns the name of the helper button.
Definition IsisAml.cpp:1947
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:1515
QString ParamDefault(const int &group, const int &param) const
Returns the default for a parameter in a specified group.
Definition IsisAml.cpp:1668
int ParamLessThanSize(const int &group, const int &param) const
Returns the number of values in the parameters less than list.
Definition IsisAml.cpp:1502
QString HelperBrief(const int &group, const int &param, const int &helper) const
Returns the brief description of the helper button.
Definition IsisAml.cpp:1977
QString ParamInclude(const int &group, const int &param, const int &include) const
Returns the name of the specified included parameter.
Definition IsisAml.cpp:1639
QString GetAsString(const QString &paramName) const
Allows the retrieval of a value for a parameter of any type.
Definition IsisAml.cpp:570
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:1488
QString ParamInternalDefault(const int &group, const int &param) const
Returns the internal default for a parameter in a specified group.
Definition IsisAml.cpp:1688
int ParamNotEqualSize(const int &group, const int &param) const
Returns the number of values in the not equal list.
Definition IsisAml.cpp:1529
int ParamIncludeSize(const int &group, const int &param) const
Returns the number of parameters included in this parameter's inclusions.
Definition IsisAml.cpp:1907
QString ParamMinimumInclusive(const int &group, const int &param) const
Returns whether the minimum value is inclusive or not.
Definition IsisAml.cpp:1432
QString ParamGreaterThan(const int &group, const int &param, const int &great) const
Returns the name of the specified greaterThan parameter.
Definition IsisAml.cpp:1543
QString ParamMinimum(const int &group, const int &param) const
Returns the minimum value of a parameter in a specified group.
Definition IsisAml.cpp:1404
QString HelperDescription(const int &group, const int &param, const int &helper) const
Returns the long description of the helper button.
Definition IsisAml.cpp:1992
QString ParamName(const int &group, const int &param) const
Returns the parameter name.
Definition IsisAml.cpp:1362
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:2007
QString ParamMaximum(const int &group, const int &param) const
Returns the maximum value of a parameter in a specified group.
Definition IsisAml.cpp:1418
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16