Kstars

notifyupdatesui.cpp
1 /*
2  SPDX-FileCopyrightText: 2012 Samikshan Bairagya <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "skyobjects/supernova.h"
8 #include "supernovaecomponent.h"
9 #include "notifyupdatesui.h"
10 #include "ui_notifyupdatesui.h"
11 #include "kstars.h"
12 #include "kstarsdata.h"
13 #include "skymap.h"
14 #include "QTreeWidget"
15 
16 #include <QApplication>
17 
18 NotifyUpdatesUI::NotifyUpdatesUI(QWidget *parent) : QDialog(parent), ui(new Ui::NotifyUpdatesUI)
19 {
20  ui->setupUi(this);
21  setWindowTitle(i18nc("@title:window", "New Supernova(e) Discovered"));
22  connect(ui->centrePushButton, SIGNAL(clicked()), SLOT(slotCenter()));
23 }
24 
25 NotifyUpdatesUI::~NotifyUpdatesUI()
26 {
27  delete ui;
28 }
29 
30 void NotifyUpdatesUI::addItems(QList<SkyObject *> updatesList)
31 {
32  //int len = updatesList.size();
33  foreach (SkyObject *so, updatesList)
34  {
35  Supernova *sup = (Supernova *)so;
36 
37  QString name = sup->name();
38  QString hostGalaxy = i18n("Host Galaxy :: %1", sup->getHostGalaxy());
39  QString magnitude = i18n("Magnitude :: %1", QString::number(sup->getMagnitude()));
40  QString type = i18n("Type :: %1", sup->getType());
41  QString position =
42  i18n("Position :: RA : %1 Dec : %2", sup->getRA().toHMSString(), sup->getDec().toDMSString());
43  QString date = i18n("Date :: %1", sup->getDate());
44 
45  QTreeWidgetItem *info = new QTreeWidgetItem(ui->infoTreeWidget);
46  QTreeWidgetItem *hGalaxy = new QTreeWidgetItem(info);
47  QTreeWidgetItem *t = new QTreeWidgetItem(info);
48  QTreeWidgetItem *mag = new QTreeWidgetItem(info);
49  QTreeWidgetItem *pos = new QTreeWidgetItem(info);
50  QTreeWidgetItem *dt = new QTreeWidgetItem(info);
51 
52  info->setText(0, name);
53  hGalaxy->setText(0, hostGalaxy);
54  pos->setText(0, position);
55  mag->setText(0, magnitude);
56  t->setText(0, type);
57  dt->setText(0, date);
58  ui->infoTreeWidget->addTopLevelItem(info);
59  }
60 }
61 
62 void NotifyUpdatesUI::slotCenter()
63 {
64  KStars *kstars = KStars::Instance();
65  SkyObject *o = 0;
66  // get selected item
67  if (ui->infoTreeWidget->currentItem() != 0)
68  {
69  if (ui->infoTreeWidget->currentItem()->childCount() > 0) //Serial No. is selected
70  o = kstars->data()->objectNamed(ui->infoTreeWidget->currentItem()->text(0));
71  else
72  o = kstars->data()->objectNamed(ui->infoTreeWidget->currentItem()->parent()->text(0));
73  }
74  if (o != 0)
75  {
76  kstars->map()->setFocusPoint(o);
77  kstars->map()->setFocusObject(o);
78  kstars->map()->setDestination(*kstars->map()->focusPoint());
79  }
80 }
QString getDate() const
Definition: supernova.h:54
QString number(int n, int base)
QString getType() const
Definition: supernova.h:48
Type type(const QSqlDatabase &db)
SkyObject * objectNamed(const QString &name)
Find object by name.
Definition: kstarsdata.cpp:429
virtual QString name(void) const
Definition: skyobject.h:145
QString getHostGalaxy() const
Definition: supernova.h:51
SkyMap * map() const
Definition: kstars.h:143
void setFocusObject(SkyObject *o)
Set the FocusObject pointer to the argument.
Definition: skymap.cpp:336
static KStars * Instance()
Definition: kstars.h:125
void setDestination(const SkyPoint &f)
sets the destination point of the sky map.
Definition: skymap.cpp:968
QString i18n(const char *text, const TYPE &arg...)
void setFocusPoint(SkyPoint *f)
set the FocusPoint; the position that is to be the next Destination.
Definition: skymap.h:203
void setText(int column, const QString &text)
This is the main window for KStars. In addition to the GUI elements, the class contains the program c...
Definition: kstars.h:92
void setupUi(QWidget *widget)
QString name(StandardShortcut id)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
SkyPoint * focusPoint()
retrieve the FocusPoint position.
Definition: skymap.h:148
KStarsData * data() const
Definition: kstars.h:137
Information about an object in the sky.
Definition: skyobject.h:41
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 19 2022 03:57:52 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.