10#include "CurrentLocationWidget.h"
13#include "MarbleDebug.h"
14#include "MarbleLocale.h"
17#include "MarbleWidgetPopupMenu.h"
18#include "GeoDataCoordinates.h"
19#include "PositionProviderPlugin.h"
20#include "PluginManager.h"
21#include "PositionTracking.h"
22#include "routing/RoutingManager.h"
28#include "ui_CurrentLocationWidget.h"
37class CurrentLocationWidgetPrivate
40 CurrentLocationWidgetPrivate();
42 Ui::CurrentLocationWidget m_currentLocationUi;
44 AutoNavigation *m_adjustNavigation;
53 void adjustPositionTrackingStatus( PositionProviderStatus
status );
54 void changePositionProvider(
const QString &provider );
55 void trackPlacemark();
56 void centerOnCurrentLocation();
57 void updateRecenterComboBox( AutoNavigation::CenterMode centerMode );
58 void updateAutoZoomCheckBox(
bool autoZoom );
60 void updateGuidanceMode();
66CurrentLocationWidgetPrivate::CurrentLocationWidgetPrivate()
67 : m_widget( nullptr ),
68 m_adjustNavigation( nullptr ),
69 m_positionProviderPlugins(),
78 d( new CurrentLocationWidgetPrivate() )
80 d->m_currentLocationUi.
setupUi(
this );
81 layout()->setMargin( 0 );
83 connect( d->m_currentLocationUi.recenterComboBox, SIGNAL (currentIndexChanged(
int)),
84 this, SLOT(setRecenterMode(
int)) );
86 connect( d->m_currentLocationUi.autoZoomCheckBox, SIGNAL(clicked(
bool)),
87 this, SLOT(setAutoZoom(
bool)) );
89 bool const smallScreen = MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen;
90 d->m_currentLocationUi.positionTrackingComboBox->setVisible( !smallScreen );
91 d->m_currentLocationUi.locationLabel->setVisible( !smallScreen );
94CurrentLocationWidget::~CurrentLocationWidget()
99void CurrentLocationWidget::setMarbleWidget(
MarbleWidget *widget )
101 d->m_widget = widget;
103 delete d->m_adjustNavigation;
104 d->m_adjustNavigation =
new AutoNavigation( widget->
model(), widget->viewport(),
this );
109 d->m_currentLocationUi.positionTrackingComboBox->addItem( plugin->
guiString() );
111 if ( d->m_positionProviderPlugins.isEmpty() ) {
112 d->m_currentLocationUi.positionTrackingComboBox->setEnabled(
false );
113 QString html =
"<p>No Position Tracking Plugin installed.</p>";
114 d->m_currentLocationUi.locationLabel->setText( html );
115 d->m_currentLocationUi.locationLabel->setEnabled (
true );
116 bool const hasTrack = !d->m_widget->
model()->positionTracking()->isTrackEmpty();
117 d->m_currentLocationUi.showTrackCheckBox->setEnabled( hasTrack );
118 d->m_currentLocationUi.saveTrackButton->setEnabled( hasTrack );
119 d->m_currentLocationUi.clearTrackButton->setEnabled( hasTrack );
129 disconnect( d->m_currentLocationUi.positionTrackingComboBox, SIGNAL(currentIndexChanged(
QString)),
130 this, SLOT(changePositionProvider(
QString)) );
131 disconnect( d->m_currentLocationUi.locationLabel, SIGNAL(linkActivated(
QString)),
132 this, SLOT(centerOnCurrentLocation()) );
134 SIGNAL(statusChanged(PositionProviderStatus)),
this,
135 SLOT(adjustPositionTrackingStatus(PositionProviderStatus)) );
138 this, SLOT(trackPlacemark()) );
147 d->updateActivePositionProvider( d->m_widget->
model()->positionTracking()->positionProviderPlugin() );
148 connect( d->m_currentLocationUi.positionTrackingComboBox, SIGNAL(currentIndexChanged(
QString)),
149 this, SLOT(changePositionProvider(
QString)) );
150 connect( d->m_currentLocationUi.locationLabel, SIGNAL(linkActivated(
QString)),
151 this, SLOT(centerOnCurrentLocation()) );
153 SIGNAL(statusChanged(PositionProviderStatus)),
this,
154 SLOT(adjustPositionTrackingStatus(PositionProviderStatus)) );
156 connect( d->m_adjustNavigation, SIGNAL(recenterModeChanged(AutoNavigation::CenterMode)),
157 this, SLOT(updateRecenterComboBox(AutoNavigation::CenterMode)) );
158 connect( d->m_adjustNavigation, SIGNAL(autoZoomToggled(
bool)),
159 this, SLOT(updateAutoZoomCheckBox(
bool)) );
168 d->m_adjustNavigation, SLOT(inhibitAutoAdjustments()) );
169 connect( d->m_widget->
model()->routingManager(), SIGNAL(guidanceModeEnabledChanged(
bool)),
170 this, SLOT(updateGuidanceMode()) );
172 connect (d->m_currentLocationUi.showTrackCheckBox, SIGNAL(clicked(
bool)),
173 d->m_widget->
model()->positionTracking(), SLOT(setTrackVisible(
bool)));
174 connect (d->m_currentLocationUi.showTrackCheckBox, SIGNAL(clicked(
bool)),
175 d->m_widget, SLOT(
update()));
176 if ( d->m_widget->
model()->positionTracking()->trackVisible() ) {
177 d->m_currentLocationUi.showTrackCheckBox->setCheckState(
Qt::Checked);
179 connect ( d->m_currentLocationUi.saveTrackButton, SIGNAL(clicked(
bool)),
180 this, SLOT(saveTrack()));
181 connect ( d->m_currentLocationUi.openTrackButton, SIGNAL(clicked(
bool)),
182 this, SLOT(openTrack()));
183 connect (d->m_currentLocationUi.clearTrackButton, SIGNAL(clicked(
bool)),
184 this, SLOT(clearTrack()));
186 this, SLOT(trackPlacemark()) );
189void CurrentLocationWidgetPrivate::adjustPositionTrackingStatus( PositionProviderStatus
status )
191 if (
status == PositionProviderStatusAvailable ) {
195 QString html =
"<html><body><p>";
198 case PositionProviderStatusUnavailable:
201 case PositionProviderStatusAcquiring:
202 html +=
QObject::tr(
"Waiting for current location information..." );
204 case PositionProviderStatusAvailable:
207 case PositionProviderStatusError:
208 html +=
QObject::tr(
"Error when determining current location: " );
209 html += m_widget->
model()->positionTracking()->error();
214 m_currentLocationUi.locationLabel->setEnabled(
true );
215 m_currentLocationUi.locationLabel->setText( html );
220 m_currentLocationUi.positionTrackingComboBox->blockSignals(
true );
222 m_currentLocationUi.positionTrackingComboBox->setCurrentIndex( 0 );
224 for(
int i=0; i<m_currentLocationUi.positionTrackingComboBox->count(); ++i ) {
225 if ( m_currentLocationUi.positionTrackingComboBox->itemText( i ) == plugin->
guiString() ) {
226 m_currentLocationUi.positionTrackingComboBox->setCurrentIndex( i );
231 m_currentLocationUi.positionTrackingComboBox->blockSignals(
false );
232 m_currentLocationUi.recenterLabel->setEnabled( plugin );
233 m_currentLocationUi.recenterComboBox->setEnabled( plugin );
234 m_currentLocationUi.autoZoomCheckBox->setEnabled( plugin );
238void CurrentLocationWidgetPrivate::updateGuidanceMode()
240 const bool enabled = m_widget->
model()->routingManager()->guidanceModeEnabled();
242 m_adjustNavigation->setAutoZoom( enabled );
243 m_adjustNavigation->setRecenter( enabled ? AutoNavigation::RecenterOnBorder : AutoNavigation::DontRecenter );
246void CurrentLocationWidgetPrivate::receiveGpsCoordinates(
const GeoDataCoordinates &position, qreal speed )
248 m_currentPosition = position;
252 qreal unitSpeed = 0.0;
253 qreal altitude = 0.0;
254 qreal length = m_widget->
model()->positionTracking()->length( m_widget->
model()->planetRadius() );
257 "<table cellspacing=\"2\" cellpadding=\"2\">"
258 "<tr><td>Longitude</td><td><a href=\"https://edu.kde.org/marble\">%1</a></td></tr>"
259 "<tr><td>Latitude</td><td><a href=\"https://edu.kde.org/marble\">%2</a></td></tr>"
260 "<tr><td>Altitude</td><td>%3</td></tr>"
261 "<tr><td>Speed</td><td>%4</td></tr>"
262 "<tr><td>Distance</td><td>%5</td></tr>"
266 switch ( MarbleGlobal::getInstance()->locale()->measurementSystem() ) {
267 case MarbleLocale::MetricSystem:
270 unitSpeed = speed * HOUR2SEC * METER2KM;
273 if ( length > 1000.0 ) {
279 case MarbleLocale::ImperialSystem:
282 unitSpeed = speed * HOUR2SEC * METER2KM * KM2MI;
285 altitude = position.
altitude() * M2FT;
289 case MarbleLocale::NauticalSystem:
292 unitSpeed = speed * HOUR2SEC * METER2KM * KM2NM;
296 length *= METER2KM*KM2NM;
305 html = html.
arg(altitudeString, speedString +
QLatin1Char(
' ') + unitString);
306 html = html.
arg( distanceString );
307 m_currentLocationUi.locationLabel->setText( html );
308 m_currentLocationUi.showTrackCheckBox->setEnabled(
true );
309 m_currentLocationUi.saveTrackButton->setEnabled(
true );
310 m_currentLocationUi.clearTrackButton->setEnabled(
true );
313void CurrentLocationWidgetPrivate::changePositionProvider(
const QString &provider )
317 m_currentLocationUi.locationLabel->setEnabled(
true );
319 PositionTracking *tracking = m_widget->
model()->positionTracking();
320 tracking->setPositionProviderPlugin( instance );
327 m_currentLocationUi.locationLabel->setEnabled(
false );
328 m_widget->
model()->positionTracking()->setPositionProviderPlugin(
nullptr );
332void CurrentLocationWidgetPrivate::trackPlacemark()
334 changePositionProvider(
QObject::tr(
"Placemark" ) );
335 m_adjustNavigation->setRecenter( AutoNavigation::AlwaysRecenter );
338void CurrentLocationWidget::setRecenterMode(
int mode )
340 if ( mode >= 0 && mode <= AutoNavigation::RecenterOnBorder ) {
341 AutoNavigation::CenterMode centerMode = ( AutoNavigation::CenterMode ) mode;
342 d->m_adjustNavigation->setRecenter( centerMode );
346void CurrentLocationWidget::setAutoZoom(
bool autoZoom )
348 d->m_adjustNavigation->setAutoZoom( autoZoom );
351void CurrentLocationWidgetPrivate::updateAutoZoomCheckBox(
bool autoZoom )
353 m_currentLocationUi.autoZoomCheckBox->setChecked( autoZoom );
356void CurrentLocationWidgetPrivate::updateRecenterComboBox( AutoNavigation::CenterMode centerMode )
358 m_currentLocationUi.recenterComboBox->setCurrentIndex( centerMode );
361void CurrentLocationWidgetPrivate::centerOnCurrentLocation()
363 m_widget->
centerOn(m_currentPosition,
true);
366void CurrentLocationWidgetPrivate::saveTrack()
368 QString suggested = m_lastSavePath;
379 m_lastSavePath = file.absolutePath();
380 m_widget->
model()->positionTracking()->saveTrack( fileName );
383void CurrentLocationWidgetPrivate::openTrack()
385 QString suggested = m_lastOpenPath;
390 m_lastOpenPath = file.absolutePath();
395void CurrentLocationWidgetPrivate::clearTrack()
399 QObject::tr(
"Are you sure you want to clear the current track?" ),
404 m_widget->
model()->positionTracking()->clearTrack();
406 m_currentLocationUi.saveTrackButton->setEnabled(
false );
407 m_currentLocationUi.clearTrackButton->setEnabled(
false );
411AutoNavigation::CenterMode CurrentLocationWidget::recenterMode()
const
413 return d->m_adjustNavigation->recenterMode();
416bool CurrentLocationWidget::autoZoom()
const
418 return d->m_adjustNavigation->autoZoom();
421bool CurrentLocationWidget::trackVisible()
const
423 return d->m_widget->
model()->positionTracking()->trackVisible();
426QString CurrentLocationWidget::lastOpenPath()
const
428 return d->m_lastOpenPath;
431QString CurrentLocationWidget::lastSavePath()
const
433 return d->m_lastSavePath;
436void CurrentLocationWidget::setTrackVisible(
bool visible )
438 d->m_currentLocationUi.showTrackCheckBox->setChecked(
visible );
439 d->m_widget->
model()->positionTracking()->setTrackVisible(
visible );
442void CurrentLocationWidget::setLastOpenPath(
const QString &path )
444 d->m_lastOpenPath =
path;
447void CurrentLocationWidget::setLastSavePath(
const QString &path )
449 d->m_lastSavePath =
path;
454#include "moc_CurrentLocationWidget.cpp"
This file contains the headers for MarbleModel.
A 3d point representation.
static QString latToString(qreal lat, GeoDataCoordinates::Notation notation, GeoDataCoordinates::Unit unit=Radian, int precision=-1, char format='f')
qreal altitude() const
return the altitude of the Point in meters
static QString lonToString(qreal lon, GeoDataCoordinates::Notation notation, GeoDataCoordinates::Unit unit=Radian, int precision=-1, char format='f')
A class that defines a 3D bounding box for geographic data.
a class representing a point of interest on the map
void addGeoDataFile(const QString &filename)
Handle file loading into the treeModel.
The class that handles Marble's plugins.
QList< const PositionProviderPlugin * > positionProviderPlugins() const
Returns all available PositionProviderPlugins.
The abstract class that provides position information.
virtual QString guiString() const =0
Returns the string that should appear in the user interface.
virtual PositionProviderPlugin * newInstance() const =0
Create a new PositionProvider Plugin and return it.
Q_SCRIPTABLE CaptureState status()
char * toString(const EngineQuery &query)
QString path(const QString &relativePath)
QAction * zoomIn(const QObject *recvr, const char *slot, QObject *parent)
QAction * zoomOut(const QObject *recvr, const char *slot, QObject *parent)
Binds a QML item to a specific geodetic location in screen coordinates.
FlyToMode
Describes possible flight mode (interpolation between source and target camera positions)
QDateTime currentDateTime()
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, Options options)
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, Options options)
QString toString(QDate date, FormatType format) const const
StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons, StandardButton defaultButton)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
QString tr(const char *sourceText, const char *disambiguation, int n)
QString & append(QChar ch)
QString arg(Args &&... args) const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)