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

Stellarium / stellarium / 5926409083

21 Aug 2023 12:45PM UTC coverage: 11.905% (+0.01%) from 11.891%
5926409083

Pull #3373

github

gzotti
Reduce verbosity a bit.
Pull Request #3373: Fix: unambiguous comet names

264 of 264 new or added lines in 9 files covered. (100.0%)

14845 of 124700 relevant lines covered (11.9%)

23289.81 hits per line

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

0.0
/plugins/SolarSystemEditor/src/gui/SolarSystemManagerWindow.cpp
1
/*
2
 * Solar System editor plug-in for Stellarium
3
 *
4
 * Copyright (C) 2010 Bogdan Marinov
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 "SolarSystemEditor.hpp"
22

23
#include "SolarSystemManagerWindow.hpp"
24
#include "ui_solarSystemManagerWindow.h"
25

26
#include "MpcImportWindow.hpp"
27
#include "ManualImportWindow.hpp"
28

29
#include "StelApp.hpp"
30
#include "StelGui.hpp"
31
#include "StelFileMgr.hpp"
32
#include "StelModuleMgr.hpp"
33
#include "StelTranslator.hpp"
34
#include "Planet.hpp"
35
#include "SolarSystem.hpp"
36

37
#include <QFileDialog>
38

39
SolarSystemManagerWindow::SolarSystemManagerWindow()
×
40
        : StelDialog("SolarSystemEditor")
41
        , manualImportWindow(nullptr)
×
42
{
43
        ui = new Ui_solarSystemManagerWindow();
×
44
        mpcImportWindow = new MpcImportWindow();
×
45

46
        ssEditor = GETSTELMODULE(SolarSystemEditor);
×
47
}
×
48

49
SolarSystemManagerWindow::~SolarSystemManagerWindow()
×
50
{
51
        delete ui;
×
52

53
        if (mpcImportWindow)
×
54
                delete mpcImportWindow;
×
55
        if (manualImportWindow)
×
56
                delete manualImportWindow;
×
57
}
×
58

59
void SolarSystemManagerWindow::createDialogContent()
×
60
{
61
        ui->setupUi(dialog);
×
62

63
        // Kinetic scrolling
64
        kineticScrollingList << ui->listWidgetObjects;
×
65
        StelGui* gui= dynamic_cast<StelGui*>(StelApp::getInstance().getGui());
×
66
        if (gui)
×
67
        {
68
                enableKineticScrolling(gui->getFlagUseKineticScrolling());
×
69
                connect(gui, SIGNAL(flagUseKineticScrollingChanged(bool)), this, SLOT(enableKineticScrolling(bool)));
×
70
        }
71

72
        //Signals
73
        connect(&StelApp::getInstance(), SIGNAL(languageChanged()),
×
74
                this, SLOT(retranslate()));
75
        connect(ui->closeStelWindow, SIGNAL(clicked()), this, SLOT(close()));
×
76
        connect(ui->TitleBar, SIGNAL(movedTo(QPoint)), this, SLOT(handleMovedTo(QPoint)));
×
77
        connect(ui->pushButtonCopyFile, SIGNAL(clicked()), this, SLOT(copyConfiguration()));
×
78
        connect(ui->pushButtonReplaceFile, SIGNAL(clicked()), this, SLOT(replaceConfiguration()));
×
79
        connect(ui->pushButtonAddFile, SIGNAL(clicked()), this, SLOT(addConfiguration()));
×
80
        connect(ui->pushButtonRemove, SIGNAL(clicked()), this, SLOT(removeObjects()));
×
81
        connect(ui->pushButtonImportMPC, SIGNAL(clicked()), this, SLOT(newImportMPC()));
×
82
        //connect(ui->pushButtonManual, SIGNAL(clicked()), this, SLOT(newImportManual()));
83

84
        connect(ssEditor, SIGNAL(solarSystemChanged()), this, SLOT(populateSolarSystemList()));
×
85
        connect(ui->pushButtonReset, SIGNAL(clicked()), this, SLOT(resetSSOdefaults()));
×
86

87
        // bug #1350669 (https://bugs.launchpad.net/stellarium/+bug/1350669)
88
        connect(ui->listWidgetObjects, SIGNAL(currentRowChanged(int)), ui->listWidgetObjects, SLOT(repaint()));
×
89

90
        setAboutHtml();
×
91
        updateTexts();
×
92

93
        Q_ASSERT(mpcImportWindow);
×
94
        //Rebuild the list if any planets have been imported
95
        connect(mpcImportWindow, SIGNAL(objectsImported()), this, SLOT(populateSolarSystemList()));
×
96

97
        ui->lineEditUserFilePath->setText(ssEditor->getCustomSolarSystemFilePath());
×
98
        populateSolarSystemList();
×
99
}
×
100

101
void SolarSystemManagerWindow::updateTexts()
×
102
{
103
        //Solar System tab
104
        // TRANSLATORS: Appears as the text of hyperlinks linking to websites. :)
105
        QString linkText(q_("website"));
×
106
        QString linkCode = QString("<a href=\"https://www.minorplanetcenter.net/\">%1</a>").arg(linkText);
×
107
               
108
        // TRANSLATORS: IAU = International Astronomical Union
109
        QString mpcText(q_("You can import comet and asteroid data formatted in the export formats of the IAU's Minor Planet Center (%1). You can import files with lists of objects, download such lists from the Internet or search the online Minor Planet and Comet Ephemeris Service (MPES)."));
×
110
        ui->labelMPC->setText(QString(mpcText).arg(linkCode));
×
111
}
×
112

113
void SolarSystemManagerWindow::retranslate()
×
114
{
115
        if (dialog)
×
116
        {
117
                ui->retranslateUi(dialog);
×
118
                populateSolarSystemList();
×
119
                setAboutHtml();
×
120
                updateTexts();
×
121
        }
122
}
×
123

124
void SolarSystemManagerWindow::newImportMPC()
×
125
{
126
        Q_ASSERT(mpcImportWindow);
×
127

128
        mpcImportWindow->setVisible(true);
×
129
}
×
130

131
void SolarSystemManagerWindow::newImportManual()
×
132
{
133
        if (manualImportWindow == nullptr)
×
134
        {
135
                manualImportWindow = new ManualImportWindow();
×
136
                connect(manualImportWindow, SIGNAL(visibleChanged(bool)), this, SLOT(resetImportManual(bool)));
×
137
        }
138

139
        manualImportWindow->setVisible(true);
×
140
}
×
141

142
void SolarSystemManagerWindow::resetImportManual(bool show)
×
143
{
144
        //If the window is being displayed, do nothing
145
        if (show)
×
146
                return;
×
147

148
        if (manualImportWindow)
×
149
        {
150
                //TODO:Move this out of here!
151
                //Reload the list, in case there are new objects
152
                populateSolarSystemList();
×
153

154
                delete manualImportWindow;
×
155
                manualImportWindow = nullptr;
×
156

157
                //This window is in the background, bring it to the foreground
158
                dialog->setVisible(true);
×
159
        }
160
}
161

162
void SolarSystemManagerWindow::resetSSOdefaults()
×
163
{
164
        if (askConfirmation()) 
×
165
        {
166
                qDebug() << "permission to reset SSO to defaults...";
×
167
                ssEditor->resetSolarSystemToDefault();
×
168
        }
169
        else
170
                qDebug() << "SSO reset cancelled";
×
171
}
×
172

173
void SolarSystemManagerWindow::populateSolarSystemList()
×
174
{
175
        unlocalizedNames.clear();
×
176
        for (const auto& object : GETSTELMODULE(SolarSystem)->getAllMinorBodies())
×
177
        {
178
                // GZ new for 0.16: only insert objects which are minor bodies.
179
                unlocalizedNames.insert(object->getCommonNameI18n(), object->getCommonEnglishName());
×
180
        }
181

182
        ui->listWidgetObjects->clear();
×
183
        ui->listWidgetObjects->addItems(unlocalizedNames.keys());
×
184
        //No explicit sorting is necessary: sortingEnabled is set in the .ui
185
}
×
186

187
void SolarSystemManagerWindow::removeObjects()
×
188
{
189
        if (!ui->listWidgetObjects->selectedItems().isEmpty())
×
190
        {
191
                // we must disconnect the signal or else the list will be rebuilt after the first deletion.
192
                disconnect(ssEditor, SIGNAL(solarSystemChanged()), this, SLOT(populateSolarSystemList()));
×
193
                // This is slow for many objects.
194
                // TODO: For more than 50, it may be better to remove from ini file and reload all ini files.
195
                for (auto* item : ui->listWidgetObjects->selectedItems())
×
196
                {
197
                        QString ssoI18nName = item->text();
×
198
                        QString ssoEnglishName = unlocalizedNames.value(ssoI18nName);
×
199
                        //qDebug() << ssoId;
200
                        //TODO: Ask for confirmation first?
201
                        ssEditor->removeSsoWithName(ssoEnglishName);
×
202
                }
×
203
                connect(ssEditor, SIGNAL(solarSystemChanged()), this, SLOT(populateSolarSystemList()));
×
204
                populateSolarSystemList();
×
205
        }
206
}
×
207

208
void SolarSystemManagerWindow::copyConfiguration()
×
209
{
210
        QString filePath = QFileDialog::getSaveFileName(nullptr,
211
                                                        q_("Save the minor Solar System bodies as..."),
×
212
                                                        QDir::homePath() + "/ssystem_minor.ini");
×
213
        ssEditor->copySolarSystemConfigurationFileTo(filePath);
×
214
}
×
215

216
void SolarSystemManagerWindow::replaceConfiguration()
×
217
{
218
        QString filter = q_("Configuration files");
×
219
        filter.append(" (*.ini)");
×
220
        QString filePath = QFileDialog::getOpenFileName(nullptr, q_("Select a file to replace the Solar System minor bodies"), QDir::homePath(), filter);
×
221
        ssEditor->replaceSolarSystemConfigurationFileWith(filePath);
×
222
}
×
223

224
void SolarSystemManagerWindow::addConfiguration()
×
225
{
226
        QString filter = q_("Configuration files");
×
227
        filter.append(" (*.ini)");
×
228
        QString filePath = QFileDialog::getOpenFileName(nullptr, q_("Select a file to add the Solar System minor bodies"), QDir::toNativeSeparators(StelFileMgr::getInstallationDir()+"/data/ssystem_1000comets.ini"), filter);
×
229
        ssEditor->addFromSolarSystemConfigurationFile(filePath);
×
230
}
×
231

232
void SolarSystemManagerWindow::setAboutHtml(void)
×
233
{
234
        QString html = "<html><head></head><body>";
×
235
        html += "<h2>" + q_("Solar System Editor") + "</h2><table width=\"90%\">";
×
236
        html += "<tr width=\"30%\"><td><strong>" + q_("Version") + ":</strong></td><td>" + SOLARSYSTEMEDITOR_PLUGIN_VERSION + "</td></tr>";
×
237
        html += "<tr><td><strong>" + q_("License") + ":</strong></td><td>" + SOLARSYSTEMEDITOR_PLUGIN_LICENSE + "</td></tr>";
×
238
        html += "<tr><td><strong>" + q_("Author") + ":</strong></td><td>Bogdan Marinov &lt;bogdan.marinov84@gmail.com&gt;</td></tr>";
×
239
        html += "<tr><td rowspan=2><strong>" + q_("Contributors") + ":</strong></td><td>Georg Zotti</td></tr>";
×
240
        html += "<tr><td>Alexander Wolf</td></tr>";
×
241
        html += "</table>";
×
242

243
        html += "<p>" + q_("An interface for adding asteroids and comets to Stellarium. It can download object lists from the Minor Planet Center's website and perform searches in its online database.") + "</p>";
×
244

245
        html += StelApp::getInstance().getModuleMgr().getStandardSupportLinksInfo("Solar System Editor plugin");
×
246
        html += "</body></html>";
×
247

248
        StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui());
×
249
        if(gui!=nullptr)
×
250
        {
251
                QString htmlStyleSheet(gui->getStelStyle().htmlStyleSheet);
×
252
                ui->aboutTextBrowser->document()->setDefaultStyleSheet(htmlStyleSheet);
×
253
        }
×
254

255
        ui->aboutTextBrowser->setHtml(html);
×
256
}
×
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