Marble

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

KDE's Doxygen guidelines are available online.