Subversion Repositories public

Compare Revisions

Ignore whitespace Rev 282 → Rev 283

/sportwatcher/trunk/src/wmsselectorwidgetbase.ui
0,0 → 1,408
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>wmsSelectorWidgetBase</class>
<widget class="QDialog" name="wmsSelectorWidgetBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>677</width>
<height>392</height>
</rect>
</property>
<property name="windowTitle">
<string>WMS Selector</string>
</property>
<property name="windowIcon">
<iconset>
<normaloff>hi16-app-sportwatcher.png</normaloff>hi16-app-sportwatcher.png</iconset>
</property>
<property name="locale">
<locale language="English" country="UnitedStates"/>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="4">
<widget class="KUrlRequester" name="urlWMS"/>
</item>
<item row="2" column="0" rowspan="6" colspan="2">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Waypoint in WGS84 date</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Latitude</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="KDoubleNumInput" name="edLat">
<property name="minimum">
<double>-90.000000000000000</double>
</property>
<property name="maximum">
<double>90.000000000000000</double>
</property>
<property name="decimals">
<number>6</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Longitude</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="KDoubleNumInput" name="edLon">
<property name="minimum">
<double>-180.000000000000000</double>
</property>
<property name="maximum">
<double>180.000000000000000</double>
</property>
<property name="decimals">
<number>6</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Capital city</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="KComboBox" name="cbCities"/>
</item>
</layout>
</widget>
</item>
<item row="2" column="2" colspan="2">
<widget class="KPushButton" name="pbGetCapabilities">
<property name="text">
<string>Get capabilities</string>
</property>
</widget>
</item>
<item row="6" column="2" colspan="2">
<widget class="KPushButton" name="pbDetails">
<property name="text">
<string>Details about WMS server</string>
</property>
</widget>
</item>
<item row="7" column="2" rowspan="2" colspan="2">
<widget class="QLabel" name="lbPreview">
<property name="minimumSize">
<size>
<width>300</width>
<height>0</height>
</size>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="KActionSelector" name="actionLayer">
<property name="minimumSize">
<size>
<width>0</width>
<height>200</height>
</size>
</property>
</widget>
</item>
<item row="9" column="0" colspan="4">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="3" column="2" rowspan="3" colspan="2">
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Bands</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="KIntSpinBox" name="edBands">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>4</number>
</property>
</widget>
</item>
<item row="1" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>199</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="cbStyles">
<property name="text">
<string>Set styles</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KIntSpinBox</class>
<extends>QSpinBox</extends>
<header>knuminput.h</header>
</customwidget>
<customwidget>
<class>KUrlRequester</class>
<extends>QFrame</extends>
<header>kurlrequester.h</header>
</customwidget>
<customwidget>
<class>KDoubleNumInput</class>
<extends>QWidget</extends>
<header>knuminput.h</header>
</customwidget>
<customwidget>
<class>KPushButton</class>
<extends>QPushButton</extends>
<header>kpushbutton.h</header>
</customwidget>
<customwidget>
<class>KComboBox</class>
<extends>QComboBox</extends>
<header>kcombobox.h</header>
</customwidget>
<customwidget>
<class>KActionSelector</class>
<extends>QWidget</extends>
<header>kactionselector.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>urlWMS</tabstop>
<tabstop>cbCities</tabstop>
<tabstop>buttonBox</tabstop>
<tabstop>pbGetCapabilities</tabstop>
<tabstop>edBands</tabstop>
<tabstop>cbStyles</tabstop>
<tabstop>pbDetails</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>wmsSelectorWidgetBase</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>246</x>
<y>384</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>wmsSelectorWidgetBase</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>314</x>
<y>384</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>pbDetails</sender>
<signal>clicked()</signal>
<receiver>wmsSelectorWidgetBase</receiver>
<slot>slotDetails()</slot>
<hints>
<hint type="sourcelabel">
<x>672</x>
<y>152</y>
</hint>
<hint type="destinationlabel">
<x>485</x>
<y>50</y>
</hint>
</hints>
</connection>
<connection>
<sender>pbGetCapabilities</sender>
<signal>clicked()</signal>
<receiver>wmsSelectorWidgetBase</receiver>
<slot>slotGetCapabilities()</slot>
<hints>
<hint type="sourcelabel">
<x>387</x>
<y>49</y>
</hint>
<hint type="destinationlabel">
<x>386</x>
<y>73</y>
</hint>
</hints>
</connection>
<connection>
<sender>actionLayer</sender>
<signal>added(QListWidgetItem*)</signal>
<receiver>wmsSelectorWidgetBase</receiver>
<slot>slotAdded(QListWidgetItem*)</slot>
<hints>
<hint type="sourcelabel">
<x>345</x>
<y>322</y>
</hint>
<hint type="destinationlabel">
<x>370</x>
<y>334</y>
</hint>
</hints>
</connection>
<connection>
<sender>actionLayer</sender>
<signal>removed(QListWidgetItem*)</signal>
<receiver>wmsSelectorWidgetBase</receiver>
<slot>slotRemoved(QListWidgetItem*)</slot>
<hints>
<hint type="sourcelabel">
<x>338</x>
<y>286</y>
</hint>
<hint type="destinationlabel">
<x>370</x>
<y>296</y>
</hint>
</hints>
</connection>
<connection>
<sender>actionLayer</sender>
<signal>movedDown(QListWidgetItem*)</signal>
<receiver>wmsSelectorWidgetBase</receiver>
<slot>slotDown(QListWidgetItem*)</slot>
<hints>
<hint type="sourcelabel">
<x>348</x>
<y>252</y>
</hint>
<hint type="destinationlabel">
<x>371</x>
<y>260</y>
</hint>
</hints>
</connection>
<connection>
<sender>actionLayer</sender>
<signal>movedUp(QListWidgetItem*)</signal>
<receiver>wmsSelectorWidgetBase</receiver>
<slot>slotUp(QListWidgetItem*)</slot>
<hints>
<hint type="sourcelabel">
<x>345</x>
<y>209</y>
</hint>
<hint type="destinationlabel">
<x>370</x>
<y>214</y>
</hint>
</hints>
</connection>
<connection>
<sender>cbCities</sender>
<signal>currentIndexChanged(QString)</signal>
<receiver>wmsSelectorWidgetBase</receiver>
<slot>slotCities(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>310</x>
<y>142</y>
</hint>
<hint type="destinationlabel">
<x>369</x>
<y>166</y>
</hint>
</hints>
</connection>
<connection>
<sender>cbStyles</sender>
<signal>toggled(bool)</signal>
<receiver>wmsSelectorWidgetBase</receiver>
<slot>slotStyles(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>615</x>
<y>112</y>
</hint>
<hint type="destinationlabel">
<x>677</x>
<y>104</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>slotURLChanged()</slot>
<slot>slotDetails()</slot>
<slot>slotGetCapabilities()</slot>
<slot>slotAdded(QListWidgetItem*)</slot>
<slot>slotRemoved(QListWidgetItem*)</slot>
<slot>slotDown(QListWidgetItem*)</slot>
<slot>slotUp(QListWidgetItem*)</slot>
<slot>slotCities(QString)</slot>
<slot>slotStyles(bool)</slot>
</slots>
</ui>
/sportwatcher/trunk/src/wmsbase.h
36,6 → 36,7
/*$PUBLIC_SLOTS$*/
virtual void bpCancelSlot();
virtual void bpSaveSlot();
virtual void slotGetCapabilities();
 
protected:
/*$PROTECTED_FUNCTIONS$*/
/sportwatcher/trunk/src/wmscapabilitieswidgetbase.ui
0,0 → 1,302
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>wmsCapabilitiesWidgetBase</class>
<widget class="QDialog" name="wmsCapabilitiesWidgetBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>517</width>
<height>609</height>
</rect>
</property>
<property name="windowTitle">
<string>Capabilities</string>
</property>
<property name="locale">
<locale language="English" country="UnitedStates"/>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Get capabilities</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Get</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="KLineEdit" name="edCapabilitiesGet">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Post</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="KLineEdit" name="edCapabilitiesPost">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="KLineEdit" name="edFormat">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Format</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Get map</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Get</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="KLineEdit" name="edMapGet">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Post</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="KLineEdit" name="edMapPost">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Formats</string>
</property>
</widget>
</item>
<item row="2" column="1" rowspan="2">
<widget class="KListWidget" name="liFormats">
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
</widget>
</item>
<item row="3" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>123</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>177</width>
<height>78</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="3" column="0">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>430</width>
<height>22</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="1">
<widget class="KPushButton" name="pbCancel">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Contact person primary</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Contact person</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="KLineEdit" name="edPerson">
<property name="acceptDrops">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Contact organisation</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="KLineEdit" name="edOrg">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Voice telephone</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="KLineEdit" name="edPhone">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Facsimile telephone</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="KLineEdit" name="edFax">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Electronic mail address</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="KLineEdit" name="edMail">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KListWidget</class>
<extends>QListWidget</extends>
<header>klistwidget.h</header>
</customwidget>
<customwidget>
<class>KPushButton</class>
<extends>QPushButton</extends>
<header>kpushbutton.h</header>
</customwidget>
<customwidget>
<class>KLineEdit</class>
<extends>QLineEdit</extends>
<header>klineedit.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>edPerson</tabstop>
<tabstop>edOrg</tabstop>
<tabstop>edPhone</tabstop>
<tabstop>edFax</tabstop>
<tabstop>edMail</tabstop>
<tabstop>edCapabilitiesGet</tabstop>
<tabstop>edCapabilitiesPost</tabstop>
<tabstop>edFormat</tabstop>
<tabstop>edMapGet</tabstop>
<tabstop>edMapPost</tabstop>
<tabstop>liFormats</tabstop>
<tabstop>pbCancel</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>pbCancel</sender>
<signal>clicked()</signal>
<receiver>wmsCapabilitiesWidgetBase</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>460</x>
<y>587</y>
</hint>
<hint type="destinationlabel">
<x>517</x>
<y>566</y>
</hint>
</hints>
</connection>
</connections>
</ui>
/sportwatcher/trunk/src/wmsselectorwidget.h
0,0 → 1,263
//
// C++ Interface:
//
// Description:
//
//
// Author: Andreas Theofilu <andreas@theosys.at>, (C) 2009
//
// Copyright: See COPYING file that comes with this distribution
//
//
 
#ifndef WMSSELECTORWIDGET_H
#define WMSSELECTORWIDGET_H
 
#include <QDialog>
#include <QString>
#include <QLabel>
#include <QHttp>
#include <QFile>
#include <QXmlReader>
#include <KUrlRequester>
#include <KActionSelector>
#include <KProgressDialog>
#include <KDoubleNumInput>
#include "ui_wmsselectorwidgetbase.h"
 
typedef struct
{
QString Name;
QString Title;
QString Abstract;
QString OnlineResource;
QString Type;
QString ContactPerson;
QString ContactOrganisation;
QString ContactPosition;
QString AddressType;
QString Address;
QString City;
QString StateOrProvince;
QString PostCode;
QString Country;
QString ContactVoiceTelephone;
QString ContactFacsimileTelephone;
QString ContactElectronicMailAddress;
QString Fees;
QString AccessConstraints;
}SERVICE;
 
typedef struct
{
QStringList Format;
QString Get;
QString Post;
}GET;
 
typedef struct
{
GET GetCapabilities;
GET GetMap;
GET GetFeatureInfo;
}REQUEST;
 
typedef struct
{
double maxx;
double minx;
double maxy;
double miny;
QString SRS;
}BOX;
 
typedef struct STYLE
{
QString Name;
QString Title;
QString Format;
QString LegendURL;
STYLE *next;
}STYLE;
 
typedef struct LAYER
{
bool opaque;
bool noSubsets;
bool queryable;
bool cascaded;
QString Name;
QString Title;
QString Abstract;
QStringList SRS;
QStringList CRS;
BOX LatLon;
BOX Bounding;
double scaleMin;
double scaleMax;
STYLE *style;
LAYER *next;
}LAYER;
 
typedef struct
{
QString city;
double lon;
double lat;
}CITIES;
 
class wmsSelectorWidget : public QDialog,
public QXmlDefaultHandler,
private Ui::wmsSelectorWidgetBase
{
Q_OBJECT
 
public:
enum ELEMENT
{
el_none,
el_WMT_MS_Capabilities,
el_Service,
el_Name,
el_Title,
el_Abstract,
el_KeywordList,
el_Keyword,
el_OnlineResource,
el_ContactInformation,
el_ContactPersonPrimary,
el_ContactPerson,
el_ContactOrganisation,
el_ContactPosition,
el_ContactAddress,
el_AddressType,
el_Address,
el_City,
el_StateOrProvince,
el_PostCode,
el_Country,
el_ContactVoiceTelephone,
el_ContactFacsimileTelephone,
el_ElectronicMailAddress,
el_Fees,
el_AccessConstraints,
el_Capability,
el_Request,
el_GetCapabilities,
el_Format,
el_DCPType,
el_HTTP,
el_Get,
el_Post,
el_GetMap,
el_GetFeatureInfo,
el_DescribeLayer,
el_GetLegendGraphic,
el_GetStyles,
el_Exception,
el_VendorSpecificCapabilities,
el_UserDefinedSymbolization,
el_Layer,
el_SRS,
el_LatLonBoundingBox,
el_BoundingBox,
el_ScaleHint,
el_Style,
el_LegendURL,
el_MetadataURL
};
 
enum ATTRIBUTE
{
at_none,
at_Name,
at_Title,
at_Abstract,
at_ContactPerson,
at_ContactOrganisation,
at_ContactPosition,
at_AddressType,
at_Address,
at_City,
at_StateOrProvince,
at_PostCode,
at_Country,
at_ContactVoiceTelephone,
at_ContactFacsimileTelephone,
at_ContactElectronicMailAddress,
at_Fees,
at_AccessConstraints,
at_Format,
at_SRS,
at_CRS
};
 
public:
wmsSelectorWidget (QWidget* parent = 0, Qt::WFlags fl = 0);
~wmsSelectorWidget();
/*$PUBLIC_FUNCTIONS$*/
 
// Functions to parse the XML file
bool startDocument ();
bool startElement (const QString&, const QString&, const QString& , const QXmlAttributes&);
bool endElement (const QString&, const QString&, const QString&);
bool characters (const QString&);
 
 
public slots:
/*$PUBLIC_SLOTS$*/
virtual void slotGetCapabilities();
virtual void slotDetails();
virtual void slotAdded(QListWidgetItem *);
virtual void slotRemoved(QListWidgetItem *);
virtual void slotUp(QListWidgetItem *);
virtual void slotDown(QListWidgetItem *);
virtual void slotCities(QString);
virtual void slotStyles(bool);
 
protected:
/*$PROTECTED_FUNCTIONS$*/
void getCapabilities();
bool parseWMS();
bool grabPicture(double, double, double, double);
 
private slots:
// Functions called during downloading the capabilities of a WMS-server
void WMSrequestFinished(int, bool);
void updateDataReadProgress(int, int);
void readResponseHeader(const QHttpResponseHeader &);
void slotAuthenticationRequired(const QString &, quint16, QAuthenticator *);
#ifndef QT_NO_OPENSSL
void sslErrors(const QList<QSslError> &);
#endif
void cancelDownload(); // The cancel button in progress dialog
 
private:
void initializeParser();
LAYER *allocateLayer();
STYLE *allocateStyle();
STYLE *findLastStyle(LAYER *);
bool writeWMSTag(double, double, double, double, int, int);
void setDimension(double &, double &, double &, double &, QListWidgetItem *);
 
private:
int id; // ID used during download
QString Data, MAP;
QHttp *http;
bool httpRequestAborted;
bool StyleCommas;
QFile file;
KProgressDialog *progressDialog;
ELEMENT element, el2;
ATTRIBUTE attribute;
QStringList Exception; // List of exceptions of WMS server
QString WMSVersion; // Version, WMS server supports
SERVICE Service;
REQUEST Request;
LAYER *Layer, *firstLayer;
int line; // actual line number during parsing
int lcount; // counts the deepnes of layers
};
 
#endif
 
/sportwatcher/trunk/src/wmscapabilitieswidget.cpp
0,0 → 1,30
//
// C++ Implementation:
//
// Description:
//
//
// Author: Andreas Theofilu <andreas@theosys.at>, (C) 2009
//
// Copyright: See COPYING file that comes with this distribution
//
//
 
 
#include "wmscapabilitieswidget.h"
 
wmsCapabilitiesWidget::wmsCapabilitiesWidget (QWidget* parent, Qt::WFlags fl)
: QDialog (parent, fl), Ui::wmsCapabilitiesWidgetBase()
{
setupUi (this);
}
 
wmsCapabilitiesWidget::~wmsCapabilitiesWidget()
{
}
 
/*$SPECIALIZATION$*/
 
 
#include "wmscapabilitieswidget.moc"
 
/sportwatcher/trunk/src/GDALError.h
0,0 → 1,24
//
// C++ Interface: GDALError
//
// Description:
//
//
// Author: Andreas Theofilu <andreas@theosys.at>, (C) 2009
//
// Copyright: See COPYING file that comes with this distribution
//
//
 
#ifndef _GDALERROR_H
#define _GDALERROR_H
 
#include <QString>
 
#if defined HAVE_GDAL
void spwErrorHandler(CPLErr, int, const char *);
void destroyErrors();
QString catGDALError();
#endif // HAVE_GDAL
 
#endif // _GDALERROR_H
/sportwatcher/trunk/src/CMakeLists.txt
13,15 → 13,20
sportwatcher.cpp
sportwatcherwidget.cpp
transform.cpp
wmsbase.cpp)
wmsbase.cpp
wmscapabilitieswidget.cpp
wmsselectorwidget.cpp)
 
