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 "MarbleDebug.h"
15#include "MarbleModel.h"
16#include "RenderPluginModel.h"
17#include "RenderState.h"
18
19// Qt
20#include <QAction>
21#include <QStandardItem>
22
23namespace Marble
24{
25
26class Q_DECL_HIDDEN RenderPlugin::Private
27{
28public:
29 Private(const MarbleModel *marbleModel)
30 : m_marbleModel(marbleModel)
31 , m_item()
32 , m_enabled(true)
33 , m_visible(true)
34 , m_userCheckable(true)
35 {
36 }
37
38 ~Private() = default;
39
40 // const: RenderPlugins should only read the model, not modify it
41 const MarbleModel *const m_marbleModel;
42
43 QAction m_action;
44 QStandardItem m_item;
45
46 bool m_enabled;
47 bool m_visible;
48 bool m_userCheckable;
49};
50
51RenderPlugin::RenderPlugin(const MarbleModel *marbleModel)
52 : d(new Private(marbleModel))
53{
54 connect(&d->m_action, SIGNAL(toggled(bool)), this, SLOT(setVisible(bool)));
55 connect(this, SIGNAL(visibilityChanged(bool, QString)), &d->m_action, SLOT(setChecked(bool)));
56 connect(this, SIGNAL(enabledChanged(bool)), &d->m_action, SLOT(setVisible(bool)));
57 connect(this, SIGNAL(enabledChanged(bool)), SIGNAL(actionGroupsChanged()));
58
59 connect(this, SIGNAL(visibilityChanged(bool, QString)), this, SIGNAL(repaintNeeded()));
60 connect(this, SIGNAL(settingsChanged(QString)), this, SIGNAL(repaintNeeded()));
61}
62
63RenderPlugin::~RenderPlugin()
64{
65 delete d;
66}
67
68const MarbleModel *RenderPlugin::marbleModel() const
69{
70 return d->m_marbleModel;
71}
72
73QAction *RenderPlugin::action() const
74{
75 d->m_action.setCheckable(true);
76 d->m_action.setChecked(visible());
77 d->m_action.setIcon(icon());
78 d->m_action.setText(guiString());
79 d->m_action.setToolTip(description());
80 return &d->m_action;
81}
82
83const QList<QActionGroup *> *RenderPlugin::actionGroups() const
84{
85 return nullptr;
86}
87
88const QList<QActionGroup *> *RenderPlugin::toolbarActionGroups() const
89{
90 return nullptr;
91}
92
93QStandardItem *RenderPlugin::item()
94{
95 d->m_item.setIcon(icon());
96 d->m_item.setText(name());
97 d->m_item.setEditable(false);
98 d->m_item.setCheckable(true);
99 d->m_item.setCheckState(enabled() ? Qt::Checked : Qt::Unchecked);
100 d->m_item.setToolTip(description());
101 d->m_item.setFlags(d->m_item.flags() & ~Qt::ItemIsSelectable);
102
103 // Custom data
104 d->m_item.setData(nameId(), RenderPluginModel::NameId);
105 d->m_item.setData((bool)qobject_cast<DialogConfigurationInterface *>(this), RenderPluginModel::ConfigurationDialogAvailable);
106 d->m_item.setData(backendTypes(), RenderPluginModel::BackendTypes);
107 d->m_item.setData(version(), RenderPluginModel::Version);
108 d->m_item.setData(aboutDataText(), RenderPluginModel::AboutDataText);
109 d->m_item.setData(copyrightYears(), RenderPluginModel::CopyrightYears);
110
111 return &d->m_item;
112}
113
114void RenderPlugin::applyItemState()
115{
116 setEnabled(d->m_item.checkState() == Qt::Checked);
117}
118
119void RenderPlugin::retrieveItemState()
120{
121 d->m_item.setCheckState(enabled() ? Qt::Checked : Qt::Unchecked);
122}
123
124void RenderPlugin::setEnabled(bool enabled)
125{
126 if (enabled == d->m_enabled)
127 return;
128
129 d->m_enabled = enabled;
130
131 d->m_item.setCheckState(enabled ? Qt::Checked : Qt::Unchecked);
132
133 Q_EMIT enabledChanged(enabled);
134}
135
136void RenderPlugin::setVisible(bool visible)
137{
138 if (visible == d->m_visible)
139 return;
140
141 d->m_visible = visible;
142
143 Q_EMIT visibilityChanged(visible, nameId());
144}
145
146void RenderPlugin::setUserCheckable(bool checkable)
147{
148 if (checkable != d->m_userCheckable) {
149 d->m_action.setEnabled(checkable);
150 d->m_userCheckable = checkable;
151 Q_EMIT userCheckableChanged(checkable);
152 }
153}
154
155bool RenderPlugin::enabled() const
156{
157 return d->m_enabled;
158}
159
160bool RenderPlugin::visible() const
161{
162 return d->m_visible;
163}
164
165bool RenderPlugin::isUserCheckable() const
166{
167 return d->m_userCheckable;
168}
169
170QHash<QString, QVariant> RenderPlugin::settings() const
171{
173
174 result.insert(QStringLiteral("enabled"), enabled());
175 result.insert(QStringLiteral("visible"), visible());
176
177 return result;
178}
179
180void RenderPlugin::setSettings(const QHash<QString, QVariant> &settings)
181{
182 setEnabled(settings.value(QStringLiteral("enabled"), enabled()).toBool());
183 setVisible(settings.value(QStringLiteral("visible"), visible()).toBool());
184}
185
186RenderPlugin::RenderType RenderPlugin::renderType() const
187{
188 return UnknownRenderType;
189}
190
191RenderState RenderPlugin::renderState() const
192{
193 return RenderState(name());
194}
195
196QString RenderPlugin::runtimeTrace() const
197{
198 return name();
199}
200
201bool RenderPlugin::eventFilter(QObject *, QEvent *)
202{
203 return false;
204}
205
206void RenderPlugin::restoreDefaultSettings()
207{
208 setSettings(QHash<QString, QVariant>());
209}
210
211QStringList RenderPlugin::settingKeys() const
212{
213 return settings().keys();
214}
215
216bool RenderPlugin::setSetting(const QString &key, const QVariant &value)
217{
218 QHash<QString, QVariant> settings = this->settings();
219 if (settings.contains(key)) {
220 settings[key] = value;
221 setSettings(settings);
222 return true;
223 } else {
224 return false;
225 }
226}
227
228QVariant RenderPlugin::setting(const QString &name) const
229{
230 return settings().value(name, QVariant());
231}
232
233} // namespace Marble
234
235#include "moc_RenderPlugin.cpp"
This file contains the headers for MarbleModel.
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition MarbleModel.h:84
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 Sat Dec 21 2024 17:04:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.