Enroute Flight Navigation
A navigation app for VFR pilots
TileServer.h
1/***************************************************************************
2 * Copyright (C) 2019-2024 by Stefan Kebekus *
3 * stefan.kebekus@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21#pragma once
22
23#include "fileFormats/MBTILES.h"
24#include "geomaps/TileHandler.h"
25
26#include <QAbstractHttpServer>
27#include <QSharedPointer>
28
29
30namespace GeoMaps {
31
61
62class TileServer : public QAbstractHttpServer
63{
64 Q_OBJECT
65
66public:
75 explicit TileServer(QObject* parent = nullptr);
76
77 // Standard destructor
78 ~TileServer() override = default;
79
80
81
82 //
83 // Properties
84 //
85
92 Q_PROPERTY(QString serverUrl READ serverUrl NOTIFY serverUrlChanged)
93
94
95
96 //
97 // Getter Methods
98 //
99
100
104 [[nodiscard]] QString serverUrl();
105
106
107public slots:
127 void addMbtilesFileSet(const QString& baseName, const QVector<QSharedPointer<FileFormats::MBTILES>>& MBTilesFiles);
128
133 void removeMbtilesFileSet(const QString& baseName) {m_tileHandlers.take(baseName);}
134
139 void removeMbtilesFileSets() {m_tileHandlers.clear();}
140
141
142signals:
145
146
147private:
148 Q_DISABLE_COPY_MOVE(TileServer)
149
150 // Implemented pure virtual method from QAbstractHttpServer
151 bool handleRequest(const QHttpServerRequest& request, QHttpServerResponder& responder) override;
152
153 // Implemented pure virtual method from QAbstractHttpServer
154 void missingHandler(const QHttpServerRequest& request, QHttpServerResponder& responder) override;
155
165 void restart();
166
167 // List of tile handlers
168 QMap<QString, QSharedPointer<GeoMaps::TileHandler>> m_tileHandlers;
169
170 // Night-mode sprite sheets, keyed by resource file name of the day-mode
171 // original. Computing the recolored PNGs is not free, so they are cached
172 // here after the first request. The transform is deterministic, so entries
173 // never need to be invalidated.
174 QMap<QString, QByteArray> m_nightSprites;
175
176 // Internal variable. Indicates if the app has been suspended.
177 // This is used on changes of QGuiApplication::applicationState,
178 // to check if the application is currently awaking from sleep,
179 // so that the server needs to be restarted (if on iOS).
180#if defined(Q_OS_IOS)
181 bool suspended = false;
182#endif
183};
184
185} // namespace GeoMaps
TileServer(QObject *parent=nullptr)
Create a new tile server.
void serverUrlChanged()
Notification signal for the property with the same name.
void removeMbtilesFileSet(const QString &baseName)
Removes a set of tile files.
Definition TileServer.h:133
QString serverUrl
URL under which this server is presently reachable.
Definition TileServer.h:92
void removeMbtilesFileSets()
Removes a set of tile files.
Definition TileServer.h:139
void addMbtilesFileSet(const QString &baseName, const QVector< QSharedPointer< FileFormats::MBTILES > > &MBTilesFiles)
Add a new set of tile files.
QString serverUrl()
Getter function for the property with the same name.