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