• 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/MeteorShowers/src/gui/MSSearchDialog.cpp
1
/*
2
 * Stellarium: Meteor Showers Plug-in
3
 * Copyright (C) 2013-2015 Marcos Cardinot
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, Suite 500, Boston, MA  02110-1335, USA.
18
*/
19

20
#include <QMessageBox>
21

22
#include "MSSearchDialog.hpp"
23
#include "StelApp.hpp"
24
#include "StelGui.hpp"
25
#include "StelModuleMgr.hpp"
26
#include "StelMovementMgr.hpp"
27
#include "StelObjectMgr.hpp"
28
#include "StelLocaleMgr.hpp"
29
#include "StelUtils.hpp"
30
#include "StelMainView.hpp"
31
#include "ui_MSSearchDialog.h"
32

33
MSSearchDialog::MSSearchDialog(MeteorShowersMgr* mgr)
×
34
        : StelDialog("MeteorShowersSearch")
35
        , m_mgr(mgr)
×
36
        , m_ui(new Ui_MSSearchDialog)
×
37
{}
×
38

39
MSSearchDialog::~MSSearchDialog()
×
40
{
41
        delete m_ui;
×
42
}
×
43

44
void MSSearchDialog::retranslate()
×
45
{
46
        if (dialog)
×
47
        {
48
                m_ui->retranslateUi(dialog);
×
49
                setHeaderNames();
×
50

51
                if (!m_ui->listEvents->findItems("", Qt::MatchContains, 0).isEmpty())
×
52
                        searchEvents();
×
53
        }
54
}
×
55

56
void MSSearchDialog::createDialogContent()
×
57
{
58
        m_ui->setupUi(dialog);
×
59

60
        // Kinetic scrolling
61
        kineticScrollingList << m_ui->listEvents;
×
62
        StelGui* gui= dynamic_cast<StelGui*>(StelApp::getInstance().getGui());
×
63
        if (gui)
×
64
        {
65
                enableKineticScrolling(gui->getFlagUseKineticScrolling());
×
66
                connect(gui, SIGNAL(flagUseKineticScrollingChanged(bool)), this, SLOT(enableKineticScrolling(bool)));
×
67
        }
68

69
        connect(this, SIGNAL(visibleChanged(bool)), this, SLOT(refreshRangeDates()));
×
70

71
        connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SLOT(retranslate()));
×
72

73
        connect(m_ui->titleBar, &TitleBar::closeClicked, this, &StelDialog::close);
×
74
        connect(m_ui->titleBar, SIGNAL(movedTo(QPoint)), this, SLOT(handleMovedTo(QPoint)));
×
75

76
        connect(m_ui->searchButton, SIGNAL(clicked()), this, SLOT(searchEvents()));
×
77

78
        connect(m_ui->listEvents, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(selectEvent(QModelIndex)));
×
79

80
        // bug #1350669 (https://bugs.launchpad.net/stellarium/+bug/1350669)
81
        connect(m_ui->listEvents, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
×
82
                m_ui->listEvents, SLOT(repaint()));
×
83

84
        int year = QDate::fromJulianDay(StelApp::getInstance().getCore()->getJD()).year();
×
85
        m_ui->fromYearSpinBox->setValue(year);
×
86
        m_ui->fromYearSpinBox->setToolTip(QString("%1 %2..%3").arg(q_("Valid range years:"), QString::number(m_ui->fromYearSpinBox->minimum()), QString::number(m_ui->fromYearSpinBox->maximum())));
×
87

88
        refreshRangeDates();
×
89
        initListEvents();
×
90
}
×
91

92
void MSSearchDialog::initListEvents()
×
93
{
94
        m_ui->listEvents->clear();
×
95
        m_ui->listEvents->setColumnCount(ColumnCount);
×
96
        setHeaderNames();
×
97
        m_ui->listEvents->header()->setSectionsMovable(false);
×
98
        m_ui->listEvents->header()->setStretchLastSection(true);
×
99
}
×
100

