Kstars

satellitegroup.cpp
1 /*
2  SPDX-FileCopyrightText: 2011 Jerome SONRIER <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "satellitegroup.h"
8 
9 #include "ksutils.h"
10 #include "kspaths.h"
11 #include "skyobjects/satellite.h"
12 
13 #include <QTextStream>
14 
15 SatelliteGroup::SatelliteGroup(const QString& name, const QString& tle_filename, const QUrl& update_url)
16 {
17  m_name = name;
18  m_tle_file = tle_filename;
19  m_tle_url = update_url;
20 
21  // Read TLE file and create satellites
22  readTLE();
23 }
24 
26 {
27  QFile file;
28  QString line1, line2;
29 
30  // Delete all satellites
31  qDeleteAll(*this);
32  clear();
33 
34  // Read TLE file
35  if (KSUtils::openDataFile(file, m_tle_file))
36  {
37  QTextStream stream(&file);
38  while (!stream.atEnd())
39  {
40  // Read satellite name
41  QString sat_name = stream.readLine().trimmed();
42  line1 = stream.readLine();
43  line2 = stream.readLine();
44  // Create a new satellite and add it to the list of satellites
45  if (line1.startsWith('1') && line2.startsWith('2'))
46  append(new Satellite(sat_name, line1, line2));
47  }
48  file.close();
49  }
50 }
51 
53 {
55 
56  while (sats.hasNext())
57  {
58  Satellite *sat = sats.next();
59 
60  if (sat->selected())
61  {
62  int rc = sat->updatePos();
63  // If position cannot be calculated, remove it from list
64  if (rc != 0)
65  sats.remove();
66  }
67  }
68 }
69 
71 {
72  // Return absolute path with "file:" before the path
73  //return QUrl( "file:" + (QDir(KSPaths::writableLocation(QStandardPaths::AppLocalDataLocation)).filePath(m_tle_file));
74  return QUrl::fromLocalFile(QDir(KSPaths::writableLocation(QStandardPaths::AppLocalDataLocation)).filePath(m_tle_file));
75 }
76 
78 {
79  return m_tle_url;
80 }
81 
83 {
84  return m_name;
85 }
void append(const T &value)
QString trimmed() const const
bool selected()
Definition: satellite.cpp:1299
SatelliteGroup(const QString &name, const QString &tle_filename, const QUrl &update_url)
Constructor.
bool hasNext() const const
bool atEnd() const const
QUrl fromLocalFile(const QString &localFile)
QString readLine(qint64 maxlen)
void readTLE()
Read TLE file of the group and create all satellites found in the file.
virtual void close() override
void updateSatellitesPos()
Compute current position of the each satellites in the group.
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
int updatePos()
Update satellite position.
Definition: satellite.cpp:706
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 19 2022 03:57:54 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.