From 2f3848e7eca5af77221ff7cd4b9890d242ec43c5 Mon Sep 17 00:00:00 2001 From: ephy Date: Thu, 25 Mar 2010 22:32:45 +0000 Subject: [PATCH] GCS/map: Updates to try out settings functionality. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@388 ebee16cc-31ac-478f-84a7-5cbb03baadba --- ground/src/plugins/map/mapgadget.cpp | 11 ++++ ground/src/plugins/map/mapgadget.h | 4 +- .../plugins/map/mapgadgetconfiguration.cpp | 15 ++++- .../src/plugins/map/mapgadgetconfiguration.h | 5 ++ .../src/plugins/map/mapgadgetoptionspage.cpp | 58 +++++++++++++++++-- ground/src/plugins/map/mapgadgetoptionspage.h | 5 ++ ground/src/plugins/map/mapgadgetwidget.cpp | 12 ++++ ground/src/plugins/map/mapgadgetwidget.h | 3 + 8 files changed, 107 insertions(+), 6 deletions(-) diff --git a/ground/src/plugins/map/mapgadget.cpp b/ground/src/plugins/map/mapgadget.cpp index 1ad9ad7f5..d3d29aa2b 100644 --- a/ground/src/plugins/map/mapgadget.cpp +++ b/ground/src/plugins/map/mapgadget.cpp @@ -6,6 +6,7 @@ */ #include "mapgadget.h" #include "mapgadgetwidget.h" +#include "mapgadgetconfiguration.h" MapGadget::MapGadget(QString classId, QList *configurations, MapGadgetWidget *widget) : IUAVGadget(classId, configurations, widget), @@ -17,3 +18,13 @@ MapGadget::~MapGadget() { } + +void MapGadget::loadConfiguration(IUAVGadgetConfiguration* config) +{ + MapGadgetConfiguration *m = qobject_cast(config); + m_widget->setZoom(m->zoom()); + m_widget->setPosition(QPointF(m->longitude(), m->latitude())); + int index = m_toolbar->findText(config->name()); + m_toolbar->setCurrentIndex(index); +} + diff --git a/ground/src/plugins/map/mapgadget.h b/ground/src/plugins/map/mapgadget.h index 49cbbd331..9c3250f31 100644 --- a/ground/src/plugins/map/mapgadget.h +++ b/ground/src/plugins/map/mapgadget.h @@ -9,6 +9,7 @@ #define MAPGADGET_H_ #include +#include "mapgadgetwidget.h" class IUAVGadget; //class QList; @@ -28,9 +29,10 @@ public: QList context() const { return m_context; } QWidget *widget() { return m_widget; } QString contextHelpId() const { return QString(); } + void loadConfiguration(IUAVGadgetConfiguration* config); private: - QWidget *m_widget; + MapGadgetWidget *m_widget; QList m_context; }; diff --git a/ground/src/plugins/map/mapgadgetconfiguration.cpp b/ground/src/plugins/map/mapgadgetconfiguration.cpp index 0ca2790c4..8ac0f2d30 100644 --- a/ground/src/plugins/map/mapgadgetconfiguration.cpp +++ b/ground/src/plugins/map/mapgadgetconfiguration.cpp @@ -35,14 +35,25 @@ MapGadgetConfiguration::MapGadgetConfiguration(bool locked, QString classId, QSt if (state.count() > 0) { QDataStream stream(state); int zoom; + double latitude; + double longitude; stream >> zoom; + stream >> latitude; + stream >> longitude; m_defaultZoom = zoom; + m_defaultLatitude = latitude; + m_defaultLongitude = longitude; + } } IUAVGadgetConfiguration *MapGadgetConfiguration::clone(QString name) { - return new MapGadgetConfiguration(this->locked(), this->classId(), name); + MapGadgetConfiguration *m = new MapGadgetConfiguration(this->locked(), this->classId(), name); + m->m_defaultZoom = m_defaultZoom; + m->m_defaultLatitude = m_defaultLatitude; + m->m_defaultLongitude = m_defaultLongitude; + return m; } QByteArray MapGadgetConfiguration::saveState() const @@ -50,6 +61,8 @@ QByteArray MapGadgetConfiguration::saveState() const QByteArray bytes; QDataStream stream(&bytes, QIODevice::WriteOnly); stream << m_defaultZoom; + stream << m_defaultLatitude; + stream << m_defaultLongitude; return bytes; } diff --git a/ground/src/plugins/map/mapgadgetconfiguration.h b/ground/src/plugins/map/mapgadgetconfiguration.h index c956b92ad..420217195 100644 --- a/ground/src/plugins/map/mapgadgetconfiguration.h +++ b/ground/src/plugins/map/mapgadgetconfiguration.h @@ -38,6 +38,11 @@ Q_OBJECT public: explicit MapGadgetConfiguration(bool locked, QString classId, QString name, 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; IUAVGadgetConfiguration *clone(QString name); signals: diff --git a/ground/src/plugins/map/mapgadgetoptionspage.cpp b/ground/src/plugins/map/mapgadgetoptionspage.cpp index 55a1fe2d7..641340c7c 100644 --- a/ground/src/plugins/map/mapgadgetoptionspage.cpp +++ b/ground/src/plugins/map/mapgadgetoptionspage.cpp @@ -28,6 +28,11 @@ #include "mapgadgetoptionspage.h" #include "mapgadgetconfiguration.h" #include +#include +#include +#include +#include + MapGadgetOptionsPage::MapGadgetOptionsPage(IUAVGadgetConfiguration *config, QObject *parent) : IOptionsPage(parent), @@ -37,14 +42,59 @@ MapGadgetOptionsPage::MapGadgetOptionsPage(IUAVGadgetConfiguration *config, QObj QWidget *MapGadgetOptionsPage::createPage(QWidget *parent) { - QWidget *label = new QLabel("Settings will be here.", parent); -// QLabel *label = new QLabel(QString(m_config->zoom())); - label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); - return label; + QWidget *widget = new QWidget; + QVBoxLayout *vl = new QVBoxLayout(); + widget->setLayout(vl); + + QHBoxLayout *zoomLayout = new QHBoxLayout(); + QWidget *x = new QWidget; + x->setLayout(zoomLayout); + QWidget *label = new QLabel("Default zoom:"); + m_zoomSpin = new QSpinBox(); + m_zoomSpin->setMaximum(18); + zoomLayout->addWidget(label); + zoomLayout->addWidget(m_zoomSpin); + + QHBoxLayout *latLayout = new QHBoxLayout(); + QWidget *y = new QWidget; + y->setLayout(latLayout); + label = new QLabel("Default latitude:"); + m_latSpin = new QDoubleSpinBox(); + m_latSpin->setDecimals(8); + m_latSpin->setMinimum(-90); + m_latSpin->setMaximum(90); + latLayout->addWidget(label); + latLayout->addWidget(m_latSpin); + + + QHBoxLayout *longLayout = new QHBoxLayout(); + QWidget *z = new QWidget; + z->setLayout(longLayout); + label = new QLabel("Default longitude:"); + m_longSpin = new QDoubleSpinBox(); + m_longSpin->setDecimals(8); + m_longSpin->setMinimum(-180); + m_longSpin->setMaximum(180); + longLayout->addWidget(label); + longLayout->addWidget(m_longSpin); + QSpacerItem *item = new QSpacerItem(100, 100, QSizePolicy::Expanding, QSizePolicy::Expanding); + + vl->addWidget(x); + vl->addWidget(y); + vl->addWidget(z); + + m_zoomSpin->setValue(m_config->zoom()); + m_latSpin->setValue(m_config->latitude()); + m_longSpin->setValue(m_config->longitude()); + + return widget; } void MapGadgetOptionsPage::apply() { + m_config->setZoom(m_zoomSpin->value()); + m_config->setLatitude(m_latSpin->value()); + m_config->setLongitude(m_longSpin->value()); } diff --git a/ground/src/plugins/map/mapgadgetoptionspage.h b/ground/src/plugins/map/mapgadgetoptionspage.h index bb102812c..dd008a4e0 100644 --- a/ground/src/plugins/map/mapgadgetoptionspage.h +++ b/ground/src/plugins/map/mapgadgetoptionspage.h @@ -34,6 +34,8 @@ namespace Core { class IUAVGadgetConfiguration; } class MapGadgetConfiguration; +class QSpinBox; +class QDoubleSpinBox; using namespace Core; @@ -56,6 +58,9 @@ signals: public slots: private: MapGadgetConfiguration *m_config; + QSpinBox *m_zoomSpin; + QDoubleSpinBox *m_latSpin; + QDoubleSpinBox *m_longSpin; }; diff --git a/ground/src/plugins/map/mapgadgetwidget.cpp b/ground/src/plugins/map/mapgadgetwidget.cpp index 80fd0c89a..c9981bc54 100644 --- a/ground/src/plugins/map/mapgadgetwidget.cpp +++ b/ground/src/plugins/map/mapgadgetwidget.cpp @@ -36,6 +36,18 @@ MapGadgetWidget::~MapGadgetWidget() { // Do nothing } +void MapGadgetWidget::setZoom(int value) +{ + mc->setZoom(value); + mc->updateRequestNew(); +} + +void MapGadgetWidget::setPosition(QPointF pos) +{ + mc->setView(pos); + mc->updateRequestNew(); +} + void MapGadgetWidget::resizeEvent(QResizeEvent *event) { diff --git a/ground/src/plugins/map/mapgadgetwidget.h b/ground/src/plugins/map/mapgadgetwidget.h index f4f8a96d5..687c719cb 100644 --- a/ground/src/plugins/map/mapgadgetwidget.h +++ b/ground/src/plugins/map/mapgadgetwidget.h @@ -11,6 +11,7 @@ #include "qmapcontrol/qmapcontrol.h" #include + using namespace qmapcontrol; class MapGadgetWidget : public QWidget @@ -20,6 +21,8 @@ class MapGadgetWidget : public QWidget public: MapGadgetWidget(QWidget *parent = 0); ~MapGadgetWidget(); + void setZoom(int value); + void setPosition(QPointF pos); protected: void resizeEvent(QResizeEvent *event);