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 
17 namespace 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 
Isis::GuiParameter::RememberWidget
void RememberWidget(QWidget *w)
Add widgets to a list for enabling/disabling.
Definition: GuiParameter.cpp:212
Isis::FileName::name
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
Definition: FileName.cpp:162
Isis::FileName
File name manipulation and expansion.
Definition: FileName.h:100
QFlags
Definition: AbstractFilter.h:19
IsisAml::HelpersSize
int HelpersSize(const int &group, const int &param) const
Returns the number of helpers the parameter has.
Definition: IsisAml.cpp:1755
Isis::GuiFileNameParameter::~GuiFileNameParameter
~GuiFileNameParameter()
Destructor of GuiFileNameParameter object.
Definition: GuiFilenameParameter.cpp:64
Isis::GuiParameter
Definition: GuiParameter.h:34
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
IsisAml::ParamPath
QString ParamPath(const int &group, const int &param) const
Returns the default path for a filename/cube parameter.
Definition: IsisAml.cpp:1562
Isis::GuiFileNameParameter::Value
QString Value()
Gets the value found in the line edit text box.
Definition: GuiFilenameParameter.cpp:82
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
Isis::FileName::dir
QDir dir() const
Returns the path of the file's parent directory as a QDir object.
Definition: FileName.cpp:465
IsisAml::ParamFileMode
QString ParamFileMode(const int &group, const int &param) const
Returns the file mode for a parameter in a specified group.
Definition: IsisAml.cpp:1581
Isis::GuiFileNameParameter::SelectFile
virtual void SelectFile()
Gets an input/output file from a GUI filechooser or typed in filename.
Definition: GuiFilenameParameter.cpp:105
Isis::UserInterface
Command Line and Xml loader, validation, and access.
Definition: UserInterface.h:140
IsisAml::ParamFilter
QString ParamFilter(const int &group, const int &param) const
Returns the parameter filter for a parameter in a specified group.
Definition: IsisAml.cpp:1543
QAction
Isis::GuiFileNameParameter::GuiFileNameParameter
GuiFileNameParameter(QGridLayout *grid, UserInterface &ui, int group, int param)
Construct a GuiFileNameParameter object.
Definition: GuiFilenameParameter.cpp:29
Isis::GuiFileNameParameter::Set
void Set(QString newValue)
Sets the line edit text box to value passed in by this method.
Definition: GuiFilenameParameter.cpp:72
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