CuteLogger
Fast and simple logging solution for Qt based applications
filedialog.h
1 /*
2  * Copyright (c) 2023 Meltytech, LLC
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef FILEDIALOG_H
19 #define FILEDIALOG_H
20 
21 #include <QFileDialog>
22 
23 class FileDialog : public QObject
24 {
25  Q_OBJECT
26  Q_PROPERTY(FileDialog::FileMode fileMode READ fileMode WRITE setFileMode NOTIFY fileModeChanged)
27  Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
28  Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters NOTIFY nameFiltersChanged)
29  Q_PROPERTY(QString selectedFile READ selectedFile NOTIFY fileSelected)
30 
31 public:
32  enum FileMode {OpenFile, SaveFile};
33  Q_ENUM(FileMode)
34 
35  explicit FileDialog(QObject *parent = nullptr);
36  FileDialog::FileMode fileMode() const
37  {
38  return m_fileMode;
39  }
40  void setFileMode(FileDialog::FileMode mode);
41  QString title() const;
42  void setTitle(const QString &title);
43  QStringList nameFilters() const;
44  void setNameFilters(const QStringList &filters);
45  QString selectedFile();
46  Q_INVOKABLE void open();
47 
48 signals:
49  void fileModeChanged();
50  void titleChanged();
51  void nameFiltersChanged();
52  void fileSelected(const QString &file);
53  void filterSelected(const QString &filter);
54  void accepted();
55  void rejected();
56 
57 private:
58  FileDialog::FileMode m_fileMode {FileDialog::OpenFile};
59  std::unique_ptr<QFileDialog> m_fileDialog;
60 };
61 
62 #endif // FILEDIALOG_H