-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmapwidget.cpp
More file actions
197 lines (172 loc) · 7.03 KB
/
mapwidget.cpp
File metadata and controls
197 lines (172 loc) · 7.03 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#include "mapwidget.h"
//#include "utils.h"
#include <QAction>
//#include "mainwindow.h"
#include <QMenu>
#include <QContextMenuEvent>
#include "src/mapwidget/poiitem.h"
#include "menu.h"
#include "xmlparser.h"
#define USE_LOCAL_CACHE "USE_LOCAL_CACHE"
#define USE_INTERNET_SERVER "USER_INTERNET_SERVER"
MapWidget::MapWidget(QWidget *parent) :
mapcontrol::OPMapWidget(parent),
m_window (NULL)
{
SetUseOpenGL(false);
//default appears to be Google Hybrid, and is broken currently
#if defined MAP_DEFAULT_TYPE_BING
this->SetMapType(MapType::BingHybrid);
#elif defined MAP_DEFAULT_TYPE_GOOGLE
this->SetMapType(MapType::GoogleHybrid);
#else
this->SetMapType(MapType::OpenStreetMap);
#endif
this->setContextMenuPolicy(Qt::ActionsContextMenu);
QSignalMapper* signalMapper = new QSignalMapper (this) ;
m_GoogleHybrid = new QAction(this);
m_GoogleHybrid->setText("GoogleHybrid");
m_GoogleHybrid->setChecked(true);
//this->addAction(GoogleHybrid);
connect(m_GoogleHybrid, SIGNAL(triggered()), signalMapper, SLOT(map()));
signalMapper->setMapping(m_GoogleHybrid, MapType::GoogleHybrid);
m_GoogleTerrain = new QAction(this);
m_GoogleTerrain->setText("GoogleTerrain");
//this->addAction(m_GoogleTerrain);
connect(m_GoogleTerrain, SIGNAL(triggered()), signalMapper, SLOT(map()));
signalMapper->setMapping(m_GoogleTerrain, MapType::GoogleTerrain);
/*
m_GoogleSatellite = new QAction(this);
m_GoogleSatellite->setText("GoogleSatellite");
//this->addAction(m_GoogleSatellite);
connect(m_GoogleSatellite, SIGNAL(triggered()), signalMapper, SLOT(map()));
signalMapper->setMapping(m_GoogleSatellite, MapType::GoogleSatellite);
m_GoogleMap = new QAction(this);
m_GoogleMap->setText("GoogleMap");
//this->addAction(m_GoogleMap);
connect(m_GoogleMap, SIGNAL(triggered()), signalMapper, SLOT(map()));
signalMapper->setMapping(m_GoogleMap, MapType::GoogleMap);
m_YandexMap = new QAction(this);
m_YandexMap->setText("YandexMap");
//this->addAction(m_YandexMap);
connect(m_YandexMap, SIGNAL(triggered()), signalMapper, SLOT(map()));
signalMapper->setMapping(m_YandexMap, MapType::YandexMapRu);
m_ArcGIS_Map = new QAction(this);
m_ArcGIS_Map->setText("ArcGIS_Map");
//this->addAction(m_ArcGIS_Map);
connect(m_ArcGIS_Map, SIGNAL(triggered()), signalMapper, SLOT(map()));
signalMapper->setMapping(m_ArcGIS_Map, MapType::ArcGIS_Map);
m_ArcGIS_Satellite = new QAction(this);
m_ArcGIS_Satellite->setText("ArcGIS_Satellite");
//this->addAction(m_ArcGIS_Satellite);
connect(m_ArcGIS_Satellite, SIGNAL(triggered()), signalMapper, SLOT(map()));
signalMapper->setMapping(m_ArcGIS_Satellite, MapType::ArcGIS_Satellite);
m_ArcGIS_Terrain = new QAction(this);
m_ArcGIS_Terrain->setText("ArcGIS_Terrain");
//this->addAction(m_ArcGIS_Terrain);
connect(m_ArcGIS_Terrain, SIGNAL(triggered()), signalMapper, SLOT(map()));
signalMapper->setMapping(m_ArcGIS_Terrain, MapType::ArcGIS_Terrain);
*/
//QSettings settings(QUOTE(COMPANY_NAME), QUOTE(APP_NAME));
//QSettings& settings = AppCore::Impl().GetSettings().getSettings();
m_useLocalCache = new QAction(this);
m_useLocalCache->setText("Use local cache");
m_useLocalCache->setCheckable(true);
//m_useLocalCache->setChecked(settings.value(USE_LOCAL_CACHE, true).toBool());
useCache(m_useLocalCache->isChecked());
connect(m_useLocalCache, SIGNAL(triggered(bool)), this, SLOT(useCache(bool)));
this->addAction(m_useLocalCache);
m_useInternetServer = new QAction(this);
m_useInternetServer->setText("Use internet server");
m_useInternetServer->setCheckable(true);
//m_useInternetServer->setChecked(settings.value(USE_INTERNET_SERVER, true).toBool());
useServer(m_useInternetServer->isChecked());
connect(m_useInternetServer, SIGNAL(triggered(bool)), this, SLOT(useServer(bool)));
this->addAction(m_useInternetServer);
//LOCAL_ASSERT(connect(signalMapper, SIGNAL(mapped(int)),this, SLOT(mapTypeChanged(int))));
setContextMenuPolicy(Qt::DefaultContextMenu);
//OPMaps::Instance()->setAccessMode((AccessMode::Types)(OPMaps::Instance()->GetAccessMode() & AccessMode::UseServer));
OPMaps::Instance()->setAccessMode((AccessMode::Types)(OPMaps::Instance()->GetAccessMode() | AccessMode::UseServer));
}
MapWidget::~MapWidget()
{
// From QGCMapWidget.cc
SetShowHome(false); // doing this appears to stop the map lib crashing on exit
SetShowUAV(false); // " "
//storeSettings();
//
}
void MapWidget::contextMenuEvent(QContextMenuEvent *event)
{
mapcontrol::OPMapWidget::contextMenuEvent(event);
if(!event->isAccepted())
{
XmlParser parser;
//TODO: Replace absolute path with the configured path
QHash<QString, QString> info = parser.Parse("D:/Project/Prototype/Map/Ico/desc.xml");
QMenu menu(this);
menu.addAction(m_GoogleTerrain);
// menu.addAction(m_GoogleSatellite);
// menu.addAction(m_GoogleMap);
// menu.addAction(m_YandexMap);
// menu.addAction(m_ArcGIS_Map);
// menu.addAction(m_ArcGIS_Satellite);
// menu.addAction(m_ArcGIS_Terrain);
menu.addSeparator();
menu.addAction(m_useLocalCache);
menu.addAction(m_useInternetServer);
//TODO: Replace absolute path with the configured path
Menu m(this, info, &menu, "D:/Project/Prototype/Map/Ico/");
menuPosition = event->globalPos();
connect(&m, SIGNAL(clicked(QString)), this, SLOT(PopUp(QString)));
menu.exec(menuPosition);
}
}
void MapWidget::PopUp(QString itemId)
{
}
void MapWidget::useCache(bool use)
{
if(use)
{
OPMaps::Instance()->setAccessMode((AccessMode::Types)(OPMaps::Instance()->GetAccessMode() | AccessMode::UseCache));
}
else
{
OPMaps::Instance()->setAccessMode((AccessMode::Types)(OPMaps::Instance()->GetAccessMode() & AccessMode::UseServer));
}
//QSettings settings(QUOTE(COMPANY_NAME), QUOTE(APP_NAME));
//AppCore::Impl().GetSettings().PutValue(USE_LOCAL_CACHE, use);
}
void MapWidget::useServer(bool use)
{
if(use)
{
OPMaps::Instance()->setAccessMode((AccessMode::Types)(OPMaps::Instance()->GetAccessMode() | AccessMode::UseServer));
}
else
{
OPMaps::Instance()->setAccessMode((AccessMode::Types)(OPMaps::Instance()->GetAccessMode() & AccessMode::UseCache));
}
//QSettings settings(QUOTE(COMPANY_NAME), QUOTE(APP_NAME));
// AppCore::Impl().GetSettings().PutValue(USE_INTERNET_SERVER, use);
}
void MapWidget::mapTypeChanged(int type)
{
this->SetMapType((core::MapType::Types)type);
}
void MapWidget::mouseDoubleClickEvent(QMouseEvent* event)
{
QPointF p=event->localPos();
p=map->mapFromParent(p);
QString path;
internals::PointLatLng coord = map->FromLocalToLatLng(p.x(), p.y());
mapcontrol::POIItem * item = new mapcontrol::POIItem(this->getMap(), this, path);
item->setParentItem(this->getMap());
item->SetCoord(coord);
item->RefreshPos();
}
void MapWidget::SetExtWindows(MainWindow* window)
{
m_window = window;
}