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 "AbstractDataPluginModel.h"
11#include "AbstractDataPluginItem.h"
12#include "GeoPainter.h"
13#include "GeoSceneLayer.h"
14#include "MarbleModel.h"
15#include "ViewportParams.h"
16#include "MarbleDebug.h"
17
18// Qt
19#include <QTimer>
20#include <QRegion>
21
22namespace Marble
23{
24
25class AbstractDataPluginPrivate
26{
27 public:
28 AbstractDataPluginPrivate()
29 : m_model( nullptr ),
30 m_numberOfItems( 10 )
31 {
32 m_updateTimer.setSingleShot( true );
33 }
34
35 ~AbstractDataPluginPrivate() {
36 delete m_model;
37 }
38
40 quint32 m_numberOfItems;
41 QTimer m_updateTimer;
42};
43
44AbstractDataPlugin::AbstractDataPlugin( const MarbleModel *marbleModel )
45 : RenderPlugin( marbleModel ),
46 d( new AbstractDataPluginPrivate )
47{
48 connect( &d->m_updateTimer, SIGNAL(timeout()), this, SIGNAL(repaintNeeded()) );
49}
50
51AbstractDataPlugin::~AbstractDataPlugin()
52{
53 delete d;
54}
55
56bool AbstractDataPlugin::isInitialized() const
57{
58 return model() != nullptr;
59}
60
62{
63 return QStringList( name() );
64}
65
67{
68 return QString( "ALWAYS" );
69}
70
72{
73 return QStringList( "ALWAYS_ON_TOP" );
74}
75
77 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,
115 SLOT(favoriteItemsChanged(QStringList)) );
116 connect( d->m_model, SIGNAL(favoriteItemsOnlyChanged()), this,
117 SIGNAL(favoriteItemsOnlyChanged()) );
118
119 emit favoritesModelChanged();
120}
121
122quint32 AbstractDataPlugin::numberOfItems() const
123{
124 return d->m_numberOfItems;
125}
126
128{
129 bool changed = ( number != d->m_numberOfItems );
130 d->m_numberOfItems = number;
131
132 if ( changed )
133 emit changedNumberOfItems( number );
134}
135
137{
138 if ( d->m_model && enabled() && visible()) {
139 return d->m_model->whichItemAt( curpos );
140 }
141 else {
143 }
144}
145
147{
148 return OnlineRenderType;
149}
150
152{
153 if ( d->m_model && d->m_model->isFavoriteItemsOnly() != favoriteOnly ) {
154 d->m_model->setFavoriteItemsOnly( favoriteOnly );
155 }
156}
157
158bool AbstractDataPlugin::isFavoriteItemsOnly() const
159{
160 return d->m_model && d->m_model->isFavoriteItemsOnly();
161}
162
164{
165 return d->m_model ? d->m_model->favoritesModel() : nullptr;
166}
167
168void AbstractDataPlugin::favoriteItemsChanged( const QStringList& favoriteItems )
169{
170 Q_UNUSED( favoriteItems )
171}
172
173void AbstractDataPlugin::delayedUpdate()
174{
175 if ( !d->m_updateTimer.isActive() )
176 {
177 d->m_updateTimer.start( 500 );
178 }
179}
180
181} // namespace Marble
182
183#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:89
Layer of a GeoScene document.
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition MarbleModel.h:87
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
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 Jul 12 2024 11:58:54 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.