mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
OP-65 GCS/map gadget: Option to choose map provider.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@489 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
74e5cfa3ca
commit
052791620e
@ -42,6 +42,7 @@ MapGadget::~MapGadget()
|
|||||||
void MapGadget::loadConfiguration(IUAVGadgetConfiguration* config)
|
void MapGadget::loadConfiguration(IUAVGadgetConfiguration* config)
|
||||||
{
|
{
|
||||||
MapGadgetConfiguration *m = qobject_cast<MapGadgetConfiguration*>(config);
|
MapGadgetConfiguration *m = qobject_cast<MapGadgetConfiguration*>(config);
|
||||||
|
m_widget->setMapProvider(m->mapProvider());
|
||||||
m_widget->setZoom(m->zoom());
|
m_widget->setZoom(m->zoom());
|
||||||
m_widget->setPosition(QPointF(m->longitude(), m->latitude()));
|
m_widget->setPosition(QPointF(m->longitude(), m->latitude()));
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
MapGadgetConfiguration::MapGadgetConfiguration(QString classId, const QByteArray &state, QObject *parent) :
|
MapGadgetConfiguration::MapGadgetConfiguration(QString classId, const QByteArray &state, QObject *parent) :
|
||||||
IUAVGadgetConfiguration(classId, parent),
|
IUAVGadgetConfiguration(classId, parent),
|
||||||
|
m_mapProvider("OpenStreetMap"),
|
||||||
m_defaultZoom(10),
|
m_defaultZoom(10),
|
||||||
m_defaultLatitude(0),
|
m_defaultLatitude(0),
|
||||||
m_defaultLongitude(0)
|
m_defaultLongitude(0)
|
||||||
@ -39,12 +40,16 @@ MapGadgetConfiguration::MapGadgetConfiguration(QString classId, const QByteArray
|
|||||||
int zoom;
|
int zoom;
|
||||||
double latitude;
|
double latitude;
|
||||||
double longitude;
|
double longitude;
|
||||||
|
QString mapProvider;
|
||||||
stream >> zoom;
|
stream >> zoom;
|
||||||
stream >> latitude;
|
stream >> latitude;
|
||||||
stream >> longitude;
|
stream >> longitude;
|
||||||
|
stream >> mapProvider;
|
||||||
m_defaultZoom = zoom;
|
m_defaultZoom = zoom;
|
||||||
m_defaultLatitude = latitude;
|
m_defaultLatitude = latitude;
|
||||||
m_defaultLongitude = longitude;
|
m_defaultLongitude = longitude;
|
||||||
|
if (mapProvider != "")
|
||||||
|
m_mapProvider = mapProvider;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -55,6 +60,7 @@ IUAVGadgetConfiguration *MapGadgetConfiguration::clone()
|
|||||||
m->m_defaultZoom = m_defaultZoom;
|
m->m_defaultZoom = m_defaultZoom;
|
||||||
m->m_defaultLatitude = m_defaultLatitude;
|
m->m_defaultLatitude = m_defaultLatitude;
|
||||||
m->m_defaultLongitude = m_defaultLongitude;
|
m->m_defaultLongitude = m_defaultLongitude;
|
||||||
|
m->m_mapProvider = m_mapProvider;
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,6 +71,7 @@ QByteArray MapGadgetConfiguration::saveState() const
|
|||||||
stream << m_defaultZoom;
|
stream << m_defaultZoom;
|
||||||
stream << m_defaultLatitude;
|
stream << m_defaultLatitude;
|
||||||
stream << m_defaultLongitude;
|
stream << m_defaultLongitude;
|
||||||
|
stream << m_mapProvider;
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,27 +29,35 @@
|
|||||||
#define MAPGADGETCONFIGURATION_H
|
#define MAPGADGETCONFIGURATION_H
|
||||||
|
|
||||||
#include <coreplugin/iuavgadgetconfiguration.h>
|
#include <coreplugin/iuavgadgetconfiguration.h>
|
||||||
|
#include <QtCore/QString>
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
|
|
||||||
class MapGadgetConfiguration : public IUAVGadgetConfiguration
|
class MapGadgetConfiguration : public IUAVGadgetConfiguration
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString mapProvider READ mapProvider WRITE setMapProvider)
|
||||||
|
Q_PROPERTY(int zoommo READ zoom WRITE setZoom)
|
||||||
|
Q_PROPERTY(double latitude READ latitude WRITE setLatitude)
|
||||||
|
Q_PROPERTY(double longitude READ longitude WRITE setLongitude)
|
||||||
public:
|
public:
|
||||||
explicit MapGadgetConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0);
|
explicit MapGadgetConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0);
|
||||||
int zoom() { return m_defaultZoom; }
|
|
||||||
void setZoom(int zoom) { m_defaultZoom = zoom; }
|
|
||||||
double latitude() { return m_defaultLatitude; }
|
|
||||||
void setLatitude(double lat) { m_defaultLatitude = lat; }
|
|
||||||
double longitude() { return m_defaultLongitude; }
|
|
||||||
void setLongitude(double lon) { m_defaultLongitude = lon; }
|
|
||||||
QByteArray saveState() const;
|
QByteArray saveState() const;
|
||||||
IUAVGadgetConfiguration *clone();
|
IUAVGadgetConfiguration *clone();
|
||||||
signals:
|
|
||||||
|
QString mapProvider() const { return m_mapProvider; }
|
||||||
|
int zoom() const { return m_defaultZoom; }
|
||||||
|
double latitude() const { return m_defaultLatitude; }
|
||||||
|
double longitude() const { return m_defaultLongitude; }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void setMapProvider(QString provider) { m_mapProvider = provider; }
|
||||||
|
void setZoom(int zoom) { m_defaultZoom = zoom; }
|
||||||
|
void setLatitude(double latitude) { m_defaultLatitude = latitude; }
|
||||||
|
void setLongitude(double longitude) { m_defaultLongitude = longitude; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QString m_mapProvider;
|
||||||
int m_defaultZoom;
|
int m_defaultZoom;
|
||||||
double m_defaultLatitude;
|
double m_defaultLatitude;
|
||||||
double m_defaultLongitude;
|
double m_defaultLongitude;
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "mapgadgetoptionspage.h"
|
#include "mapgadgetoptionspage.h"
|
||||||
#include "mapgadgetconfiguration.h"
|
#include "mapgadgetconfiguration.h"
|
||||||
#include <QtGui/QLabel>
|
#include <QtGui/QLabel>
|
||||||
|
#include <QtGui/QComboBox>
|
||||||
#include <QtGui/QSpinBox>
|
#include <QtGui/QSpinBox>
|
||||||
#include <QtGui/QDoubleSpinBox>
|
#include <QtGui/QDoubleSpinBox>
|
||||||
#include <QtGui/QHBoxLayout>
|
#include <QtGui/QHBoxLayout>
|
||||||
@ -46,10 +47,22 @@ QWidget *MapGadgetOptionsPage::createPage(QWidget *parent)
|
|||||||
QVBoxLayout *vl = new QVBoxLayout();
|
QVBoxLayout *vl = new QVBoxLayout();
|
||||||
widget->setLayout(vl);
|
widget->setLayout(vl);
|
||||||
|
|
||||||
|
QHBoxLayout *providerLayout = new QHBoxLayout();
|
||||||
|
QWidget *mp = new QWidget;
|
||||||
|
mp->setLayout(providerLayout);
|
||||||
|
QWidget *label = new QLabel("Map Provider:");
|
||||||
|
m_providerComboBox = new QComboBox();
|
||||||
|
m_providerComboBox->addItem("OpenStreetMap");
|
||||||
|
m_providerComboBox->addItem("Google");
|
||||||
|
m_providerComboBox->addItem("Google Sat");
|
||||||
|
// m_providerComboBox->addItem("Yahoo");
|
||||||
|
providerLayout->addWidget(label);
|
||||||
|
providerLayout->addWidget(m_providerComboBox);
|
||||||
|
|
||||||
QHBoxLayout *zoomLayout = new QHBoxLayout();
|
QHBoxLayout *zoomLayout = new QHBoxLayout();
|
||||||
QWidget *x = new QWidget;
|
QWidget *x = new QWidget;
|
||||||
x->setLayout(zoomLayout);
|
x->setLayout(zoomLayout);
|
||||||
QWidget *label = new QLabel("Default zoom:");
|
label = new QLabel("Default zoom:");
|
||||||
m_zoomSpin = new QSpinBox();
|
m_zoomSpin = new QSpinBox();
|
||||||
m_zoomSpin->setMaximum(18);
|
m_zoomSpin->setMaximum(18);
|
||||||
zoomLayout->addWidget(label);
|
zoomLayout->addWidget(label);
|
||||||
@ -66,7 +79,6 @@ QWidget *MapGadgetOptionsPage::createPage(QWidget *parent)
|
|||||||
latLayout->addWidget(label);
|
latLayout->addWidget(label);
|
||||||
latLayout->addWidget(m_latSpin);
|
latLayout->addWidget(m_latSpin);
|
||||||
|
|
||||||
|
|
||||||
QHBoxLayout *longLayout = new QHBoxLayout();
|
QHBoxLayout *longLayout = new QHBoxLayout();
|
||||||
QWidget *z = new QWidget;
|
QWidget *z = new QWidget;
|
||||||
z->setLayout(longLayout);
|
z->setLayout(longLayout);
|
||||||
@ -79,11 +91,15 @@ QWidget *MapGadgetOptionsPage::createPage(QWidget *parent)
|
|||||||
longLayout->addWidget(m_longSpin);
|
longLayout->addWidget(m_longSpin);
|
||||||
QSpacerItem *spacer = new QSpacerItem(100, 100, QSizePolicy::Expanding, QSizePolicy::Expanding);
|
QSpacerItem *spacer = new QSpacerItem(100, 100, QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
|
|
||||||
|
vl->addWidget(mp);
|
||||||
vl->addWidget(x);
|
vl->addWidget(x);
|
||||||
vl->addWidget(y);
|
vl->addWidget(y);
|
||||||
vl->addWidget(z);
|
vl->addWidget(z);
|
||||||
vl->addSpacerItem(spacer);
|
vl->addSpacerItem(spacer);
|
||||||
|
|
||||||
|
int index = m_providerComboBox->findText(m_config->mapProvider());
|
||||||
|
index = (index >= 0) ? index : 0;
|
||||||
|
m_providerComboBox->setCurrentIndex(index);
|
||||||
m_zoomSpin->setValue(m_config->zoom());
|
m_zoomSpin->setValue(m_config->zoom());
|
||||||
m_latSpin->setValue(m_config->latitude());
|
m_latSpin->setValue(m_config->latitude());
|
||||||
m_longSpin->setValue(m_config->longitude());
|
m_longSpin->setValue(m_config->longitude());
|
||||||
@ -93,10 +109,10 @@ QWidget *MapGadgetOptionsPage::createPage(QWidget *parent)
|
|||||||
|
|
||||||
void MapGadgetOptionsPage::apply()
|
void MapGadgetOptionsPage::apply()
|
||||||
{
|
{
|
||||||
|
m_config->setMapProvider(m_providerComboBox->currentText());
|
||||||
m_config->setZoom(m_zoomSpin->value());
|
m_config->setZoom(m_zoomSpin->value());
|
||||||
m_config->setLatitude(m_latSpin->value());
|
m_config->setLatitude(m_latSpin->value());
|
||||||
m_config->setLongitude(m_longSpin->value());
|
m_config->setLongitude(m_longSpin->value());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapGadgetOptionsPage::finish()
|
void MapGadgetOptionsPage::finish()
|
||||||
|
@ -34,6 +34,7 @@ namespace Core {
|
|||||||
class IUAVGadgetConfiguration;
|
class IUAVGadgetConfiguration;
|
||||||
}
|
}
|
||||||
class MapGadgetConfiguration;
|
class MapGadgetConfiguration;
|
||||||
|
class QComboBox;
|
||||||
class QSpinBox;
|
class QSpinBox;
|
||||||
class QDoubleSpinBox;
|
class QDoubleSpinBox;
|
||||||
|
|
||||||
@ -54,6 +55,7 @@ signals:
|
|||||||
public slots:
|
public slots:
|
||||||
private:
|
private:
|
||||||
MapGadgetConfiguration *m_config;
|
MapGadgetConfiguration *m_config;
|
||||||
|
QComboBox *m_providerComboBox;
|
||||||
QSpinBox *m_zoomSpin;
|
QSpinBox *m_zoomSpin;
|
||||||
QDoubleSpinBox *m_latSpin;
|
QDoubleSpinBox *m_latSpin;
|
||||||
QDoubleSpinBox *m_longSpin;
|
QDoubleSpinBox *m_longSpin;
|
||||||
|
@ -32,23 +32,36 @@
|
|||||||
MapGadgetWidget::MapGadgetWidget(QWidget *parent) : QWidget(parent)
|
MapGadgetWidget::MapGadgetWidget(QWidget *parent) : QWidget(parent)
|
||||||
{
|
{
|
||||||
int size = 256;
|
int size = 256;
|
||||||
mc = new MapControl(QSize(size, size));
|
m_mc = new MapControl(QSize(size, size));
|
||||||
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||||
mc->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
m_mc->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||||
mc->setMinimumSize(64, 64);
|
m_mc->setMinimumSize(64, 64);
|
||||||
mc->showScale(true);
|
m_mc->showScale(true);
|
||||||
mapadapter = new OSMMapAdapter();
|
m_osmAdapter = new OSMMapAdapter();
|
||||||
mainlayer = new MapLayer("OpenStreetMap-Layer", mapadapter);
|
m_googleSatAdapter = new GoogleSatMapAdapter();
|
||||||
mc->addLayer(mainlayer);
|
m_googleAdapter = new GoogleMapAdapter();
|
||||||
|
m_yahooAdapter = new YahooMapAdapter();
|
||||||
|
m_osmLayer = new MapLayer("OpenStreetMap", m_osmAdapter);
|
||||||
|
m_googleLayer = new MapLayer("Google", m_googleAdapter);
|
||||||
|
m_googleSatLayer = new MapLayer("Google Sat", m_googleSatAdapter);
|
||||||
|
m_yahooLayer = new MapLayer("Yahoo", m_yahooAdapter);
|
||||||
|
m_osmLayer->setVisible(true);
|
||||||
|
m_googleLayer->setVisible(false);
|
||||||
|
m_googleSatLayer->setVisible(false);
|
||||||
|
m_yahooLayer->setVisible(false);
|
||||||
|
m_mc->addLayer(m_osmLayer);
|
||||||
|
m_mc->addLayer(m_googleLayer);
|
||||||
|
m_mc->addLayer(m_googleSatLayer);
|
||||||
|
m_mc->addLayer(m_yahooLayer);
|
||||||
|
|
||||||
addZoomButtons();
|
addZoomButtons();
|
||||||
mc->setView(QPointF(5.718888888888, 58.963333333333));
|
m_mc->setView(QPointF(5.718888888888, 58.963333333333));
|
||||||
mc->setZoom(10);
|
m_mc->setZoom(10);
|
||||||
mc->updateRequestNew();
|
m_mc->updateRequestNew();
|
||||||
QVBoxLayout *layout = new QVBoxLayout;
|
QVBoxLayout *layout = new QVBoxLayout;
|
||||||
layout->setSpacing(0);
|
layout->setSpacing(0);
|
||||||
layout->setContentsMargins(0, 0, 0, 0);
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
layout->addWidget(mc);
|
layout->addWidget(m_mc);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,20 +71,26 @@ MapGadgetWidget::~MapGadgetWidget()
|
|||||||
}
|
}
|
||||||
void MapGadgetWidget::setZoom(int value)
|
void MapGadgetWidget::setZoom(int value)
|
||||||
{
|
{
|
||||||
mc->setZoom(value);
|
m_mc->setZoom(value);
|
||||||
mc->updateRequestNew();
|
m_mc->updateRequestNew();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapGadgetWidget::setPosition(QPointF pos)
|
void MapGadgetWidget::setPosition(QPointF pos)
|
||||||
{
|
{
|
||||||
mc->setView(pos);
|
m_mc->setView(pos);
|
||||||
mc->updateRequestNew();
|
m_mc->updateRequestNew();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapGadgetWidget::setMapProvider(QString provider)
|
||||||
|
{
|
||||||
|
foreach(QString layerName, m_mc->layers())
|
||||||
|
m_mc->layer(layerName)->setVisible(layerName == provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MapGadgetWidget::resizeEvent(QResizeEvent *event)
|
void MapGadgetWidget::resizeEvent(QResizeEvent *event)
|
||||||
{
|
{
|
||||||
mc->resize(QSize(width(), height()));
|
m_mc->resize(QSize(width(), height()));
|
||||||
update();
|
update();
|
||||||
QWidget::resizeEvent(event);
|
QWidget::resizeEvent(event);
|
||||||
}
|
}
|
||||||
@ -85,14 +104,14 @@ void MapGadgetWidget::addZoomButtons()
|
|||||||
zoomout->setMaximumWidth(50);
|
zoomout->setMaximumWidth(50);
|
||||||
|
|
||||||
connect(zoomin, SIGNAL(clicked(bool)),
|
connect(zoomin, SIGNAL(clicked(bool)),
|
||||||
mc, SLOT(zoomIn()));
|
m_mc, SLOT(zoomIn()));
|
||||||
connect(zoomout, SIGNAL(clicked(bool)),
|
connect(zoomout, SIGNAL(clicked(bool)),
|
||||||
mc, SLOT(zoomOut()));
|
m_mc, SLOT(zoomOut()));
|
||||||
|
|
||||||
// add zoom buttons to the layout of the MapControl
|
// add zoom buttons to the layout of the MapControl
|
||||||
QVBoxLayout* innerlayout = new QVBoxLayout;
|
QVBoxLayout* innerlayout = new QVBoxLayout;
|
||||||
innerlayout->addWidget(zoomin);
|
innerlayout->addWidget(zoomin);
|
||||||
innerlayout->addWidget(zoomout);
|
innerlayout->addWidget(zoomout);
|
||||||
mc->setLayout(innerlayout);
|
m_mc->setLayout(innerlayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,16 +43,24 @@ public:
|
|||||||
~MapGadgetWidget();
|
~MapGadgetWidget();
|
||||||
void setZoom(int value);
|
void setZoom(int value);
|
||||||
void setPosition(QPointF pos);
|
void setPosition(QPointF pos);
|
||||||
|
void setMapProvider(QString provider);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *event);
|
void resizeEvent(QResizeEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MapControl *mc;
|
|
||||||
MapAdapter *mapadapter;
|
|
||||||
Layer *mainlayer;
|
|
||||||
|
|
||||||
void addZoomButtons();
|
void addZoomButtons();
|
||||||
|
|
||||||
|
MapControl *m_mc;
|
||||||
|
MapAdapter *m_osmAdapter;
|
||||||
|
MapAdapter *m_googleAdapter;
|
||||||
|
MapAdapter *m_googleSatAdapter;
|
||||||
|
MapAdapter *m_yahooAdapter;
|
||||||
|
Layer *m_osmLayer;
|
||||||
|
Layer *m_googleLayer;
|
||||||
|
Layer *m_googleSatLayer;
|
||||||
|
Layer *m_yahooLayer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* MAPGADGETWIDGET_H_ */
|
#endif /* MAPGADGETWIDGET_H_ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user