Commit 1be5d2bd authored by Matej Frančeškin's avatar Matej Frančeškin

Show and parse MGRS strings in Edit Position Dialog

parent 36748f71
...@@ -40,5 +40,10 @@ ...@@ -40,5 +40,10 @@
"type": "uint8", "type": "uint8",
"enumStrings": "North,South", "enumStrings": "North,South",
"enumValues": "0,1" "enumValues": "0,1"
},
{
"name": "MGRS",
"shortDescription": "MGRS coordinate",
"type": "string"
} }
] ]
...@@ -47,82 +47,110 @@ QGCViewDialog { ...@@ -47,82 +47,110 @@ QGCViewDialog {
rowSpacing: _margin rowSpacing: _margin
columns: 2 columns: 2
QGCLabel { text: qsTr("Latitude") } QGCLabel {
text: qsTr("Latitude")
}
FactTextField { FactTextField {
fact: controller.latitude fact: controller.latitude
Layout.fillWidth: true Layout.fillWidth: true
} }
QGCLabel { text: qsTr("Longitude") } QGCLabel {
text: qsTr("Longitude")
}
FactTextField { FactTextField {
fact: controller.longitude fact: controller.longitude
Layout.fillWidth: true Layout.fillWidth: true
} }
}
QGCButton { QGCButton {
anchors.right: parent.right
text: qsTr("Set Geographic") text: qsTr("Set Geographic")
Layout.alignment: Qt.AlignRight
Layout.columnSpan: 2
onClicked: { onClicked: {
controller.setFromGeo() controller.setFromGeo()
reject() reject()
} }
} }
GridLayout { Item { width: 1; height: ScreenTools.defaultFontPixelHeight; Layout.columnSpan: 2}
anchors.left: parent.left
anchors.right: parent.right
columnSpacing: _margin
rowSpacing: _margin
columns: 2
QGCLabel { text: qsTr("Zone") } QGCLabel {
text: qsTr("Zone")
}
FactTextField { FactTextField {
fact: controller.zone fact: controller.zone
Layout.fillWidth: true Layout.fillWidth: true
} }
QGCLabel { text: qsTr("Hemisphere") } QGCLabel {
text: qsTr("Hemisphere")
}
FactComboBox { FactComboBox {
fact: controller.hemisphere fact: controller.hemisphere
indexModel: false indexModel: false
Layout.fillWidth: true Layout.fillWidth: true
} }
QGCLabel { text: qsTr("Easting") } QGCLabel {
text: qsTr("Easting")
}
FactTextField { FactTextField {
fact: controller.easting fact: controller.easting
Layout.fillWidth: true Layout.fillWidth: true
} }
QGCLabel { text: qsTr("Northing") } QGCLabel {
text: qsTr("Northing")
}
FactTextField { FactTextField {
fact: controller.northing fact: controller.northing
Layout.fillWidth: true Layout.fillWidth: true
} }
}
QGCButton { QGCButton {
anchors.right: parent.right
text: qsTr("Set UTM") text: qsTr("Set UTM")
Layout.alignment: Qt.AlignRight
Layout.columnSpan: 2
onClicked: { onClicked: {
controller.setFromUTM() controller.setFromUTM()
reject() reject()
} }
} }
Item { width: 1; height: ScreenTools.defaultFontPixelHeight; Layout.columnSpan: 2}
QGCLabel {
text: qsTr("MGRS")
}
FactTextField {
fact: controller.mgrs
Layout.fillWidth: true
}
QGCButton {
text: qsTr("Set MGRS")
Layout.alignment: Qt.AlignRight
Layout.columnSpan: 2
onClicked: {
controller.setFromMGRS()
reject()
}
}
Item { width: 1; height: ScreenTools.defaultFontPixelHeight; Layout.columnSpan: 2}
QGCButton { QGCButton {
anchors.right: parent.right
text: qsTr("Set From Vehicle Position") text: qsTr("Set From Vehicle Position")
visible: QGroundControl.multiVehicleManager.activeVehicle && QGroundControl.multiVehicleManager.activeVehicle.coordinate.isValid visible: QGroundControl.multiVehicleManager.activeVehicle && QGroundControl.multiVehicleManager.activeVehicle.coordinate.isValid
Layout.alignment: Qt.AlignRight
Layout.columnSpan: 2
onClicked: { onClicked: {
controller.setFromVehicle() controller.setFromVehicle()
reject() reject()
} }
} }
}
} // Column } // Column
} // QGCFlickable } // QGCFlickable
} // QGCViewDialog } // QGCViewDialog
...@@ -17,6 +17,7 @@ const char* EditPositionDialogController::_zoneFactName = "Zone"; ...@@ -17,6 +17,7 @@ const char* EditPositionDialogController::_zoneFactName = "Zone";
const char* EditPositionDialogController::_hemisphereFactName = "Hemisphere"; const char* EditPositionDialogController::_hemisphereFactName = "Hemisphere";
const char* EditPositionDialogController::_eastingFactName = "Easting"; const char* EditPositionDialogController::_eastingFactName = "Easting";
const char* EditPositionDialogController::_northingFactName = "Northing"; const char* EditPositionDialogController::_northingFactName = "Northing";
const char* EditPositionDialogController::_mgrsFactName = "MGRS";
QMap<QString, FactMetaData*> EditPositionDialogController::_metaDataMap; QMap<QString, FactMetaData*> EditPositionDialogController::_metaDataMap;
...@@ -27,6 +28,7 @@ EditPositionDialogController::EditPositionDialogController(void) ...@@ -27,6 +28,7 @@ EditPositionDialogController::EditPositionDialogController(void)
, _hemisphereFact (0, _hemisphereFactName, FactMetaData::valueTypeUint8) , _hemisphereFact (0, _hemisphereFactName, FactMetaData::valueTypeUint8)
, _eastingFact (0, _eastingFactName, FactMetaData::valueTypeDouble) , _eastingFact (0, _eastingFactName, FactMetaData::valueTypeDouble)
, _northingFact (0, _northingFactName, FactMetaData::valueTypeDouble) , _northingFact (0, _northingFactName, FactMetaData::valueTypeDouble)
, _mgrsFact (0, _mgrsFactName, FactMetaData::valueTypeString)
{ {
if (_metaDataMap.isEmpty()) { if (_metaDataMap.isEmpty()) {
_metaDataMap = FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/EditPositionDialog.FactMetaData.json"), nullptr /* QObject parent */); _metaDataMap = FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/EditPositionDialog.FactMetaData.json"), nullptr /* QObject parent */);
...@@ -38,6 +40,7 @@ EditPositionDialogController::EditPositionDialogController(void) ...@@ -38,6 +40,7 @@ EditPositionDialogController::EditPositionDialogController(void)
_hemisphereFact.setMetaData (_metaDataMap[_hemisphereFactName]); _hemisphereFact.setMetaData (_metaDataMap[_hemisphereFactName]);
_eastingFact.setMetaData (_metaDataMap[_eastingFactName]); _eastingFact.setMetaData (_metaDataMap[_eastingFactName]);
_northingFact.setMetaData (_metaDataMap[_northingFactName]); _northingFact.setMetaData (_metaDataMap[_northingFactName]);
_mgrsFact.setMetaData (_metaDataMap[_mgrsFactName]);
} }
void EditPositionDialogController::setCoordinate(QGeoCoordinate coordinate) void EditPositionDialogController::setCoordinate(QGeoCoordinate coordinate)
...@@ -55,10 +58,16 @@ void EditPositionDialogController::initValues(void) ...@@ -55,10 +58,16 @@ void EditPositionDialogController::initValues(void)
double easting, northing; double easting, northing;
int zone = convertGeoToUTM(_coordinate, easting, northing); int zone = convertGeoToUTM(_coordinate, easting, northing);
if (zone >= 1 && zone <= 60) {
_zoneFact.setRawValue(zone); _zoneFact.setRawValue(zone);
_hemisphereFact.setRawValue(_coordinate.latitude() < 0); _hemisphereFact.setRawValue(_coordinate.latitude() < 0);
_eastingFact.setRawValue(easting); _eastingFact.setRawValue(easting);
_northingFact.setRawValue(northing); _northingFact.setRawValue(northing);
}
QString mgrs = convertGeoToMGRS(_coordinate);
if (!mgrs.isEmpty()) {
_mgrsFact.setRawValue(mgrs);
}
} }
void EditPositionDialogController::setFromGeo(void) void EditPositionDialogController::setFromGeo(void)
...@@ -71,9 +80,21 @@ void EditPositionDialogController::setFromGeo(void) ...@@ -71,9 +80,21 @@ void EditPositionDialogController::setFromGeo(void)
void EditPositionDialogController::setFromUTM(void) void EditPositionDialogController::setFromUTM(void)
{ {
qDebug() << _eastingFact.rawValue().toDouble() << _northingFact.rawValue().toDouble() << _zoneFact.rawValue().toInt() << (_hemisphereFact.rawValue().toInt() == 1); qDebug() << _eastingFact.rawValue().toDouble() << _northingFact.rawValue().toDouble() << _zoneFact.rawValue().toInt() << (_hemisphereFact.rawValue().toInt() == 1);
convertUTMToGeo(_eastingFact.rawValue().toDouble(), _northingFact.rawValue().toDouble(), _zoneFact.rawValue().toInt(), _hemisphereFact.rawValue().toInt() == 1, _coordinate); if (convertUTMToGeo(_eastingFact.rawValue().toDouble(), _northingFact.rawValue().toDouble(), _zoneFact.rawValue().toInt(), _hemisphereFact.rawValue().toInt() == 1, _coordinate)) {
qDebug() << _eastingFact.rawValue().toDouble() << _northingFact.rawValue().toDouble() << _zoneFact.rawValue().toInt() << (_hemisphereFact.rawValue().toInt() == 1) << _coordinate; qDebug() << _eastingFact.rawValue().toDouble() << _northingFact.rawValue().toDouble() << _zoneFact.rawValue().toInt() << (_hemisphereFact.rawValue().toInt() == 1) << _coordinate;
emit coordinateChanged(_coordinate); emit coordinateChanged(_coordinate);
} else {
initValues();
}
}
void EditPositionDialogController::setFromMGRS(void)
{
if (convertMGRSToGeo(_mgrsFact.rawValue().toString(), _coordinate)) {
emit coordinateChanged(_coordinate);
} else {
initValues();
}
} }
void EditPositionDialogController::setFromVehicle(void) void EditPositionDialogController::setFromVehicle(void)
......
...@@ -28,6 +28,7 @@ public: ...@@ -28,6 +28,7 @@ public:
Q_PROPERTY(Fact* hemisphere READ hemisphere CONSTANT) Q_PROPERTY(Fact* hemisphere READ hemisphere CONSTANT)
Q_PROPERTY(Fact* easting READ easting CONSTANT) Q_PROPERTY(Fact* easting READ easting CONSTANT)
Q_PROPERTY(Fact* northing READ northing CONSTANT) Q_PROPERTY(Fact* northing READ northing CONSTANT)
Q_PROPERTY(Fact* mgrs READ mgrs CONSTANT)
QGeoCoordinate coordinate(void) const { return _coordinate; } QGeoCoordinate coordinate(void) const { return _coordinate; }
Fact* latitude (void) { return &_latitudeFact; } Fact* latitude (void) { return &_latitudeFact; }
...@@ -36,12 +37,14 @@ public: ...@@ -36,12 +37,14 @@ public:
Fact* hemisphere(void) { return &_hemisphereFact; } Fact* hemisphere(void) { return &_hemisphereFact; }
Fact* easting (void) { return &_eastingFact; } Fact* easting (void) { return &_eastingFact; }
Fact* northing (void) { return &_northingFact; } Fact* northing (void) { return &_northingFact; }
Fact* mgrs (void) { return &_mgrsFact; }
void setCoordinate(QGeoCoordinate coordinate); void setCoordinate(QGeoCoordinate coordinate);
Q_INVOKABLE void initValues(void); Q_INVOKABLE void initValues(void);
Q_INVOKABLE void setFromGeo(void); Q_INVOKABLE void setFromGeo(void);
Q_INVOKABLE void setFromUTM(void); Q_INVOKABLE void setFromUTM(void);
Q_INVOKABLE void setFromMGRS(void);
Q_INVOKABLE void setFromVehicle(void); Q_INVOKABLE void setFromVehicle(void);
signals: signals:
...@@ -58,6 +61,7 @@ private: ...@@ -58,6 +61,7 @@ private:
Fact _hemisphereFact; Fact _hemisphereFact;
Fact _eastingFact; Fact _eastingFact;
Fact _northingFact; Fact _northingFact;
Fact _mgrsFact;
static const char* _latitudeFactName; static const char* _latitudeFactName;
static const char* _longitudeFactName; static const char* _longitudeFactName;
...@@ -65,4 +69,5 @@ private: ...@@ -65,4 +69,5 @@ private:
static const char* _hemisphereFactName; static const char* _hemisphereFactName;
static const char* _eastingFactName; static const char* _eastingFactName;
static const char* _northingFactName; static const char* _northingFactName;
static const char* _mgrsFactName;
}; };
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