casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QtFileDialog.qo.h
Go to the documentation of this file.
1 //# QtFileDialog.qo.h: Subclass of QFileDialog with additional functionality.
2 //# Copyright (C) 2009
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id: $
27 #ifndef QTFILEDIALOG_QO_H_
28 #define QTFILEDIALOG_QO_H_
29 
30 #include <casa/BasicSL/String.h>
31 
32 #include <QFileDialog>
33 #include <QLabel>
34 #include <QTimer>
35 
36 namespace casa {
37 
38 // Subclass of QFileDialog with additional functionality.
39 // IMPORTANT: This class needs to be checked when the Qt version changes!
40 // Specifically:
41 // 1) The label at the bottom assumes that the layout is a QGridLayout, where
42 // the first column is for a label and the rest can be used for a widget.
43 // 2) As of Qt 4.3.4, the QFileDialog::filesSelected() signal is NOT emitted
44 // whenever the selection changes, but only when the selection is finalized.
45 // Because we're using a label to keep track of the current selection, this
46 // class uses a timer to update the label at a set time to the current
47 // selection. This is slightly inefficient, but there's no better way to do
48 // it without making our own file chooser dialog.
49 class QtFileDialog : public QFileDialog {
50  Q_OBJECT
51 
52 public:
53  // Static //
54 
55  // Returns an existing directory using the given optional parent, caption,
56  // and starting directory parameters. See QFileDialog.
57  // <group>
58  static QString qgetExistingDir(QWidget* parent = NULL,
59  const QString& caption = QString(),
60  const QString& directory = lastDirectory(),
61  int histLimit = historyLimit()) {
62  return qgetHelper(AcceptOpen, DirectoryOnly, parent, caption,
63  directory, QString(), histLimit); }
64  static casacore::String getExistingDir(QWidget* parent = NULL,
65  const QString& caption = QString(),
66  const QString& directory = lastDirectory(),
67  int histLimit = historyLimit()) {
68  return qgetExistingDir(parent, caption, directory,
69  histLimit).toStdString(); }
70  // </group>
71 
72  // Returns an existing file using the given optional parent, caption,
73  // starting directory, and filter parameters. See QFileDialog.
74  // <group>
75  static QString qgetExistingFile(QWidget* parent = NULL,
76  const QString& caption = QString(),
77  const QString& directory = lastDirectory(),
78  const QString& filter = QString(), int histLimit = historyLimit()){
79  (void)filter;
80  return qgetHelper(AcceptOpen, ExistingFile, parent, caption, directory,
81  QString(), histLimit); }
82  static casacore::String getExistingFile(QWidget* parent = NULL,
83  const QString& caption = QString(),
84  const QString& directory = lastDirectory(),
85  const QString& filter = QString(), int histLimit = historyLimit()){
86  return qgetExistingFile(parent, caption, directory, filter,
87  histLimit).toStdString(); }
88  // </group>
89 
90  // Returns a new filename using the given optional parent, caption,
91  // starting directory, and filter parameters. See QFileDialog.
92  // <group>
93  static QString qgetAnyFile(
94  QWidget* parent = NULL, const QString& caption = QString(),
95  const QString& directory = lastDirectory(),
96  const QString& /*filter*/ = QString(), int histLimit = historyLimit()){
97  return qgetHelper(AcceptSave, AnyFile, parent, caption, directory,
98  QString(), histLimit); }
99  static casacore::String getAnyFile(QWidget* parent = NULL,
100  const QString& caption = QString(),
101  const QString& directory = lastDirectory(),
102  const QString& filter = QString(), int histLimit = historyLimit()){
103  return qgetAnyFile(parent, caption, directory, filter,
104  histLimit).toStdString(); }
105  // </group>
106 
107  // Gets/Sets the last directory to be used by a QtFileDialog. Blank means
108  // the current directory, which is the default.
109  // <group>
110  static const QString& lastDirectory();
111  static void setNextDirectory(const QString& directory);
112  // </group>
113 
114  // Gets/Sets the limit for the history size used by a QtFileDialog. -1
115  // means it is not managed, which is the default.
116  // <group>
117  static int historyLimit();
118  static void setHistoryLimit(int limit);
119  // </group>
120 
121 
122  // Non-Static //
123 
124  // See QFileDialog constructors.
125  // <group>
126  QtFileDialog(QWidget* parent, Qt::WindowFlags flags);
127  QtFileDialog(QWidget* parent = NULL, const QString& caption = QString(),
128  const QString& directory = lastDirectory(),
129  const QString& filter = QString());
130  // </group>
131 
132  // Destructor.
133  ~QtFileDialog();
134 
135 public slots:
136  // Overrides QFileDialog::accept().
137  void accept();
138 
139 private:
140  // Label to display the currently chosen file(s).
141  QLabel* chosenLabel;
142 
143  // Timer.
144  QTimer* timer;
145 
146 
147  // To be called from the constructors.
148  void initialize();
149 
150 
151  // Static //
152 
153  // Last directory.
154  static QString lastDirectory_;
155 
156  // Set history limit.
157  static int historyLimit_;
158 
159 
160  // Helper method for the static qget* functions.
161  static QString qgetHelper(AcceptMode acceptMode, FileMode fileMode,
162  QWidget* parent, const QString& caption, const QString& directory,
163  const QString& filter, int histLimit);
164 
165 private slots:
166  // Signal for timer timeout.
167  void timeout();
168 };
169 
170 }
171 
172 #endif /* QTFILEDIALOG_QO_H_ */
QLabel * chosenLabel
Label to display the currently chosen file(s).
static casacore::String getAnyFile(QWidget *parent=NULL, const QString &caption=QString(), const QString &directory=lastDirectory(), const QString &filter=QString(), int histLimit=historyLimit())
~QtFileDialog()
Destructor.
void initialize()
To be called from the constructors.
static void setHistoryLimit(int limit)
static QString lastDirectory_
Static //.
static QString qgetExistingFile(QWidget *parent=NULL, const QString &caption=QString(), const QString &directory=lastDirectory(), const QString &filter=QString(), int histLimit=historyLimit())
Returns an existing file using the given optional parent, caption, starting directory, and filter parameters.
static const QString & lastDirectory()
Gets/Sets the last directory to be used by a QtFileDialog.
static QString qgetExistingDir(QWidget *parent=NULL, const QString &caption=QString(), const QString &directory=lastDirectory(), int histLimit=historyLimit())
Static //.
static int historyLimit_
Set history limit.
static casacore::String getExistingDir(QWidget *parent=NULL, const QString &caption=QString(), const QString &directory=lastDirectory(), int histLimit=historyLimit())
static int historyLimit()
Gets/Sets the limit for the history size used by a QtFileDialog.
std::set< ScanKey > filter(const std::set< ScanKey > scans, const ArrayKey &arrayKey)
given a set of scan keys, return the subset that matches the given array key
void timeout()
Signal for timer timeout.
Subclass of QFileDialog with additional functionality.
static void setNextDirectory(const QString &directory)
String: the storage and methods of handling collections of characters.
Definition: String.h:223
static QString qgetAnyFile(QWidget *parent=NULL, const QString &caption=QString(), const QString &directory=lastDirectory(), const QString &=QString(), int histLimit=historyLimit())
Returns a new filename using the given optional parent, caption, starting directory, and filter parameters.
static QString qgetHelper(AcceptMode acceptMode, FileMode fileMode, QWidget *parent, const QString &caption, const QString &directory, const QString &filter, int histLimit)
Helper method for the static qget* functions.
static casacore::String getExistingFile(QWidget *parent=NULL, const QString &caption=QString(), const QString &directory=lastDirectory(), const QString &filter=QString(), int histLimit=historyLimit())
QTimer * timer
Timer.
void accept()
Overrides QFileDialog::accept().
QtFileDialog(QWidget *parent, Qt::WindowFlags flags)
Non-Static //.