• 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/Satellites/src/gui/SatellitesCommDialog.cpp
1
/*
2
 * Stellarium Satellites Plug-in: satellites communications editor
3
 * Copyright (C) 2022 Alexander Wolf
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
 * 
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
*/
19

20
#include "Satellites.hpp"
21
#include "SatellitesCommDialog.hpp"
22
#include "ui_satellitesCommDialog.h"
23

24
#include "StelApp.hpp"
25
#include "StelTranslator.hpp"
26
#include "StelModuleMgr.hpp"
27
#include "StelMainView.hpp"
28

29
#include <QMessageBox>
30

31
SatellitesCommDialog::SatellitesCommDialog()
×
32
        : StelDialog("SatellitesComms")
33
        , satelliteID(QString())
×
34
{
35
        ui = new Ui_satellitesCommDialog;
×
36
        SatellitesMgr = GETSTELMODULE(Satellites);
×
37
}
×
38

39
SatellitesCommDialog::~SatellitesCommDialog()
×
40
{
41
        delete ui;
×
42
}
×
43

44
void SatellitesCommDialog::retranslate()
×
45
{
46
        if (dialog)
×
47
        {
48
                ui->retranslateUi(dialog);
×
49
                setCommunicationsHeaderNames();
×
50
                populateTexts();
×
51
        }
52
}
×
53

54
void SatellitesCommDialog::setVisible(bool visible)
×
55
{
56
        StelDialog::setVisible(visible);
×
57
        satelliteID = SatellitesMgr->getLastSelectedSatelliteID();
×
58
        if (!satelliteID.isEmpty())
×
59
                getSatCommData();
×
60
}
×
61

62
void SatellitesCommDialog::createDialogContent()
×
63
{
64
        ui->setupUi(dialog);
×
65

66
        connect(ui->titleBar, &TitleBar::closeClicked, this, &StelDialog::close);
×
67
        connect(ui->titleBar, SIGNAL(movedTo(QPoint)), this, SLOT(handleMovedTo(QPoint)));
×
68
        connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SLOT(retranslate()));
×
69

70
        initListCommunications();
×
71

72
        connect(SatellitesMgr, SIGNAL(satSelectionChanged(QString)), this, SLOT(updateSatID(QString)));
×
73
        connect(ui->communicationsTreeWidget, SIGNAL(itemSelectionChanged()), this, SLOT(selectCurrentCommLink()));
×
74
        connect(ui->addCommLinkButton, SIGNAL(clicked()), this, SLOT(addCommData()));
×
75
        connect(ui->removeCommLinkButton, SIGNAL(clicked()), this, SLOT(removeCommData()));
×
76

77
        populateTexts();
×
78

79
        // Set size of buttons
80
        QSize bs = QSize(26, 26);
×
81
        ui->addCommLinkButton->setFixedSize(bs);
×
82
        ui->removeCommLinkButton->setFixedSize(bs);
×
83
}
×
84

85
void SatellitesCommDialog::populateTexts()
×
86
{
87
        ui->descriptionLineEdit->setToolTip(q_("Callsign with channel description"));
×
88
        ui->frequencySpinBox->setSuffix(QString(" %1").arg(qc_("MHz", "frequency")));
×
89
        ui->frequencySpinBox->setToolTip(q_("Channel frequency"));
×
90
        ui->modulationLineEdit->setToolTip(q_("Signal modulation mode"));
×
91
        ui->removeCommLinkButton->setToolTip(q_("Remove selected communication data"));
×
92
        ui->addCommLinkButton->setToolTip(q_("Add communication data"));
×
93
}
×
94

95
void SatellitesCommDialog::updateSatID(QString satID)
×
96
{
97
        satelliteID = satID;
×
98
        ui->communicationsTreeWidget->clearSelection();
×
99
        ui->communicationsTreeWidget->clearFocus();
×
100
        getSatCommData();
×
101
}
×
102

103
void SatellitesCommDialog::getSatCommData()
×
104
{
105
        initListCommunications();
×
106
        communications.clear();
×
107
        if (satelliteID.isEmpty())
×
108
                ui->satelliteLabel->setText("");
×
109
        else
110
        {
111
                ui->satelliteLabel->setText(QString("%1 / NORAD %2").arg(SatellitesMgr->searchByID(satelliteID)->getNameI18n(), satelliteID));
×
112
                communications = SatellitesMgr->getCommunicationData(satelliteID);
×
113
                if (communications.count()>0)
×
114
                {
115
                        for (const auto& comm : qAsConst(communications))
×
116
                        {
117
                                fillCommunicationsTable(satelliteID, comm.description, comm.frequency, comm.modulation);
×
118
                        }
119
                        adjustCommunicationsColumns();
×
120
                }
121
        }
122
        // cleanup input fields
123
        ui->descriptionLineEdit->setText("");
×
124
        ui->modulationLineEdit->setText("");
×
125
        ui->frequencySpinBox->setValue(0.0);
×
126
}
×
127

