Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / plugins / opmap / opmapgadget.cpp
blobb677d1d6f75355a60cd712c4b87379ff8d9dd46f
1 /**
2 ******************************************************************************
4 * @file opmapgadget.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
6 * @addtogroup GCSPlugins GCS Plugins
7 * @{
8 * @addtogroup OPMapPlugin OpenPilot Map Plugin
9 * @{
10 * @brief The OpenPilot Map plugin
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "opmapgadget.h"
28 #include "opmapgadgetwidget.h"
30 OPMapGadget::OPMapGadget(QString classId, OPMapGadgetWidget *widget, QWidget *parent) :
31 IUAVGadget(classId, parent),
32 m_widget(widget), m_config(NULL)
34 connect(m_widget, SIGNAL(defaultLocationAndZoomChanged(double, double, double)), this, SLOT(saveDefaultLocation(double, double, double)));
35 connect(m_widget, SIGNAL(defaultSafeAreaChanged(int, bool)), this, SLOT(saveDefaultSafeArea(int, bool)));
36 connect(m_widget, SIGNAL(overlayOpacityChanged(qreal)), this, SLOT(saveOpacity(qreal)));
39 OPMapGadget::~OPMapGadget()
41 delete m_widget;
43 void OPMapGadget::saveDefaultLocation(double lng, double lat, double zoom)
45 if (m_config) {
46 m_config->setLatitude(lat);
47 m_config->setLongitude(lng);
48 m_config->setZoom(zoom);
49 m_config->save();
52 void OPMapGadget::saveDefaultSafeArea(int safe_area_radius, bool showSafeArea)
54 if (m_config) {
55 m_config->setSafeAreaRadius(safe_area_radius);
56 m_config->setShowSafeArea(showSafeArea);
57 m_config->save();
61 void OPMapGadget::saveOpacity(qreal value)
63 if (m_config) {
64 m_config->setOpacity(value);
67 void OPMapGadget::loadConfiguration(IUAVGadgetConfiguration *config)
69 m_config = qobject_cast<OPMapGadgetConfiguration *>(config);
70 m_widget->setMapProvider(m_config->mapProvider());
71 m_widget->setMaxUpdateRate(m_config->maxUpdateRate());
72 m_widget->setUseOpenGL(m_config->useOpenGL());
73 m_widget->setShowTileGridLines(m_config->showTileGridLines());
74 m_widget->setAccessMode(m_config->accessMode());
75 m_widget->setUseMemoryCache(m_config->useMemoryCache());
76 m_widget->setCacheLocation(m_config->cacheLocation());
77 m_widget->SetUavPic(m_config->uavSymbol());
78 m_widget->setZoom(m_config->zoom());
79 m_widget->setPosition(QPointF(m_config->longitude(), m_config->latitude()));
80 m_widget->setSafeAreaRadius(m_config->safeAreaRadius());
81 m_widget->setShowSafeArea(m_config->showSafeArea());
82 m_widget->setOverlayOpacity(m_config->opacity());
83 m_widget->setDefaultWaypointAltitude(m_config->defaultWaypointAltitude());
84 m_widget->setDefaultWaypointVelocity(m_config->defaultWaypointVelocity());
86 if (!m_widget->applyHomeLocationOnMap()) {
87 // Set default HomeLocation in center of map
88 m_widget->setHomePosition(QPointF(m_config->longitude(), m_config->latitude()));