Commit e8d8a788 authored by Torsten Rahn's avatar Torsten Rahn
Browse files

- Preparing for cleaning up this mess a bit :-)


svn path=/trunk/KDE/kdeedu/marble/; revision=726593
parent d69632c8
//
// This file is part of the Marble Desktop Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2007 Murad Tagirov <tmurad@gmail.com>
//
#include "KMLColorStyle.h"
KMLColorStyle::KMLColorStyle() :
m_color( Qt::black )
{
}
void KMLColorStyle::setColor( const QColor &value )
{
m_color = value;
}
QColor KMLColorStyle::color() const
{
return m_color;
}
void KMLColorStyle::pack( QDataStream& stream ) const
{
KMLObject::pack( stream );
stream << m_color;
}
void KMLColorStyle::unpack( QDataStream& stream )
{
KMLObject::unpack( stream );
stream >> m_color;
}
//
// This file is part of the Marble Desktop Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2007 Murad Tagirov <tmurad@gmail.com>
//
#ifndef GEODATACOLORSTYLE_H
#define GEODATACOLORSTYLE_H
#include <QtGui/QColor>
#include "GeoDataObject.h"
class GeoDataColorStyle : public GeoDataObject
{
public:
void setColor( const QColor &value );
QColor color() const;
/*
* Serializable methods
*/
virtual void pack( QDataStream& stream ) const;
virtual void unpack( QDataStream& stream );
protected:
GeoDataColorStyle();
protected:
QColor m_color;
};
#endif // GEODATACOLORSTYLE_H
//
// This file is part of the Marble Desktop Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2007 Murad Tagirov <tmurad@gmail.com>
//
#include <QtGui/QImage>
#include "KMLContainer.h"
#include "KMLPlaceMark.h"
#include "ViewParams.h"
KMLContainer::KMLContainer()
{
}
KMLContainer::~KMLContainer()
{
qDebug("KMLContainer::~KMLContainer(). Object count: %d", m_placemarkVector.count());
foreach ( KMLPlaceMark* placemark, m_placemarkVector ) {
delete placemark;
}
}
void KMLContainer::addPlaceMark( KMLPlaceMark* placemark )
{
m_placemarkVector.append( placemark );
}
PlaceMarkContainer& KMLContainer::activePlaceMarkContainer( const ViewParams& viewParams )
{
switch( viewParams.m_projection ) {
case Spherical:
return sphericalActivePlaceMarkContainer(viewParams);
break;
case Equirectangular:
return rectangularActivePlaceMarkContainer(viewParams);
break;
}
//
// Return at least something...
//
return sphericalActivePlaceMarkContainer(viewParams);
}
PlaceMarkContainer& KMLContainer::sphericalActivePlaceMarkContainer( const ViewParams& viewParams )
{
m_activePlaceMarkContainer.clear ();
int x = 0;
int y = 0;
int imgwidth = viewParams.m_canvasImage->width();
int imgheight = viewParams.m_canvasImage->height();
Quaternion invplanetAxis = viewParams.m_planetAxis.inverse();
Quaternion qpos;
QVector < KMLPlaceMark* >::const_iterator it;
for ( it = m_placemarkVector.constBegin();
it != m_placemarkVector.constEnd();
it++ )
{
KMLPlaceMark* placemark = *it;
qpos = placemark->coordinate().quaternion();
qpos.rotateAroundAxis(invplanetAxis);
if ( qpos.v[Q_Z] > 0 ) {
x = (int)(imgwidth / 2 + viewParams.m_radius * qpos.v[Q_X]);
y = (int)(imgheight / 2 + viewParams.m_radius * qpos.v[Q_Y]);
// Don't process placemarks if they are outside the screen area
if ( x >= 0 && x < imgwidth && y >= 0 && y < imgheight ) {
m_activePlaceMarkContainer.append( placemark );
}
}
}
qDebug("KMLDocument::activePlaceMarkContainer (). PlaceMarks count: %d", m_activePlaceMarkContainer.count());
return m_activePlaceMarkContainer;
}
PlaceMarkContainer& KMLContainer::rectangularActivePlaceMarkContainer( const ViewParams& viewParams )
{
m_activePlaceMarkContainer.clear ();
int x = 0;
int y = 0;
int imgwidth = viewParams.m_canvasImage->width();
int imgheight = viewParams.m_canvasImage->height();
Quaternion invplanetAxis = viewParams.m_planetAxis.inverse();
Quaternion qpos;
float const centerLat = viewParams.m_planetAxis.pitch();
float const centerLon = -viewParams.m_planetAxis.yaw();
QVector < KMLPlaceMark* >::const_iterator it;
for ( it = m_placemarkVector.constBegin();
it != m_placemarkVector.constEnd();
it++ )
{
KMLPlaceMark* placemark = *it;
qpos = placemark->coordinate().quaternion();
double xyFactor = (float)(2 * viewParams.m_radius) / M_PI;
double degX;
double degY;
qpos.getSpherical(degX,degY);
x = (int)(imgwidth / 2 + xyFactor * (degX + centerLon));
y = (int)(imgheight / 2 + xyFactor * (degY + centerLat));
// Don't process placemarks if they are outside the screen area
if ( ( x >= 0 && x < imgwidth || x+4*viewParams.m_radius < imgwidth || x-4*viewParams.m_radius >= 0 ) && y >= 0 && y < imgheight ) {
m_activePlaceMarkContainer.append( placemark );
}
}
qDebug("KMLDocument::activePlaceMarkContainer (). PlaceMarks count: %d", m_activePlaceMarkContainer.count());
return m_activePlaceMarkContainer;
}
void KMLContainer::pack( QDataStream& stream ) const
{
KMLFeature::pack( stream );
stream << m_placemarkVector.count();
for ( QVector <KMLPlaceMark*>::const_iterator iterator = m_placemarkVector.constBegin();
iterator != m_placemarkVector.end();
iterator++ )
{
const KMLPlaceMark& placemark = * ( *iterator );
placemark.pack( stream );
}
}
void KMLContainer::unpack( QDataStream& stream )
{
KMLFeature::unpack( stream );
int count;
stream >> count;
for ( int i = 0; i < count; ++i ) {
KMLPlaceMark* placemark = new KMLPlaceMark();
placemark->unpack( stream );
m_placemarkVector.append( placemark );
}
}
//
// This file is part of the Marble Desktop Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2007 Murad Tagirov <tmurad@gmail.com>
//
#ifndef GEODATACONTAINER_H
#define GEODATACONTAINER_H
#include <QtCore/QVector>
#include "GeoDataFeature.h"
#include "PlaceMarkContainer.h"
class GeoDataPlaceMark;
class ViewParams;
class GeoDataContainer : public GeoDataFeature
{
public:
virtual ~GeoDataContainer();
void addPlaceMark( GeoDataPlaceMark* placemark );
virtual void pack( QDataStream& stream ) const;
virtual void unpack( QDataStream& stream );
/*
* Will move this method to GeoDataDocumentModel in a next step
*/
PlaceMarkContainer& activePlaceMarkContainer( const ViewParams& viewParams );
protected:
GeoDataContainer();
QVector < GeoDataPlaceMark* > m_placemarkVector;
private:
PlaceMarkContainer& sphericalActivePlaceMarkContainer( const ViewParams& viewParams );
PlaceMarkContainer& rectangularActivePlaceMarkContainer( const ViewParams& viewParams );
PlaceMarkContainer m_activePlaceMarkContainer;
};
#endif // GEODATACONTAINER_H
//
// This file is part of the Marble Desktop Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2007 Murad Tagirov <tmurad@gmail.com>
//
#include "KMLDocument.h"
#include <QtXml/QXmlInputSource>
#include <QtXml/QXmlSimpleReader>
#include "KMLDocumentParser.h"
#include "KMLPlaceMark.h"
#include "KMLStyle.h"
KMLDocument::KMLDocument()
{
}
KMLDocument::~KMLDocument()
{
foreach ( KMLStyle* style, m_styleHash ) {
delete style;
}
}
void KMLDocument::load( QIODevice& source )
{
/*
* 1. create KMLParser
* 2. create QXMLSimpleReader
* 3. start to parsing input stream
*/
KMLDocumentParser parser( *this );
QXmlInputSource xmlDocumentSource( &source );
QXmlSimpleReader reader;
reader.setContentHandler( &parser );
reader.setErrorHandler( &parser );
reader.setFeature( "http://trolltech.com/xml/features/report-whitespace-only-CharData", false );
bool result = reader.parse( &xmlDocumentSource );
if ( ! result ) {
qDebug("KMLDocument::load( QIODevice& ). Error while parsing xml source");
}
}
void KMLDocument::addStyle( KMLStyle* style )
{
qDebug("KMLDocument: Add new style");
m_styleHash.insert( style->styleId(), style );
}
const KMLStyle& KMLDocument::getStyle( QString styleId ) const
{
/*
* TODO: m_styleHash always should contain at least default KMLStyle element
*/
return *m_styleHash.value( styleId );
}
//
// This file is part of the Marble Desktop Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2007 Murad Tagirov <tmurad@gmail.com>
//
#ifndef GEODATADOCUMENT_H
#define GEODATADOCUMENT_H
#include <QtCore/QHash>
#include "GeoDataFolder.h"
class QIODevice;
class GeoDataStyle;
class GeoDataDocument : public GeoDataFolder
{
public:
GeoDataDocument();
~GeoDataDocument();
void load( QIODevice& source );
void addStyle( GeoDataStyle* style );
const GeoDataStyle& getStyle( QString styleId ) const;
private:
QHash < QString, GeoDataStyle* > m_styleHash;
};
#endif // GEODATADOCUMENT_H
//
// This file is part of the Marble Desktop Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2007 Murad Tagirov <tmurad@gmail.com>
//
#include "KMLFeature.h"
#include <QtCore/QDataStream>
KMLFeature::KMLFeature() :
m_visible( true )
{
}
KMLFeature::KMLFeature( const QString& name ) :
m_name( name )
{
}
KMLFeature::~KMLFeature()
{
}
QString KMLFeature::name() const
{
return m_name;
}
void KMLFeature::setName( const QString &value )
{
m_name = value;
}
QString KMLFeature::address() const
{
return m_address;
}
void KMLFeature::setAddress( const QString &value)
{
m_address = value;
}
QString KMLFeature::phoneNumber() const
{
return m_phoneNumber;
}
void KMLFeature::setPhoneNumber( const QString &value)
{
m_phoneNumber = value;
}
QString KMLFeature::description() const
{
return m_description;
}
void KMLFeature::setDescription( const QString &value)
{
m_description = value;
}
bool KMLFeature::isVisible() const
{
return m_visible;
}
void KMLFeature::setVisible( bool value )
{
m_visible = value;
}
void KMLFeature::pack( QDataStream& stream ) const
{
KMLObject::pack( stream );
stream << m_name;
stream << m_address;
stream << m_phoneNumber;
stream << m_description;
stream << m_visible;
}
void KMLFeature::unpack( QDataStream& stream )
{
KMLObject::unpack( stream );
stream >> m_name;
stream >> m_address;
stream >> m_phoneNumber;
stream >> m_description;
stream >> m_visible;
}
//
// This file is part of the Marble Desktop Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2007 Murad Tagirov <tmurad@gmail.com>
//
#ifndef GEODATAFEATURE_H
#define GEODATAFEATURE_H
#include <QtCore/QString>
#include "GeoDataObject.h"
class GeoDataFeature
: public GeoDataObject
{
public:
virtual ~GeoDataFeature();
QString name() const;
void setName( const QString &value );
QString address() const;
void setAddress( const QString &value);
QString phoneNumber() const;
void setPhoneNumber( const QString &value);
QString description() const;
void setDescription( const QString &value);
bool isVisible() const;
void setVisible( bool value );
virtual void pack( QDataStream& stream ) const;
virtual void unpack( QDataStream& stream );
protected:
GeoDataFeature();
GeoDataFeature( const QString& name );
private:
QString m_name;
QString m_address;
QString m_phoneNumber;
QString m_description;
bool m_visible;
};
#endif // GEODATAFEATURE_H
//
// This file is part of the Marble Desktop Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2007 Murad Tagirov <tmurad@gmail.com>
//
#include "KMLFolder.h"
#include "PlaceMarkContainer.h"
KMLFolder::KMLFolder()
{
}
KMLFolder::~KMLFolder()
{
qDebug("KMLFolder::~KMLFolder(). Subfolders count: %d", m_folderVector.count());
foreach ( KMLFolder* folder, m_folderVector ) {
delete folder;
}
}
void KMLFolder::addFolder( KMLFolder* folder )
{
m_folderVector.append( folder );
}
//
// This file is part of the Marble Desktop Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2007 Murad Tagirov <tmurad@gmail.com>
//
#ifndef GEODATAFOLDER_H
#define GEODATAFOLDER_H
#include <QtCore/QVector>
#include "GeoDataContainer.h"
class GeoDataFolder : public GeoDataContainer
{
public:
GeoDataFolder();
~GeoDataFolder();
void addFolder( GeoDataFolder* folder );