From 530bfe26c2cddc24ff1e3546b32a7b7f285d79aa Mon Sep 17 00:00:00 2001 From: DonLakeFlyer Date: Tue, 25 Aug 2020 08:13:07 -0700 Subject: [PATCH] QGCFileDialog remove separate mobile fileExtension properties --- HackAndroidFileDialog.qrc | 5 -- HackFileDialog.qrc | 5 -- qgroundcontrol.pro | 9 -- src/MissionManager/QGCMapPolylineVisuals.qml | 1 - src/PlanView/PlanView.qml | 6 -- src/QmlControls/AppMessages.qml | 1 - src/QmlControls/HackFileDialog.qml | 9 -- src/QmlControls/KMLOrSHPFileDialog.qml | 2 - src/QmlControls/LogReplayStatusBar.qml | 3 +- src/QmlControls/ParameterEditor.qml | 1 - src/QmlControls/QGCFileDialog.qml | 89 ++++++++++--------- src/QmlControls/QGCFileDialogController.cc | 66 +++++++------- src/QmlControls/QGCFileDialogController.h | 10 +-- .../QMLControl/OfflineMap.qml | 1 - 14 files changed, 88 insertions(+), 120 deletions(-) delete mode 100644 HackAndroidFileDialog.qrc delete mode 100644 HackFileDialog.qrc delete mode 100644 src/QmlControls/HackFileDialog.qml diff --git a/HackAndroidFileDialog.qrc b/HackAndroidFileDialog.qrc deleted file mode 100644 index 509c47125..000000000 --- a/HackAndroidFileDialog.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - src/QmlControls/HackAndroidFileDialog.qml - - diff --git a/HackFileDialog.qrc b/HackFileDialog.qrc deleted file mode 100644 index a7436f270..000000000 --- a/HackFileDialog.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - src/QmlControls/HackFileDialog.qml - - diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index aba1506e1..8a0b3ddef 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -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 # diff --git a/src/MissionManager/QGCMapPolylineVisuals.qml b/src/MissionManager/QGCMapPolylineVisuals.qml index 2a864eebd..46c43b52c 100644 --- a/src/MissionManager/QGCMapPolylineVisuals.qml +++ b/src/MissionManager/QGCMapPolylineVisuals.qml @@ -128,7 +128,6 @@ Item { title: qsTr("Select KML File") selectExisting: true nameFilters: ShapeFileHelper.fileDialogKMLFilters - fileExtension: QGroundControl.settingsManager.appSettings.kmlFileExtension onAcceptedForLoad: { mapPolyline.loadKMLFile(file) diff --git a/src/PlanView/PlanView.qml b/src/PlanView/PlanView.qml index 141abedea..2fe5fec30 100644 --- a/src/PlanView/PlanView.qml +++ b/src/PlanView/PlanView.qml @@ -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() } } diff --git a/src/QmlControls/AppMessages.qml b/src/QmlControls/AppMessages.qml index b6717b964..95015b432 100644 --- a/src/QmlControls/AppMessages.qml +++ b/src/QmlControls/AppMessages.qml @@ -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: { diff --git a/src/QmlControls/HackFileDialog.qml b/src/QmlControls/HackFileDialog.qml deleted file mode 100644 index 24e0c5dd6..000000000 --- a/src/QmlControls/HackFileDialog.qml +++ /dev/null @@ -1,9 +0,0 @@ -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 { -} diff --git a/src/QmlControls/KMLOrSHPFileDialog.qml b/src/QmlControls/KMLOrSHPFileDialog.qml index cf57c11e4..a7b3e9711 100644 --- a/src/QmlControls/KMLOrSHPFileDialog.qml +++ b/src/QmlControls/KMLOrSHPFileDialog.qml @@ -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 } diff --git a/src/QmlControls/LogReplayStatusBar.qml b/src/QmlControls/LogReplayStatusBar.qml index ab5638867..e51ba014d 100644 --- a/src/QmlControls/LogReplayStatusBar.qml +++ b/src/QmlControls/LogReplayStatusBar.qml @@ -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: { diff --git a/src/QmlControls/ParameterEditor.qml b/src/QmlControls/ParameterEditor.qml index 13ffcac57..e8e0b811a 100644 --- a/src/QmlControls/ParameterEditor.qml +++ b/src/QmlControls/ParameterEditor.qml @@ -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: { diff --git a/src/QmlControls/QGCFileDialog.qml b/src/QmlControls/QGCFileDialog.qml index aba634bb4..baafccfe1 100644 --- a/src/QmlControls/QGCFileDialog.qml +++ b/src/QmlControls/QGCFileDialog.qml @@ -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