summaryrefslogtreecommitdiff
path: root/src/imports/location/tilecache.h
blob: 6efefbfa36dfe852f06e1bbf17e039fb49dd6761 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef TILECACHE_H
#define TILECACHE_H

#include <QObject>
#include <QMap>

#include "tilespec.h"
#include "tile.h"
#include "tileprovider.h"

class TileCache : public QObject
{
    Q_OBJECT
public:
    TileCache(const QString &directory = QString(), QObject *parent = 0);

    void prefetch(const TileSpec &spec);
    void waitForPrefetchedTiles();

    Tile get(const TileSpec &spec) const;

signals:
    void prefetchingFinished();

private slots:
    void insert(const Tile &tile);
    void handleError(const TileSpec &spec);

private:
    void loadTiles();

    void updateWaitingStatus();

    QString tileSpecToFilename(const TileSpec &spec) const;
    TileSpec filenameToTileSpec(const QString &filename) const;

    QString directory_;
    TileProvider *provider_;

    bool waitingForPrefetchedTiles_;
    int tilesOutstanding_;

    QMap<TileSpec, Tile> cache_;
};

#endif // TILECACHE_H