Isis 3 Programmer Reference
GuiFilenameParameter.cpp
Go to the documentation of this file.
1 
24 #include <QFileDialog>
25 #include <QFontMetrics>
26 #include <QHBoxLayout>
27 
28 #include "GuiFilenameParameter.h"
29 #include "IString.h"
30 #include "UserInterface.h"
31 
32 
33 namespace Isis {
34 
46  int group, int param) :
47  GuiParameter(grid, ui, group, param) {
48  connect(p_lineEdit, SIGNAL(textChanged(const QString &)), this, SIGNAL(ValueChanged()));
49  grid->addWidget(p_lineEdit, param, 2);
50 
51  grid->addWidget(p_fileButton, param, 3);
52 
53  QAction *action = new QAction(this);
54  QString file = FileName("$ISIS3DATA/base/icons/view_tree.png").expanded();
55  action->setIcon(QPixmap(file));
56  connect(action, SIGNAL(triggered(bool)), this, SLOT(SelectFile()));
57 
58  p_fileButton->setIconSize(QSize(22, 22));
59  p_fileButton->setIcon(QPixmap(file));
60  p_fileButton->setDefaultAction(action);
61  p_fileButton->setToolTip("Select file");
62  QString fileButtonWhatsThisText = "<p><b>Function:</b> \
63  Opens a file chooser window to select a file from</p>";
64  p_fileButton->setWhatsThis(fileButtonWhatsThisText);
65 
66  if(p_ui->HelpersSize(group, param) != 0) {
67  grid->addWidget(AddHelpers(p_lineEdit), param, 4);
68  }
69 
70  RememberWidget(p_lineEdit);
71  RememberWidget(p_fileButton);
72 
73  p_type = FileNameWidget;
74  }
75 
76 
81 
82 
88  void GuiFileNameParameter::Set(QString newValue) {
89  p_lineEdit->setText(newValue);
90  }
91 
92 
99  return p_lineEdit->text();
100  }
101 
122  // What directory do we look in?
123  QString dir;
124  if((p_lineEdit->text().length() > 0) &&
125  (p_lineEdit->text() != p_ui->ParamInternalDefault(p_group, p_param))) {
126  Isis::FileName fname(p_lineEdit->text());
127  dir = fname.expanded();
128  }
129  else if(p_ui->ParamPath(p_group, p_param).length() > 0) {
130  Isis::FileName fname(p_ui->ParamPath(p_group, p_param));
131  dir = fname.expanded();
132  }
133 
134  // Set up the filter
135  QString filter = p_ui->ParamFilter(p_group, p_param);
136  if(filter.isEmpty()) {
137  filter = "Any(*)";
138  }
139  else {
140  filter += ";;Any(*)";
141  }
142 
143  // Get the filename
144  QString fnameQString;
145 
146  if(p_ui->ParamFileMode(p_group, p_param) == "input") {
147  fnameQString = QFileDialog::getOpenFileName(p_fileButton, "Select file", dir, filter);
148  }
149  else {
150  // The IsisPreference file has groups "FileCustomization" and
151  // "CubeCustomization" with keyword "Overwrite" and possible values
152  // "Allow" or "Error".
153  // Qt does not provide an option to disallow overwrites, so we are unable
154  // to handle this preference here. Instead, the IsisAml class and the
155  // Cube class CubeIoHandler checks these preferences, respectively, and
156  // throws an error if overwrites are not allowed
157  // 2010-07-15 Jeannie Walldren
158  QFlags<QFileDialog::Option> options(QFileDialog::DontConfirmOverwrite);
159  fnameQString = QFileDialog::getSaveFileName(p_fileButton, "Select file", dir, filter, 0, options);
160  }
161  if(fnameQString != "") {
162  Isis::FileName fname(fnameQString);
163  if(fname.dir() == QDir::currentPath()) {
164  fnameQString = fname.name();
165  }
166  Set(fnameQString);
167  }
168  }
169 }
170 
virtual void SelectFile()
Gets an input/output file from a GUI filechooser or typed in filename.
File name manipulation and expansion.
Definition: FileName.h:116
QWidget * AddHelpers(QObject *lo)
Sets up helper button.
int HelpersSize(const int &group, const int &param) const
Returns the number of helpers the parameter has.
Definition: IsisAml.cpp:1771
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.
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
Definition: FileName.cpp:178
GuiFileNameParameter(QGridLayout *grid, UserInterface &ui, int group, int param)
Construct a GuiFileNameParameter object.
QString ParamInternalDefault(const int &group, const int &param) const
Returns the internal default for a parameter in a specified group.
Definition: IsisAml.cpp:1540
QString ParamPath(const int &group, const int &param) const
Returns the default path for a filename/cube parameter.
Definition: IsisAml.cpp:1578
QString ParamFilter(const int &group, const int &param) const
Returns the parameter filter for a parameter in a specified group.
Definition: IsisAml.cpp:1559
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition: FileName.cpp:212
QDir dir() const
Returns the path of the file&#39;s parent directory as a QDir object.
Definition: FileName.cpp:481
QString ParamFileMode(const int &group, const int &param) const
Returns the file mode for a parameter in a specified group.
Definition: IsisAml.cpp:1597
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
Command Line and Xml loader, validation, and access.
void RememberWidget(QWidget *w)
Add widgets to a list for enabling/disabling.
~GuiFileNameParameter()
Destructor of GuiFileNameParameter object.