• 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
/plugins/Pulsars/src/gui/PulsarsDialog.cpp
1
/*
2
 * Stellarium Pulsars Plug-in GUI
3
 *
4
 * Copyright (C) 2012 Alexander Wolf
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 <QDebug>
22
#include <QTimer>
23
#include <QDateTime>
24
#include <QUrl>
25
#include <QFileDialog>
26
#include <QColorDialog>
27

28
#include "StelApp.hpp"
29
#include "ui_pulsarsDialog.h"
30
#include "PulsarsDialog.hpp"
31
#include "Pulsars.hpp"
32
#include "StelModuleMgr.hpp"
33
#include "StelStyle.hpp"
34
#include "StelGui.hpp"
35
#include "StelTranslator.hpp"
36

37
PulsarsDialog::PulsarsDialog()
×
38
        : StelDialog("Pulsars")
39
        , psr(Q_NULLPTR)
×
40
        , updateTimer(Q_NULLPTR)
×
41
{
42
        ui = new Ui_pulsarsDialog;
×
43
}
×
44

45
PulsarsDialog::~PulsarsDialog()
×
46
{
47
        if (updateTimer)
×
48
        {
49
                updateTimer->stop();
×
50
                delete updateTimer;
×
51
                updateTimer = Q_NULLPTR;
×
52
        }
53
        delete ui;
×
54
}
×
55

56
void PulsarsDialog::retranslate()
×
57
{
58
        if (dialog)
×
59
        {
60
                ui->retranslateUi(dialog);
×
61
                refreshUpdateValues();
×
62
                setAboutHtml();
×
63
        }
64
}
×
65

66
// Initialize the dialog widgets and connect the signals/slots
67
void PulsarsDialog::createDialogContent()
×
68
{
69
        psr = GETSTELMODULE(Pulsars);
×
70
        ui->setupUi(dialog);
×
71
        ui->tabs->setCurrentIndex(0);        
×
72
        connect(&StelApp::getInstance(), SIGNAL(languageChanged()),
×
73
                this, SLOT(retranslate()));
74

75
        // Kinetic scrolling
76
        kineticScrollingList << ui->aboutTextBrowser;
×
77
        StelGui* gui= dynamic_cast<StelGui*>(StelApp::getInstance().getGui());
×
78
        if (gui)
×
79
        {
80
                enableKineticScrolling(gui->getFlagUseKineticScrolling());
×
81
                connect(gui, SIGNAL(flagUseKineticScrollingChanged(bool)), this, SLOT(enableKineticScrolling(bool)));
×
82
        }
83

84
        // Settings tab / updates group
85
        ui->displayModeCheckBox->setChecked(psr->getDisplayMode());
×
86
        connect(ui->displayModeCheckBox, SIGNAL(stateChanged(int)), this, SLOT(setDistributionEnabled(int)));
×
87
        ui->displayAtStartupCheckBox->setChecked(psr->getEnableAtStartup());
×
88
        connect(ui->displayAtStartupCheckBox, SIGNAL(stateChanged(int)), this, SLOT(setDisplayAtStartupEnabled(int)));
×
89
        ui->displayShowPulsarsButton->setChecked(psr->getFlagShowPulsarsButton());
×
90
        ui->displaySeparateColorsCheckBox->setChecked(psr->getGlitchFlag());
×
91
        ui->displayFilteredPulsarsCheckBox->setChecked(psr->getFilteredMode());
×
92
        ui->mJyDoubleSpinBox->setValue(psr->getFilterValue());
×
93
        connect(ui->displayShowPulsarsButton, SIGNAL(stateChanged(int)), this, SLOT(setDisplayShowPulsarsButton(int)));
×
94
        connect(ui->displaySeparateColorsCheckBox, SIGNAL(stateChanged(int)), this, SLOT(setSeparateColorsFlag(int)));
×
95
        connect(ui->displayFilteredPulsarsCheckBox, SIGNAL(stateChanged(int)), this, SLOT(setFilteringEnabled(int)));
×
96
        connect(ui->mJyDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setFilterValue(double)));
×
97
        connect(ui->internetUpdatesCheckbox, SIGNAL(stateChanged(int)), this, SLOT(setUpdatesEnabled(int)));
×
98
        connect(ui->updateButton, SIGNAL(clicked()), this, SLOT(updateJSON()));
×
99
        connect(psr, SIGNAL(updateStateChanged(Pulsars::UpdateState)), this, SLOT(updateStateReceiver(Pulsars::UpdateState)));
×
100
        connect(psr, SIGNAL(jsonUpdateComplete(void)), this, SLOT(updateCompleteReceiver(void)));        
×
101
        connect(ui->updateFrequencySpinBox, SIGNAL(valueChanged(int)), this, SLOT(setUpdateValues(int)));
×
102
        refreshUpdateValues(); // fetch values for last updated and so on
×
103
        // if the state didn't change, setUpdatesEnabled will not be called, so we force it
104
        setUpdatesEnabled(ui->internetUpdatesCheckbox->checkState());
×
105

106
        connectColorButton(ui->pulsarMarkerColor,         "Pulsars.markerColor", "Pulsars/marker_color");
×
107
        connectColorButton(ui->pulsarGlitchesMarkerColor, "Pulsars.glitchColor", "Pulsars/glitch_color");
×
108

109
        updateTimer = new QTimer(this);
×
110
        connect(updateTimer, SIGNAL(timeout()), this, SLOT(refreshUpdateValues()));
×
111
        updateTimer->start(7000);
×
112

113
        connect(ui->titleBar, &TitleBar::closeClicked, this, &StelDialog::close);
×
114
        connect(ui->titleBar, SIGNAL(movedTo(QPoint)), this, SLOT(handleMovedTo(QPoint)));
×
115

116
        connect(ui->restoreDefaultsButton, SIGNAL(clicked()), this, SLOT(restoreDefaults()));
×
117
        connect(ui->saveSettingsButton, SIGNAL(clicked()), this, SLOT(saveSettings()));
×
118

119
        // About tab
120
        setAboutHtml();
×
121
        if(gui!=Q_NULLPTR)
×
122
                ui->aboutTextBrowser->document()->setDefaultStyleSheet(QString(gui->getStelStyle().htmlStyleSheet));
×
123

124
        updateGuiFromSettings();
×
125
}
×
126

127
void PulsarsDialog::setAboutHtml(void)
×
128
{
129
        QString html = "<html><head></head><body>";
×
130
        html += "<h2>" + q_("Pulsars Plug-in") + "</h2><table width=\"90%\">";
×
131
        html += "<tr width=\"30%\"><td><strong>" + q_("Version") + ":</strong></td><td>" + PULSARS_PLUGIN_VERSION + "</td></tr>";
×
132
        html += "<tr><td><strong>" + q_("License") + ":</strong></td><td>" + PULSARS_PLUGIN_LICENSE + "</td></tr>";
×
133
        html += "<tr><td><strong>" + q_("Author") + ":</strong></td><td>Alexander Wolf</td></tr>";
×
134
        html += "</table>";
×
135

136
        html += "<p>" + q_("This plugin plots the position of various pulsars, with object information about each one.") + "</p>";
×
137
        html += "<p>" + QString(q_("Pulsar data is derived from 'The ATNF Pulsar Catalogue'  (Manchester, R. N., Hobbs, G. B., Teoh, A. & Hobbs, M., Astron. J., 129, 1993-2006 (2005) (%1astro-ph/0412641%2))."))
×
138
                        .arg("<a href=\"http://arxiv.org/abs/astro-ph/0412641\">", "</a>") + "</p>";
×
139
        html += "<p>" + q_("Current catalog contains info about %1 pulsars.").arg(psr->getCountPulsars()) + "</p>";
×
140
        html += "<p>" + QString("<strong>%1:</strong> %2").arg(q_("Note"), q_("pulsar identifiers have the prefix 'PSR'")) + "</p>";
×
141
        html += "<h3>" + q_("Acknowledgment") + "</h3>";
×
142
        html += "<p>" + q_("We thank the following people for their contribution and valuable comments:") + "</p><ul>";
×
143
        html += "<li>" + QString("%1 (<a href='%2'>%3</a> %4)").arg(
×
144
                                 q_("Vladimir Samodourov"),
×
145
                                 "http://www.prao.ru/",
146
                                 q_("Pushchino Radio Astronomy Observatory"),
×
147
                                 q_("in Russia")) + "</li>";
×
148
        html += "<li>" + QString("%1 (<a href='%2'>%3</a> %4)").arg(
×
149
                                 q_("Maciej Serylak"),
×
150
                                 "http://www.obs-nancay.fr/",
151
                                 q_("Nancay Radioastronomical Observatory"),
×
152
                                 q_("in France")) + "</li>";
×
153
        html += "</ul>";
×
154

155
        html += StelApp::getInstance().getModuleMgr().getStandardSupportLinksInfo("Pulsars plugin");
×
156
        html += "</body></html>";
×
157

158
        StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui());
×
159
        if(gui!=Q_NULLPTR)
×
160
        {
161
                QString htmlStyleSheet(gui->getStelStyle().htmlStyleSheet);
×
162
                ui->aboutTextBrowser->document()->setDefaultStyleSheet(htmlStyleSheet);
×
163
        }
×
164

165
        ui->aboutTextBrowser->setHtml(html);
×
166
}
×
167

168
void PulsarsDialog::refreshUpdateValues(void)
×
169
{
170
        QString nextUpdate = q_("Next update");
×
171
        ui->lastUpdateDateTimeEdit->setDateTime(psr->getLastUpdate());
×
172
        ui->updateFrequencySpinBox->setValue(psr->getUpdateFrequencyDays());
×
173
        int secondsToUpdate = psr->getSecondsToUpdate();
×
174
        ui->internetUpdatesCheckbox->setChecked(psr->getUpdatesEnabled());
×
175
        if (!psr->getUpdatesEnabled())
×
176
                ui->nextUpdateLabel->setText(q_("Internet updates disabled"));
×
177
        else if (psr->getUpdateState() == Pulsars::Updating)
×
178
                ui->nextUpdateLabel->setText(q_("Updating now..."));
×
179
        else if (secondsToUpdate <= 60)
×
180
                ui->nextUpdateLabel->setText(QString("%1: %2").arg(nextUpdate, q_("< 1 minute")));
×
181
        else if (secondsToUpdate < 3600)
×
182
        {
183
                int n = (secondsToUpdate/60)+1;
×
184
                // TRANSLATORS: minutes.
185
                ui->nextUpdateLabel->setText(QString("%1: %2 %3").arg(nextUpdate, QString::number(n), qc_("m", "time")));
×
186
        }
187
        else if (secondsToUpdate < 86400)
×
188
        {
189
                int n = (secondsToUpdate/3600)+1;
×
190
                // TRANSLATORS: hours.
191
                ui->nextUpdateLabel->setText(QString("%1: %2 %3").arg(nextUpdate, QString::number(n), qc_("h", "time")));
×
192
        }
193
        else
194
        {
195
                int n = (secondsToUpdate/86400)+1;
×
196
                // TRANSLATORS: days.
197
                ui->nextUpdateLabel->setText(QString("%1: %2 %3").arg(nextUpdate, QString::number(n), qc_("d", "time")));
×
198
        }
199
}
×
200

201
void PulsarsDialog::setUpdateValues(int days)
×
202
{
203
        psr->setUpdateFrequencyDays(days);
×
204
        refreshUpdateValues();
×
205
}
×
206

207
void PulsarsDialog::setUpdatesEnabled(int checkState)
×
208
{
209
        bool b = checkState != Qt::Unchecked;
×
210
        psr->setUpdatesEnabled(b);
×
211
        ui->updateFrequencySpinBox->setEnabled(b);
×
212
        if(b)
×
213
                ui->updateButton->setText(q_("Update now"));
×
214
        else
215
                ui->updateButton->setText(q_("Update from files"));
×
216

217
        refreshUpdateValues();
×
218
}
×
219

220
void PulsarsDialog::setDistributionEnabled(int checkState)
×
221
{
222
        bool b = checkState != Qt::Unchecked;
×
223
        psr->setDisplayMode(b);
×
224
}
×
225

226
void PulsarsDialog::setFilteringEnabled(int checkState)
×
227
{
228
        bool b = checkState != Qt::Unchecked;
×
229
        psr->setFilteredMode(b);
×
230
}
×
231

232
void PulsarsDialog::setFilterValue(double v)
×
233
{
234
        psr->setFilterValue(static_cast<float>(v));
×
235
}
×
236

237
void PulsarsDialog::setDisplayAtStartupEnabled(int checkState)
×
238
{
239
        bool b = checkState != Qt::Unchecked;
×
240
        psr->setEnableAtStartup(b);
×
241
}
×
242

243
void PulsarsDialog::setDisplayShowPulsarsButton(int checkState)
×
244
{
245
        bool b = checkState != Qt::Unchecked;
×
246
        psr->setFlagShowPulsarsButton(b);
×
247
}
×
248

249
void PulsarsDialog::setSeparateColorsFlag(int checkState)
×
250
{
251
        bool b = checkState != Qt::Unchecked;
×
252
        psr->setGlitchFlag(b);
×
253
}
×
254

255
void PulsarsDialog::updateStateReceiver(Pulsars::UpdateState state)
×
256
{
257
        //qDebug() << "PulsarsDialog::updateStateReceiver got a signal";
258
        if (state==Pulsars::Updating)
×
259
                ui->nextUpdateLabel->setText(q_("Updating now..."));
×
260
        else if (state==Pulsars::DownloadError || state==Pulsars::OtherError)
×
261
        {
262
                ui->nextUpdateLabel->setText(q_("Update error"));
×
263
                updateTimer->start();  // make sure message is displayed for a while...
×
264
        }
265
}
×
266

267
void PulsarsDialog::updateCompleteReceiver(void)
×
268
{
269
        ui->nextUpdateLabel->setText(QString(q_("Pulsars is updated")));
×
270
        // display the status for another full interval before refreshing status
271
        updateTimer->start();
×
272
        ui->lastUpdateDateTimeEdit->setDateTime(psr->getLastUpdate());
×
273
        QTimer *timer = new QTimer(this);
×
274
        connect(timer, SIGNAL(timeout()), this, SLOT(refreshUpdateValues()));
×
275
        setAboutHtml();
×
276
}
×
277

278
void PulsarsDialog::restoreDefaults(void)
×
279
{
280
        if (askConfirmation())
×
281
        {
282
                qDebug() << "[Pulsars] restore defaults...";
×
283
                psr->restoreDefaults();
×
284
                psr->readSettingsFromConfig();
×
285
                updateGuiFromSettings();
×
286
        }
287
        else
288
                qDebug() << "[Pulsars] restore defaults is canceled...";
×
289
}
×
290

291
void PulsarsDialog::updateGuiFromSettings(void)
×
292
{
293
        ui->internetUpdatesCheckbox->setChecked(psr->getUpdatesEnabled());
×
294
        refreshUpdateValues();
×
295
}
×
296

297
void PulsarsDialog::saveSettings(void)
×
298
{
299
        psr->saveSettingsToConfig();
×
300
}
×
301

302
void PulsarsDialog::updateJSON(void)
×
303
{
304
        if(psr->getUpdatesEnabled())
×
305
        {
306
                psr->updateJSON();
×
307
        }
308
}
×
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