• 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
  • earthquake
EarthquakeModel.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 2010 Utku Aydin <utkuaydin34@gmail.com>
9 //
10 
11 #include "EarthquakeModel.h"
12 #include "EarthquakeItem.h"
13 
14 #include "MarbleGlobal.h"
15 #include "MarbleModel.h"
16 #include "GeoDataCoordinates.h"
17 #include "GeoDataLatLonAltBox.h"
18 #include "MarbleDebug.h"
19 
20 #include <QDebug>
21 #include <QString>
22 #include <QUrl>
23 #include <QMessageBox>
24 #include <QScriptEngine>
25 #include <QScriptValue>
26 #include <QScriptValueIterator>
27 
28 namespace Marble {
29 
30 EarthquakeModel::EarthquakeModel( const MarbleModel *marbleModel, QObject *parent )
31  : AbstractDataPluginModel( "earthquake", marbleModel, parent ),
32  m_minMagnitude( 0.0 ),
33  m_startDate( QDateTime::fromString( "2006-02-04", "yyyy-MM-dd" ) ),
34  m_endDate( QDateTime::currentDateTime() )
35 {
36  // nothing to do
37 }
38 
39 EarthquakeModel::~EarthquakeModel()
40 {
41 }
42 
43 void EarthquakeModel::setMinMagnitude( double minMagnitude )
44 {
45  m_minMagnitude = minMagnitude;
46 }
47 
48 void EarthquakeModel::setStartDate( const QDateTime& startDate )
49 {
50  m_startDate = startDate;
51 }
52 
53 void EarthquakeModel::setEndDate( const QDateTime& endDate )
54 {
55  m_endDate = endDate;
56 }
57 
58 void EarthquakeModel::getAdditionalItems( const GeoDataLatLonAltBox& box, qint32 number )
59 {
60  if( marbleModel()->planetId() != "earth" ) {
61  return;
62  }
63 
64  QString geonamesUrl( "http://ws.geonames.org/earthquakesJSON" );
65  geonamesUrl += "?north=" + QString::number( box.north() * RAD2DEG );
66  geonamesUrl += "&south=" + QString::number( box.south() * RAD2DEG );
67  geonamesUrl += "&east=" + QString::number( box.east() * RAD2DEG );
68  geonamesUrl += "&west=" + QString::number( box.west() * RAD2DEG );
69  geonamesUrl += "&date=" + m_endDate.toString( "yyyy-MM-dd" );
70  geonamesUrl += "&maxRows=" + QString::number( number );
71  geonamesUrl += "&username=marble";
72  geonamesUrl += "&formatted=true";
73  downloadDescriptionFile( QUrl( geonamesUrl ) );
74 }
75 
76 void EarthquakeModel::parseFile( const QByteArray& file )
77 {
78  QScriptValue data;
79  QScriptEngine engine;
80 
81  // Qt requires parentheses around json code
82  data = engine.evaluate( '(' + QString( file ) + ')' );
83 
84  // Parse if any result exists
85  if ( data.property( "earthquakes" ).isArray() ) {
86  QScriptValueIterator iterator( data.property( "earthquakes" ) );
87  // Add items to the list
88  QList<AbstractDataPluginItem*> items;
89  while ( iterator.hasNext() ) {
90  iterator.next();
91  // Converting earthquake's properties from QScriptValue to appropriate types
92  QString eqid = iterator.value().property( "eqid" ).toString(); // Earthquake's ID
93  double longitude = iterator.value().property( "lng" ).toNumber();
94  double latitude = iterator.value().property( "lat" ).toNumber();
95  double magnitude = iterator.value().property( "magnitude" ).toNumber();
96  QString data = iterator.value().property( "datetime" ).toString();
97  QDateTime date = QDateTime::fromString( data, "yyyy-MM-dd hh:mm:ss" );
98  double depth = iterator.value().property( "depth" ).toNumber();
99 
100  if( date <= m_endDate && date >= m_startDate && magnitude >= m_minMagnitude ) {
101  if( !itemExists( eqid ) ) {
102  // If it does not exists, create it
103  GeoDataCoordinates coordinates( longitude, latitude, 0.0, GeoDataCoordinates::Degree );
104  EarthquakeItem *item = new EarthquakeItem( this );
105  item->setId( eqid );
106  item->setCoordinate( coordinates );
107  item->setTarget( "earth" );
108  item->setMagnitude( magnitude );
109  item->setDateTime( date );
110  item->setDepth( depth );
111  items << item;
112  }
113  }
114  }
115 
116  addItemsToList( items );
117  }
118 }
119 
120 
121 }
122 
123 #include "EarthquakeModel.moc"
Marble::EarthquakeItem::setDateTime
void setDateTime(const QDateTime &dateTime)
Definition: EarthquakeItem.cpp:102
GeoDataCoordinates.h
Marble::AbstractDataPluginModel::items
QList< AbstractDataPluginItem * > items(const ViewportParams *viewport, qint32 number=10)
Get the items on the viewport Returns the currently downloaded images in the viewport.
Definition: AbstractDataPluginModel.cpp:274
Marble::RAD2DEG
const qreal RAD2DEG
Definition: MarbleGlobal.h:220
QDateTime::toString
QString toString(Qt::DateFormat format) const
Marble::AbstractDataPluginItem::setTarget
void setTarget(const QString &target)
Definition: AbstractDataPluginItem.cpp:66
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::EarthquakeModel::getAdditionalItems
virtual void getAdditionalItems(const GeoDataLatLonAltBox &box, qint32 number=10)
Generates the download url for the description file from the web service depending on the box surroun...
Definition: EarthquakeModel.cpp:58
QByteArray
Marble::AbstractDataPluginModel::itemExists
bool itemExists(const QString &id) const
Testing the existence of the item id in the list.
Definition: AbstractDataPluginModel.cpp:563
MarbleModel.h
This file contains the headers for MarbleModel.
Marble::AbstractDataPluginItem::setId
void setId(const QString &id)
Definition: AbstractDataPluginItem.cpp:86
QScriptValue
QScriptEngine::evaluate
QScriptValue evaluate(const QString &program, const QString &fileName, int lineNumber)
Marble::AbstractDataPluginModel
An abstract data model (not based on QAbstractModel) for a AbstractDataPlugin.
Definition: AbstractDataPluginModel.h:45
QScriptValueIterator
Marble::AbstractDataPluginModel::marbleModel
const MarbleModel * marbleModel() const
Definition: AbstractDataPluginModel.cpp:269
Marble::EarthquakeModel::~EarthquakeModel
~EarthquakeModel()
Definition: EarthquakeModel.cpp:39
MarbleDebug.h
Marble::EarthquakeModel::EarthquakeModel
EarthquakeModel(const MarbleModel *marbleModel, QObject *parent=0)
Definition: EarthquakeModel.cpp:30
QScriptValue::toString
QString toString() const
Marble::GeoDataCoordinates::Degree
Definition: GeoDataCoordinates.h:66
Marble::EarthquakeModel::parseFile
void parseFile(const QByteArray &file)
Parses the file which getAdditionalItems downloads and prepares the data for usage.
Definition: EarthquakeModel.cpp:76
Marble::GeoDataLatLonBox::north
qreal north(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the northern boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:93
QScriptEngine
Marble::AbstractDataPluginModel::downloadDescriptionFile
void downloadDescriptionFile(const QUrl &url)
Download the description file from the url.
Definition: AbstractDataPluginModel.cpp:392
Marble::GeoDataLatLonBox::east
qreal east(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the eastern boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:135
EarthquakeItem.h
QString::number
QString number(int n, int base)
Marble::EarthquakeModel::setMinMagnitude
void setMinMagnitude(double minMagnitude)
Definition: EarthquakeModel.cpp:43
QObject
EarthquakeModel.h
QString
QList< AbstractDataPluginItem * >
MarbleGlobal.h
QScriptValue::property
QScriptValue property(const QString &name, const ResolveFlags &mode) const
QUrl
QDateTime::fromString
QDateTime fromString(const QString &string, Qt::DateFormat format)
Marble::GeoDataLatLonBox::west
qreal west(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the western boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:156
Marble::MarbleModel
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition: MarbleModel.h:97
GeoDataLatLonAltBox.h
Marble::EarthquakeModel::setStartDate
void setStartDate(const QDateTime &startDate)
Definition: EarthquakeModel.cpp:48
Marble::GeoDataLatLonBox::south
qreal south(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the southern boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:114
Marble::EarthquakeModel::setEndDate
void setEndDate(const QDateTime &endDate)
Definition: EarthquakeModel.cpp:53
Marble::EarthquakeItem
Definition: EarthquakeItem.h:23
Marble::BillboardGraphicsItem::setCoordinate
void setCoordinate(const GeoDataCoordinates &coordinates)
Definition: BillboardGraphicsItem.cpp:98
QScriptValue::isArray
bool isArray() const
Marble::GeoDataLatLonAltBox
A class that defines a 3D bounding box for geographic data.
Definition: GeoDataLatLonAltBox.h:49
QDateTime
Marble::AbstractDataPluginModel::addItemsToList
void addItemsToList(const QList< AbstractDataPluginItem * > &items)
Adds the items to the list of initialized items.
Definition: AbstractDataPluginModel.cpp:408
Marble::EarthquakeItem::setMagnitude
void setMagnitude(double magnitude)
Definition: EarthquakeItem.cpp:55
Marble::EarthquakeItem::setDepth
void setDepth(double depth)
Definition: EarthquakeItem.cpp:118
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