set(sportwatcher_UI
authenticationdialog.ui
coordinateswidgetbase.ui
progresswidgetbase.ui
settingswidgetbase.ui
shapewidgetbase.ui
sportwatcherwidgetbase.ui
wmswidgetbase.ui)
wmscapabilitieswidgetbase.ui
wmswidgetbase.ui
wmsselectorwidgetbase.ui)
 
add_definitions(-fvisibility=default -pedantic -fexceptions -Wextra -D_REENTRANT)
 
/sportwatcher/trunk/src/wmswidgetbase.ui
7,7 → 7,7
<x>0</x>
<y>0</y>
<width>513</width>
<height>637</height>
<height>657</height>
</rect>
</property>
<property name="windowTitle">
97,7 → 97,7
<string>Server settings</string>
</property>
<layout class="QGridLayout">
<item row="6" column="3">
<item row="6" column="3" colspan="2">
<spacer name="spacer5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
182,7 → 182,7
</property>
</widget>
</item>
<item row="1" column="1" colspan="3">
<item row="1" column="1" colspan="4">
<widget class="KLineEdit" name="edLayer">
<property name="toolTip">
<string>If you need or want to specify layers, do it here.</string>
215,7 → 215,7
</property>
</widget>
</item>
<item row="7" column="1" colspan="3">
<item row="7" column="1" colspan="4">
<widget class="KLineEdit" name="edStyles">
<property name="toolTip">
<string>In case you've entered layers, you must enter one style for every layer!</string>
232,7 → 232,7
</property>
</widget>
</item>
<item row="4" column="2" colspan="2">
<item row="4" column="2" colspan="3">
<spacer name="spacer4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
248,7 → 248,7
</property>
</spacer>
</item>
<item row="9" column="2" colspan="2">
<item row="9" column="2" colspan="3">
<spacer name="spacer7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
274,7 → 274,7
</property>
</widget>
</item>
<item row="3" column="3">
<item row="3" column="3" colspan="2">
<spacer name="spacer3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
300,7 → 300,7
</property>
</widget>
</item>
<item row="8" column="3">
<item row="8" column="3" colspan="2">
<spacer name="spacer6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
358,7 → 358,7
</property>
</widget>
</item>
<item row="0" column="1" colspan="3">
<item row="0" column="1" colspan="4">
<widget class="KUrlRequester" name="edServerURL">
<property name="acceptDrops">
<bool>true</bool>
378,7 → 378,7
</property>
</widget>
</item>
<item row="5" column="3">
<item row="5" column="3" colspan="2">
<spacer name="spacer18">
<property name="orientation">
<enum>Qt::Horizontal</enum>
518,7 → 518,7
</property>
</widget>
</item>
<item row="2" column="3">
<item row="2" column="3" colspan="2">
<spacer name="spacer2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
547,6 → 547,13
</property>
</widget>
</item>
<item row="10" column="4">
<widget class="KPushButton" name="pbGetCapabilities">
<property name="text">
<string>Get capabilities</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
816,19 → 823,14
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>KComboBox</class>
<extends>QComboBox</extends>
<header>kcombobox.h</header>
</customwidget>
<customwidget>
<class>KIntSpinBox</class>
<extends>QSpinBox</extends>
<header>knuminput.h</header>
</customwidget>
<customwidget>
<class>KLineEdit</class>
<extends>QLineEdit</extends>
<header>klineedit.h</header>
<class>KUrlRequester</class>
<extends>QFrame</extends>
<header>kurlrequester.h</header>
</customwidget>
<customwidget>
<class>KPushButton</class>
836,11 → 838,16
<header>kpushbutton.h</header>
</customwidget>
<customwidget>
<class>KUrlRequester</class>
<extends>QFrame</extends>
<header>kurlrequester.h</header>
<class>KLineEdit</class>
<extends>QLineEdit</extends>
<header>klineedit.h</header>
</customwidget>
<customwidget>
<class>KComboBox</class>
<extends>QComboBox</extends>
<header>kcombobox.h</header>
</customwidget>
<customwidget>
<class>Q3GroupBox</class>
<extends>QGroupBox</extends>
<header>Qt3Support/Q3GroupBox</header>
859,6 → 866,7
<tabstop>cbTile</tabstop>
<tabstop>edDepth</tabstop>
<tabstop>edOverview</tabstop>
<tabstop>pbGetCapabilities</tabstop>
<tabstop>chSquare</tabstop>
<tabstop>chOffline</tabstop>
<tabstop>chAdvice</tabstop>
896,8 → 904,8
<slot>bpSaveSlot()</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
<x>147</x>
<y>648</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
912,8 → 920,8
<slot>bpCancelSlot()</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
<x>334</x>
<y>648</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
921,5 → 929,24
</hint>
</hints>
</connection>
<connection>
<sender>pbGetCapabilities</sender>
<signal>clicked()</signal>
<receiver>wmsWidgetBase</receiver>
<slot>slotGetCapabilities()</slot>
<hints>
<hint type="sourcelabel">
<x>412</x>
<y>347</y>
</hint>
<hint type="destinationlabel">
<x>510</x>
<y>370</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>slotGetCapabilities()</slot>
</slots>
</ui>
/sportwatcher/trunk/src/wmsbase.cpp
25,6 → 25,7
#include <qdir.h>
#include <qcheckbox.h>
#include "wmsbase.h"
#include "wmsselectorwidget.h"
 
