From 3c15818b3b7dfe6b56bbf41c4dac53b1232a41d3 Mon Sep 17 00:00:00 2001 From: ephy Date: Fri, 19 Mar 2010 17:31:13 +0000 Subject: [PATCH] GCS/map: A map gadget to have something more interesting to look at than the emptygadget. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@339 ebee16cc-31ac-478f-84a7-5cbb03baadba --- ground/src/plugins/map/MapGadget.pluginspec | 10 ++++ ground/src/plugins/map/map.pro | 18 ++++++ ground/src/plugins/map/mapgadget.cpp | 21 +++++++ ground/src/plugins/map/mapgadget.h | 40 +++++++++++++ ground/src/plugins/map/mapgadgetfactory.cpp | 28 +++++++++ ground/src/plugins/map/mapgadgetfactory.h | 28 +++++++++ ground/src/plugins/map/mapgadgetwidget.cpp | 66 +++++++++++++++++++++ ground/src/plugins/map/mapgadgetwidget.h | 35 +++++++++++ ground/src/plugins/map/mapplugin.cpp | 46 ++++++++++++++ ground/src/plugins/map/mapplugin.h | 27 +++++++++ 10 files changed, 319 insertions(+) create mode 100644 ground/src/plugins/map/MapGadget.pluginspec create mode 100644 ground/src/plugins/map/map.pro create mode 100644 ground/src/plugins/map/mapgadget.cpp create mode 100644 ground/src/plugins/map/mapgadget.h create mode 100644 ground/src/plugins/map/mapgadgetfactory.cpp create mode 100644 ground/src/plugins/map/mapgadgetfactory.h create mode 100644 ground/src/plugins/map/mapgadgetwidget.cpp create mode 100644 ground/src/plugins/map/mapgadgetwidget.h create mode 100644 ground/src/plugins/map/mapplugin.cpp create mode 100644 ground/src/plugins/map/mapplugin.h diff --git a/ground/src/plugins/map/MapGadget.pluginspec b/ground/src/plugins/map/MapGadget.pluginspec new file mode 100644 index 000000000..b2c7dd487 --- /dev/null +++ b/ground/src/plugins/map/MapGadget.pluginspec @@ -0,0 +1,10 @@ + + The OpenPilot Project + (C) 2010 OpenPilot Project + + A map gadget! + http://www.openpilot.org + + + + diff --git a/ground/src/plugins/map/map.pro b/ground/src/plugins/map/map.pro new file mode 100644 index 000000000..abaafda6a --- /dev/null +++ b/ground/src/plugins/map/map.pro @@ -0,0 +1,18 @@ +TEMPLATE = lib +TARGET = MapGadget + +include(../../openpilotgcsplugin.pri) +include(../../plugins/coreplugin/coreplugin.pri) + +include(../../libs/qmapcontrol/qmapcontrol.pri) + +HEADERS += mapplugin.h +HEADERS += mapgadget.h +HEADERS += mapgadgetwidget.h +HEADERS += mapgadgetfactory.h +SOURCES += mapplugin.cpp +SOURCES += mapgadget.cpp +SOURCES += mapgadgetfactory.cpp +SOURCES += mapgadgetwidget.cpp + +OTHER_FILES += MapGadget.pluginspec diff --git a/ground/src/plugins/map/mapgadget.cpp b/ground/src/plugins/map/mapgadget.cpp new file mode 100644 index 000000000..0e5d10bcd --- /dev/null +++ b/ground/src/plugins/map/mapgadget.cpp @@ -0,0 +1,21 @@ +/* + * mapgadget.cpp + * + * Created on: Mar 11, 2010 + * Author: peter + */ +#include "mapgadget.h" +#include "mapgadgetwidget.h" +#include + +MapGadget::MapGadget(MapGadgetWidget *widget) : + IUAVGadget(widget), + m_widget(widget), + m_toolbar(new QToolBar()) +{ +} + +MapGadget::~MapGadget() +{ + +} diff --git a/ground/src/plugins/map/mapgadget.h b/ground/src/plugins/map/mapgadget.h new file mode 100644 index 000000000..a2ba8a571 --- /dev/null +++ b/ground/src/plugins/map/mapgadget.h @@ -0,0 +1,40 @@ +/* + * mapgadget.h + * + * Created on: Mar 11, 2010 + * Author: peter + */ + +#ifndef MAPGADGET_H_ +#define MAPGADGET_H_ + +#include + +class IUAVGadget; +//class QList; +class QWidget; +class QString; +class MapGadgetWidget; + +using namespace Core; + +class MapGadget : public Core::IUAVGadget +{ + Q_OBJECT +public: + MapGadget(MapGadgetWidget *widget = 0); + ~MapGadget(); + + QList context() const { return m_context; } + QWidget *widget() { return m_widget; } + QString contextHelpId() const { return QString(); } + + QWidget *toolBar() { return m_toolbar; } +private: + QWidget *m_widget; + QWidget *m_toolbar; + QList m_context; +}; + + +#endif // MAPGADGET_H_ diff --git a/ground/src/plugins/map/mapgadgetfactory.cpp b/ground/src/plugins/map/mapgadgetfactory.cpp new file mode 100644 index 000000000..d300b6bb6 --- /dev/null +++ b/ground/src/plugins/map/mapgadgetfactory.cpp @@ -0,0 +1,28 @@ +/* + * mapgadgetfactory.cpp + * + * Created on: Mar 11, 2010 + * Author: peter + */ +#include "mapgadgetfactory.h" +#include "mapgadgetwidget.h" +#include "mapgadget.h" +#include + +MapGadgetFactory::MapGadgetFactory(QObject *parent) : IUAVGadgetFactory(parent) +{ +} + +MapGadgetFactory::~MapGadgetFactory() +{ + +} + +Core::IUAVGadget* MapGadgetFactory::createUAVGadget(QWidget *parent) { + MapGadgetWidget* gadgetWidget = new MapGadgetWidget(parent); + return new MapGadget(gadgetWidget); +} + +QString MapGadgetFactory::name() { + return QString("MapGadget"); +} diff --git a/ground/src/plugins/map/mapgadgetfactory.h b/ground/src/plugins/map/mapgadgetfactory.h new file mode 100644 index 000000000..612f32468 --- /dev/null +++ b/ground/src/plugins/map/mapgadgetfactory.h @@ -0,0 +1,28 @@ +/* + * mapgadgetfactory.h + * + * Created on: Mar 6, 2010 + * Author: peter + */ + +#ifndef MAPGADGETFACTORY_H_ +#define MAPGADGETFACTORY_H_ + +#include + +using namespace Core; +class IUAVGadget; +class IUAVGadgetFactory; + +class MapGadgetFactory : public Core::IUAVGadgetFactory +{ + Q_OBJECT +public: + MapGadgetFactory(QObject *parent = 0); + ~MapGadgetFactory(); + + Core::IUAVGadget *createUAVGadget(QWidget *parent); + QString name(); +}; + +#endif // MAPGADGETFACTORY_H_ diff --git a/ground/src/plugins/map/mapgadgetwidget.cpp b/ground/src/plugins/map/mapgadgetwidget.cpp new file mode 100644 index 000000000..80fd0c89a --- /dev/null +++ b/ground/src/plugins/map/mapgadgetwidget.cpp @@ -0,0 +1,66 @@ +/* + * mapgadgetwidget.cpp + * + * Created on: Mar 6, 2010 + * Author: peter + */ +#include "mapgadgetwidget.h" +#include +#include +#include + +MapGadgetWidget::MapGadgetWidget(QWidget *parent) : QWidget(parent) +{ + int size = 256; + mc = new MapControl(QSize(size, size)); + setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); + mc->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); + mc->setMinimumSize(64, 64); + mc->showScale(true); + mapadapter = new OSMMapAdapter(); + mainlayer = new MapLayer("OpenStreetMap-Layer", mapadapter); + mc->addLayer(mainlayer); + + addZoomButtons(); + mc->setView(QPointF(5.718888888888, 58.963333333333)); + mc->setZoom(10); + mc->updateRequestNew(); + QVBoxLayout *layout = new QVBoxLayout; + layout->setSpacing(0); + layout->setContentsMargins(0, 0, 0, 0); + layout->addWidget(mc); + setLayout(layout); +} + +MapGadgetWidget::~MapGadgetWidget() +{ + // Do nothing +} + +void MapGadgetWidget::resizeEvent(QResizeEvent *event) +{ + mc->resize(QSize(width(), height())); + update(); + QWidget::resizeEvent(event); +} + +void MapGadgetWidget::addZoomButtons() +{ + // create buttons as controls for zoom + QPushButton* zoomin = new QPushButton("+"); + QPushButton* zoomout = new QPushButton("-"); + zoomin->setMaximumWidth(50); + zoomout->setMaximumWidth(50); + + connect(zoomin, SIGNAL(clicked(bool)), + mc, SLOT(zoomIn())); + connect(zoomout, SIGNAL(clicked(bool)), + mc, SLOT(zoomOut())); + + // add zoom buttons to the layout of the MapControl + QVBoxLayout* innerlayout = new QVBoxLayout; + innerlayout->addWidget(zoomin); + innerlayout->addWidget(zoomout); + mc->setLayout(innerlayout); +} + diff --git a/ground/src/plugins/map/mapgadgetwidget.h b/ground/src/plugins/map/mapgadgetwidget.h new file mode 100644 index 000000000..f4f8a96d5 --- /dev/null +++ b/ground/src/plugins/map/mapgadgetwidget.h @@ -0,0 +1,35 @@ +/* + * mapgadgetwidget.h + * + * Created on: Mar 6, 2010 + * Author: peter + */ + +#ifndef MAPGADGETWIDGET_H_ +#define MAPGADGETWIDGET_H_ + +#include "qmapcontrol/qmapcontrol.h" +#include + +using namespace qmapcontrol; + +class MapGadgetWidget : public QWidget +{ + Q_OBJECT + +public: + MapGadgetWidget(QWidget *parent = 0); + ~MapGadgetWidget(); + +protected: + void resizeEvent(QResizeEvent *event); + +private: + MapControl *mc; + MapAdapter *mapadapter; + Layer *mainlayer; + + void addZoomButtons(); +}; + +#endif /* MAPGADGETWIDGET_H_ */ diff --git a/ground/src/plugins/map/mapplugin.cpp b/ground/src/plugins/map/mapplugin.cpp new file mode 100644 index 000000000..1a56c878b --- /dev/null +++ b/ground/src/plugins/map/mapplugin.cpp @@ -0,0 +1,46 @@ +/* + * mapplugin.cpp + * + * Created on: Mar 6, 2010 + * Author: peter + */ +#include "mapplugin.h" +#include "mapgadgetfactory.h" +#include +#include +#include +#include + + +MapPlugin::MapPlugin() +{ + // Do nothing +} + +MapPlugin::~MapPlugin() +{ + // Do nothing +} + +bool MapPlugin::initialize(const QStringList& args, QString *errMsg) +{ + Q_UNUSED(args); + Q_UNUSED(errMsg); + mf = new MapGadgetFactory(this); + addAutoReleasedObject(mf); + qDebug() << "MapPlugin::initialize()"; + + return true; +} + +void MapPlugin::extensionsInitialized() +{ + // Do nothing +} + +void MapPlugin::shutdown() +{ + // Do nothing +} +Q_EXPORT_PLUGIN(MapPlugin) + diff --git a/ground/src/plugins/map/mapplugin.h b/ground/src/plugins/map/mapplugin.h new file mode 100644 index 000000000..b2f0d0ad7 --- /dev/null +++ b/ground/src/plugins/map/mapplugin.h @@ -0,0 +1,27 @@ +/* + * mapplugin.h + * + * Created on: Mar 6, 2010 + * Author: peter + */ + +#ifndef MAPPLUGIN_H_ +#define MAPPLUGIN_H_ + +#include + +class MapGadgetFactory; + +class MapPlugin : public ExtensionSystem::IPlugin +{ +public: + MapPlugin(); + ~MapPlugin(); + + void extensionsInitialized(); + bool initialize(const QStringList & arguments, QString * errorString); + void shutdown(); +private: + MapGadgetFactory *mf; +}; +#endif /* MAPPLUGIN_H_ */