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

19
#include "StelApp.hpp"
20
#include "StelCore.hpp"
21
#include "StelSkyDrawer.hpp"
22
#include "StelTranslator.hpp"
23
#include "StelPropertyMgr.hpp"
24
#include "AtmosphereDialog.hpp"
25
#include "StelPropertyMgr.hpp"
26
#include "StelFileMgr.hpp"
27
#include "StelMainView.hpp"
28
#include "ui_atmosphereDialog.h"
29

30
#include <QFileInfo>
31
#include <QFileDialog>
32

33
namespace
34
{
35
constexpr char MODEL_PROPERTY[]      = "LandscapeMgr.atmosphereModel";
36
constexpr char MODEL_PATH_PROPERTY[] = "LandscapeMgr.atmosphereModelPath";
37
constexpr char DEFAULT_MODEL_PATH_PROPERTY[] = "LandscapeMgr.defaultAtmosphereModelPath";
38
constexpr char ERROR_PROPERTY[]       = "LandscapeMgr.atmosphereShowMySkyStoppedWithError";
39
constexpr char STATUS_TEXT_PROPERTY[] = "LandscapeMgr.atmosphereShowMySkyStatusText";
40
constexpr char ECLIPSE_SIM_QUALITY_PROPERTY[] = "LandscapeMgr.atmosphereEclipseSimulationQuality";
41
}
42

43
AtmosphereDialog::AtmosphereDialog()
×
44
        : StelDialog("Atmosphere")
×
45
{
46
        ui = new Ui_atmosphereDialogForm;
×
47
}
×
48

49
AtmosphereDialog::~AtmosphereDialog()
×
50
{
51
        delete ui;
×
52
}
×
53

54
void AtmosphereDialog::retranslate()
×
55
{
56
        if (dialog)
×
57
                ui->retranslateUi(dialog);
×
58
}
×
59

60
void AtmosphereDialog::createDialogContent()
×
61
{
62
        ui->setupUi(dialog);
×
63
        dialog->installEventFilter(this);
×
64
        
65
        //Signals and slots
66
        connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SLOT(retranslate()));
×
67
        connect(ui->titleBar, &TitleBar::closeClicked, this, &StelDialog::close);
×
68
        connect(ui->titleBar, SIGNAL(movedTo(QPoint)), this, SLOT(handleMovedTo(QPoint)));
×
69

70
        connectDoubleProperty(ui->pressureDoubleSpinBox,"StelSkyDrawer.atmospherePressure");
×
71
        connectDoubleProperty(ui->temperatureDoubleSpinBox,"StelSkyDrawer.atmosphereTemperature");
×
72
        connectDoubleProperty(ui->extinctionDoubleSpinBox,"StelSkyDrawer.extinctionCoefficient");
×
73
        connect(StelApp::getInstance().getStelPropertyManager()->getProperty(STATUS_TEXT_PROPERTY),
×
74
                        &StelProperty::changed, this, [this](const QVariant& v){ ui->showMySky_statusLabel->setText(v.toString()); });
×
75
        connect(StelApp::getInstance().getStelPropertyManager()->getProperty(ERROR_PROPERTY),
×
76
                        &StelProperty::changed, this, [this](const QVariant& v){ onErrorStateChanged(v.toBool()); });
×
77

78
        connect(ui->standardAtmosphereButton, SIGNAL(clicked()), this, SLOT(setStandardAtmosphere()));
×
79

80
        // Experimental settings, protected by Skylight.flagGuiPublic
81
        StelPropertyMgr* propMgr = StelApp::getInstance().getStelPropertyManager();
×
82
        if (propMgr->getProperty("Skylight.flagGuiPublic")->getValue().toBool())
×
83
        {
84
                connectBoolProperty(ui->checkBox_TfromK, "StelSkyDrawer.flagTfromK");
×
85

86
                if (ui->checkBox_TfromK->isChecked())
×
87
                {
88
                        // prepare T display
89
                        double T=25.*(propMgr->getProperty("StelSkyDrawer.extinctionCoefficient")->getValue().toDouble()-0.16)+1.;
×
90
                        ui->doubleSpinBox_T->setValue(T);
×
91
                }
92
                connect(ui->checkBox_TfromK, SIGNAL(toggled(bool)), ui->doubleSpinBox_T, SLOT(setDisabled(bool)));
×
93
                connect(ui->extinctionDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setTfromK(double)));
×
94
                connectDoubleProperty(ui->doubleSpinBox_T, "StelSkyDrawer.turbidity");
×
95

