• 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
  • wikipedia
WikipediaModel.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 "WikipediaModel.h"
13 
14 // Plugin
15 #include "GeonamesParser.h"
16 
17 // Marble
18 #include "GeoDataLatLonAltBox.h"
19 #include "MarbleGlobal.h"
20 #include "MarbleWidget.h"
21 #include "MarbleModel.h"
22 #include "MarbleDirs.h"
23 #include "WikipediaItem.h"
24 #include "MarbleLocale.h"
25 #include "MarbleDebug.h"
26 
27 // Qt
28 #include <QUrl>
29 #include <QString>
30 #include <QIcon>
31 #include <QImage>
32 #include <QPainter>
33 #include <QPixmap>
34 #include <QSvgRenderer>
35 
36 #if QT_VERSION >= 0x050000
37  #include <QUrlQuery>
38 #endif
39 
40 using namespace Marble;
41 
42 WikipediaModel::WikipediaModel( const MarbleModel *marbleModel, QObject *parent )
43  : AbstractDataPluginModel( "wikipedia", marbleModel, parent ),
44  m_marbleWidget( 0 ),
45  m_wikipediaIcon( MarbleDirs::path( "svg/wikipedia_shadow.svg" ) ),
46  m_showThumbnail( true )
47 {
48  m_languageCode = MarbleLocale::languageCode();
49 }
50 
51 WikipediaModel::~WikipediaModel()
52 {
53 }
54 
55 void WikipediaModel::setShowThumbnail( bool show )
56 {
57  m_showThumbnail = show;
58 }
59 
60 void WikipediaModel::getAdditionalItems( const GeoDataLatLonAltBox& box,
61  qint32 number )
62 {
63  // Geonames only supports wikipedia articles for earth
64  if ( marbleModel()->planetId() != "earth" ) {
65  return;
66  }
67 
68  QUrl geonamesUrl( "http://ws.geonames.org/wikipediaBoundingBox" );
69 #if QT_VERSION < 0x050000
70  geonamesUrl.addQueryItem( "north", QString::number( box.north( GeoDataCoordinates::Degree ) ) );
71  geonamesUrl.addQueryItem( "south", QString::number( box.south( GeoDataCoordinates::Degree ) ) );
72  geonamesUrl.addQueryItem( "east", QString::number( box.east( GeoDataCoordinates::Degree ) ) );
73  geonamesUrl.addQueryItem( "west", QString::number( box.west( GeoDataCoordinates::Degree ) ) );
74  geonamesUrl.addQueryItem( "maxRows", QString::number( number ) );
75  geonamesUrl.addQueryItem( "lang", m_languageCode );
76  geonamesUrl.addQueryItem( "username", "marble" );
77 #else
78  QUrlQuery urlQuery;
79  urlQuery.addQueryItem( "north", QString::number( box.north( GeoDataCoordinates::Degree ) ) );
80  urlQuery.addQueryItem( "south", QString::number( box.south( GeoDataCoordinates::Degree ) ) );
81  urlQuery.addQueryItem( "east", QString::number( box.east( GeoDataCoordinates::Degree ) ) );
82  urlQuery.addQueryItem( "west", QString::number( box.west( GeoDataCoordinates::Degree ) ) );
83  urlQuery.addQueryItem( "maxRows", QString::number( number ) );
84  urlQuery.addQueryItem( "lang", m_languageCode );
85  urlQuery.addQueryItem( "username", "marble" );
86  geonamesUrl.setQuery( urlQuery );
87 #endif
88 
89  downloadDescriptionFile( geonamesUrl );
90 }
91 
92 void WikipediaModel::parseFile( const QByteArray& file )
93 {
94  QList<WikipediaItem*> list;
95  GeonamesParser parser( m_marbleWidget, &list, this );
96 
97  parser.read( file );
98 
99  QList<AbstractDataPluginItem*> items;
100  QList<WikipediaItem*>::const_iterator it;
101 
102  for ( it = list.constBegin(); it != list.constEnd(); ++it ) {
103  if ( itemExists( (*it)->id() ) ) {
104  delete *it;
105  continue;
106  }
107 
108  (*it)->setIcon( m_wikipediaIcon );
109  // Currently all wikipedia articles with geotags are on earth
110  (*it)->setTarget( "earth" );
111  QUrl thumbnailImageUrl = (*it)->thumbnailImageUrl();
112  if ( m_showThumbnail && !thumbnailImageUrl.isEmpty() ) {
113  downloadItem( thumbnailImageUrl, "thumbnail", *it );
114  }
115  else {
116  items << *it;
117  }
118  }
119 
120  addItemsToList( items );
121 }
122 
123 void WikipediaModel::setMarbleWidget(MarbleWidget *widget)
124 {
125  m_marbleWidget = widget;
126 }
127 
128 #include "WikipediaModel.moc"
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::MarbleLocale::languageCode
static QString languageCode()
Definition: MarbleLocale.cpp:50
QUrl::setQuery
void setQuery(const QString &txt)
QByteArray
Marble::WikipediaModel::setShowThumbnail
void setShowThumbnail(bool show)
Definition: WikipediaModel.cpp:55
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::WikipediaModel::parseFile
void parseFile(const QByteArray &file)
The reimplementation has to parse the file and should generate widgets.
Definition: WikipediaModel.cpp:92
Marble::AbstractDataPluginModel
An abstract data model (not based on QAbstractModel) for a AbstractDataPlugin.
Definition: AbstractDataPluginModel.h:45
Marble::AbstractDataPluginModel::marbleModel
const MarbleModel * marbleModel() const
Definition: AbstractDataPluginModel.cpp:269
WikipediaItem.h
QUrl::isEmpty
bool isEmpty() const
MarbleDebug.h
QList::const_iterator
Marble::WikipediaModel::WikipediaModel
WikipediaModel(const MarbleModel *marbleModel, QObject *parent=0)
Definition: WikipediaModel.cpp:42
Marble::GeoDataCoordinates::Degree
Definition: GeoDataCoordinates.h:66
Marble::MarbleWidget
A widget class that displays a view of the earth.
Definition: MarbleWidget.h:104
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)
Marble::GeonamesParser
Definition: GeonamesParser.h:26
QObject
MarbleDirs.h
Marble::MarbleDirs
A class that manages data look-up for Marble.
Definition: MarbleDirs.h:79
GeonamesParser.h
Marble::WikipediaModel::setMarbleWidget
void setMarbleWidget(MarbleWidget *widget)
Definition: WikipediaModel.cpp:123
QList
MarbleLocale.h
WikipediaModel.h
MarbleGlobal.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::GeoDataLatLonBox::south
qreal south(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the southern boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:114
MarbleWidget.h
This file contains the headers for MarbleWidget.
QUrl::addQueryItem
void addQueryItem(const QString &key, const QString &value)
QList::constEnd
const_iterator constEnd() const
QList::constBegin
const_iterator constBegin() const
Marble::WikipediaModel::~WikipediaModel
~WikipediaModel()
Definition: WikipediaModel.cpp:51
Marble::GeonamesParser::read
bool read(const QByteArray &data)
Definition: GeonamesParser.cpp:33
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::WikipediaModel::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: WikipediaModel.cpp:60
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