Marble

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

KDE's Doxygen guidelines are available online.