Merged and resolved conflict
[situare] / src / map / maptile.cpp
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Sami Rämö - sami.ramo@ixonos.com
6
7    Situare is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License
9    version 2 as published by the Free Software Foundation.
10
11    Situare is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with Situare; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
19    USA.
20 */
21
22 #include <QDebug>
23 #include <QTransform>
24
25 #include "common.h"
26 #include "mapengine.h"
27 #include "maptile.h"
28
29 MapTile::MapTile()
30 {
31     m_tileNumber = QPoint(UNDEFINED, UNDEFINED);
32     m_zoomLevel = UNDEFINED;
33     setPos(UNDEFINED, UNDEFINED);
34 }
35
36 int MapTile::zoomLevel()
37 {
38     return m_zoomLevel;
39 }
40
41 void MapTile::setZoomLevel(int zoomLevel)
42 {
43     m_zoomLevel = zoomLevel;
44     setPosition();
45
46     qreal zoomFactor = (qreal)(1 << (MAX_ZOOM_LEVEL - m_zoomLevel));
47     setScale(zoomFactor);
48 }
49
50 QPoint MapTile::tileNumber()
51 {
52     return m_tileNumber;
53 }
54
55 void MapTile::setTileNumber(QPoint tileNumber)
56 {
57     m_tileNumber = tileNumber;
58     setPosition();
59 }
60
61 void MapTile::setPosition()
62 {
63     const int maxTileNumber = (1 << m_zoomLevel) - 1;
64
65     if ((m_zoomLevel >= MIN_ZOOM_LEVEL) && (m_zoomLevel <= MAX_ZOOM_LEVEL) &&
66             (m_tileNumber.x() >= 0) && (m_tileNumber.x() <= maxTileNumber) &&
67             (m_tileNumber.y() >= 0) && (m_tileNumber.y() <= maxTileNumber)) {
68         setPos(MapEngine::convertTileNumberToSceneCoordinate(m_zoomLevel, m_tileNumber));
69         return; // done
70     }
71     // else
72     setPos(UNDEFINED, UNDEFINED);
73     //Q_ASSERT_X(false, __PRETTY_FUNCTION__, "m_zoomLevel and/or m_tileNumber is undefined");
74 }
75