Merge branch 'master' into settings_auto_update
[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     /**
59     * @brief Enqueue stacked tiles removal request
60     *
61     * Removal is triggered after events have been processed so the UI
62     * stays more responsive
63     * @param newTile New tile, which area under it is inspected
64     */
65     void enqueueRemoveStackedTiles(MapTile *newTile);
66
67     /**
68     * @brief Returns if tile mathcing hash key is already in the scene
69     *
70     * @param hashKey
71     * @return True if tile was in the scene, otherwise false
72     */
73     bool isTileInScene(QString hashKey);
74
75     /**
76     * @brief Remove tiles which are out of view bounds.
77     *
78     */
79     void removeOutOfViewTiles();
80
81     /**
82     * @brief Remove tiles which are stacked.
83     *
84     * Iterate through tiles which are under this map tile and remove tiles which
85     * are fully obscured by this new tile. Tiles which are only partially
86     * obscured by this new tile are not checked, and thus deleted, because of
87     * the required complexity of the algorithm and processing power. Those tiles
88     * will be removed when they go out of the view area caused by scrolling or
89     * zooming in enough.
90     *
91     * @param newTile new tile covering old tiles
92     */
93     void removeStackedTiles(MapTile *newTile);
94
95     /**
96     * @brief Remove tile.
97     *
98     * Removes tile from scene and list of current tiles in scene.
99     * @param tile MapTile to remove
100     */
101     void removeTile(MapTile *tile);
102
103     /**
104     * @brief Set drawing order of all tiles in the scene
105     *
106     * Check MapTile::setSceneLevel for more information.
107     * @param zoomLevel Current zoom level
108     */
109     void setTilesDrawingLevels(int zoomLevel);
110
111     /**
112     * @brief Save new view rect
113     *
114     * View rect must be saved to local scope whenever it changes because
115     * it is used by removal algorithms and some of the algorithms are run
116     * delayed so the actual view rect may change before the cleanup
117     * algorithm is run.
118     *
119     * @param viewRect New view rect
120     */
121     void viewRectUpdated(QRect viewRect);
122
123 private slots:
124     /**
125     * @brief Slot for running next queued removal of stacked tiles
126     *
127     */
128     void runNextStackedTilesRemoval();
129
130 /*******************************************************************************
131  * DATA MEMBERS
132  ******************************************************************************/
133 private:
134     bool m_isRemoveStackedTilesRunning; ///< Is singleshot timer already running
135     QHash<QString, MapTile *> m_mapTilesInScene;  ///< List of map tiles in map scene
136     QList<MapTile *> m_removeStackedTilesList; ///< "Queue" for stacked tiles removal requests
137     QRect m_viewRect; ///< Current viewable area
138 };
139
140 #endif // MAPSCENE_H