• 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/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 "StelMainView.hpp"
33
#include "StelModuleMgr.hpp"
34
#include "StelTranslator.hpp"
35
#include "Planet.hpp"
36
#include "SolarSystem.hpp"
37

38
#include <QFileDialog>
39

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

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

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

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

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

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

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

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

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

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

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

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

102
void SolarSystemManagerWindow::updateTexts()
×
103
{
104
        //Solar System tab
105
        // TRANSLATORS: Appears as the text of hyperlinks linking to websites. :)
106
        QString linkText(q_("website"));
×
107
        QString linkCode = QString("<a href=\"https://www.minorplanetcenter.net/\">%1</a>").arg(linkText);
×
108
               
109
        // TRANSLATORS: IAU = International Astronomical Union
110
        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)."));
×
111
        ui->labelMPC->setText(QString(mpcText).arg(linkCode));
×
112
}
×
113

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

244
        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>";
×
245

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

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

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