96
                connectBoolProperty(ui->checkBox_noScatter, "LandscapeMgr.atmosphereNoScatter");
×
97
        }
98
        else
99
                ui->groupBox_experimental->hide();
×
100

101
#ifdef ENABLE_SHOWMYSKY
102
        connect(ui->atmosphereModel, &QComboBox::currentTextChanged, this, &AtmosphereDialog::onModelChoiceChanged);
×
103
        connect(ui->showMySky_pathToModelBrowseBtn, &QPushButton::clicked, this, &AtmosphereDialog::browsePathToModel);
×
104
        connect(ui->showMySky_pathToModelEdit, &QLineEdit::textChanged, this, &AtmosphereDialog::onPathToModelChanged);
×
105
        connect(ui->showMySky_pathToModelEdit, &QLineEdit::editingFinished, this, &AtmosphereDialog::onPathToModelEditingFinished);
×
106
        connect(ui->showMySky_debugOptionsEnabled, &QCheckBox::toggled, this,
×
107
                        [this](const bool enabled){ ui->showMySky_debugOptionsGroup->setVisible(enabled); });
×
108
        connectBoolProperty(ui->showMySky_zeroOrderEnabled, "LandscapeMgr.flagAtmosphereZeroOrderScattering");
×
109
        connectBoolProperty(ui->showMySky_singleScatteringEnabled, "LandscapeMgr.flagAtmosphereSingleScattering");
×
110
        connectBoolProperty(ui->showMySky_multipleScatteringEnabled, "LandscapeMgr.flagAtmosphereMultipleScattering");
×
111
        connectIntProperty(ui->showMySky_eclipseSimulationQualitySpinBox, ECLIPSE_SIM_QUALITY_PROPERTY);
×
112
#else
113
        ui->visualModelConfigGroup->hide();
114
#endif
115

116
        setCurrentValues();
×
117
}
×
118

119
bool AtmosphereDialog::eventFilter(QObject* object, QEvent* event)
×
120
{
121
        if (object != dialog || event->type() != QEvent::KeyPress)
×
122
                return false;
×
123
        const auto keyEvent = static_cast<QKeyEvent*>(event);
×
124
        if (keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return)
×
125
                return true; // Prevent these keys pressing buttons when focus is not on the buttons
×
126
        return false;
×
127
}
128

129
void AtmosphereDialog::setStandardAtmosphere()
×
130
{
131
        // See https://en.wikipedia.org/wiki/International_Standard_Atmosphere#ICAO_Standard_Atmosphere
132
        ui->pressureDoubleSpinBox->setValue(1013.25);
×
133
        ui->temperatureDoubleSpinBox->setValue(15.0);
×
134
        // See http://www.icq.eps.harvard.edu/ICQExtinct.html
135
        ui->extinctionDoubleSpinBox->setValue(0.2);
×
136
}
×
137

138
void AtmosphereDialog::setTfromK(double k)
×
139
{
140
        if (ui->checkBox_TfromK->isChecked())
×
141
        {
142
                double T=25.*(k-0.16)+1.;
×
143
                ui->doubleSpinBox_T->setValue(T);
×
144
                StelSkyDrawer* skyDrawer = StelApp::getInstance().getCore()->getSkyDrawer();
×
145

146
                skyDrawer->setT(T);
×
147
        }
148
}
×
149

150
void AtmosphereDialog::clearStatus()
×
151
{
152
        ui->showMySky_statusLabel->setText("");
×
153
        ui->showMySky_statusLabel->setStyleSheet("");
×
154
}
×
155

156
void AtmosphereDialog::onModelChoiceChanged(const QString& model)
×
157
{
158
        updatePathToModelStyle();
×
159

160
        const bool isShowMySky = model.toLower()=="showmysky";
×
161
        ui->showMySky_optionsGroup->setVisible(isShowMySky);
×
162
        if(!isShowMySky || this->hasValidModelPath())
×
163
                StelApp::getInstance().getStelPropertyManager()->setStelPropertyValue(MODEL_PROPERTY, model);
×
164
}
×
165

