FlightGear next
QtFileDialog.cxx
Go to the documentation of this file.
1// QtFileDialog.cxx - Qt5 implementation of FGFileDialog
2//
3// Written by Rebecca Palmer, started February 2016.
4//
5// Copyright (C) 2015 Rebecca Palmer <rebecca_palmer@zoho.com>
6//
7// This program is free software; you can redistribute it and/or
8// modify it under the terms of the GNU General Public License as
9// published by the Free Software Foundation; either version 2 of the
10// License, or (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful, but
13// WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15// General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program; if not, write to the Free Software
19// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
21#include "QtFileDialog.hxx"
22#include "QtLauncher.hxx"
23#include <simgear/debug/logstream.hxx>
24
25// Qt
26#include <QFileDialog>
27#include <QDir>
28#include <QString>
29#include <QStringList>
30
36
38
40{
41 // concatenate filter patterns, as Qt uses a single string
42 std::string filter="";
43 for( string_list::const_iterator it = _filterPatterns.begin(); it != _filterPatterns.end();++it ) {
44 if(!filter.empty()){
45 filter=filter+" ";
46 }
47 filter=filter+*it;
48 }
49 QFileDialog dlg(0,QString::fromStdString(_title),QString::fromStdString(_initialPath.utf8Str()),QString::fromStdString(filter));
50 if (_usage==USE_SAVE_FILE) {
51 dlg.setAcceptMode(QFileDialog::AcceptSave);
52 }
54 dlg.setFileMode(QFileDialog::Directory);
55 }
56 if (_usage==USE_OPEN_FILE) {
57 dlg.setFileMode(QFileDialog::ExistingFile);
58 }
59 dlg.setLabelText(QFileDialog::Accept,QString::fromStdString(_buttonText));
60 dlg.selectFile(QString::fromStdString(_placeholder));
61 if(_showHidden){
62 dlg.setFilter(dlg.filter() | QDir::Hidden);
63 }
64 if(dlg.exec()){
65 QStringList result = dlg.selectedFiles();
66 if(!(result.isEmpty())){
67 _callback->onFileDialogDone(this, SGPath(result[0].toStdString()));
68 }
69 }
70}
71
73
SGPath _initialPath
string_list _filterPatterns
FGFileDialog(Usage use)
std::string _buttonText
const Usage _usage
std::string _placeholder
std::unique_ptr< Callback > _callback
std::string _title
virtual void close()
virtual ~QtFileDialog()
virtual void exec()
QtFileDialog(FGFileDialog::Usage use)