File indexing completed on 2024-05-05 03:50:42
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2012 Rene Kuettner <rene@bitkanal.net> 0004 // 0005 0006 #ifndef MARBLE_ECLIPSESMODEL_H 0007 #define MARBLE_ECLIPSESMODEL_H 0008 0009 #include <QAbstractItemModel> 0010 0011 #include "GeoDataCoordinates.h" 0012 #include "MarbleModel.h" 0013 0014 class EclSolar; 0015 0016 namespace Marble 0017 { 0018 0019 class EclipsesItem; 0020 0021 /** 0022 * @brief The model for eclipses 0023 * 0024 * EclipsesModel provides an interface to the eclsolar backend. Instances 0025 * of this class hold EclipseItem objects for every eclipse event of a given 0026 * year. Furthermore, it implements QTs AbstractItemModel interface and can 0027 * be used with QTs view classes. 0028 */ 0029 class EclipsesModel : public QAbstractItemModel 0030 { 0031 Q_OBJECT 0032 0033 public: 0034 explicit EclipsesModel( const MarbleModel *model, QObject *parent = nullptr ); 0035 0036 ~EclipsesModel() override; 0037 0038 /** 0039 * @brief Return the current observation point 0040 * 0041 * Returns the current observation point on which location specific 0042 * eclipse calculations are based. 0043 * 0044 * @return GeoDataCoordinates of the current observation point 0045 * @see setObservationPoint 0046 */ 0047 const GeoDataCoordinates& observationPoint() const; 0048 0049 /** 0050 * @brief Set the current observation point 0051 * 0052 * @param coords 0053 * 0054 * Set the current observation point to @p coords. This will mark all 0055 * items for recalculation of eclipses details according to the new 0056 * observation point. 0057 * 0058 * @see observationPoint 0059 */ 0060 void setObservationPoint( const GeoDataCoordinates &coords ); 0061 0062 /** 0063 * @brief Set the year 0064 * 0065 * @param year The year 0066 * 0067 * Sets the year to @p year. This clears all items in the model and 0068 * fills it with all eclipse items for the given year. 0069 * 0070 * @see year 0071 */ 0072 void setYear( int year ); 0073 0074 /** 0075 * @brief Return the year 0076 * 0077 * Returns the year of all eclipse items in this model. 0078 * 0079 * @return the year of eclipse items in this model 0080 * @see setYear 0081 */ 0082 int year() const; 0083 0084 /** 0085 * @brief Set if lunar eclipses are enabled 0086 * @param enable Indicates whether or not to allow lunar eclipses 0087 * 0088 * Allows to enable or disable inclusion of lunar eclipses. 0089 * 0090 * @see withLunarEclipses 0091 */ 0092 void setWithLunarEclipses( const bool enable ); 0093 0094 /** 0095 * @brief Return whether or not lunar eclipses are enabled 0096 * 0097 * Returns whether or not lunar eclipses are included in the eclipse 0098 * calculation. 0099 * 0100 * @return True if lunar eclipses are enabled or false otherwise 0101 * @see setWithLunarEclipses 0102 */ 0103 bool withLunarEclipses() const; 0104 0105 /** 0106 * @brief Get eclipse item of a given year 0107 * 0108 * @param index 0109 * 0110 * This returns the eclipse item with @p index for the year set. If 0111 * there is no eclipse with @p index in the set year, NULL will be 0112 * returned. 0113 * 0114 * @return the requested eclipse item or NULL if there is no eclipse 0115 * @see setYear 0116 */ 0117 EclipsesItem* eclipseWithIndex( int index ); 0118 0119 /** 0120 * @brief Return the items in this model 0121 * 0122 * Returns a list of items currently in the model. 0123 * 0124 * @return list of items in the model 0125 */ 0126 QList<EclipsesItem*> items() const; 0127 0128 // QT abstract item model interface 0129 QModelIndex index( int row, int column, 0130 const QModelIndex &parent = QModelIndex() ) const override; 0131 QModelIndex parent( const QModelIndex &index ) const override; 0132 int rowCount( const QModelIndex &parent = QModelIndex() ) const override; 0133 int columnCount( const QModelIndex &parent = QModelIndex() ) const override; 0134 QVariant data( const QModelIndex &index, 0135 int role = Qt::DisplayRole ) const override; 0136 QVariant headerData( int section, Qt::Orientation orientation, 0137 int role = Qt::DisplayRole ) const override; 0138 0139 public Q_SLOTS: 0140 /** 0141 * @brief Update the list of eclipse items 0142 * 0143 * This forces an update of the current list of eclipse items by 0144 * calculating all eclipse events for the currently set year and 0145 * adding them to the model. All previously added items are 0146 * cleared before. 0147 * 0148 * @see clear 0149 */ 0150 void update(); 0151 0152 private: 0153 /** 0154 * @brief Add an item to the model 0155 * @param item the item to add 0156 * 0157 * Adds @p item to the model. 0158 * 0159 * @see clear 0160 */ 0161 void addItem( EclipsesItem *item ); 0162 0163 /** 0164 * @brief Clears all items 0165 * 0166 * Clear the model by removing all items. 0167 * 0168 * @see addItem 0169 */ 0170 void clear(); 0171 0172 const MarbleModel *m_marbleModel; 0173 EclSolar *m_ecl; 0174 QList<EclipsesItem*> m_items; 0175 int m_currentYear; 0176 bool m_withLunarEclipses; 0177 GeoDataCoordinates m_observationPoint; 0178 }; 0179 0180 } 0181 0182 #endif // MARBLE_ECLIPSESMODEL_H