wmsbase::wmsbase ( QWidget* parent, Qt::WFlags fl )
: QDialog(parent, fl), Ui::wmsWidgetBase ()
37,7 → 38,7
KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
KConfigGroup ic (&cfg, "WMS");
edServerURL->setUrl (ic.readEntry("ServerURL", "http://onearth.jpl.nasa.gov/wms.cgi"));
edLayer->setText (ic.readEntry("Layer", QString("")));
edLayer->setText (ic.readEntry("Layer", QString("modis,global_mosaic")));
cbSRS->setCurrentIndex (ic.readEntry("SRS", 0));
cbCRS->setCurrentIndex (ic.readEntry("CRS", 0));
edBands->setValue (ic.readEntry("Bands", 3));
49,8 → 50,8
edOverview->setValue (ic.readEntry("Overview", 10));
chSquare->setChecked (ic.readEntry("Square", false));
chOffline->setChecked (ic.readEntry("Offline", false));
chAdvice->setChecked (ic.readEntry("Advice", false));
chVerify->setChecked (ic.readEntry("Verify", true));
chAdvice->setChecked (ic.readEntry("Advice", true));
chVerify->setChecked (ic.readEntry("Verify", false));
edCorrX->setValue (ic.readEntry("CorrX", 0));
edCorrY->setValue (ic.readEntry("CorrY", 0));
}
60,6 → 61,15
}
 
/*$SPECIALIZATION$*/
void wmsbase::slotGetCapabilities()
{
wmsSelectorWidget *dlg = new wmsSelectorWidget(this);
 
if (dlg->exec() == QDialog::Accepted)
{
}
}
 
void wmsbase::bpCancelSlot()
{
done(QDialog::Rejected);
/sportwatcher/trunk/src/wmsselectorwidget.cpp
0,0 → 1,1491
//
// C++ Implementation:
//
// Description:
//
//
// Author: Andreas Theofilu <andreas@theosys.at>, (C) 2009
//
// Copyright: See COPYING file that comes with this distribution
//
//
 
#include <iostream>
 
#include <QPixmap>
#include <QBitmap>
#include <QDir>
#include <QFile>
#include <QImage>
#include <QtNetwork>
#include <QListWidget>
#include <QPainter>
#include <QCheckBox>
#include <KStandardDirs>
#include <KConfig>
#include <KLocale>
#include <KMessageBox>
#include <KGlobalSettings>
#include <KConfigGroup>
#include <KIconLoader>
#include <KUrl>
#include <KUrlRequester>
#include <KFile>
 
#include "config.h"
 
#if defined HAVE_GDAL
#include <gdal/gdal_priv.h>
#include <gdal/ogr_spatialref.h>
#include <gdal/ogrsf_frmts.h>
#include <gdal/gdalwarper.h>
#include <gdal/ogrsf_frmts.h>
#include "GDALError.h"
#endif
 
#include "wmsselectorwidget.h"
#include "ui_authenticationdialog.h"
#include "wmscapabilitieswidget.h"
 
// The capital cities from all countries of the world
// Source: Wikipedia, Google
CITIES Cities[] = {
{ "Abidjan", 5.3363, -4.0277 },
{ "Abu Dhabi", 24.4758, 54.3714 },
{ "Abuja", 9.0578, 7.4892 },
{ "Accora", 5.5555, -0.196 },
{ "Addis Abeba", 9.0164, 38.7579 },
{ "Algier", 36.7527, 3.0422 },
{ "Amman", 31.9565, 35.9457 },
{ "Amsterdam", 52.3737, 4.8911 },
{ "Andorra la Vella", 42.5074, 1.5219 },
{ "Ankara", 39.9438, 32.856 },
{ "Antananarivo", -18.915, 47.5318 },
{ "Apia", -13.8314, -171.7516 },
{ "Aschgabat", 37.9501, 58.3802 },
{ "Asmara", 15.3324, 38.9261 },
{ "Astana", 51.1798, 71.4466 },
{ "Asuncion", -25.3003, -57.6363 },
{ "Athen", 37.9792, 23.7166 },
{ "Bagdad", 33.3158, 44.3921 },
{ "Baku", 40.4167, 49.8236 },
{ "Bamako", 12.6529, -7.9865 },
{ "Bandar Seri Begawan", 4.9431, 114.9424 },
{ "Bankok", 13.7211, 100.4765 },
{ "Bangui", 4.3616, 18.556 },
{ "Banjul", 13.4548, -16.579 },
{ "Basseterre", 17.2968, -62.7137 },
{ "Beirut", 33.8886, 35.4954 },
{ "Belgrad", 44.8024, 20.4651 },
{ "Belmopan", 17.2617, -88.7785 },
{ "Berlin", 52.5234, 13.4105 },
{ "Bern", 46.9479, 7.4479 },
{ "Bratislava", 48.1483, 17.1068 },
{ "Bridgetown", 13.0935, -59.6106 },
{ "BrĂĽssel", 50.8462, 4.3545 },
{ "Budapest", 47.4984, 19.0403 },
{ "Buenos Aires", -34.6084, -58.3733 },
{ "Bukarest", 44.4304, 26.1225 },
{ "Den Haag", 52.0782, 4.3134 },
{ "Dublin", 53.3441, -6.2677 },
{ "Helsinki", 60.1698, 24.9379 },
{ "Kopenhagen", 55.6762, 12.5678 },
{ "Lissabon", 38.7071, -9.1357 },
{ "Ljubljana", 46.0514, 14.5055 },
{ "London", 51.5001, -0.1262 },
{ "Luxemburg", 49.8152, 6.1286 },
{ "Madrid", 40.4167, -3.7036 },
{ "Mexiko City", 19.427, -99.128 },
{ "Minsk", 53.8996, 27.5753 },
{ "Monaco", 43.7326, 7.4189 },
{ "Moskau", 55.7554, 37.6203 },
{ "Oslo", 59.9136, 10.7394 },
{ "Ottawa", 45.4218, -75.6964 },
{ "Paris", 48.856, 2.3515 },
{ "Peking", 39.9077, 116.3994 },
{ "Prag", 50.088, 14.4217 },
{ "Reykjavik", 64.1352, -21.8951 },
{ "Riga", 56.9462, 24.1049 },
{ "Rom", 41.8945, 12.4826 },
{ "San Marino", 43.9322, 12.4484 },
{ "Sofia", 42.6963, 23.3236 },
{ "Stockholm", 59.3329, 18.0652 },
{ "Tirana", 41.3309, 19.8325 },
{ "Tokio", 35.688, 139.6932 },
{ "Vaduz", 47.1407, 9.5218 },
{ "Valletta", 35.9009, 14.5154 },
{ "Vilnius", 54.6888, 25.2801 },
{ "Warschau", 52.2291, 21.0123 },
{ "Washington D.C.", 38.8917, -77.0239 },
{ "Wien", 48.2091, 16.3727 },
{ "Zagreb", 45.8149, 15.9784 },
{ "", 0.0, 0.0 }
};
 
wmsSelectorWidget::wmsSelectorWidget (QWidget* parent, Qt::WFlags fl)
: QDialog (parent, fl), Ui::wmsSelectorWidgetBase()
{
// Initialize some variables
http = 0;
httpRequestAborted = false;
progressDialog = 0;
id = 0;
Layer = 0;
firstLayer = 0;
initializeParser();
// Initialize the GUI elements
setupUi (this);
// Initialize the environment
urlWMS->setMode(KFile::File | KFile::ExistingOnly);
KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
KConfigGroup ic (&cfg, "WMS");
urlWMS->setUrl (ic.readEntry("ServerURL", "http://onearth.jpl.nasa.gov/wms.cgi"));
Data = ic.readEntry("Data", QDir::home().absolutePath() + "/.sportwatcher");
MAP = ic.readEntry("MAP", QDir::home().absolutePath() + "/.sportwatcher/track.wms");
file.setFileName(Data + "/capabilities.xml"); // File to save WMS capabilities
edBands->setValue(ic.readEntry("Bands", 3));
StyleCommas = true;
cbStyles->setChecked(StyleCommas);
// Fill the cities combo box
int i = 0;
 
while (!Cities[i].city.isEmpty())
{
cbCities->addUrl(KUrl(Cities[i].city));
i++;
}
 
// Connect the http module
progressDialog = new KProgressDialog(this);
http = new QHttp(this);
connect(http, SIGNAL(requestFinished(int, bool)), this, SLOT(WMSrequestFinished(int, bool)));
connect(http, SIGNAL(dataReadProgress(int, int)), this, SLOT(updateDataReadProgress(int, int)));
connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)), this, SLOT(readResponseHeader(const QHttpResponseHeader &)));
connect(http, SIGNAL(authenticationRequired(const QString &, quint16, QAuthenticator *)),
this, SLOT(slotAuthenticationRequired(const QString &, quint16, QAuthenticator *)));
connect(progressDialog, SIGNAL(cancelClicked()), this, SLOT(cancelDownload()));
#ifndef QT_NO_OPENSSL
connect(http, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(sslErrors(const QList<QSslError> &)));
#endif
getCapabilities();
}
 
