1
0
mirror of git://projects.qi-hardware.com/nanomap.git synced 2024-11-22 00:28:05 +02:00

add menu to show/hide layers

This commit is contained in:
Niels 2010-10-01 15:01:08 +02:00
parent bfd639fd99
commit 8daff2686c
5 changed files with 33 additions and 10 deletions

View File

@ -74,10 +74,12 @@ bool AbstractLayer::isVisible() const
void AbstractLayer::setVisible(bool visible) void AbstractLayer::setVisible(bool visible)
{ {
m_visible = visible; m_visible = visible;
emit visibilityChanged(m_visible);
} }
void AbstractLayer::toggleVisibility() void AbstractLayer::toggleVisibility()
{ {
m_visible = !m_visible; m_visible = !m_visible;
emit visibilityChanged(m_visible);
} }

View File

@ -40,12 +40,17 @@ public:
void paintLayer(QPainter *painter); void paintLayer(QPainter *painter);
MapWidget *map() const;
bool isVisible() const; bool isVisible() const;
public slots:
void setVisible(bool visible = true); void setVisible(bool visible = true);
void toggleVisibility(); void toggleVisibility();
signals:
void visibilityChanged(bool visible);
protected: protected:
MapWidget *map() const;
virtual void paint(QPainter *painter) = 0; virtual void paint(QPainter *painter) = 0;
private: private:

View File

@ -48,11 +48,11 @@ MainWidget::MainWidget(QWidget *parent)
AbstractLayer *l = new TimeLayer(m_map); AbstractLayer *l = new TimeLayer(m_map);
l->setVisible(false); l->setVisible(false);
m_map->addLayer(l, 4); m_map->addLayer(l, 4, "Time");
l = new BatteryLayer(m_map); l = new BatteryLayer(m_map);
l->setVisible(false); l->setVisible(false);
m_map->addLayer(l, 4); m_map->addLayer(l, 4, "Battery");
l = new MarkerLayer(m_map); l = new MarkerLayer(m_map);
connect(l, SIGNAL(markerAdded(QString)), m_markerList, SLOT(addMarker(QString))); connect(l, SIGNAL(markerAdded(QString)), m_markerList, SLOT(addMarker(QString)));
@ -60,10 +60,10 @@ MainWidget::MainWidget(QWidget *parent)
connect(m_markerList, SIGNAL(removeMarker(int)), l, SLOT(removeMarker(int))); connect(m_markerList, SIGNAL(removeMarker(int)), l, SLOT(removeMarker(int)));
connect(m_markerList, SIGNAL(markerRenamed(int, QString)), l, SLOT(renameMarker(int, QString))); connect(m_markerList, SIGNAL(markerRenamed(int, QString)), l, SLOT(renameMarker(int, QString)));
l->load(QDir::homePath()+"/Maps/marker.list"); l->load(QDir::homePath()+"/Maps/marker.list");
m_map->addLayer(l, 3); m_map->addLayer(l, 3, "Marker");
l = new GpsLayer(m_map); l = new GpsLayer(m_map);
m_map->addLayer(l, 1); m_map->addLayer(l, 1, "GPS-Position");
connect(m_map, SIGNAL(close()), this, SIGNAL(close())); connect(m_map, SIGNAL(close()), this, SIGNAL(close()));
connect(m_map, SIGNAL(showMarkerList()), this, SLOT(showList())); connect(m_map, SIGNAL(showMarkerList()), this, SLOT(showList()));
@ -93,7 +93,7 @@ void MainWidget::loadGpx(const QString &fileName)
if (fileName.endsWith(".gpx")) { if (fileName.endsWith(".gpx")) {
AbstractLayer *l = new GpxLayer(m_map); AbstractLayer *l = new GpxLayer(m_map);
l->load(fileName); l->load(fileName);
m_map->addLayer(l, 2); m_map->addLayer(l, 2, "GPS-Track");
} }
} }

View File

@ -73,7 +73,8 @@ MapWidget::MapWidget(QWidget *parent)
m_manager(new QNetworkAccessManager(this)), m_manager(new QNetworkAccessManager(this)),
m_networkMode(false), m_networkMode(false),
m_copyright(), m_copyright(),
m_layer() m_layer(),
m_layerMenu(new QMenu(this))
{ {
for (int x = 0; x < 100; ++x) { for (int x = 0; x < 100; ++x) {
for (int y = 0; y < 100; ++y) { for (int y = 0; y < 100; ++y) {
@ -135,8 +136,14 @@ MapWidget::~MapWidget()
} }
} }
void MapWidget::addLayer(AbstractLayer *layer, int z) void MapWidget::addLayer(AbstractLayer *layer, int z, const QString &name)
{ {
QAction *action = new QAction(name, m_layerMenu);
action->setCheckable(true);
action->setChecked(layer->isVisible());
connect(action, SIGNAL(triggered(bool)), layer, SLOT(setVisible(bool)));
connect(layer, SIGNAL(visibilityChanged(bool)), action, SLOT(setChecked(bool)));
m_layerMenu->addAction(action);
m_layer.insertMulti(z, layer); m_layer.insertMulti(z, layer);
} }
@ -315,6 +322,13 @@ void MapWidget::keyPressEvent(QKeyEvent *event)
} }
break; break;
} }
case Qt::Key_L:
{
if (event->modifiers() == Qt::NoModifier) {
m_layerMenu->popup(mapToGlobal(QPoint(0, 0)));
}
break;
}
case Qt::Key_Q: case Qt::Key_Q:
case Qt::Key_Escape: case Qt::Key_Escape:
{ {
@ -420,7 +434,7 @@ void MapWidget::paintEvent(QPaintEvent *event)
} }
usage << "u: Show/hide user interface"; usage << "u: Show/hide user interface";
usage << "m: Add a marker"; usage << "m: Add a marker";
usage << "Alt+m: Show/hide all marker"; usage << "l: Show/hide individual layers";
usage << "tab: Show/hide marker list"; usage << "tab: Show/hide marker list";
if (m_networkMode) { if (m_networkMode) {
usage << "d: Download tiles for visible area"; usage << "d: Download tiles for visible area";

View File

@ -24,6 +24,7 @@
#include <QtCore/QMap> #include <QtCore/QMap>
#include <QtCore/QPoint> #include <QtCore/QPoint>
#include <QtGui/QMenu>
#include <QtGui/QWidget> #include <QtGui/QWidget>
#include <QtNetwork/QNetworkAccessManager> #include <QtNetwork/QNetworkAccessManager>
@ -34,7 +35,7 @@ public:
MapWidget(QWidget *parent = 0); MapWidget(QWidget *parent = 0);
~MapWidget(); ~MapWidget();
void addLayer(AbstractLayer *layer, int z); void addLayer(AbstractLayer *layer, int z, const QString &name);
QRectF geoRect() const; QRectF geoRect() const;
QPointF geoPos() const; QPointF geoPos() const;
@ -95,6 +96,7 @@ private:
bool m_networkMode; bool m_networkMode;
QString m_copyright; QString m_copyright;
QMap<int, AbstractLayer *> m_layer; QMap<int, AbstractLayer *> m_layer;
QMenu *m_layerMenu;
}; };