• 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
  • weather
WeatherModel.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 2009 Bastian Holst <bastianholst@gmx.de>
9 //
10 
11 // Self
12 #include "WeatherModel.h"
13 
14 // Qt
15 #include <QTimer>
16 #include <QUrl>
17 
18 // Marble
19 #include "BBCWeatherService.h"
20 #include "FakeWeatherService.h"
21 #include "GeoNamesWeatherService.h"
22 #include "AbstractDataPluginItem.h"
23 #include "WeatherItem.h"
24 #include "MarbleDebug.h"
25 #include "MarbleModel.h"
26 
27 using namespace Marble;
28 
29 WeatherModel::WeatherModel( const MarbleModel *marbleModel, QObject *parent )
30  : AbstractDataPluginModel( "weather", marbleModel, parent )
31 {
32  registerItemProperties( WeatherItem::staticMetaObject );
33 
34  // addService( new FakeWeatherService( marbleModel(), this ) );
35  addService( new BBCWeatherService( marbleModel, this ) );
36  addService( new GeoNamesWeatherService( marbleModel, this ) );
37 
38  m_timer = new QTimer();
39  connect( m_timer, SIGNAL(timeout()), SLOT(clear()) );
40 
41  // Default interval = 3 hours
42  setUpdateInterval( 3 );
43 
44  m_timer->start();
45 }
46 
47 WeatherModel::~WeatherModel()
48 {
49 }
50 
51 void WeatherModel::setFavoriteItems( const QStringList& list )
52 {
53  if ( favoriteItems() != list ) {
54  foreach ( AbstractWeatherService *service, m_services ) {
55  service->setFavoriteItems( list );
56  }
57 
58  AbstractDataPluginModel::setFavoriteItems( list );
59  }
60 }
61 
62 void WeatherModel::setUpdateInterval( quint32 hours )
63 {
64  quint32 msecs = hours * 60 * 60 * 1000;
65  m_timer->setInterval( msecs );
66 }
67 
68 void WeatherModel::downloadItemData( const QUrl& url,
69  const QString& type,
70  AbstractDataPluginItem *item )
71 {
72  AbstractDataPluginItem *existingItem = findItem( item->id() );
73  if ( !existingItem ) {
74  WeatherItem *weatherItem = qobject_cast<WeatherItem*>( item );
75  if( weatherItem ) {
76  weatherItem->request( type );
77  }
78 
79  downloadItem( url, type, item );
80  addItemToList( item );
81  } else {
82  if ( existingItem != item )
83  item->deleteLater();
84 
85  WeatherItem *existingWeatherItem = qobject_cast<WeatherItem*>( existingItem );
86  if( existingWeatherItem && existingWeatherItem->request( type ) ) {
87  downloadItem( url, type, existingItem );
88  addItemToList( existingItem );
89  }
90  }
91 }
92 
93 void WeatherModel::getAdditionalItems( const GeoDataLatLonAltBox& box,
94  qint32 number )
95 {
96  emit additionalItemsRequested( box, number );
97 }
98 
99 void WeatherModel::getItem( const QString &id )
100 {
101  foreach( AbstractWeatherService* service, m_services ) {
102  service->getItem( id );
103  }
104 }
105 
106 void WeatherModel::parseFile( const QByteArray& file )
107 {
108  emit parseFileRequested( file );
109 }
110 
111 void WeatherModel::downloadDescriptionFileRequested( const QUrl& url )
112 {
113  downloadDescriptionFile( url );
114 }
115 
116 void WeatherModel::setMarbleWidget(MarbleWidget *widget)
117 {
118  foreach ( AbstractWeatherService* service, m_services ) {
119  service->setMarbleWidget( widget );
120  }
121 }
122 
123 void WeatherModel::addService( AbstractWeatherService *service )
124 {
125  service->setFavoriteItems( favoriteItems() );
126 
127  connect( service, SIGNAL(createdItems(QList<AbstractDataPluginItem*>)),
128  this, SLOT(addItemsToList(QList<AbstractDataPluginItem*>)) );
129  connect( service, SIGNAL(requestedDownload(QUrl,QString,AbstractDataPluginItem*)),
130  this, SLOT(downloadItemData(QUrl,QString,AbstractDataPluginItem*)) );
131  connect( service, SIGNAL(downloadDescriptionFileRequested(QUrl)),
132  this, SLOT(downloadDescriptionFileRequested(QUrl)) );
133 
134  connect( this, SIGNAL(additionalItemsRequested(GeoDataLatLonAltBox,qint32)),
135  service, SLOT(getAdditionalItems(GeoDataLatLonAltBox,qint32)) );
136  connect( this, SIGNAL(parseFileRequested(QByteArray)),
137  service, SLOT(parseFile(QByteArray)) );
138 
139  m_services.append( service );
140 }
141 
142 #include "WeatherModel.moc"
QTimer::setInterval
void setInterval(int msec)
Marble::BBCWeatherService
Definition: BBCWeatherService.h:26
Marble::GeoNamesWeatherService
Definition: GeoNamesWeatherService.h:22
Marble::WeatherModel::downloadItemData
void downloadItemData(const QUrl &url, const QString &type, AbstractDataPluginItem *item)
Downloads the file from url.
Definition: WeatherModel.cpp:68
QByteArray
Marble::AbstractDataPluginItem
Definition: AbstractDataPluginItem.h:28
Marble::AbstractDataPluginModel::setFavoriteItems
virtual void setFavoriteItems(const QStringList &list)
Definition: AbstractDataPluginModel.cpp:466
Marble::WeatherModel::setMarbleWidget
void setMarbleWidget(MarbleWidget *widget)
Definition: WeatherModel.cpp:116
MarbleModel.h
This file contains the headers for MarbleModel.
WeatherModel.h
Marble::AbstractWeatherService
Definition: AbstractWeatherService.h:27
Marble::AbstractDataPluginModel
An abstract data model (not based on QAbstractModel) for a AbstractDataPlugin.
Definition: AbstractDataPluginModel.h:45
FakeWeatherService.h
Marble::AbstractWeatherService::setMarbleWidget
void setMarbleWidget(MarbleWidget *widget)
Definition: AbstractWeatherService.cpp:29
MarbleDebug.h
Marble::AbstractDataPluginItem::id
QString id() const
Definition: AbstractDataPluginItem.cpp:81
Marble::MarbleWidget
A widget class that displays a view of the earth.
Definition: MarbleWidget.h:104
Marble::WeatherModel::WeatherModel
WeatherModel(const MarbleModel *marbleModel, QObject *parent)
Definition: WeatherModel.cpp:29
Marble::WeatherModel::getItem
virtual void getItem(const QString &id)
Retrieve data for a specific item.
Definition: WeatherModel.cpp:99
Marble::AbstractDataPluginModel::downloadDescriptionFile
void downloadDescriptionFile(const QUrl &url)
Download the description file from the url.
Definition: AbstractDataPluginModel.cpp:392
Marble::WeatherModel::~WeatherModel
~WeatherModel()
Definition: WeatherModel.cpp:47
Marble::AbstractDataPluginModel::clear
void clear()
Removes all items.
Definition: AbstractDataPluginModel.cpp:663
QTimer
QObject
Marble::WeatherItem::request
virtual bool request(const QString &type)
Test if the item wants to request type again.
Definition: WeatherItem.cpp:354
Marble::AbstractWeatherService::setFavoriteItems
virtual void setFavoriteItems(const QStringList &favorite)
Definition: AbstractWeatherService.cpp:44
Marble::WeatherModel::parseFile
void parseFile(const QByteArray &file)
Parse the file and generate items.
Definition: WeatherModel.cpp:106
QObject::deleteLater
void deleteLater()
QString
QList< AbstractDataPluginItem * >
Marble::AbstractDataPluginModel::findItem
AbstractDataPluginItem * findItem(const QString &id) const
Finds the item with id in the list.
Definition: AbstractDataPluginModel.cpp:552
Marble::WeatherModel::getAdditionalItems
void getAdditionalItems(const GeoDataLatLonAltBox &box, qint32 number=10)
Managing to get number additional items in box.
Definition: WeatherModel.cpp:93
BBCWeatherService.h
QStringList
Marble::WeatherModel::setUpdateInterval
void setUpdateInterval(quint32 hours)
Definition: WeatherModel.cpp:62
QUrl
Marble::WeatherModel::downloadDescriptionFileRequested
void downloadDescriptionFileRequested(const QUrl &url)
Definition: WeatherModel.cpp:111
Marble::AbstractDataPluginModel::registerItemProperties
void registerItemProperties(const QMetaObject &item)
Definition: AbstractDataPluginModel.cpp:675
Marble::MarbleModel
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition: MarbleModel.h:97
Marble::WeatherModel::setFavoriteItems
void setFavoriteItems(const QStringList &list)
Definition: WeatherModel.cpp:51
Marble::AbstractDataPluginModel::favoriteItems
QStringList favoriteItems() const
Definition: AbstractDataPluginModel.cpp:478
Marble::AbstractWeatherService::getItem
virtual void getItem(const QString &id)=0
QTimer::start
void start(int msec)
Marble::AbstractDataPluginModel::addItemToList
void addItemToList(AbstractDataPluginItem *item)
Convenience method to add one item to the list.
Definition: AbstractDataPluginModel.cpp:403
GeoNamesWeatherService.h
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Marble::WeatherModel::parseFileRequested
void parseFileRequested(const QByteArray &file)
Marble::WeatherItem
This is the class painting a weather item on the screen.
Definition: WeatherItem.h:37
Marble::AbstractDataPluginModel::downloadItem
void downloadItem(const QUrl &url, const QString &type, AbstractDataPluginItem *item)
Downloads the file from url.
Definition: AbstractDataPluginModel.cpp:378
Marble::GeoDataLatLonAltBox
A class that defines a 3D bounding box for geographic data.
Definition: GeoDataLatLonAltBox.h:49
Marble::WeatherModel::additionalItemsRequested
void additionalItemsRequested(const GeoDataLatLonAltBox &, qint32 number)
AbstractDataPluginItem.h
WeatherItem.h
Marble::AbstractDataPluginModel::addItemsToList
void addItemsToList(const QList< AbstractDataPluginItem * > &items)
Adds the items to the list of initialized items.
Definition: AbstractDataPluginModel.cpp:408
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