MapEngine::removeStackedTiles.
MapEngine::MapEngine(QObject *parent)
: QObject(parent)
- , m_zoomLevel(DEFAULT_ZOOM_LEVEL)
- , m_viewSize(QSize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT))
, m_centerTile(QPoint(UNDEFINED, UNDEFINED))
+ , m_viewSize(QSize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT))
+ , m_zoomLevel(DEFAULT_ZOOM_LEVEL)
{
m_mapScene = new MapScene(this);
void MapEngine::mapImageReceived(const QUrl &url, const QPixmap &pixmap)
{
//qDebug() << __PRETTY_FUNCTION__;
+
int zoom = UNDEFINED;
int x = UNDEFINED;
int y = UNDEFINED;
void MapEngine::calculateNewTiles(QPoint sceneCoordinate)
{
- //qDebug() << __PRETTY_FUNCTION__;
+// qDebug() << __PRETTY_FUNCTION__;
m_viewGrid = calculateGrid(sceneCoordinate);
removeTile(tile);
}
}
-
-// qDebug() << m_mapScene->items().count();
}
void MapEngine::removeStackedTiles(MapTile *newTile)
//qDebug() << __PRETTY_FUNCTION__;
QRectF newTileSceneRect = newTile->mapRectToScene(newTile->boundingRect());
- QList<QGraphicsItem *> collidingItems = newTile->collidingItems(Qt::IntersectsItemBoundingRect);
+ QList<QGraphicsItem *> collidingTiles = newTile->collidingItems(Qt::IntersectsItemBoundingRect);
//Loop all items under new tile
- foreach (QGraphicsItem *collidingItem, collidingItems) {
+ foreach (QGraphicsItem *collidingTile, collidingTiles) {
- QRectF collidingItemSceneRect = collidingItem->sceneBoundingRect();
+ QRectF collidingTileSceneRect = collidingTile->sceneBoundingRect();
- //If new tile covers the tile under, remove the tile (zoom out)
- if (newTileSceneRect.contains(collidingItemSceneRect)) {
- MapTile *tile = dynamic_cast<MapTile *>(collidingItem);
+ //If new tile covers the tile under, remove the tile
+ if (newTileSceneRect.contains(collidingTileSceneRect)) {
+ MapTile *tile = dynamic_cast<MapTile *>(collidingTile);
removeTile(tile);
}
else {
//Get tiles below removal candidate
- QList<QGraphicsItem *> stackedItems = m_mapScene->items(collidingItemSceneRect,
+ QList<QGraphicsItem *> stackedTiles = m_mapScene->items(collidingTileSceneRect,
Qt::ContainsItemBoundingRect);
- QRectF combined;
- int count = 0;
-
- //Loop all tiles below removal candidate and combine tiles
- foreach (QGraphicsItem *stackedItem, stackedItems) {
- if (stackedItem != collidingItem) {
- count++;
- QRectF stackedItemSceneRect = stackedItem->sceneBoundingRect();
- combined = combined.united(stackedItemSceneRect);
- }
- }
- //If combined tiles below removal candidate covers removal candidate, remove it (zoom in)
- if ((combined.contains(collidingItemSceneRect)) && (count >= 4)) {
- MapTile *tile = dynamic_cast<MapTile *>(collidingItem);
+ QRectF combined = combineTiles(collidingTile, stackedTiles);
+
+ //If combined tiles below removal candidate covers removal candidate, remove it
+ if (combined.contains(collidingTileSceneRect)) {
+ MapTile *tile = dynamic_cast<MapTile *>(collidingTile);
removeTile(tile);
}
}
}
+}
+
+QRectF MapEngine::combineTiles(QGraphicsItem *parentTile,
+ const QList<QGraphicsItem*> &stackedTiles)
+{
+ QRectF combined;
+ int count = 0;
+
+ foreach (QGraphicsItem *stackedTile, stackedTiles) {
+ if (stackedTile != parentTile) {
+ count++;
+ QRectF stackedTileSceneRect = stackedTile->sceneBoundingRect();
+ combined = combined.united(stackedTileSceneRect);
+ }
+ }
+
+ if (count < 4)
+ combined = QRectF();
-// qDebug() << m_mapScene->items().count();
+ return combined;
}
void MapEngine::viewResized(const QSize &size)
setTilesDrawingLevels();
calculateNewTiles(m_sceneCoordinate);
-
- /**
- * @todo Remove old tiles after zoom
- */
QTimer::singleShot(500, this, SLOT(removeOldTiles()));
}
QPoint MapEngine::convertLatLonToSceneCoordinate(QPointF latLonCoordinate)
{
- qDebug() << __PRETTY_FUNCTION__;
+// qDebug() << __PRETTY_FUNCTION__;
qreal longitude = latLonCoordinate.x();
qreal latitude = latLonCoordinate.y();
*/
MapEngine(QObject *parent = 0);
+/*******************************************************************************
+ * CLASS SPECIFIC MEMBER FUNCTIONS AND SLOTS
+ ******************************************************************************/
/**
* @brief Convert latitude and longitude to scene coordinates.
*
bool centerTileChanged(QPoint sceneCoordinate);
/**
+ * @brief Combine tiles' rectangles to one rectangle.
+ *
+ * @param stackedTiles tiles to combine
+ * @return QRectF resulting rectangle
+ */
+ QRectF combineTiles(QGraphicsItem *parentTile, const QList<QGraphicsItem*> &stackedTiles);
+
+ /**
* @brief Parse given URL to zoom, x and y values. Parsed values are
* placed in variables given as parameters.
*
*/
void zoomOut();
+/*******************************************************************************
+ * SIGNALS
+ ******************************************************************************/
signals:
/**
* @brief Signal for image fetching.
*/
void zoomLevelChanged(int newZoomLevel);
+/*******************************************************************************
+ * DATA MEMBERS
+ ******************************************************************************/
private:
- MapScene *m_mapScene; ///< Scene for map tiles
+ QPoint m_centerTile; ///< Current center tile
MapFetcher *m_mapFetcher; ///< Fetcher for map tiles
- int m_zoomLevel; ///< Current zoom level
+ MapScene *m_mapScene; ///< Scene for map tiles
QHash<QString, MapTile *> m_mapTilesInScene; ///< List of map tiles in map scene
- QSize m_viewSize; ///< Current view size
QPoint m_sceneCoordinate; ///< Current center coordinate
- QPoint m_centerTile; ///< Current center tile
QRect m_viewGrid; ///< Current grid of tiles in view
+ QSize m_viewSize; ///< Current view size
+ int m_zoomLevel; ///< Current zoom level
};
#endif // MAPENGINE_H
#include "mapfetcher.h"
-static int MAX_PARALLEL_DOWNLOADS = 2;
-static int DOWNLOAD_QUEUE_SIZE = 50;
+const int MAX_PARALLEL_DOWNLOADS = 2;
+const int DOWNLOAD_QUEUE_SIZE = 50;
MapFetcher::MapFetcher(QNetworkAccessManager *manager, QObject *parent)
- : QObject(parent), m_manager(manager)
+ : QObject(parent)
+ , m_manager(manager)
{
QNetworkDiskCache *diskCache = new QNetworkDiskCache(this);
diskCache->setCacheDirectory(QDesktopServices::storageLocation(
*/
~MapFetcher();
+/*******************************************************************************
+ * CLASS SPECIFIC MEMBER FUNCTIONS AND SLOTS
+ ******************************************************************************/
public slots:
/**
* @brief Fetch image from given URL.
*/
void startNextDownload();
+/*******************************************************************************
+ * SIGNALS
+ ******************************************************************************/
signals:
/**
* @brief Signal which is emitted when a map tile
*/
void error(const QString &message);
+/*******************************************************************************
+ * DATA MEMBERS
+ ******************************************************************************/
private:
-
- QNetworkAccessManager *m_manager; ///< Network access manager
QList<QNetworkReply*> m_currentDownloads; ///< List of current downloads
QQueue<QUrl> m_downloadQueue; ///< Queue of pending requests
+ QNetworkAccessManager *m_manager; ///< Network access manager
};
#endif
void TestMapEngine::setLocationNewTilesCount()
{
- MapEngine engine;
+ MapEngine engine;
engine.viewResized(QSize(800, 480));
QSignalSpy fetchImageSpy(&engine, SIGNAL(fetchImage(QUrl)));
MapEngine engine;
engine.viewResized(QSize(800, 480));
- const int maxItemsCount = 30;
+ const int maxItemsCount = 40;
engine.setLocation(QPoint(1220*16, 1220*16));
QTest::qWait(1000);
MapEngine engine;
engine.viewResized(QSize(800, 480));
- const int maxItemsCount = 30;
+ const int maxItemsCount = 40;
engine.setLocation(QPoint(1220*16, 1220*16));
QTest::qWait(1000);
MapEngine engine;
engine.viewResized(QSize(800, 480));
- const int maxItemsCount = 30;
+ const int maxItemsCount = 40;
engine.setLocation(QPoint(1220*16, 1220.23*16));
QTest::qWait(1000);
DEPENDPATH += .
INCLUDEPATH += . \
../../../src/
-DEFINES += QT_NO_DEBUG_OUTPUT
+#DEFINES += QT_NO_DEBUG_OUTPUT
# Input
SOURCES += testmapengine.cpp \