Skip to content
Browse files

Added mapping capabilities. Several minor bug fixes..

  • Loading branch information...
1 parent b12f8c7 commit 622314bb0d7e1dea03de916d09446f7a1584ecd0 @shaque committed Oct 30, 2012
View
4 locationdiagnostics/assets/LabelLabel.qml
@@ -32,7 +32,7 @@ Container {
textStyle {
base: SystemDefaults.TextStyles.BodyText
- color: Color.Black
+ color: Color.Green
fontStyle: FontStyle.Italic
}
@@ -49,7 +49,7 @@ Container {
multiline: true
textStyle {
base: SystemDefaults.TextStyles.BodyText
- color: Color.Black
+ color: Color.White
}
}
}
View
225 locationdiagnostics/assets/LocationPage.qml
@@ -1,299 +1,250 @@
/* Copyright (c) 2012 Research In Motion Limited.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
import bb.cascades 1.0
+import bb.cascades.maps 1.0
Page {
-//! [0]
+ //! [0]
property variant session
-//! [0]
-
+ //! [0]
Container {
- layout: DockLayout {}
+ layout: DockLayout {
+ }
// The background image
ImageView {
imageSource: "asset:///images/background.png"
}
-
Container {
topPadding: 150
-//! [1]
+ //! [1]
// Location page
ScrollView {
scrollViewProperties {
scrollMode: ScrollMode.Vertical
}
-
visible: (pageSelector.selectedIndex == 0)
-
Container {
topPadding: 50
leftPadding: 50
rightPadding: 50
-
LabelLabel {
- label: qsTr ("timestamp")
+ label: qsTr("timestamp")
text: session ? session.time : ""
}
-
LabelLabel {
- label: qsTr ("method")
+ label: qsTr("method")
text: session ? session.method : ""
}
-
- Divider {}
-
+ Divider {
+ }
LabelLabel {
- label: qsTr ("latitude")
+ label: qsTr("latitude")
text: session ? session.latitude : ""
}
-
LabelLabel {
- label: qsTr ("longitude")
+ label: qsTr("longitude")
text: session ? session.longitude : ""
}
-
LabelLabel {
- label: qsTr ("altitude")
+ label: qsTr("altitude")
text: session ? session.altitude : ""
}
-
- Divider {}
-
+ Divider {
+ }
LabelLabel {
- label: qsTr ("direction")
+ label: qsTr("direction")
text: session ? session.direction : ""
}
-
LabelLabel {
- label: qsTr ("ground speed")
+ label: qsTr("ground speed")
text: session ? session.groundSpeed : ""
}
-
LabelLabel {
- label: qsTr ("vertical speed")
+ label: qsTr("vertical speed")
text: session ? session.verticalSpeed : ""
}
-
- Divider {}
-
+ Divider {
+ }
LabelLabel {
- label: qsTr ("magnetic variation")
+ label: qsTr("magnetic variation")
text: session ? session.magneticVariation : ""
}
-
LabelLabel {
- label: qsTr ("horizontal accuracy")
+ label: qsTr("horizontal accuracy")
text: session ? session.horizontalAccuracy : ""
}
-
LabelLabel {
- label: qsTr ("vertical accuracy")
+ label: qsTr("vertical accuracy")
text: session ? session.verticalAccuracy : ""
}
-
LabelLabel {
- label: qsTr ("horizontal dilution")
+ label: qsTr("horizontal dilution")
text: session ? session.horizontalDilution : ""
}
-
LabelLabel {
- label: qsTr ("vertical dilution")
+ label: qsTr("vertical dilution")
text: session ? session.verticalDilution : ""
}
-
LabelLabel {
- label: qsTr ("position dilution")
+ label: qsTr("position dilution")
text: session ? session.positionDilution : ""
}
-
- Divider {}
-
+ Divider {
+ }
LabelLabel {
- label: qsTr ("ttff")
+ label: qsTr("ttff")
text: session ? session.ttff : ""
}
-
LabelLabel {
- label: qsTr ("gps week")
+ label: qsTr("gps week")
text: session ? session.gpsWeek : ""
}
-
LabelLabel {
- label: qsTr ("gps time of week")
+ label: qsTr("gps time of week")
text: session ? session.gpsTimeOfWeek : ""
}
-
LabelLabel {
- label: qsTr ("is propagated")
+ label: qsTr("is propagated")
text: session ? session.isPropagated : ""
}
-
DropDown {
id: resetModeSelector
-
- title: qsTr ("Reset Mode")
-
+ title: qsTr("Reset Mode")
Option {
- text: qsTr ("Cold")
+ text: qsTr("Cold")
value: "cold"
selected: true
}
-
Option {
- text: qsTr ("Warm")
+ text: qsTr("Warm")
value: "warm"
}
-
Option {
- text: qsTr ("Hot")
+ text: qsTr("Hot")
value: "hot"
}
}
-
Button {
horizontalAlignment: HorizontalAlignment.Center
-
- text: qsTr ("Reset")
-
+ text: qsTr("Reset")
onClicked: session.resetSession(resetModeSelector.selectedValue)
}
}
}
-//! [1]
+ //! [1]
// Satellites page
ScrollView {
scrollViewProperties {
scrollMode: ScrollMode.Vertical
}
-
visible: (pageSelector.selectedIndex == 1)
-
Container {
topPadding: 30
leftPadding: 30
rightPadding: 30
-
TextArea {
textStyle {
base: SystemDefaults.TextStyles.SmallText
- color: Color.Gray
- fontWeight: FontWeight.Normal
+ color: Color.White
+ fontWeight: FontWeight.Bold
fontFamily: "courier"
}
-
editable: false
-
backgroundVisible: true
-
text: session.satellitesInView
- hintText: qsTr ("Satellite Information")
+ hintText: qsTr("Satellite Information")
}
-
TextArea {
textStyle {
base: SystemDefaults.TextStyles.SmallText
- color: Color.Gray
- fontWeight: FontWeight.Normal
+ color: Color.White
+ fontWeight: FontWeight.Bold
fontFamily: "courier"
}
-
editable: false
-
backgroundVisible: true
-
text: session.satellitesInUse
- hintText: qsTr ("Satellite Information")
+ hintText: qsTr("Satellite Information")
}
}
}
-//! [2]
- // Logs page
- ScrollView {
- scrollViewProperties {
- scrollMode: ScrollMode.Vertical
+ //! [2]
+ // Map page
+ Container {
+ layout: DockLayout {
}
-
visible: (pageSelector.selectedIndex == 2)
-
- Container {
- topPadding: 30
- leftPadding: 30
- rightPadding: 30
-
- TextArea {
- textStyle {
- base: SystemDefaults.TextStyles.BodyText
- fontWeight: FontWeight.Normal
- fontFamily: "courier"
- }
-
- editable: false
-
- backgroundVisible: true
-
- hintText: qsTr ("Logs")
- text: session ? session.log : ""
- }
+ leftPadding: 30
+ topPadding: 30
+ rightPadding: 30
+ bottomPadding: 30
+ preferredWidth: maxWidth
+ preferredHeight: maxHeight
+ MapView {
+ id: myMap
+ objectName: "myMap"
+ altitude: 5000
+ latitude: 0
+ longitude: 0
+ verticalAlignment: VerticalAlignment.Center
+ horizontalAlignment: HorizontalAlignment.Center
}
}
-//! [2]
- }
+ //! [2]
+ }
Container {
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Top
-
leftPadding: 30
topPadding: 30
rightPadding: 30
-//! [3]
+ //! [3]
SegmentedControl {
id: pageSelector
-
Option {
- text: qsTr ("Location")
+ text: qsTr("Location")
selected: true
}
-
Option {
- text: qsTr ("Satellites")
+ text: qsTr("Satellites")
}
-
Option {
- text: qsTr ("Logs")
+ text: qsTr("Map")
}
}
-//! [3]
+ //! [3]
}
}
-//! [4]
+ //! [4]
paneProperties: NavigationPaneProperties {
backButton: ActionItem {
- title: qsTr ("Back")
- onTriggered: {
- session.stopUpdates()
+ title: qsTr("Back")
+ onTriggered: {
navigationPane.pop()
}
}
}
-//! [4]
+
+
+ //! [4]
}
View
BIN locationdiagnostics/assets/images/background.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
168 locationdiagnostics/assets/main.qml
@@ -1,245 +1,209 @@
/* Copyright (c) 2012 Research In Motion Limited.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/import bb.cascades 1.0
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */import bb.cascades 1.0
NavigationPane {
id: navigationPane
-
- onPopTransitionEnded: page.destroy()
-
+ onPopTransitionEnded: {
+ page.session.stopUpdates();
+ page.destroy();
+ }
Page {
-//! [0]
+ //! [0]
actions: [
ActionItem {
- title: qsTr ("Start Updates")
+ title: qsTr("Start Updates")
imageSource: "asset:///images/track.png"
ActionBar.placement: ActionBarPlacement.OnBar
-
onTriggered: {
- var session = _locationDiagnostics.createLocationSession(true)
var page = locationPage.createObject()
+ var session = _locationDiagnostics.createLocationSession(true, page)
page.session = session
navigationPane.push(page)
}
},
-
ActionItem {
- title: qsTr ("Request Update")
+ title: qsTr("Request Update")
imageSource: "asset:///images/pin.png"
ActionBar.placement: ActionBarPlacement.OnBar
-
onTriggered: {
- var session = _locationDiagnostics.createLocationSession(false)
var page = locationPage.createObject()
+ var session = _locationDiagnostics.createLocationSession(false, page)
page.session = session;
navigationPane.push(page)
}
}
]
-//! [0]
+ //! [0]
-//! [1]
+ //! [1]
attachedObjects: [
ComponentDefinition {
id: locationPage
source: "LocationPage.qml"
}
]
-//! [1]
-
+ //! [1]
Container {
- layout: DockLayout {}
+ layout: DockLayout {
+ }
// The background image
ImageView {
imageSource: "asset:///images/background.png"
}
-
ScrollView {
scrollViewProperties {
scrollMode: ScrollMode.Vertical
}
-
Container {
horizontalAlignment: HorizontalAlignment.Fill
-
topPadding: 50
leftPadding: 50
- rightPadding: 50
-
+ rightPadding: 50
DropDown {
- title: qsTr ("Positioning Method")
-
+ title: qsTr("Positioning Method")
Option {
- text: qsTr ("All")
- description: qsTr ("GPS, MS-Based, MS-Assisted, Cell or Wifi")
+ text: qsTr("All")
+ description: qsTr("GPS, MS-Based, MS-Assisted, Cell or Wifi")
value: "all"
selected: (_locationDiagnostics.positionMethod == value)
}
-
Option {
- text: qsTr ("Non-Satellite")
- description: qsTr ("Cell or WiFi")
+ text: qsTr("Non-Satellite")
+ description: qsTr("Cell or WiFi")
value: "nonSatellite"
selected: (_locationDiagnostics.positionMethod == value)
}
-
Option {
- text: qsTr ("Satellite")
- description: qsTr ("GPS, MS-Based, MS-Assisted")
+ text: qsTr("Satellite")
+ description: qsTr("GPS, MS-Based, MS-Assisted")
value: "satellite"
selected: (_locationDiagnostics.positionMethod == value)
}
-
Option {
- text: qsTr ("GPS")
- description: qsTr ("GPS Only")
+ text: qsTr("GPS")
+ description: qsTr("GPS Only")
value: "gps"
selected: (_locationDiagnostics.positionMethod == value)
}
-
Option {
- text: qsTr ("Cellular")
- description: qsTr ("Cellular only")
+ text: qsTr("Cellular")
+ description: qsTr("Cellular only")
value: "cellular"
selected: (_locationDiagnostics.positionMethod == value)
}
-
Option {
- text: qsTr ("WiFi")
- description: qsTr ("WiFi only")
+ text: qsTr("WiFi")
+ description: qsTr("WiFi only")
value: "wifi"
selected: (_locationDiagnostics.positionMethod == value)
}
-
Option {
- text: qsTr ("MS-Based")
- description: qsTr ("MS-Based only")
+ text: qsTr("MS-Based")
+ description: qsTr("MS-Based only")
value: "msb"
selected: (_locationDiagnostics.positionMethod == value)
}
-
Option {
- text: qsTr ("MS-Assisted")
- description: qsTr ("MS-Assisted only")
+ text: qsTr("MS-Assisted")
+ description: qsTr("MS-Assisted only")
value: "msa"
selected: (_locationDiagnostics.positionMethod == value)
}
-
onSelectedValueChanged: {
_locationDiagnostics.positionMethod = selectedValue
}
}
-//! [2]
+ //! [2]
DropDown {
id: assistanceModeSelector
-
- title: qsTr ("Assistance")
-
+ title: qsTr("Assistance")
Option {
- text: qsTr ("None")
- description: qsTr ("No carrier assistance")
+ text: qsTr("None")
+ description: qsTr("No carrier assistance")
value: "none"
selected: (_locationDiagnostics.assistanceMode == value)
}
-
Option {
- text: qsTr ("PDE")
- description: qsTr ("PDE Server")
+ text: qsTr("PDE")
+ description: qsTr("PDE Server")
value: "pde"
selected: (_locationDiagnostics.assistanceMode == value)
}
-
Option {
- text: qsTr ("SLP")
- description: qsTr ("SLP Server")
+ text: qsTr("SLP")
+ description: qsTr("SLP Server")
value: "slp"
selected: (_locationDiagnostics.assistanceMode == value)
}
-
Option {
- text: qsTr ("App ID/Password")
- description: qsTr ("Assistance requiring ID/Password")
+ text: qsTr("App ID/Password")
+ description: qsTr("Assistance requiring ID/Password")
value: "password"
selected: (_locationDiagnostics.assistanceMode == value)
}
-
onSelectedValueChanged: {
_locationDiagnostics.assistanceMode = selectedValue
}
}
-//! [2]
+ //! [2]
-//! [3]
+ //! [3]
TextField {
- hintText: qsTr ("PDE URL")
+ hintText: qsTr("PDE URL")
visible: (assistanceModeSelector.selectedValue == "pde")
inputMode: TextFieldInputMode.Url
-
onTextChanging: _locationDiagnostics.pdeUrl = text
}
-//! [3]
-
+ //! [3]
TextField {
- hintText: qsTr ("SUPL URL")
+ hintText: qsTr("SUPL URL")
visible: (assistanceModeSelector.selectedValue == "slp")
inputMode: TextFieldInputMode.Url
-
onTextChanging: _locationDiagnostics.slpUrl = text
}
-
TextField {
- hintText: qsTr ("App ID")
+ hintText: qsTr("App ID")
visible: (assistanceModeSelector.selectedValue == "password")
-
onTextChanging: _locationDiagnostics.appId = text
}
-
TextField {
- hintText: qsTr ("Password")
+ hintText: qsTr("Password")
visible: (assistanceModeSelector.selectedValue == "password")
inputMode: TextFieldInputMode.Password
-
onTextChanging: _locationDiagnostics.password = text
}
-
- Divider {}
-
+ Divider {
+ }
WarpDrive {
frequency: _locationDiagnostics.frequency
-
onFrequencyChanged: _locationDiagnostics.frequency = frequency
}
-
ToggleLabelButton {
horizontalAlignment: HorizontalAlignment.Fill
topMargin: 10
-
- text: qsTr ("Sound")
+ text: qsTr("Sound")
checked: _locationDiagnostics.useSound
-
onCheckedChanged: _locationDiagnostics.useSound = checked
}
-
ToggleLabelButton {
horizontalAlignment: HorizontalAlignment.Fill
topMargin: 10
-
- text: qsTr ("Background Mode")
+ text: qsTr("Background Mode")
checked: _locationDiagnostics.backgroundMode
-
onCheckedChanged: _locationDiagnostics.backgroundMode = checked
}
}
View
13 locationdiagnostics/bar-descriptor.xml
@@ -53,21 +53,23 @@
<!-- Name of author which is used for signing. Must match the developer name of your development certificate. -->
<author>Example Inc.</author>
<description>The locationdiagnostics application</description>
- <icon>
- <image>icon.png</image>
- </icon>
+ <cascadesTheme>dark</cascadesTheme>
<!-- Unique author ID assigned by signing authority. Required if using debug tokens. -->
<!-- <authorId>ABC1234YjsnUk235h</authorId> -->
<initialWindow>
<aspectRatio>portrait</aspectRatio>
<autoOrients>false</autoOrients>
+ <systemChrome>dark</systemChrome>
<transparent>false</transparent>
</initialWindow>
<!-- The category where the application appears. Either core.games or core.media. -->
<category>core.games</category>
+ <icon>
+ <image>icon.png</image>
+ </icon>
<configuration id="com.qnx.qcc.toolChain.1083946818" name="Default">
<platformArchitecture>armle-v7</platformArchitecture>
<asset path="arm/o.le-v7-g/locationdiagnostics" entry="true" type="Qnx/Elf">locationdiagnostics</asset>
@@ -95,6 +97,10 @@
<asset path="translations" dest="qm">
<include name="*.qm"/>
</asset>
+ <asset path="assets/images/compass_base.png">compass_base.png</asset>
+ <asset path="assets/images/compass_pointer.png">compass_pointer.png</asset>
+ <asset path="assets/images/track.png">track.png</asset>
+ <asset path="assets/images/pin.png">pin.png</asset>
<asset path="icon.png">icon.png</asset>
<!-- Request permission to execute native code. Required for native applications. -->
@@ -103,6 +109,7 @@
<action>access_internet</action>
<action>run_when_backgrounded</action>
<action>play_audio</action>
+ <permission>access_location_services</permission>
<env var="LD_LIBRARY_PATH" value="app/native/lib:/usr/lib/qt4/lib"/>
<!-- The permissions requested by your application. -->
View
BIN locationdiagnostics/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
4 locationdiagnostics/locationdiagnostics.pro
@@ -1,12 +1,12 @@
TEMPLATE = app
TARGET = locationdiagnostics
-CONFIG += qt warn_on debug_and_release cascades
+CONFIG += qt warn_on debug_and_release cascades console
INCLUDEPATH += ../src
SOURCES += ../src/*.cpp
HEADERS += ../src/*.hpp ../src/*.h
-LIBS += -lQtLocationSubset -lbbmultimedia -lmmrndclient -lasound -lbbcascadesmaps
+LIBS += -lQtLocationSubset -lbbmultimedia -lbbcascadesmaps -lGLESv1_CM
lupdate_inclusion {
SOURCES += ../assets/*.qml
View
6 locationdiagnostics/src/LocationDiagnostics.cpp
@@ -37,10 +37,10 @@ LocationDiagnostics::LocationDiagnostics(QObject *parent)
//! [0]
//! [1]
-LocationSession* LocationDiagnostics::createLocationSession(bool trackingMode)
+LocationSession* LocationDiagnostics::createLocationSession(bool trackingMode, QObject *var)
{
// Create a new location session
- LocationSession* session = new LocationSession(this, true);
+ LocationSession* session = new LocationSession(this, true, qobject_cast<Page*>(var)->findChild<MapView*>("myMap"));
// Configure the session according to the property values
session->setSoundEnabled(m_useSound);
@@ -88,6 +88,7 @@ LocationSession* LocationDiagnostics::createLocationSession(bool trackingMode)
session->positionSource()->setUpdateInterval(m_frequency * 1000);
session->positionSource()->setProperty("canRunInBackground", m_backgroundMode);
+
// Activate the session
if (trackingMode) {
session->startUpdates();
@@ -251,3 +252,4 @@ void LocationDiagnostics::setBackgroundMode(bool mode)
emit backgroundModeChanged();
}
+
View
9 locationdiagnostics/src/LocationDiagnostics.hpp
@@ -17,9 +17,14 @@
#define LOCATIONDIAGNOSTICS_HPP
#include <QtCore/QObject>
+#include <bb/cascades/controls/page.h>
+#include <bb/cascades/TitleBar>
class LocationSession;
+using namespace bb::cascades;
+
+
//! [0]
class LocationDiagnostics : public QObject
{
@@ -44,7 +49,8 @@ class LocationDiagnostics : public QObject
/**
* This method creates a new location session.
*/
- Q_INVOKABLE LocationSession* createLocationSession(bool trackingMode);
+ Q_INVOKABLE LocationSession* createLocationSession(bool trackingMode, QObject *var);
+
Q_SIGNALS:
// The change notification signals of the properties
@@ -92,6 +98,7 @@ private Q_SLOTS:
int m_frequency;
bool m_useSound;
bool m_backgroundMode;
+
};
//! [0]
View
510 locationdiagnostics/src/LocationSession.cpp
@@ -26,359 +26,331 @@
using namespace bb::multimedia;
//! [0]
-LocationSession::LocationSession(QObject* parent, bool satInfo)
- : QObject(parent)
- , m_soundEnabled(false)
- , m_positionSource(QGeoPositionInfoSource::createDefaultSource(this))
- , m_isPropagated(false)
-{
- if (m_positionSource) {
- connect(m_positionSource, SIGNAL(positionUpdated(const QGeoPositionInfo &)), this, SLOT(positionUpdated(const QGeoPositionInfo &)));
- connect(m_positionSource, SIGNAL(updateTimeout()), this, SLOT(positionUpdateTimeout()));
-
- log(tr("Initialized QGeoPositionInfoSource"));
- } else {
- log(tr("Failed to initialized QGeoPositionInfoSource"));
- }
-
- if (satInfo) {
- m_satelliteSource = QGeoSatelliteInfoSource::createDefaultSource(this);
-
- if (m_satelliteSource) {
- connect(m_satelliteSource, SIGNAL(satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &)), this, SLOT(satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &)));
- connect(m_satelliteSource, SIGNAL(satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &)), this, SLOT(satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &)));
-
- log(tr("Initialized QGeoSatelliteInfoSource"));
- } else {
- log(tr("Failed to initialized QGeoSatelliteInfoSource"));
- }
- }
-
- m_latitude = m_longitude = m_altitude = m_direction = m_horizontalAccuracy = m_verticalAccuracy = m_magneticVariation = tr("--");
- m_time = tr("-/-/- -:-");
- m_groundSpeed = tr("-- km/h");
- m_verticalSpeed = tr("-- km/h");
- m_satellitesInUse = m_satellitesInView = tr("No satellite information available");
+LocationSession::LocationSession(QObject* parent, bool satInfo, MapView *map) :
+ QObject(parent), m_soundEnabled(false), m_positionSource(QGeoPositionInfoSource::createDefaultSource(this)), m_isPropagated(false) {
+
+ setMapView(map);
+
+ // Long pressing on the mapview will drop a push pin. This triggers
+ MapLongPressToPinDrop *longPressAction = new MapLongPressToPinDrop(map);
+ bool connected = connect(longPressAction, SIGNAL(pinCreated(const QString&)), this, SLOT(onPinCreated(const QString&)));
+
+
+ if (m_positionSource) {
+ connect(m_positionSource, SIGNAL(positionUpdated(const QGeoPositionInfo &)), this, SLOT(positionUpdated(const QGeoPositionInfo &)));
+ connect(m_positionSource, SIGNAL(updateTimeout()), this, SLOT(positionUpdateTimeout()));
+
+ log(tr("Initialized QGeoPositionInfoSource"));
+ } else {
+ log(tr("Failed to initialized QGeoPositionInfoSource"));
+ }
+
+ if (satInfo) {
+ m_satelliteSource = QGeoSatelliteInfoSource::createDefaultSource(this);
+
+ if (m_satelliteSource) {
+ connect(m_satelliteSource, SIGNAL(satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &)), this, SLOT(satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &)));
+ connect(m_satelliteSource, SIGNAL(satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &)), this, SLOT(satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &)));
+
+ log(tr("Initialized QGeoSatelliteInfoSource"));
+ } else {
+ log(tr("Failed to initialized QGeoSatelliteInfoSource"));
+ }
+ }
+
+ m_direction = m_horizontalAccuracy = m_verticalAccuracy = m_magneticVariation = tr("--");
+ m_time = tr("-/-/- -:-");
+ m_groundSpeed = tr("-- km/h");
+ m_verticalSpeed = tr("-- km/h");
+ m_satellitesInUse = m_satellitesInView = tr("No satellite information available");
}
//! [0]
//! [1]
-void LocationSession::startUpdates()
-{
- if (m_positionSource) {
- m_positionSource->startUpdates();
- log(tr("Position updates started"));
- }
-
- if (m_satelliteSource) {
- m_satelliteSource->startUpdates();
- log(tr("Satellite updates started"));
- }
+void LocationSession::startUpdates() {
+ if (m_positionSource) {
+ m_positionSource->startUpdates();
+ log(tr("Position updates started"));
+ }
+
+ if (m_satelliteSource) {
+ m_satelliteSource->startUpdates();
+ log(tr("Satellite updates started"));
+ }
}
//! [1]
//! [2]
-void LocationSession::requestUpdate()
-{
- if (m_positionSource) {
- m_positionSource->requestUpdate(120000);
- log(tr("Update requested"));
- }
+void LocationSession::requestUpdate() {
+ if (m_positionSource) {
+ m_positionSource->requestUpdate(120000);
+ log(tr("Update requested"));
+ }
}
//! [2]
//! [3]
-void LocationSession::stopUpdates()
-{
- if (m_positionSource) {
- m_positionSource->stopUpdates();
- log(tr("Position updates stopped"));
- }
+void LocationSession::stopUpdates() {
+ if (m_positionSource) {
+ m_positionSource->stopUpdates();
+ log(tr("Position updates stopped"));
+ }
- if (m_satelliteSource) {
- m_satelliteSource->stopUpdates();
- log(tr("Satellite updates stopped"));
- }
+ if (m_satelliteSource) {
+ m_satelliteSource->stopUpdates();
+ log(tr("Satellite updates stopped"));
+ }
- deleteLater();
+ deleteLater();
}
//! [3]
//! [4]
-void LocationSession::resetSession(const QString &type)
-{
- if (m_soundEnabled)
- SystemSound::play(SystemSound::GeneralNotification);
-
- if (m_positionSource) {
- m_positionSource->stopUpdates();
- m_positionSource->setProperty("reset", type);
- m_positionSource->startUpdates();
- log(tr("%1 RESET").arg(type));
- }
+void LocationSession::resetSession(const QString &type) {
+ if (m_soundEnabled)
+ SystemSound::play(SystemSound::GeneralNotification);
+
+ if (m_positionSource) {
+ m_positionSource->stopUpdates();
+ m_positionSource->setProperty("reset", type);
+ m_positionSource->startUpdates();
+ log(tr("%1 RESET").arg(type));
+ }
}
//! [4]
//! [5]
-void LocationSession::positionUpdated(const QGeoPositionInfo& pos)
-{
- if (m_soundEnabled)
- SystemSound::play(SystemSound::GeneralNotification);
+void LocationSession::positionUpdated(const QGeoPositionInfo& pos) {
+ if (m_soundEnabled)
+ SystemSound::play(SystemSound::GeneralNotification);
+
+ m_latitude = pos.coordinate().latitude();
+ m_longitude = pos.coordinate().longitude();
+ m_altitude = pos.coordinate().altitude();
+ m_time = pos.timestamp().toString();
+ m_direction = QString::number(pos.attribute(QGeoPositionInfo::Direction));
+ m_groundSpeed = QString::number(pos.attribute(QGeoPositionInfo::GroundSpeed));
+ m_verticalSpeed = QString::number(pos.attribute(QGeoPositionInfo::VerticalSpeed));
+ m_horizontalAccuracy = QString::number(pos.attribute(QGeoPositionInfo::HorizontalAccuracy));
+ m_verticalAccuracy = QString::number(pos.attribute(QGeoPositionInfo::VerticalAccuracy));
+ m_magneticVariation = QString::number(pos.attribute(QGeoPositionInfo::MagneticVariation));
+
+ parseRawData();
- m_latitude = QString::number(pos.coordinate().latitude());
- m_longitude = QString::number(pos.coordinate().longitude());
- m_altitude = QString::number(pos.coordinate().altitude());
- m_time = pos.timestamp().toString();
- m_direction = QString::number(pos.attribute(QGeoPositionInfo::Direction));
- m_groundSpeed = QString::number(pos.attribute(QGeoPositionInfo::GroundSpeed));
- m_verticalSpeed = QString::number(pos.attribute(QGeoPositionInfo::VerticalSpeed));
- m_horizontalAccuracy = QString::number(pos.attribute(QGeoPositionInfo::HorizontalAccuracy));
- m_verticalAccuracy = QString::number(pos.attribute(QGeoPositionInfo::VerticalAccuracy));
- m_magneticVariation = QString::number(pos.attribute(QGeoPositionInfo::MagneticVariation));
+ emit dataChanged();
- parseRawData();
+ Geographic *myGeo = mapView->mapData()->geographic("myLocation");
+ GeoLocation *myLocation = NULL;
+ if(myGeo != NULL){
+ myLocation = qobject_cast<GeoLocation*>(myGeo);
+ }
- emit dataChanged();
+ if(myLocation == NULL){
+ myLocation = new GeoLocation("myLocation");
+ mapView->mapData()->add(myLocation);
+ }
- log(tr("update"));
+
+
+ myLocation->setLatitude(latitude());
+ myLocation->setLongitude(longitude());
+ myLocation->setName("You're here!");
+ myLocation->setDescription(QString::number(latitude()) + ", " + QString::number(longitude()));
+ mapView->setFocusedId(myLocation->id());
+ mapView->setLocationOnFocused();
+
+ log(tr("update"));
}
//! [5]
-QGeoPositionInfoSource* LocationSession::positionSource() const
-{
- return m_positionSource;
+QGeoPositionInfoSource* LocationSession::positionSource() const {
+ return m_positionSource;
+}
+
+void LocationSession::setSoundEnabled(bool enabled) {
+ m_soundEnabled = enabled;
}
-void LocationSession::setSoundEnabled(bool enabled)
-{
- m_soundEnabled = enabled;
-}
-
-void LocationSession::positionUpdateTimeout()
-{
- log(tr("positionUpdateTimeout() received"));
-}
-
-static QString satellitesToString(const QList<QGeoSatelliteInfo> &satellites)
-{
- QString text;
-
- foreach (const QGeoSatelliteInfo &info, satellites) {
- text += QObject::tr("PRN: %1\nAzimuth: %2\nElevation: %3\nSignal: %4\n")
- .arg(info.prnNumber())
- .arg(info.attribute(QGeoSatelliteInfo::Azimuth))
- .arg(info.attribute(QGeoSatelliteInfo::Elevation))
- .arg(info.signalStrength());
- }
-
- return text;
-}
-
-void LocationSession::satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &satellites)
-{
- log(tr("satellitesInUseUpdated received"));
-
- m_satellitesInUse = tr("Satellites In Use\n%1").arg(satellitesToString(satellites));
-
- emit dataChanged();
-}
-
-void LocationSession::satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &satellites)
-{
- log(tr("satellitesInViewUpdated received"));
-
- m_satellitesInView = tr("Satellites In View\n%1").arg(satellitesToString(satellites));
+void LocationSession::positionUpdateTimeout() {
+ log(tr("positionUpdateTimeout() received"));
+}
- emit dataChanged();
-}
+static QString satellitesToString(const QList<QGeoSatelliteInfo> &satellites) {
+ QString text;
-void LocationSession::parseRawData()
-{
- // Parsing the raw data from the low level Location Manager. Use this only if a field is not accessible via QGeoPositionInfo above.
- const QVariant replyData = (m_positionSource ? m_positionSource->property("replyDat") : QVariant());
+ foreach (const QGeoSatelliteInfo &info, satellites){
+ text += QObject::tr("PRN: %1\nAzimuth: %2\nElevation: %3\nSignal: %4\n")
+ .arg(info.prnNumber())
+ .arg(info.attribute(QGeoSatelliteInfo::Azimuth))
+ .arg(info.attribute(QGeoSatelliteInfo::Elevation))
+ .arg(info.signalStrength());
+}
- if (!replyData.isValid()) {
- log(tr("!!! Invalid replyDat."));
- }
+ return text;
+}
- RawLocationParser parser(replyData);
+void LocationSession::satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &satellites) {
+ log(tr("satellitesInUseUpdated received"));
- m_method = parser.positionMethod();
- m_horizontalDilution = QString::number(parser.hdop());
- m_verticalDilution = QString::number(parser.vdop());
- m_positionDilution = QString::number(parser.pdop());
- m_ttff = QString::number(parser.ttff());
- m_gpsWeek = QString::number(parser.gpsWeek());
- m_gpsTimeOfWeek = QString::number(parser.gpsTow());
- m_isPropagated = parser.propagated();
+ m_satellitesInUse = tr("Satellites In Use\n%1").arg(satellitesToString(satellites));
- const double latitude = parser.latitude();
- const double longitude = parser.longitude();
- const double altitude = parser.altitude();
- const double hAccuracy = parser.horizontalAccuracy();
- const double vAccuracy = parser.verticalAccuracy();
- const double heading = parser.heading();
- const double speed = parser.speed();
- const double utc = parser.utc();
+ emit dataChanged();
+}
+
+void LocationSession::satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &satellites) {
+ log(tr("satellitesInViewUpdated received"));
+
+ m_satellitesInView = tr("Satellites In View\n%1").arg(satellitesToString(satellites));
+
+ emit dataChanged();
+}
- log(tr("Method: %0, Latitude: %1, Longitude: %2, Altitude: %3, Horizontal Accuracy: %4, Vertical Accuracy: %5, Heading: %6, Speed: %7, TTFF: %8, GPS Week: %9, ")
- .arg(m_method)
- .arg(latitude)
- .arg(longitude)
- .arg(altitude)
- .arg(hAccuracy)
- .arg(vAccuracy)
- .arg(heading)
- .arg(speed)
- .arg(m_ttff)
- .arg(m_gpsWeek) +
- tr("GPS TOW: %0, UTC: %1, Horizontal Dilution: %2, Vertical Dilution: %3, Positional Dilution: %4, Propagated: %5")
- .arg(m_gpsTimeOfWeek)
- .arg(utc)
- .arg(m_horizontalDilution)
- .arg(m_verticalDilution)
- .arg(m_positionDilution)
- .arg(m_isPropagated ? tr("true") : tr("false"))
- , false);
+void LocationSession::parseRawData() {
+ // Parsing the raw data from the low level Location Manager. Use this only if a field is not accessible via QGeoPositionInfo above.
+ const QVariant replyData = (m_positionSource ? m_positionSource->property("replyDat") : QVariant());
- const QString error = parser.error();
- if (error.length() > 3) {
- log(tr("!!! [Error] %1").arg(error));
- }
+ if (!replyData.isValid()) {
+ log(tr("!!! Invalid replyDat."));
+ }
- for (int i = 0; i < parser.numberOfSatellites(); i++) {
- const double id = parser.satelliteId(i);
- const double cno = parser.satelliteCarrierToNoiseRatio(i);
- const bool ephemerisAvailable = parser.satelliteEphemerisAvailable(i);
- const double azimuth = parser.satelliteAzimuth(i);
- const double elevation = parser.satelliteElevation(i);
- const bool tracked = parser.satelliteTracked(i);
- const bool used = parser.satelliteUsed(i);
+ RawLocationParser parser(replyData);
- log(tr("\t[Satellite %0], ID: %1, CNO: %2, Ephemeris Available: %3, Azimuth: %4, Elevation: %5, Tracked: %6, Used: %7")
- .arg(i)
- .arg(id)
- .arg(cno)
- .arg(ephemerisAvailable ? tr("true") : tr("false"))
- .arg(azimuth)
- .arg(elevation)
- .arg(tracked ? tr("true") : tr("false"))
- .arg(used ? tr("true") : tr("false"))
- , false);
- }
+ m_method = parser.positionMethod();
+ m_horizontalDilution = QString::number(parser.hdop());
+ m_verticalDilution = QString::number(parser.vdop());
+ m_positionDilution = QString::number(parser.pdop());
+ m_ttff = QString::number(parser.ttff());
+ m_gpsWeek = QString::number(parser.gpsWeek());
+ m_gpsTimeOfWeek = QString::number(parser.gpsTow());
+ m_isPropagated = parser.propagated();
+
+ const double latitude = parser.latitude();
+ const double longitude = parser.longitude();
+ const double altitude = parser.altitude();
+ const double hAccuracy = parser.horizontalAccuracy();
+ const double vAccuracy = parser.verticalAccuracy();
+ const double heading = parser.heading();
+ const double speed = parser.speed();
+ const double utc = parser.utc();
+
+ log(
+ tr("Method: %0, Latitude: %1, Longitude: %2, Altitude: %3, Horizontal Accuracy: %4, Vertical Accuracy: %5, Heading: %6, Speed: %7, TTFF: %8, GPS Week: %9, ").arg(m_method).arg(latitude).arg(longitude).arg(altitude).arg(hAccuracy).arg(vAccuracy).arg(heading).arg(speed).arg(m_ttff).arg(m_gpsWeek)
+ + tr("GPS TOW: %0, UTC: %1, Horizontal Dilution: %2, Vertical Dilution: %3, Positional Dilution: %4, Propagated: %5").arg(m_gpsTimeOfWeek).arg(utc).arg(m_horizontalDilution).arg(m_verticalDilution).arg(m_positionDilution).arg(m_isPropagated ? tr("true") : tr("false")), false);
+
+ const QString error = parser.error();
+ if (error.length() > 3) {
+ log(tr("!!! [Error] %1").arg(error));
+ }
+
+ for (int i = 0; i < parser.numberOfSatellites(); i++) {
+ const double id = parser.satelliteId(i);
+ const double cno = parser.satelliteCarrierToNoiseRatio(i);
+ const bool ephemerisAvailable = parser.satelliteEphemerisAvailable(i);
+ const double azimuth = parser.satelliteAzimuth(i);
+ const double elevation = parser.satelliteElevation(i);
+ const bool tracked = parser.satelliteTracked(i);
+ const bool used = parser.satelliteUsed(i);
+
+ log(tr("\t[Satellite %0], ID: %1, CNO: %2, Ephemeris Available: %3, Azimuth: %4, Elevation: %5, Tracked: %6, Used: %7").arg(i).arg(id).arg(cno).arg(ephemerisAvailable ? tr("true") : tr("false")).arg(azimuth).arg(elevation).arg(tracked ? tr("true") : tr("false")).arg(used ? tr("true") : tr("false")), false);
+ }
+}
+
+void LocationSession::log(const QString &msg, bool showInUi) {
+ std::cout << msg.toStdString() << std::endl;
+ if (showInUi) {
+ m_log += msg + QLatin1String("\n");
+ emit logChanged();
+ }
}
-void LocationSession::log(const QString &msg, bool showInUi)
-{
- std::cout << msg.toStdString() << std::endl;
+void LocationSession::setMapView(MapView *value) {
+ mapView = value;
+}
- if (showInUi) {
- m_log += msg + QLatin1String("\n");
- emit logChanged();
- }
+QString LocationSession::method() const {
+ return m_method;
}
-QString LocationSession::method() const
-{
- return m_method;
+double LocationSession::latitude() const {
+ return m_latitude;
}
-QString LocationSession::latitude() const
-{
- return m_latitude;
+double LocationSession::longitude() const {
+ return m_longitude;
}
-QString LocationSession::longitude() const
-{
- return m_longitude;
+double LocationSession::altitude() const {
+ return m_altitude;
}
-QString LocationSession::altitude() const
-{
- return m_altitude;
+QString LocationSession::time() const {
+ return m_time;
}
-QString LocationSession::time() const
-{
- return m_time;
+QString LocationSession::direction() const {
+ return m_direction;
}
-QString LocationSession::direction() const
-{
- return m_direction;
+QString LocationSession::groundSpeed() const {
+ return m_groundSpeed;
}
-QString LocationSession::groundSpeed() const
-{
- return m_groundSpeed;
+QString LocationSession::verticalSpeed() const {
+ return m_verticalSpeed;
}
-QString LocationSession::verticalSpeed() const
-{
- return m_verticalSpeed;
+QString LocationSession::horizontalAccuracy() const {
+ return m_horizontalAccuracy;
}
-QString LocationSession::horizontalAccuracy() const
-{
- return m_horizontalAccuracy;
+QString LocationSession::verticalAccuracy() const {
+ return m_verticalAccuracy;
}
-QString LocationSession::verticalAccuracy() const
-{
- return m_verticalAccuracy;
+QString LocationSession::magneticVariation() const {
+ return m_magneticVariation;
}
-QString LocationSession::magneticVariation() const
-{
- return m_magneticVariation;
+QString LocationSession::horizontalDilution() const {
+ return m_horizontalDilution;
}
-QString LocationSession::horizontalDilution() const
-{
- return m_horizontalDilution;
+QString LocationSession::verticalDilution() const {
+ return m_verticalDilution;
}
-QString LocationSession::verticalDilution() const
-{
- return m_verticalDilution;
+QString LocationSession::positionDilution() const {
+ return m_positionDilution;
}
-QString LocationSession::positionDilution() const
-{
- return m_positionDilution;
+QString LocationSession::ttff() const {
+ return m_ttff;
}
-QString LocationSession::ttff() const
-{
- return m_ttff;
+QString LocationSession::gpsWeek() const {
+ return m_gpsWeek;
}
-QString LocationSession::gpsWeek() const
-{
- return m_gpsWeek;
+QString LocationSession::gpsTimeOfWeek() const {
+ return m_gpsTimeOfWeek;
}
-QString LocationSession::gpsTimeOfWeek() const
-{
- return m_gpsTimeOfWeek;
+bool LocationSession::isPropagated() const {
+ return m_isPropagated;
}
-bool LocationSession::isPropagated() const
-{
- return m_isPropagated;
+QString LocationSession::satellitesInUse() const {
+ return m_satellitesInUse;
}
-QString LocationSession::satellitesInUse() const
-{
- return m_satellitesInUse;
+QString LocationSession::satellitesInView() const {
+ return m_satellitesInView;
}
-QString LocationSession::satellitesInView() const
-{
- return m_satellitesInView;
+void LocationSession::onPinCreated(const QString& pinID) {
+ log("pin created: " + pinID, false);
}
-QString LocationSession::log() const
-{
- return m_log;
+QString LocationSession::log() const {
+ return m_log;
}
View
37 locationdiagnostics/src/LocationSession.hpp
@@ -16,14 +16,23 @@
#ifndef LOCATIONSESSION_HPP
#define LOCATIONSESSION_HPP
+#include <QDebug>
#include <QtLocationSubset/QGeoPositionInfo>
#include <QtLocationSubset/QGeoPositionInfoSource>
#include <QtLocationSubset/QGeoSatelliteInfo>
#include <QtLocationSubset/QGeoSatelliteInfoSource>
+#include <bb/cascades/maps/MapView>
+#include <bb/cascades/maps/MapData.hpp>
+#include <bb/platform/geo/GeoLocation.hpp>
+#include <bb/cascades/maps/MapLongPressToPinDrop.hpp>
+
+
#include <QtCore/QObject>
using namespace QtMobilitySubset;
+using namespace bb::cascades::maps;
+using namespace bb::platform::geo;
/**
* @short A helper class that encapsulates the retrieval of location information.
@@ -35,9 +44,9 @@ class LocationSession: public QObject
// The properties that provide the location information to the UI
Q_PROPERTY(QString method READ method NOTIFY dataChanged)
- Q_PROPERTY(QString latitude READ latitude NOTIFY dataChanged)
- Q_PROPERTY(QString longitude READ longitude NOTIFY dataChanged)
- Q_PROPERTY(QString altitude READ altitude NOTIFY dataChanged)
+ Q_PROPERTY(double latitude READ latitude NOTIFY dataChanged)
+ Q_PROPERTY(double longitude READ longitude NOTIFY dataChanged)
+ Q_PROPERTY(double altitude READ altitude NOTIFY dataChanged)
Q_PROPERTY(QString time READ time NOTIFY dataChanged)
Q_PROPERTY(QString direction READ direction NOTIFY dataChanged)
Q_PROPERTY(QString groundSpeed READ groundSpeed NOTIFY dataChanged)
@@ -59,7 +68,7 @@ class LocationSession: public QObject
Q_PROPERTY(QString log READ log NOTIFY logChanged)
public:
- LocationSession(QObject* parent, bool satInfo);
+ LocationSession(QObject* parent, bool satInfo, MapView *map);
// This method is called to trigger the continious retrieval of location information
void startUpdates();
@@ -79,6 +88,9 @@ class LocationSession: public QObject
// This method is called to reset the internal retrieval engine
Q_INVOKABLE void resetSession(const QString &type);
+ // This mehod is called to expose the MapView created in qml to this.
+ Q_INVOKABLE void setMapView(MapView *value);
+
Q_SIGNALS:
// The change notification signals of the properties
void dataChanged();
@@ -97,6 +109,9 @@ private Q_SLOTS:
// This slot is invoked whenever new information about the in-view satellites are retrieved
void satellitesInViewUpdated(const QList<QGeoSatelliteInfo> & satellites);
+ // This slot is invoked whenever a new pin is created by long pressing on the mapView.
+ void onPinCreated(const QString& pinID);
+
private:
// A helper method to parse the raw geo information
void parseRawData();
@@ -106,9 +121,9 @@ private Q_SLOTS:
// The accessor methods of the properties
QString method() const;
- QString latitude() const;
- QString longitude() const;
- QString altitude() const;
+ double latitude() const;
+ double longitude() const;
+ double altitude() const;
QString time() const;
QString direction() const;
QString groundSpeed() const;
@@ -138,9 +153,9 @@ private Q_SLOTS:
// The property values
QString m_method;
- QString m_latitude;
- QString m_longitude;
- QString m_altitude;
+ double m_latitude;
+ double m_longitude;
+ double m_altitude;
QString m_time;
QString m_direction;
QString m_groundSpeed;
@@ -158,6 +173,8 @@ private Q_SLOTS:
QString m_satellitesInUse;
QString m_satellitesInView;
QString m_log;
+
+ MapView *mapView;
};
//! [0]

0 comments on commit 622314b

Please sign in to comment.
Something went wrong with that request. Please try again.