Marble

AbstractDataPlugin.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2009 Bastian Holst <[email protected]>
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 
22 namespace Marble
23 {
24 
25 class 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 
39  AbstractDataPluginModel *m_model;
40  quint32 m_numberOfItems;
41  QTimer m_updateTimer;
42 };
43 
44 AbstractDataPlugin::AbstractDataPlugin( const MarbleModel *marbleModel )
45  : RenderPlugin( marbleModel ),
46  d( new AbstractDataPluginPrivate )
47 {
48  connect( &d->m_updateTimer, SIGNAL(timeout()), this, SIGNAL(repaintNeeded()) );
49 }
50 
51 AbstractDataPlugin::~AbstractDataPlugin()
52 {
53  delete d;
54 }
55 
56 bool 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 
122 quint32 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 
158 bool AbstractDataPlugin::isFavoriteItemsOnly() const
159 {
160  return d->m_model && d->m_model->isFavoriteItemsOnly();
161 }
162 
163 QObject *AbstractDataPlugin::favoritesModel()
164 {
165  return d->m_model ? d->m_model->favoritesModel() : nullptr;
166 }
167 
168 void AbstractDataPlugin::favoriteItemsChanged( const QStringList& favoriteItems )
169 {
170  Q_UNUSED( favoriteItems )
171 }
172 
173 void 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"
void setNumberOfItems(quint32 number)
Set the number of items to be shown at the same time.
A painter that allows to draw geometric primitives on the map.
Definition: GeoPainter.h:88
Binds a QML item to a specific geodetic location in screen coordinates.
This file contains the headers for MarbleModel.
const T & at(int i) const const
void save()
void setFavoriteItemsOnly(bool favoriteOnly)
Convenience method to set the favorite item state on the current model.
An abstract data model (not based on QAbstractModel) for a AbstractDataPlugin.
const QLatin1String name
int size() const const
quint32 numberOfItems() const
Layer of a GeoScene document.
Definition: GeoSceneLayer.h:28
void setModel(AbstractDataPluginModel *model)
Set the model of the plugin.
QList< AbstractDataPluginItem * > whichItemAt(const QPoint &curpos)
This function returns all items at the position curpos.
A public class that controls what is visible in the viewport of a Marble map.
RenderType renderType() const override
Function for returning the type of plugin this is for.
This file contains the headers for ViewportParams.
void restore()
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition: MarbleModel.h:86
QString renderPolicy() const override
Return how the plugin settings should be used.
QStringList renderPosition() const override
Preferred level in the layer stack for the rendering.
QStringList backendTypes() const override
Returns the name(s) of the backend that the plugin can render.
RenderType
A Type of plugin.
Definition: RenderPlugin.h:54
AbstractDataPluginModel * model()
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.
The abstract class that creates a renderable item.
Definition: RenderPlugin.h:38
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue Jan 25 2022 23:11:35 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.