USA.
*/
-/// @todo Jussi: check includes
-#include <QtCore>
-#include <QtGlobal>
+///< @todo check includes DONE
#include <QDebug>
#include <QString>
#include <QStringList>
int size = pathParts.size();
- if (size < 3)
- /// @todo Jussi: return only at the end
- return;
+ if (size >= 3) {
+ /// @todo Jussi: return only at the end DONE
- zoom = (pathParts.at(size-3)).toInt();
- x = (pathParts.at(size-2)).toInt();
- QString yString = pathParts.at(size-1);
- yString.chop(4);
- y = yString.toInt();
+ zoom = (pathParts.at(size-3)).toInt();
+ x = (pathParts.at(size-2)).toInt();
+ QString yString = pathParts.at(size-1);
+ yString.chop(4);
+ y = yString.toInt();
+ }
}
void MapEngine::mapImageReceived(const QUrl &url, const QPixmap &pixmap)
int y = UNDEFINED;
parseURL(url, zoom, x, y);
-
- /// @todo Jussi: call tilepath only once
- if (!m_mapTilesInScene.contains(tilePath(zoom, x, y))) {
+ QString hashKey = tilePath(zoom, x, y);
+ /// @todo Jussi: call tilepath only once DONE
+ if (!m_mapTilesInScene.contains(hashKey)) {
MapTile *mapTile = new MapTile();
mapTile->setZoomLevel(zoom);
mapTile->setTileNumber(QPoint(x, y));
mapTile->setPixmap(pixmap);
- m_mapTilesInScene.insert(tilePath(zoom, x, y), mapTile);
+ m_mapTilesInScene.insert(hashKey, mapTile);
m_mapScene->addMapTile(mapTile);
removeStackedTiles(mapTile);
return (1 << zoomLevel) - 1;
}
-/// @todo Jussi: calculateTileGrid
-QRect MapEngine::calculateGrid(QPoint sceneCoordinate)
+/// @todo Jussi: calculateTileGrid DONE
+QRect MapEngine::calculateTileGrid(QPoint sceneCoordinate)
{
QPoint tileCoordinate = convertSceneCoordinateToTileNumber(m_zoomLevel, sceneCoordinate);
int gridWidth = (m_viewSize.width()/TILE_SIZE_X + 1) + (GRID_PADDING*2);
m_sceneCoordinate = sceneCoordinate;
emit locationChanged(m_sceneCoordinate);
- if (centerTileChanged(sceneCoordinate)) {
- calculateNewTiles(sceneCoordinate);
- removeOldTiles();
+ if (isCenterTileChanged(sceneCoordinate)) {
+ getTiles(sceneCoordinate);
+ removeTilesOutOfView();
}
}
-/// @todo Jussi: is-prefix
-bool MapEngine::centerTileChanged(QPoint sceneCoordinate)
+/// @todo Jussi: is-prefix DONE
+bool MapEngine::isCenterTileChanged(QPoint sceneCoordinate)
{
QPoint centerTile = convertSceneCoordinateToTileNumber(m_zoomLevel, sceneCoordinate);
QPoint temp = m_centerTile;
return (centerTile != temp);
}
-/// @todo Jussi: method name? getTiles()?
-void MapEngine::calculateNewTiles(QPoint sceneCoordinate)
+/// @todo Jussi: method name? getTiles()? DONE
+void MapEngine::getTiles(QPoint sceneCoordinate)
{
// qDebug() << __PRETTY_FUNCTION__;
- m_viewGrid = calculateGrid(sceneCoordinate);
+ m_viewGrid = calculateTileGrid(sceneCoordinate);
int topLeftX = m_viewGrid.topLeft().x();
int topLeftY = m_viewGrid.topLeft().y();
}
/// @todo Jussi: removeTilesOutOfView()
-void MapEngine::removeOldTiles()
+void MapEngine::removeTilesOutOfView()
{
//qDebug() << __PRETTY_FUNCTION__;
{
//qDebug() << __PRETTY_FUNCTION__;
- /// @todo Jussi: use sceneBoundingRect
- QRectF newTileSceneRect = newTile->mapRectToScene(newTile->boundingRect());
+ /// @todo Jussi: use sceneBoundingRect DONE
+// QRectF newTileSceneRect = newTile->mapRectToScene(newTile->boundingRect());
+ QRectF newTileSceneRect = newTile->sceneBoundingRect();
QList<QGraphicsItem *> collidingTiles = newTile->collidingItems(Qt::IntersectsItemBoundingRect);
//Loop all items under new tile
//Get tiles below removal candidate
QList<QGraphicsItem *> stackedTiles = m_mapScene->items(collidingTileSceneRect,
Qt::ContainsItemBoundingRect);
-
QRectF combined = combineTiles(collidingTile, stackedTiles);
//If combined tiles below removal candidate covers removal candidate, remove it
void MapEngine::viewResized(const QSize &size)
{
m_viewSize = size;
- calculateNewTiles(m_sceneCoordinate);
- removeOldTiles();
+ getTiles(m_sceneCoordinate);
+ removeTilesOutOfView();
}
void MapEngine::zoomIn()
setTilesDrawingLevels();
- calculateNewTiles(m_sceneCoordinate);
- QTimer::singleShot(500, this, SLOT(removeOldTiles()));
+ getTiles(m_sceneCoordinate);
+ QTimer::singleShot(500, this, SLOT(removeTilesOutOfView()));
}
void MapEngine::zoomOut()
setTilesDrawingLevels();
- calculateNewTiles(m_sceneCoordinate);
+ getTiles(m_sceneCoordinate);
}
void MapEngine::setTilesDrawingLevels()
* @param sceneCoordinate scene's current center coordinate
* @return QRect grid of tile coordinates
*/
- QRect calculateGrid(QPoint sceneCoordinate);
+ QRect calculateTileGrid(QPoint sceneCoordinate);
/**
- * @brief Calculate new tiles to fetch.
+ * @brief Get new tiles.
*
+ * Calculates which tiles has to be fetched.
* @param sceneCoordinate scene's center coordinate
*/
- void calculateNewTiles(QPoint sceneCoordinate);
+ void getTiles(QPoint sceneCoordinate);
/**
* @brief Check if center tile has changed.
* @param sceneCoordinate scene's center coordinate
* @return bool true if center tile changed, false otherwise
*/
- bool centerTileChanged(QPoint sceneCoordinate);
+ bool isCenterTileChanged(QPoint sceneCoordinate);
/**
* @brief Combine tiles' rectangles to one rectangle.
*
+ * @param parentTile parent tile not to combine
* @param stackedTiles tiles to combine
* @return QRectF resulting rectangle
*/
/**
* @brief Remove tiles which are out of view bounds.
*/
- void removeOldTiles();
+ void removeTilesOutOfView();
/**
* @brief Slot for view scaling factor change events
#include <QDesktopServices>
#include "mapfetcher.h"
-
-const int MAX_PARALLEL_DOWNLOADS = 2;
-const int DOWNLOAD_QUEUE_SIZE = 50;
+#include "mapcommon.h"
MapFetcher::MapFetcher(QNetworkAccessManager *manager, QObject *parent)
: QObject(parent)
QUrl url = m_downloadQueue.dequeue();
QNetworkRequest request(url);
- /// @todo Jussi: set user agent
- request.setRawHeader("User-Agent", "Map Test");
+ /// @todo Jussi: set user agent DONE
+ request.setRawHeader("User-Agent", "Situare");
QNetworkReply *reply = m_manager->get(request);
m_currentDownloads.append(reply);
QImage image;
QUrl url = reply->url();
- if (!image.load(reply, 0)) {
- qDebug() << "Could not load image";
+ if (!image.load(reply, 0))
image = QImage();
- }
emit mapImageReceived(url, QPixmap::fromImage(image));
}
startNextDownload();
}
-/// @todo Jussi: remove destructor
-MapFetcher::~MapFetcher()
-{
-
-}
+/// @todo Jussi: remove destructor DONE