128
void SatellitesCommDialog::setCommunicationsHeaderNames()
×
129
{
130
        communicationsHeader.clear();
×
131
        communicationsHeader << q_("Description");
×
132
        communicationsHeader << q_("Frequency, MHz");
×
133
        communicationsHeader << q_("Modulation");
×
134

135
        ui->communicationsTreeWidget->setHeaderLabels(communicationsHeader);
×
136
        adjustCommunicationsColumns();
×
137
}
×
138

139
void SatellitesCommDialog::adjustCommunicationsColumns()
×
140
{
141
        // adjust the column width
142
        for (int i = 0; i < CommsCount; ++i)
×
143
        {
144
                ui->communicationsTreeWidget->resizeColumnToContents(i);
×
145
        }
146
}
×
147

148
void SatellitesCommDialog::initListCommunications()
×
149
{
150
        ui->communicationsTreeWidget->clear();
×
151
        ui->communicationsTreeWidget->setColumnCount(CommsCount);
×
152
        setCommunicationsHeaderNames();
×
153
        ui->communicationsTreeWidget->header()->setSectionsMovable(false);
×
154
        ui->communicationsTreeWidget->header()->setDefaultAlignment(Qt::AlignCenter);
×
155
        //ui->communicationsTreeWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
156
}
×
157

158
void SatellitesCommDialog::fillCommunicationsTable(QString satID, QString description, double frequency, QString modulation)
×
159
{
160
        CommsTreeWidgetItem* treeItem = new CommsTreeWidgetItem(ui->communicationsTreeWidget);
×
161
        treeItem->setText(CommsDescription, description);
×
162
        treeItem->setData(CommsDescription, Qt::UserRole, satID);
×
163
        treeItem->setText(CommsFrequency, QString::number(frequency, 'f', 3));
×
164
        treeItem->setData(CommsFrequency, Qt::UserRole, frequency);
×
165
        treeItem->setTextAlignment(CommsFrequency, Qt::AlignRight);
×
166
        treeItem->setText(CommsModulation, modulation);
×
167
}
×
168

169
void SatellitesCommDialog::selectCurrentCommLink()
×
170
{
171
        QTreeWidgetItem* linkItem = ui->communicationsTreeWidget->currentItem();
×
172
        ui->descriptionLineEdit->setText(linkItem->data(CommsDescription, Qt::DisplayRole).toString());
×
173
        ui->modulationLineEdit->setText(linkItem->data(CommsModulation, Qt::DisplayRole).toString());
×
174
        ui->frequencySpinBox->setValue(linkItem->data(CommsFrequency, Qt::UserRole).toDouble());
×
175
}
×
176

177
void SatellitesCommDialog::addCommData()
×
178
{
179
        QString description = ui->descriptionLineEdit->text();
×
180
        QString modulation  = ui->modulationLineEdit->text();
×
181
        double frequency    = ui->frequencySpinBox->value();
×
182
        if (!description.isEmpty() && frequency>0.)
×
183
        {
184
                CommLink c;
×
185
                c.description = description;
×
186
                c.frequency = frequency;
×
187
                if (!modulation.isEmpty())
×
188
                        c.modulation = modulation;
×
189

190
                communications.append(c);
×
191
                SatellitesMgr->getById(satelliteID)->setCommData(communications);
×
192
                SatellitesMgr->saveCatalog();
×
193

194
                getSatCommData();
×
195
                // A "hackish" updating list of satellites
196
                emit SatellitesMgr->customFilterChanged();
×
197
        }
×
198
        else
199
                QMessageBox::warning(&StelMainView::getInstance(), q_("Nothing added"), q_("Please fill in description and add frequency before adding!"), QMessageBox::Ok);
×
200
}
×
201

202
void SatellitesCommDialog::removeCommData()
×
203
{
204
        QTreeWidgetItem* linkItem = ui->communicationsTreeWidget->currentItem();
×
205
        if (linkItem)
×
206
        {
207
                CommLink c;
×
208
                QString modulation = linkItem->data(CommsModulation, Qt::DisplayRole).toString();
×
209
                c.description = linkItem->data(CommsDescription, Qt::DisplayRole).toString();
×
210
                c.frequency = linkItem->data(CommsFrequency, Qt::UserRole).toDouble();
×
211
                if (!modulation.isEmpty())
×
212
                        c.modulation = modulation;
×
213

214
                QList<CommLink> newComms;
×
215
                for (auto& comm : communications)
×
216
                {
217
                        if (c.description==comm.description && c.frequency==comm.frequency)
×
218
                                continue;
×
219
                        newComms.append(comm);
×
220
                }
221
                communications = newComms;
×
222
                SatellitesMgr->getById(satelliteID)->setCommData(communications);
×
223
                SatellitesMgr->saveCatalog();
×
224

225
                getSatCommData();
×
226
                // A "hackish" updating list of satellites
227
                emit SatellitesMgr->customFilterChanged();
×
228
        }
×
229
        else
230
                QMessageBox::warning(&StelMainView::getInstance(), q_("Nothing deleted"), q_("Please select a line first!"), QMessageBox::Ok);
×
231
}
×
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