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