Marble

RenderPlugin.h
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2008 Torsten Rahn <tackat@kde.org>
4// SPDX-FileCopyrightText: 2008 Inge Wallin <inge@lysator.liu.se>
5// SPDX-FileCopyrightText: 2011, 2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
6// SPDX-FileCopyrightText: 2012 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
7//
8
9#ifndef MARBLE_RENDERPLUGIN_H
10#define MARBLE_RENDERPLUGIN_H
11
12#include <QObject>
13#include <QRegion>
14#include <QString>
15
16#include "RenderPluginInterface.h"
17#include "marble_export.h"
18
19class QAction;
20class QActionGroup;
21class QStandardItem;
22
23namespace Marble
24{
25
26class MarbleModel;
27class RenderPluginModel;
28
29/**
30 * @brief The abstract class that creates a renderable item
31 *
32 * Renderable Plugins can be used to extend Marble's functionality:
33 * They allow to draw stuff on top of the map / globe
34 *
35 */
36
37class MARBLE_EXPORT RenderPlugin : public QObject, public RenderPluginInterface
38{
39 Q_OBJECT
40
41 Q_PROPERTY(QString name READ name CONSTANT)
42 Q_PROPERTY(QString nameId READ nameId CONSTANT)
43 Q_PROPERTY(QString version READ version CONSTANT)
44 Q_PROPERTY(QString description READ description CONSTANT)
45 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
46 Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibilityChanged)
47 Q_PROPERTY(bool userCheckable READ isUserCheckable WRITE setUserCheckable NOTIFY userCheckableChanged)
48
49public:
50 /**
51 * @brief A Type of plugin
52 */
54 UnknownRenderType,
55 TopLevelRenderType,
56 PanelRenderType,
57 OnlineRenderType,
58 ThemeRenderType
59 };
60
61 explicit RenderPlugin(const MarbleModel *marbleModel);
62 ~RenderPlugin() override;
63
64 /**
65 * @brief String that should be displayed in GUI
66 *
67 * Using a "&" you can suggest key shortcuts
68 *
69 * Example: "&Stars"
70 *
71 * @return string for gui usage
72 */
73 virtual QString guiString() const = 0;
74
75 /**
76 * @brief Creation a new instance of the plugin
77 *
78 * This method is used to create a new object of the current
79 * plugin using the @p marbleModel given.
80 *
81 * @param marbleModel base model
82 * @return new instance of current plugin
83 * @note Typically this method is implemented with the help of the MARBLE_PLUGIN() macro.
84 */
85 virtual RenderPlugin *newInstance(const MarbleModel *marbleModel) const = 0;
86
87 /**
88 * @brief Access to the MarbleModel
89 *
90 * Internal way to access the model of marble.
91 * Can be used to interact with the main application
92 *
93 * @return marble model
94 * @see MarbleModel
95 */
96 const MarbleModel *marbleModel() const;
97
98 /**
99 * @brief Getting all actions
100 *
101 * This method is used by the main window to get all of the actions that this
102 * plugin defines. There is no guarantee where the main window will place the
103 * actions but it will generally be in a Menu. The returned QList should
104 * also contain all of the actions returned by @see toolbarActions().
105 *
106 * @return a list of grouped actions
107 */
108 virtual const QList<QActionGroup *> *actionGroups() const;
109
110 /**
111 * @brief Getting all actions which should be placed in the toolbar
112 *
113 * This method returns a subset of the actions returned by @see actions() which
114 * are intended to be placed in a more prominent place such as a toolbar above
115 * the Marble Widget. You are not guaranteed that they will be in an actual
116 * toolbar but they will be visible and discoverable
117 *
118 * @return a list of grouped toolbar actions
119 */
120 virtual const QList<QActionGroup *> *toolbarActionGroups() const;
121
122 /**
123 * @brief is enabled
124 *
125 * This method indicates enableability of the plugin
126 *
127 * If plugin is enabled it going to be displayed in Marble Menu
128 * as active action which can be @see setUserCheckable
129 *
130 * @return enableability of the plugin
131 * @see setEnabled
132 */
133 bool enabled() const;
134
135 /**
136 * @brief is visible
137 *
138 * This method indicates visibility of the plugin
139 *
140 * If plugin is visible you can see it on the map/globe
141 *
142 * @return visibility of the plugin
143 * @see setVisible
144 */
145 bool visible() const;
146
147 /**
148 * @brief is user checkable
149 *
150 * This method indicates user checkability of plugin's
151 * action displayed in application menu
152 *
153 * Can control plugin visibility
154 *
155 * @warning User can do it only if @see enabled is true
156 *
157 * @return checkability of the plugin
158 * @see setUserCheckable
159 */
160 bool isUserCheckable() const;
161
162 /**
163 * @brief Settings of the plugin
164 *
165 * Settings is the map (hash table) of plugin's settings
166 * This method is called to determine the current settings of the plugin
167 * for serialization, e.g. when closing the application.
168 *
169 * @return plugin's settings
170 * @see setSettings
171 */
172 virtual QHash<QString, QVariant> settings() const;
173
174 /**
175 * @brief Set the settings of the plugin
176 *
177 * Usually this is called at startup to restore saved settings.
178 *
179 * @param new plugin's settings
180 * @see settings
181 */
182 virtual void setSettings(const QHash<QString, QVariant> &settings);
183
184 /**
185 * @brief Render type of the plugin
186 *
187 * Function for returning the type of plugin this is for.
188 * This affects where in the menu tree the action() is placed.
189 *
190 * @see RenderType
191 * @return: The type of render plugin this is
192 */
193 virtual RenderType renderType() const;
194
195 RenderState renderState() const override;
196
197 QString runtimeTrace() const override;
198
199public Q_SLOTS:
200 /**
201 * @brief setting enabled
202 *
203 * If @p enabled = true, plugin will be enabled
204 *
205 * If plugin is enabled it will be possible to show/hide it
206 * from menu (access from UI)
207 *
208 * @param enabled plugin's enabled state
209 * @see enabled
210 */
211 void setEnabled(bool enabled);
212
213 /**
214 * @brief setting visible
215 *
216 * If @p visible = true, plugin will be visible
217 *
218 * @param visible visibility of the plugin
219 * @see visible
220 */
221 void setVisible(bool visible);
222
223 /**
224 * @brief setting user checkable
225 *
226 * If @p isUserCheckable = true, user will get an
227 * option to control visibility in application menu
228 *
229 * @param isUserCheckable user checkability of the plugin
230 * @see isUserCheckable
231 */
232 void setUserCheckable(bool isUserCheckable);
233
234 /**
235 * @brief Passes an empty set of settings to the plugin
236 *
237 * Well behaving plugins restore their settings to default values as a result of calling this method.
238 *
239 */
240 void restoreDefaultSettings();
241
242 /**
243 * @brief Full list of the settings keys
244 *
245 * This method should be used to get all possible
246 * settings' keys for the plugin's settings
247 *
248 * @return list with the keys of settings
249 */
250 QStringList settingKeys() const;
251
252 /**
253 * @brief Change setting key's values
254 * @param key setting key
255 * @param value new value
256 *
257 * This method applies @p value for the @p key
258 *
259 * @return successfully changed or not
260 */
261 bool setSetting(const QString &key, const QVariant &value);
262
263 /**
264 * @brief Getting setting value from the settings
265 * @param key setting's key index
266 *
267 * This method should be used to get current value of @p key
268 * in settings hash table
269 *
270 * @return setting value
271 */
272 QVariant setting(const QString &key) const;
273
274 /**
275 * @brief Plugin's menu action
276 *
277 * The action is checkable and controls the visibility of the plugin.
278 *
279 * @return action, displayed in menu
280 */
281 QAction *action() const;
282
283Q_SIGNALS:
284 /**
285 * This signal is emitted if the visibility is changed with @see setVisible
286 */
287 void visibilityChanged(bool visible, const QString &nameId);
288
289 /**
290 * This signal is emitted if the enabled property is changed with @see setEnabled
291 */
292 void enabledChanged(bool enable);
293
294 /**
295 * This signal is emitted if the user checkable property is changed with @see setUserCheckable
296 */
297 void userCheckableChanged(bool isUserCheckable);
298
299 /**
300 * This signal is emitted if the settings of the RenderPlugin changed.
301 */
302 void settingsChanged(const QString &nameId);
303
304 /**
305 * This signal is emitted if the actions that the plugin supports change in
306 * any way
307 */
309
310 /**
311 * This signal is emitted if an update of the view is needed. If available with the
312 * @p dirtyRegion which is the region the view will change in. If dirtyRegion.isEmpty() returns
313 * true, the whole viewport has to be repainted.
314 */
315 void repaintNeeded(const QRegion &dirtyRegion = QRegion());
316
317protected:
318 bool eventFilter(QObject *, QEvent *) override;
319
320private:
321 friend class RenderPluginModel;
322
323 QStandardItem *item();
324
325 void applyItemState();
326 void retrieveItemState();
327
328private:
329 Q_DISABLE_COPY(RenderPlugin)
330 class Private;
331 Private *const d;
332};
333
334#define MARBLE_PLUGIN(T) \
335public: \
336 RenderPlugin *newInstance(const MarbleModel *marbleModel) const override \
337 { \
338 return new T(marbleModel); \
339 }
340}
341
342#endif
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition MarbleModel.h:84
The class that specifies the Marble layer interface of a plugin.
Provides common access to various kinds of plugins without having to know about their details.
The abstract class that creates a renderable item.
virtual QString guiString() const =0
String that should be displayed in GUI.
virtual RenderPlugin * newInstance(const MarbleModel *marbleModel) const =0
Creation a new instance of the plugin.
void enabledChanged(bool enable)
This signal is emitted if the enabled property is changed with.
void actionGroupsChanged()
This signal is emitted if the actions that the plugin supports change in any way.
RenderType
A Type of plugin.
void repaintNeeded(const QRegion &dirtyRegion=QRegion())
This signal is emitted if an update of the view is needed.
void userCheckableChanged(bool isUserCheckable)
This signal is emitted if the user checkable property is changed with.
void settingsChanged(const QString &nameId)
This signal is emitted if the settings of the RenderPlugin changed.
void visibilityChanged(bool visible, const QString &nameId)
This signal is emitted if the visibility is changed with.
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 Fri Nov 29 2024 11:55:54 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.