wmsSelectorWidget::~wmsSelectorWidget()
{
if (file.exists())
file.remove();
 
destroyErrors();
}
 
/*$SPECIALIZATION$*/
void wmsSelectorWidget::slotGetCapabilities()
{
actionLayer->availableListWidget()->clear();
actionLayer->selectedListWidget()->clear();
getCapabilities();
}
 
void wmsSelectorWidget::slotDetails()
{
wmsCapabilitiesWidget *dlg = new wmsCapabilitiesWidget(this);
dlg->setPerson(Service.ContactPerson);
dlg->setOrg(Service.ContactOrganisation);
dlg->setPhone(Service.ContactVoiceTelephone);
dlg->setFax(Service.ContactFacsimileTelephone);
dlg->setMail(Service.ContactElectronicMailAddress);
dlg->setCapabilitiesGet(Request.GetCapabilities.Get);
dlg->setCapabilitiesPost(Request.GetCapabilities.Post);
 
if (Request.GetCapabilities.Format.size() > 0)
dlg->setFormat(Request.GetCapabilities.Format.at(0));
 
dlg->setMapGet(Request.GetMap.Get);
dlg->setMapPost(Request.GetMap.Post);
 
for (int i = 0; i < Request.GetMap.Format.size(); ++i)
dlg->addFormats(Request.GetMap.Format.at(i));
 
dlg->exec();
delete dlg;
}
 
void wmsSelectorWidget::slotAdded(QListWidgetItem *item)
{
double minx, miny, maxx, maxy;
 
setDimension(minx, miny, maxx, maxy, item);
grabPicture(minx, miny, maxx, maxy);
}
 
void wmsSelectorWidget::slotRemoved(QListWidgetItem *item)
{
double minx, miny, maxx, maxy;
 
setDimension(minx, miny, maxx, maxy, item);
grabPicture(minx, miny, maxx, maxy);
}
 
void wmsSelectorWidget::slotUp(QListWidgetItem *item)
{
double minx, miny, maxx, maxy;
 
setDimension(minx, miny, maxx, maxy, item);
grabPicture(minx, miny, maxx, maxy);
}
 
void wmsSelectorWidget::slotDown(QListWidgetItem *item)
{
double minx, miny, maxx, maxy;
 
setDimension(minx, miny, maxx, maxy, item);
grabPicture(minx, miny, maxx, maxy);
}
 
void wmsSelectorWidget::slotCities(QString city)
{
int i = 0;
double minx, miny, maxx, maxy;
 
while (!Cities[i].city.isEmpty())
{
if (Cities[i].city == city)
{
edLat->setValue(Cities[i].lat);
edLon->setValue(Cities[i].lon);
break;
}
 
i++;
}
 
if (actionLayer->selectedListWidget()->count() > 0)
{
setDimension(minx, miny, maxx, maxy, 0);
grabPicture(minx, miny, maxx, maxy);
}
}
 
void wmsSelectorWidget::slotStyles(bool mode)
{
StyleCommas = mode;
}
 
/*
* This functions try to get a small example picture from the WMS server
*/
bool wmsSelectorWidget::grabPicture(double minx, double miny, double maxx, double maxy)
{
#if defined HAVE_GDAL
QPixmap pm;
GDALDataset *poDataset = 0;
GDALRasterBand *poBand = 0;
unsigned char *pafScanline = 0;
unsigned char *pafScanlineRed = 0;
unsigned char *pafScanlineGreen = 0;
unsigned char *pafScanlineBlue = 0;
unsigned char *pafScanlineAlpha = 0;
int nXSize, nYSize;
int width, height;
bool Fgeo = false;
QPainter paint;
 
QApplication::setOverrideCursor (QCursor(Qt::WaitCursor));
width = lbPreview->width();
height = lbPreview->height() - 2;
nXSize = nYSize = 0;
 
if (!writeWMSTag(minx, miny, maxx, maxy, width, height))
{
QApplication::restoreOverrideCursor();
KMessageBox::error(this, i18n("Error writing a tag file!"));
return false;
}
 
// set the dimensions of the pixmap
pm = QPixmap(width, height);
// start painting the map
paint.begin(&pm);
QColor background(220, 220, 220);
paint.fillRect(0, 0, width, height, background);
 
if ((poDataset = (GDALDataset *)GDALOpen (MAP.toAscii().constData(), GA_ReadOnly)) != NULL)
{
int nRasterCount = poDataset->GetRasterCount();
int nXBlock, nYBlock;
GDALColorTable *pCT, *pCTb, *pCTr, *pCTg, *pCTa;
 
int bGotMin, bGotMax;
int tTypeLen, tColor, tColorEntrys;
GDALDataType tRasterType;
double adfMinMax[2];
 
pCT = pCTb = pCTr = pCTg = pCTa = 0;
tTypeLen = 0;
pafScanlineRed = pafScanlineGreen = pafScanlineBlue = pafScanlineAlpha = 0;
Fgeo = true;
 
for (int a = 1; a <= nRasterCount; a++)
{
if (!Fgeo)
break;
 
if (!(poBand = poDataset->GetRasterBand (a)))
{
paint.end();
QApplication::restoreOverrideCursor();
KMessageBox::error(this, i18n("Error getting a raster band:\n%1").arg(catGDALError()));
if (pafScanlineRed)
delete pafScanlineRed;
 
if (pafScanlineGreen)
delete pafScanlineGreen;
 
if (pafScanlineBlue)
delete pafScanlineBlue;
 
if (pafScanlineAlpha)
delete pafScanlineAlpha;
 
GDALClose (poDataset);
poDataset = 0;
 
return false;
}
 
poBand->GetBlockSize (&nXBlock, &nYBlock);
nXSize = poBand->GetXSize();
nYSize = poBand->GetYSize();
tRasterType = poBand->GetRasterDataType ();
tTypeLen = GDALGetDataTypeSize (tRasterType) / 8; // We need Bytes not Bits!
tColor = poBand->GetColorInterpretation ();
 
adfMinMax[0] = poBand->GetMinimum (&bGotMin);
adfMinMax[1] = poBand->GetMaximum (&bGotMax);
 
if (!(bGotMin && bGotMax))
GDALComputeRasterMinMax ((GDALRasterBandH)poBand, TRUE, adfMinMax);
 
if ((pCT = poBand->GetColorTable()) != NULL)
tColorEntrys = poBand->GetColorTable()->GetColorEntryCount();
 
switch (a)
{
case 1: pafScanlineRed = new unsigned char[tTypeLen * nXSize * nYSize]; pafScanline = pafScanlineRed; pCTr = pCT; break;
case 2: pafScanlineGreen = new unsigned char[tTypeLen * nXSize * nYSize]; pafScanline = pafScanlineGreen; pCTg = pCT; break;
case 3: pafScanlineBlue = new unsigned char[tTypeLen * nXSize * nYSize]; pafScanline = pafScanlineBlue; pCTb = pCT; break;
case 4: pafScanlineAlpha = new unsigned char[tTypeLen * nXSize * nYSize]; pafScanline = pafScanlineAlpha; pCTa = pCT; break;
}
 
if (!pafScanline)
{
paint.end();
QApplication::restoreOverrideCursor();
KMessageBox::error(this, i18n("Not enough memory for a raster operation!"));
 
if (pafScanlineRed)
delete pafScanlineRed;
 
if (pafScanlineGreen)
delete pafScanlineGreen;
 
if (pafScanlineBlue)
delete pafScanlineBlue;
 
if (pafScanlineAlpha)
delete pafScanlineAlpha;
 
GDALClose (poDataset);
poDataset = 0;
 
return false;
}
 
memset (pafScanline, 0, tTypeLen * nXSize * nYSize);
 
/*
* Get the image (from the server) and put the tiles together.
*
* The function reads only one raster band. This is,
* because the function is called for every raster band and
* every raster band is stored into a separate array.
*/
if (poBand->RasterIO (GF_Read, 0, 0, nXSize, nYSize, pafScanline, nXSize, nYSize, tRasterType, 0, 0) == CE_Failure)
{
paint.end();
QApplication::restoreOverrideCursor();
KMessageBox::error(this, i18n("Error reading a raster band:\n%1").arg(catGDALError()));
QApplication::setOverrideCursor (QCursor(Qt::WaitCursor));
paint.begin(&pm);
Fgeo = false;
break;
}
else
Fgeo = true;
}
 
/*
* Only if Fgeo is TRUE, we've read successfully all raster
* bands. Now we have to put the bands together to get
* an image.
*/
if (Fgeo)
{
unsigned char *pCombinedBytes = new unsigned char[(tTypeLen * nXSize * nYSize * nRasterCount)];
unsigned char *ptr_dest, *ptr_src;
int j, x1, y1, a;
 
ptr_dest = ptr_src = 0;
 
/*
* We need two nested loops to set the pixels in the wanted
* order.
*/
for (a = 0, j = 0; a < (nXSize * nYSize * nRasterCount); a += nRasterCount, j++)
{
int k = a;
 
for (int m = nRasterCount - 1; m >= 0; m--, k++)
{
unsigned char *pBytes = 0;
 
switch (m)
{
case 3: pBytes = pafScanlineAlpha; pCT = pCTa; break;
case 2: pBytes = pafScanlineBlue; pCT = pCTb; break;
case 1: pBytes = pafScanlineGreen; pCT = pCTg; break;
default: pBytes = pafScanlineRed; pCT = pCTr;
}
 
ptr_dest = pCombinedBytes + k;
unsigned char b = pBytes[j];
 
/*
* If we have a color table, the pixels are pointers
* to the color table. We need to convert them into
* 24 bit pixels plus an optional alpha channel.
*/
if (pCT != NULL)
{
GDALColorEntry ce;
unsigned int c = (unsigned int)b;
c = pCT->GetColorEntryAsRGB (c, &ce);
 
if (m == 0) c = ce.c1;
if (m == 1) c = ce.c2;
if (m == 2) c = ce.c3;
if (m == 3) c = ce.c4;
 
b = (unsigned char)c;
}
 
ptr_src = &b;
memcpy (ptr_dest, ptr_src, 1);
}
}
 
x1 = y1 = 0;
 
/*
* The following loop is QT specific! It sets the pixels
* of the raw image, pixel by pixel. This may be slow, but
* everything else didn't work :-(
*
* FIXME: We need a more effective routine to put the
* raw image into QT's "painter" class.
*/
for (a = 0; a < (nXSize * nYSize * nRasterCount); a += nRasterCount)
{
if (x1 < width && y1 < height)
{
if (nRasterCount == 3)
paint.setPen (QPen(QColor((int)pCombinedBytes[a+2], (int)pCombinedBytes[a+1], (int)pCombinedBytes[a]), Qt::SolidLine));
else if (nRasterCount > 3)
paint.setPen (QPen(QColor(qRgba((int)pCombinedBytes[a+3], (int)pCombinedBytes[a+2], (int)pCombinedBytes[a+1], (int)pCombinedBytes[a])), Qt::SolidLine));
else if (nRasterCount == 2)
paint.setPen (QPen(QColor((int)pCombinedBytes[a+1], (int)pCombinedBytes[a], (int)pCombinedBytes[a+1]), Qt::SolidLine));
else if (nRasterCount == 1)
paint.setPen (QPen(QColor((int)pCombinedBytes[a], (int)pCombinedBytes[a], (int)pCombinedBytes[a]), Qt::SolidLine));
 
paint.drawPoint(x1, y1);
}
 
x1++;
 
if (x1 >= nXSize)
{
x1 = 0;
y1++;
}
}
 
delete pCombinedBytes;
pCombinedBytes = 0;
}
 
if (pafScanlineRed)
delete pafScanlineRed;
 
if (pafScanlineGreen)
delete pafScanlineGreen;
 
if (pafScanlineBlue)
delete pafScanlineBlue;
 
if (pafScanlineAlpha)
delete pafScanlineAlpha;
 
GDALClose (poDataset);
poDataset = 0;
}
else
{
paint.end();
lbPreview->setPixmap(pm);
QApplication::restoreOverrideCursor();
KMessageBox::error(this, i18n("Error initializing GDAL:\n%1").arg(catGDALError()));
return false;
}
 
paint.end();
lbPreview->setPixmap(pm);
QApplication::restoreOverrideCursor();
#endif
return true;
}
 
