File indexing completed on 2024-04-21 03:49:54

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2008 Torsten Rahn <tackat@kde.org>
0004 // SPDX-FileCopyrightText: 2008 Inge Wallin <inge@lysator.liu.se>
0005 // SPDX-FileCopyrightText: 2011, 2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
0006 // SPDX-FileCopyrightText: 2012 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
0007 //
0008 
0009 #ifndef MARBLE_RENDERPLUGIN_H
0010 #define MARBLE_RENDERPLUGIN_H
0011 
0012 #include <QObject>
0013 #include <QString>
0014 #include <QRegion>
0015 
0016 #include "RenderPluginInterface.h"
0017 #include "marble_export.h"
0018 
0019 
0020 class QAction;
0021 class QActionGroup;
0022 class QStandardItem;
0023 
0024 namespace Marble
0025 {
0026 
0027 class MarbleModel;
0028 class RenderPluginModel;
0029 
0030 /**
0031  * @brief The abstract class that creates a renderable item
0032  *
0033  * Renderable Plugins can be used to extend Marble's functionality:
0034  * They allow to draw stuff on top of the map / globe
0035  *
0036  */
0037 
0038 class MARBLE_EXPORT RenderPlugin : public QObject, public RenderPluginInterface
0039 {
0040     Q_OBJECT
0041 
0042     Q_PROPERTY ( QString name READ name CONSTANT )
0043     Q_PROPERTY ( QString nameId READ nameId CONSTANT )
0044     Q_PROPERTY ( QString version READ version CONSTANT )
0045     Q_PROPERTY ( QString description READ description CONSTANT )
0046     Q_PROPERTY ( bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged )
0047     Q_PROPERTY ( bool visible READ visible WRITE setVisible NOTIFY visibilityChanged )
0048     Q_PROPERTY ( bool userCheckable READ isUserCheckable WRITE setUserCheckable NOTIFY userCheckableChanged )
0049 
0050  public:
0051     /**
0052      * @brief A Type of plugin
0053      */
0054     enum RenderType {
0055         UnknownRenderType,
0056         TopLevelRenderType,
0057         PanelRenderType,
0058         OnlineRenderType,
0059         ThemeRenderType
0060     };
0061 
0062     explicit RenderPlugin( const MarbleModel *marbleModel );
0063     ~RenderPlugin() override;
0064 
0065     /**
0066      * @brief String that should be displayed in GUI
0067      *
0068      * Using a "&" you can suggest key shortcuts
0069      *
0070      * Example: "&Stars"
0071      *
0072      * @return string for gui usage
0073      */
0074     virtual QString guiString() const = 0;
0075 
0076     /**
0077      * @brief Creation a new instance of the plugin
0078      *
0079      * This method is used to create a new object of the current
0080      * plugin using the @p marbleModel given.
0081      *
0082      * @param marbleModel base model
0083      * @return new instance of current plugin
0084      * @note Typically this method is implemented with the help of the MARBLE_PLUGIN() macro.
0085      */
0086     virtual RenderPlugin *newInstance( const MarbleModel *marbleModel ) const = 0;
0087 
0088     /**
0089      * @brief Access to the MarbleModel
0090      *
0091      * Internal way to access the model of marble.
0092      * Can be used to interact with the main application
0093      *
0094      * @return marble model
0095      * @see MarbleModel
0096      */
0097     const MarbleModel* marbleModel() const;
0098 
0099     /**
0100      * @brief Getting all actions
0101      *
0102      * This method is used by the main window to get all of the actions that this
0103      * plugin defines. There is no guarantee where the main window will place the
0104      * actions but it will generally be in a Menu. The returned QList should
0105      * also contain all of the actions returned by @see toolbarActions().
0106      *
0107      * @return a list of grouped actions
0108      */
0109     virtual const QList<QActionGroup*>*   actionGroups() const;
0110 
0111     /**
0112      * @brief Getting all actions which should be placed in the toolbar
0113      *
0114      * This method returns a subset of the actions returned by @see actions() which
0115      * are intended to be placed in a more prominent place such as a toolbar above
0116      * the Marble Widget. You are not guaranteed that they will be in an actual
0117      * toolbar but they will be visible and discoverable
0118      *
0119      * @return a list of grouped toolbar actions
0120      */
0121     virtual const QList<QActionGroup*>*   toolbarActionGroups() const;
0122 
0123     /**
0124      * @brief is enabled
0125      *
0126      * This method indicates enableability of the plugin
0127      *
0128      * If plugin is enabled it going to be displayed in Marble Menu
0129      * as active action which can be @see setUserCheckable
0130      *
0131      * @return enableability of the plugin
0132      * @see setEnabled
0133      */
0134     bool    enabled() const;
0135 
0136     /**
0137      * @brief is visible
0138      *
0139      * This method indicates visibility of the plugin
0140      *
0141      * If plugin is visible you can see it on the map/globe
0142      *
0143      * @return visibility of the plugin
0144      * @see setVisible
0145      */
0146     bool    visible() const;
0147 
0148     /**
0149      * @brief is user checkable
0150      *
0151      * This method indicates user checkability of plugin's
0152      * action displayed in application menu
0153      *
0154      * Can control plugin visibility
0155      *
0156      * @warning User can do it only if @see enabled is true
0157      *
0158      * @return checkability of the plugin
0159      * @see setUserCheckable
0160      */
0161     bool    isUserCheckable() const;
0162 
0163     /**
0164      * @brief Settings of the plugin
0165      *
0166      * Settings is the map (hash table) of plugin's settings
0167      * This method is called to determine the current settings of the plugin
0168      * for serialization, e.g. when closing the application.
0169      *
0170      * @return plugin's settings
0171      * @see setSettings
0172      */
0173     virtual QHash<QString,QVariant> settings() const;
0174 
0175     /**
0176      * @brief Set the settings of the plugin
0177      *
0178      * Usually this is called at startup to restore saved settings.
0179      *
0180      * @param new plugin's settings
0181      * @see settings
0182      */
0183     virtual void setSettings( const QHash<QString,QVariant> &settings );
0184 
0185     /**
0186      * @brief Render type of the plugin
0187      *
0188      * Function for returning the type of plugin this is for.
0189      * This affects where in the menu tree the action() is placed.
0190      *
0191      * @see RenderType
0192      * @return: The type of render plugin this is
0193      */
0194     virtual RenderType renderType() const;
0195 
0196     RenderState renderState() const override;
0197 
0198     QString runtimeTrace() const override;
0199 
0200  public Q_SLOTS:
0201     /**
0202      * @brief setting enabled
0203      *
0204      * If @p enabled = true, plugin will be enabled
0205      *
0206      * If plugin is enabled it will be possible to show/hide it
0207      * from menu (access from UI)
0208      *
0209      * @param enabled plugin's enabled state
0210      * @see enabled
0211      */
0212     void    setEnabled( bool enabled );
0213 
0214     /**
0215      * @brief setting visible
0216      *
0217      * If @p visible = true, plugin will be visible
0218      *
0219      * @param visible visibility of the plugin
0220      * @see visible
0221      */
0222     void    setVisible( bool visible );
0223 
0224     /**
0225      * @brief setting user checkable
0226      *
0227      * If @p isUserCheckable = true, user will get an
0228      * option to control visibility in application menu
0229      *
0230      * @param isUserCheckable user checkability of the plugin
0231      * @see isUserCheckable
0232      */
0233     void    setUserCheckable(bool isUserCheckable);
0234 
0235     /**
0236      * @brief Passes an empty set of settings to the plugin
0237      *
0238      * Well behaving plugins restore their settings to default values as a result of calling this method.
0239      *
0240      */
0241     void    restoreDefaultSettings();
0242 
0243     /**
0244      * @brief Full list of the settings keys
0245      *
0246      * This method should be used to get all possible
0247      * settings' keys for the plugin's settings
0248      *
0249      * @return list with the keys of settings
0250      */
0251     QStringList settingKeys() const;
0252 
0253     /**
0254      * @brief Change setting key's values
0255      * @param key setting key
0256      * @param value new value
0257      *
0258      * This method applies @p value for the @p key
0259      *
0260      * @return successfully changed or not
0261      */
0262     bool setSetting( const QString & key, const QVariant & value );
0263 
0264     /**
0265      * @brief Getting setting value from the settings
0266      * @param key setting's key index
0267      *
0268      * This method should be used to get current value of @p key
0269      * in settings hash table
0270      *
0271      * @return setting value
0272      */
0273     QVariant setting( const QString & key ) const;
0274 
0275     /**
0276      * @brief Plugin's menu action
0277      *
0278      * The action is checkable and controls the visibility of the plugin.
0279      *
0280      * @return action, displayed in menu
0281      */
0282     QAction *action() const;
0283 
0284  Q_SIGNALS:
0285     /**
0286      * This signal is emitted if the visibility is changed with @see setVisible
0287      */
0288     void visibilityChanged( bool visible, const QString &nameId );
0289 
0290     /**
0291      * This signal is emitted if the enabled property is changed with @see setEnabled
0292      */
0293     void enabledChanged( bool enable );
0294 
0295     /**
0296      * This signal is emitted if the user checkable property is changed with @see setUserCheckable
0297      */
0298     void userCheckableChanged(bool isUserCheckable);
0299 
0300     /**
0301      * This signal is emitted if the settings of the RenderPlugin changed.
0302      */
0303     void settingsChanged( const QString& nameId );
0304 
0305     /**
0306      * This signal is emitted if the actions that the plugin supports change in
0307      * any way
0308      */
0309     void actionGroupsChanged();
0310 
0311     /**
0312      * This signal is emitted if an update of the view is needed. If available with the
0313      * @p dirtyRegion which is the region the view will change in. If dirtyRegion.isEmpty() returns
0314      * true, the whole viewport has to be repainted.
0315      */
0316     void repaintNeeded( const QRegion& dirtyRegion = QRegion() );
0317 
0318  protected:
0319     bool eventFilter( QObject *, QEvent * ) override;
0320 
0321  private:
0322     friend class RenderPluginModel;
0323 
0324     QStandardItem *item();
0325 
0326     void applyItemState();
0327     void retrieveItemState();
0328 
0329  private:
0330     Q_DISABLE_COPY( RenderPlugin )
0331     class Private;
0332     Private * const d;
0333 };
0334 
0335 #define MARBLE_PLUGIN(T) public:\
0336     RenderPlugin* newInstance( const MarbleModel *marbleModel ) const override { return new T( marbleModel ); }
0337 }
0338 
0339 #endif