101
void MSSearchDialog::searchEvents()
×
102
{
103
        QList<MeteorShowers::SearchResult> searchResult;
×
104
        searchResult = m_mgr->getMeteorShowers()->searchEvents(m_ui->fromYearSpinBox->value());
×
105

106
        //Fill list of events
107
        initListEvents();
×
108
        for (const auto& r : qAsConst(searchResult))
×
109
        {
110
                MSTreeWidgetItem* treeItem = new MSTreeWidgetItem(m_ui->listEvents);
×
111
                treeItem->setText(ColumnCode, r.code);
×
112
                treeItem->setText(ColumnName, r.name);
×
113
                treeItem->setText(ColumnDataType, r.type);
×
114
                // peak JD from solar longitude
115
                double peakJD = MeteorShower::JDfromSolarLongitude(r.peak, r.peakyear);
×
116
                StelCore* core = StelApp::getInstance().getCore();
×
117
                const double utcShift = core->getUTCOffset(core->getJD()) / 24.;
×
118
                int Year, Month, Day;
119
                StelUtils::getDateFromJulianDay(peakJD+utcShift, &Year, &Month, &Day);
×
120
                treeItem->setText(ColumnPeak, QString("%1 %2").arg(Day).arg(StelLocaleMgr::longGenitiveMonthName(Month)));
×
121
                if (r.zhrMin != r.zhrMax)
×
122
                        treeItem->setText(ColumnZHR, QString("%1-%2").arg(r.zhrMin).arg(r.zhrMax));
×
123
                else
124
                        treeItem->setText(ColumnZHR, QString::number(r.zhrMax));
×
125

126
                // let's store the stuff in the UserRole to allow easier sorting
127
                // check MSTreeWidgetItem::operator <()
128
                treeItem->setData(ColumnCode, Qt::UserRole, r.code);
×
129
                treeItem->setData(ColumnName, Qt::UserRole, r.name);
×
130
                treeItem->setData(ColumnDataType, Qt::UserRole, r.type);
×
131
                treeItem->setData(ColumnPeak, Qt::UserRole, peakJD);
×
132
                treeItem->setData(ColumnZHR, Qt::UserRole, r.zhrMax);
×
133
        }
134

135
        // adjust the column width
136
        for(int i = 0; i < ColumnCount; ++i)
×
137
        {
138
            m_ui->listEvents->resizeColumnToContents(i);
×
139
        }
140

141
        // sort-by-date
142
        m_ui->listEvents->sortItems(ColumnPeak, Qt::AscendingOrder);
×
143
}
×
144

145
void MSSearchDialog::selectEvent(const QModelIndex &modelIndex)
×
146
{
147
        // plugin is disabled ? enable it automatically
148
        if (!m_mgr->getEnablePlugin())
×
149
                m_mgr->setEnablePlugin(true);
×
150

151
        // Change date
152
        StelCore *core = StelApp::getInstance().getCore();        
×
153
        double JD = modelIndex.sibling(modelIndex.row(), ColumnPeak).data(Qt::UserRole).toDouble();
×
154
        core->setJD(JD - core->getUTCOffset(JD)/24.);
×
155

156
        // Find the object
157
        QString nameI18n = modelIndex.sibling(modelIndex.row(), ColumnName).data().toString();
×
158
        StelObjectP obj = m_mgr->getMeteorShowers()->searchByNameI18n(nameI18n);
×
159
        if (!obj)
×
160
                obj = m_mgr->getMeteorShowers()->searchByName(nameI18n);
×
161

162
        if (obj) // Set time near transit...
×
163
        {
164
                Vec4d rts = obj->getRTSTime(core);
×
165
                core->setJD(rts[1]);
×
166
        }
167

168
        // Move to object
169
        if (GETSTELMODULE(StelObjectMgr)->findAndSelectI18n(nameI18n))
×
170
                GETSTELMODULE(StelMovementMgr)->setFlagTracking(true);
×
171
}
×
172

173
void MSSearchDialog::refreshRangeDates()
×
174
{
175
        int year = QDate::fromJulianDay(StelApp::getInstance().getCore()->getJD()).year();
×
176
        m_ui->fromYearSpinBox->setValue(year);
×
177
}
×
178

179
void MSSearchDialog::setHeaderNames()
×
180
{
181
        QStringList headerStrings;
×
182
        headerStrings << q_("Code");
×
183
        headerStrings << q_("Name");
×
184
        headerStrings << q_("ZHR");
×
185
        headerStrings << q_("Data Type");
×
186
        headerStrings << q_("Peak");
×
187
        m_ui->listEvents->setHeaderLabels(headerStrings);
×
188

189
        // adjust the column width
190
        for(int i = 0; i < ColumnCount; ++i)
×
191
        {
192
            m_ui->listEvents->resizeColumnToContents(i);
×
193
        }
194
}
×
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