FileDialog.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/qt/widgets/utils/FileDialog.h
22 
23  \brief An instance of QFileDialog that includes file extention if necessary.
24 */
25 
26 #ifndef __TERRALIB_QT_WIDGETS_INTERNAL_FILEDIALOG_H
27 #define __TERRALIB_QT_WIDGETS_INTERNAL_FILEDIALOG_H
28 
29 // TerraLib
30 #include "../Config.h"
31 
32 // Qt
33 #include <QDialog>
34 #include <QFileDialog>
35 
36 #include <set>
37 
38 namespace te
39 {
40  namespace qt
41  {
42  namespace widgets
43  {
44  /*!
45  \class FileDialog
46 
47  \brief Defines a component for choose a file.
48 
49  This class is used to create a QFileDialog in order to facilitate the use of file path,
50  file name and file extension.
51 
52  \ingroup widgets
53  */
55  {
56  public:
57 
58  enum FileType
59  {
61  VECTOR
62  };
63 
65  {
68  SAVE_FILE_MODE
69  };
70 
71  /*!
72  \brief Constructor.
73  \param parent The QWidget parent argumnt.
74  \param pathInfo The type of file opened. Actually we assume three values: "vector", "raster", "database". Any other value may be not used in the system.
75  \param File Mode will be set to UNDEFINED_FILE_MODE.
76  */
77  FileDialog(QWidget* parent, FileType type, std::string pathInfo = "");
78 
79  /*!
80  \brief Constructor.
81  \param parent The QWidget parent argumnt.
82  \param pathInfo The type of file opened. Actually we assume three values: "vector", "raster", "database". Any other value may be not used in the system.
83  \fileMode File mode.
84  */
85  FileDialog(QWidget* parent, const FileType& type,
86  const std::string& pathInfo, const FileAccessMode& fileMode );
87 
88  /*!
89  \brief Destructor.
90  */
92 
93  /*!
94  \brief This method will open the dialog of file selection and
95  populate the class members with the chosen file path.
96  \note te::common::Exception on errors.
97  */
98  void exec();
99 
100  /*!
101  \brief This method will return the chosen path.
102  \return The complete chosen path.
103  */
104  std::string getPath();
105 
106  /*!
107  \brief Sets the file path.
108  \param The file path.
109  */
110  void setPath(std::string filePath);
111 
112  /*!
113  \brief This method will return the file name.
114  \return The complete chosen file name.
115  */
116  std::string getFileName();
117 
118  /*!
119  \brief Sets the file name.
120  \param The file path with a file name.
121  */
122  void setFileName(std::string filePath);
123 
124  /*!
125  \brief This method will return the file extension.
126  \return The complete chosen file extension.
127  */
128  std::string getExtension();
129 
130  /*!
131  \brief Sets the file extension.
132  \param The file path with a file and an extension.
133  */
134  void setExtension(std::string filePath);
135 
136  /*!
137  \brief Genarate an extensions map with the extensions returned by driver.
138  \param The extensions returned by driver.
139  */
140  std::map<QString, QString> getMappedExtensions(QString extensions);
141 
142  /*!
143  \brief Verify if the file name has special characters
144  \param The name of the file.
145  */
146  bool hasInvalidCharacters(std::string filename);
147 
148  void setAllowedExtensions(std::set<std::string> allowedExtensions);
149 
150  private:
151 
153  QWidget* m_parent; //!< The QWidget parent argumnt.
154  FileType m_type; //!< The type of file.
155  std::string m_pathInfo; //!< The file path info.
156  std::string m_path; //!< The path of the file.
157  std::string m_fileName; //!< The name of the file.
158  std::string m_extension; //!< The extension of the file.
159  std::set<std::string> m_allowedExtensions; //!< Set of allowed extensions.
160  };
161 
162  } // end namespace widgets
163  } // end namespace qt
164 } // end namespace te
165 
166 #endif // __TERRALIB_QT_WIDGETS_INTERNAL_FILEDIALOG_H
167 
te::qt::widgets::FileDialog::m_parent
QWidget * m_parent
The QWidget parent argumnt.
Definition: FileDialog.h:153
te::qt::widgets::FileDialog::UNDEFINED_FILE_MODE
@ UNDEFINED_FILE_MODE
Definition: FileDialog.h:66
te::qt::widgets::FileDialog::getMappedExtensions
std::map< QString, QString > getMappedExtensions(QString extensions)
Genarate an extensions map with the extensions returned by driver.
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::qt::widgets::FileDialog::m_allowedExtensions
std::set< std::string > m_allowedExtensions
Set of allowed extensions.
Definition: FileDialog.h:159
te::qt::widgets::FileDialog::FileType
FileType
Definition: FileDialog.h:59
te::qt::widgets::FileDialog::setFileName
void setFileName(std::string filePath)
Sets the file name.
te::qt::widgets::FileDialog::OPEN_FILE_MODE
@ OPEN_FILE_MODE
Definition: FileDialog.h:67
te::qt::widgets::FileDialog::m_path
std::string m_path
The path of the file.
Definition: FileDialog.h:156
te::qt::widgets::FileDialog::m_fileMode
FileAccessMode m_fileMode
Definition: FileDialog.h:152
te::qt::widgets::FileDialog::getPath
std::string getPath()
This method will return the chosen path.
te::qt::widgets::FileDialog::~FileDialog
~FileDialog()
Destructor.
Definition: FileDialog.h:91
te::qt::widgets::FileDialog
Defines a component for choose a file.
Definition: FileDialog.h:55
te::qt::widgets::FileDialog::setExtension
void setExtension(std::string filePath)
Sets the file extension.
te::qt::widgets::FileDialog::setAllowedExtensions
void setAllowedExtensions(std::set< std::string > allowedExtensions)
te::qt::widgets::FileDialog::m_type
FileType m_type
The type of file.
Definition: FileDialog.h:154
TEQTWIDGETSEXPORT
#define TEQTWIDGETSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:63
te::qt::widgets::FileDialog::hasInvalidCharacters
bool hasInvalidCharacters(std::string filename)
Verify if the file name has special characters.
te::qt::widgets::FileDialog::RASTER
@ RASTER
Definition: FileDialog.h:60
te::qt::widgets::FileDialog::FileDialog
FileDialog(QWidget *parent, FileType type, std::string pathInfo="")
Constructor.
te::qt::widgets::FileDialog::getFileName
std::string getFileName()
This method will return the file name.
te::qt::widgets::FileDialog::exec
void exec()
This method will open the dialog of file selection and populate the class members with the chosen fil...
te::qt::widgets::FileDialog::getExtension
std::string getExtension()
This method will return the file extension.
te::qt::widgets::FileDialog::FileAccessMode
FileAccessMode
Definition: FileDialog.h:65
te::qt::widgets::FileDialog::m_pathInfo
std::string m_pathInfo
The file path info.
Definition: FileDialog.h:155
te::qt::widgets::FileDialog::FileDialog
FileDialog(QWidget *parent, const FileType &type, const std::string &pathInfo, const FileAccessMode &fileMode)
Constructor.
te::qt::widgets::FileDialog::m_fileName
std::string m_fileName
The name of the file.
Definition: FileDialog.h:157
te::qt::widgets::FileDialog::setPath
void setPath(std::string filePath)
Sets the file path.
te::qt::widgets::FileDialog::m_extension
std::string m_extension
The extension of the file.
Definition: FileDialog.h:158