• 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
  • panoramio
PanoramioModel.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 2008 Shashan Singh <shashank.personal@gmail.com>
9 // Copyright 2009 Bastian Holst <bastianholst@gmx.de>
10 //
11 
12 // Self
13 #include "PanoramioModel.h"
14 #include "jsonparser.h"
15 
16 // Marble
17 #include "GeoDataLatLonAltBox.h"
18 #include "PanoramioWidget.h"
19 
20 // Qt
21 #include <QUrl>
22 #include <QString>
23 
24 using namespace Marble;
25 
26 PanoramioModel::PanoramioModel( const MarbleModel *marbleModel, QObject *parent )
27  : AbstractDataPluginModel( "panoramio", marbleModel, parent )
28 {
29 }
30 
31 void PanoramioModel::getAdditionalItems( const GeoDataLatLonAltBox &box, qint32 number )
32 {
33  // FIXME: Download a list of constant number, because the parser doesn't support
34  // loading a file of an unknown length.
35  QUrl jsonUrl( "http://www.panoramio.com/map/get_panoramas.php?from="
36  + QString::number( 0 )
37  + "&order=upload_date"
38  + "&set=public"
39  + "&to=" + QString::number( number )
40 // + "&to=" + QString::number( number )
41  + "&minx=" + QString::number( box.west() * RAD2DEG )
42  + "&miny=" + QString::number( box.south() * RAD2DEG )
43  + "&maxx=" + QString::number( box.east() * RAD2DEG )
44  + "&maxy=" + QString::number( box.north() * RAD2DEG )
45  + "&size=small");
46 
47  downloadDescriptionFile( jsonUrl );
48 }
49 
50 void PanoramioModel::parseFile( const QByteArray &file )
51 {
52  jsonParser panoramioJsonParser;
53  QList<panoramioDataStructure> list
54  = panoramioJsonParser.parseAllObjects( file,
55  numberOfImagesPerFetch );
56 
57  QList<panoramioDataStructure>::iterator it;
58  for ( it = list.begin(); it != list.end(); ++it ) {
59  // Setting the meta information of the current image
60  GeoDataCoordinates coordinates( (*it).longitude,
61  (*it).latitude,
62  0,
63  GeoDataCoordinates::Degree );
64 
65  if( itemExists( QString::number( (*it).photo_id ) ) ) {
66  continue;
67  }
68 
69  PanoramioWidget *widget = new PanoramioWidget( this );
70  widget->setTarget( "earth" );
71  widget->setCoordinate( coordinates );
72  widget->setId( QString::number( (*it).photo_id ) );
73  widget->setUploadDate( (*it).upload_date );
74 
75  // We need to download the file from Panoramio if it doesn't exist already
76  if ( !fileExists( widget->id(), standardImageSize ) ) {
77  downloadItem( QUrl( (*it).photo_file_url ),
78  standardImageSize,
79  widget );
80  }
81  else {
82  // If the file does exist, we can simply load it to our widget.
83  QString filename = generateFilepath( widget->id(),
84  standardImageSize );
85  widget->addDownloadedFile( filename,
86  standardImageSize );
87  }
88 
89  addItemToList( widget );
90  }
91 }
92 
93 #include "PanoramioModel.moc"
Marble::PanoramioWidget::setUploadDate
void setUploadDate(QDate uploadDate)
Definition: PanoramioWidget.cpp:55
Marble::RAD2DEG
const qreal RAD2DEG
Definition: MarbleGlobal.h:220
Marble::AbstractDataPluginItem::setTarget
void setTarget(const QString &target)
Definition: AbstractDataPluginItem.cpp:66
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::PanoramioModel::PanoramioModel
PanoramioModel(const MarbleModel *marbleModel, QObject *parent=0)
Definition: PanoramioModel.cpp:26
Marble::AbstractDataPluginModel::fileExists
bool fileExists(const QString &fileName) const
Testing the existence of the file fileName.
Definition: AbstractDataPluginModel.cpp:542
QByteArray
Marble::AbstractDataPluginModel::itemExists
bool itemExists(const QString &id) const
Testing the existence of the item id in the list.
Definition: AbstractDataPluginModel.cpp:563
Marble::numberOfImagesPerFetch
const quint32 numberOfImagesPerFetch
Definition: PanoramioModel.h:19
Marble::AbstractDataPluginItem::setId
void setId(const QString &id)
Definition: AbstractDataPluginItem.cpp:86
Marble::standardImageSize
const QString standardImageSize
Definition: PanoramioWidget.h:22
Marble::AbstractDataPluginModel
An abstract data model (not based on QAbstractModel) for a AbstractDataPlugin.
Definition: AbstractDataPluginModel.h:45
Marble::AbstractDataPluginItem::id
QString id() const
Definition: AbstractDataPluginItem.cpp:81
Marble::GeoDataCoordinates::Degree
Definition: GeoDataCoordinates.h:66
Marble::GeoDataLatLonBox::north
qreal north(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the northern boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:93
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
QString::number
QString number(int n, int base)
QObject
Marble::PanoramioWidget::addDownloadedFile
void addDownloadedFile(const QString &url, const QString &type)
Definition: PanoramioWidget.cpp:32
QString
QList< panoramioDataStructure >
Marble::PanoramioModel::getAdditionalItems
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: PanoramioModel.cpp:31
QList::end
iterator end()
PanoramioWidget.h
QUrl
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::PanoramioWidget
Definition: PanoramioWidget.h:24
Marble::GeoDataLatLonBox::south
qreal south(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the southern boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:114
PanoramioModel.h
jsonParser
Definition: panoramio/jsonparser.h:46
Marble::AbstractDataPluginModel::generateFilepath
QString generateFilepath(const QString &id, const QString &type) const
Generates the absolute filepath of the from id and type.
Definition: AbstractDataPluginModel.cpp:537
Marble::AbstractDataPluginModel::addItemToList
void addItemToList(AbstractDataPluginItem *item)
Convenience method to add one item to the list.
Definition: AbstractDataPluginModel.cpp:403
jsonParser::parseAllObjects
QList< panoramioDataStructure > parseAllObjects(const QString &content, int number)
Definition: panoramio/jsonparser.cpp:88
Marble::BillboardGraphicsItem::setCoordinate
void setCoordinate(const GeoDataCoordinates &coordinates)
Definition: BillboardGraphicsItem.cpp:98
QList::begin
iterator begin()
jsonparser.h
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::PanoramioModel::parseFile
void parseFile(const QByteArray &file)
The reimplementation has to parse the file and should generate widgets.
Definition: PanoramioModel.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:41 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