30 using namespace Marble;
34 #include "ui_CurrentLocationWidget.h"
37 #include <QFileDialog>
38 #include <QMessageBox>
43 class CurrentLocationWidgetPrivate
46 CurrentLocationWidgetPrivate();
48 Ui::CurrentLocationWidget m_currentLocationUi;
52 QList<const PositionProviderPlugin*> m_positionProviderPlugins;
55 QString m_lastOpenPath;
56 QString m_lastSavePath;
60 void changePositionProvider(
const QString &provider );
61 void trackPlacemark();
62 void centerOnCurrentLocation();
64 void updateAutoZoomCheckBox(
bool autoZoom );
71 CurrentLocationWidgetPrivate::CurrentLocationWidgetPrivate()
73 m_adjustNavigation( 0 ),
74 m_positionProviderPlugins(),
83 d( new CurrentLocationWidgetPrivate() )
85 d->m_currentLocationUi.setupUi(
this );
86 layout()->setMargin( 0 );
88 connect( d->m_currentLocationUi.recenterComboBox, SIGNAL (currentIndexChanged(
int)),
91 connect( d->m_currentLocationUi.autoZoomCheckBox, SIGNAL(clicked(
bool)),
95 d->m_currentLocationUi.positionTrackingComboBox->setVisible( !smallScreen );
96 d->m_currentLocationUi.locationLabel->setVisible( !smallScreen );
106 d->m_widget = widget;
109 d->m_widget->model()->routingManager()->setAutoNavigation( d->m_adjustNavigation );
111 const PluginManager* pluginManager = d->m_widget->model()->pluginManager();
114 d->m_currentLocationUi.positionTrackingComboBox->addItem( plugin->
guiString() );
116 if ( d->m_positionProviderPlugins.isEmpty() ) {
117 d->m_currentLocationUi.positionTrackingComboBox->setEnabled(
false );
118 QString html =
"<p>No Position Tracking Plugin installed.</p>";
119 d->m_currentLocationUi.locationLabel->setText( html );
120 d->m_currentLocationUi.locationLabel->setEnabled (
true );
121 bool const hasTrack = !d->m_widget->model()->positionTracking()->isTrackEmpty();
122 d->m_currentLocationUi.showTrackCheckBox->setEnabled( hasTrack );
123 d->m_currentLocationUi.saveTrackButton->setEnabled( hasTrack );
124 d->m_currentLocationUi.clearTrackButton->setEnabled( hasTrack );
128 disconnect( d->m_widget->model()->positionTracking(),
131 disconnect( d->m_widget->model()->positionTracking(),
134 disconnect( d->m_currentLocationUi.positionTrackingComboBox, SIGNAL(currentIndexChanged(QString)),
135 this, SLOT(changePositionProvider(QString)) );
136 disconnect( d->m_currentLocationUi.locationLabel, SIGNAL(linkActivated(QString)),
137 this, SLOT(centerOnCurrentLocation()) );
138 disconnect( d->m_widget->model()->positionTracking(),
144 disconnect( d->m_adjustNavigation, SIGNAL(autoZoomToggled(
bool)),
145 this, SLOT(updateAutoZoomCheckBox(
bool)) );
146 disconnect( d->m_widget->model(), SIGNAL(trackedPlacemarkChanged(
const GeoDataPlacemark*)),
147 this, SLOT(trackPlacemark()) );
150 connect( d->m_widget->model()->positionTracking(),
153 connect( d->m_widget->model()->positionTracking(),
156 d->updateActivePositionProvider( d->m_widget->model()->positionTracking()->positionProviderPlugin() );
157 connect( d->m_currentLocationUi.positionTrackingComboBox, SIGNAL(currentIndexChanged(QString)),
158 this, SLOT(changePositionProvider(QString)) );
159 connect( d->m_currentLocationUi.locationLabel, SIGNAL(linkActivated(QString)),
160 this, SLOT(centerOnCurrentLocation()) );
161 connect( d->m_widget->model()->positionTracking(),
167 connect( d->m_adjustNavigation, SIGNAL(autoZoomToggled(
bool)),
168 this, SLOT(updateAutoZoomCheckBox(
bool)) );
169 connect( d->m_adjustNavigation, SIGNAL(zoomIn(
FlyToMode)),
171 connect( d->m_adjustNavigation, SIGNAL(zoomOut(
FlyToMode)),
177 d->m_adjustNavigation, SLOT(inhibitAutoAdjustments()) );
179 connect (d->m_currentLocationUi.showTrackCheckBox, SIGNAL(clicked(
bool)),
180 d->m_widget->model()->positionTracking(), SLOT(
setTrackVisible(
bool)));
181 connect (d->m_currentLocationUi.showTrackCheckBox, SIGNAL(clicked(
bool)),
182 d->m_widget, SLOT(update()));
183 if ( d->m_widget->model()->positionTracking()->trackVisible() ) {
184 d->m_currentLocationUi.showTrackCheckBox->setCheckState(Qt::Checked);
186 connect ( d->m_currentLocationUi.saveTrackButton, SIGNAL(clicked(
bool)),
187 this, SLOT(saveTrack()));
188 connect ( d->m_currentLocationUi.openTrackButton, SIGNAL(clicked(
bool)),
189 this, SLOT(openTrack()));
190 connect (d->m_currentLocationUi.clearTrackButton, SIGNAL(clicked(
bool)),
191 this, SLOT(clearTrack()));
192 connect( d->m_widget->model(), SIGNAL(trackedPlacemarkChanged(
const GeoDataPlacemark*)),
193 this, SLOT(trackPlacemark()) );
202 QString html =
"<html><body><p>";
206 html += QObject::tr(
"Waiting for current location information..." );
209 html += QObject::tr(
"Initializing current location service..." );
215 html += QObject::tr(
"Error when determining current location: " );
216 html += m_widget->model()->positionTracking()->error();
220 html +=
"</p></body></html>";
221 m_currentLocationUi.locationLabel->setEnabled(
true );
222 m_currentLocationUi.locationLabel->setText( html );
227 m_currentLocationUi.positionTrackingComboBox->blockSignals(
true );
229 m_currentLocationUi.positionTrackingComboBox->setCurrentIndex( 0 );
231 for(
int i=0; i<m_currentLocationUi.positionTrackingComboBox->count(); ++i ) {
232 if ( m_currentLocationUi.positionTrackingComboBox->itemText( i ) == plugin->
guiString() ) {
233 m_currentLocationUi.positionTrackingComboBox->setCurrentIndex( i );
238 m_currentLocationUi.positionTrackingComboBox->blockSignals(
false );
239 m_currentLocationUi.recenterLabel->setEnabled( plugin );
240 m_currentLocationUi.recenterComboBox->setEnabled( plugin );
241 m_currentLocationUi.autoZoomCheckBox->setEnabled( plugin );
245 void CurrentLocationWidgetPrivate::receiveGpsCoordinates(
const GeoDataCoordinates &position, qreal speed )
249 QString altitudeUnitString;
250 QString distanceUnitString;
251 qreal unitSpeed = 0.0;
252 qreal altitude = 0.0;
253 qreal length = m_widget->model()->positionTracking()->length( m_widget->model()->planetRadius() );
255 QString html =
"<html><body>";
256 html +=
"<table cellspacing=\"2\" cellpadding=\"2\">";
257 html +=
"<tr><td>Longitude</td><td><a href=\"http://edu.kde.org/marble\">%1</a></td></tr>";
258 html +=
"<tr><td>Latitude</td><td><a href=\"http://edu.kde.org/marble\">%2</a></td></tr>";
259 html +=
"<tr><td>Altitude</td><td>%3</td></tr>";
260 html +=
"<tr><td>Speed</td><td>%4</td></tr>";
261 html +=
"<tr><td>Distance</td><td>%5</td></tr>";
263 html +=
"</body></html>";
266 case QLocale::MetricSystem:
268 unitString = QObject::tr(
"km/h");
270 altitudeUnitString = QObject::tr(
"m");
271 distanceUnitString = QObject::tr(
"m");
272 if ( length > 1000.0 ) {
274 distanceUnitString = QObject::tr(
"km");
279 case QLocale::ImperialSystem:
281 unitString = QObject::tr(
"m/h");
283 altitudeUnitString = QObject::tr(
"ft");
284 distanceUnitString = QObject::tr(
"ft");
290 const QString speedString = QLocale::system().toString( unitSpeed,
'f', 1);
291 const QString altitudeString = QString(
"%1 %2" ).arg( altitude, 0,
'f', 1, QChar(
' ') ).arg( altitudeUnitString );
292 const QString distanceString = QString(
"%1 %2" ).arg( length, 0,
'f', 1, QChar(
' ') ).arg( distanceUnitString );
295 html = html.arg( altitudeString ).arg( speedString +
' ' + unitString );
296 html = html.arg( distanceString );
297 m_currentLocationUi.locationLabel->setText( html );
298 m_currentLocationUi.showTrackCheckBox->setEnabled(
true );
299 m_currentLocationUi.saveTrackButton->setEnabled(
true );
300 m_currentLocationUi.clearTrackButton->setEnabled(
true );
303 void CurrentLocationWidgetPrivate::changePositionProvider(
const QString &provider )
305 bool hasProvider = ( provider != QObject::tr(
"Disabled") );
310 m_currentLocationUi.locationLabel->setEnabled(
true );
321 m_currentLocationUi.locationLabel->setEnabled(
false );
322 m_widget->model()->positionTracking()->setPositionProviderPlugin( 0 );
327 void CurrentLocationWidgetPrivate::trackPlacemark()
329 changePositionProvider(
"Placemark" );
337 d->m_adjustNavigation->setRecenter( centerMode );
343 d->m_adjustNavigation->setAutoZoom( autoZoom );
346 void CurrentLocationWidgetPrivate::updateAutoZoomCheckBox(
bool autoZoom )
348 m_currentLocationUi.autoZoomCheckBox->setChecked( autoZoom );
353 m_currentLocationUi.recenterComboBox->setCurrentIndex( centerMode );
356 void CurrentLocationWidgetPrivate::centerOnCurrentLocation()
361 void CurrentLocationWidgetPrivate::saveTrack()
363 QString suggested = m_lastSavePath;
364 QString fileName = QFileDialog::getSaveFileName(m_widget, QObject::tr(
"Save Track"),
365 suggested.append(
'/' + QDateTime::currentDateTime().toString(
"yyyy-MM-dd_hhmmss") +
".kml"),
366 QObject::tr(
"KML File (*.kml)"));
367 if ( fileName.isEmpty() ) {
370 if ( !fileName.endsWith(QLatin1String(
".kml" ), Qt::CaseInsensitive) ) {
371 fileName.append(
".kml" );
373 QFileInfo file( fileName );
374 m_lastSavePath = file.absolutePath();
375 m_widget->model()->positionTracking()->saveTrack( fileName );
378 void CurrentLocationWidgetPrivate::openTrack()
380 QString suggested = m_lastOpenPath;
381 QString fileName = QFileDialog::getOpenFileName( m_widget, QObject::tr(
"Open Track"),
382 suggested, QObject::tr(
"KML File (*.kml)"));
383 if ( !fileName.isEmpty() ) {
384 QFileInfo file( fileName );
385 m_lastOpenPath = file.absolutePath();
386 m_widget->model()->addGeoDataFile( fileName );
390 void CurrentLocationWidgetPrivate::clearTrack()
392 const int result = QMessageBox::question( m_widget,
393 QObject::tr(
"Clear current track" ),
394 QObject::tr(
"Are you sure you want to clear the current track?" ),
398 if ( result == QMessageBox::Yes ) {
399 m_widget->model()->positionTracking()->clearTrack();
401 m_currentLocationUi.saveTrackButton->setEnabled(
false );
402 m_currentLocationUi.clearTrackButton->setEnabled(
false );
408 return d->m_adjustNavigation->recenterMode();
413 return d->m_adjustNavigation->autoZoom();
418 return d->m_widget->model()->positionTracking()->trackVisible();
423 return d->m_lastOpenPath;
428 return d->m_lastSavePath;
433 d->m_currentLocationUi.showTrackCheckBox->setChecked( visible );
434 d->m_widget->model()->positionTracking()->setTrackVisible( visible );
439 d->m_lastOpenPath = path;
444 d->m_lastSavePath = path;
449 #include "CurrentLocationWidget.moc"
A 3d point representation.
GeoDataCoordinates m_currentPosition
static QString lonToString(qreal lon, GeoDataCoordinates::Notation notation, GeoDataCoordinates::Unit unit=Radian, int precision=-1, char format= 'f')
Enum Value AlwaysRecenter.
The class that handles Marble's plugins.
QLocale::MeasurementSystem measurementSystem() const
This file contains the headers for MarbleModel.
QList< const PositionProviderPlugin * > positionProviderPlugins() const
Returns all available PositionProviderPlugins.
Enum Value RecenterOnBorder.
The abstract class that provides position information.
qreal altitude() const
return the altitude of the Point in meters
void setMarbleModel(const MarbleModel *)
MarbleLocale * locale() const
static MarbleGlobal * getInstance()
FlyToMode
Describes possible flight mode (interpolation between source and target camera positions) ...
static QString latToString(qreal lat, GeoDataCoordinates::Notation notation, GeoDataCoordinates::Unit unit=Radian, int precision=-1, char format= 'f')
Profiles profiles() const
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.
void setPositionProviderPlugin(PositionProviderPlugin *plugin)
Change the position provider to use.
CenterMode
An enum type Represents which recentering method is selected.
a class representing a point of interest on the map
A class that defines a 3D bounding box for geographic data.