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(
29  QStringList nameFilters READ nameFilters WRITE setNameFilters NOTIFY nameFiltersChanged)
30  Q_PROPERTY(QString selectedFile READ selectedFile NOTIFY fileSelected)
31 
32 public:
33  enum FileMode { OpenFile, SaveFile };
34  Q_ENUM(FileMode)
35 
36  explicit FileDialog(QObject *parent = nullptr);
37  FileDialog::FileMode fileMode() const { return m_fileMode; }
38  void setFileMode(FileDialog::FileMode mode);
39  QString title() const;
40  void setTitle(const QString &title);
41  QStringList nameFilters() const;
42  void setNameFilters(const QStringList &filters);
43  QString selectedFile();
44  Q_INVOKABLE void open();
45 
46 signals:
47  void fileModeChanged();
48  void titleChanged();
49  void nameFiltersChanged();
50  void fileSelected(const QString &file);
51  void filterSelected(const QString &filter);
52  void accepted();
53  void rejected();
54 
55 private:
56  FileDialog::FileMode m_fileMode{FileDialog::OpenFile};
57  std::unique_ptr<QFileDialog> m_fileDialog;
58 };
59 
60 #endif // FILEDIALOG_H