• 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/Scenery3d/src/gui/StoredViewDialog.cpp
1
/*
2
 * Stellarium Scenery3d Plug-in
3
 *
4
 * Copyright (C) 2011-2015 Simon Parzer, Peter Neubauer, Georg Zotti, Andrei Borza, Florian Schaukowitsch
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 "StoredViewDialog.hpp"
22
#include "StoredViewDialog_p.hpp"
23
#include "Scenery3d.hpp"
24

25
#include "StelApp.hpp"
26
#include "StelGui.hpp"
27
#include "StelModuleMgr.hpp"
28
#include "StelTranslator.hpp"
29

30
StoredViewDialog::StoredViewDialog(QObject *parent) : StelDialog("Scenery3dViews", parent), mgr(nullptr), viewModel(nullptr)
×
31
{
32
        ui = new Ui_storedViewDialogForm;
×
33
}
×
34

35
StoredViewDialog::~StoredViewDialog()
×
36
{
37
        delete ui;
×
38
}
×
39

40
void StoredViewDialog::retranslate()
×
41
{
42
        if(dialog)
×
43
                ui->retranslateUi(dialog);
×
44
}
×
45

46
void StoredViewDialog::createDialogContent()
×
47
{
48
        ui->setupUi(dialog);
×
49
        connect(ui->titleBar, &TitleBar::closeClicked, this, &StelDialog::close);
×
50
        connect(ui->titleBar, SIGNAL(movedTo(QPoint)), this, SLOT(handleMovedTo(QPoint)));
×
51

52
        mgr = GETSTELMODULE(Scenery3d);
×
53
        Q_ASSERT(mgr);
×
54

55
        connect(ui->pushButtonAddView, &QPushButton::clicked, this, &StoredViewDialog::addUserView);
×
56
        connect(ui->pushButtonLoadView, &QPushButton::clicked, this, &StoredViewDialog::loadView);
×
57
        //also allow doubleclick to load view
58
        connect(ui->listView, &QListView::doubleClicked, this, &StoredViewDialog::loadView);
×
59
        connect(ui->pushButtonDeleteView, &QPushButton::clicked, this, &StoredViewDialog::deleteView);
×
60

61
        connect(ui->lineEditTitle, &QLineEdit::editingFinished, this, &StoredViewDialog::updateCurrentView);
×
62
        connect(ui->textEditDescription, &CustomTextEdit::editingFinished, this, &StoredViewDialog::updateCurrentView);
×
63

64
        StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui());
×
65
        if (gui)
×
66
                ui->textEditDescription->document()->setDefaultStyleSheet(QString(gui->getStelStyle().htmlStyleSheet));
×
67

68
        //we use a sorta MVC system here
69
        viewModel = new StoredViewModel(ui->listView);
×
70
        ui->listView->setModel(viewModel);
×
71
        connect(ui->listView->selectionModel(), &QItemSelectionModel::currentChanged, this, &StoredViewDialog::updateViewSelection);
×
72

73
        connect(mgr, &Scenery3d::currentSceneChanged, viewModel, &StoredViewModel::setScene);
×
74
        connect(viewModel, &QAbstractItemModel::modelReset, this, &StoredViewDialog::resetViewSelection);
×
75
        viewModel->setScene(mgr->getCurrentScene());
×
76
}
×
77

78
void StoredViewDialog::updateCurrentView()
×
79
{
80
        int idx = ui->listView->selectionModel()->currentIndex().row();
×
81

82
        if(idx>=0)
×
83
        {
84
                StoredView& view = viewModel->getViewAtIdx(idx);
×
85
                view.label = ui->lineEditTitle->text();
×
86
                view.description = ui->textEditDescription->toHtml();
×
87
                viewModel->updatedAtIdx(idx);
×
88
        }
89
}
×
90

91
void StoredViewDialog::updateViewSelection(const QModelIndex &idx)
×
92
{
93
        if(idx.isValid())
×
94
        {
95
                StoredView& view = viewModel->getViewAtIdx(idx.row());
×
96

97
                ui->lineEditTitle->setEnabled(true);
×
98
                ui->textEditDescription->setEnabled(true);
×
99
                ui->lineEditTitle->setReadOnly(view.isGlobal);
×
100
                ui->textEditDescription->setReadOnly(view.isGlobal);
×
101

102
                ui->lineEditTitle->setText(view.label);
×
103
                ui->textEditDescription->setHtml(view.description);
×
104

105
                ui->pushButtonDeleteView->setEnabled(!view.isGlobal);
×
106
                ui->pushButtonLoadView->setEnabled(true);
×
107
        }
108
        else
109
        {
110
                //for example deletion of last item in the list
111
                ui->lineEditTitle->setEnabled(false);
×
112
                ui->lineEditTitle->clear();
×
113
                ui->textEditDescription->setEnabled(false);
×
114
                ui->textEditDescription->clear();
×
115
                ui->pushButtonLoadView->setEnabled(false);
×
116
                ui->pushButtonDeleteView->setEnabled(false);
×
117
        }
118
}
×
119

120
void StoredViewDialog::resetViewSelection()
×
121
{
122
        ui->pushButtonAddView->setEnabled(viewModel->getScene().isValid);
×
123

124
        //disable all
125
        ui->lineEditTitle->setEnabled(false);
×
126
        ui->lineEditTitle->clear();
×
127
        ui->textEditDescription->setEnabled(false);
×
128
        ui->textEditDescription->clear();
×
129
        ui->pushButtonLoadView->setEnabled(false);
×
130
        ui->pushButtonDeleteView->setEnabled(false);
×
131
}
×
132

133
void StoredViewDialog::loadView()
×
134
{
135
        int idx = ui->listView->selectionModel()->currentIndex().row();
×
136
        if(idx>=0)
×
137
        {
138
                mgr->setView(viewModel->getViewAtIdx(idx), ui->useDateCheckBox->isChecked());
×
139
        }
140
}
×
141

142
void StoredViewDialog::deleteView()
×
143
{
144
        int idx = ui->listView->selectionModel()->currentIndex().row();
×
145

146
        if(idx>=0)
×
147
        {
148
                viewModel->deleteView(idx);
×
149
        }
150
}
×
151

152
void StoredViewDialog::addUserView()
×
153
{
154
        StoredView sv = mgr->getCurrentView();
×
155
        sv.label = "New user view";
×
156
        if (ui->useDateCheckBox->isChecked())
×
157
        {
158
                StelCore *core=StelApp::getInstance().getCore();
×
159
                sv.jd=core->getJD();
×
160
                sv.jdIsRelevant=true;
×
161
        }
162

163
        SceneInfo info = viewModel->getScene();
×
164
        sv.description = QString(q_("Grid coordinates (%1): %2m, %3m, %4m")).arg(info.gridName)
×
165
                        .arg(sv.position[0], 0, 'f', 2).arg(sv.position[1],0,'f',2).arg(sv.position[2],0,'f',2);
×
166

167
        QModelIndex idx = viewModel->addUserView(sv);
×
168
        ui->listView->setCurrentIndex(idx);
×
169
}
×
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