Marble

AbstractDataPlugin.cpp
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2009 Bastian Holst <[email protected]>
9 //
10 
11 // Self
12 #include "AbstractDataPlugin.h"
13 
14 // Marble
15 #include "AbstractDataPluginModel.h"
16 #include "AbstractDataPluginItem.h"
17 #include "GeoPainter.h"
18 #include "GeoSceneLayer.h"
19 #include "MarbleModel.h"
20 #include "ViewportParams.h"
21 #include "MarbleDebug.h"
22 
23 // Qt
24 #include <QTimer>
25 #include <QRegion>
26 
27 namespace Marble
28 {
29 
30 class AbstractDataPluginPrivate
31 {
32  public:
33  AbstractDataPluginPrivate()
34  : m_model( nullptr ),
35  m_numberOfItems( 10 )
36  {
37  m_updateTimer.setSingleShot( true );
38  }
39 
40  ~AbstractDataPluginPrivate() {
41  delete m_model;
42  }
43 
44  AbstractDataPluginModel *m_model;
45  quint32 m_numberOfItems;
46  QTimer m_updateTimer;
47 };
48 
49 AbstractDataPlugin::AbstractDataPlugin( const MarbleModel *marbleModel )
50  : RenderPlugin( marbleModel ),
51  d( new AbstractDataPluginPrivate )
52 {
53  connect( &d->m_updateTimer, SIGNAL(timeout()), this, SIGNAL(repaintNeeded()) );
54 }
55 
56 AbstractDataPlugin::~AbstractDataPlugin()
57 {
58  delete d;
59 }
60 
61 bool AbstractDataPlugin::isInitialized() const
62 {
63  return model() != nullptr;
64 }
65 
67 {
68  return QStringList( name() );
69 }
70 
72 {
73  return QString( "ALWAYS" );
74 }
75 
77 {
78  return QStringList( "ALWAYS_ON_TOP" );
79 }
80 
82  const QString& renderPos, GeoSceneLayer * layer)
83 {
84  Q_UNUSED( renderPos );
85  Q_UNUSED( layer );
86 
87  QList<AbstractDataPluginItem*> items = d->m_model->items( viewport, numberOfItems() );
88  painter->save();
89 
90  // Paint the most important item at last
91  for( int i = items.size() - 1; i >= 0; --i ) {
92  items.at( i )->paintEvent( painter, viewport );
93  }
94 
95  painter->restore();
96 
97  return true;
98 }
99 
101 {
102  return d->m_model;
103 }
104 
106 {
107  return d->m_model;
108 }
109 
111 {
112  if ( d->m_model ) {
113  disconnect( d->m_model, SIGNAL(itemsUpdated()), this, SLOT(delayedUpdate()) );
114  delete d->m_model;
115  }
116  d->m_model = model;
117 
118  connect( d->m_model, SIGNAL(itemsUpdated()), this, SLOT(delayedUpdate()) );
119  connect( d->m_model, SIGNAL(favoriteItemsChanged(QStringList)), this,
120  SLOT(favoriteItemsChanged(QStringList)) );
121  connect( d->m_model, SIGNAL(favoriteItemsOnlyChanged()), this,
122  SIGNAL(favoriteItemsOnlyChanged()) );
123 
124  emit favoritesModelChanged();
125 }
126 
127 quint32 AbstractDataPlugin::numberOfItems() const
128 {
129  return d->m_numberOfItems;
130 }
131 
133 {
134  bool changed = ( number != d->m_numberOfItems );
135  d->m_numberOfItems = number;
136 
137  if ( changed )
138  emit changedNumberOfItems( number );
139 }
140 
142 {
143  if ( d->m_model && enabled() && visible()) {
144  return d->m_model->whichItemAt( curpos );
145  }
146  else {
148  }
149 }
150 
152 {
153  return OnlineRenderType;
154 }
155 
157 {
158  if ( d->m_model && d->m_model->isFavoriteItemsOnly() != favoriteOnly ) {
159  d->m_model->setFavoriteItemsOnly( favoriteOnly );
160  }
161 }
162 
163 bool AbstractDataPlugin::isFavoriteItemsOnly() const
164 {
165  return d->m_model && d->m_model->isFavoriteItemsOnly();
166 }
167 
168 QObject *AbstractDataPlugin::favoritesModel()
169 {
170  return d->m_model ? d->m_model->favoritesModel() : nullptr;
171 }
172 
173 void AbstractDataPlugin::favoriteItemsChanged( const QStringList& favoriteItems )
174 {
175  Q_UNUSED( favoriteItems )
176 }
177 
178 void AbstractDataPlugin::delayedUpdate()
179 {
180  if ( !d->m_updateTimer.isActive() )
181  {
182  d->m_updateTimer.start( 500 );
183  }
184 }
185 
186 } // namespace Marble
187 
188 #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:93
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.
int size() const const
quint32 numberOfItems() const
Layer of a GeoScene document.
Definition: GeoSceneLayer.h:43
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:91
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:59
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:43
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Nov 30 2020 23:21:12 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.