Stellarium 0.13.3
StelLocationMgr.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 _STELLOCATIONMGR_HPP_
20 #define _STELLOCATIONMGR_HPP_
21 
22 #include "StelLocation.hpp"
23 #include <QString>
24 #include <QObject>
25 #include <QMetaType>
26 #include <QMap>
27 
28 class QStringListModel;
29 class QNetworkReply;
30 
33 class StelLocationMgr : public QObject
34 {
35  Q_OBJECT
36 
37 public:
42 
44  QStringListModel* getModelAll() {return modelAllLocation;}
46  QStringListModel* getModelPicked() {return modelPickedLocation;}
47 
49  QList<StelLocation> getAll() const {return locations.values();}
50 
53  const StelLocation locationForString(const QString& s) const;
54 
56  const StelLocation locationFromCLI() const;
57 
59  const StelLocation& getLastResortLocation() const {return lastResortLocation;}
60 
63  bool canSaveUserLocation(const StelLocation& loc) const;
64 
67  bool saveUserLocation(const StelLocation& loc);
68 
72  bool canDeleteUserLocation(const QString& id) const;
73 
77  bool deleteUserLocation(const QString& id);
78 
80  void locationFromIP();
81 
84  void pickLocationsNearby(const QString planetName, const float longitude, const float latitude, const float radiusDegrees);
87  void pickLocationsInCountry(const QString country);
88 
89 public slots:
92 
93 private:
94  void generateBinaryLocationFile(const QString& txtFile, bool isUserLocation, const QString& binFile) const;
95 
97  QMap<QString, StelLocation> loadCities(const QString& fileName, bool isUserLocation) const;
98  QMap<QString, StelLocation> loadCitiesBin(const QString& fileName) const;
99 
101  QStringListModel* modelAllLocation;
103  QStringListModel* modelPickedLocation;
104 
106  QMap<QString, StelLocation> locations;
108  QMap<QString, StelLocation> pickedLocations;
109 
110  StelLocation lastResortLocation;
111 
113  QNetworkReply *networkReply;
114 
115 };
116 
117 #endif // _STELLOCATIONMGR_HPP_
const StelLocation locationForString(const QString &s) const
Return the StelLocation for a given string Can match location name, or coordinates.
Store the informations for a location on a planet.
~StelLocationMgr()
Destructor.
QList< StelLocation > getAll() const
Return the list of all loaded locations.
QStringListModel * getModelAll()
Return the model containing all the city.
StelLocationMgr()
Default constructor.
Manage the list of available location.
const StelLocation locationFromCLI() const
Return the StelLocation from a CLI.
bool saveUserLocation(const StelLocation &loc)
Add permanently a location to the list of user locations It is later identified by its small string...
QStringListModel * getModelPicked()
Return the model containing picked (nearby) cities or cities from a single country, or other preselection.
void changeLocationFromNetworkLookup()
Process answer from online lookup of IP address.
const StelLocation & getLastResortLocation() const
Return a valid location when no valid one was found.
bool deleteUserLocation(const QString &id)
Delete permanently the given location from the list of user locations If the location comes from the ...
bool canDeleteUserLocation(const QString &id) const
Get whether a location can be deleted from the list of user locations If the location comes from the ...
void locationFromIP()
Find location via online lookup of IP address.
bool canSaveUserLocation(const StelLocation &loc) const
Get whether a location can be permanently added to the list of user locations The main constraint is ...