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 
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 setModel(AbstractDataPluginModel *model)
Set the model of the plugin.
AbstractDataPluginModel * model()
The abstract class that creates a renderable item.
Definition: RenderPlugin.h:38
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
void setNumberOfItems(quint32 number)
Set the number of items to be shown at the same time.
QStringList renderPosition() const override
Preferred level in the layer stack for the rendering.
RenderType renderType() const override
Function for returning the type of plugin this is for.
void setFavoriteItemsOnly(bool favoriteOnly)
Convenience method to set the favorite item state on the current model.
Layer of a GeoScene document.
Definition: GeoSceneLayer.h:28
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
int size() const const
A public class that controls what is visible in the viewport of a Marble map.
const T & at(int i) const const
Binds a QML item to a specific geodetic location in screen coordinates.
A painter that allows to draw geometric primitives on the map.
Definition: GeoPainter.h:88
QList< AbstractDataPluginItem * > whichItemAt(const QPoint &curpos)
This function returns all items at the position curpos.
RenderType
A Type of plugin.
Definition: RenderPlugin.h:54
QString renderPolicy() const override
Return how the plugin settings should be used.
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.
void restore()
void save()
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition: MarbleModel.h:86
An abstract data model (not based on QAbstractModel) for a AbstractDataPlugin.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sat Sep 23 2023 04:12:04 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.