Isis 3 Programmer Reference
GuiFilenameParameter.cpp
1
6/* SPDX-License-Identifier: CC0-1.0 */
7
8#include <QFileDialog>
9#include <QFontMetrics>
10#include <QHBoxLayout>
11
12#include "GuiFilenameParameter.h"
13#include "IString.h"
14#include "UserInterface.h"
15
16
17namespace Isis {
18
30 int group, int param) :
31 GuiParameter(grid, ui, group, param) {
32 connect(p_lineEdit, SIGNAL(textChanged(const QString &)), this, SIGNAL(ValueChanged()));
33 grid->addWidget(p_lineEdit, param, 2);
34
35 grid->addWidget(p_fileButton, param, 3);
36
37 QAction *action = new QAction(this);
38 QString file = FileName("$ISISROOT/appdata/images/icons/view_tree.png").expanded();
39 action->setIcon(QPixmap(file));
40 connect(action, SIGNAL(triggered(bool)), this, SLOT(SelectFile()));
41
42 p_fileButton->setIconSize(QSize(22, 22));
43 p_fileButton->setIcon(QPixmap(file));
44 p_fileButton->setDefaultAction(action);
45 p_fileButton->setToolTip("Select file");
46 QString fileButtonWhatsThisText = "<p><b>Function:</b> \
47 Opens a file chooser window to select a file from</p>";
48 p_fileButton->setWhatsThis(fileButtonWhatsThisText);
49
50 if(p_ui->HelpersSize(group, param) != 0) {
51 grid->addWidget(AddHelpers(p_lineEdit), param, 4);
52 }
53
54 RememberWidget(p_lineEdit);
55 RememberWidget(p_fileButton);
56
57 p_type = FileNameWidget;
58 }
59
60
65
66
72 void GuiFileNameParameter::Set(QString newValue) {
73 p_lineEdit->setText(newValue);
74 }
75
76
83 return p_lineEdit->text();
84 }
85
106 // What directory do we look in?
107 QString dir;
108 if((p_lineEdit->text().length() > 0) &&
109 (p_lineEdit->text() != p_ui->ParamInternalDefault(p_group, p_param))) {
110 Isis::FileName fname(p_lineEdit->text());
111 dir = fname.expanded();
112 }
113 else if(p_ui->ParamPath(p_group, p_param).length() > 0) {
114 Isis::FileName fname(p_ui->ParamPath(p_group, p_param));
115 dir = fname.expanded();
116 }
117
118 // Set up the filter
119 QString filter = p_ui->ParamFilter(p_group, p_param);
120 if(filter.isEmpty()) {
121 filter = "Any(*)";
122 }
123 else {
124 filter += ";;Any(*)";
125 }
126
127 // Get the filename
128 QString fnameQString;
129
130 if(p_ui->ParamFileMode(p_group, p_param) == "input") {
131 fnameQString = QFileDialog::getOpenFileName(p_fileButton, "Select file", dir, filter);
132 }
133 else {
134 // The IsisPreference file has groups "FileCustomization" and
135 // "CubeCustomization" with keyword "Overwrite" and possible values
136 // "Allow" or "Error".
137 // Qt does not provide an option to disallow overwrites, so we are unable
138 // to handle this preference here. Instead, the IsisAml class and the
139 // Cube class CubeIoHandler checks these preferences, respectively, and
140 // throws an error if overwrites are not allowed
141 // 2010-07-15 Jeannie Walldren
142 QFlags<QFileDialog::Option> options(QFileDialog::DontConfirmOverwrite);
143 fnameQString = QFileDialog::getSaveFileName(p_fileButton, "Select file", dir, filter, 0, options);
144 }
145 if(fnameQString != "") {
146 Isis::FileName fname(fnameQString);
147 if(fname.dir() == QDir::currentPath()) {
148 fnameQString = fname.name();
149 }
150 Set(fnameQString);
151 }
152 }
153}
154
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
virtual void SelectFile()
Gets an input/output file from a GUI filechooser or typed in filename.
GuiFileNameParameter(QGridLayout *grid, UserInterface &ui, int group, int param)
Construct a GuiFileNameParameter object.
~GuiFileNameParameter()
Destructor of GuiFileNameParameter object.
QString Value()
Gets the value found in the line edit text box.
void Set(QString newValue)
Sets the line edit text box to value passed in by this method.
void RememberWidget(QWidget *w)
Add widgets to a list for enabling/disabling.
QWidget * AddHelpers(QObject *lo)
Sets up helper button.
Command Line and Xml loader, validation, and access.
int HelpersSize(const int &group, const int &param) const
Returns the number of helpers the parameter has.
Definition IsisAml.cpp:1933
QString ParamFilter(const int &group, const int &param) const
Returns the parameter filter for a parameter in a specified group.
Definition IsisAml.cpp:1708
QString ParamInternalDefault(const int &group, const int &param) const
Returns the internal default for a parameter in a specified group.
Definition IsisAml.cpp:1688
QString ParamFileMode(const int &group, const int &param) const
Returns the file mode for a parameter in a specified group.
Definition IsisAml.cpp:1748
QString ParamPath(const int &group, const int &param) const
Returns the default path for a filename/cube parameter.
Definition IsisAml.cpp:1728
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16