SGL
gfilechooser.h
1 /*
2  * File: gfilechooser.h
3  * --------------------
4  * This file defines the <code>GFileChooser</code> class which supports
5  * popping up graphical dialog boxes to select file names.
6  *
7  * @author Marty Stepp
8  * @version 2021/04/09
9  * - added sgl namespace
10  * @version 2018/09/07
11  * - added doc comments for new documentation generation
12  * - added overloads that accept GWindow* parent
13  * @version 2018/08/23
14  * - renamed to gfilechooser.h to replace Java version
15  * @version 2018/06/28
16  * - initial version
17  */
18 
19 
20 #ifndef _gfilechooser_h
21 #define _gfilechooser_h
22 
23 #include <string>
24 #include <QWidget>
25 
26 #include "gwindow.h"
27 
28 namespace sgl {
29 
36 class GFileChooser {
37 public:
45  static string showOpenDialog(const string& title = "Open file", const string& currentDir = "", const string& fileFilter = "");
46 
55  static string showOpenDialog(GWindow* parent, const string& title = "Open file", const string& currentDir = "", const string& fileFilter = "");
56 
65  static string showOpenDialog(QWidget* parent, const string& title = "Open file", const string& currentDir = "", const string& fileFilter = "");
66 
82  static string showSaveDialog(const string& title = "Save file", const string& currentDir = "", const string& fileFilter = "");
83 
100  static string showSaveDialog(GWindow* parent, const string& title = "Save file", const string& currentDir = "", const string& fileFilter = "");
101 
118  static string showSaveDialog(QWidget* parent, const string& title = "Save file", const string& currentDir = "", const string& fileFilter = "");
119 
120 private:
121  GFileChooser(); // prevent construction
122 
123  /*
124  * Constants for dialog types, similar to those in Java's JFileChooser
125  */
126  enum DialogType {
127  OPEN_DIALOG = 0,
128  SAVE_DIALOG = 1
129  };
130 
131  /*
132  * Converts between our comma-separated file filter format to the one
133  * used by Qt that uses ;; as its separator.
134  * @param fileFilter a file filter string such as "*.gif,*.jpg,*.png".
135  */
136  static string normalizeFileFilter(const string& fileFilter);
137 };
138 
139 } // namespace sgl
140 
141 #endif // _gfilechooser_h
This class represents a graphics window that supports simple graphics.
Definition: gwindow.h:102
static string showOpenDialog(string title="Open file", string currentDir="", string fileFilter="")
Pops up a file "Open" chooser dialog with the given top title text, current directory, and file filter.
Definition: gfilechooser.cpp:32
Definition: console.h:45
static string showSaveDialog(string title="Save file", string currentDir="", string fileFilter="")
Pops up a file "Save" chooser dialog with the given top title text, current directory, and file filter.
Definition: gfilechooser.cpp:55
The GFileChooser class contains static methods for popping up file-choosing dialog boxes that allow t...
Definition: gfilechooser.h:36