Enroute Flight Navigation
A navigation app for VFR pilots
Downloadable_MultiFile.h
1/***************************************************************************
2 * Copyright (C) 2022-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 <QQmlEngine>
24
25#include "dataManagement/Downloadable_Abstract.h"
26
27namespace DataManagement {
28
29
34
36 Q_OBJECT
37 QML_ELEMENT
38 QML_UNCREATABLE("")
39
40public:
46 Q_ENUM(UpdatePolicy)
47
48
54 explicit Downloadable_MultiFile(DataManagement::Downloadable_MultiFile::UpdatePolicy updatePolicy, QObject *parent = nullptr);
55
56 // Standard destructor
57 ~Downloadable_MultiFile() override;
58
59
60 //
61 // PROPERTIES
62 //
63
64 // Repeated from Downloadable_Abstract to keep QML happy
65 Q_PROPERTY(bool downloading READ downloading NOTIFY downloadingChanged)
66 Q_PROPERTY(QStringList files READ files NOTIFY filesChanged)
67 Q_PROPERTY(bool hasFile READ hasFile BINDABLE bindableHasFile NOTIFY hasFileChanged)
68 Q_PROPERTY(Units::ByteSize updateSize READ updateSize NOTIFY updateSizeChanged)
69
74 Q_PROPERTY(QVector<DataManagement::Downloadable_Abstract*> downloadables READ downloadables NOTIFY downloadablesChanged)
75
76
77 //
78 // Getter Methods
79 //
80
85 [[nodiscard]] auto description() -> QString override;
86
91 [[nodiscard]] QVector<DataManagement::Downloadable_Abstract*> downloadables();
92
97 [[nodiscard]] auto downloading() -> bool override { return m_downloading; }
98
103 [[nodiscard]] auto files() -> QStringList override { return m_files; }
104
109 [[nodiscard]] auto infoText() -> QString override;
110
115 [[nodiscard]] auto remoteFileSize() -> qint64 override { return m_remoteFileSize; }
116
121 [[nodiscard]] auto updateSize() -> Units::ByteSize override { return m_updateSize; }
122
123
124
125 //
126 // Methods
127 //
128
140
148 Q_INVOKABLE void add(const QVector<DataManagement::Downloadable_Abstract*>& maps);
149
151 Q_INVOKABLE void clear();
152
154 Q_INVOKABLE void deleteFiles() override;
155
162 [[nodiscard]] Q_INVOKABLE QList<DataManagement::Downloadable_Abstract*> downloadables4Location(const QGeoCoordinate& location);
163
170 [[nodiscard]] Q_INVOKABLE QList<DataManagement::Downloadable_Abstract*> downloadablesByDistance(const QGeoCoordinate& location);
171
177
179 Q_INVOKABLE void startDownload() override;
180
182 Q_INVOKABLE void stopDownload() override;
183
185 Q_INVOKABLE void update() override;
186
187signals:
190
191private:
192 // Re-evaluate members when the properties of a member changes
193 bool computeHasFile();
194 void evaluateDownloading();
195 void evaluateFiles();
196 void evaluateRemoteFileSize();
197 void evaluateUpdateSize();
198
199 // Similar to 'add', but does not emit any notifier signals
200 // Returns 'true' if item has actually been added.
202
203 bool m_downloading {false};
204 QStringList m_files;
205 qint64 m_remoteFileSize {-1};
206 qint64 m_updateSize {0};
207
208 QProperty<QVector<QPointer<DataManagement::Downloadable_Abstract>>> m_downloadables;
210};
211
212} // namespace DataManagement
Abstract base class for Downloadable_SingleFile and Downloadable_MultiFile.
void downloadingChanged()
Notifier signal.
void filesChanged()
Notifier signal.
Downloadable_Abstract(QObject *parent=nullptr)
Standard constructor.
void hasFileChanged()
Notifier signal.
QBindable< bool > bindableHasFile() const
Getter method for the property with the same name.
void updateSizeChanged()
Notifier signal.
Q_INVOKABLE void update() override
Implementation of pure virtual method from Downloadable_Abstract.
QVector< DataManagement::Downloadable_Abstract * > downloadables
List of Downloadables in this group.
auto infoText() -> QString override
Implementation of pure virtual getter method from Downloadable_Abstract.
Q_INVOKABLE void add(DataManagement::Downloadable_Abstract *map)
Add a Downloadable_SingleFile to this Downloadable_MultiFile.
Downloadable_MultiFile(DataManagement::Downloadable_MultiFile::UpdatePolicy updatePolicy, QObject *parent=nullptr)
Standard constructor.
Q_INVOKABLE void clear()
Removes all children.
Q_INVOKABLE void deleteFiles() override
Implementation of pure virtual method from Downloadable_Abstract.
auto description() -> QString override
Implementation of pure virtual getter method from Downloadable_Abstract.
@ MultiUpdate
Update children that are updatable. If one local file exist, download all other files on update.
@ SingleUpdate
Update children that are updatable.
Q_INVOKABLE void startDownload() override
Implementation of pure virtual method from Downloadable_Abstract.
Q_INVOKABLE QList< DataManagement::Downloadable_Abstract * > downloadables4Location(const QGeoCoordinate &location)
Downloadables for a given location.
auto updateSize() -> Units::ByteSize override
Implementation of pure virtual getter method from Downloadable_Abstract.
void downloadablesChanged()
Notifier signal.
Q_INVOKABLE void add(const QVector< DataManagement::Downloadable_Abstract * > &maps)
Add 'Downloadable_SingleFile's to this Downloadable_MultiFile.
Q_INVOKABLE void remove(DataManagement::Downloadable_Abstract *map)
Remove a Downloadable_SingleFile from this Downloadable_MultiFile.
auto files() -> QStringList override
Implementation of pure virtual getter method from Downloadable_Abstract.
auto remoteFileSize() -> qint64 override
Getter function for the property with the same name.
Q_INVOKABLE void stopDownload() override
Implementation of pure virtual method from Downloadable_Abstract.
Q_INVOKABLE QList< DataManagement::Downloadable_Abstract * > downloadablesByDistance(const QGeoCoordinate &location)
Downloadables, sorted by distance to a given location.
Convenience class for size_t.
Definition ByteSize.h:37
Conversion between units used in aviation.
Definition Angle.h:34