5722d01bbaf5e3aaab632ae4e1e107d77c550950
[situare] / src / map / mapscene.h
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 #ifndef MAPSCENE_H
23 #define MAPSCENE_H
24
25 #include <QGraphicsScene>
26
27 #include "mapcommon.h"
28
29 class MapTile;
30
31 /**
32 * @brief Map scene for storing MapTile items
33 *
34 * @author Sami Rämö - sami.ramo (at) ixonos.com
35 */
36 class MapScene : public QGraphicsScene
37 {
38     Q_OBJECT
39 public:
40     /**
41     * @brief Constructor
42     *
43     * Scene size is set to the amount of pixels on closest zoom level
44     * @param parent Parent
45     */
46     MapScene(QObject *parent = 0);
47
48 /*******************************************************************************
49  * MEMBER FUNCTIONS AND SLOTS
50  ******************************************************************************/
51 public:
52     /**
53     * @brief Create and add new MapTile to MapScene
54     *
55     * If there is a tile with same parameter already in the scene, it will be removed
56     * before adding the new tile.
57     *
58     * @param mapTile Map tile item to be added
59     * @param hashKey Hash key for the tile
60     */
61     void addTile(int zoomLevel, QPoint tileNumber, const QPixmap &image, int viewZoomLevel);
62
63     /**
64     * @brief Enqueue stacked tiles removal request
65     *
66     * Removal is triggered after events have been processed so the UI
67     * stays more responsive
68     * @param newTile New tile, which area under it is inspected
69     */
70     void enqueueRemoveStackedTiles(MapTile *newTile);
71
72     /**
73     * @brief Returns tile mathcing given hash key
74     *
75     * @param hashKey
76     * @return Returns tile matching given hash key, or 0 if no match found
77     */
78     MapTile* tileInScene(QString hashKey);
79
80     /**
81     * @brief Remove tiles which are out of view bounds.
82     *
83     */
84     void removeOutOfViewTiles(QRect tilesGrid, int zoomLevel);
85
86     /**
87     * @brief Remove tiles which are stacked.
88     *
89     * Iterate through tiles which are under this map tile and remove tiles which
90     * are fully obscured by this new tile. Tiles which are only partially
91     * obscured by this new tile are not checked, and thus deleted, because of
92     * the required complexity of the algorithm and processing power. Those tiles
93     * will be removed when they go out of the view area caused by scrolling or
94     * zooming in enough.
95     *
96     * @param newTile new tile covering old tiles
97     */
98     void removeStackedTiles(MapTile *newTile);
99
100     /**
101     * @brief Remove tile.
102     *
103     * Removes tile from scene and list of current tiles in scene.
104     * @param tile MapTile to remove
105     */
106     void removeTile(MapTile *tile);
107
108     void setSceneVerticalOverlap(int viewHeight, int zoomLevel);
109
110     /**
111     * @brief Set drawing order of all tiles in the scene
112     *
113     * Check MapTile::setSceneLevel for more information.
114     * @param zoomLevel Current zoom level
115     */
116     void setTilesDrawingLevels(int zoomLevel);
117
118     QRect spanItems(ScrollDirection direction, int zoomLevel);
119
120     /**
121     * @brief Save new tiles scene rect
122     *
123     * Tiles scene rect must be saved to local scope whenever it changes because
124     * it is used by removal algorithms and some of the algorithms are run
125     * delayed so the actual tiles scene rect may change before the cleanup
126     * algorithm is run.
127     *
128     * @param tilesSceneRect New view rect
129     */
130     void tilesSceneRectUpdated(QRect tilesSceneRect);
131
132 private slots:
133     /**
134     * @brief Slot for running next queued removal of stacked tiles
135     *
136     */
137     void runNextStackedTilesRemoval();
138
139 /*******************************************************************************
140  * DATA MEMBERS
141  ******************************************************************************/
142 private:
143     bool m_isRemoveStackedTilesRunning; ///< Is singleshot timer already running
144     QHash<QString, MapTile *> m_mapTilesInScene;  ///< List of map tiles in map scene
145     QList<MapTile *> m_removeStackedTilesList; ///< "Queue" for stacked tiles removal requests
146     QRect m_tilesSceneRect; ///< Current viewable area
147 };
148
149 #endif // MAPSCENE_H