Commit 54331a19 authored by DonLakeFlyer's avatar DonLakeFlyer

Add delete file support to QGCFileDialog

parent 1d46da77
...@@ -515,7 +515,7 @@ HEADERS += \ ...@@ -515,7 +515,7 @@ HEADERS += \
src/QmlControls/CoordinateVector.h \ src/QmlControls/CoordinateVector.h \
src/QmlControls/MavlinkQmlSingleton.h \ src/QmlControls/MavlinkQmlSingleton.h \
src/QmlControls/ParameterEditorController.h \ src/QmlControls/ParameterEditorController.h \
src/QmlControls/QFileDialogController.h \ src/QmlControls/QGCFileDialogController.h \
src/QmlControls/QGCImageProvider.h \ src/QmlControls/QGCImageProvider.h \
src/QmlControls/QGroundControlQmlGlobal.h \ src/QmlControls/QGroundControlQmlGlobal.h \
src/QmlControls/QmlObjectListModel.h \ src/QmlControls/QmlObjectListModel.h \
...@@ -691,7 +691,7 @@ SOURCES += \ ...@@ -691,7 +691,7 @@ SOURCES += \
src/QmlControls/AppMessages.cc \ src/QmlControls/AppMessages.cc \
src/QmlControls/CoordinateVector.cc \ src/QmlControls/CoordinateVector.cc \
src/QmlControls/ParameterEditorController.cc \ src/QmlControls/ParameterEditorController.cc \
src/QmlControls/QFileDialogController.cc \ src/QmlControls/QGCFileDialogController.cc \
src/QmlControls/QGCImageProvider.cc \ src/QmlControls/QGCImageProvider.cc \
src/QmlControls/QGroundControlQmlGlobal.cc \ src/QmlControls/QGroundControlQmlGlobal.cc \
src/QmlControls/QmlObjectListModel.cc \ src/QmlControls/QmlObjectListModel.cc \
......
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
<file alias="QGroundControl/Controls/DropButton.qml">src/QmlControls/DropButton.qml</file> <file alias="QGroundControl/Controls/DropButton.qml">src/QmlControls/DropButton.qml</file>
<file alias="QGroundControl/Controls/ExclusiveGroupItem.qml">src/QmlControls/ExclusiveGroupItem.qml</file> <file alias="QGroundControl/Controls/ExclusiveGroupItem.qml">src/QmlControls/ExclusiveGroupItem.qml</file>
<file alias="QGroundControl/Controls/FactSliderPanel.qml">src/QmlControls/FactSliderPanel.qml</file> <file alias="QGroundControl/Controls/FactSliderPanel.qml">src/QmlControls/FactSliderPanel.qml</file>
<file alias="QGroundControl/Controls/FileButton.qml">src/QmlControls/FileButton.qml</file>
<file alias="QGroundControl/Controls/FlightModeDropdown.qml">src/QmlControls/FlightModeDropdown.qml</file> <file alias="QGroundControl/Controls/FlightModeDropdown.qml">src/QmlControls/FlightModeDropdown.qml</file>
<file alias="QGroundControl/Controls/FlightModeMenu.qml">src/QmlControls/FlightModeMenu.qml</file> <file alias="QGroundControl/Controls/FlightModeMenu.qml">src/QmlControls/FlightModeMenu.qml</file>
<file alias="QGroundControl/Controls/FWLandingPatternMapVisual.qml">src/PlanView/FWLandingPatternMapVisual.qml</file> <file alias="QGroundControl/Controls/FWLandingPatternMapVisual.qml">src/PlanView/FWLandingPatternMapVisual.qml</file>
......
...@@ -41,7 +41,7 @@ Rectangle { ...@@ -41,7 +41,7 @@ Rectangle {
readonly property string _vehicleLabel: qsTr("Vehicle") readonly property string _vehicleLabel: qsTr("Vehicle")
QGCPalette { id: qgcPal } QGCPalette { id: qgcPal }
QFileDialogController { id: fileController } QGCFileDialogController { id: fileController }
Loader { Loader {
id: deferedload id: deferedload
...@@ -153,9 +153,10 @@ Rectangle { ...@@ -153,9 +153,10 @@ Rectangle {
spacing: _margin spacing: _margin
visible: missionEndHeader.checked visible: missionEndHeader.checked
FactCheckBox { QGCCheckBox {
text: qsTr("Return To Launch") text: qsTr("Return To Launch")
fact: missionItem.missionEndRTL checked: missionItem.missionEndRTL
onClicked: missionItem.missionEndRTL = checked
} }
} }
......
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
#include "CustomCommandWidgetController.h" #include "CustomCommandWidgetController.h"
#include "ESP8266ComponentController.h" #include "ESP8266ComponentController.h"
#include "ScreenToolsController.h" #include "ScreenToolsController.h"
#include "QFileDialogController.h" #include "QGCFileDialogController.h"
#include "RCChannelMonitorController.h" #include "RCChannelMonitorController.h"
#include "SyslinkComponentController.h" #include "SyslinkComponentController.h"
#include "AutoPilotPlugin.h" #include "AutoPilotPlugin.h"
...@@ -363,16 +363,16 @@ void QGCApplication::_initCommon(void) ...@@ -363,16 +363,16 @@ void QGCApplication::_initCommon(void)
qmlRegisterUncreatableType<GeoFenceController> ("QGroundControl.Controllers", 1, 0, "GeoFenceController", "Reference only"); qmlRegisterUncreatableType<GeoFenceController> ("QGroundControl.Controllers", 1, 0, "GeoFenceController", "Reference only");
qmlRegisterUncreatableType<RallyPointController>("QGroundControl.Controllers", 1, 0, "RallyPointController", "Reference only"); qmlRegisterUncreatableType<RallyPointController>("QGroundControl.Controllers", 1, 0, "RallyPointController", "Reference only");
qmlRegisterType<ParameterEditorController> ("QGroundControl.Controllers", 1, 0, "ParameterEditorController"); qmlRegisterType<ParameterEditorController> ("QGroundControl.Controllers", 1, 0, "ParameterEditorController");
qmlRegisterType<ESP8266ComponentController> ("QGroundControl.Controllers", 1, 0, "ESP8266ComponentController"); qmlRegisterType<ESP8266ComponentController> ("QGroundControl.Controllers", 1, 0, "ESP8266ComponentController");
qmlRegisterType<ScreenToolsController> ("QGroundControl.Controllers", 1, 0, "ScreenToolsController"); qmlRegisterType<ScreenToolsController> ("QGroundControl.Controllers", 1, 0, "ScreenToolsController");
qmlRegisterType<PlanMasterController> ("QGroundControl.Controllers", 1, 0, "PlanElemementMasterController"); qmlRegisterType<PlanMasterController> ("QGroundControl.Controllers", 1, 0, "PlanElemementMasterController");
qmlRegisterType<ValuesWidgetController> ("QGroundControl.Controllers", 1, 0, "ValuesWidgetController"); qmlRegisterType<ValuesWidgetController> ("QGroundControl.Controllers", 1, 0, "ValuesWidgetController");
qmlRegisterType<QFileDialogController> ("QGroundControl.Controllers", 1, 0, "QFileDialogController"); qmlRegisterType<QGCFileDialogController> ("QGroundControl.Controllers", 1, 0, "QGCFileDialogController");
qmlRegisterType<RCChannelMonitorController> ("QGroundControl.Controllers", 1, 0, "RCChannelMonitorController"); qmlRegisterType<RCChannelMonitorController> ("QGroundControl.Controllers", 1, 0, "RCChannelMonitorController");
qmlRegisterType<JoystickConfigController> ("QGroundControl.Controllers", 1, 0, "JoystickConfigController"); qmlRegisterType<JoystickConfigController> ("QGroundControl.Controllers", 1, 0, "JoystickConfigController");
qmlRegisterType<LogDownloadController> ("QGroundControl.Controllers", 1, 0, "LogDownloadController"); qmlRegisterType<LogDownloadController> ("QGroundControl.Controllers", 1, 0, "LogDownloadController");
qmlRegisterType<SyslinkComponentController> ("QGroundControl.Controllers", 1, 0, "SyslinkComponentController"); qmlRegisterType<SyslinkComponentController> ("QGroundControl.Controllers", 1, 0, "SyslinkComponentController");
#ifndef __mobile__ #ifndef __mobile__
qmlRegisterType<ViewWidgetController> ("QGroundControl.Controllers", 1, 0, "ViewWidgetController"); qmlRegisterType<ViewWidgetController> ("QGroundControl.Controllers", 1, 0, "ViewWidgetController");
qmlRegisterType<CustomCommandWidgetController> ("QGroundControl.Controllers", 1, 0, "CustomCommandWidgetController"); qmlRegisterType<CustomCommandWidgetController> ("QGroundControl.Controllers", 1, 0, "CustomCommandWidgetController");
......
import QtQuick 2.3
import QtQuick.Controls 1.2
import QGroundControl.Palette 1.0
import QGroundControl.ScreenTools 1.0
/// File Button controls used by QGCFileDialog control
Rectangle {
implicitWidth: ScreenTools.implicitButtonWidth
implicitHeight: ScreenTools.implicitButtonHeight
color: highlight ? qgcPal.buttonHighlight : qgcPal.button
border.color: highlight ? qgcPal.buttonHighlightText : qgcPal.buttonText
property alias text: label.text
property bool highlight: false
signal clicked
signal hamburgerClicked
property real _margins: ScreenTools.defaultFontPixelWidth / 2
QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
QGCLabel {
id: label
anchors.margins: _margins
anchors.left: parent.left
anchors.right: hamburger.left
anchors.top: parent.top
anchors.bottom: parent.bottom
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
color: highlight ? qgcPal.buttonHighlightText : qgcPal.buttonText
elide: Text.ElideRight
}
QGCColoredImage {
id: hamburger
anchors.rightMargin: _margins
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
width: _hamburgerSize
height: _hamburgerSize
sourceSize.height: _hamburgerSize
source: "qrc:/qmlimages/Hamburger.svg"
color: highlight ? qgcPal.buttonHighlightText : qgcPal.buttonText
property real _hamburgerSize: parent.height * 0.75
}
QGCMouseArea {
anchors.fill: parent
onClicked: parent.clicked()
}
QGCMouseArea {
anchors.leftMargin: -_margins * 2
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.left: hamburger.left
onClicked: parent.hamburgerClicked()
}
}
...@@ -17,16 +17,25 @@ Item { ...@@ -17,16 +17,25 @@ Item {
property var qgcView property var qgcView
property string folder property string folder
property var nameFilters property var nameFilters
property string fileExtension property string fileExtension // Primary file extension to search for
property string fileExtension2 property string fileExtension2 // Secondary file extension to search for
property string title property string title
property bool selectExisting property bool selectExisting
property bool selectFolder property bool selectFolder
property bool _openForLoad: true property bool _openForLoad: true
property real _margins: ScreenTools.defaultFontPixelHeight / 2 property real _margins: ScreenTools.defaultFontPixelHeight / 2
property bool _mobile: ScreenTools.isMobile property bool _mobile: ScreenTools.isMobile
property var _rgExtensions
Component.onCompleted: {
if (fileExtension2 === "") {
_rgExtensions = [ fileExtension ]
} else {
_rgExtensions = [ fileExtension, fileExtension2 ]
}
}
function openForLoad() { function openForLoad() {
_openForLoad = true _openForLoad = true
...@@ -54,7 +63,7 @@ Item { ...@@ -54,7 +63,7 @@ Item {
signal acceptedForSave(string file) signal acceptedForSave(string file)
signal rejected signal rejected
QFileDialogController { id: controller } QGCFileDialogController { id: controller }
QGCPalette { id: qgcPal; colorGroupEnabled: true } QGCPalette { id: qgcPal; colorGroupEnabled: true }
FileDialog { FileDialog {
...@@ -92,9 +101,10 @@ Item { ...@@ -92,9 +101,10 @@ Item {
Repeater { Repeater {
id: fileList id: fileList
model: controller.getFiles(folder, fileExtension) model: controller.getFiles(folder, _rgExtensions)
QGCButton { FileButton {
id: fileButton
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
text: modelData text: modelData
...@@ -103,21 +113,27 @@ Item { ...@@ -103,21 +113,27 @@ Item {
hideDialog() hideDialog()
_root.acceptedForLoad(controller.fullyQualifiedFilename(folder, modelData, fileExtension)) _root.acceptedForLoad(controller.fullyQualifiedFilename(folder, modelData, fileExtension))
} }
}
}
Repeater { onHamburgerClicked: {
id: fileList2 highlight = true
model: fileExtension2 == "" ? [ ] : controller.getFiles(folder, fileExtension2) hamburgerMenu.fileToDelete = controller.fullyQualifiedFilename(folder, modelData, fileExtension)
hamburgerMenu.popup()
}
QGCButton { Menu {
anchors.left: parent.left id: hamburgerMenu
anchors.right: parent.right
text: modelData
onClicked: { property string fileToDelete
hideDialog()
_root.acceptedForLoad(controller.fullyQualifiedFilename(folder, modelData, fileExtension2)) onAboutToHide: {
fileButton.highlight = false
hideDialog()
}
MenuItem {
text: qsTr("Delete")
onTriggered: controller.deleteFile(hamburgerMenu.fileToDelete);
}
} }
} }
} }
...@@ -197,9 +213,9 @@ Item { ...@@ -197,9 +213,9 @@ Item {
} }
Repeater { Repeater {
model: controller.getFiles(folder, fileExtension) model: controller.getFiles(folder, [ fileExtension ])
QGCButton { FileButton {
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
text: modelData text: modelData
...@@ -208,10 +224,30 @@ Item { ...@@ -208,10 +224,30 @@ Item {
hideDialog() hideDialog()
_root.acceptedForSave(controller.fullyQualifiedFilename(folder, modelData, fileExtension)) _root.acceptedForSave(controller.fullyQualifiedFilename(folder, modelData, fileExtension))
} }
}
}
onHamburgerClicked: {
highlight = true
hamburgerMenu.fileToDelete = controller.fullyQualifiedFilename(folder, modelData, fileExtension)
hamburgerMenu.popup()
}
Menu {
id: hamburgerMenu
property string fileToDelete
onAboutToHide: {
fileButton.highlight = false
hideDialog()
}
MenuItem {
text: qsTr("Delete")
onTriggered: controller.deleteFile(hamburgerMenu.fileToDelete);
}
}
}
}
} }
} }
} }
......
...@@ -8,32 +8,37 @@ ...@@ -8,32 +8,37 @@
****************************************************************************/ ****************************************************************************/
#include "QFileDialogController.h" #include "QGCFileDialogController.h"
#include <QStandardPaths> #include <QStandardPaths>
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
QGC_LOGGING_CATEGORY(QFileDialogControllerLog, "QFileDialogControllerLog") QGC_LOGGING_CATEGORY(QGCFileDialogControllerLog, "QGCFileDialogControllerLog")
QStringList QFileDialogController::getFiles(const QString& directoryPath, const QString& fileExtension) QStringList QGCFileDialogController::getFiles(const QString& directoryPath, const QStringList& fileExtensions)
{ {
qCDebug(QFileDialogControllerLog) << "getFiles" << directoryPath << fileExtension; qCDebug(QGCFileDialogControllerLog) << "getFiles" << directoryPath << fileExtensions;
QStringList files; QStringList files;
QDir fileDir(directoryPath); QDir fileDir(directoryPath);
QFileInfoList fileInfoList = fileDir.entryInfoList(QStringList(QString("*.%1").arg(fileExtension)), QDir::Files, QDir::Name); QStringList infoListExtensions;
foreach (const QString& extension, fileExtensions) {
infoListExtensions.append(QStringLiteral("*.%1").arg(extension));
}
QFileInfoList fileInfoList = fileDir.entryInfoList(infoListExtensions, QDir::Files, QDir::Name);
foreach (const QFileInfo& fileInfo, fileInfoList) { foreach (const QFileInfo& fileInfo, fileInfoList) {
qCDebug(QFileDialogControllerLog) << "getFiles found" << fileInfo.baseName(); qCDebug(QGCFileDialogControllerLog) << "getFiles found" << fileInfo.fileName();
files << fileInfo.baseName(); files << fileInfo.fileName();
} }
return files; return files;
} }
QString QFileDialogController::filenameWithExtension(const QString& filename, const QString& fileExtension) QString QGCFileDialogController::filenameWithExtension(const QString& filename, const QString& fileExtension)
{ {
QString filenameWithExtension(filename); QString filenameWithExtension(filename);
...@@ -45,12 +50,17 @@ QString QFileDialogController::filenameWithExtension(const QString& filename, co ...@@ -45,12 +50,17 @@ QString QFileDialogController::filenameWithExtension(const QString& filename, co
return filenameWithExtension; return filenameWithExtension;
} }
bool QFileDialogController::fileExists(const QString& filename) bool QGCFileDialogController::fileExists(const QString& filename)
{ {
return QFile(filename).exists(); return QFile(filename).exists();
} }
QString QFileDialogController::fullyQualifiedFilename(const QString& directoryPath, const QString& filename, const QString& fileExtension) QString QGCFileDialogController::fullyQualifiedFilename(const QString& directoryPath, const QString& filename, const QString& fileExtension)
{ {
return directoryPath + QStringLiteral("/") + filenameWithExtension(filename, fileExtension); return directoryPath + QStringLiteral("/") + filenameWithExtension(filename, fileExtension);
} }
void QGCFileDialogController::deleteFile(const QString& filename)
{
QFile::remove(filename);
}
...@@ -8,23 +8,23 @@ ...@@ -8,23 +8,23 @@
****************************************************************************/ ****************************************************************************/
#ifndef QFileDialogController_H #ifndef QGCFileDialogController_H
#define QFileDialogController_H #define QGCFileDialogController_H
#include <QObject> #include <QObject>
#include <QUrl> #include <QUrl>
#include "QGCLoggingCategory.h" #include "QGCLoggingCategory.h"
Q_DECLARE_LOGGING_CATEGORY(QFileDialogControllerLog) Q_DECLARE_LOGGING_CATEGORY(QGCFileDialogControllerLog)
class QFileDialogController : public QObject class QGCFileDialogController : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
/// Return all file in the specified path which match the specified extension /// Return all file in the specified path which match the specified extension
Q_INVOKABLE QStringList getFiles(const QString& directoryPath, const QString& fileExtension); Q_INVOKABLE QStringList getFiles(const QString& directoryPath, const QStringList& fileExtensions);
/// Returns the specified file name with the extension added it needed /// Returns the specified file name with the extension added it needed
Q_INVOKABLE QString filenameWithExtension(const QString& filename, const QString& fileExtension); Q_INVOKABLE QString filenameWithExtension(const QString& filename, const QString& fileExtension);
...@@ -35,6 +35,9 @@ public: ...@@ -35,6 +35,9 @@ public:
/// Check for file existence of specified fully qualified file name /// Check for file existence of specified fully qualified file name
Q_INVOKABLE bool fileExists(const QString& filename); Q_INVOKABLE bool fileExists(const QString& filename);
/// Deletes the file specified by the fully qualified file name
Q_INVOKABLE void deleteFile(const QString& filename);
Q_INVOKABLE QString urlToLocalFile(QUrl url) { return url.toLocalFile(); } Q_INVOKABLE QString urlToLocalFile(QUrl url) { return url.toLocalFile(); }
}; };
......
...@@ -8,6 +8,7 @@ DropButton 1.0 DropButton.qml ...@@ -8,6 +8,7 @@ DropButton 1.0 DropButton.qml
DropPanel 1.0 DropPanel.qml DropPanel 1.0 DropPanel.qml
ExclusiveGroupItem 1.0 ExclusiveGroupItem.qml ExclusiveGroupItem 1.0 ExclusiveGroupItem.qml
FactSliderPanel 1.0 FactSliderPanel.qml FactSliderPanel 1.0 FactSliderPanel.qml
FileButton 1.0 FileButton.qml
FlightModeDropdown 1.0 FlightModeDropdown.qml FlightModeDropdown 1.0 FlightModeDropdown.qml
FlightModeMenu 1.0 FlightModeMenu.qml FlightModeMenu 1.0 FlightModeMenu.qml
GeoFenceEditor 1.0 GeoFenceEditor.qml GeoFenceEditor 1.0 GeoFenceEditor.qml
......
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