Marble

AbstractDataPlugin.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2009 Bastian Holst <bastianholst@gmx.de>
4//
5
6// Self
7#include "AbstractDataPlugin.h"
8
9// Marble
10#include "AbstractDataPluginItem.h"
11#include "AbstractDataPluginModel.h"
12#include "GeoPainter.h"
13#include "GeoSceneLayer.h"
14#include "MarbleDebug.h"
15#include "MarbleModel.h"
16#include "ViewportParams.h"
17
18// Qt
19#include <QRegion>
20#include <QTimer>
21
22namespace Marble
23{
24
25class AbstractDataPluginPrivate
26{
27public:
28 AbstractDataPluginPrivate()
29 : m_model(nullptr)
30 , m_numberOfItems(10)
31 {
32 m_updateTimer.setSingleShot(true);
33 }
34
35 ~AbstractDataPluginPrivate()
36 {
37 delete m_model;
38 }
39
40 AbstractDataPluginModel *m_model = nullptr;
41 quint32 m_numberOfItems;
42 QTimer m_updateTimer;
43};
44
45AbstractDataPlugin::AbstractDataPlugin(const MarbleModel *marbleModel)
46 : RenderPlugin(marbleModel)
47 , d(new AbstractDataPluginPrivate)
48{
49 connect(&d->m_updateTimer, SIGNAL(timeout()), this, SIGNAL(repaintNeeded()));
50}
51
52AbstractDataPlugin::~AbstractDataPlugin()
53{
54 delete d;
55}
56
57bool AbstractDataPlugin::isInitialized() const
58{
59 return model() != nullptr;
60}
61
63{
64 return QStringList(name());
65}
66
68{
69 return QStringLiteral("ALWAYS");
70}
71
73{
74 return QStringList(QStringLiteral("ALWAYS_ON_TOP"));
75}
76
77bool AbstractDataPlugin::render(GeoPainter *painter, ViewportParams *viewport, const QString &renderPos, GeoSceneLayer *layer)
78{
79 Q_UNUSED(renderPos);
80 Q_UNUSED(layer);
81
82 QList<AbstractDataPluginItem *> items = d->m_model->items(viewport, numberOfItems());
83 painter->save();
84
85 // Paint the most important item at last
86 for (int i = items.size() - 1; i >= 0; --i) {
87 items.at(i)->paintEvent(painter, viewport);
88 }
89
90 painter->restore();
91
92 return true;
93}
94
96{
97 return d->m_model;
98}
99
101{
102 return d->m_model;
103}
104
106{
107 if (d->m_model) {
108 disconnect(d->m_model, SIGNAL(itemsUpdated()), this, SLOT(delayedUpdate()));
109 delete d->m_model;
110 }
111 d->m_model = model;
112
113 connect(d->m_model, SIGNAL(itemsUpdated()), this, SLOT(delayedUpdate()));
114 connect(d->m_model, SIGNAL(favoriteItemsChanged(QStringList)), this, SLOT(favoriteItemsChanged(QStringList)));
115 connect(d->m_model, SIGNAL(favoriteItemsOnlyChanged()), this, SIGNAL(favoriteItemsOnlyChanged()));
116
117 Q_EMIT favoritesModelChanged();
118}
119
120quint32 AbstractDataPlugin::numberOfItems() const
121{
122 return d->m_numberOfItems;
123}
124
126{
127 bool changed = (number != d->m_numberOfItems);
128 d->m_numberOfItems = number;
129
130 if (changed)
131 Q_EMIT changedNumberOfItems(number);
132}
133
135{
136 if (d->m_model && enabled() && visible()) {
137 return d->m_model->whichItemAt(curpos);
138 } else {
139 return {};
140 }
141}
142
144{
145 return OnlineRenderType;
146}
147
149{
150 if (d->m_model && d->m_model->isFavoriteItemsOnly() != favoriteOnly) {
151 d->m_model->setFavoriteItemsOnly(favoriteOnly);
152 }
153}
154
155bool AbstractDataPlugin::isFavoriteItemsOnly() const
156{
157 return d->m_model && d->m_model->isFavoriteItemsOnly();
158}
159
161{
162 return d->m_model ? d->m_model->favoritesModel() : nullptr;
163}
164
165void AbstractDataPlugin::favoriteItemsChanged(const QStringList &favoriteItems)
166{
167 Q_UNUSED(favoriteItems)
168}
169
170void AbstractDataPlugin::delayedUpdate()
171{
172 if (!d->m_updateTimer.isActive()) {
173 d->m_updateTimer.start(500);
174 }
175}
176
177} // namespace Marble
178
179#include "moc_AbstractDataPlugin.cpp"
This file contains the headers for MarbleModel.
This file contains the headers for ViewportParams.
An abstract data model (not based on QAbstractModel) for a AbstractDataPlugin.
QList< AbstractDataPluginItem * > whichItemAt(const QPoint &curpos)
Get all items that contain the given point Returns a list of all items that contain the point curpos.
QList< AbstractDataPluginItem * > items(const ViewportParams *viewport, qint32 number=10)
Get the items on the viewport Returns the currently downloaded images in the viewport.
QList< AbstractDataPluginItem * > whichItemAt(const QPoint &curpos)
This function returns all items at the position curpos.
void setFavoriteItemsOnly(bool favoriteOnly)
Convenience method to set the favorite item state on the current model.
QStringList backendTypes() const override
Returns the name(s) of the backend that the plugin can render.
bool render(GeoPainter *painter, ViewportParams *viewport, const QString &renderPos=QLatin1String("NONE"), GeoSceneLayer *layer=nullptr) override
Renders the content provided by the plugin on the viewport.
AbstractDataPluginModel * model()
void setNumberOfItems(quint32 number)
Set the number of items to be shown at the same time.
RenderType renderType() const override
Function for returning the type of plugin this is for.
QStringList renderPosition() const override
Preferred level in the layer stack for the rendering.
QString renderPolicy() const override
Return how the plugin settings should be used.
void setModel(AbstractDataPluginModel *model)
Set the model of the plugin.
A painter that allows to draw geometric primitives on the map.
Definition GeoPainter.h:86
Layer of a GeoScene document.
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition MarbleModel.h:84
The abstract class that creates a renderable item.
RenderType
A Type of plugin.
A public class that controls what is visible in the viewport of a Marble map.
Binds a QML item to a specific geodetic location in screen coordinates.
const_reference at(qsizetype i) const const
qsizetype size() const const
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
void restore()
void save()
bool isActive() const const
void setSingleShot(bool singleShot)
void start()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 12:02:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.