-
Notifications
You must be signed in to change notification settings - Fork 0
/
landmarkmanager.cpp
85 lines (68 loc) · 1.95 KB
/
landmarkmanager.cpp
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "landmarkmanager.h"
#include <qlandmarkmanager.h>
#include <qlandmark.h>
#include <qlandmarkid.h>
#include <qgeocoordinate.h>
#include <qlandmarkcategory.h>
#include <QObject>
#include <QString>
#include <QStringList>
#include <QDebug>
#include <QList>
QTM_USE_NAMESPACE
LandmarkManager::LandmarkManager (QObject *parent)
: QObject(parent)
, m_manager(0)
{
}
LandmarkManager::~LandmarkManager()
{
}
void LandmarkManager::init()
{
m_manager = new QLandmarkManager;
connect(m_manager, SIGNAL(landmarksAdded(const QList<QLandmarkId> &)), this,
SLOT(onLandmarksAdded(const QList<QLandmarkId> &)));
QList<QLandmarkCategory> categories = m_manager->categories();
foreach(QLandmarkCategory category, categories) {
if (category.name() == "Geographical area")
m_categoryId = category.categoryId();
}
}
void LandmarkManager::saveLandmark(double latitude, double longitude, QString name)
{
if (!m_manager)
return;
QGeoCoordinate coordinate;
coordinate.setLatitude(latitude);
coordinate.setLongitude(longitude);
QLandmark *landmark = new QLandmark;
landmark->addCategoryId(m_categoryId);
landmark->setName(name);
landmark->setCoordinate(coordinate);
landmark->setRadius(100);
bool result = m_manager->saveLandmark(landmark);
}
void LandmarkManager::landmarks()
{
if (!m_manager)
return;
QList<QLandmarkId> landmarkIds = m_manager->landmarkIds();
QList<QLandmark> landmarks = m_manager->landmarks(landmarkIds);
}
bool LandmarkManager::cleanLandmarks()
{
bool result = false;
if (!m_manager)
return result;
QList<QLandmark> lms = m_manager->landmarks();
if (lms.count() > 0)
result = m_manager->removeLandmarks(lms);
return result;
}
void LandmarkManager::onLandmarksAdded(const QList<QLandmarkId> &landmarkIds)
{
foreach(QLandmarkId id, landmarkIds)
qDebug() << " ID: " << id.localId();
landmarks();
}