/*
* This part is a parser, able to read an XML-file produced by a WMS-server.
* The file contains informations about the layers and styles the server
* supports.
*/
bool wmsSelectorWidget::startDocument()
{
initializeParser();
Exception.clear();
WMSVersion.clear();
element = el2 = el_none;
attribute = at_none;
line = 0;
lcount = 0;
return true;
}
 
bool wmsSelectorWidget::startElement( const QString&, const QString&,
const QString& qName,
const QXmlAttributes& att)
{
int index;
 
attribute = at_none;
 
if (qName.toLower() == QString("wmt_ms_capabilities"))
{
element = el_WMT_MS_Capabilities;
 
if ((index = att.index(QString("version"))) != -1)
WMSVersion = att.value(index);
}
else if (qName.toLower() == QString("service"))
element = el_Service;
else if (qName.toLower() == QString("name"))
attribute = at_Name;
else if (qName.toLower() == QString("title"))
attribute = at_Title;
else if (qName.toLower() == QString("onlineresource"))
{
if (element == el_Service)
{
if ((index = att.index(QString("href"))) != -1)
Service.OnlineResource = att.value(index);
 
if ((index = att.index(QString("type"))) != -1)
Service.Type = att.value(index);
}
else if (element == el_GetCapabilities && el2 == el_Get)
{
if ((index = att.index(QString("href"))) != -1)
Request.GetCapabilities.Get = att.value(index);
}
else if (element == el_GetCapabilities && el2 == el_Post)
{
if ((index = att.index(QString("href"))) != -1)
Request.GetCapabilities.Post = att.value(index);
}
else if (element == el_GetMap && el2 == el_Get)
{
if ((index = att.index(QString("href"))) != -1)
Request.GetMap.Get = att.value(index);
}
else if (element == el_GetMap && el2 == el_Post)
{
if ((index = att.index(QString("href"))) != -1)
Request.GetMap.Post = att.value(index);
}
else if (element == el_GetFeatureInfo && el2 == el_Get)
{
if ((index = att.index(QString("href"))) != -1)
Request.GetFeatureInfo.Get = att.value(index);
}
else if (element == el_GetFeatureInfo && el2 == el_Post)
{
if ((index = att.index(QString("href"))) != -1)
Request.GetFeatureInfo.Post = att.value(index);
}
}
else if (qName.toLower() == QString("contactinformation"))
element = el_ContactInformation;
else if (qName.toLower() == QString("contactpersonprimary"))
element = el_ContactPersonPrimary;
else if (qName.toLower() == QString("contactperson"))
attribute = at_ContactPerson;
else if (qName.toLower() == QString("contactorganisation"))
attribute = at_ContactOrganisation;
else if (qName.toLower() == QString("contactposition"))
attribute = at_ContactPosition;
else if (qName.toLower() == QString("contactaddress"))
element = el_ContactAddress;
else if (qName.toLower() == QString("addresstype"))
attribute = at_AddressType;
else if (qName.toLower() == QString("address"))
attribute = at_Address;
else if (qName.toLower() == QString("city"))
attribute = at_City;
else if (qName.toLower() == QString("stateorprovince"))
attribute = at_StateOrProvince;
else if (qName.toLower() == QString("postcode"))
attribute = at_PostCode;
else if (qName.toLower() == QString("country"))
attribute = at_Country;
else if (qName.toLower() == QString("contactvoicetelephone"))
attribute = at_ContactVoiceTelephone;
else if (qName.toLower() == QString("contactfacsimiletelephone"))
attribute = at_ContactFacsimileTelephone;
else if (qName.toLower() == QString("contactelectronicmailaddress"))
attribute = at_ContactElectronicMailAddress;
else if (qName.toLower() == QString("fees"))
attribute = at_Fees;
else if (qName.toLower() == QString("accessconstraints"))
attribute = at_AccessConstraints;
else if (qName.toLower() == QString("capability"))
element = el_Capability;
else if (qName.toLower() == QString("request"))
element = el_Request;
else if (qName.toLower() == QString("getcapabilities"))
element = el_GetCapabilities;
else if (qName.toLower() == QString("format"))
attribute = at_Format;
else if (qName.toLower() == QString("dcptype"))
el2 = el_DCPType;
else if (qName.toLower() == QString("http"))
el2 = el_HTTP;
else if (qName.toLower() == QString("get"))
el2 = el_Get;
else if (qName.toLower() == QString("post"))
el2 = el_Post;
else if (qName.toLower() == QString("getmap"))
element = el_GetMap;
else if (qName.toLower() == QString("getfeatureinfo"))
element = el_GetFeatureInfo;
else if (qName.toLower() == QString("exception"))
element = el_Exception;
else if (qName.toLower() == QString("layer"))
{
LAYER *akt;
 
element = el_Layer;
lcount++;
akt = allocateLayer();
 
if (firstLayer == 0)
firstLayer = akt;
 
if ((index = att.index(QString("opaque"))) != -1)
akt->opaque = (att.value(index).toInt() == 0) ? false : true;
 
if ((index = att.index(QString("noSubsets"))) != -1)
akt->noSubsets = (att.value(index).toInt() == 0) ? false : true;
 
if ((index = att.index(QString("queryable"))) != -1)
akt->queryable = (att.value(index).toInt() == 0) ? false : true;
 
if ((index = att.index(QString("cascaded"))) != -1)
akt->cascaded = (att.value(index).toInt() == 0) ? false : true;
}
else if (qName.toLower() == QString("srs"))
attribute = at_SRS;
else if (qName.toLower() == QString("crs"))
attribute = at_CRS;
else if (qName.toLower() == QString("abstract"))
attribute = at_Abstract;
else if (qName.toLower() == QString("latlonboundingbox"))
{
if (lcount < 1)
{
KMessageBox::error(this, i18n("Error at line %1: Element LatLonBoundingBox was found outside of a Layer element!").arg(line));
return false;
}
 
if (!Layer || !firstLayer)
{
KMessageBox::error(this, i18n("Fatal error at line %1: Layer was not initialized!").arg(line));
return false;
}
 
if ((index = att.index(QString("maxx"))) != -1)
Layer->LatLon.maxx = att.value(index).toDouble();
 
if ((index = att.index(QString("maxy"))) != -1)
Layer->LatLon.maxy = att.value(index).toDouble();
 
if ((index = att.index(QString("minx"))) != -1)
Layer->LatLon.minx = att.value(index).toDouble();
 
if ((index = att.index(QString("miny"))) != -1)
Layer->LatLon.miny = att.value(index).toDouble();
}
else if (qName.toLower() == QString("boundingbox"))
{
if (lcount < 1)
{
KMessageBox::error(this, i18n("Error at line %1: Element BoundingBox was found outside of a Layer element!").arg(line));
return false;
}
 
if (!Layer || !firstLayer)
{
KMessageBox::error(this, i18n("Fatal error at line %1: Layer was not initialized!").arg(line));
return false;
}
 
if ((index = att.index(QString("maxx"))) != -1)
Layer->Bounding.maxx = att.value(index).toDouble();
 
if ((index = att.index(QString("maxy"))) != -1)
Layer->Bounding.maxy = att.value(index).toDouble();
 
if ((index = att.index(QString("minx"))) != -1)
Layer->Bounding.minx = att.value(index).toDouble();
 
if ((index = att.index(QString("miny"))) != -1)
Layer->Bounding.miny = att.value(index).toDouble();
 
if ((index = att.index(QString("srs"))) != -1)
Layer->Bounding.SRS = att.value(index);
}
else if (qName.toLower() == QString("metadataurl"))
element = el_MetadataURL;
else if (qName.toLower() == QString("legendurl"))
element = el_LegendURL;
else if (qName.toLower() == QString("style"))
{
element = el_Style;
 
if (!Layer || !firstLayer)
{
KMessageBox::error(this, i18n("Fatal error at line %1: Layer was not initialized!").arg(line));
return false;
}
 
if (!Layer->style)
Layer->style = allocateStyle();
else
{
STYLE *akt = findLastStyle(Layer);
 
akt->next = allocateStyle();
}
}
else if (qName.toLower() == QString("scalehint"))
{
if (lcount < 1)
{
KMessageBox::error(this, i18n("Error at line %1: Element ScaleHint was found outside of a Layer element!").arg(line));
return false;
}
 
if (!Layer || !firstLayer)
{
KMessageBox::error(this, i18n("Fatal error at line %1: Layer was not initialized!").arg(line));
return false;
}
 
if ((index = att.index(QString("min"))) != -1)
Layer->scaleMin = att.value(index).toDouble();
 
if ((index = att.index(QString("max"))) != -1)
Layer->scaleMax = att.value(index).toDouble();
}
 
return true;
}
 
