Marble

RenderPlugin.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2008 Torsten Rahn <[email protected]>
4 // SPDX-FileCopyrightText: 2008 Inge Wallin <[email protected]>
5 // SPDX-FileCopyrightText: 2011, 2012 Bernhard Beschow <[email protected]>
6 // SPDX-FileCopyrightText: 2012 Illya Kovalevskyy <[email protected]>
7 //
8 
9 // Self
10 #include "RenderPlugin.h"
11 
12 // Marble
13 #include "DialogConfigurationInterface.h"
14 #include "MarbleModel.h"
15 #include "MarbleDebug.h"
16 #include "RenderPluginModel.h"
17 #include "RenderState.h"
18 
19 // Qt
20 #include <QAction>
21 #include <QStandardItem>
22 
23 
24 namespace Marble
25 {
26 
27 class Q_DECL_HIDDEN RenderPlugin::Private
28 {
29  public:
30  Private( const MarbleModel *marbleModel )
31  : m_marbleModel( marbleModel ),
32  m_action(nullptr),
33  m_item(),
34  m_enabled(true),
35  m_visible(true),
36  m_userCheckable(true)
37  {
38  }
39 
40  ~Private()
41  {
42  }
43 
44  // const: RenderPlugins should only read the model, not modify it
45  const MarbleModel *const m_marbleModel;
46 
47  QAction m_action;
48  QStandardItem m_item;
49 
50  bool m_enabled;
51  bool m_visible;
52  bool m_userCheckable;
53 };
54 
55 
56 RenderPlugin::RenderPlugin( const MarbleModel *marbleModel )
57  : d( new Private( marbleModel ) )
58 {
59  connect( &d->m_action, SIGNAL(toggled(bool)),
60  this, SLOT(setVisible(bool)) );
61  connect( this, SIGNAL(visibilityChanged(bool,QString)),
62  &d->m_action, SLOT(setChecked(bool)) );
63  connect( this, SIGNAL(enabledChanged(bool)),
64  &d->m_action, SLOT(setVisible(bool)) );
65  connect( this, SIGNAL(enabledChanged(bool)),
66  SIGNAL(actionGroupsChanged()) );
67 
68  connect( this, SIGNAL(visibilityChanged(bool,QString)),
69  this, SIGNAL(repaintNeeded()) );
70  connect( this, SIGNAL(settingsChanged(QString)),
71  this, SIGNAL(repaintNeeded()) );
72 }
73 
74 RenderPlugin::~RenderPlugin()
75 {
76  delete d;
77 }
78 
80 {
81  return d->m_marbleModel;
82 }
83 
85 {
86  d->m_action.setCheckable( true );
87  d->m_action.setChecked( visible() );
88  d->m_action.setIcon( icon() );
89  d->m_action.setText( guiString() );
90  d->m_action.setToolTip( description() );
91  return &d->m_action;
92 }
93 
95 {
96  return nullptr;
97 }
98 
100 {
101  return nullptr;
102 }
103 
104 QStandardItem* RenderPlugin::item()
105 {
106  d->m_item.setIcon( icon() );
107  d->m_item.setText( name() );
108  d->m_item.setEditable( false );
109  d->m_item.setCheckable( true );
110  d->m_item.setCheckState( enabled() ? Qt::Checked : Qt::Unchecked );
111  d->m_item.setToolTip( description() );
112  d->m_item.setFlags( d->m_item.flags() & ~Qt::ItemIsSelectable );
113 
114  // Custom data
115  d->m_item.setData( nameId(), RenderPluginModel::NameId );
116  d->m_item.setData( (bool) qobject_cast<DialogConfigurationInterface *>( this ), RenderPluginModel::ConfigurationDialogAvailable );
117  d->m_item.setData( backendTypes(), RenderPluginModel::BackendTypes );
118  d->m_item.setData( version(), RenderPluginModel::Version );
119  d->m_item.setData( aboutDataText(), RenderPluginModel::AboutDataText );
120  d->m_item.setData( copyrightYears(), RenderPluginModel::CopyrightYears );
121 
122  return &d->m_item;
123 }
124 
125 void RenderPlugin::applyItemState()
126 {
127  setEnabled( d->m_item.checkState() == Qt::Checked );
128 }
129 
130 void RenderPlugin::retrieveItemState()
131 {
132  d->m_item.setCheckState( enabled() ? Qt::Checked : Qt::Unchecked );
133 }
134 
135 void RenderPlugin::setEnabled( bool enabled )
136 {
137  if ( enabled == d->m_enabled )
138  return;
139 
140  d->m_enabled = enabled;
141 
142  d->m_item.setCheckState( enabled ? Qt::Checked : Qt::Unchecked );
143 
144  emit enabledChanged( enabled );
145 }
146 
147 void RenderPlugin::setVisible( bool visible )
148 {
149  if ( visible == d->m_visible )
150  return;
151 
152  d->m_visible = visible;
153 
154  emit visibilityChanged( visible, nameId() );
155 }
156 
157 void RenderPlugin::setUserCheckable( bool checkable )
158 {
159  if ( checkable != d->m_userCheckable ) {
160  d->m_action.setEnabled( checkable );
161  d->m_userCheckable = checkable;
162  emit userCheckableChanged( checkable );
163  }
164 }
165 
166 bool RenderPlugin::enabled() const
167 {
168  return d->m_enabled;
169 }
170 
171 bool RenderPlugin::visible() const
172 {
173  return d->m_visible;
174 }
175 
177 {
178  return d->m_userCheckable;
179 }
180 
182 {
184 
185  result.insert(QStringLiteral("enabled"), enabled());
186  result.insert(QStringLiteral("visible"), visible());
187 
188  return result;
189 }
190 
192 {
193  setEnabled(settings.value(QStringLiteral("enabled"), enabled()).toBool());
194  setVisible(settings.value(QStringLiteral("visible"), visible()).toBool());
195 }
196 
198 {
199  return UnknownRenderType;
200 }
201 
202 RenderState RenderPlugin::renderState() const
203 {
204  return RenderState( name() );
205 }
206 
207 QString RenderPlugin::runtimeTrace() const
208 {
209  return name();
210 }
211 
212 bool RenderPlugin::eventFilter( QObject *, QEvent * )
213 {
214  return false;
215 }
216 
218 {
220 }
221 
223 {
224  return settings().keys();
225 }
226 
227 bool RenderPlugin::setSetting( const QString & key, const QVariant & value )
228 {
230  if( settings.contains( key ) )
231  {
232  settings [ key ] = value;
234  return true;
235  } else {
236  return false;
237  }
238 }
239 
241 {
242  return settings().value( name, QVariant() );
243 }
244 
245 } // namespace Marble
246 
247 #include "moc_RenderPlugin.cpp"
const T value(const Key &key) const const
QAction * action() const
Plugin's menu action.
virtual RenderType renderType() const
Render type of the plugin.
QVariant setting(const QString &key) const
Getting setting value from the settings.
QList< Key > keys() const const
void setUserCheckable(bool isUserCheckable)
setting user checkable
void visibilityChanged(bool visible, const QString &nameId)
This signal is emitted if the visibility is changed with.
virtual QStringList backendTypes() const =0
Returns the name(s) of the backend that the plugin can render.
void setEnabled(bool enabled)
setting enabled
const MarbleModel * marbleModel() const
Access to the MarbleModel.
void setVisible(bool visible)
setting visible
virtual const QList< QActionGroup * > * actionGroups() const
Getting all actions.
void enabledChanged(bool enable)
This signal is emitted if the enabled property is changed with.
QHash::iterator insert(const Key &key, const T &value)
virtual QString aboutDataText() const
Returns about text (credits) for external data the plugin uses.
ItemIsSelectable
void restoreDefaultSettings()
Passes an empty set of settings to the plugin.
virtual QString guiString() const =0
String that should be displayed in GUI.
void userCheckableChanged(bool isUserCheckable)
This signal is emitted if the user checkable property is changed with.
Binds a QML item to a specific geodetic location in screen coordinates.
RenderType
A Type of plugin.
Definition: RenderPlugin.h:54
virtual void setSettings(const QHash< QString, QVariant > &settings)
Set the settings of the plugin.
bool setSetting(const QString &key, const QVariant &value)
Change setting key's values.
virtual QIcon icon() const =0
Returns an icon for the plugin.
bool isUserCheckable() const
is user checkable
virtual QHash< QString, QVariant > settings() const
Settings of the plugin.
bool contains(const Key &key) const const
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition: MarbleModel.h:86
QStringList settingKeys() const
Full list of the settings keys.
virtual const QList< QActionGroup * > * toolbarActionGroups() const
Getting all actions which should be placed in the toolbar.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Sep 21 2023 04:12:28 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.