Skip to content

Commit

Permalink
Added ability to use a wider range of dates for AstroCalc/Phenomena t…
Browse files Browse the repository at this point in the history
…ool (fix #1327)
  • Loading branch information
alex-w committed Aug 28, 2024
1 parent 99cc172 commit a851666
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 34 deletions.
31 changes: 12 additions & 19 deletions src/gui/AstroCalcDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,19 @@ void AstroCalcDialog::createDialogContent()
QDateTime currentDT = StelUtils::jdToQDateTime(JD, Qt::LocalTime);
ui->dateFromDateTimeEdit->setDateTime(currentDT);
ui->dateToDateTimeEdit->setDateTime(currentDT.addMonths(1));
ui->phenomenFromDateEdit->setDateTime(currentDT);
ui->phenomenToDateEdit->setDateTime(currentDT.addMonths(1));
ui->rtsFromDateEdit->setDateTime(currentDT);
ui->rtsToDateEdit->setDateTime(currentDT.addMonths(1));
ui->eclipseFromYearSpinBox->setValue(currentDT.date().year());
int year, month, day;
StelUtils::getDateFromJulianDay(JD, &year, &month, &day);
ui->phenomenFromYearSpinBox->setValue(year);
ui->phenomenFromMonthSpinBox->setValue(month);
ui->eclipseFromYearSpinBox->setValue(year);

// TODO: Replace QDateTimeEdit by a new StelDateTimeEdit widget to apply full range of dates
// NOTE: https://github.com/Stellarium/stellarium/issues/711
const QDate minDate = QDate(1582, 10, 15); // QtDateTime's minimum date is 1.1.100AD, but appears to be always Gregorian.
ui->dateFromDateTimeEdit->setMinimumDate(minDate);
ui->dateToDateTimeEdit->setMinimumDate(minDate);
ui->phenomenFromDateEdit->setMinimumDate(minDate);
ui->phenomenToDateEdit->setMinimumDate(minDate);
ui->dateToDateTimeEdit->setMinimumDate(minDate);
ui->rtsFromDateEdit->setMinimumDate(minDate);
ui->rtsToDateEdit->setMinimumDate(minDate);

Expand Down Expand Up @@ -589,10 +589,9 @@ void AstroCalcDialog::populateToolTips()
QString validDates = QString("%1 1582/10/15 - 9999/12/31").arg(q_("Gregorian dates. Valid range:"));
ui->dateFromDateTimeEdit->setToolTip(validDates);
ui->dateToDateTimeEdit->setToolTip(validDates);
ui->phenomenFromDateEdit->setToolTip(validDates);
ui->phenomenToDateEdit->setToolTip(validDates);
ui->rtsFromDateEdit->setToolTip(validDates);
ui->rtsToDateEdit->setToolTip(validDates);
ui->phenomenFromYearSpinBox->setToolTip(QString("%1 %2..%3").arg(q_("Valid range years:"), QString::number(ui->phenomenFromYearSpinBox->minimum()), QString::number(ui->phenomenFromYearSpinBox->maximum())));
ui->eclipseFromYearSpinBox->setToolTip(QString("%1 %2..%3").arg(q_("Valid range years:"), QString::number(ui->eclipseFromYearSpinBox->minimum()), QString::number(ui->eclipseFromYearSpinBox->maximum())));
ui->allowedSeparationSpinBox->setToolTip(QString("%1: %2..%3").arg(q_("Valid range"), StelUtils::decDegToDmsStr(ui->allowedSeparationSpinBox->getMinimum(true)), StelUtils::decDegToDmsStr(ui->allowedSeparationSpinBox->getMaximum(true))));
ui->allowedSeparationLabel->setToolTip(QString("<p>%1</p>").arg(q_("This is a tolerance for the angular distance for conjunctions and oppositions from 0 and 180 degrees respectively.")));
Expand Down Expand Up @@ -5560,15 +5559,9 @@ void AstroCalcDialog::calculatePhenomena()

initListPhenomena();

#if QT_VERSION >= QT_VERSION_CHECK(5,14,0)
double startJD = StelUtils::qDateTimeToJd(ui->phenomenFromDateEdit->date().startOfDay(Qt::UTC));
double stopJD = StelUtils::qDateTimeToJd(ui->phenomenToDateEdit->date().endOfDay(Qt::UTC));
#else
double startJD = StelUtils::qDateTimeToJd(QDateTime(ui->phenomenFromDateEdit->date()));
double stopJD = StelUtils::qDateTimeToJd(QDateTime(ui->phenomenToDateEdit->date().addDays(1)));
#endif
if (stopJD<=startJD) // Stop warming atmosphere!..
return;
double startJD;
StelUtils::getJDFromDate(&startJD, ui->phenomenFromYearSpinBox->value(), ui->phenomenFromMonthSpinBox->value(), 1, 0, 0, 1);
double stopJD = startJD + ui->phenomenToMonthSpinBox->value()*30.4375; // month = 1/12 of year in days

QVector<PlanetP> objects;
Q_ASSERT(objects.isEmpty());
Expand Down Expand Up @@ -5781,8 +5774,8 @@ void AstroCalcDialog::calculatePhenomena()
if (planet)
{
const double currentJD = core->getJD(); // save current JD
startJD = startJD - core->getUTCOffset(startJD) / 24.;
stopJD = stopJD - core->getUTCOffset(stopJD) / 24.;
startJD -= core->getUTCOffset(startJD) / 24.;
stopJD -= core->getUTCOffset(stopJD) / 24.;

if (obj2Type == PHCLatestSelectedObject)
{
Expand Down
66 changes: 51 additions & 15 deletions src/gui/astroCalcDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1210,15 +1210,31 @@
</widget>
</item>
<item>
<widget class="QDateEdit" name="phenomenFromDateEdit">
<property name="wrapping">
<bool>true</bool>
<widget class="QSpinBox" name="phenomenFromYearSpinBox">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="displayFormat">
<string notr="true">yyyy.MM.dd</string>
<property name="minimum">
<number>-13000</number>
</property>
<property name="calendarPopup">
<bool>true</bool>
<property name="maximum">
<number>17000</number>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="phenomenFromMonthSpinBox">
<property name="toolTip">
<string>Month</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>12</number>
</property>
</widget>
</item>
Expand All @@ -1232,20 +1248,30 @@
<item>
<widget class="QLabel" name="phenomenToLabel">
<property name="text">
<string>To:</string>
<string>to the next</string>
</property>
</widget>
</item>
<item>
<widget class="QDateEdit" name="phenomenToDateEdit">
<property name="wrapping">
<bool>true</bool>
<widget class="QSpinBox" name="phenomenToMonthSpinBox">
<property name="toolTip">
<string>Duration in months</string>
</property>
<property name="displayFormat">
<string notr="true">yyyy.MM.dd</string>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="calendarPopup">
<bool>true</bool>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>60</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="phenomenToMonthsLabel">
<property name="text">
<string comment="duration, short form">mths</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -2847,6 +2873,9 @@
</item>
<item>
<widget class="QSpinBox" name="eclipseYearsSpinBox">
<property name="toolTip">
<string>Duration in years</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
Expand All @@ -2861,6 +2890,13 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="eclipseYearsFinalLabel">
<property name="text">
<string comment="duration, short form">yrs</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down

0 comments on commit a851666

Please sign in to comment.