bool wmsSelectorWidget::endElement( const QString&, const QString&, const QString& qName)
{
attribute = at_none;
 
if (qName.toLower() == QString("wmt_ms_Capabilities"))
element = el_none;
else if (qName.toLower() == QString("service"))
element = el_WMT_MS_Capabilities;
else if (qName.toLower() == QString("keywordlist"))
element = el_Service;
else if (qName.toLower() == QString("contactinformation"))
element = el_Service;
else if (qName.toLower() == QString("contactpersonprimary"))
element = el_ContactInformation;
else if (qName.toLower() == QString("contactaddress"))
element = el_ContactInformation;
else if (qName.toLower() == QString("capability"))
element = el_WMT_MS_Capabilities;
else if (qName.toLower() == QString("request"))
element = el_Capability;
else if (qName.toLower() == QString("getcapabilities"))
element = el_Request;
else if (qName.toLower() == QString("dcptype"))
el2 = el_none;
else if (qName.toLower() == QString("http"))
el2 = el_DCPType;
else if (qName.toLower() == QString("get"))
el2 = el_HTTP;
else if (qName.toLower() == QString("post"))
el2 = el_HTTP;
else if (qName.toLower() == QString("getmap"))
element = el_Request;
else if (qName.toLower() == QString("getfeatureinfo"))
element = el_Request;
else if (qName.toLower() == QString("exception"))
element = el_Capability;
else if (qName.toLower() == QString("layer"))
{
lcount--;
 
if (lcount == 0)
element = el_Capability;
else
element = el_Layer;
}
else if (qName.toLower() == QString("metadataurl"))
element = el_Layer;
else if (qName.toLower() == QString("legendurl"))
element = el_Layer;
else if (qName.toLower() == QString("style"))
element = el_Layer;
 
return true;
}
 
bool wmsSelectorWidget::characters (const QString& chraw)
{
if (chraw.at(0) == QChar('\n'))
{
line++;
return true;
}
 
QString ch = chraw.trimmed();
 
if (ch.length() == 0)
return true;
 
if (element == el_Service || element == el_ContactInformation ||
element == el_ContactPersonPrimary || element == el_ContactAddress)
{
if (attribute == at_Name)
Service.Name = ch;
else if (attribute == at_Title)
Service.Title = ch;
else if (attribute == at_Abstract)
Service.Abstract = ch;
else if (attribute == at_ContactPerson)
Service.ContactPerson = ch;
else if (attribute == at_ContactOrganisation)
Service.ContactOrganisation = ch;
else if (attribute == at_ContactElectronicMailAddress)
Service.ContactElectronicMailAddress = ch;
else if (attribute == at_ContactPosition)
Service.ContactPosition = ch;
else if (attribute == at_AddressType)
Service.AddressType = ch;
else if (attribute == at_Address)
Service.Address = ch;
else if (attribute == at_City)
Service.City = ch;
else if (attribute == at_StateOrProvince)
Service.StateOrProvince = ch;
else if (attribute == at_PostCode)
Service.PostCode = ch;
else if (attribute == at_Country)
Service.Country = ch;
else if (attribute == at_ContactVoiceTelephone)
Service.ContactVoiceTelephone = ch;
else if (attribute == at_ContactFacsimileTelephone)
Service.ContactFacsimileTelephone = ch;
else if (attribute == at_Fees)
Service.Fees = ch;
else if (attribute == at_AccessConstraints)
Service.AccessConstraints = ch;
}
else if (element == el_GetCapabilities)
{
if (attribute == at_Format)
Request.GetCapabilities.Format << ch;
}
else if (element == el_GetMap)
{
if (attribute == at_Format)
Request.GetMap.Format << ch;
}
else if (element == el_GetFeatureInfo)
{
if (attribute == at_Format)
Request.GetFeatureInfo.Format << ch;
}
else if (element == el_Exception)
{
if (attribute == at_Format)
Exception << ch;
}
else if (element == el_Layer)
{
if (attribute == at_Name)
Layer->Name = ch;
else if (attribute == at_Title)
Layer->Title = ch;
else if (attribute == at_Abstract)
Layer->Abstract = ch;
else if (attribute == at_SRS)
Layer->SRS << ch;
else if (attribute == at_CRS)
Layer->CRS << ch;
}
else if (element == el_Style)
{
STYLE *akt = findLastStyle(Layer);
 
if (!Layer->style)
{
Layer->style = allocateStyle();
akt = Layer->style;
}
 
if (!akt)
{
KMessageBox::error(this, i18n("Fatal error at line %1: No, or unable to allocate memory for a style!").arg(line));
return false;
}
 
if (attribute == at_Name)
akt->Name = ch;
else if (attribute == at_Title)
akt->Title = ch;
}
 
return true;
}
 
void wmsSelectorWidget::getCapabilities()
{
if (file.exists())
file.remove();
 
if (!file.open(QIODevice::WriteOnly))
{
KMessageBox::information(this,
i18n("Unable to save the file %1: %2.").arg(file.fileName()).arg(file.errorString()),
i18n("WMS capabilities"));
 
return;
}
 
#ifndef QT_NO_OPENSSL
QHttp::ConnectionMode mode = (urlWMS->url().protocol().toLower() == "https") ? QHttp::ConnectionModeHttps : QHttp::ConnectionModeHttp;
#else
QHttp::ConnectionMode mode = QHttp::ConnectionModeHttp;
#endif
http->setHost(urlWMS->url().host(), mode, (urlWMS->url().port() == -1) ? 0 : urlWMS->url().port());
 
if (!urlWMS->url().user().isEmpty())
http->setUser(urlWMS->url().user(), urlWMS->url().pass());
 
httpRequestAborted = false;
id = http->get(urlWMS->url().url() + "?VERSION=1.1.1&REQUEST=GetCapabilities&SERVICE=WMS", &file);
// Show a progress dialog
progressDialog->setVisible(true);
progressDialog->setWindowTitle(i18n("Getting capabilities"));
progressDialog->setLabelText(i18n("Downloading capabilities."));
}
 
bool wmsSelectorWidget::parseWMS()
{
QXmlSimpleReader reader;
LAYER *aktLayer;
 
QXmlInputSource source (&file);
reader.setContentHandler (this);
reader.parse (source);
 
// Put the result into the elements of the mask
aktLayer = firstLayer;
 
while (aktLayer)
{
if (!aktLayer->Name.isEmpty()) // Do we have a valid layer?
actionLayer->availableListWidget()->addItem(aktLayer->Name);
 
aktLayer = aktLayer->next;
}
 
return true;
}
 
void wmsSelectorWidget::cancelDownload()
{
httpRequestAborted = true;
http->abort();
}
 
void wmsSelectorWidget::WMSrequestFinished(int requestId, bool error)
{
if (requestId != id)
return;
 
if (httpRequestAborted)
{
file.close();
file.remove();
progressDialog->hide();
return;
}
 
progressDialog->hide();
file.close();
 
if (error)
{
file.remove();
KMessageBox::information(this, i18n("Download failed: %1.").arg(http->errorString()), i18n("WMS capabilities"));
}
else
{
parseWMS();
}
}
 
void wmsSelectorWidget::readResponseHeader(const QHttpResponseHeader &responseHeader)
{
switch (responseHeader.statusCode())
{
case 200: // Ok
case 301: // Moved Permanently
case 302: // Found
case 303: // See Other
case 307: // Temporary Redirect
// these are not error conditions
break;
 
default:
KMessageBox::information(this,
i18n("Download failed: %1.").arg(responseHeader.reasonPhrase()),
i18n("WMS capabilities"));
httpRequestAborted = true;
progressDialog->hide();
http->abort();
}
}
 
void wmsSelectorWidget::updateDataReadProgress(int bytesRead, int totalBytes)
{
if (httpRequestAborted)
return;
 
progressDialog->progressBar()->setMaximum(totalBytes);
progressDialog->progressBar()->setValue(bytesRead);
}
 
void wmsSelectorWidget::slotAuthenticationRequired(const QString &hostName, quint16, QAuthenticator *authenticator)
{
QDialog dlg;
Ui::Dialog ui;
 
ui.setupUi(&dlg);
dlg.adjustSize();
ui.siteDescription->setText(i18n("%1 at %2").arg(authenticator->realm()).arg(hostName));
 
if (dlg.exec() == QDialog::Accepted)
{
authenticator->setUser(ui.userEdit->text());
authenticator->setPassword(ui.passwordEdit->text());
}
}
 
#ifndef QT_NO_OPENSSL
void wmsSelectorWidget::sslErrors(const QList<QSslError> &errors)
{
QString errorString;
 
foreach (const QSslError &error, errors)
{
if (!errorString.isEmpty())
errorString += ", ";
 
errorString += error.errorString();
}
 
if (KMessageBox::warningContinueCancel(this,
i18n("One or more SSL errors has occurred: %1").arg(errorString),
i18n("WMS capabilities")) == KMessageBox::Continue)
{
http->ignoreSslErrors();
}
}
#endif
 
void wmsSelectorWidget::initializeParser()
{
LAYER *aktLayer;
 
Service.Name.clear();
Service.Title.clear();
Service.Abstract.clear();
Service.OnlineResource.clear();
Service.Type.clear();
Service.ContactPerson.clear();
Service.ContactOrganisation.clear();
Service.ContactPosition.clear();
Service.AddressType.clear();
Service.Address.clear();
Service.City.clear();
Service.StateOrProvince.clear();
Service.PostCode.clear();
Service.Country.clear();
Service.ContactVoiceTelephone.clear();
Service.ContactFacsimileTelephone.clear();
Service.ContactElectronicMailAddress.clear();
Service.Fees.clear();
Service.AccessConstraints.clear();
 
Request.GetCapabilities.Format.clear();
Request.GetCapabilities.Get.clear();
Request.GetCapabilities.Post.clear();
Request.GetMap.Format.clear();
Request.GetMap.Get.clear();
Request.GetMap.Post.clear();
 
Request.GetFeatureInfo.Format.clear();
Request.GetFeatureInfo.Get.clear();
Request.GetFeatureInfo.Post.clear();
 
if (Layer)
{
LAYER *nl;
 
aktLayer = Layer;
 
while (aktLayer)
{
aktLayer->opaque = false;
aktLayer->noSubsets = false;
aktLayer->queryable = false;
aktLayer->cascaded = false;
aktLayer->Name.clear();
aktLayer->Title.clear();
aktLayer->Abstract.clear();
aktLayer->SRS.clear();
aktLayer->LatLon.maxx = 0.0;
aktLayer->LatLon.maxy = 0.0;
aktLayer->LatLon.minx = 0.0;
aktLayer->LatLon.miny = 0.0;
aktLayer->Bounding.maxx = 0.0;
aktLayer->Bounding.maxy = 0.0;
aktLayer->Bounding.minx = 0.0;
aktLayer->Bounding.miny = 0.0;
aktLayer->scaleMin = 0.0;
aktLayer->scaleMax = 0.0;
 
if (aktLayer->style)
{
STYLE *ns, *akt;
 
akt = aktLayer->style;
 
while (akt)
{
akt->Name.clear();
akt->Title.clear();
akt->Format.clear();
akt->LegendURL.clear();
ns = akt->next;
delete akt;
akt = ns;
}
 
aktLayer->style = 0;
}
 
nl = aktLayer->next;
delete aktLayer;
aktLayer = nl;
}
 
Layer = 0;
firstLayer = 0;
}
}
 
