Marble

AbstractDataPluginModel.h
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2009 Bastian Holst <bastianholst@gmx.de>
4//
5
6#ifndef MARBLE_ABSTRACTDATAPLUGINMODEL_H
7#define MARBLE_ABSTRACTDATAPLUGINMODEL_H
8
9#include <QHash>
10#include <QList>
11#include <QObject>
12
13#include "marble_export.h"
14
15#include <QPoint>
16#include <QString>
17#include <QStringList>
18#include <QUrl>
19
20namespace Marble
21{
22
23class AbstractDataPluginModelPrivate;
24class AbstractDataPluginItem;
25class GeoDataLatLonAltBox;
26class MarbleModel;
27class 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 **/
39class 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
46public:
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, qint32 number = 10);
60
61 /**
62 * @brief Get all items that contain the given point
63 * Returns a list of all items that contain the point @p curpos
64 */
65 QList<AbstractDataPluginItem *> whichItemAt(const QPoint &curpos);
66
67 /**
68 * @brief Sets the settings for all items.
69 * Sets the settings for all items before painting. This ensures that all items react on
70 * changed settings.
71 */
72 void setItemSettings(const QHash<QString, QVariant> &itemSettings);
73
74 virtual void setFavoriteItems(const QStringList &list);
75 QStringList favoriteItems() const;
76
77 void setFavoriteItemsOnly(bool favoriteOnly);
78 bool isFavoriteItemsOnly() const;
79
80 QObject *favoritesModel();
81
82 /**
83 * Finds the item with @p id in the list.
84 * @return The pointer to the item or (if no item has been found) 0
85 */
86 AbstractDataPluginItem *findItem(const QString &id) const;
87
88 /**
89 * Testing the existence of the item @p id in the list
90 */
91 bool itemExists(const QString &id) const;
92
93public Q_SLOTS:
94 /**
95 * Adds the @p items to the list of initialized items. It checks if items with the same id are
96 * already in the list and ignores and deletes them in this case.
97 */
98 void addItemsToList(const QList<AbstractDataPluginItem *> &items);
99
100 /**
101 * Convenience method to add one item to the list. See addItemsToList
102 */
103 void addItemToList(AbstractDataPluginItem *item);
104
105 /**
106 * Removes all items
107 */
108 void clear();
109
110protected:
111 /**
112 * Managing to get @p number additional items in @p box. This includes generating a url and
113 * downloading the corresponding file.
114 * This method has to be implemented in a subclass.
115 **/
116 virtual void getAdditionalItems(const GeoDataLatLonAltBox &box, qint32 number = 10) = 0;
117
118 /**
119 * @brief Retrieve data for a specific item
120 * @param id Item id of the item to retrieve
121 */
122 virtual void getItem(const QString &id);
123
124 /**
125 * Parse the @p file and generate items. The items will be added to the list or the method
126 * starts additionally needed downloads.
127 * This method has to be implemented in a subclass.
128 **/
129 virtual void parseFile(const QByteArray &file);
130
131 /**
132 * Downloads the file from @p url. @p item -> addDownloadedFile() will be called when the
133 * download is finished.
134 * @param url the file URL
135 * @param type The type of the download (to be specified by the subclasser)
136 * @param item the data plugin item
137 **/
138 void downloadItem(const QUrl &url, const QString &type, AbstractDataPluginItem *item);
139
140 /**
141 * Download the description file from the @p url.
142 */
143 void downloadDescriptionFile(const QUrl &url);
144
145 void registerItemProperties(const QMetaObject &item);
146
147private Q_SLOTS:
148 /**
149 * @brief Get new items with getAdditionalItems if it is reasonable.
150 */
151 void handleChangedViewport();
152
153 /**
154 * @brief This method will assign downloaded files to the corresponding items
155 * @param relativeUrlString The string containing the relative (to the downloader path)
156 * url of the downloaded file.
157 * @param id The id of the downloaded file
158 */
159 void processFinishedJob(const QString &relativeUrlString, const QString &id);
160
161 /**
162 * @brief Removes the item from the list.
163 */
164 void removeItem(QObject *item);
165
166 void favoriteItemChanged(const QString &id, bool isFavorite);
167
168 void scheduleItemSort();
169
170 void themeChanged();
171
172Q_SIGNALS:
173 void itemsUpdated();
174 void favoriteItemsChanged(const QStringList &favoriteItems);
175 void favoriteItemsOnlyChanged();
176
177private:
178 AbstractDataPluginModelPrivate *const d;
179 friend class AbstractDataPluginModelPrivate;
180};
181
182}
183
184#endif
An abstract data model (not based on QAbstractModel) for a AbstractDataPlugin.
virtual void getAdditionalItems(const GeoDataLatLonAltBox &box, qint32 number=10)=0
Managing to get number additional items in box.
A class that defines a 3D bounding box for geographic data.
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition MarbleModel.h:84
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.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.