mirror of
git://projects.qi-hardware.com/nanomap.git
synced 2024-11-22 00:13:10 +02:00
add menu to show/hide layers
This commit is contained in:
parent
bfd639fd99
commit
8daff2686c
@ -74,10 +74,12 @@ bool AbstractLayer::isVisible() const
|
||||
void AbstractLayer::setVisible(bool visible)
|
||||
{
|
||||
m_visible = visible;
|
||||
emit visibilityChanged(m_visible);
|
||||
}
|
||||
|
||||
void AbstractLayer::toggleVisibility()
|
||||
{
|
||||
m_visible = !m_visible;
|
||||
emit visibilityChanged(m_visible);
|
||||
}
|
||||
|
||||
|
@ -40,12 +40,17 @@ public:
|
||||
|
||||
void paintLayer(QPainter *painter);
|
||||
|
||||
MapWidget *map() const;
|
||||
bool isVisible() const;
|
||||
|
||||
public slots:
|
||||
void setVisible(bool visible = true);
|
||||
void toggleVisibility();
|
||||
|
||||
signals:
|
||||
void visibilityChanged(bool visible);
|
||||
|
||||
protected:
|
||||
MapWidget *map() const;
|
||||
virtual void paint(QPainter *painter) = 0;
|
||||
|
||||
private:
|
||||
|
@ -48,11 +48,11 @@ MainWidget::MainWidget(QWidget *parent)
|
||||
|
||||
AbstractLayer *l = new TimeLayer(m_map);
|
||||
l->setVisible(false);
|
||||
m_map->addLayer(l, 4);
|
||||
m_map->addLayer(l, 4, "Time");
|
||||
|
||||
l = new BatteryLayer(m_map);
|
||||
l->setVisible(false);
|
||||
m_map->addLayer(l, 4);
|
||||
m_map->addLayer(l, 4, "Battery");
|
||||
|
||||
l = new MarkerLayer(m_map);
|
||||
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(markerRenamed(int, QString)), l, SLOT(renameMarker(int, QString)));
|
||||
l->load(QDir::homePath()+"/Maps/marker.list");
|
||||
m_map->addLayer(l, 3);
|
||||
m_map->addLayer(l, 3, "Marker");
|
||||
|
||||
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(showMarkerList()), this, SLOT(showList()));
|
||||
@ -93,7 +93,7 @@ void MainWidget::loadGpx(const QString &fileName)
|
||||
if (fileName.endsWith(".gpx")) {
|
||||
AbstractLayer *l = new GpxLayer(m_map);
|
||||
l->load(fileName);
|
||||
m_map->addLayer(l, 2);
|
||||
m_map->addLayer(l, 2, "GPS-Track");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,8 @@ MapWidget::MapWidget(QWidget *parent)
|
||||
m_manager(new QNetworkAccessManager(this)),
|
||||
m_networkMode(false),
|
||||
m_copyright(),
|
||||
m_layer()
|
||||
m_layer(),
|
||||
m_layerMenu(new QMenu(this))
|
||||
{
|
||||
for (int x = 0; x < 100; ++x) {
|
||||
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);
|
||||
}
|
||||
|
||||
@ -315,6 +322,13 @@ void MapWidget::keyPressEvent(QKeyEvent *event)
|
||||
}
|
||||
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_Escape:
|
||||
{
|
||||
@ -420,7 +434,7 @@ void MapWidget::paintEvent(QPaintEvent *event)
|
||||
}
|
||||
usage << "u: Show/hide user interface";
|
||||
usage << "m: Add a marker";
|
||||
usage << "Alt+m: Show/hide all marker";
|
||||
usage << "l: Show/hide individual layers";
|
||||
usage << "tab: Show/hide marker list";
|
||||
if (m_networkMode) {
|
||||
usage << "d: Download tiles for visible area";
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QPoint>
|
||||
#include <QtGui/QMenu>
|
||||
#include <QtGui/QWidget>
|
||||
#include <QtNetwork/QNetworkAccessManager>
|
||||
|
||||
@ -34,7 +35,7 @@ public:
|
||||
MapWidget(QWidget *parent = 0);
|
||||
~MapWidget();
|
||||
|
||||
void addLayer(AbstractLayer *layer, int z);
|
||||
void addLayer(AbstractLayer *layer, int z, const QString &name);
|
||||
|
||||
QRectF geoRect() const;
|
||||
QPointF geoPos() const;
|
||||
@ -95,6 +96,7 @@ private:
|
||||
bool m_networkMode;
|
||||
QString m_copyright;
|
||||
QMap<int, AbstractLayer *> m_layer;
|
||||
QMenu *m_layerMenu;
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user