LAYER *wmsSelectorWidget::allocateLayer()
{
LAYER *aktLayer, *last;
 
if (Layer)
{
last = Layer;
 
while (last)
{
if (!last->next)
break;
 
last = last->next;
}
 
aktLayer = new LAYER;
aktLayer->next = 0;
last->next = aktLayer;
Layer = aktLayer;
}
else
{
aktLayer = new LAYER;
aktLayer->next = 0;
Layer = last = firstLayer = aktLayer;
}
aktLayer->opaque = false;
aktLayer->noSubsets = false;
aktLayer->queryable = false;
aktLayer->cascaded = false;
aktLayer->Name.clear();
aktLayer->Title.clear();
aktLayer->Abstract.clear();
aktLayer->SRS.clear();
aktLayer->LatLon.maxx = 0.0;
aktLayer->LatLon.maxy = 0.0;
aktLayer->LatLon.minx = 0.0;
aktLayer->LatLon.miny = 0.0;
aktLayer->LatLon.SRS.clear();
aktLayer->Bounding.maxx = 0.0;
aktLayer->Bounding.maxy = 0.0;
aktLayer->Bounding.minx = 0.0;
aktLayer->Bounding.miny = 0.0;
aktLayer->Bounding.SRS.clear();
aktLayer->scaleMin = 0.0;
aktLayer->scaleMax = 0.0;
aktLayer->style = 0;
return aktLayer;
}
 
STYLE *wmsSelectorWidget::allocateStyle()
{
STYLE *akt;
 
akt = new STYLE;
akt->Name.clear();
akt->Title.clear();
akt->Format.clear();
akt->LegendURL.clear();
akt->next = 0;
return akt;
}
 
STYLE *wmsSelectorWidget::findLastStyle(LAYER *l)
{
STYLE *akt;
 
if (!l)
return 0;
 
akt = l->style;
 
while (akt)
{
if (!akt->next)
return akt;
 
akt = akt->next;
}
 
return 0;
}
 
bool wmsSelectorWidget::writeWMSTag(double llat, double llon, double rlat, double rlon, int width, int height)
{
#if defined HAVE_GDAL
QFile fl(MAP);
QString xml, s, srs, crs, styles, bSize, ext;
QDir dir = QDir::home();
QString path = dir.absolutePath();
int item;
double _llat, _llon, _rlat, _rlon;
 
if (!fl.open(QIODevice::ReadWrite | QIODevice::Truncate))
{
KMessageBox::error (this, i18n("Error opening or creating the WMS tag file!\nPlease check file name and/or permissions."));
return false;
}
 
KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
KConfigGroup wms (&cfg, "WMS");
 
xml = "<GDAL_WMS>\n";
xml += " <Service name=\"WMS\">\n";
xml += " <Version>" + WMSVersion + "</Version>\n";
xml += " <ServerURL>" + urlWMS->url().url() + "?</serverURL>\n";
_llon = llon;
_llat = llat;
_rlon = rlon;
_rlat = rlat;
 
if (firstLayer && firstLayer->SRS.size())
srs = firstLayer->SRS.at(0);
else
srs = QString("EPSG:4326");
 
xml += " <SRS>" + srs + "</SRS>\n";
 
if (firstLayer && firstLayer->CRS.size())
crs = firstLayer->CRS.at(0);
else
crs = QString("EPSG:4326");
 
xml += " <CRS>" + crs + "</CRS>\n";
xml += " <ImageFormat>image/";
xml += "png";
ext = QString(".png");
xml += "</ImageFormat>\n";
 
xml += " <Layers>";
QListWidget *lw = actionLayer->selectedListWidget();
s.clear();
 
for (int i = 0; i < lw->count(); i++)
{
QListWidgetItem *lwi;
 
if (i > 0 && i < lw->count())
{
xml += ",";
s += ",";
}
 
lwi = lw->item(i);
xml += lwi->text();
}
 
xml += "</Layers>\n";
 
if (StyleCommas)
xml += " <Styles>" + s + "</Styles>\n";
else
xml += " <Styles></Styles>\n";
 
xml += " <BBoxOrder>xyXY</BBoxOrder>\n";
xml += " </Service>\n";
xml += " <DataWindow>\n";
s.sprintf ("%f", _llat);
xml += " <UpperLeftX>" + s + "</UpperLeftX>\n";
s.sprintf ("%f", _llon);
xml += " <UpperLeftY>" + s + "</UpperLeftY>\n";
s.sprintf ("%f", _rlat);
xml += " <LowerRightX>" + s + "</LowerRightX>\n";
s.sprintf ("%f", _rlon);
xml += " <LowerRightY>" + s + "</LowerRightY>\n";
s.sprintf ("%d", width);
xml += " <SizeX>" + s + "</SizeX>\n";
s.sprintf ("%d", height);
xml += " <SizeY>" + s + "</SizeY>\n";
xml += " </DataWindow>\n";
 
xml += " <Projection>" + srs + "</Projection>\n";
xml += " <BandsCount>" + QString("%1").arg(edBands->value()) + "</BandsCount>\n";
item = wms.readEntry("Tile", 2);
 
switch (item)
{
case 0: bSize = QString("64"); break;
case 1: bSize = QString("128"); break;
case 2: bSize = QString("256"); break;
case 3: bSize = QString("512"); break;
case 4: bSize = QString("1024"); break;
default: bSize = QString("256");
}
 
xml += " <BlockSizeX>" + bSize + "</BlockSizeX>\n";
xml += " <BlockSizeY>" + bSize + "</BlockSizeY>\n";
xml += " <OverviewCount>" + wms.readEntry("Overview", QString("10")) + "</OverviewCount>\n";
xml += " <Cache>\n";
xml += " <Path>" + path + "/.gdalwmscache" + "</Path>\n";
xml += " <Depth>" + wms.readEntry("Depth", QString("2")) + "</Depth>\n";
xml += " <Extension>" + ext + "</Extension>\n";
xml += " </Cache>\n";
QString adv((wms.readEntry("Advice", true)) ? "true" : "false");
QString ver((wms.readEntry("Verify", false)) ? "true" : "false");
 
xml += " <OfflineMode>false</OfflineMode>\n";
xml += " <AdviseRead>" + adv + "</AdviseRead>\n";
xml += " <VerifyAdviseRead>" + ver + "</VerifyAdviseRead>\n";
xml += "</GDAL_WMS>\n";
 
write (fl.handle(), xml.toAscii().data(), strlen (xml.toAscii().data()));
fl.close();
#endif
return true;
}
 
void wmsSelectorWidget::setDimension(double &minx, double &miny, double &maxx, double &maxy, QListWidgetItem *item = 0)
{
double cx, cy;
/*LAYER *akt;
 
if (!firstLayer)
return;
//std::cout << "minx: " << firstLayer->LatLon.minx << "miny: " << firstLayer->LatLon.miny << "maxx: " << firstLayer->LatLon.maxx << "maxy: " << firstLayer->LatLon.maxy << std::endl;
cx = cy = 0.0;
akt = firstLayer;
 
while (akt)
{
cx = akt->LatLon.minx + (akt->LatLon.maxx - akt->LatLon.minx) / 2.0;
cy = akt->LatLon.miny + (akt->LatLon.maxy - akt->LatLon.miny) / 2.0;
 
if ((cx != 0.0 || cy != 0.0) && !item)
break;
 
if (item && item->text() == akt->Name && cx != 0.0 && cy != 0.0)
break;
 
akt = akt->next;
}
 
if (cx == 0.0 && cy == 0.0)
{ // Schloss Schönbrunn in Vienna
cx = 16.298223 + (0.014108 / 2.0);
cy = 48.177103 + (0.003554 / 2.0);
}
*/
cx = edLat->value();
cy = edLon->value();
 
minx = cx - (0.014108 / 2.0);
maxx = cx + (0.014108 / 2.0);
miny = cy + (0.003554 / 2.0);
maxy = cy - (0.003554 / 2.0);
 
// edLat->setValue(cx);
// edLon->setValue(cy);
}
 
#include "wmsselectorwidget.moc"
 
/sportwatcher/trunk/src/sportwatcherwidget.cpp
56,6 → 56,7
#include <gdal/ogrsf_frmts.h>
#include <gdal/gdalwarper.h>
#include <gdal/ogrsf_frmts.h>
#include "GDALError.h"
#endif
 
#include "garmin.h"
78,6 → 79,16
double lat;
} posn_type;
 
#if defined HAVE_GDAL
typedef struct ERRMSG
{
char msg[4096];
ERRMSG *next;
}ERRMSG;
 
ERRMSG *firstError;
#endif
 
sportwatcherWidget::sportwatcherWidget(QWidget *parent)
{
ui_sportwatcherWidgetBase.setupUi(this);
84,6 → 95,7
 
#if defined HAVE_GDAL
mFactor = 10; // Factor to calculate square pixels
firstError = 0;
#endif
mama = parent;
gmn = 0;
125,6 → 137,11
MAP = ic.readEntry("MAP", QDir::home().absolutePath() + "/.sportwatcher/track.wms");
Units = ic.readEntry("Units", 0);
MapType = ic.readEntry("MapType", 7);
#ifdef HAVE_GDAL
// set our own error handler here
CPLSetErrorHandler((CPLErrorHandler)spwErrorHandler);
#endif
 
}
 
