Marble

AbstractDataPluginModel.h
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2009 Bastian Holst <[email protected]>
4 //
5 
6 #ifndef MARBLE_ABSTRACTDATAPLUGINMODEL_H
7 #define MARBLE_ABSTRACTDATAPLUGINMODEL_H
8 
9 #include <QObject>
10 #include <QList>
11 #include <QHash>
12 
13 #include "marble_export.h"
14 
15 class QPoint;
16 class QUrl;
17 class QString;
18 class QStringList;
19 
20 namespace Marble
21 {
22 
23 class AbstractDataPluginModelPrivate;
24 class AbstractDataPluginItem;
25 class GeoDataLatLonAltBox;
26 class MarbleModel;
27 class ViewportParams;
28 
29 /**
30  * @short An abstract data model (not based on QAbstractModel) for a AbstractDataPlugin.
31  *
32  * This class is an abstract model for a AbstractDataPlugin.
33  * It provides the storage and selection of added <b>items</b> and it is also responsible for
34  * downloading item data.
35  *
36  * The functions <b>getAdditionalItems()</b> and <b>parseFile()</b> have to be reimplemented in
37  * a subclass.
38  **/
39 class MARBLE_EXPORT AbstractDataPluginModel : public QObject
40 {
41  Q_OBJECT
42 
43  /** @todo FIXME Qt Quick segfaults if using the real class here instead of QObject */
44  Q_PROPERTY( QObject* favoritesModel READ favoritesModel CONSTANT )
45 
46  public:
47  explicit AbstractDataPluginModel( const QString& name, const MarbleModel *marbleModel, QObject *parent = nullptr );
48  ~AbstractDataPluginModel() override;
49 
50  const MarbleModel *marbleModel() const;
51 
52  /**
53  * @brief Get the items on the viewport
54  * Returns the currently downloaded images in the @p viewport.
55  * The maximum number of images can be specified with @p number,
56  * 0 means no limit.
57  * @return The list of item with most important item first.
58  */
59  QList<AbstractDataPluginItem*> items( const ViewportParams *viewport,
60  qint32 number = 10 );
61 
62  /**
63  * @brief Get all items that contain the given point
64  * Returns a list of all items that contain the point @p curpos
65  */
66  QList<AbstractDataPluginItem *> whichItemAt( const QPoint& curpos );
67 
68  /**
69  * @brief Sets the settings for all items.
70  * Sets the settings for all items before painting. This ensures that all items react on
71  * changed settings.
72  */
73  void setItemSettings(const QHash<QString, QVariant> &itemSettings);
74 
75  virtual void setFavoriteItems( const QStringList& list );
76  QStringList favoriteItems() const;
77 
78  void setFavoriteItemsOnly( bool favoriteOnly );
79  bool isFavoriteItemsOnly() const;
80 
81  QObject* favoritesModel();
82 
83  /**
84  * Finds the item with @p id in the list.
85  * @return The pointer to the item or (if no item has been found) 0
86  */
87  AbstractDataPluginItem *findItem( const QString& id ) const;
88 
89  /**
90  * Testing the existence of the item @p id in the list
91  */
92  bool itemExists( const QString& id ) const;
93 
94 public Q_SLOTS:
95  /**
96  * Adds the @p items to the list of initialized items. It checks if items with the same id are
97  * already in the list and ignores and deletes them in this case.
98  */
99  void addItemsToList( const QList<AbstractDataPluginItem*> &items );
100 
101  /**
102  * Convenience method to add one item to the list. See addItemsToList
103  */
104  void addItemToList( AbstractDataPluginItem *item );
105 
106  /**
107  * Removes all items
108  */
109  void clear();
110 
111  protected:
112  /**
113  * Managing to get @p number additional items in @p box. This includes generating a url and
114  * downloading the corresponding file.
115  * This method has to be implemented in a subclass.
116  **/
117  virtual void getAdditionalItems( const GeoDataLatLonAltBox& box,
118  qint32 number = 10 ) = 0;
119 
120  /**
121  * @brief Retrieve data for a specific item
122  * @param id Item id of the item to retrieve
123  */
124  virtual void getItem( const QString &id );
125 
126  /**
127  * Parse the @p file and generate items. The items will be added to the list or the method
128  * starts additionally needed downloads.
129  * This method has to be implemented in a subclass.
130  **/
131  virtual void parseFile( const QByteArray& file );
132 
133  /**
134  * Downloads the file from @p url. @p item -> addDownloadedFile() will be called when the
135  * download is finished.
136  * @param url the file URL
137  * @param type The type of the download (to be specified by the subclasser)
138  * @param item the data plugin item
139  **/
140  void downloadItem( const QUrl& url, const QString& type, AbstractDataPluginItem *item );
141 
142  /**
143  * Download the description file from the @p url.
144  */
145  void downloadDescriptionFile( const QUrl& url );
146 
147  void registerItemProperties( const QMetaObject& item );
148 
149  private Q_SLOTS:
150  /**
151  * @brief Get new items with getAdditionalItems if it is reasonable.
152  */
153  void handleChangedViewport();
154 
155  /**
156  * @brief This method will assign downloaded files to the corresponding items
157  * @param relativeUrlString The string containing the relative (to the downloader path)
158  * url of the downloaded file.
159  * @param id The id of the downloaded file
160  */
161  void processFinishedJob( const QString& relativeUrlString, const QString& id );
162 
163  /**
164  * @brief Removes the item from the list.
165  */
166  void removeItem( QObject *item );
167 
168  void favoriteItemChanged( const QString& id, bool isFavorite );
169 
170  void scheduleItemSort();
171 
172  void themeChanged();
173 
174  Q_SIGNALS:
175  void itemsUpdated();
176  void favoriteItemsChanged( const QStringList& favoriteItems );
177  void favoriteItemsOnlyChanged();
178 
179  private:
180  AbstractDataPluginModelPrivate * const d;
181  friend class AbstractDataPluginModelPrivate;
182 };
183 
184 }
185 
186 #endif
A class that defines a 3D bounding box for geographic data.
A public class that controls what is visible in the viewport of a Marble map.
Binds a QML item to a specific geodetic location in screen coordinates.
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition: MarbleModel.h:86
An abstract data model (not based on QAbstractModel) for a AbstractDataPlugin.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 12 2022 04:06:54 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.