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

Stellarium / stellarium / 6685397774

29 Oct 2023 07:37PM UTC coverage: 11.735% (-0.002%) from 11.737%
6685397774

push

github

10110111
Deduplicate title bar implementation

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

14842 of 126472 relevant lines covered (11.74%)

21617.74 hits per line

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

0.0
/src/gui/DateTimeDialog.cpp
1
/*
2
 * Stellarium
3
 * Copyright (C) 2008 Nigel Kerr
4
 * Copyright (C) 2012 Timothy Reaves
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
19
*/
20

21
#include "Dialog.hpp"
22
#include "DateTimeDialog.hpp"
23
#include "StelApp.hpp"
24
#include "StelCore.hpp"
25
#include "StelLocaleMgr.hpp"
26
#include "StelUtils.hpp"
27
#include "StelGui.hpp"
28

29
#include "ui_dateTimeDialogGui.h"
30

31
#include <QDebug>
32
#include <QFrame>
33
#include <QLineEdit>
34

35
DateTimeDialog::DateTimeDialog(QObject* parent) :
×
36
        StelDialog("DateTime", parent),
37
        year(0),
×
38
        month(0),
×
39
        day(0),
×
40
        hour(0),
×
41
        minute(0),
×
42
        second(0),
×
43
        jd(0),
×
44
        oldyear(0),
×
45
        oldmonth(0),
×
46
        oldday(0),
×
47
        enableFocus(false)
×
48
{
49
        ui = new Ui_dateTimeDialogForm;
×
50
        updateTimer=new QTimer(this); // parenting will auto-delete timer on destruction!
×
51
        connect (updateTimer, SIGNAL(timeout()), this, SLOT(onTimerTimeout()));
×
52
        updateTimer->start(20); // must be short enough to allow fast scroll-through.
×
53
        core = StelApp::getInstance().getCore();
×
54
}
×
55

56
DateTimeDialog::~DateTimeDialog()
×
57
{
58
        delete ui;
×
59
        ui=Q_NULLPTR;
×
60
}
×
61

62
void DateTimeDialog::createDialogContent()
×
63
{
64
        ui->setupUi(dialog);
×
65
        setDateTime(core->getJD());
×
66

67
        connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SLOT(retranslate()));
×
68
        connect(ui->titleBar, &TitleBar::closeClicked, this, &StelDialog::close);
×
69
        connect(ui->titleBar, SIGNAL(movedTo(QPoint)), this, SLOT(handleMovedTo(QPoint)));
×
70

71
        connectSpinnerEvents();
×
72

73
        connect(ui->spinner_second, &ExternalStepSpinBox::stepsRequested, this, [this](int steps){secondChanged(second+steps);});
×
74
        connect(ui->spinner_minute, &ExternalStepSpinBox::stepsRequested, this, [this](int steps){minuteChanged(minute+steps);});
×
75
        connect(ui->spinner_hour  , &ExternalStepSpinBox::stepsRequested, this, [this](int steps){  hourChanged(hour  +steps);});
×
76
        connect(ui->spinner_day   , &ExternalStepSpinBox::stepsRequested, this, [this](int steps){   dayChanged(day   +steps);});
×
77
        connect(ui->spinner_month , &ExternalStepSpinBox::stepsRequested, this, [this](int steps){ monthChanged(month +steps);});
×
78

79
        StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui());
×
80
        if (gui)
×
81
        {
82
                connect(gui, SIGNAL(flagEnableFocusOnDaySpinnerChanged(bool)), this, SLOT(setFlagEnableFocus(bool)));
×
83
                setFlagEnableFocus(gui->getFlagEnableFocusOnDaySpinner());
×
84
        }
85
}
×
86

87
void DateTimeDialog::setFlagEnableFocus(bool b)
×
88
{
89
        if (enableFocus!=b)
×
90
        {
91
                enableFocus=b;
×
92
                if (enableFocus)
×
93
                        ui->spinner_day->setFocus();
×
94
                else
95
                        ui->dateTimeTab->setFocus();
×
96
        }
97
}
×
98

