7#include "modcalcsidtime.h"
10#include "kstarsdatetime.h"
11#include "ksnotification.h"
12#include "dialogs/locationdialog.h"
19#include <qtskipemptyparts.h>
21modCalcSidTime::modCalcSidTime(
QWidget *parent) :
QFrame(parent)
26 showCurrentTimeAndLocation();
29 connect(LocationButton, SIGNAL(clicked()),
this, SLOT(slotChangeLocation()));
30 connect(Date, SIGNAL(dateChanged(
QDate)),
this, SLOT(slotChangeDate()));
34 connect(LocationCheckBatch, SIGNAL(clicked()),
this, SLOT(slotLocationChecked()));
35 connect(DateCheckBatch, SIGNAL(clicked()),
this, SLOT(slotDateChecked()));
36 connect(LocationCheckBatch, SIGNAL(clicked()),
this, SLOT(slotHelpLabel()));
37 connect(DateCheckBatch, SIGNAL(clicked()),
this, SLOT(slotHelpLabel()));
38 connect(ComputeComboBatch, SIGNAL(currentIndexChanged(
int)),
this, SLOT(slotHelpLabel()));
40 connect(InputFileBatch, SIGNAL(urlSelected(
QUrl)),
this, SLOT(slotCheckFiles()));
41 connect(OutputFileBatch, SIGNAL(urlSelected(
QUrl)),
this, SLOT(slotCheckFiles()));
42 connect(LocationButtonBatch, SIGNAL(clicked()),
this, SLOT(slotLocationBatch()));
43 connect(RunButtonBatch, SIGNAL(clicked()),
this, SLOT(slotRunBatch()));
44 connect(ViewButtonBatch, SIGNAL(clicked()),
this, SLOT(slotViewBatch()));
46 RunButtonBatch->setEnabled(
false);
47 ViewButtonBatch->setEnabled(
false);
52void modCalcSidTime::showCurrentTimeAndLocation()
55 LT->setTime(data->
lt().
time());
56 Date->setDate(data->
lt().
date());
59 LocationButton->setText(geo->
fullName());
60 geoBatch = data->
geo();
61 LocationButtonBatch->setText(geoBatch->
fullName());
63 slotConvertST(LT->time());
66void modCalcSidTime::slotChangeLocation()
76 LocationButton->setText(geo->
fullName());
79 slotConvertST(LT->time());
85void modCalcSidTime::slotChangeDate()
87 slotConvertST(LT->time());
90void modCalcSidTime::slotConvertST(
const QTime <)
93 ST->blockSignals(
true);
94 ST->setTime(computeLTtoST(lt));
95 ST->blockSignals(
false);
98void modCalcSidTime::slotConvertLT(
const QTime &st)
101 LT->blockSignals(
true);
102 LT->setTime(computeSTtoLT(st));
103 LT->blockSignals(
false);
109 dms st = geo->GSTtoLST(utdt.
gst());
118 dms gst = geo->LSTtoGST(lst);
123void modCalcSidTime::slotDateChecked()
125 DateBatch->setEnabled(!DateCheckBatch->isChecked());
128void modCalcSidTime::slotLocationChecked()
130 LocationButtonBatch->setEnabled(!LocationCheckBatch->isChecked());
132 if (LocationCheckBatch->isChecked())
134 QString message =
i18n(
"Location strings consist of the "
135 "comma-separated names of the city, province and country. "
136 "If the string contains spaces, enclose it in quotes so it "
137 "gets parsed properly.");
140 "DontShowLocationStringMessageBox");
144void modCalcSidTime::slotHelpLabel()
147 if (ComputeComboBatch->currentIndex() == 0)
155 if (LocationCheckBatch->checkState() ==
Qt::Checked)
158 QString inListString = inList[0];
159 if (inList.
size() == 2)
160 inListString =
i18n(
"%1 and %2", inList[0], inList[1]);
161 if (inList.
size() == 3)
162 inListString =
i18n(
"%1, %2 and %3", inList[0], inList[1], inList[2]);
164 HelpLabel->setText(
i18n(
"Specify %1 in the input file.", inListString));
167void modCalcSidTime::slotLocationBatch()
177 LocationButtonBatch->setText(geoBatch->
fullName());
183void modCalcSidTime::slotCheckFiles()
185 if (!InputFileBatch->lineEdit()->text().isEmpty() && !OutputFileBatch->lineEdit()->text().isEmpty())
187 RunButtonBatch->setEnabled(
true);
191 RunButtonBatch->setEnabled(
false);
195void modCalcSidTime::slotRunBatch()
197 QString inputFileName = InputFileBatch->url().toLocalFile();
201 QFile f(inputFileName);
204 QString message =
i18n(
"Could not open file %1.", f.fileName());
205 KSNotification::sorry(message,
i18n(
"Could Not Open File"));
206 inputFileName.
clear();
211 processLines(istream);
213 ViewButtonBatch->setEnabled(
true);
219 QString message =
i18n(
"Invalid file: %1", inputFileName);
220 KSNotification::sorry(message,
i18n(
"Invalid file"));
221 inputFileName.
clear();
226void modCalcSidTime::processLines(
QTextStream &istream)
228 QFile fOut(OutputFileBatch->url().toLocalFile());
234 QTime inTime, outTime;
237 if (!DateCheckBatch->isChecked())
238 dt = DateBatch->date();
240 while (!istream.
atEnd())
248 if (LocationCheckBatch->isChecked())
254 if (line.
count(q) == 2)
257 int iEnd = line.
indexOf(q, iStart + 1);
258 QString locationString = line.
mid(iStart, iEnd - iStart + 1);
259 line.
remove(locationString);
264 for (
int i = 0; i < locationFields.
size(); i++)
265 locationFields[i] = locationFields[i].trimmed();
267 if (locationFields.
size() == 1)
268 locationFields.
insert(1,
"");
269 if (locationFields.
size() == 2)
270 locationFields.
insert(1,
"");
271 if (locationFields.
size() != 3)
273 qDebug() << Q_FUNC_INFO <<
"Error: could not parse location string: " << locationString;
277 geoBatch = KStarsData::Instance()->locationNamed(locationFields[0], locationFields[1],
279 if (geoBatch ==
nullptr)
281 qDebug() << Q_FUNC_INFO <<
"Error: location not found in database: " << locationString;
287 if (DateCheckBatch->isChecked())
290 for (
auto &s : fields)
298 qDebug() << Q_FUNC_INFO <<
"Error: did not find a valid date string in: " << line;
304 for (
auto &s : fields)
315 qDebug() << Q_FUNC_INFO <<
"Error: did not find a valid time string in: " << line;
319 if (geoBatch !=
nullptr)
321 if (ComputeComboBatch->currentIndex() == 0)
325 ksdt = geoBatch->LTtoUT(ksdt);
326 dms lst = geoBatch->GSTtoLST(ksdt.gst());
335 QTime ut = ksdt.GSTtoUT(geoBatch->LSTtoGST(lst));
337 ksdt = geoBatch->UTtoLT(ksdt);
338 outTime = ksdt.time();
350void modCalcSidTime::slotViewBatch()
352 QFile fOut(OutputFileBatch->url().toLocalFile());
357 while (!istream.
atEnd())
363 OutputFileBatch->url().toLocalFile());
Contains all relevant information for specifying a location on Earth: City Name, State/Province name,...
KStarsData is the backbone of KStars.
const KStarsDateTime & lt() const
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
QTime GSTtoUT(dms GST) const
Convert a given Greenwich Sidereal Time to Universal Time (=Greenwich Mean Time).
Dialog for changing the geographic location of the observer.
An angle, stored as degrees, but expressible in many ways.
virtual void setH(const double &x)
Sets floating-point value of angle, in hours.
QString i18n(const char *text, const TYPE &arg...)
void informationList(QWidget *parent, const QString &text, const QStringList &strlist, const QString &title=QString(), const QString &dontShowAgainName=QString(), Options options=Notify)
void information(QWidget *parent, const QString &text, const QString &title=QString(), const QString &dontShowAgainName=QString(), Options options=Notify)
QDate fromString(QStringView string, QStringView format, QCalendar cal)
bool isValid(int year, int month, int day)
bool exists() const const
void append(QList< T > &&value)
iterator insert(const_iterator before, parameter_type value)
qsizetype size() const const
QString toString(QDate date, FormatType format) const const
qsizetype count() const const
qsizetype indexOf(QChar ch, qsizetype from, Qt::CaseSensitivity cs) const const
QString mid(qsizetype position, qsizetype n) const const
QString & remove(QChar ch, Qt::CaseSensitivity cs)
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
QString trimmed() const const
QString readLine(qint64 maxlen)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QTime fromString(QStringView string, QStringView format)
bool isValid(int h, int m, int s, int ms)