sportwatcherWidget::~sportwatcherWidget()
131,6 → 148,10
{
destroy();
delete kl;
#ifdef HAVE_GDAL
// destroy the error handler here
CPLSetErrorHandler(NULL);
#endif
}
 
void sportwatcherWidget::destroy()
675,6 → 696,7
// We dont care about page margins of a printer. Instead we assume
// a frame from about 20mm arround the page. European paper size is
// A4 (210x297mm) and the output is optimized for this.
totdist = 0;
extMil[0] = 20.0;
extMil[1] = 20.0;
extMil[2] = 210.0 - 20.0;
2914,7 → 2936,9
if (mapLap != lap)
mapLap = lap;
 
y2 = x2 = 0;
#if defined HAVE_GDAL
nXSize = nYSize = 0;
KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
KConfigGroup wms (&cfg, "WMS");
bool square = wms.readEntry("Square", false);
3112,6 → 3136,8
GDALDataType tRasterType;
double adfMinMax[2];
 
pCT = pCTb = pCTr = pCTg = pCTa = 0;
tTypeLen = 0;
pafScanlineRed = pafScanlineGreen = pafScanlineBlue = pafScanlineAlpha = 0;
Fgeo = true;
/*
3768,11 → 3794,11
 
// Information on left side
if (cuType == 0)
paint.drawText((height + 4) * -1, 3, height - 2, lineHeight, Qt::AlignCenter, i18n((Units == 1) ? "Elevation (ft)" : "Elevation (m)"));
paint.drawText((height + 4) * -1, 3, height - 2, lineHeight, Qt::AlignCenter, i18n("Elevation (%1)").arg((Units == 1) ? "ft" : "m"));
else if (cuType == 1)
paint.drawText((height + 4) * -1, 3, height - 2, lineHeight, Qt::AlignCenter, i18n((Units == 1) ? "Speed (mph)" : "Speed (km/h)"));
paint.drawText((height + 4) * -1, 3, height - 2, lineHeight, Qt::AlignCenter, i18n("Speed (%1)").arg((Units == 1) ? "mph" : "km/h"));
else
paint.drawText((height + 4) * -1, 3, height - 2, lineHeight, Qt::AlignCenter, i18n((Units == 1) ? "Elevation (ft)" : "Elevation (m)"));
paint.drawText((height + 4) * -1, 3, height - 2, lineHeight, Qt::AlignCenter, i18n("Elevation (%1)").arg((Units == 1) ? "ft" : "m"));
 
if (cuType == 2)
paint.setPen(QPen(red, 1, Qt::SolidLine));
3783,7 → 3809,7
if (cuType < 2)
paint.drawText((height + 4) * -1, width - 1 - lineHeight, height - 2, lineHeight, Qt::AlignCenter, i18n("Heart Rate (bpm)"));
else
paint.drawText((height + 4) * -1, width - 1 - lineHeight, height - 2, lineHeight, Qt::AlignCenter, i18n((Units == 1) ? "Speed (mph)" : "Speed (km/h)"));
paint.drawText((height + 4) * -1, width - 1 - lineHeight, height - 2, lineHeight, Qt::AlignCenter, i18n("Speed (%1)").arg((Units == 1) ? "mph" : "km/h"));
 
paint.restore();
paint.setPen(QPen(mark, 1, Qt::SolidLine));
4278,10 → 4304,9
{
QPainter ptHR, ptElevation, ptSpeed;
int width, height, wdHR, htHR, wdElev, htElev, wdSpeed, htSpeed;
int i, secs, cuType;
int i, secs;
int lineHeight, margin_left, margin_right, margin_bottom;
int x1, y1, x2, y2; // Coordinates
bool meterHR;
double maxHeight, minHeight, maxSpeed, minSpeed;
int maxHr, minHr, rh, rhHR, rhElev, rhSpeed;
POINT *point;
4300,6 → 4325,9
if (!ActivePrint && (!DIRTY || curTab != 2))
return;
 
w_tick = h_tick = 0.0;
rh = 0;
width = height = 0;
// Get the dimensions of the available draw area
// First for heart rate
if (!ActivePrint)
4519,8 → 4547,8
 
// Information on right side
ptHR.drawText((htHR + 4) * -1, wdHR - 1 - lineHeight, htHR - 2, lineHeight, Qt::AlignCenter, i18n("Heart Rate (bpm)"));
ptElevation.drawText((htElev + 4) * -1, wdElev - 1 - lineHeight, htElev - 2, lineHeight, Qt::AlignCenter, i18n((Units == 1) ? "Elevation (ft)" : "Elevation (m)"));
ptSpeed.drawText((htSpeed + 4) * -1, wdSpeed - 1 - lineHeight, htSpeed - 2, lineHeight, Qt::AlignCenter, i18n((Units == 1) ? "Speed (mph)" : "Speed (km/h)"));
ptElevation.drawText((htElev + 4) * -1, wdElev - 1 - lineHeight, htElev - 2, lineHeight, Qt::AlignCenter, i18n("Elevation (%1)").arg((Units == 1) ? "ft" : "m"));
ptSpeed.drawText((htSpeed + 4) * -1, wdSpeed - 1 - lineHeight, htSpeed - 2, lineHeight, Qt::AlignCenter, i18n("Speed (%1)").arg((Units == 1) ? "mph" : "km/h"));
 
// restore to normal
ptHR.restore();
4701,23 → 4729,11
x1 = margin_left + 1;
x2 = wdHR - margin_right - 1;
 
if (meterHR)
{
double hrscale = rh / (double)(maxHr - minHr);
ay1 = (double)rh - (double)(lower1 - minHr) * hrscale;
ay2 = (double)rh - (double)(lower2 - minHr) * hrscale;
ay3 = (double)rh - (double)(lower3 - minHr) * hrscale;
ay4 = (double)rh - (double)(upper3 - minHr) * hrscale;
ay5 = (double)rh - (double)(avg_hr - minHr) * hrscale;
}
else
{
ay1 = (double)rh - (double)(lower1 - minHr) * htiHR;
ay2 = (double)rh - (double)(lower2 - minHr) * htiHR;
ay3 = (double)rh - (double)(lower3 - minHr) * htiHR;
ay4 = (double)rh - (double)(upper3 - minHr) * htiHR;
ay5 = (double)rh - (double)(avg_hr - minHr) * htiHR;
}
ay1 = (double)rh - (double)(lower1 - minHr) * htiHR;
ay2 = (double)rh - (double)(lower2 - minHr) * htiHR;
ay3 = (double)rh - (double)(lower3 - minHr) * htiHR;
ay4 = (double)rh - (double)(upper3 - minHr) * htiHR;
ay5 = (double)rh - (double)(avg_hr - minHr) * htiHR;
 
ptHR.setPen(QPen(barcol2, 1, Qt::DashLine)); // color for limits
 
4801,7 → 4817,7
 
avgHlast = avgHeight;
// If wanted, even the lines
if (Contour && hEc > 0 && cuType != 0)
if (Contour && hEc > 0)
{
double alt[100], avg, avg1, avg2, avg3, avg4;
int a, pos;
5857,5 → 5873,89
 
#endif
 
#ifdef HAVE_GDAL
void spwErrorHandler(CPLErr err, int num, const char *msg)
{
ERRMSG *akt;
char et[32], hv0[4096];
 
if (err == CE_None || !msg)
return;
 
if (err == CE_Fatal)
std::cerr << "ERROR " << num << ": " << msg << endl;
 
if (!firstError)
{
firstError = new ERRMSG;
memset (firstError, 0, sizeof(ERRMSG));
akt = firstError;
}
else
{
akt = firstError;
 
while (akt)
{
if (!akt->next)
break;
 
akt = akt->next;
}
 
akt->next = new ERRMSG;
akt = akt->next;
memset (akt, 0, sizeof(ERRMSG));
}
 
switch (err)
{
case CE_None: strcpy (et, "None"); break;
case CE_Debug: strcpy (et, "DEBUG"); break;
case CE_Warning: strcpy (et, "Warning"); break;
case CE_Failure: strcpy (et, "Failure"); break;
case CE_Fatal: strcpy (et, "Fatal"); break;
}
 
memset(hv0, 0, sizeof(hv0));
strncpy (hv0, msg, 4000);
sprintf (akt->msg, "ERROR TYPE %s - %d: %s", et, num, hv0);
}
 
void destroyErrors()
{
ERRMSG *akt;
 
if (!firstError)
return;
 
akt = firstError;
 
while (akt)
{
firstError = akt->next;
delete akt;
akt = firstError;
}
 
firstError = 0;
}
 
QString catGDALError()
{
QString err;
ERRMSG *akt = firstError;
 
while (akt)
{
err += QString(akt->msg) + "\n";
akt = akt->next;
}
 
destroyErrors();
return err;
}
#endif
 
#include "sportwatcherwidget.moc"
 
/sportwatcher/trunk/src/wmscapabilitieswidget.h
0,0 → 1,53
//
// C++ Interface:
//
// Description:
//
//
// Author: Andreas Theofilu <andreas@theosys.at>, (C) 2009
//
// Copyright: See COPYING file that comes with this distribution
//
//
 
#ifndef WMSCAPABILITIESWIDGET_H
#define WMSCAPABILITIESWIDGET_H
 
#include <QDialog>
#include <QString>
#include <KLineEdit>
#include <KListWidget>
#include "ui_wmscapabilitieswidgetbase.h"
 
class wmsCapabilitiesWidget : public QDialog, private Ui::wmsCapabilitiesWidgetBase
{
Q_OBJECT
 
public:
wmsCapabilitiesWidget (QWidget* parent = 0, Qt::WFlags fl = 0);
~wmsCapabilitiesWidget();
/*$PUBLIC_FUNCTIONS$*/
void setPerson(QString s) { edPerson->setText(s); };
void setOrg(QString s) { edOrg->setText(s); };
void setPhone(QString s) { edPhone->setText(s); };
void setFax(QString s) { edFax->setText(s); };
void setMail(QString s) { edMail->setText(s); };
void setCapabilitiesGet(QString s) { edCapabilitiesGet->setText(s); };
void setCapabilitiesPost(QString s) { edCapabilitiesPost->setText(s); };
void setFormat(QString s) { edFormat->setText(s); };
void setMapGet(QString s) { edMapGet->setText(s); };
void setMapPost(QString s) { edMapPost->setText(s); };
void addFormats(QString s) { liFormats->addItem(s); };
 
public slots:
/*$PUBLIC_SLOTS$*/
 
protected:
/*$PROTECTED_FUNCTIONS$*/
 
protected slots:
/*$PROTECTED_SLOTS$*/
};
 
#endif