Commit 611b3330 authored by Gus Grubba's avatar Gus Grubba

Turn "Sync" menu into a proper "File" menu

parent e4dc651d
...@@ -280,6 +280,7 @@ void PlanMasterController::loadFromFile(const QString& filename) ...@@ -280,6 +280,7 @@ void PlanMasterController::loadFromFile(const QString& filename)
return; return;
} }
QFileInfo fileInfo(filename);
QFile file(filename); QFile file(filename);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
...@@ -288,8 +289,8 @@ void PlanMasterController::loadFromFile(const QString& filename) ...@@ -288,8 +289,8 @@ void PlanMasterController::loadFromFile(const QString& filename)
return; return;
} }
QString fileExtension(".%1"); bool success = false;
if (filename.endsWith(fileExtension.arg(AppSettings::planFileExtension))) { if(fileInfo.suffix() == AppSettings::planFileExtension) {
QJsonDocument jsonDoc; QJsonDocument jsonDoc;
QByteArray bytes = file.readAll(); QByteArray bytes = file.readAll();
...@@ -319,17 +320,31 @@ void PlanMasterController::loadFromFile(const QString& filename) ...@@ -319,17 +320,31 @@ void PlanMasterController::loadFromFile(const QString& filename)
!_geoFenceController.load(json[_jsonGeoFenceObjectKey].toObject(), errorString) || !_geoFenceController.load(json[_jsonGeoFenceObjectKey].toObject(), errorString) ||
!_rallyPointController.load(json[_jsonRallyPointsObjectKey].toObject(), errorString)) { !_rallyPointController.load(json[_jsonRallyPointsObjectKey].toObject(), errorString)) {
qgcApp()->showMessage(errorMessage.arg(errorString)); qgcApp()->showMessage(errorMessage.arg(errorString));
} else {
success = true;
} }
} else if (filename.endsWith(fileExtension.arg(AppSettings::missionFileExtension))) { } else if (fileInfo.suffix() == AppSettings::missionFileExtension) {
if (!_missionController.loadJsonFile(file, errorString)) { if (!_missionController.loadJsonFile(file, errorString)) {
qgcApp()->showMessage(errorMessage.arg(errorString)); qgcApp()->showMessage(errorMessage.arg(errorString));
} else {
success = true;
} }
} else if (filename.endsWith(fileExtension.arg(AppSettings::waypointsFileExtension)) || } else if (fileInfo.suffix() == AppSettings::waypointsFileExtension || fileInfo.suffix() == QStringLiteral("txt")) {
filename.endsWith(fileExtension.arg(QStringLiteral("txt")))) {
if (!_missionController.loadTextFile(file, errorString)) { if (!_missionController.loadTextFile(file, errorString)) {
qgcApp()->showMessage(errorMessage.arg(errorString)); qgcApp()->showMessage(errorMessage.arg(errorString));
} else {
success = true;
} }
} else {
//-- TODO: What then?
}
if(success){
_currentPlanFile.sprintf("%s/%s.%s", fileInfo.path().toLocal8Bit().data(), fileInfo.completeBaseName().toLocal8Bit().data(), AppSettings::planFileExtension);
} else {
_currentPlanFile.clear();
} }
emit currentPlanFileChanged();
if (!offline()) { if (!offline()) {
setDirty(true); setDirty(true);
...@@ -352,6 +367,14 @@ QJsonDocument PlanMasterController::saveToJson() ...@@ -352,6 +367,14 @@ QJsonDocument PlanMasterController::saveToJson()
return QJsonDocument(planJson); return QJsonDocument(planJson);
} }
void
PlanMasterController::saveToCurrent()
{
if(!_currentPlanFile.isEmpty()) {
saveToFile(_currentPlanFile);
}
}
void PlanMasterController::saveToFile(const QString& filename) void PlanMasterController::saveToFile(const QString& filename)
{ {
if (filename.isEmpty()) { if (filename.isEmpty()) {
...@@ -367,9 +390,15 @@ void PlanMasterController::saveToFile(const QString& filename) ...@@ -367,9 +390,15 @@ void PlanMasterController::saveToFile(const QString& filename)
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qgcApp()->showMessage(tr("Plan save error %1 : %2").arg(filename).arg(file.errorString())); qgcApp()->showMessage(tr("Plan save error %1 : %2").arg(filename).arg(file.errorString()));
_currentPlanFile.clear();
emit currentPlanFileChanged();
} else { } else {
QJsonDocument saveDoc = saveToJson(); QJsonDocument saveDoc = saveToJson();
file.write(saveDoc.toJson()); file.write(saveDoc.toJson());
if(_currentPlanFile != planFilename) {
_currentPlanFile = planFilename;
emit currentPlanFileChanged();
}
} }
// Only clear dirty bit if we are offline // Only clear dirty bit if we are offline
...@@ -411,6 +440,8 @@ void PlanMasterController::removeAll(void) ...@@ -411,6 +440,8 @@ void PlanMasterController::removeAll(void)
_missionController.setDirty(false); _missionController.setDirty(false);
_geoFenceController.setDirty(false); _geoFenceController.setDirty(false);
_rallyPointController.setDirty(false); _rallyPointController.setDirty(false);
_currentPlanFile.clear();
emit currentPlanFileChanged();
} }
} }
......
...@@ -40,6 +40,7 @@ public: ...@@ -40,6 +40,7 @@ public:
Q_PROPERTY(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged) ///< true: Unsaved/sent changes are present, false: no changes since last save/send Q_PROPERTY(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged) ///< true: Unsaved/sent changes are present, false: no changes since last save/send
Q_PROPERTY(QString fileExtension READ fileExtension CONSTANT) ///< File extension for missions Q_PROPERTY(QString fileExtension READ fileExtension CONSTANT) ///< File extension for missions
Q_PROPERTY(QString kmlFileExtension READ kmlFileExtension CONSTANT) Q_PROPERTY(QString kmlFileExtension READ kmlFileExtension CONSTANT)
Q_PROPERTY(QString currentPlanFile READ currentPlanFile NOTIFY currentPlanFileChanged)
///< kml file extension for missions ///< kml file extension for missions
Q_PROPERTY(QStringList loadNameFilters READ loadNameFilters CONSTANT) ///< File filter list loading plan files Q_PROPERTY(QStringList loadNameFilters READ loadNameFilters CONSTANT) ///< File filter list loading plan files
Q_PROPERTY(QStringList saveNameFilters READ saveNameFilters CONSTANT) ///< File filter list saving plan files Q_PROPERTY(QStringList saveNameFilters READ saveNameFilters CONSTANT) ///< File filter list saving plan files
...@@ -63,6 +64,7 @@ public: ...@@ -63,6 +64,7 @@ public:
Q_INVOKABLE void loadFromVehicle(void); Q_INVOKABLE void loadFromVehicle(void);
Q_INVOKABLE void sendToVehicle(void); Q_INVOKABLE void sendToVehicle(void);
Q_INVOKABLE void loadFromFile(const QString& filename); Q_INVOKABLE void loadFromFile(const QString& filename);
Q_INVOKABLE void saveToCurrent();
Q_INVOKABLE void saveToFile(const QString& filename); Q_INVOKABLE void saveToFile(const QString& filename);
Q_INVOKABLE void saveToKml(const QString& filename); Q_INVOKABLE void saveToKml(const QString& filename);
Q_INVOKABLE void removeAll(void); ///< Removes all from controller only, synce required to remove from vehicle Q_INVOKABLE void removeAll(void); ///< Removes all from controller only, synce required to remove from vehicle
...@@ -79,6 +81,7 @@ public: ...@@ -79,6 +81,7 @@ public:
void setDirty (bool dirty); void setDirty (bool dirty);
QString fileExtension (void) const; QString fileExtension (void) const;
QString kmlFileExtension(void) const; QString kmlFileExtension(void) const;
QString currentPlanFile (void) const { return _currentPlanFile; }
QStringList loadNameFilters (void) const; QStringList loadNameFilters (void) const;
QStringList saveNameFilters (void) const; QStringList saveNameFilters (void) const;
QStringList fileKmlFilters (void) const; QStringList fileKmlFilters (void) const;
...@@ -93,6 +96,7 @@ signals: ...@@ -93,6 +96,7 @@ signals:
void syncInProgressChanged (void); void syncInProgressChanged (void);
void dirtyChanged (bool dirty); void dirtyChanged (bool dirty);
void offlineChanged (bool offlineEditing); void offlineChanged (bool offlineEditing);
void currentPlanFileChanged ();
private slots: private slots:
void _activeVehicleChanged(Vehicle* activeVehicle); void _activeVehicleChanged(Vehicle* activeVehicle);
...@@ -118,6 +122,7 @@ private: ...@@ -118,6 +122,7 @@ private:
bool _loadRallyPoints; bool _loadRallyPoints;
bool _sendGeoFence; bool _sendGeoFence;
bool _sendRallyPoints; bool _sendRallyPoints;
QString _currentPlanFile;
static const int _planFileVersion; static const int _planFileVersion;
static const char* _planFileType; static const char* _planFileType;
......
...@@ -524,37 +524,37 @@ QGCView { ...@@ -524,37 +524,37 @@ QGCView {
color: qgcPal.window color: qgcPal.window
title: qsTr("Plan") title: qsTr("Plan")
z: QGroundControl.zOrderWidgets z: QGroundControl.zOrderWidgets
showAlternateIcon: [ false, false, false, masterController.dirty, false, false, false ] showAlternateIcon: [ masterController.dirty, false, false, false, false, false, false ]
rotateImage: [ false, false, false, masterController.syncInProgress, false, false, false ] rotateImage: [ masterController.syncInProgress, false, false, false, false, false, false ]
animateImage: [ false, false, false, masterController.dirty, false, false, false ] animateImage: [ masterController.dirty, false, false, false, false, false, false ]
buttonEnabled: [ true, true, true, !masterController.syncInProgress, true, true, true ] buttonEnabled: [ !masterController.syncInProgress, true, true, true, true, true, true ]
buttonVisible: [ true, _waypointsOnlyMode, true, true, true, _showZoom, _showZoom ] buttonVisible: [ true, true, _waypointsOnlyMode, true, true, _showZoom, _showZoom ]
maxHeight: mapScale.y - toolStrip.y maxHeight: mapScale.y - toolStrip.y
property bool _showZoom: !ScreenTools.isMobile property bool _showZoom: !ScreenTools.isMobile
model: [ model: [
{ {
name: "Waypoint", name: "File",
iconSource: "/qmlimages/MapAddMission.svg", iconSource: "/qmlimages/MapSync.svg",
toggle: true alternateIconSource: "/qmlimages/MapSyncChanged.svg",
dropPanelComponent: syncDropPanel
},
{
name: "Waypoint",
iconSource: "/qmlimages/MapAddMission.svg",
toggle: true
}, },
{ {
name: "ROI", name: "ROI",
iconSource: "/qmlimages/MapAddMission.svg", iconSource: "/qmlimages/MapAddMission.svg",
toggle: true toggle: true
}, },
{ {
name: _singleComplexItem ? _missionController.complexMissionItemNames[0] : "Pattern", name: _singleComplexItem ? _missionController.complexMissionItemNames[0] : "Pattern",
iconSource: "/qmlimages/MapDrawShape.svg", iconSource: "/qmlimages/MapDrawShape.svg",
dropPanelComponent: _singleComplexItem ? undefined : patternDropPanel dropPanelComponent: _singleComplexItem ? undefined : patternDropPanel
}, },
{
name: "Sync",
iconSource: "/qmlimages/MapSync.svg",
alternateIconSource: "/qmlimages/MapSyncChanged.svg",
dropPanelComponent: syncDropPanel
},
{ {
name: "Center", name: "Center",
iconSource: "/qmlimages/MapCenter.svg", iconSource: "/qmlimages/MapCenter.svg",
...@@ -802,7 +802,7 @@ QGCView { ...@@ -802,7 +802,7 @@ QGCView {
Component { Component {
id: removeAllPromptDialog id: removeAllPromptDialog
QGCViewMessage { QGCViewMessage {
message: qsTr("Are you sure you want to remove all items? ") + message: qsTr("Are you sure you want to remove all items and create a new plan? ") +
(_planMasterController.offline ? "" : qsTr("This will also remove all items from the vehicle.")) (_planMasterController.offline ? "" : qsTr("This will also remove all items from the vehicle."))
function accept() { function accept() {
if (_planMasterController.offline) { if (_planMasterController.offline) {
...@@ -863,8 +863,11 @@ QGCView { ...@@ -863,8 +863,11 @@ QGCView {
width: sendSaveGrid.width width: sendSaveGrid.width
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
text: masterController.dirty ? text: masterController.dirty ?
qsTr("You have unsaved changes. You should upload to your vehicle, or save to a file:") : (_activeVehicle ?
qsTr("Sync:") qsTr("You have unsaved changes. You should upload to your vehicle, or save to a file:") :
qsTr("You have unsaved changes.")
) :
qsTr("Plan File:")
} }
GridLayout { GridLayout {
...@@ -878,6 +881,7 @@ QGCView { ...@@ -878,6 +881,7 @@ QGCView {
text: qsTr("Upload") text: qsTr("Upload")
Layout.fillWidth: true Layout.fillWidth: true
enabled: !masterController.offline && !masterController.syncInProgress enabled: !masterController.offline && !masterController.syncInProgress
visible: _activeVehicle
onClicked: { onClicked: {
dropPanel.hide() dropPanel.hide()
masterController.upload() masterController.upload()
...@@ -888,6 +892,7 @@ QGCView { ...@@ -888,6 +892,7 @@ QGCView {
text: qsTr("Download") text: qsTr("Download")
Layout.fillWidth: true Layout.fillWidth: true
enabled: !masterController.offline && !masterController.syncInProgress enabled: !masterController.offline && !masterController.syncInProgress
visible: _activeVehicle
onClicked: { onClicked: {
dropPanel.hide() dropPanel.hide()
if (masterController.dirty) { if (masterController.dirty) {
...@@ -899,17 +904,17 @@ QGCView { ...@@ -899,17 +904,17 @@ QGCView {
} }
QGCButton { QGCButton {
text: qsTr("Save Plan...") text: qsTr("New...")
Layout.fillWidth: true Layout.fillWidth: true
enabled: !masterController.syncInProgress enabled: _visualItems.count > 1
onClicked: { onClicked: {
dropPanel.hide() dropPanel.hide()
masterController.saveToSelectedFile() _qgcView.showDialog(removeAllPromptDialog, qsTr("New Plan"), _qgcView.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
} }
} }
QGCButton { QGCButton {
text: qsTr("Load Plan...") text: qsTr("Open...")
Layout.fillWidth: true Layout.fillWidth: true
enabled: !masterController.syncInProgress enabled: !masterController.syncInProgress
onClicked: { onClicked: {
...@@ -922,6 +927,30 @@ QGCView { ...@@ -922,6 +927,30 @@ QGCView {
} }
} }
QGCButton {
text: qsTr("Save")
Layout.fillWidth: true
enabled: !masterController.syncInProgress
onClicked: {
dropPanel.hide()
if(masterController.currentPlanFile !== "") {
masterController.saveToCurrent()
} else {
masterController.saveToSelectedFile()
}
}
}
QGCButton {
text: qsTr("Save As...")
Layout.fillWidth: true
enabled: !masterController.syncInProgress
onClicked: {
dropPanel.hide()
masterController.saveToSelectedFile()
}
}
QGCButton { QGCButton {
text: qsTr("Load KML...") text: qsTr("Load KML...")
Layout.fillWidth: true Layout.fillWidth: true
...@@ -938,7 +967,7 @@ QGCView { ...@@ -938,7 +967,7 @@ QGCView {
Layout.fillWidth: true Layout.fillWidth: true
enabled: !masterController.syncInProgress enabled: !masterController.syncInProgress
onClicked: { onClicked: {
// First point do not count // First point does not count
if (_visualItems.count < 2) { if (_visualItems.count < 2) {
_qgcView.showDialog(noItemForKML, qsTr("KML"), _qgcView.showDialogDefaultWidth, StandardButton.Cancel) _qgcView.showDialog(noItemForKML, qsTr("KML"), _qgcView.showDialogDefaultWidth, StandardButton.Cancel)
return return
...@@ -948,14 +977,6 @@ QGCView { ...@@ -948,14 +977,6 @@ QGCView {
} }
} }
QGCButton {
text: qsTr("Remove All")
Layout.fillWidth: true
onClicked: {
dropPanel.hide()
_qgcView.showDialog(removeAllPromptDialog, qsTr("Remove all"), _qgcView.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
}
}
} }
} }
} }
......
...@@ -16,7 +16,7 @@ import QGroundControl.Palette 1.0 ...@@ -16,7 +16,7 @@ import QGroundControl.Palette 1.0
Rectangle { Rectangle {
id: _root id: _root
color: qgcPal.window color: qgcPal.window
width: ScreenTools.isMobile ? ScreenTools.minTouchPixels : ScreenTools.defaultFontPixelWidth * 6 width: ScreenTools.isMobile ? ScreenTools.minTouchPixels : ScreenTools.defaultFontPixelWidth * 7
height: buttonStripColumn.height + (buttonStripColumn.anchors.margins * 2) height: buttonStripColumn.height + (buttonStripColumn.anchors.margins * 2)
radius: _radius radius: _radius
border.width: 1 border.width: 1
...@@ -133,7 +133,7 @@ Rectangle { ...@@ -133,7 +133,7 @@ Rectangle {
id: scope id: scope
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
height: width height: width * 0.8
Rectangle { Rectangle {
anchors.fill: parent anchors.fill: parent
...@@ -141,9 +141,11 @@ Rectangle { ...@@ -141,9 +141,11 @@ Rectangle {
QGCColoredImage { QGCColoredImage {
id: button id: button
anchors.fill: parent height: parent.height
width: height
anchors.centerIn: parent
source: _source source: _source
sourceSize.height: parent.height sourceSize.height: height
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
mipmap: true mipmap: true
smooth: true smooth: true
......
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