summaryrefslogtreecommitdiffstats
path: root/qt-ui/globe.cpp
blob: a8fb886d8b75702e1d305cba7316fa9601cf9752 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "globe.h"
#include "../dive.h"

#include <QDebug>

#include <marble/AbstractFloatItem.h>
#include <marble/GeoDataPlacemark.h>
#include <marble/GeoDataDocument.h>
#include <marble/MarbleModel.h>
#include <marble/GeoDataTreeModel.h>

using namespace Marble;

GlobeGPS::GlobeGPS(QWidget* parent) : MarbleWidget(parent), loadedDives(0)
{
	setMapThemeId("earth/bluemarble/bluemarble.dgml");
	setProjection( Marble::Spherical );

	setAnimationsEnabled(true);
	setShowClouds( false );
	setShowBorders( false );
	setShowPlaces( false );
	setShowCrosshairs( false );
	setShowGrid( false );
	setShowOverviewMap(false);
	setShowScaleBar(false);

	Q_FOREACH( AbstractFloatItem * floatItem, floatItems() ){
		if ( floatItem && floatItem->nameId() == "compass" ) {
			floatItem->setPosition( QPoint( 10, 10 ) );
			floatItem->setContentSize( QSize( 50, 50 ) );
		}
	}

}

void GlobeGPS::reload()
{
	if (loadedDives){
		model()->treeModel()->removeDocument(loadedDives);
		delete loadedDives;
	}


	loadedDives = new GeoDataDocument;

	int idx = 0;
	struct dive *dive;
	for_each_dive(idx, dive) {
		if (dive_has_gps_location(dive)) {
			// don't add dive locations twice.
			if( diveLocations.contains( QString(dive->location)))
				continue;

			GeoDataPlacemark *place = new GeoDataPlacemark( dive->location );
			place->setCoordinate(dive->longitude.udeg / 1000000.0,dive->latitude.udeg / 1000000.0 , 0, GeoDataCoordinates::Degree );
			loadedDives->append( place );
		}
	}
	model()->treeModel()->addDocument( loadedDives );
}

void GlobeGPS::centerOn(dive* dive)
{
	centerOn(dive->longitude.udeg / 1000000.0,dive->latitude.udeg / 1000000.0, true);
}