99
void DateTimeDialog::connectSpinnerEvents() const
×
100
{
101
        connect(ui->spinner_year, SIGNAL(valueChanged(int)), this, SLOT(yearChanged(int)));
×
102
        connect(ui->spinner_month, SIGNAL(valueChanged(int)), this, SLOT(monthChanged(int)));
×
103
        connect(ui->spinner_day, SIGNAL(valueChanged(int)), this, SLOT(dayChanged(int)));
×
104
        connect(ui->spinner_hour, SIGNAL(valueChanged(int)), this, SLOT(hourChanged(int)));
×
105
        connect(ui->spinner_minute, SIGNAL(valueChanged(int)), this, SLOT(minuteChanged(int)));
×
106
        connect(ui->spinner_second, SIGNAL(valueChanged(int)), this, SLOT(secondChanged(int)));
×
107
        connect(ui->spinner_jd, SIGNAL(valueChanged(double)), this, SLOT(jdChanged(double)));
×
108
        connect(ui->spinner_mjd, SIGNAL(valueChanged(double)), this, SLOT(mjdChanged(double)));
×
109
}
×
110

111
void DateTimeDialog::disconnectSpinnerEvents()const
×
112
{
113
        disconnect(ui->spinner_year, SIGNAL(valueChanged(int)), this, SLOT(yearChanged(int)));
×
114
        disconnect(ui->spinner_month, SIGNAL(valueChanged(int)), this, SLOT(monthChanged(int)));
×
115
        disconnect(ui->spinner_day, SIGNAL(valueChanged(int)), this, SLOT(dayChanged(int)));
×
116
        disconnect(ui->spinner_hour, SIGNAL(valueChanged(int)), this, SLOT(hourChanged(int)));
×
117
        disconnect(ui->spinner_minute, SIGNAL(valueChanged(int)), this, SLOT(minuteChanged(int)));
×
118
        disconnect(ui->spinner_second, SIGNAL(valueChanged(int)), this, SLOT(secondChanged(int)));
×
119
        disconnect(ui->spinner_jd, SIGNAL(valueChanged(double)), this, SLOT(jdChanged(double)));
×
120
        disconnect(ui->spinner_mjd, SIGNAL(valueChanged(double)), this, SLOT(mjdChanged(double)));
×
121
}
×
122

123

124
//! take in values, adjust for calendrical correctness if needed, and push to
125
//! the widgets and signals
126
bool DateTimeDialog::makeValidAndApply(int y, int m, int d, int h, int min, int s)
×
127
{
128
        if (!StelUtils::changeDateTimeForRollover(y, m, d, h, min, s, &year, &month, &day, &hour, &minute, &second)) {
×
129
                year =  y;
×
130
                month = m;
×
131
                day = d;
×
132
                hour =  h;
×
133
                minute = min;
×
134
                second = s;
×
135
        }
136

137
        pushToWidgets();
×
138
        core->setJD(newJd());
×
139
        return true;
×
140
}
141

142
bool DateTimeDialog::applyJD(double jday)
×
143
{
144
        pushToWidgets();
×
145
        core->setJD(jday);
×
146
        return true;
×
147
}
148

149
void DateTimeDialog::retranslate()
×
150
{
151
        if (dialog) {
×
152
                ui->retranslateUi(dialog);
×
153
        }
154
}
×
155

156
void DateTimeDialog::close()
×
157
{
158
        ui->dateTimeTab->setFocus();
×
159
        StelDialog::close();
×
160
}
×
161

162
/************************************************************************
163
 year slider or dial changed
164
************************************************************************/
165

166
void DateTimeDialog::yearChanged(int newyear)
×
167
{
168
        if ( year != newyear )
×
169
        {
170
                makeValidAndApply( newyear, month, day, hour, minute, second );
×
171
        }
172
}
×
173

174
void DateTimeDialog::monthChanged(int newmonth)
×
175
{
176
        if ( month != newmonth )
×
177
        {
178
                makeValidAndApply( year, newmonth, day, hour, minute, second );
×
179
        }
180
}
×
181

182
void DateTimeDialog::dayChanged(int newday)
×
183
{
184
        int delta = newday - day;
×
185
        applyJD(jd + delta);
×
186
}
×
187

188
void DateTimeDialog::hourChanged(int newhour)
×
189
{
190
        int delta = newhour - hour;
×
191
        applyJD(jd + delta/24.);
×
192
}
×
193

