• 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
BBCItemGetter.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 "BBCItemGetter.h"
13 #include "BBCStation.h"
14 #include "BBCWeatherItem.h"
15 #include "MarbleDebug.h"
16 
17 // Qt
18 #include <QMutexLocker>
19 #include <QUrl>
20 
21 using namespace Marble;
22 
23 BBCItemGetter::BBCItemGetter( QObject *parent )
24  : AbstractWorkerThread( parent ),
25  m_scheduleMutex(),
26  m_scheduledNumber( 0 )
27 {
28 }
29 
30 BBCItemGetter::~BBCItemGetter()
31 {
32 }
33 
34 void BBCItemGetter::setSchedule( const GeoDataLatLonAltBox& box,
35  qint32 number )
36 {
37  m_scheduleMutex.lock();
38  m_scheduledBox = box;
39  m_scheduledNumber = number;
40  m_scheduleMutex.unlock();
41  ensureRunning();
42 }
43 
44 void BBCItemGetter::setStationList( const QList<BBCStation>& items )
45 {
46  m_items = items;
47  ensureRunning();
48 }
49 
50 BBCStation BBCItemGetter::station( const QString &id )
51 {
52  QString const bbcIdTemplate = QString( "bbc%1" );
53  foreach( const BBCStation &station, m_items ) {
54  if ( bbcIdTemplate.arg( station.bbcId() ) == id ) {
55  return station;
56  }
57  }
58 
59  return BBCStation();
60 }
61 
62 bool BBCItemGetter::workAvailable()
63 {
64  return !m_scheduledBox.isNull()
65  && m_scheduledNumber;
66 
67 }
68 
69 void BBCItemGetter::work()
70 {
71  if ( m_items.isEmpty() ) {
72  sleep( 1 );
73  return;
74  }
75 
76  m_scheduleMutex.lock();
77  GeoDataLatLonAltBox box = m_scheduledBox;
78  qint32 number = m_scheduledNumber;
79  m_scheduledBox = GeoDataLatLonAltBox();
80  m_scheduledNumber = 0;
81  m_scheduleMutex.unlock();
82 
83  qint32 fetched = 0;
84  QList<BBCStation>::ConstIterator it = m_items.constBegin();
85  QList<BBCStation>::ConstIterator end = m_items.constEnd();
86 
87  while ( fetched < number && it != end ) {
88  if ( box.contains( it->coordinate() ) ) {
89  emit foundStation( (*it) );
90  fetched++;
91  }
92  ++it;
93  }
94 }
95 
96 #include "BBCItemGetter.moc"
Marble::BBCItemGetter::m_items
QList< BBCStation > m_items
Definition: BBCItemGetter.h:52
Marble::BBCItemGetter::setSchedule
void setSchedule(const GeoDataLatLonAltBox &box, qint32 number)
Definition: BBCItemGetter.cpp:34
QThread::sleep
void sleep(unsigned long secs)
Marble::BBCItemGetter::foundStation
void foundStation(BBCStation)
Marble::BBCItemGetter::m_scheduledBox
GeoDataLatLonAltBox m_scheduledBox
Definition: BBCItemGetter.h:54
BBCWeatherItem.h
Marble::BBCItemGetter::work
void work()
Definition: BBCItemGetter.cpp:69
QMutex::unlock
void unlock()
Marble::GeoDataLatLonAltBox::contains
virtual bool contains(const GeoDataCoordinates &) const
Definition: GeoDataLatLonAltBox.cpp:170
MarbleDebug.h
BBCStation.h
Marble::GeoDataLatLonAltBox::isNull
bool isNull() const
Indicates whether the bounding box only contains a single 2D point ("singularity").
Definition: GeoDataLatLonAltBox.cpp:275
Marble::BBCItemGetter::m_scheduleMutex
QMutex m_scheduleMutex
Definition: BBCItemGetter.h:53
QObject
Marble::BBCStation::bbcId
quint32 bbcId() const
Definition: BBCStation.cpp:116
QString
QList
Marble::BBCItemGetter::workAvailable
bool workAvailable()
Definition: BBCItemGetter.cpp:62
Marble::BBCItemGetter::setStationList
void setStationList(const QList< BBCStation > &items)
Definition: BBCItemGetter.cpp:44
QMutex::lock
void lock()
Marble::BBCItemGetter::~BBCItemGetter
~BBCItemGetter()
Definition: BBCItemGetter.cpp:30
Marble::BBCStation
Definition: BBCStation.h:24
Marble::AbstractWorkerThread::ensureRunning
void ensureRunning()
Definition: AbstractWorkerThread.cpp:59
BBCItemGetter.h
Marble::BBCItemGetter::BBCItemGetter
BBCItemGetter(QObject *parent=0)
Definition: BBCItemGetter.cpp:23
Marble::BBCItemGetter::m_scheduledNumber
qint32 m_scheduledNumber
Definition: BBCItemGetter.h:55
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
Marble::AbstractWorkerThread
The AbstractWorkerThread is a class written for small tasks that have to run multiple times on differ...
Definition: AbstractWorkerThread.h:36
Marble::GeoDataLatLonAltBox
A class that defines a 3D bounding box for geographic data.
Definition: GeoDataLatLonAltBox.h:49
Marble::BBCItemGetter::station
BBCStation station(const QString &id)
Definition: BBCItemGetter.cpp:50
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:38 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