File indexing completed on 2024-04-21 03:44:49

0001 /*
0002     SPDX-FileCopyrightText: 2018 Valentin Boettcher <valentin@boettcher.cf>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 #include <QFrame>
0009 #include <QHash>
0010 #include <QAbstractTableModel>
0011 #include "eclipsetool/lunareclipsehandler.h"
0012 
0013 namespace Ui
0014 {
0015 class EclipseTool;
0016 }
0017 
0018 class KSPlanetBase;
0019 class QComboBox;
0020 class GeoLocation;
0021 
0022 /**
0023  * @brief The EclipseModel class
0024  * @short A simple model to contain EclipseEvents.
0025  */
0026 class EclipseModel : public QAbstractTableModel
0027 {
0028         Q_OBJECT
0029     public:
0030         // This is reimplemented boilerplate from QAbstractModel
0031         explicit EclipseModel(QObject * parent = nullptr);
0032         int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0033         int columnCount(const QModelIndex &parent = QModelIndex()) const override
0034         {
0035             Q_UNUSED(parent);
0036             return COLUMNS;
0037         }
0038         QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0039         QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
0040 
0041     public slots:
0042         /**
0043          * @brief reset
0044          * @short resets the data and the model
0045          */
0046         void reset();
0047 
0048         /**
0049          * @brief slotAddEclipse
0050          * @param eclipse
0051          * @short add an eclipse to the model
0052          */
0053         void slotAddEclipse(EclipseEvent_s eclipse);
0054 
0055         /**
0056          * @brief exportAsCsv
0057          * @short Export data as CSV (plus dialog)
0058          */
0059         void exportAsCsv();
0060 
0061         /**
0062          * @brief getEvent
0063          * @param index
0064          * @short retrieve an event
0065          */
0066         EclipseEvent_s getEvent(int index)
0067         {
0068             return m_eclipses.at(index);
0069         }
0070 
0071     private slots:
0072         // reimplemented to clear the data
0073         void resetInternalData()
0074         {
0075             m_eclipses.clear();
0076         }
0077 
0078     private:
0079         EclipseHandler::EclipseVector m_eclipses;
0080         const int COLUMNS { 5 };
0081 };
0082 
0083 /**
0084  * @brief The EclipseTool class
0085  * @short The UI for the Eclipsetool.
0086  * Currently only lunar eclipses are implemented.
0087  * Others will follow.
0088  */
0089 class EclipseTool : public QFrame
0090 {
0091         Q_OBJECT
0092 
0093     public:
0094         explicit EclipseTool(QWidget *parent = nullptr);
0095         ~EclipseTool();
0096 
0097     private slots:
0098         /**
0099          * @brief slotLocation
0100          * @short slot for setting the geolocation
0101          */
0102         void slotLocation();
0103 
0104         /**
0105          * @brief slotCompute
0106          * @short slot to start the computation
0107          */
0108         void slotCompute();
0109 
0110         /**
0111          * @brief slotFinished
0112          * @short slot to clear any residuals
0113          */
0114         void slotFinished();
0115 
0116         /**
0117          * @brief slotContextMenu
0118          * @short show context menu for an eclipse
0119          * @param pos
0120          */
0121         void slotContextMenu(QPoint pos);
0122 
0123         /**
0124          * @brief slotView
0125          * @param event
0126          * @short view an eclipse on the SkyMap
0127          */
0128         void slotView(EclipseEvent_s event);
0129 
0130     private:
0131         Ui::EclipseTool *ui;
0132 
0133         QVector<std::pair<int, QString>> m_object1List;
0134         QVector<std::pair<int, QString>> m_object2List;
0135 
0136         GeoLocation * m_geoLocation { nullptr };
0137         EclipseModel m_model;
0138 };