194
void DateTimeDialog::minuteChanged(int newminute)
×
195
{
196
        int delta = newminute - minute;
×
197
        applyJD(jd + delta/1440.);
×
198
}
×
199

200
void DateTimeDialog::secondChanged(int newsecond)
×
201
{
202
        int delta = newsecond - second;
×
203
        applyJD(jd + delta/86400.);
×
204
}
×
205

206
void DateTimeDialog::jdChanged(double njd)
×
207
{
208
        applyJD(njd);
×
209
}
×
210

211
void DateTimeDialog::mjdChanged(double nmjd)
×
212
{
213
        double delta = nmjd - getMjd();
×
214
        applyJD(jd + delta);
×
215
}
×
216

217
double DateTimeDialog::newJd()
×
218
{
219
        double cjd;
220
        StelUtils::getJDFromDate(&cjd, year, month, day, hour, minute, static_cast<float>(second));
×
221
        cjd -= (core->getUTCOffset(cjd)/24.0); // local tz -> UTC
×
222

223
        return cjd;
×
224
}
225

226

227
void DateTimeDialog::pushToWidgets()
×
228
{
229
        disconnectSpinnerEvents();
×
230

231
        // Don't touch spinboxes that don't change. Otherwise it interferes with
232
        // typing (e.g. when starting a number with leading zero), and sometimes
233
        // even with stepping (e.g. the user clicks an arrow, but the number
234
        // remains the same, although the time did change).
235
        if(ui->spinner_year->value() != year)
×
236
                ui->spinner_year->setValue(year);
×
237
        if(ui->spinner_month->value() != month)
×
238
                ui->spinner_month->setValue(month);
×
239
        if(ui->spinner_day->value() != day)
×
240
                ui->spinner_day->setValue(day);
×
241
        if(ui->spinner_hour->value() != hour)
×
242
                ui->spinner_hour->setValue(hour);
×
243
        if(ui->spinner_minute->value() != minute)
×
244
                ui->spinner_minute->setValue(minute);
×
245
        if(ui->spinner_second->value() != second)
×
246
                ui->spinner_second->setValue(second);
×
247

248
        ui->spinner_jd->setValue(jd);
×
249
        ui->spinner_mjd->setValue(getMjd());
×
250

251
        if (jd<2299161) // 1582-10-15
×
252
        {
253
                ui->dateTimeTab->setToolTip(q_("Date and Time in Julian calendar"));
×
254
                ui->dateTimeTabWidget->setTabToolTip(0, q_("Date and Time in Julian calendar"));
×
255
        }
256
        else
257
        {
258
                ui->dateTimeTab->setToolTip(q_("Date and Time in Gregorian calendar"));
×
259
                ui->dateTimeTabWidget->setTabToolTip(0, q_("Date and Time in Gregorian calendar"));
×
260
        }
261

262
        connectSpinnerEvents();
×
263
}
×
264

265
/************************************************************************
266
Prepare date elements from newJd and send to spinner_*
267
 ************************************************************************/
268
void DateTimeDialog::setDateTime(double newJd)
×
269
{
270
        if (this->visible())
×
271
        {
272
                // JD and MJD should be at the UTC scale on the window!
273
                double newJdC = newJd + core->getUTCOffset(newJd)/24.0; // UTC -> local tz
×
274
                StelUtils::getDateTimeFromJulianDay(newJdC, &year, &month, &day, &hour, &minute, &second);
×
275
                jd = newJd;
×
276

277
                pushToWidgets();
×
278

279
                if (oldyear != year || oldmonth != month || oldday != day) 
×
280
                        emit core->dateChanged();
×
281
                if (oldyear != year) 
×
282
                        emit core->dateChangedByYear(year);
×
283
                if (oldmonth != month) 
×
284
                        emit core->dateChangedForMonth();
×
285

286
                oldyear = year;
×
287
                oldmonth = month;
×
288
                oldday = day;
×
289
        }
290
}
×
291

292
// handle timer-triggered update
293
void DateTimeDialog::onTimerTimeout(void)
×
294
{
295
        this->setDateTime(core->getJD());
×
296
}
×
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