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

marble

  • sources
  • kde-4.12
  • 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  {
38  }
39 
40  ~TrackerPluginModelPrivate()
41  {
42  delete m_document;
43  qDeleteAll( m_itemVector );
44  delete m_downloadManager;
45  }
46 
47  void downloaded(const QString &relativeUrlString, const QString &id)
48  {
49  Q_UNUSED( relativeUrlString );
50 
51  m_parent->parseFile( id, m_storagePolicy.data( id ) );
52  }
53 
54  void update()
55  {
56  foreach( TrackerPluginItem *item, m_itemVector ) {
57  item->update();
58  }
59  }
60 
61  void updateDocument()
62  {
63  // we cannot use ->clear() since its implementation
64  // will delete all items
65  foreach( TrackerPluginItem *item, m_itemVector ) {
66  int idx = m_document->childPosition( item->placemark() );
67  if( item->isEnabled() && idx == -1 ) {
68  m_document->append( item->placemark() );
69  }
70  if( !item->isEnabled() && idx > -1 ) {
71  m_document->remove( idx );
72  }
73  }
74  }
75 
76  TrackerPluginModel *m_parent;
77  bool m_enabled;
78  GeoDataTreeModel *m_treeModel;
79  GeoDataDocument *m_document;
80  CacheStoragePolicy m_storagePolicy;
81  HttpDownloadManager *m_downloadManager;
82  QVector<TrackerPluginItem *> m_itemVector;
83 };
84 
85 TrackerPluginModel::TrackerPluginModel( GeoDataTreeModel *treeModel )
86  : d( new TrackerPluginModelPrivate( this, treeModel ) )
87 {
88  d->m_document->setDocumentRole( TrackingDocument );
89  d->m_document->setName("Satellites");
90  if( d->m_enabled ) {
91  d->m_treeModel->addDocument( d->m_document );
92  }
93 
94  d->m_downloadManager = new HttpDownloadManager( &d->m_storagePolicy );
95  connect( d->m_downloadManager, SIGNAL(downloadComplete(QString,QString)),
96  this, SLOT(downloaded(QString,QString)) );
97 }
98 
99 TrackerPluginModel::~TrackerPluginModel()
100 {
101  if( d->m_enabled ) {
102  d->m_treeModel->removeDocument( d->m_document );
103  }
104  delete d;
105 }
106 
107 void TrackerPluginModel::enable( bool enabled )
108 {
109  if( enabled == d->m_enabled ) {
110  return;
111  }
112  if( enabled ) {
113  d->m_treeModel->addDocument( d->m_document );
114  } else {
115  d->m_treeModel->removeDocument( d->m_document );
116  }
117  d->m_enabled = enabled;
118 }
119 
120 void TrackerPluginModel::addItem( TrackerPluginItem *mark )
121 {
122  d->m_document->append( mark->placemark() );
123  d->m_itemVector.append( mark );
124 }
125 
126 QVector<TrackerPluginItem*> TrackerPluginModel::items() const
127 {
128  return d->m_itemVector;
129 }
130 
131 void TrackerPluginModel::clear()
132 {
133  beginUpdateItems();
134  qDeleteAll( d->m_itemVector );
135  d->m_itemVector.clear();
136  d->m_itemVector.squeeze();
137  d->m_document->clear();
138  endUpdateItems();
139 }
140 
141 void TrackerPluginModel::beginUpdateItems()
142 {
143  if( d->m_enabled ) {
144  d->m_treeModel->removeDocument( d->m_document );
145  }
146 
147  emit itemUpdateStarted();
148 }
149 
150 void TrackerPluginModel::endUpdateItems()
151 {
152  if( d->m_enabled ) {
153  d->updateDocument();
154  d->m_treeModel->addDocument( d->m_document );
155  }
156 
157  emit itemUpdateEnded();
158 }
159 
160 void TrackerPluginModel::loadSettings( const QHash<QString, QVariant> &settings )
161 {
162  Q_UNUSED( settings );
163 }
164 
165 void TrackerPluginModel::downloadFile(const QUrl &url, const QString &id)
166 {
167  d->m_downloadManager->addJob( url, id, id, DownloadBrowse );
168 }
169 
170 void TrackerPluginModel::parseFile( const QString &id, const QByteArray &file )
171 {
172  Q_UNUSED( id );
173  Q_UNUSED( file );
174 }
175 
176 } // namespace Marble
177 
178 #include "TrackerPluginModel.moc"
Marble::TrackerPluginModel::itemUpdateEnded
void itemUpdateEnded()
GeoDataDocument.h
Marble::TrackerPluginModel::enable
void enable(bool enabled)
Definition: TrackerPluginModel.cpp:107
Marble::GeoDataTreeModel
The representation of GeoData in a model This class represents all available data given by kml-data f...
Definition: GeoDataTreeModel.h:32
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:162
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:170
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:40
Marble::TrackerPluginModel::items
QVector< TrackerPluginItem * > items() const
Return all available items.
Definition: TrackerPluginModel.cpp:126
Marble::TrackerPluginModel::endUpdateItems
void endUpdateItems()
End a series of add or remove items operations on the model.
Definition: TrackerPluginModel.cpp:150
Marble::TrackerPluginModel::~TrackerPluginModel
virtual ~TrackerPluginModel()
Definition: TrackerPluginModel.cpp:99
GeoDataPlacemark.h
GeoDataTreeModel.h
Marble::TrackerPluginItem
Subclass this to represent items in your TrackerPluginModel.
Definition: TrackerPluginItem.h:29
Marble::TrackerPluginModel::beginUpdateItems
void beginUpdateItems()
Begin a series of add or remove items operations on the model.
Definition: TrackerPluginModel.cpp:141
TrackerPluginItem.h
TrackerPluginModel.h
Marble::TrackerPluginModel::loadSettings
void loadSettings(const QHash< QString, QVariant > &settings)
Load settings.
Definition: TrackerPluginModel.cpp:160
Marble::TrackerPluginModel::TrackerPluginModel
TrackerPluginModel(GeoDataTreeModel *treeModel)
Constructs a model with the given treeModel and pluginManager.
Definition: TrackerPluginModel.cpp:85
Marble::TrackerPluginModel::clear
void clear()
Remove all items from the model.
Definition: TrackerPluginModel.cpp:131
Marble::TrackerPluginModel::addItem
void addItem(TrackerPluginItem *mark)
Add the item mark to the model.
Definition: TrackerPluginModel.cpp:120
Marble::TrackerPluginModel::downloadFile
void downloadFile(const QUrl &url, const QString &id)
Adds url to the download queue.
Definition: TrackerPluginModel.cpp:165
Marble::HttpDownloadManager
This class manages scheduled downloads.
Definition: HttpDownloadManager.h:44
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:53 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
  • kstars
  • libkdeedu
  •   keduvocdocument
  • 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