166
void AtmosphereDialog::browsePathToModel()
×
167
{
168
        const auto mgr = StelApp::getInstance().getStelPropertyManager();
×
169
        const auto dataDir = mgr->getProperty(DEFAULT_MODEL_PATH_PROPERTY)->getValue().toString() + "/..";
×
170
        const auto path=QFileDialog::getExistingDirectory(&StelMainView::getInstance(), q_("Open ShowMySky model"), dataDir);
×
171
        if(path.isNull()) return;
×
172

173
        const auto currentModel = mgr->getProperty(MODEL_PROPERTY)->getValue().toString();
×
174

175
        clearStatus();
×
176
        ui->showMySky_pathToModelEdit->setText(path);
×
177
        StelApp::getInstance().getStelPropertyManager()->setStelPropertyValue(MODEL_PATH_PROPERTY, path);
×
178

179
        const auto selectedModel = ui->atmosphereModel->currentText();
×
180
        if(selectedModel.toLower() != currentModel.toLower())
×
181
                onModelChoiceChanged(selectedModel);
×
182
}
×
183

184
bool AtmosphereDialog::hasValidModelPath() const
×
185
{
186
        const auto text=ui->showMySky_pathToModelEdit->text();
×
187
        if(text.isEmpty()) return false;
×
188
        return QFileInfo(text+"/params.atmo").exists();
×
189
}
×
190

191
void AtmosphereDialog::onPathToModelEditingFinished()
×
192
{
193
        clearStatus();
×
194

195
        if(!hasValidModelPath())
×
196
                return;
×
197

198
        const auto mgr = StelApp::getInstance().getStelPropertyManager();
×
199
        const auto currentModel = mgr->getProperty(MODEL_PROPERTY)->getValue().toString();
×
200

201
        const auto path = ui->showMySky_pathToModelEdit->text();
×
202
        StelApp::getInstance().getStelPropertyManager()->setStelPropertyValue(MODEL_PATH_PROPERTY, path);
×
203

204
        const auto selectedModel = ui->atmosphereModel->currentText();
×
205
        if(selectedModel.toLower() != currentModel.toLower())
×
206
                onModelChoiceChanged(selectedModel);
×
207
}
×
208

209
void AtmosphereDialog::updatePathToModelStyle()
×
210
{
211
        if(hasValidModelPath())
×
212
                ui->showMySky_pathToModelEdit->setStyleSheet("");
×
213
        else
214
                ui->showMySky_pathToModelEdit->setStyleSheet("color:red;");
×
215
}
×
216

217
void AtmosphereDialog::onPathToModelChanged()
×
218
{
219
        clearStatus();
×
220
        updatePathToModelStyle();
×
221
}
×
222

223
void AtmosphereDialog::onErrorStateChanged(const bool error)
×
224
{
225
        if(error)
×
226
                ui->showMySky_statusLabel->setStyleSheet("margin-left: 1px; border-radius: 5px; background-color: #ff5757;");
×
227
        else
228
                ui->showMySky_statusLabel->setStyleSheet("");
×
229
}
×
230

231
void AtmosphereDialog::setCurrentValues()
×
232
{
233
        const auto mgr = StelApp::getInstance().getStelPropertyManager();
×
234
        const auto currentModel = mgr->getProperty(MODEL_PROPERTY)->getValue().toString();
×
235
        for(int i = 0; i < ui->atmosphereModel->count(); ++i)
×
236
        {
237
                if(ui->atmosphereModel->itemText(i).toLower()==currentModel.toLower())
×
238
                {
239
                        ui->atmosphereModel->setCurrentIndex(i);
×
240
                        break;
×
241
                }
242
        }
243
        onModelChoiceChanged(ui->atmosphereModel->currentText());
×
244

245
        const auto currentModelPath = mgr->getProperty(MODEL_PATH_PROPERTY)->getValue().toString();
×
246
        if(currentModelPath.isEmpty())
×
247
        {
248
                const auto modelPath = mgr->getProperty(DEFAULT_MODEL_PATH_PROPERTY)->getValue().toString();
×
249
                ui->showMySky_pathToModelEdit->setText(modelPath);
×
250
        }
×
251
        else
252
        {
253
                ui->showMySky_pathToModelEdit->setText(currentModelPath);
×
254
        }
255
        const auto currentStatusText = mgr->getProperty(STATUS_TEXT_PROPERTY)->getValue().toString();
×
256
        ui->showMySky_statusLabel->setText(currentStatusText);
×
257
        const bool currentErrorStatus = mgr->getProperty(ERROR_PROPERTY)->getValue().toBool();
×
258
        onErrorStateChanged(currentErrorStatus);
×
259

260
        const auto eclipseQuality = mgr->getProperty(ECLIPSE_SIM_QUALITY_PROPERTY)->getValue().toInt();
×
261
        ui->showMySky_eclipseSimulationQualitySpinBox->setValue(eclipseQuality);
×
262

263
        ui->showMySky_debugOptionsEnabled->setChecked(false);
×
264
}
×
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