• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • src
  • plugins
  • render
  • satellites
TrackerPluginModel.cpp
Go to the documentation of this file.
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 2011 Guillaume Martres <smarter@ubuntu.com>
9 //
10 
11 #include "TrackerPluginModel.h"
12 
13 #include "CacheStoragePolicy.h"
14 #include "HttpDownloadManager.h"
15 #include "GeoDataDocument.h"
16 #include "GeoDataPlacemark.h"
17 #include "GeoDataTreeModel.h"
18 #include "MarbleDebug.h"
19 #include "MarbleDirs.h"
20 #include "MarbleModel.h"
21 #include "TrackerPluginItem.h"
22 
23 #include <QTimer>
24 
25 namespace Marble
26 {
27 
28 class TrackerPluginModelPrivate
29 {
30 public:
31  TrackerPluginModelPrivate( TrackerPluginModel *parent, GeoDataTreeModel *treeModel )
32  : m_parent( parent ),
33  m_enabled( false ),
34  m_treeModel( treeModel ),
35  m_document( new GeoDataDocument() ),
36  m_storagePolicy( MarbleDirs::localPath() + "/cache/" ),
37  m_downloadManager( 0 )
38  {
39  }
40 
41  ~TrackerPluginModelPrivate()
42  {
43  delete m_document;
44  qDeleteAll( m_itemVector );
45  delete m_downloadManager;
46  }
47 
48  void downloaded(const QString &relativeUrlString, const QString &id)
49  {
50  Q_UNUSED( relativeUrlString );
51 
52  m_parent->parseFile( id, m_storagePolicy.data( id ) );
53  }
54 
55  void update()
56  {
57  foreach( TrackerPluginItem *item, m_itemVector ) {
58  item->update();
59  }
60  }
61 
62  void updateDocument()
63  {
64  // we cannot use ->clear() since its implementation
65  // will delete all items
66  foreach( TrackerPluginItem *item, m_itemVector ) {
67  int idx = m_document->childPosition( item->placemark() );
68  if( item->isEnabled() && idx == -1 ) {
69  m_document->append( item->placemark() );
70  }
71  if( !item->isEnabled() && idx > -1 ) {
72  m_document->remove( idx );
73  }
74  }
75  }
76 
77  TrackerPluginModel *m_parent;
78  bool m_enabled;
79  GeoDataTreeModel *m_treeModel;
80  GeoDataDocument *m_document;
81  CacheStoragePolicy m_storagePolicy;
82  HttpDownloadManager *m_downloadManager;
83  QVector<TrackerPluginItem *> m_itemVector;
84 };
85 
86 TrackerPluginModel::TrackerPluginModel( GeoDataTreeModel *treeModel )
87  : d( new TrackerPluginModelPrivate( this, treeModel ) )
88 {
89  d->m_document->setDocumentRole( TrackingDocument );
90  d->m_document->setName("Satellites");
91  if( d->m_enabled ) {
92  d->m_treeModel->addDocument( d->m_document );
93  }
94 
95  d->m_downloadManager = new HttpDownloadManager( &d->m_storagePolicy );
96  connect( d->m_downloadManager, SIGNAL(downloadComplete(QString,QString)),
97  this, SLOT(downloaded(QString,QString)) );
98 }
99 
100 TrackerPluginModel::~TrackerPluginModel()
101 {
102  if( d->m_enabled ) {
103  d->m_treeModel->removeDocument( d->m_document );
104  }
105  delete d;
106 }
107 
108 void TrackerPluginModel::enable( bool enabled )
109 {
110  if( enabled == d->m_enabled ) {
111  return;
112  }
113  if( enabled ) {
114  d->m_treeModel->addDocument( d->m_document );
115  } else {
116  d->m_treeModel->removeDocument( d->m_document );
117  }
118  d->m_enabled = enabled;
119 }
120 
121 void TrackerPluginModel::addItem( TrackerPluginItem *mark )
122 {
123  d->m_document->append( mark->placemark() );
124  d->m_itemVector.append( mark );
125 }
126 
127 QVector<TrackerPluginItem*> TrackerPluginModel::items() const
128 {
129  return d->m_itemVector;
130 }
131 
132 void TrackerPluginModel::clear()
133 {
134  beginUpdateItems();
135  qDeleteAll( d->m_itemVector );
136  d->m_itemVector.clear();
137  d->m_itemVector.squeeze();
138  d->m_document->clear();
139  endUpdateItems();
140 }
141 
142 void TrackerPluginModel::beginUpdateItems()
143 {
144  if( d->m_enabled ) {
145  d->m_treeModel->removeDocument( d->m_document );
146  }
147 
148  emit itemUpdateStarted();
149 }
150 
151 void TrackerPluginModel::endUpdateItems()
152 {
153  if( d->m_enabled ) {
154  d->updateDocument();
155  d->m_treeModel->addDocument( d->m_document );
156  }
157 
158  emit itemUpdateEnded();
159 }
160 
161 void TrackerPluginModel::downloadFile(const QUrl &url, const QString &id)
162 {
163  d->m_downloadManager->addJob( url, id, id, DownloadBrowse );
164 }
165 
166 void TrackerPluginModel::parseFile( const QString &id, const QByteArray &file )
167 {
168  Q_UNUSED( id );
169  Q_UNUSED( file );
170 }
171 
172 } // namespace Marble
173 
174 #include "TrackerPluginModel.moc"
Marble::TrackerPluginModel::itemUpdateEnded
void itemUpdateEnded()
GeoDataDocument.h
Marble::TrackerPluginModel::enable
void enable(bool enabled)
Definition: TrackerPluginModel.cpp:108
Marble::GeoDataTreeModel
The representation of GeoData in a model This class represents all available data given by kml-data f...
Definition: GeoDataTreeModel.h:32
QByteArray
MarbleModel.h
This file contains the headers for MarbleModel.
HttpDownloadManager.h
Marble::DownloadBrowse
Browsing mode, normal operation of Marble, like a web browser.
Definition: MarbleGlobal.h:166
MarbleDebug.h
Marble::TrackerPluginModel::parseFile
virtual void parseFile(const QString &id, const QByteArray &file)
This method is called whenever a file queued up for download by downloadFile() has finished downloadi...
Definition: TrackerPluginModel.cpp:166
CacheStoragePolicy.h
Marble::TrackingDocument
Definition: GeoDataDocument.h:43
Marble::TrackerPluginModel::itemUpdateStarted
void itemUpdateStarted()
MarbleDirs.h
Marble::TrackerPluginItem::placemark
GeoDataPlacemark * placemark()
Returns the wrapped placemark which will be displayed if this item is in a TrackerPluginModel.
Definition: TrackerPluginItem.cpp:49
Marble::TrackerPluginModel::items
QVector< TrackerPluginItem * > items() const
Return all available items.
Definition: TrackerPluginModel.cpp:127
Marble::TrackerPluginModel::endUpdateItems
void endUpdateItems()
End a series of add or remove items operations on the model.
Definition: TrackerPluginModel.cpp:151
Marble::TrackerPluginModel::~TrackerPluginModel
virtual ~TrackerPluginModel()
Definition: TrackerPluginModel.cpp:100
QString
GeoDataPlacemark.h
GeoDataTreeModel.h
Marble::TrackerPluginItem
Subclass this to represent items in your TrackerPluginModel.
Definition: TrackerPluginItem.h:29
QUrl
Marble::TrackerPluginModel::beginUpdateItems
void beginUpdateItems()
Begin a series of add or remove items operations on the model.
Definition: TrackerPluginModel.cpp:142
QVector
TrackerPluginItem.h
TrackerPluginModel.h
Marble::TrackerPluginModel::TrackerPluginModel
TrackerPluginModel(GeoDataTreeModel *treeModel)
Constructs a model with the given treeModel and pluginManager.
Definition: TrackerPluginModel.cpp:86
Marble::TrackerPluginModel::clear
void clear()
Remove all items from the model.
Definition: TrackerPluginModel.cpp:132
Marble::TrackerPluginModel::addItem
void addItem(TrackerPluginItem *mark)
Add the item mark to the model.
Definition: TrackerPluginModel.cpp:121
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Marble::TrackerPluginModel::downloadFile
void downloadFile(const QUrl &url, const QString &id)
Adds url to the download queue.
Definition: TrackerPluginModel.cpp:161
Marble::HttpDownloadManager
This class manages scheduled downloads.
Definition: HttpDownloadManager.h:44
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:42 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal