Unverified Commit 08cc9375 authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #9032 from DonLakeFlyer/QGCFileDialog

QGCFileDialog remove separate mobile fileExtension properties
parents 7f7bfe63 530bfe26
<RCC>
<qresource prefix="/qml">
<file alias="QGroundControl/Controls/HackFileDialog.qml">src/QmlControls/HackAndroidFileDialog.qml</file>
</qresource>
</RCC>
<RCC>
<qresource prefix="/qml">
<file alias="QGroundControl/Controls/HackFileDialog.qml">src/QmlControls/HackFileDialog.qml</file>
</qresource>
</RCC>
......@@ -362,15 +362,6 @@ CustomBuild {
$$PWD/resources/InstrumentValueIcons/InstrumentValueIcons.qrc \
}
# On Qt 5.9 android versions there is the following bug: https://bugreports.qt.io/browse/QTBUG-61424
# This prevents FileDialog from being used. So we have a temp hack workaround for it which just no-ops
# the FileDialog fallback mechanism on android 5.9 builds.
equals(QT_MAJOR_VERSION, 5):equals(QT_MINOR_VERSION, 9):AndroidBuild {
RESOURCES += $$PWD/HackAndroidFileDialog.qrc
} else {
RESOURCES += $$PWD/HackFileDialog.qrc
}
#
# Main QGroundControl portion of project file
#
......
......@@ -128,7 +128,6 @@ Item {
title: qsTr("Select KML File")
selectExisting: true
nameFilters: ShapeFileHelper.fileDialogKMLFilters
fileExtension: QGroundControl.settingsManager.appSettings.kmlFileExtension
onAcceptedForLoad: {
mapPolyline.loadKMLFile(file)
......
......@@ -271,8 +271,6 @@ Item {
fileDialog.planFiles = true
fileDialog.selectExisting = true
fileDialog.nameFilters = _planMasterController.loadNameFilters
fileDialog.fileExtension = _appSettings.planFileExtension
fileDialog.fileExtension2 = _appSettings.missionFileExtension
fileDialog.openForLoad()
}
......@@ -284,8 +282,6 @@ Item {
fileDialog.planFiles = true
fileDialog.selectExisting = false
fileDialog.nameFilters = _planMasterController.saveNameFilters
fileDialog.fileExtension = _appSettings.planFileExtension
fileDialog.fileExtension2 = _appSettings.missionFileExtension
fileDialog.openForSave()
}
......@@ -301,8 +297,6 @@ Item {
fileDialog.planFiles = false
fileDialog.selectExisting = false
fileDialog.nameFilters = ShapeFileHelper.fileDialogKMLFilters
fileDialog.fileExtension = _appSettings.kmlFileExtension
fileDialog.fileExtension2 = ""
fileDialog.openForSave()
}
}
......
......@@ -162,7 +162,6 @@ Item {
id: writeDialog
folder: QGroundControl.settingsManager.appSettings.logSavePath
nameFilters: [qsTr("Log files (*.txt)"), qsTr("All Files (*)")]
fileExtension: qsTr("txt")
selectExisting: false
title: qsTr("Select log save file")
onAcceptedForSave: {
......
import QtQuick 2.3
import QtQuick.Dialogs 1.2
// On Qt 5.9 android versions there is the following bug: https://bugreports.qt.io/browse/QTBUG-61424
// This prevents FileDialog from being used. So we have a temp hack workaround for it which just no-ops
// the FileDialog fallback mechanism on android 5.9 builds.
FileDialog {
}
......@@ -19,6 +19,4 @@ QGCFileDialog {
title: qsTr("Select Polygon File")
selectExisting: true
nameFilters: ShapeFileHelper.fileDialogKMLOrSHPFilters
fileExtension: QGroundControl.settingsManager.appSettings.kmlFileExtension
fileExtension2: QGroundControl.settingsManager.appSettings.shpFileExtension
}
......@@ -28,8 +28,7 @@ Rectangle {
QGCFileDialog {
id: filePicker
title: qsTr("Select Telemetery Log")
nameFilters: [qsTr("Telemetry Logs (*.%1)").arg(_logFileExtension), qsTr("All Files (*)")]
fileExtension: _logFileExtension
nameFilters: [ qsTr("Telemetry Logs (*.%1)").arg(_logFileExtension), qsTr("All Files (*)") ]
selectExisting: true
folder: QGroundControl.settingsManager.appSettings.telemetrySavePath
onAcceptedForLoad: {
......
......@@ -287,7 +287,6 @@ Item {
QGCFileDialog {
id: fileDialog
folder: _appSettings.parameterSavePath
fileExtension: _appSettings.parameterFileExtension
nameFilters: [ qsTr("Parameter Files (*.%1)").arg(_appSettings.parameterFileExtension) , qsTr("All Files (*.*)") ]
onAcceptedForSave: {
......
......@@ -15,41 +15,14 @@ Item {
visible: false
property string folder // Due to Qt bug with file url parsing this must be an absolute path
property var nameFilters
property string fileExtension // Primary file extension to search for
property string fileExtension2: "" // Secondary file extension to search for
property var nameFilters: [] // Important: Only name filters with simple wildcarding like *.foo are supported.
property string title
property bool selectExisting
property bool selectFolder
property bool _openForLoad: true
property real _margins: ScreenTools.defaultFontPixelHeight / 2
property bool _mobileDlg: QGroundControl.corePlugin.options.useMobileFileDialog
property var _rgExtensions
property string _mobileShortPath
Component.onCompleted: {
setupFileExtensions()
_updateMobileShortPath()
}
onFileExtensionChanged: setupFileExtensions()
onFileExtension2Changed: setupFileExtensions()
onFolderChanged: _updateMobileShortPath()
function _updateMobileShortPath() {
if (ScreenTools.isMobile) {
_mobileShortPath = controller.fullFolderPathToShortMobilePath(folder);
}
}
function setupFileExtensions() {
if (fileExtension2 == "") {
_rgExtensions = [ fileExtension ]
} else {
_rgExtensions = [ fileExtension, fileExtension2 ]
}
}
signal acceptedForLoad(string file)
signal acceptedForSave(string file)
signal rejected
function openForLoad() {
_openForLoad = true
......@@ -73,17 +46,48 @@ Item {
fullFileDialog.close()
}
signal acceptedForLoad(string file)
signal acceptedForSave(string file)
signal rejected
property bool _openForLoad: true
property real _margins: ScreenTools.defaultFontPixelHeight / 2
property bool _mobileDlg: QGroundControl.corePlugin.options.useMobileFileDialog
property var _rgExtensions
property string _mobileShortPath
Component.onCompleted: {
_setupFileExtensions()
_updateMobileShortPath()
}
onFolderChanged: _updateMobileShortPath()
onNameFiltersChanged: _setupFileExtensions()
function _updateMobileShortPath() {
if (ScreenTools.isMobile) {
_mobileShortPath = controller.fullFolderPathToShortMobilePath(folder);
}
}
function _setupFileExtensions() {
_rgExtensions = [ ]
for (var i=0; i<_root.nameFilters.length; i++) {
var filter = _root.nameFilters[i]
var regExp = /^.*\((.*)\)$/
var result = regExp.exec(filter)
if (result.length === 2) {
filter = result[1]
}
var rgFilters = filter.split(" ")
for (var j=0; j<rgFilters.length; j++) {
if (!_mobileDlg || (rgFilters[j] !== "*" && rgFilters[j] !== "*.*")) {
_rgExtensions.push(rgFilters[j])
}
}
}
}
QGCFileDialogController { id: controller }
QGCPalette { id: qgcPal; colorGroupEnabled: true }
// On Qt 5.9 android versions there is the following bug: https://bugreports.qt.io/browse/QTBUG-61424
// This prevents FileDialog from being used. So we have a temp hack workaround for it which just no-ops
// the FileDialog fallback mechanism on android 5.9 builds.
HackFileDialog {
FileDialog {
id: fullFileDialog
folder: "file:///" + _root.folder
nameFilters: _root.nameFilters ? _root.nameFilters : []
......@@ -130,12 +134,12 @@ Item {
onClicked: {
hideDialog()
_root.acceptedForLoad(controller.fullyQualifiedFilename(folder, modelData, _rgExtensions))
_root.acceptedForLoad(controller.fullyQualifiedFilename(folder, modelData))
}
onHamburgerClicked: {
highlight = true
hamburgerMenu.fileToDelete = controller.fullyQualifiedFilename(folder, modelData, _rgExtensions)
hamburgerMenu.fileToDelete = controller.fullyQualifiedFilename(folder, modelData)
hamburgerMenu.popup()
}
......@@ -149,6 +153,7 @@ Item {
QGCMenuItem {
text: qsTr("Delete")
onTriggered: {
console.log("hamburgerMenu.fileToDelete", hamburgerMenu.fileToDelete)
controller.deleteFile(hamburgerMenu.fileToDelete)
fileRepeater.model = controller.getFiles(folder, _rgExtensions)
}
......@@ -243,12 +248,12 @@ Item {
onClicked: {
hideDialog()
_root.acceptedForSave(controller.fullyQualifiedFilename(folder, modelData, _rgExtensions))
_root.acceptedForSave(controller.fullyQualifiedFilename(folder, modelData))
}
onHamburgerClicked: {
highlight = true
hamburgerMenu.fileToDelete = controller.fullyQualifiedFilename(folder, modelData, _rgExtensions)
hamburgerMenu.fileToDelete = controller.fullyQualifiedFilename(folder, modelData)
hamburgerMenu.popup()
}
......
......@@ -19,19 +19,14 @@
QGC_LOGGING_CATEGORY(QGCFileDialogControllerLog, "QGCFileDialogControllerLog")
QStringList QGCFileDialogController::getFiles(const QString& directoryPath, const QStringList& fileExtensions)
QStringList QGCFileDialogController::getFiles(const QString& directoryPath, const QStringList& nameFilters)
{
qCDebug(QGCFileDialogControllerLog) << "getFiles" << directoryPath << fileExtensions;
qCDebug(QGCFileDialogControllerLog) << "getFiles" << directoryPath << nameFilters;
QStringList files;
QDir fileDir(directoryPath);
QStringList infoListExtensions;
for (const QString& extension: fileExtensions) {
infoListExtensions.append(QStringLiteral("*.%1").arg(extension));
}
QFileInfoList fileInfoList = fileDir.entryInfoList(infoListExtensions, QDir::Files, QDir::Name);
QFileInfoList fileInfoList = fileDir.entryInfoList(nameFilters, QDir::Files, QDir::Name);
for (const QFileInfo& fileInfo: fileInfoList) {
qCDebug(QGCFileDialogControllerLog) << "getFiles found" << fileInfo.fileName();
......@@ -41,34 +36,45 @@ QStringList QGCFileDialogController::getFiles(const QString& directoryPath, cons
return files;
}
QString QGCFileDialogController::filenameWithExtension(const QString& filename, const QStringList& rgFileExtensions)
{
QString filenameWithExtension(filename);
bool matchFound = false;
for (const QString& extension : rgFileExtensions) {
QString dotExtension = QStringLiteral(".%1").arg(extension);
matchFound = filenameWithExtension.endsWith(dotExtension);
if (matchFound) {
break;
}
}
if (!matchFound) {
filenameWithExtension += QStringLiteral(".%1").arg(rgFileExtensions[0]);
}
return filenameWithExtension;
}
bool QGCFileDialogController::fileExists(const QString& filename)
{
return QFile(filename).exists();
}
QString QGCFileDialogController::fullyQualifiedFilename(const QString& directoryPath, const QString& filename, const QStringList& rgFileExtensions)
QString QGCFileDialogController::fullyQualifiedFilename(const QString& directoryPath, const QString& filename, const QStringList& nameFilters)
{
return directoryPath + QStringLiteral("/") + filenameWithExtension(filename, rgFileExtensions);
QString firstFileExtention;
// Check that the filename has one of the specified file extensions
bool extensionFound = true;
if (nameFilters.count()) {
extensionFound = false;
for (const QString& nameFilter: nameFilters) {
if (nameFilter.startsWith("*.")) {
QString fileExtension = nameFilter.right(nameFilter.length() - 2);
if (fileExtension != "*") {
if (firstFileExtention.isEmpty()) {
firstFileExtention = fileExtension;
}
if (filename.endsWith(fileExtension)) {
extensionFound = true;
break;
}
}
} else if (nameFilter != "*") {
qCWarning(QGCFileDialogControllerLog) << "unsupported name filter format" << nameFilter;
}
}
}
// Add the extension if it is missing
QString filenameWithExtension = filename;
if (!extensionFound) {
filenameWithExtension = QStringLiteral("%1.%2").arg(filename).arg(firstFileExtention);
}
return directoryPath + QStringLiteral("/") + filenameWithExtension;
}
void QGCFileDialogController::deleteFile(const QString& filename)
......
......@@ -24,13 +24,11 @@ class QGCFileDialogController : public QObject
public:
/// Return all file in the specified path which match the specified extension
Q_INVOKABLE QStringList getFiles(const QString& directoryPath, const QStringList& fileExtensions);
Q_INVOKABLE QStringList getFiles(const QString& directoryPath, const QStringList& nameFilters);
/// Returns the specified file name with the extension added it needed
Q_INVOKABLE QString filenameWithExtension(const QString& filename, const QStringList& rgFileExtensions);
/// Returns the fully qualified file name from the specified parts
Q_INVOKABLE QString fullyQualifiedFilename(const QString& directoryPath, const QString& filename, const QStringList& rgFileExtensions);
/// Returns the fully qualified file name from the specified parts.
/// If filename has no file extension the first file extension is nameFilters is added to the filename.
Q_INVOKABLE QString fullyQualifiedFilename(const QString& directoryPath, const QString& filename, const QStringList& nameFilters = QStringList());
/// Check for file existence of specified fully qualified file name
Q_INVOKABLE bool fileExists(const QString& filename);
......
......@@ -210,7 +210,6 @@ Item {
id: fileDialog
folder: QGroundControl.settingsManager.appSettings.missionSavePath
nameFilters: ["Tile Sets (*.qgctiledb)"]
fileExtension: "qgctiledb"
onAcceptedForSave: {
if (QGroundControl.mapEngineManager.exportSets(file)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment