mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 03:35:53 +01:00
Added the "Load map dir" feature
This commit is contained in:
parent
8d52dbf59f
commit
9e70a1ffbb
@ -22,7 +22,9 @@ HEADERS += src/common/config.h \
|
||||
src/GUI/axislabelitem.h \
|
||||
src/GUI/graphicsscene.h \
|
||||
src/GUI/mapaction.h \
|
||||
src/GUI/mapitem.h \
|
||||
src/GUI/marginswidget.h \
|
||||
src/GUI/planeitem.h \
|
||||
src/GUI/popup.h \
|
||||
src/common/garmin.h \
|
||||
src/common/staticassert.h \
|
||||
@ -207,6 +209,7 @@ HEADERS += src/common/config.h \
|
||||
src/GUI/pngexportdialog.h
|
||||
SOURCES += src/main.cpp \
|
||||
src/GUI/axislabelitem.cpp \
|
||||
src/GUI/mapitem.cpp \
|
||||
src/GUI/marginswidget.cpp \
|
||||
src/GUI/popup.cpp \
|
||||
src/common/coordinates.cpp \
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include "map/map.h"
|
||||
#include "popup.h"
|
||||
#include "tooltip.h"
|
||||
#include "areaitem.h"
|
||||
|
||||
|
||||
@ -22,7 +23,7 @@ QString AreaItem::info() const
|
||||
}
|
||||
|
||||
AreaItem::AreaItem(const Area &area, Map *map, GraphicsItem *parent)
|
||||
: GraphicsItem(parent), _area(area)
|
||||
: PlaneItem(parent), _area(area)
|
||||
{
|
||||
_map = map;
|
||||
_digitalZoom = 0;
|
||||
@ -158,7 +159,6 @@ void AreaItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
Q_UNUSED(event);
|
||||
|
||||
_pen.setWidthF((_width + 1) * pow(2, -_digitalZoom));
|
||||
setZValue(zValue() + 1.0);
|
||||
update();
|
||||
}
|
||||
|
||||
@ -167,12 +167,5 @@ void AreaItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||
Q_UNUSED(event);
|
||||
|
||||
_pen.setWidthF(_width * pow(2, -_digitalZoom));
|
||||
setZValue(zValue() - 1.0);
|
||||
update();
|
||||
}
|
||||
|
||||
void AreaItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
Popup::show(event->screenPos(), info(), event->widget());
|
||||
QGraphicsItem::mousePressEvent(event);
|
||||
}
|
||||
|
@ -2,12 +2,9 @@
|
||||
#define AREAITEM_H
|
||||
|
||||
#include "data/area.h"
|
||||
#include "graphicsscene.h"
|
||||
#include "tooltip.h"
|
||||
#include "planeitem.h"
|
||||
|
||||
class Map;
|
||||
|
||||
class AreaItem : public GraphicsItem
|
||||
class AreaItem : public PlaneItem
|
||||
{
|
||||
public:
|
||||
AreaItem(const Area &area, Map *map, GraphicsItem *parent = 0);
|
||||
@ -19,6 +16,7 @@ public:
|
||||
|
||||
const Area &area() const {return _area;}
|
||||
|
||||
RectC bounds() const {return _area.boundingRect();}
|
||||
void setMap(Map *map);
|
||||
|
||||
void setColor(const QColor &color);
|
||||
@ -27,17 +25,15 @@ public:
|
||||
void setStyle(Qt::PenStyle style);
|
||||
void setDigitalZoom(int zoom);
|
||||
|
||||
virtual QString info() const;
|
||||
QString info() const;
|
||||
|
||||
protected:
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
private:
|
||||
QPainterPath painterPath(const Polygon &polygon);
|
||||
void updatePainterPath();
|
||||
ToolTip toolTip() const;
|
||||
|
||||
Area _area;
|
||||
Map *_map;
|
||||
|
@ -51,6 +51,7 @@
|
||||
#include "graphtab.h"
|
||||
#include "graphitem.h"
|
||||
#include "pathitem.h"
|
||||
#include "mapitem.h"
|
||||
#include "mapaction.h"
|
||||
#include "gui.h"
|
||||
|
||||
@ -306,10 +307,14 @@ void GUI::createActions()
|
||||
this);
|
||||
_loadMapAction->setMenuRole(QAction::NoRole);
|
||||
connect(_loadMapAction, SIGNAL(triggered()), this, SLOT(loadMap()));
|
||||
_loadMapDirAction = new QAction(QIcon(OPEN_FILE_ICON),
|
||||
tr("Load map directory..."), this);
|
||||
_loadMapDirAction->setMenuRole(QAction::NoRole);
|
||||
connect(_loadMapDirAction, SIGNAL(triggered()), this, SLOT(loadMapDir()));
|
||||
_clearMapCacheAction = new QAction(tr("Clear tile cache"), this);
|
||||
_clearMapCacheAction->setEnabled(false);
|
||||
_clearMapCacheAction->setMenuRole(QAction::NoRole);
|
||||
connect(_clearMapCacheAction, SIGNAL(triggered()), _mapView,
|
||||
connect(_clearMapCacheAction, SIGNAL(triggered()), this,
|
||||
SLOT(clearMapCache()));
|
||||
_nextMapAction = new QAction(tr("Next map"), this);
|
||||
_nextMapAction->setMenuRole(QAction::NoRole);
|
||||
@ -519,6 +524,7 @@ void GUI::createMenus()
|
||||
_mapMenu->addActions(_mapsActionGroup->actions());
|
||||
_mapsEnd = _mapMenu->addSeparator();
|
||||
_mapMenu->addAction(_loadMapAction);
|
||||
_mapMenu->addAction(_loadMapDirAction);
|
||||
_mapMenu->addAction(_clearMapCacheAction);
|
||||
_mapMenu->addSeparator();
|
||||
_mapMenu->addAction(_showCoordinatesAction);
|
||||
@ -774,7 +780,9 @@ bool GUI::openFile(const QString &fileName)
|
||||
if (fileName.isEmpty() || _files.contains(fileName))
|
||||
return false;
|
||||
|
||||
if (loadFile(fileName)) {
|
||||
if (!loadFile(fileName))
|
||||
return false;
|
||||
|
||||
_files.append(fileName);
|
||||
_browser->setCurrent(fileName);
|
||||
_fileActionGroup->setEnabled(true);
|
||||
@ -785,12 +793,6 @@ bool GUI::openFile(const QString &fileName)
|
||||
updateWindowTitle();
|
||||
|
||||
return true;
|
||||
} else {
|
||||
if (_files.isEmpty())
|
||||
_fileActionGroup->setEnabled(false);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool GUI::loadFile(const QString &fileName)
|
||||
@ -1453,18 +1455,22 @@ bool GUI::loadMap(const QString &fileName)
|
||||
return false;
|
||||
}
|
||||
|
||||
MapAction *lastReady = 0;
|
||||
for (int i = 0; i < maps.size(); i++) {
|
||||
Map *map = maps.at(i);
|
||||
MapAction *a = createMapAction(map);
|
||||
_mapMenu->insertAction(_mapsEnd, a);
|
||||
if (map->isReady()) {
|
||||
a->trigger();
|
||||
lastReady = a;
|
||||
_showMapAction->setEnabled(true);
|
||||
_clearMapCacheAction->setEnabled(true);
|
||||
} else
|
||||
connect(a, SIGNAL(loaded()), this, SLOT(mapLoaded()));
|
||||
}
|
||||
|
||||
if (lastReady)
|
||||
lastReady->trigger();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1485,6 +1491,52 @@ void GUI::mapLoaded()
|
||||
}
|
||||
}
|
||||
|
||||
void GUI::loadMapDir()
|
||||
{
|
||||
QString dir = QFileDialog::getExistingDirectory(this,
|
||||
tr("Select maps directory"), _mapDir, QFileDialog::ShowDirsOnly);
|
||||
if (dir.isEmpty())
|
||||
return;
|
||||
|
||||
QString error;
|
||||
QList<Map*> maps(MapList::loadMaps(dir, error));
|
||||
if (maps.isEmpty()) {
|
||||
QMessageBox::critical(this, APP_NAME, tr("No usable map found"));
|
||||
return;
|
||||
}
|
||||
|
||||
QList<MapItem*> items(_mapView->loadMaps(maps));
|
||||
|
||||
QFileInfo fi(dir);
|
||||
QMenu *menu = new QMenu(fi.fileName());
|
||||
_mapMenu->insertMenu(_mapsEnd, menu);
|
||||
|
||||
for (int i = 0; i < maps.size(); i++) {
|
||||
Map *map = maps.at(i);
|
||||
MapAction *a = createMapAction(map);
|
||||
menu->addAction(a);
|
||||
if (map->isReady()) {
|
||||
_showMapAction->setEnabled(true);
|
||||
_clearMapCacheAction->setEnabled(true);
|
||||
} else
|
||||
connect(a, SIGNAL(loaded()), this, SLOT(mapLoaded()));
|
||||
|
||||
connect(items.at(i), SIGNAL(triggered()), a, SLOT(trigger()));
|
||||
}
|
||||
|
||||
_mapDir = fi.absolutePath();
|
||||
_areaCount += maps.size();
|
||||
_fileActionGroup->setEnabled(true);
|
||||
_reloadFileAction->setEnabled(false);
|
||||
}
|
||||
|
||||
void GUI::clearMapCache()
|
||||
{
|
||||
if (QMessageBox::question(this, APP_NAME,
|
||||
tr("Clear the map tile cache?")) == QMessageBox::Yes)
|
||||
_mapView->clearMapCache();
|
||||
}
|
||||
|
||||
void GUI::updateStatusBarInfo()
|
||||
{
|
||||
if (_files.count() == 0)
|
||||
|
@ -62,9 +62,11 @@ private slots:
|
||||
void showTracks(bool show);
|
||||
void showRoutes(bool show);
|
||||
void loadMap();
|
||||
void loadMapDir();
|
||||
void nextMap();
|
||||
void prevMap();
|
||||
void openOptions();
|
||||
void clearMapCache();
|
||||
|
||||
void mapChanged();
|
||||
void graphChanged(int);
|
||||
@ -172,6 +174,7 @@ private:
|
||||
QAction *_showMapAction;
|
||||
QAction *_fullscreenAction;
|
||||
QAction *_loadMapAction;
|
||||
QAction *_loadMapDirAction;
|
||||
QAction *_clearMapCacheAction;
|
||||
QAction *_showGraphsAction;
|
||||
QAction *_showGraphGridAction;
|
||||
|
169
src/GUI/mapitem.cpp
Normal file
169
src/GUI/mapitem.cpp
Normal file
@ -0,0 +1,169 @@
|
||||
#include <QCursor>
|
||||
#include <QPainter>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include "map/map.h"
|
||||
#include "popup.h"
|
||||
#include "tooltip.h"
|
||||
#include "mapitem.h"
|
||||
|
||||
|
||||
QString MapItem::info() const
|
||||
{
|
||||
ToolTip tt;
|
||||
|
||||
if (!_name.isEmpty())
|
||||
tt.insert(tr("Name"), _name);
|
||||
if (!_fileName.isEmpty())
|
||||
tt.insert(tr("File"), _fileName);
|
||||
|
||||
return tt.toString();
|
||||
}
|
||||
|
||||
MapItem::MapItem(Map *src, Map *map, GraphicsItem *parent)
|
||||
: PlaneItem(parent)
|
||||
{
|
||||
_name = src->name();
|
||||
_fileName = src->path();
|
||||
_bounds = RectC(src->xy2ll(src->bounds().topLeft()),
|
||||
src->xy2ll(src->bounds().bottomRight()));
|
||||
|
||||
_map = map;
|
||||
_digitalZoom = 0;
|
||||
|
||||
_width = 2;
|
||||
_opacity = 0.5;
|
||||
QBrush brush(Qt::SolidPattern);
|
||||
_pen = QPen(brush, _width);
|
||||
|
||||
updatePainterPath();
|
||||
|
||||
setCursor(Qt::ArrowCursor);
|
||||
setAcceptHoverEvents(true);
|
||||
}
|
||||
|
||||
void MapItem::updatePainterPath()
|
||||
{
|
||||
_painterPath = QPainterPath();
|
||||
|
||||
if (_bounds.left() > _bounds.right()) {
|
||||
QRectF r1(_map->ll2xy(_bounds.topLeft()), _map->ll2xy(Coordinates(180,
|
||||
_bounds.bottomRight().lat())));
|
||||
QRectF r2(_map->ll2xy(Coordinates(-180, _bounds.topLeft().lat())),
|
||||
_map->ll2xy(_bounds.bottomRight()));
|
||||
QRectF r(_map->ll2xy(_bounds.topLeft()),
|
||||
_map->ll2xy(_bounds.bottomRight()));
|
||||
|
||||
if (r1.united(r2) == r)
|
||||
_painterPath.addRect(r);
|
||||
else {
|
||||
_painterPath.addRect(r1);
|
||||
_painterPath.addRect(r2);
|
||||
}
|
||||
} else
|
||||
_painterPath.addRect(QRectF(_map->ll2xy(_bounds.topLeft()),
|
||||
_map->ll2xy(_bounds.bottomRight())));
|
||||
}
|
||||
|
||||
void MapItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(option);
|
||||
Q_UNUSED(widget);
|
||||
|
||||
painter->setPen(_width ? _pen : QPen(Qt::NoPen));
|
||||
painter->drawPath(_painterPath);
|
||||
painter->fillPath(_painterPath, _brush);
|
||||
|
||||
//QPen p = QPen(QBrush(Qt::red), 0);
|
||||
//painter->setPen(p);
|
||||
//painter->drawRect(boundingRect());
|
||||
}
|
||||
|
||||
void MapItem::setMap(Map *map)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
|
||||
_map = map;
|
||||
|
||||
updatePainterPath();
|
||||
}
|
||||
|
||||
void MapItem::setColor(const QColor &color)
|
||||
{
|
||||
if (_pen.color() == color)
|
||||
return;
|
||||
|
||||
QColor bc(color);
|
||||
bc.setAlphaF(_opacity * color.alphaF());
|
||||
|
||||
_pen.setColor(color);
|
||||
_brush = QBrush(bc);
|
||||
update();
|
||||
}
|
||||
|
||||
void MapItem::setOpacity(qreal opacity)
|
||||
{
|
||||
if (_opacity == opacity)
|
||||
return;
|
||||
|
||||
_opacity = opacity;
|
||||
QColor bc(_pen.color());
|
||||
bc.setAlphaF(_opacity * _pen.color().alphaF());
|
||||
_brush = QBrush(bc);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void MapItem::setWidth(qreal width)
|
||||
{
|
||||
if (_width == width)
|
||||
return;
|
||||
|
||||
prepareGeometryChange();
|
||||
|
||||
_width = width;
|
||||
_pen.setWidthF(_width * pow(2, -_digitalZoom));
|
||||
}
|
||||
|
||||
void MapItem::setStyle(Qt::PenStyle style)
|
||||
{
|
||||
if (_pen.style() == style)
|
||||
return;
|
||||
|
||||
_pen.setStyle(style);
|
||||
update();
|
||||
}
|
||||
|
||||
void MapItem::setDigitalZoom(int zoom)
|
||||
{
|
||||
if (_digitalZoom == zoom)
|
||||
return;
|
||||
|
||||
prepareGeometryChange();
|
||||
|
||||
_digitalZoom = zoom;
|
||||
_pen.setWidthF(_width * pow(2, -_digitalZoom));
|
||||
}
|
||||
|
||||
void MapItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
|
||||
_pen.setWidthF((_width + 1) * pow(2, -_digitalZoom));
|
||||
update();
|
||||
}
|
||||
|
||||
void MapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
|
||||
_pen.setWidthF(_width * pow(2, -_digitalZoom));
|
||||
update();
|
||||
}
|
||||
|
||||
void MapItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
|
||||
emit triggered();
|
||||
}
|
55
src/GUI/mapitem.h
Normal file
55
src/GUI/mapitem.h
Normal file
@ -0,0 +1,55 @@
|
||||
#ifndef MAPITEM_H
|
||||
#define MAPITEM_H
|
||||
|
||||
#include "planeitem.h"
|
||||
|
||||
class MapItem : public QObject, public PlaneItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MapItem(Map *src, Map *map, GraphicsItem *parent = 0);
|
||||
|
||||
QPainterPath shape() const {return _painterPath;}
|
||||
QRectF boundingRect() const {return _painterPath.boundingRect();}
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget);
|
||||
|
||||
RectC bounds() const {return _bounds;}
|
||||
void setMap(Map *map);
|
||||
|
||||
void setColor(const QColor &color);
|
||||
void setOpacity(qreal opacity);
|
||||
void setWidth(qreal width);
|
||||
void setStyle(Qt::PenStyle style);
|
||||
void setDigitalZoom(int zoom);
|
||||
|
||||
QString info() const;
|
||||
|
||||
signals:
|
||||
void triggered();
|
||||
|
||||
protected:
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
private:
|
||||
void updatePainterPath();
|
||||
|
||||
RectC _bounds;
|
||||
QString _name;
|
||||
QString _fileName;
|
||||
|
||||
Map *_map;
|
||||
int _digitalZoom;
|
||||
|
||||
qreal _width;
|
||||
QPen _pen;
|
||||
QBrush _brush;
|
||||
qreal _opacity;
|
||||
|
||||
QPainterPath _painterPath;
|
||||
};
|
||||
|
||||
#endif // MAPITEM_H
|
@ -15,6 +15,7 @@
|
||||
#include "areaitem.h"
|
||||
#include "scaleitem.h"
|
||||
#include "coordinatesitem.h"
|
||||
#include "mapitem.h"
|
||||
#include "keys.h"
|
||||
#include "graphicsscene.h"
|
||||
#include "mapview.h"
|
||||
@ -27,6 +28,20 @@
|
||||
#define COORDINATES_OFFSET SCALE_OFFSET
|
||||
|
||||
|
||||
template<typename T>
|
||||
static void updateZValues(T &items)
|
||||
{
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
const QGraphicsItem *ai = items.at(i);
|
||||
for (int j = 0; j < items.size(); j++) {
|
||||
QGraphicsItem *aj = items[j];
|
||||
if (aj->boundingRect().contains(ai->boundingRect()))
|
||||
aj->setZValue(qMin(ai->zValue() - 1, aj->zValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MapView::MapView(Map *map, POI *poi, QWidget *parent)
|
||||
: QGraphicsView(parent)
|
||||
{
|
||||
@ -170,18 +185,19 @@ void MapView::addArea(const Area &area)
|
||||
}
|
||||
|
||||
AreaItem *ai = new AreaItem(area, _map);
|
||||
_areas.append(ai);
|
||||
_ar |= ai->area().boundingRect();
|
||||
ai->setColor(_palette.nextColor());
|
||||
ai->setWidth(_areaWidth);
|
||||
ai->setStyle(_areaStyle);
|
||||
ai->setOpacity(_areaOpacity);
|
||||
ai->setDigitalZoom(_digitalZoom);
|
||||
ai->setVisible(_showAreas);
|
||||
|
||||
_scene->addItem(ai);
|
||||
_ar |= ai->bounds();
|
||||
_areas.append(ai);
|
||||
|
||||
if (_showAreas)
|
||||
addPOI(_poi->points(ai->area()));
|
||||
addPOI(_poi->points(ai->bounds()));
|
||||
}
|
||||
|
||||
void MapView::addWaypoints(const QVector<Waypoint> &waypoints)
|
||||
@ -205,6 +221,26 @@ void MapView::addWaypoints(const QVector<Waypoint> &waypoints)
|
||||
}
|
||||
}
|
||||
|
||||
MapItem *MapView::addMap(Map *map)
|
||||
{
|
||||
MapItem *mi = new MapItem(map, _map);
|
||||
mi->setColor(_palette.nextColor());
|
||||
mi->setWidth(_areaWidth);
|
||||
mi->setStyle(_areaStyle);
|
||||
mi->setOpacity(_areaOpacity);
|
||||
mi->setDigitalZoom(_digitalZoom);
|
||||
mi->setVisible(_showAreas);
|
||||
|
||||
_scene->addItem(mi);
|
||||
_ar |= mi->bounds();
|
||||
_areas.append(mi);
|
||||
|
||||
if (_showAreas)
|
||||
addPOI(_poi->points(mi->bounds()));
|
||||
|
||||
return mi;
|
||||
}
|
||||
|
||||
QList<PathItem *> MapView::loadData(const Data &data)
|
||||
{
|
||||
QList<PathItem *> paths;
|
||||
@ -227,11 +263,34 @@ QList<PathItem *> MapView::loadData(const Data &data)
|
||||
else
|
||||
updatePOIVisibility();
|
||||
|
||||
if (!data.areas().isEmpty())
|
||||
updateZValues(_areas);
|
||||
|
||||
centerOn(contentCenter());
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
QList<MapItem *> MapView::loadMaps(const QList<Map*> &maps)
|
||||
{
|
||||
QList<MapItem *> items;
|
||||
int zoom = _map->zoom();
|
||||
|
||||
for (int i = 0; i < maps.size(); i++)
|
||||
items.append(addMap(maps.at(i)));
|
||||
|
||||
if (fitMapZoom() != zoom)
|
||||
rescale();
|
||||
else
|
||||
updatePOIVisibility();
|
||||
|
||||
updateZValues(_areas);
|
||||
|
||||
centerOn(contentCenter());
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
int MapView::fitMapZoom() const
|
||||
{
|
||||
RectC br = _tr | _rr | _wr | _ar;
|
||||
@ -373,7 +432,7 @@ void MapView::updatePOI()
|
||||
addPOI(_poi->points(_routes.at(i)->path()));
|
||||
if (_showAreas)
|
||||
for (int i = 0; i < _areas.size(); i++)
|
||||
addPOI(_poi->points(_areas.at(i)->area()));
|
||||
addPOI(_poi->points(_areas.at(i)->bounds()));
|
||||
if (_showWaypoints)
|
||||
for (int i = 0; i< _waypoints.size(); i++)
|
||||
addPOI(_poi->points(_waypoints.at(i)->waypoint()));
|
||||
@ -504,6 +563,10 @@ void MapView::wheelEvent(QWheelEvent *event)
|
||||
|
||||
void MapView::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
QGraphicsView::mouseDoubleClickEvent(event);
|
||||
if (event->isAccepted())
|
||||
return;
|
||||
|
||||
if (event->button() != Qt::LeftButton && event->button() != Qt::RightButton)
|
||||
return;
|
||||
|
||||
|
@ -29,7 +29,8 @@ class ScaleItem;
|
||||
class CoordinatesItem;
|
||||
class PathItem;
|
||||
class GraphItem;
|
||||
class AreaItem;
|
||||
class PlaneItem;
|
||||
class MapItem;
|
||||
class Area;
|
||||
class GraphicsScene;
|
||||
class QTimeZone;
|
||||
@ -49,6 +50,7 @@ public:
|
||||
MapView(Map *map, POI *poi, QWidget *parent = 0);
|
||||
|
||||
QList<PathItem *> loadData(const Data &data);
|
||||
QList<MapItem *> loadMaps(const QList<Map*> &maps);
|
||||
|
||||
void setPalette(const Palette &palette);
|
||||
void setPOI(POI *poi);
|
||||
@ -108,6 +110,7 @@ private:
|
||||
|
||||
PathItem *addTrack(const Track &track);
|
||||
PathItem *addRoute(const Route &route);
|
||||
MapItem *addMap(Map *map);
|
||||
void addArea(const Area &area);
|
||||
void addWaypoints(const QVector<Waypoint> &waypoints);
|
||||
void addPOI(const QList<Waypoint> &waypoints);
|
||||
@ -140,7 +143,7 @@ private:
|
||||
QList<TrackItem*> _tracks;
|
||||
QList<RouteItem*> _routes;
|
||||
QList<WaypointItem*> _waypoints;
|
||||
QList<AreaItem*> _areas;
|
||||
QList<PlaneItem*> _areas;
|
||||
POIHash _pois;
|
||||
|
||||
RectC _tr, _rr, _wr, _ar;
|
||||
|
24
src/GUI/planeitem.h
Normal file
24
src/GUI/planeitem.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef PLANEITEM_H
|
||||
#define PLANEITEM_H
|
||||
|
||||
#include "common/rectc.h"
|
||||
#include "graphicsscene.h"
|
||||
|
||||
class Map;
|
||||
|
||||
class PlaneItem : public GraphicsItem
|
||||
{
|
||||
public:
|
||||
PlaneItem(GraphicsItem *parent = 0) : GraphicsItem(parent) {}
|
||||
|
||||
virtual RectC bounds() const = 0;
|
||||
virtual void setMap(Map *map) = 0;
|
||||
|
||||
virtual void setColor(const QColor &color) = 0;
|
||||
virtual void setOpacity(qreal opacity) = 0;
|
||||
virtual void setWidth(qreal width) = 0;
|
||||
virtual void setStyle(Qt::PenStyle style) = 0;
|
||||
virtual void setDigitalZoom(int zoom) = 0;
|
||||
};
|
||||
|
||||
#endif // PLANEITEM_H
|
@ -16,7 +16,7 @@ public:
|
||||
{return _tl.isNull() && _br.isNull();}
|
||||
bool isValid() const
|
||||
{return (_tl.isValid() && _br.isValid()
|
||||
&& _tl.lat() > _br.lat() && _tl.lon() < _br.lon());}
|
||||
&& _tl.lat() != _br.lat() && _tl.lon() != _br.lon());}
|
||||
|
||||
Coordinates topLeft() const {return _tl;}
|
||||
Coordinates bottomRight() const {return _br;}
|
||||
@ -29,9 +29,6 @@ public:
|
||||
double left() const {return _tl.lon();}
|
||||
double right() const {return _br.lon();}
|
||||
|
||||
double width() const {return (right() - left());}
|
||||
double height() const {return (top() - bottom());}
|
||||
|
||||
void setLeft(double val) {_tl.rlon() = val;}
|
||||
void setRight(double val) {_br.rlon() = val;}
|
||||
void setTop(double val) {_tl.rlat() = val;}
|
||||
|
@ -8,6 +8,19 @@
|
||||
class Area : public QList<Polygon>
|
||||
{
|
||||
public:
|
||||
Area() {}
|
||||
Area(const RectC &rect)
|
||||
{
|
||||
Polygon polygon;
|
||||
QVector<Coordinates> v(4);
|
||||
v[0] = Coordinates(rect.left(), rect.top());
|
||||
v[1] = Coordinates(rect.right(), rect.top());
|
||||
v[2] = Coordinates(rect.right(), rect.bottom());
|
||||
v[3] = Coordinates(rect.left(), rect.bottom());
|
||||
polygon.append(v);
|
||||
append(polygon);
|
||||
}
|
||||
|
||||
const QString& name() const {return _name;}
|
||||
const QString& description() const {return _desc;}
|
||||
void setName(const QString &name) {_name = name;}
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "cupparser.h"
|
||||
#include "gpiparser.h"
|
||||
#include "smlparser.h"
|
||||
#include "map/map.h"
|
||||
#include "data.h"
|
||||
|
||||
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include "route.h"
|
||||
#include "parser.h"
|
||||
|
||||
|
||||
class Data
|
||||
{
|
||||
public:
|
||||
|
@ -485,15 +485,8 @@ static quint32 readCamera(QDataStream &stream, QVector<Waypoint> &waypoints,
|
||||
|
||||
waypoints.append(Coordinates(toWGS24(lon), toWGS24(lat)));
|
||||
|
||||
Area area;
|
||||
Polygon polygon;
|
||||
QVector<Coordinates> v(4);
|
||||
v[0] = Coordinates(toWGS24(left), toWGS24(top));
|
||||
v[1] = Coordinates(toWGS24(right), toWGS24(top));
|
||||
v[2] = Coordinates(toWGS24(right), toWGS24(bottom));
|
||||
v[3] = Coordinates(toWGS24(left), toWGS24(bottom));
|
||||
polygon.append(v);
|
||||
area.append(polygon);
|
||||
Area area(RectC(Coordinates(toWGS24(left), toWGS24(top)),
|
||||
Coordinates(toWGS24(right), toWGS24(bottom))));
|
||||
|
||||
switch (type) {
|
||||
case 8:
|
||||
|
@ -147,20 +147,19 @@ QList<Waypoint> POI::points(const Waypoint &point) const
|
||||
return ret;
|
||||
}
|
||||
|
||||
QList<Waypoint> POI::points(const Area &area) const
|
||||
QList<Waypoint> POI::points(const RectC &rect) const
|
||||
{
|
||||
QList<Waypoint> ret;
|
||||
qreal min[2], max[2];
|
||||
QSet<int> set;
|
||||
QSet<int>::const_iterator it;
|
||||
|
||||
RectC br(area.boundingRect());
|
||||
double offset = rad2deg(_radius / WGS84_RADIUS);
|
||||
|
||||
min[0] = br.topLeft().lon() - offset;
|
||||
min[1] = br.bottomRight().lat() - offset;
|
||||
max[0] = br.bottomRight().lon() + offset;
|
||||
max[1] = br.topLeft().lat() + offset;
|
||||
min[0] = rect.topLeft().lon() - offset;
|
||||
min[1] = rect.bottomRight().lat() - offset;
|
||||
max[0] = rect.bottomRight().lon() + offset;
|
||||
max[1] = rect.topLeft().lat() + offset;
|
||||
|
||||
_tree.Search(min, max, cb, &set);
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include "waypoint.h"
|
||||
|
||||
class Path;
|
||||
class Area;
|
||||
class RectC;
|
||||
|
||||
class POI : public QObject
|
||||
@ -29,7 +28,7 @@ public:
|
||||
|
||||
QList<Waypoint> points(const Path &path) const;
|
||||
QList<Waypoint> points(const Waypoint &point) const;
|
||||
QList<Waypoint> points(const Area &area) const;
|
||||
QList<Waypoint> points(const RectC &rect) const;
|
||||
|
||||
const QStringList &files() const {return _files;}
|
||||
void enableFile(const QString &fileName, bool enable);
|
||||
|
@ -78,7 +78,7 @@ void Atlas::computeBounds()
|
||||
}
|
||||
|
||||
Atlas::Atlas(const QString &fileName, QObject *parent)
|
||||
: Map(parent), _zoom(0), _mapIndex(-1), _valid(false)
|
||||
: Map(fileName, parent), _zoom(0), _mapIndex(-1), _valid(false)
|
||||
{
|
||||
QFileInfo fi(fileName);
|
||||
QByteArray ba;
|
||||
|
@ -388,8 +388,8 @@ QImage BSBMap::readImage()
|
||||
}
|
||||
|
||||
BSBMap::BSBMap(const QString &fileName, QObject *parent)
|
||||
: Map(parent), _fileName(fileName), _img(0), _ratio(1.0), _dataOffset(-1),
|
||||
_valid(false)
|
||||
: Map(fileName, parent), _fileName(fileName), _img(0), _ratio(1.0),
|
||||
_dataOffset(-1), _valid(false)
|
||||
{
|
||||
QFile file(fileName);
|
||||
|
||||
|
@ -18,7 +18,7 @@ static int limitZoom(int zoom)
|
||||
}
|
||||
|
||||
|
||||
EmptyMap::EmptyMap(QObject *parent) : Map(parent)
|
||||
EmptyMap::EmptyMap(QObject *parent) : Map(QString(), parent)
|
||||
{
|
||||
_zoom = OSM::ZOOMS.max();
|
||||
}
|
||||
|
@ -7,7 +7,8 @@
|
||||
|
||||
|
||||
GeoTIFFMap::GeoTIFFMap(const QString &fileName, QObject *parent)
|
||||
: Map(parent), _fileName(fileName), _img(0), _ratio(1.0), _valid(false)
|
||||
: Map(fileName, parent), _fileName(fileName), _img(0), _ratio(1.0),
|
||||
_valid(false)
|
||||
{
|
||||
QImageReader ir(fileName);
|
||||
if (!ir.canRead()) {
|
||||
|
@ -44,7 +44,7 @@ static QList<MapData*> overlays(const QString &fileName)
|
||||
}
|
||||
|
||||
IMGMap::IMGMap(const QString &fileName, QObject *parent)
|
||||
: Map(parent), _projection(PCS::pcs(3857)), _valid(false)
|
||||
: Map(fileName, parent), _projection(PCS::pcs(3857)), _valid(false)
|
||||
{
|
||||
if (GMAP::isGMAP(fileName))
|
||||
_data.append(new GMAP(fileName));
|
||||
|
@ -139,7 +139,8 @@ bool JNXMap::readTiles()
|
||||
}
|
||||
|
||||
JNXMap::JNXMap(const QString &fileName, QObject *parent)
|
||||
: Map(parent), _file(fileName), _zoom(0), _mapRatio(1.0), _valid(false)
|
||||
: Map(fileName, parent), _file(fileName), _zoom(0), _mapRatio(1.0),
|
||||
_valid(false)
|
||||
{
|
||||
_name = QFileInfo(fileName).fileName();
|
||||
|
||||
|
@ -24,9 +24,11 @@ public:
|
||||
};
|
||||
Q_DECLARE_FLAGS(Flags, Flag)
|
||||
|
||||
Map(QObject *parent = 0) : QObject(parent) {}
|
||||
Map(const QString &path, QObject *parent = 0)
|
||||
: QObject(parent), _path(path) {}
|
||||
virtual ~Map() {}
|
||||
|
||||
const QString &path() const {return _path;}
|
||||
virtual QString name() const = 0;
|
||||
|
||||
virtual QRectF bounds() = 0;
|
||||
@ -56,6 +58,9 @@ public:
|
||||
signals:
|
||||
void tilesLoaded();
|
||||
void mapLoaded();
|
||||
|
||||
private:
|
||||
QString _path;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(Map*)
|
||||
|
@ -293,24 +293,25 @@ Map *MapSource::loadMap(const QString &path, QString &errorString)
|
||||
|
||||
switch (config.type) {
|
||||
case WMTS:
|
||||
return new WMTSMap(config.name, WMTS::Setup(config.url, config.layer,
|
||||
config.set, config.style, config.format, config.rest,
|
||||
return new WMTSMap(path, config.name, WMTS::Setup(config.url,
|
||||
config.layer, config.set, config.style, config.format, config.rest,
|
||||
config.coordinateSystem, config.dimensions, config.authorization),
|
||||
config.tileRatio);
|
||||
case WMS:
|
||||
return new WMSMap(config.name, WMS::Setup(config.url, config.layer,
|
||||
config.style, config.format, config.crs, config.coordinateSystem,
|
||||
config.dimensions, config.authorization), config.tileSize);
|
||||
return new WMSMap(path, config.name, WMS::Setup(config.url,
|
||||
config.layer, config.style, config.format, config.crs,
|
||||
config.coordinateSystem, config.dimensions, config.authorization),
|
||||
config.tileSize);
|
||||
case TMS:
|
||||
return new OnlineMap(config.name, config.url, config.zooms,
|
||||
return new OnlineMap(path, config.name, config.url, config.zooms,
|
||||
config.bounds, config.tileRatio, config.authorization,
|
||||
config.tileSize, config.scalable, true, false);
|
||||
case OSM:
|
||||
return new OnlineMap(config.name, config.url, config.zooms,
|
||||
return new OnlineMap(path, config.name, config.url, config.zooms,
|
||||
config.bounds, config.tileRatio, config.authorization,
|
||||
config.tileSize, config.scalable, false, false);
|
||||
case QuadTiles:
|
||||
return new OnlineMap(config.name, config.url, config.zooms,
|
||||
return new OnlineMap(path, config.name, config.url, config.zooms,
|
||||
config.bounds, config.tileRatio, config.authorization,
|
||||
config.tileSize, config.scalable, false, true);
|
||||
default:
|
||||
|
@ -55,7 +55,7 @@ static double index2mercator(int index, int zoom)
|
||||
}
|
||||
|
||||
MBTilesMap::MBTilesMap(const QString &fileName, QObject *parent)
|
||||
: Map(parent), _fileName(fileName), _mapRatio(1.0), _tileRatio(1.0),
|
||||
: Map(fileName, parent), _fileName(fileName), _mapRatio(1.0), _tileRatio(1.0),
|
||||
_scalable(false), _scaledSize(0), _valid(false)
|
||||
{
|
||||
_db = QSqlDatabase::addDatabase("QSQLITE", fileName);
|
||||
|
@ -8,11 +8,11 @@
|
||||
#include "onlinemap.h"
|
||||
|
||||
|
||||
OnlineMap::OnlineMap(const QString &name, const QString &url,
|
||||
const Range &zooms, const RectC &bounds, qreal tileRatio,
|
||||
OnlineMap::OnlineMap(const QString &fileName, const QString &name,
|
||||
const QString &url, const Range &zooms, const RectC &bounds, qreal tileRatio,
|
||||
const Authorization &authorization, int tileSize, bool scalable, bool invertY,
|
||||
bool quadTiles, QObject *parent)
|
||||
: Map(parent), _name(name), _zooms(zooms), _bounds(bounds),
|
||||
: Map(fileName, parent), _name(name), _zooms(zooms), _bounds(bounds),
|
||||
_zoom(_zooms.max()), _mapRatio(1.0), _tileRatio(tileRatio),
|
||||
_tileSize(tileSize), _scalable(scalable), _invertY(invertY)
|
||||
{
|
||||
|
@ -11,10 +11,10 @@ class OnlineMap : public Map
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
OnlineMap(const QString &name, const QString &url, const Range &zooms,
|
||||
const RectC &bounds, qreal tileRatio, const Authorization &authorization,
|
||||
int tileSize, bool scalable, bool invertY, bool quadTiles,
|
||||
QObject *parent = 0);
|
||||
OnlineMap(const QString &fileName, const QString &name, const QString &url,
|
||||
const Range &zooms, const RectC &bounds, qreal tileRatio,
|
||||
const Authorization &authorization, int tileSize, bool scalable,
|
||||
bool invertY, bool quadTiles, QObject *parent = 0);
|
||||
|
||||
QString name() const {return _name;}
|
||||
|
||||
|
@ -17,7 +17,8 @@
|
||||
|
||||
|
||||
OziMap::OziMap(const QString &fileName, QObject *parent)
|
||||
: Map(parent), _img(0), _tar(0), _ozf(0), _zoom(0), _mapRatio(1.0), _valid(false)
|
||||
: Map(fileName, parent), _img(0), _tar(0), _ozf(0), _zoom(0), _mapRatio(1.0),
|
||||
_valid(false)
|
||||
{
|
||||
QFileInfo fi(fileName);
|
||||
QString suffix = fi.suffix().toLower();
|
||||
@ -79,7 +80,8 @@ OziMap::OziMap(const QString &fileName, QObject *parent)
|
||||
}
|
||||
|
||||
OziMap::OziMap(const QString &fileName, Tar &tar, QObject *parent)
|
||||
: Map(parent), _img(0), _tar(0), _ozf(0), _zoom(0), _mapRatio(1.0), _valid(false)
|
||||
: Map(fileName, parent), _img(0), _tar(0), _ozf(0), _zoom(0), _mapRatio(1.0),
|
||||
_valid(false)
|
||||
{
|
||||
QFileInfo fi(fileName);
|
||||
QFileInfo map(fi.absolutePath());
|
||||
|
@ -161,7 +161,8 @@ bool RMap::parseIMP(const QByteArray &data)
|
||||
}
|
||||
|
||||
RMap::RMap(const QString &fileName, QObject *parent)
|
||||
: Map(parent), _mapRatio(1.0), _fileName(fileName), _zoom(0), _valid(false)
|
||||
: Map(fileName, parent), _mapRatio(1.0), _fileName(fileName), _zoom(0),
|
||||
_valid(false)
|
||||
{
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
|
@ -67,8 +67,9 @@ void WMSMap::updateTransform()
|
||||
PointD(pixelSpan, pixelSpan));
|
||||
}
|
||||
|
||||
WMSMap::WMSMap(const QString &name, const WMS::Setup &setup, int tileSize,
|
||||
QObject *parent) : Map(parent), _name(name), _tileLoader(0), _zoom(0),
|
||||
WMSMap::WMSMap(const QString &fileName, const QString &name,
|
||||
const WMS::Setup &setup, int tileSize, QObject *parent)
|
||||
: Map(fileName, parent), _name(name), _tileLoader(0), _zoom(0),
|
||||
_tileSize(tileSize), _mapRatio(1.0)
|
||||
{
|
||||
QString tilesDir(QDir(ProgramPaths::tilesDir()).filePath(_name));
|
||||
|
@ -14,8 +14,8 @@ class WMSMap : public Map
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
WMSMap(const QString &name, const WMS::Setup &setup, int tileSize,
|
||||
QObject *parent = 0);
|
||||
WMSMap(const QString &fileName, const QString &name, const WMS::Setup &setup,
|
||||
int tileSize, QObject *parent = 0);
|
||||
|
||||
QString name() const {return _name;}
|
||||
|
||||
|
@ -12,9 +12,10 @@
|
||||
|
||||
#define CAPABILITIES_FILE "capabilities.xml"
|
||||
|
||||
WMTSMap::WMTSMap(const QString &name, const WMTS::Setup &setup, qreal tileRatio,
|
||||
QObject *parent) : Map(parent), _name(name), _tileLoader(0), _zoom(0),
|
||||
_mapRatio(1.0), _tileRatio(tileRatio)
|
||||
WMTSMap::WMTSMap(const QString &fileName, const QString &name,
|
||||
const WMTS::Setup &setup, qreal tileRatio,
|
||||
QObject *parent) : Map(fileName, parent), _name(name), _tileLoader(0),
|
||||
_zoom(0), _mapRatio(1.0), _tileRatio(tileRatio)
|
||||
{
|
||||
QString tilesDir(QDir(ProgramPaths::tilesDir()).filePath(_name));
|
||||
|
||||
|
@ -14,8 +14,8 @@ class WMTSMap : public Map
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
WMTSMap(const QString &name, const WMTS::Setup &setup, qreal tileRatio,
|
||||
QObject *parent = 0);
|
||||
WMTSMap(const QString &fileName, const QString &name,
|
||||
const WMTS::Setup &setup, qreal tileRatio, QObject *parent = 0);
|
||||
|
||||
QString name() const {return _name;}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user