• 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/Quasars/src/gui/QuasarsDialog.cpp
1
/*
2
 * Stellarium Quasars Plug-in GUI
3
 *
4
 * Copyright (C) 2012, 2018 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_quasarsDialog.h"
30
#include "QuasarsDialog.hpp"
31
#include "Quasars.hpp"
32
#include "StelModuleMgr.hpp"
33
#include "StelStyle.hpp"
34
#include "StelGui.hpp"
35
#include "StelTranslator.hpp"
36

37
QuasarsDialog::QuasarsDialog()
×
38
        : StelDialog("Quasars")
39
        , qsr(Q_NULLPTR)
×
40
        , updateTimer(Q_NULLPTR)
×
41
{
42
        ui = new Ui_quasarsDialog;
×
43
}
×
44

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

56
void QuasarsDialog::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 QuasarsDialog::createDialogContent()
×
68
{
69
        qsr = GETSTELMODULE(Quasars);
×
70
        ui->setupUi(dialog);
×
71
        ui->tabs->setCurrentIndex(0);        
×
72
        connect(&StelApp::getInstance(), SIGNAL(languageChanged()),
×
73
                this, SLOT(retranslate()));
74

75
        // Settings tab / updates group
76
        ui->displayModeCheckBox->setChecked(qsr->getDisplayMode());
×
77
        connect(ui->displayModeCheckBox, SIGNAL(stateChanged(int)), this, SLOT(setDistributionEnabled(int)));
×
78
        ui->displayAtStartupCheckBox->setChecked(qsr->getEnableAtStartup());
×
79
        connect(ui->displayAtStartupCheckBox, SIGNAL(stateChanged(int)), this, SLOT(setDisplayAtStartupEnabled(int)));
×
80
        ui->displayShowQuasarsButton->setChecked(qsr->getFlagShowQuasarsButton());
×
81
        connect(ui->displayShowQuasarsButton, SIGNAL(stateChanged(int)), this, SLOT(setDisplayShowQuasarsButton(int)));
×
82
        ui->displayUseQuasarMarkersButton->setChecked(qsr->getFlagUseQuasarMarkers());
×
83
        connect(ui->displayUseQuasarMarkersButton, SIGNAL(stateChanged(int)), this, SLOT(setDisplayUseQuasarMarkersButton(int)));
×
84
        connect(ui->internetUpdatesCheckbox, SIGNAL(stateChanged(int)), this, SLOT(setUpdatesEnabled(int)));
×
85
        connect(ui->updateButton, SIGNAL(clicked()), this, SLOT(updateJSON()));
×
86
        connect(qsr, SIGNAL(updateStateChanged(Quasars::UpdateState)), this, SLOT(updateStateReceiver(Quasars::UpdateState)));
×
87
        connect(qsr, SIGNAL(jsonUpdateComplete(void)), this, SLOT(updateCompleteReceiver(void)));        
×
88
        connect(ui->updateFrequencySpinBox, SIGNAL(valueChanged(int)), this, SLOT(setUpdateValues(int)));
×
89
        refreshUpdateValues(); // fetch values for last updated and so on
×
90
        // if the state didn't change, setUpdatesEnabled will not be called, so we force it
91
        setUpdatesEnabled(ui->internetUpdatesCheckbox->checkState());
×
92

93
        connectColorButton(ui->quasarMarkerColor, "Quasars.quasarsColor", "Quasars/marker_color");
×
94

95
        updateTimer = new QTimer(this);
×
96
        connect(updateTimer, SIGNAL(timeout()), this, SLOT(refreshUpdateValues()));
×
97
        updateTimer->start(7000);
×
98

99
        connect(ui->titleBar, &TitleBar::closeClicked, this, &StelDialog::close);
×
100
        connect(ui->titleBar, SIGNAL(movedTo(QPoint)), this, SLOT(handleMovedTo(QPoint)));
×
101

102
        connect(ui->restoreDefaultsButton, SIGNAL(clicked()), this, SLOT(restoreDefaults()));
×
103
        connect(ui->saveSettingsButton, SIGNAL(clicked()), this, SLOT(saveSettings()));
×
104

105
        // About tab
106
        setAboutHtml();
×
107
        StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui());
×
108
        if(gui!=Q_NULLPTR)
×
109
                ui->aboutTextBrowser->document()->setDefaultStyleSheet(QString(gui->getStelStyle().htmlStyleSheet));
×
110

111
        updateGuiFromSettings();
×
112
}
×
113

114
void QuasarsDialog::setAboutHtml(void)
×
115
{
116
        QString html = "<html><head></head><body>";
×
117
        html += "<h2>" + q_("Quasars Plug-in") + "</h2><table width=\"90%\">";
×
118
        html += "<tr width=\"30%\"><td><strong>" + q_("Version") + ":</strong></td><td>" + QUASARS_PLUGIN_VERSION + "</td></tr>";
×
119
        html += "<tr><td><strong>" + q_("License") + ":</strong></td><td>" + QUASARS_PLUGIN_LICENSE + "</td></tr>";
×
120
        html += "<tr><td><strong>" + q_("Author") + ":</strong></td><td>Alexander Wolf</td></tr>";
×
121
        html += "</table>";
×
122

123
        html += QString("<p>%1 (<a href=\"%2\">%3</a>)</p>").arg(
×
124
                        q_("The Quasars plugin provides visualization of some quasars brighter than visual magnitude 18. The catalogue of quasars was compiled from \"Quasars and Active Galactic Nuclei\" (13th Ed.)"),
×
125
                        "http://adsabs.harvard.edu/abs/2010A%26A...518A..10V",
126
                        q_("Veron+ 2010"));
×
127

128
        html += "</ul><p>" + q_("The current catalog contains info about %1 quasars.").arg(qsr->getCountQuasars()) + "</p>";
×
129
        html += StelApp::getInstance().getModuleMgr().getStandardSupportLinksInfo("Quasars plugin");
×
130
        html += "</body></html>";
×
131

132
        StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui());
×
133
        if(gui!=Q_NULLPTR)
×
134
        {
135
                QString htmlStyleSheet(gui->getStelStyle().htmlStyleSheet);
×
136
                ui->aboutTextBrowser->document()->setDefaultStyleSheet(htmlStyleSheet);
×
137
        }
×
138

139
        ui->aboutTextBrowser->setHtml(html);
×
140
}
×
141

142
void QuasarsDialog::refreshUpdateValues(void)
×
143
{
144
        QString nextUpdate = q_("Next update");
×
145
        ui->lastUpdateDateTimeEdit->setDateTime(qsr->getLastUpdate());
×
146
        ui->updateFrequencySpinBox->setValue(qsr->getUpdateFrequencyDays());
×
147
        int secondsToUpdate = qsr->getSecondsToUpdate();
×
148
        ui->internetUpdatesCheckbox->setChecked(qsr->getUpdatesEnabled());
×
149
        if (!qsr->getUpdatesEnabled())
×
150
                ui->nextUpdateLabel->setText(q_("Internet updates disabled"));
×
151
        else if (qsr->getUpdateState() == Quasars::Updating)
×
152
                ui->nextUpdateLabel->setText(q_("Updating now..."));
×
153
        else if (secondsToUpdate <= 60)
×
154
                ui->nextUpdateLabel->setText(QString("%1: %2").arg(nextUpdate, q_("< 1 minute")));
×
155
        else if (secondsToUpdate < 3600)
×
156
        {
157
                int n = (secondsToUpdate/60)+1;
×
158
                // TRANSLATORS: minutes.
159
                ui->nextUpdateLabel->setText(QString("%1: %2 %3").arg(nextUpdate, QString::number(n), qc_("m", "time")));
×
160
        }
161
        else if (secondsToUpdate < 86400)
×
162
        {
163
                int n = (secondsToUpdate/3600)+1;
×
164
                // TRANSLATORS: hours.
165
                ui->nextUpdateLabel->setText(QString("%1: %2 %3").arg(nextUpdate, QString::number(n), qc_("h", "time")));
×
166
        }
167
        else
168
        {
169
                int n = (secondsToUpdate/86400)+1;
×
170
                // TRANSLATORS: days.
171
                ui->nextUpdateLabel->setText(QString("%1: %2 %3").arg(nextUpdate, QString::number(n), qc_("d", "time")));
×
172
        }
173
}
×
174

175
void QuasarsDialog::setUpdateValues(int days)
×
176
{
177
        qsr->setUpdateFrequencyDays(days);
×
178
        refreshUpdateValues();
×
179
}
×
180

181
void QuasarsDialog::setUpdatesEnabled(int checkState)
×
182
{
183
        bool b = checkState != Qt::Unchecked;
×
184
        qsr->setUpdatesEnabled(b);
×
185
        ui->updateFrequencySpinBox->setEnabled(b);
×
186
        if(b)
×
187
                ui->updateButton->setText(q_("Update now"));
×
188
        else
189
                ui->updateButton->setText(q_("Update from files"));
×
190

191
        refreshUpdateValues();
×
192
}
×
193

194
void QuasarsDialog::setDistributionEnabled(int checkState)
×
195
{
196
        bool b = checkState != Qt::Unchecked;
×
197
        qsr->setDisplayMode(b);
×
198
}
×
199

200
void QuasarsDialog::setDisplayAtStartupEnabled(int checkState)
×
201
{
202
        bool b = checkState != Qt::Unchecked;
×
203
        qsr->setEnableAtStartup(b);
×
204
}
×
205

206
void QuasarsDialog::setDisplayShowQuasarsButton(int checkState)
×
207
{
208
        bool b = checkState != Qt::Unchecked;
×
209
        qsr->setFlagShowQuasarsButton(b);
×
210
}
×
211

212
void QuasarsDialog::setDisplayUseQuasarMarkersButton(int checkState)
×
213
{
214
        bool b = checkState != Qt::Unchecked;
×
215
        qsr->setFlagUseQuasarMarkers(b);
×
216
}
×
217

218
void QuasarsDialog::updateStateReceiver(Quasars::UpdateState state)
×
219
{
220
        //qDebug() << "QuasarsDialog::updateStateReceiver got a signal";
221
        if (state==Quasars::Updating)
×
222
                ui->nextUpdateLabel->setText(q_("Updating now..."));
×
223
        else if (state==Quasars::DownloadError || state==Quasars::OtherError)
×
224
        {
225
                ui->nextUpdateLabel->setText(q_("Update error"));
×
226
                updateTimer->start();  // make sure message is displayed for a while...
×
227
        }
228
}
×
229

230
void QuasarsDialog::updateCompleteReceiver(void)
×
231
{
232
        ui->nextUpdateLabel->setText(QString(q_("Quasars is updated")));
×
233
        // display the status for another full interval before refreshing status
234
        updateTimer->start();
×
235
        ui->lastUpdateDateTimeEdit->setDateTime(qsr->getLastUpdate());
×
236
        QTimer *timer = new QTimer(this);
×
237
        connect(timer, SIGNAL(timeout()), this, SLOT(refreshUpdateValues()));
×
238
        setAboutHtml();
×
239
}
×
240

241
void QuasarsDialog::restoreDefaults(void)
×
242
{
243
        if (askConfirmation())
×
244
        {
245
                qDebug() << "[Quasars] restore defaults...";
×
246
                qsr->restoreDefaults();
×
247
                qsr->readSettingsFromConfig();
×
248
                updateGuiFromSettings();
×
249
        }
250
        else
251
                qDebug() << "[Quasars] restore defaults is canceled...";
×
252
}
×
253

254
void QuasarsDialog::updateGuiFromSettings(void)
×
255
{
256
        ui->internetUpdatesCheckbox->setChecked(qsr->getUpdatesEnabled());
×
257
        refreshUpdateValues();
×
258
}
×
259

260
void QuasarsDialog::saveSettings(void)
×
261
{
262
        qsr->saveSettingsToConfig();
×
263
}
×
264

265
void QuasarsDialog::updateJSON(void)
×
266
{
267
        if(qsr->getUpdatesEnabled())
×
268
        {
269
                qsr->updateJSON();
×
270
        }
271
}
×
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