Stellarium  0.16.1
MultiLevelJsonBase.hpp
1 /*
2  * Copyright (C) 2008 Fabien Chereau
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
17  */
18 
19 #ifndef _MULTILEVELJSONBASE_HPP_
20 #define _MULTILEVELJSONBASE_HPP_
21 
22 #include "StelSkyLayer.hpp"
23 
24 #include <QList>
25 #include <QString>
26 #include <QVariantMap>
27 #include <QNetworkReply>
28 
29 class QIODevice;
30 class StelCore;
31 
35 {
36  Q_OBJECT
37 
38  friend class JsonLoadThread;
39 
40 public:
42  MultiLevelJsonBase(MultiLevelJsonBase* parent=Q_NULLPTR);
43 
46  void initFromUrl(const QString& url);
47 
50  void initFromQVariantMap(const QVariantMap& map);
51 
54 
56  QString getShortName() const {return shortName;}
57 
59  bool hasErrorOccured() const {return errorOccured;}
60 
62  int getLevel() const {return parent()==Q_NULLPTR ? 0 : (qobject_cast<MultiLevelJsonBase*>(parent()))->getLevel()+1;}
63 
66  QVariantMap toQVariantMap() const;
67 
71 
72 private slots:
74  void downloadFinished();
76  void jsonLoadFinished();
77 
78 protected:
81  virtual void loadFromQVariantMap(const QVariantMap& map)=0;
82 
84  bool isDeletionScheduled() const {return timeWhenDeletionScheduled>0.;}
85 
87  QString shortName;
88 
90  QString baseUrl;
91 
93  QString contructorUrl;
94 
96  QList<MultiLevelJsonBase*> subTiles;
97 
100 
101  void updatePercent(int tot, int numToBeLoaded);
102 
104  void deleteUnusedSubTiles();
105 
108 
110  void cancelDeletion();
111 
113  static QVariantMap loadFromJSON(QIODevice& input, bool qZcompressed=false, bool gzCompressed=false);
114 
115 private:
117  QString getBaseUrl() const {return baseUrl;}
118 
119  // Used to download remote JSON files if needed
120  class QNetworkReply* httpReply;
121 
122  // The delay after which a scheduled deletion will occur
123  float deletionDelay;
124 
125  class JsonLoadThread* loadThread;
126 
127  // Time at which deletion was first scheduled
128  double timeWhenDeletionScheduled;
129 
130  // The temporary map filled in a thread
131  QVariantMap temporaryResultMap;
132 
133  bool loadingState;
134  int lastPercent;
135 
137  static class QNetworkAccessManager* networkAccessManager;
138 
139  static QNetworkAccessManager& getNetworkAccessManager();
140 };
141 
142 #endif // _MULTILEVELJSONBASE_HPP_
void deleteUnusedSubTiles()
Delete all the subtiles which were not displayed since more than lastDrawTrigger seconds.
void cancelDeletion()
If a deletion was scheduled, cancel it.
bool errorOccured
Set to true if an error occured with this tile and it should not be displayed.
int getLevel() const
Get the depth level in the tree.
QVariantMap toQVariantMap() const
Convert the image informations to a map following the JSON structure.
void initFromUrl(const QString &url)
Init the element from a URL.
Abstract base class for managing multi-level tree objects stored in JSON format.
MultiLevelJsonBase(MultiLevelJsonBase *parent=Q_NULLPTR)
Default constructor.
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
bool downloading
true if the JSON descriptor file is currently downloading
static QVariantMap loadFromJSON(QIODevice &input, bool qZcompressed=false, bool gzCompressed=false)
Load the element information from a JSON file.
bool isDeletionScheduled() const
Return true if a deletion is currently scheduled.
QString baseUrl
Base URL to prefix to relative URL.
~MultiLevelJsonBase()
Destructor.
virtual void loadFromQVariantMap(const QVariantMap &map)=0
Load the element from a valid QVariantMap.
QString shortName
The very short name for this image set to be used in loading bar.
QList< MultiLevelJsonBase * > subTiles
The list of all the created subtiles for this tile.
void initFromQVariantMap(const QVariantMap &map)
Init the element from a QVariantMap.
void scheduleChildsDeletion()
Schedule a deletion for all the childs.
QString contructorUrl
The relative URL passed to the constructor.
bool hasErrorOccured() const
Return true if an error occured while loading the data.
Abstract class defining the API to implement for all sky layer.
QString getShortName() const
Return the short name for this image to be used in the loading bar.