Marble

RenderPlugin.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2008 Torsten Rahn <rahn@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// 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
24namespace Marble
25{
26
27class 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
56RenderPlugin::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
74RenderPlugin::~RenderPlugin()
75{
76 delete d;
77}
78
79const MarbleModel* RenderPlugin::marbleModel() const
80{
81 return d->m_marbleModel;
82}
83
84QAction* RenderPlugin::action() const
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
94const QList<QActionGroup*>* RenderPlugin::actionGroups() const
95{
96 return nullptr;
97}
98
99const QList<QActionGroup*>* RenderPlugin::toolbarActionGroups() const
100{
101 return nullptr;
102}
103
104QStandardItem* 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
125void RenderPlugin::applyItemState()
126{
127 setEnabled( d->m_item.checkState() == Qt::Checked );
128}
129
130void RenderPlugin::retrieveItemState()
131{
132 d->m_item.setCheckState( enabled() ? Qt::Checked : Qt::Unchecked );
133}
134
135void 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
147void 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
157void 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
166bool RenderPlugin::enabled() const
167{
168 return d->m_enabled;
169}
170
171bool RenderPlugin::visible() const
172{
173 return d->m_visible;
174}
175
176bool RenderPlugin::isUserCheckable() const
177{
178 return d->m_userCheckable;
179}
180
181QHash<QString,QVariant> RenderPlugin::settings() const
182{
184
185 result.insert(QStringLiteral("enabled"), enabled());
186 result.insert(QStringLiteral("visible"), visible());
187
188 return result;
189}
190
191void RenderPlugin::setSettings( const QHash<QString,QVariant> &settings )
192{
193 setEnabled(settings.value(QStringLiteral("enabled"), enabled()).toBool());
194 setVisible(settings.value(QStringLiteral("visible"), visible()).toBool());
195}
196
197RenderPlugin::RenderType RenderPlugin::renderType() const
198{
199 return UnknownRenderType;
200}
201
202RenderState RenderPlugin::renderState() const
203{
204 return RenderState( name() );
205}
206
207QString RenderPlugin::runtimeTrace() const
208{
209 return name();
210}
211
212bool RenderPlugin::eventFilter( QObject *, QEvent * )
213{
214 return false;
215}
216
217void RenderPlugin::restoreDefaultSettings()
218{
219 setSettings( QHash<QString,QVariant>() );
220}
221
222QStringList RenderPlugin::settingKeys() const
223{
224 return settings().keys();
225}
226
227bool RenderPlugin::setSetting( const QString & key, const QVariant & value )
228{
229 QHash< QString, QVariant> settings = this->settings();
230 if( settings.contains( key ) )
231 {
232 settings [ key ] = value;
233 setSettings( settings );
234 return true;
235 } else {
236 return false;
237 }
238}
239
240QVariant RenderPlugin::setting( const QString & name ) const
241{
242 return settings().value( name, QVariant() );
243}
244
245} // namespace Marble
246
247#include "moc_RenderPlugin.cpp"
This file contains the headers for MarbleModel.
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition MarbleModel.h:87
RenderType
A Type of plugin.
Binds a QML item to a specific geodetic location in screen coordinates.
void setCheckable(bool)
bool contains(const Key &key) const const
iterator insert(const Key &key, const T &value)
T value(const Key &key) const const
void setIcon(const QIcon &icon)
ItemIsSelectable
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
T value() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:49:24 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.