QtFileDialog.qo.h

Go to the documentation of this file.
00001 //# QtFileDialog.qo.h: Subclass of QFileDialog with additional functionality.
00002 //# Copyright (C) 2009
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: $
00027 #ifndef QTFILEDIALOG_QO_H_
00028 #define QTFILEDIALOG_QO_H_
00029 
00030 #include <casa/BasicSL/String.h>
00031 
00032 #include <QFileDialog>
00033 #include <QLabel>
00034 #include <QTimer>
00035 
00036 namespace casa {
00037 
00038 // Subclass of QFileDialog with additional functionality.
00039 // IMPORTANT: This class needs to be checked when the Qt version changes!
00040 // Specifically:
00041 // 1) The label at the bottom assumes that the layout is a QGridLayout, where
00042 //    the first column is for a label and the rest can be used for a widget.
00043 // 2) As of Qt 4.3.4, the QFileDialog::filesSelected() signal is NOT emitted
00044 //    whenever the selection changes, but only when the selection is finalized.
00045 //    Because we're using a label to keep track of the current selection, this
00046 //    class uses a timer to update the label at a set time to the current
00047 //    selection.  This is slightly inefficient, but there's no better way to do
00048 //    it without making our own file chooser dialog.
00049 class QtFileDialog : public QFileDialog {
00050     Q_OBJECT
00051     
00052 public:
00053     // Static //
00054     
00055     // Returns an existing directory using the given optional parent, caption,
00056     // and starting directory parameters.  See QFileDialog.
00057     // <group>
00058     static QString qgetExistingDir(QWidget* parent = NULL,
00059             const QString& caption = QString(),
00060             const QString& directory = lastDirectory(),
00061             int histLimit = historyLimit()) {
00062         return qgetHelper(AcceptOpen, DirectoryOnly, parent, caption,
00063                           directory, QString(), histLimit); }
00064     static String getExistingDir(QWidget* parent = NULL,
00065             const QString& caption = QString(),
00066             const QString& directory = lastDirectory(),
00067             int histLimit = historyLimit()) {
00068         return qgetExistingDir(parent, caption, directory,
00069                                histLimit).toStdString(); }
00070     // </group>
00071     
00072     // Returns an existing file using the given optional parent, caption,
00073     // starting directory, and filter parameters.  See QFileDialog.
00074     // <group>
00075     static QString qgetExistingFile(QWidget* parent = NULL,
00076             const QString& caption = QString(),
00077             const QString& directory = lastDirectory(),
00078             const QString& filter = QString(), int histLimit = historyLimit()){
00079         (void)filter;
00080         return qgetHelper(AcceptOpen, ExistingFile, parent, caption, directory,
00081                           QString(), histLimit); }
00082     static String getExistingFile(QWidget* parent = NULL,
00083             const QString& caption = QString(),
00084             const QString& directory = lastDirectory(),
00085             const QString& filter = QString(), int histLimit = historyLimit()){
00086         return qgetExistingFile(parent, caption, directory, filter,
00087                                 histLimit).toStdString(); }
00088     // </group>
00089     
00090     // Returns a new filename using the given optional parent, caption,
00091     // starting directory, and filter parameters.  See QFileDialog.
00092     // <group>
00093     static QString qgetAnyFile(
00094         QWidget* parent = NULL, const QString& caption = QString(),
00095         const QString& directory = lastDirectory(),
00096         const QString& /*filter*/ = QString(), int histLimit = historyLimit()){
00097         return qgetHelper(AcceptSave, AnyFile, parent, caption, directory,
00098                           QString(), histLimit); }
00099     static String getAnyFile(QWidget* parent = NULL,
00100             const QString& caption = QString(),
00101             const QString& directory = lastDirectory(),
00102             const QString& filter = QString(), int histLimit = historyLimit()){
00103         return qgetAnyFile(parent, caption, directory, filter,
00104                            histLimit).toStdString(); }
00105     // </group>
00106     
00107     // Gets/Sets the last directory to be used by a QtFileDialog.  Blank means
00108     // the current directory, which is the default.
00109     // <group>
00110     static const QString& lastDirectory();
00111     static void setNextDirectory(const QString& directory);
00112     // </group>
00113     
00114     // Gets/Sets the limit for the history size used by a QtFileDialog.  -1
00115     // means it is not managed, which is the default.
00116     // <group>
00117     static int historyLimit();
00118     static void setHistoryLimit(int limit);
00119     // </group>
00120     
00121     
00122     // Non-Static //
00123     
00124     // See QFileDialog constructors.
00125     // <group>
00126     QtFileDialog(QWidget* parent, Qt::WindowFlags flags);
00127     QtFileDialog(QWidget* parent = NULL, const QString& caption = QString(),
00128             const QString& directory = lastDirectory(),
00129             const QString& filter = QString());
00130     // </group>
00131     
00132     // Destructor.
00133     ~QtFileDialog();
00134     
00135 public slots:
00136     // Overrides QFileDialog::accept().
00137     void accept();
00138     
00139 private:
00140     // Label to display the currently chosen file(s).
00141     QLabel* chosenLabel;
00142     
00143     // Timer.
00144     QTimer* timer;
00145     
00146     
00147     // To be called from the constructors.
00148     void initialize();
00149     
00150     
00151     // Static //
00152     
00153     // Last directory.
00154     static QString lastDirectory_;
00155     
00156     // Set history limit.
00157     static int historyLimit_;
00158     
00159     
00160     // Helper method for the static qget* functions.
00161     static QString qgetHelper(AcceptMode acceptMode, FileMode fileMode,
00162             QWidget* parent, const QString& caption, const QString& directory,
00163             const QString& filter, int histLimit);
00164     
00165 private slots:
00166     // Signal for timer timeout.
00167     void timeout();
00168 };
00169 
00170 }
00171 
00172 #endif /* QTFILEDIALOG_QO_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1