• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Stellarium / stellarium / 4853788370

pending completion
4853788370

push

github

Alexander V. Wolf
Special patch for John Simple

3 of 3 new or added lines in 3 files covered. (100.0%)

14729 of 125046 relevant lines covered (11.78%)

20166.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/core/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
#ifdef Q_OS_WIN
28
#include <QtPositioning/QGeoPositionInfoSource>
29
#endif
30

31
typedef QList<StelLocation> LocationList;
32
typedef QMap<QString,StelLocation> LocationMap;
33
typedef QMap<QByteArray,QByteArray> TimezoneNameMap;
34

35
typedef struct
36
{
37
        int code;
38
        QString regionName;
39
        QString countries;
40
        QString planet;
41
} GeoRegion;
42

43
class GPSLookupHelper;
44

45
//! @class StelLocationMgr
46
//! Manage the list of available location.
47
class StelLocationMgr : public QObject
48
{
49
        Q_OBJECT
50

51
public:
52
        //! Default constructor which loads the list of locations from the base and user location files.
53
        StelLocationMgr();
54
        ~StelLocationMgr() Q_DECL_OVERRIDE;
55

56
        //! Construct a StelLocationMgr which uses the locations given instead of loading them from the files.
57
        StelLocationMgr(const LocationList& locations);
58

59
        //! Replaces the loaded location list
60
        void setLocations(const LocationList& locations);
61

62
        //! Return the list of all loaded locations
63
        LocationList getAll() const {return locations.values();}
×
64

65
        //! Returns a map of all loaded locations. The key is the location ID, suitable for a list view.
66
        LocationMap getAllMap() const { return locations; }
×
67

68
        //! Return the StelLocation from a CLI
69
        const StelLocation locationFromCLI() const;
70

71
        //! Return a valid location when no valid one was found.
72
        const StelLocation& getLastResortLocation() const {return lastResortLocation;}
×
73
        
74
        //! Get whether a location can be permanently added to the list of user locations
75
        //! The main constraint is that the small string must be unique
76
        bool canSaveUserLocation(const StelLocation& loc) const;
77

78
        //! Add permanently a location to the list of user locations
79
        //! It is later identified by its small string
80
        bool saveUserLocation(const StelLocation& loc);
81

82
        //! Get whether a location can be deleted from the list of user locations
83
        //! If the location comes from the base read only list, it cannot be deleted
84
        //! @param id the location ID
85
        bool canDeleteUserLocation(const QString& id) const;
86

87
        //! Delete permanently the given location from the list of user locations
88
        //! If the location comes from the base read only list, it cannot be deleted and false is returned
89
        //! @param id the location ID
90
        bool deleteUserLocation(const QString& id);
91

92
        //! Find list of locations within @param radiusDegrees of selected (usually screen-clicked) coordinates.
93
        LocationMap pickLocationsNearby(const QString planetName, const float longitude, const float latitude, const float radiusDegrees);
94
        //! Find list of locations in a particular region only.
95
        LocationMap pickLocationsInRegion(const QString region);
96

97
        //! return a QStringList of region names by planet (return all list of regions if planet name is empty)
98
        QStringList getRegionNames(const QString& planet = "") const;
99

100
        //! Pick region name from ISO 3166-1 two-letter country codes
101
        static QString pickRegionFromCountryCode(const QString countryCode);
102
        //! Pick region name from country English name
103
        static QString pickRegionFromCountry(const QString country);
104
        //! Pick region name from region code
105
        static QString pickRegionFromCode(int regionCode);
106

107
        static QString getTZFFileName() { return tzfFileName; }
×
108
        static bool unknownTimezonesDetected() { return unknownTZ; }
×
109

110
public slots:
111
        //! Return the StelLocation for a given string
112
        //! Can match location name, or coordinates
113
        const StelLocation locationForString(const QString& s) const;
114

115
        //! Find location via online lookup of IP address
116
        void locationFromIP();
117

118
        //! return a QStringList of valid timezone names in Stellarium's location database.
119
        QStringList getAllTimezoneNames() const;
120

121
#ifdef ENABLE_GPS
122
        //! Try to get a location from GPS lookup.
123
        //! This prefers GPSD on non-Windows platforms, and uses Qt positioning with a NMEA serial device otherwise
124
        //! Use the gpsResult() signal to determine if the location was set successfully.
125
        //! With argument 0, this always signals true.
126
        //! @note When using GPSD not on localhost, don't forget the -G switch when starting gpsd there!
127
        //! @param interval set negative to just fetch one position, mseconds to start periodic query, or 0 to stop those.
128
        //! It may be better to leave it running to observe incoming data, then switch off when fix seems good.
129
        //! When disabled, the NMEA device and its serial connection is released.
130
        void locationFromGPS(int interval=-1);
131
#endif
132

133
        //! Check timezone string and return either the same or one that we use in the Stellarium location database.
134
        //! If timezone name starts with "UTC", always return unchanged.
135
        //! This is required to store timezone names exactly as we know them, and not mix ours and current-IANA spelling flavour.
136
        static QString sanitizeTimezoneStringForLocationDB(QString tzString);
137
        //! Attempt to translate a timezone name from those used in Stellarium's location database to a name which is known
138
        //! to Qt at runtime as result of QTimeZone::availableTimeZoneIds(). That list may be updated by OS anytime and is known to differ
139
        //! between OSes. Some spellings may be different, or in some cases some names get simply translated to "UTC+HH:MM" style.
140
        //! The empty string gets translated to "UTC".
141
        static QString sanitizeTimezoneStringFromLocationDB(QString dbString);
142

143
signals:
144
        //! Can be used to detect changes to the full location list
145
        //! i.e. when the user added or removed locations
146
        void locationListChanged();
147

148
#ifdef ENABLE_GPS
149
        //! emitted when GPS location query and setting location either succeed or fail.
150
        //! @param success true if successful, false in case of any error (no device, timeout, bad fix, ...).
151
        void gpsQueryFinished(bool success);
152
#endif
153
private slots:
154
        //! Process answer from online lookup of IP address
155
        void changeLocationFromNetworkLookup();
156
#ifdef ENABLE_GPS
157
        void changeLocationFromGPSQuery(const StelLocation& loc);
158
        void gpsQueryError(const QString& err);
159
        #ifdef Q_OS_WIN
160
        void positionUpdated(QGeoPositionInfo gpsPos);
161
        #endif
162
#endif
163
private:
164
        void loadRegions();
165
        void loadCountries();
166
        void loadTimeZoneFixes();
167
        void generateBinaryLocationFile(const QString& txtFile, bool isUserLocation, const QString& binFile) const;
168

169
        //! Load cities from a file
170
        static LocationMap loadCities(const QString& fileName, bool isUserLocation);
171
        static LocationMap loadCitiesBin(const QString& fileName);
172

173
        //! The list of all loaded locations
174
        LocationMap locations;
175
        //! A Map which has to be used to replace, system- and Qt-version dependent,
176
        //! timezone names from our location database to the code names currently used by Qt.
177
        //! Required to avoid https://bugs.launchpad.net/stellarium/+bug/1662132,
178
        //! details on IANA names with Qt at http://doc.qt.io/qt-5/qtimezone.html.
179
        //! This has nothing to do with the Windows timezone names!
180
        //! Key: TZ name as used in our database.
181
        //! Value: TZ name as may be available instead in the currently running version of Qt.
182
        //! The list has to be maintained based on empirical observations.
183
        //! @todo Make it load from a configurable external file.
184
        static TimezoneNameMap locationDBToIANAtranslations;
185

186
        static QList<GeoRegion> regions;
187
        static QMap<QString, QString> countryCodeToRegionMap;
188
        static QMap<QString, QString> countryNameToCodeMap;
189
        static QString tzfFileName;
190
        static bool unknownTZ;
191
        
192
        StelLocation lastResortLocation;
193

194
        GPSLookupHelper *nmeaHelper,*libGpsHelper;
195
#ifdef Q_OS_WIN
196
        QGeoPositionInfoSource *positionSource=Q_NULLPTR;
197
#endif
198
};
199

200
#endif // STELLOCATIONMGR_HPP
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc