Subversion Repositories public

Rev

Rev 283 | Rev 285 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 283 Rev 284
Line 19... Line 19...
19
#include <QImage>
19
#include <QImage>
20
#include <QtNetwork>
20
#include <QtNetwork>
21
#include <QListWidget>
21
#include <QListWidget>
22
#include <QPainter>
22
#include <QPainter>
23
#include <QCheckBox>
23
#include <QCheckBox>
-
 
24
#include <QSlider>
24
#include <KStandardDirs>
25
#include <KStandardDirs>
25
#include <KConfig>
26
#include <KConfig>
26
#include <KLocale>
27
#include <KLocale>
27
#include <KMessageBox>
28
#include <KMessageBox>
28
#include <KGlobalSettings>
29
#include <KGlobalSettings>
Line 48... Line 49...
48
#include "wmscapabilitieswidget.h"
49
#include "wmscapabilitieswidget.h"
49
 
50
 
50
// The capital cities from all countries of the world
51
// The capital cities from all countries of the world
51
// Source: Wikipedia, Google
52
// Source: Wikipedia, Google
52
CITIES Cities[] = {
53
CITIES Cities[] = {
-
 
54
	{ " - - - - - - -", 0.0, 0.0 },
53
	{ "Abidjan", 5.3363, -4.0277 },
55
	{ "Abidjan", 5.3363, -4.0277 },
54
	{ "Abu Dhabi", 24.4758, 54.3714 },
56
	{ "Abu Dhabi", 24.4758, 54.3714 },
55
	{ "Abuja", 9.0578, 7.4892 },
57
	{ "Abuja", 9.0578, 7.4892 },
56
	{ "Accora", 5.5555, -0.196 },
58
	{ "Accora", 5.5555, -0.196 },
57
	{ "Addis Abeba", 9.0164, 38.7579 },
59
	{ "Addis Abeba", 9.0164, 38.7579 },
Line 80... Line 82...
80
	{ "Belmopan", 17.2617, -88.7785 },
82
	{ "Belmopan", 17.2617, -88.7785 },
81
	{ "Berlin", 52.5234, 13.4105 },
83
	{ "Berlin", 52.5234, 13.4105 },
82
	{ "Bern", 46.9479, 7.4479 },
84
	{ "Bern", 46.9479, 7.4479 },
83
	{ "Bratislava", 48.1483, 17.1068 },
85
	{ "Bratislava", 48.1483, 17.1068 },
84
	{ "Bridgetown", 13.0935, -59.6106 },
86
	{ "Bridgetown", 13.0935, -59.6106 },
85
	{ "Brüssel", 50.8462, 4.3545 },
87
	{ "Bruessel", 50.8462, 4.3545 },
86
	{ "Budapest", 47.4984, 19.0403 },
88
	{ "Budapest", 47.4984, 19.0403 },
87
	{ "Buenos Aires", -34.6084, -58.3733 },
89
	{ "Buenos Aires", -34.6084, -58.3733 },
88
	{ "Bukarest", 44.4304, 26.1225 },
90
	{ "Bukarest", 44.4304, 26.1225 },
89
	{ "Den Haag", 52.0782, 4.3134 },
91
	{ "Den Haag", 52.0782, 4.3134 },
90
	{ "Dublin", 53.3441, -6.2677 },
92
	{ "Dublin", 53.3441, -6.2677 },
Line 120... Line 122...
120
	{ "Wien", 48.2091, 16.3727 },
122
	{ "Wien", 48.2091, 16.3727 },
121
	{ "Zagreb", 45.8149, 15.9784 },
123
	{ "Zagreb", 45.8149, 15.9784 },
122
	{ "", 0.0, 0.0 }
124
	{ "", 0.0, 0.0 }
123
};
125
};
124
 
126
 
-
 
127
ZOOM zoom[] = {
-
 
128
	{ 0.014108, 0.003554 },
-
 
129
	{ 0.028216, 0.007108 },
-
 
130
	{ 0.056432, 0.014216 },
-
 
131
	{ 0.112864, 0.028432 },
-
 
132
	{ 0.225728, 0.056864 },
-
 
133
	{ 0.451456, 0.113728 },
-
 
134
	{ 0.902912, 0.227456 },
-
 
135
	{ 1.805824, 0.454912 },
-
 
136
	{ 3.611648, 0.909824 },
-
 
137
	{ 7.223296, 1.819648 }
-
 
138
};
-
 
139
 
125
wmsSelectorWidget::wmsSelectorWidget (QWidget* parent, Qt::WFlags fl)
140
wmsSelectorWidget::wmsSelectorWidget (QWidget* parent, Qt::WFlags fl)
126
		: QDialog (parent, fl), Ui::wmsSelectorWidgetBase()
141
		: QDialog (parent, fl), Ui::wmsSelectorWidgetBase()
127
{
142
{
128
	// Initialize some variables
143
	// Initialize some variables
129
	http = 0;
144
	http = 0;
130
	httpRequestAborted = false;
145
	httpRequestAborted = false;
131
	progressDialog = 0;
146
	progressDialog = 0;
132
	id = 0;
147
	id = 0;
133
	Layer = 0;
148
	Layer = 0;
134
	firstLayer = 0;
149
	firstLayer = 0;
-
 
150
	zLevel = 0;
135
	initializeParser();
151
	initializeParser();
136
	// Initialize the GUI elements
152
	// Initialize the GUI elements
137
	setupUi (this);
153
	setupUi (this);
138
	// Initialize the environment
154
	// Initialize the environment
139
	urlWMS->setMode(KFile::File | KFile::ExistingOnly);
155
	urlWMS->setMode(KFile::File | KFile::ExistingOnly);
Line 142... Line 158...
142
	urlWMS->setUrl (ic.readEntry("ServerURL", "http://onearth.jpl.nasa.gov/wms.cgi"));
158
	urlWMS->setUrl (ic.readEntry("ServerURL", "http://onearth.jpl.nasa.gov/wms.cgi"));
143
	Data = ic.readEntry("Data", QDir::home().absolutePath() + "/.sportwatcher");
159
	Data = ic.readEntry("Data", QDir::home().absolutePath() + "/.sportwatcher");
144
	MAP = ic.readEntry("MAP", QDir::home().absolutePath() + "/.sportwatcher/track.wms");
160
	MAP = ic.readEntry("MAP", QDir::home().absolutePath() + "/.sportwatcher/track.wms");
145
	file.setFileName(Data + "/capabilities.xml");	// File to save WMS capabilities
161
	file.setFileName(Data + "/capabilities.xml");	// File to save WMS capabilities
146
	edBands->setValue(ic.readEntry("Bands", 3));
162
	edBands->setValue(ic.readEntry("Bands", 3));
-
 
163
	Layers = ic.readEntry("Layer", QString("modis,global_mosaic"));
147
	StyleCommas = true;
164
	StyleCommas = true;
148
	cbStyles->setChecked(StyleCommas);
165
	cbStyles->setChecked(StyleCommas);
149
	// Fill the cities combo box
166
	// Fill the cities combo box
150
	int i = 0;
167
	int i = 0;
151
 
168
 
Line 166... Line 183...
166
	connect(progressDialog, SIGNAL(cancelClicked()), this, SLOT(cancelDownload()));
183
	connect(progressDialog, SIGNAL(cancelClicked()), this, SLOT(cancelDownload()));
167
#ifndef QT_NO_OPENSSL
184
#ifndef QT_NO_OPENSSL
168
	connect(http, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(sslErrors(const QList<QSslError> &)));
185
	connect(http, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(sslErrors(const QList<QSslError> &)));
169
#endif
186
#endif
170
	getCapabilities();
187
	getCapabilities();
-
 
188
	Init = true;
171
}
189
}
172
 
190
 
173
wmsSelectorWidget::~wmsSelectorWidget()
191
wmsSelectorWidget::~wmsSelectorWidget()
174
{
192
{
175
	if (file.exists())
193
	if (file.exists())
Line 269... Line 287...
269
void wmsSelectorWidget::slotStyles(bool mode)
287
void wmsSelectorWidget::slotStyles(bool mode)
270
{
288
{
271
	StyleCommas = mode;
289
	StyleCommas = mode;
272
}
290
}
273
 
291
 
-
 
292
void wmsSelectorWidget::slotSliderPressed()
-
 
293
{
-
 
294
	sliderPressed = true;
-
 
295
}
-
 
296
 
-
 
297
void wmsSelectorWidget::slotSliderReleased()
-
 
298
{
-
 
299
double minx, miny, maxx, maxy;
-
 
300
 
-
 
301
	sliderPressed = false;
-
 
302
 
-
 
303
	if (!sliderPressed && actionLayer->selectedListWidget()->count() > 0)
-
 
304
	{
-
 
305
	   setDimension(minx, miny, maxx, maxy, 0);
-
 
306
	   grabPicture(minx, miny, maxx, maxy);
-
 
307
	}
-
 
308
}
-
 
309
 
-
 
310
void wmsSelectorWidget::slotValueChanged(int val)
-
 
311
{
-
 
312
double minx, miny, maxx, maxy;
-
 
313
 
-
 
314
	zLevel = val;
-
 
315
 
-
 
316
	if (!sliderPressed && actionLayer->selectedListWidget()->count() > 0)
-
 
317
	{
-
 
318
	   setDimension(minx, miny, maxx, maxy, 0);
-
 
319
	   grabPicture(minx, miny, maxx, maxy);
-
 
320
	}
-
 
321
}
-
 
322
 
274
/*
323
/*
275
 * This functions try to get a small example picture from the WMS server
324
 * This functions try to get a small example picture from the WMS server
276
 */
325
 */
277
bool wmsSelectorWidget::grabPicture(double minx, double miny, double maxx, double maxy)
326
bool wmsSelectorWidget::grabPicture(double minx, double miny, double maxx, double maxy)
278
{
327
{
Line 290... Line 339...
290
bool Fgeo = false;
339
bool Fgeo = false;
291
QPainter paint;
340
QPainter paint;
292
 
341
 
293
	QApplication::setOverrideCursor (QCursor(Qt::WaitCursor));
342
	QApplication::setOverrideCursor (QCursor(Qt::WaitCursor));
294
	width = lbPreview->width();
343
	width = lbPreview->width();
295
	height = lbPreview->height() - 2;
344
	height = lbPreview->height() - 6;	// necessary to prevent growing of dialog window
296
	nXSize = nYSize = 0;
345
	nXSize = nYSize = 0;
297
 
346
 
298
	if (!writeWMSTag(minx, miny, maxx, maxy, width, height))
347
	if (!writeWMSTag(minx, miny, maxx, maxy, width, height))
299
	{
348
	{
300
	   QApplication::restoreOverrideCursor();
349
	   QApplication::restoreOverrideCursor();
Line 1038... Line 1087...
1038
	}
1087
	}
1039
 
1088
 
1040
	return true;
1089
	return true;
1041
}
1090
}
1042
 
1091
 
-
 
1092
QString wmsSelectorWidget::getLayers()
-
 
1093
{
-
 
1094
QString la;
-
 
1095
QListWidget *lw = actionLayer->selectedListWidget();
-
 
1096
 
-
 
1097
	for (int i = 0; i < lw->count(); i++)
-
 
1098
	{
-
 
1099
	   QListWidgetItem *item = lw->item(i);
-
 
1100
	   la += item->text();
-
 
1101
 
-
 
1102
	   if (i < lw->count())
-
 
1103
	      la += ",";
-
 
1104
	}
-
 
1105
 
-
 
1106
	return la;
-
 
1107
}
-
 
1108
 
-
 
1109
QString wmsSelectorWidget::getStyles()
-
 
1110
{
-
 
1111
QString la;
-
 
1112
QListWidget *lw = actionLayer->selectedListWidget();
-
 
1113
int anz = lw->count();
-
 
1114
 
-
 
1115
	if (cbStyles->isChecked() && anz > 1)
-
 
1116
	   la.fill(',', anz - 1);
-
 
1117
 
-
 
1118
	return la;
-
 
1119
}
-
 
1120
 
1043
void wmsSelectorWidget::cancelDownload()
1121
void wmsSelectorWidget::cancelDownload()
1044
{
1122
{
1045
	httpRequestAborted = true;
1123
	httpRequestAborted = true;
1046
	http->abort();
1124
	http->abort();
1047
}
1125
}
Line 1068... Line 1146...
1068
	   KMessageBox::information(this, i18n("Download failed: %1.").arg(http->errorString()), i18n("WMS capabilities"));
1146
	   KMessageBox::information(this, i18n("Download failed: %1.").arg(http->errorString()), i18n("WMS capabilities"));
1069
	}
1147
	}
1070
	else
1148
	else
1071
	{
1149
	{
1072
	   parseWMS();
1150
	   parseWMS();
-
 
1151
	
-
 
1152
	   if (Init)
-
 
1153
	   {
-
 
1154
	      // Set the already selected layers to the selected box
-
 
1155
	      // This will be done only, if the box with the available layers
-
 
1156
	      // is not empty. Otherwise we've to assume, that there was an
-
 
1157
	      // error getting the capabilities of the server.
-
 
1158
	      if (actionLayer->availableListWidget()->count() > 0)
-
 
1159
	      {
-
 
1160
	      QListWidget *item = actionLayer->selectedListWidget();
-
 
1161
	      QListWidget *av = actionLayer->availableListWidget();
-
 
1162
	      QStringList laList = Layers.split(',');
-
 
1163
 
-
 
1164
		 for (int i = 0; i < laList.size(); i++)
-
 
1165
		 {
-
 
1166
		    QList<QListWidgetItem*> qlwi = av->findItems(laList.at(i), Qt::MatchExactly);
-
 
1167
 
-
 
1168
		    if (qlwi.size() == 1)
-
 
1169
		    {
-
 
1170
		       item->addItem(laList.at(i));
-
 
1171
		       av->takeItem(av->row(qlwi.at(0)));
-
 
1172
		    }
-
 
1173
		 }
-
 
1174
	      }
-
 
1175
 
-
 
1176
	      Init = false;
-
 
1177
	   }
1073
	}
1178
	}
1074
}
1179
}
1075
 
1180
 
1076
void wmsSelectorWidget::readResponseHeader(const QHttpResponseHeader &responseHeader)
1181
void wmsSelectorWidget::readResponseHeader(const QHttpResponseHeader &responseHeader)
1077
{
1182
{
Line 1325... Line 1430...
1325
#if defined HAVE_GDAL
1430
#if defined HAVE_GDAL
1326
QFile fl(MAP);
1431
QFile fl(MAP);
1327
QString xml, s, srs, crs, styles, bSize, ext;
1432
QString xml, s, srs, crs, styles, bSize, ext;
1328
QDir dir = QDir::home();
1433
QDir dir = QDir::home();
1329
QString path = dir.absolutePath();
1434
QString path = dir.absolutePath();
1330
int item;
1435
//int item;
1331
double _llat, _llon, _rlat, _rlon;
1436
double _llat, _llon, _rlat, _rlon;
1332
 
1437
 
1333
	if (!fl.open(QIODevice::ReadWrite | QIODevice::Truncate))
1438
	if (!fl.open(QIODevice::ReadWrite | QIODevice::Truncate))
1334
	{
1439
	{
1335
	   KMessageBox::error (this, i18n("Error opening or creating the WMS tag file!\nPlease check file name and/or permissions."));
1440
	   KMessageBox::error (this, i18n("Error opening or creating the WMS tag file!\nPlease check file name and/or permissions."));
Line 1339... Line 1444...
1339
	KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
1444
	KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
1340
	KConfigGroup wms (&cfg, "WMS");
1445
	KConfigGroup wms (&cfg, "WMS");
1341
 
1446
 
1342
	xml = "<GDAL_WMS>\n";
1447
	xml = "<GDAL_WMS>\n";
1343
	xml += "   <Service name=\"WMS\">\n";
1448
	xml += "   <Service name=\"WMS\">\n";
-
 
1449
 
-
 
1450
	if (!WMSVersion.isEmpty())
1344
	xml += "      <Version>" + WMSVersion + "</Version>\n";
1451
	   xml += "      <Version>" + WMSVersion + "</Version>\n";
-
 
1452
	else
-
 
1453
	   xml += "      <Version>1.1.1</Version>\n";
-
 
1454
 
1345
	xml += "      <ServerURL>" + urlWMS->url().url() + "?</serverURL>\n";
1455
	xml += "      <ServerURL>" + urlWMS->url().url() + "?</serverURL>\n";
1346
	_llon = llon;
1456
	_llon = llon;
1347
	_llat = llat;
1457
	_llat = llat;
1348
	_rlon = rlon;
1458
	_rlon = rlon;
1349
	_rlat = rlat;
1459
	_rlat = rlat;
Line 1408... Line 1518...
1408
	xml += "      <SizeY>" + s + "</SizeY>\n";
1518
	xml += "      <SizeY>" + s + "</SizeY>\n";
1409
	xml += "   </DataWindow>\n";
1519
	xml += "   </DataWindow>\n";
1410
 
1520
 
1411
	xml += "   <Projection>" + srs + "</Projection>\n";
1521
	xml += "   <Projection>" + srs + "</Projection>\n";
1412
	xml += "   <BandsCount>" + QString("%1").arg(edBands->value()) + "</BandsCount>\n";
1522
	xml += "   <BandsCount>" + QString("%1").arg(edBands->value()) + "</BandsCount>\n";
1413
	item = wms.readEntry("Tile", 2);
1523
/*	item = wms.readEntry("Tile", 2);
1414
 
1524
 
1415
	switch (item)
1525
	switch (item)
1416
	{
1526
	{
1417
	   case 0: bSize = QString("64"); break;
1527
	   case 0: bSize = QString("64"); break;
1418
	   case 1: bSize = QString("128"); break;
1528
	   case 1: bSize = QString("128"); break;
1419
	   case 2: bSize = QString("256"); break;
1529
	   case 2: bSize = QString("256"); break;
1420
	   case 3: bSize = QString("512"); break;
1530
	   case 3: bSize = QString("512"); break;
1421
	   case 4: bSize = QString("1024"); break;
1531
	   case 4: bSize = QString("1024"); break;
1422
	   default: bSize = QString("256");
1532
	   default: bSize = QString("256");
1423
	}
1533
	}
1424
 
1534
*/
-
 
1535
	bSize = QString("256");
1425
	xml += "   <BlockSizeX>" + bSize + "</BlockSizeX>\n";
1536
	xml += "   <BlockSizeX>" + bSize + "</BlockSizeX>\n";
1426
	xml += "   <BlockSizeY>" + bSize + "</BlockSizeY>\n";
1537
	xml += "   <BlockSizeY>" + bSize + "</BlockSizeY>\n";
1427
	xml += "   <OverviewCount>" + wms.readEntry("Overview", QString("10")) + "</OverviewCount>\n";
1538
	xml += "   <OverviewCount>" + wms.readEntry("Overview", QString("10")) + "</OverviewCount>\n";
1428
	xml += "   <Cache>\n";
1539
	xml += "   <Cache>\n";
1429
	xml += "      <Path>" + path + "/.gdalwmscache" + "</Path>\n";
1540
	xml += "      <Path>" + path + "/.gdalwmscache" + "</Path>\n";
Line 1444... Line 1555...
1444
	return true;
1555
	return true;
1445
}
1556
}
1446
 
1557
 
1447
void wmsSelectorWidget::setDimension(double &minx, double &miny, double &maxx, double &maxy, QListWidgetItem *item = 0)
1558
void wmsSelectorWidget::setDimension(double &minx, double &miny, double &maxx, double &maxy, QListWidgetItem *item = 0)
1448
{
1559
{
1449
double cx, cy;
1560
double cx, cy, levX, levY;
1450
/*LAYER *akt;
1561
LAYER *akt;
1451
 
1562
 
1452
	if (!firstLayer)
-
 
1453
	   return;
-
 
1454
//std::cout << "minx: " << firstLayer->LatLon.minx << "miny: " << firstLayer->LatLon.miny << "maxx: " << firstLayer->LatLon.maxx << "maxy: " << firstLayer->LatLon.maxy << std::endl;
-
 
1455
	cx = cy = 0.0;
1563
	cx = cy = 0.0;
1456
	akt = firstLayer;
1564
	akt = firstLayer;
1457
 
1565
 
1458
	while (akt)
1566
	if (zLevel >= 0 && zLevel < 10)
1459
	{
1567
	{
1460
	   cx = akt->LatLon.minx + (akt->LatLon.maxx - akt->LatLon.minx) / 2.0;
-
 
1461
	   cy = akt->LatLon.miny + (akt->LatLon.maxy - akt->LatLon.miny) / 2.0;
-
 
1462
 
-
 
1463
	   if ((cx != 0.0 || cy != 0.0) && !item)
-
 
1464
	      break;
1568
	   levX = zoom[zLevel].x;
1465
 
-
 
1466
	   if (item && item->text() == akt->Name && cx != 0.0 && cy != 0.0)
-
 
1467
	      break;
-
 
1468
 
-
 
1469
	   akt = akt->next;
1569
	   levY = zoom[zLevel].y;
1470
	}
1570
	}
-
 
1571
	else
1471
 
1572
	{
1472
	if (cx == 0.0 && cy == 0.0)
1573
	   levX = zoom[0].x;
1473
	{	// Schloss Schönbrunn in Vienna
-
 
1474
	   cx = 16.298223 + (0.014108 / 2.0);
-
 
1475
	   cy = 48.177103 + (0.003554 / 2.0);
1574
	   levY = zoom[0].y;
1476
	}
1575
	}
1477
*/
1576
 
1478
	cx = edLat->value();
1577
	cx = edLat->value();
1479
	cy = edLon->value();
1578
	cy = edLon->value();
1480
 
1579
 
1481
	minx = cx - (0.014108 / 2.0);
1580
	if (cx == 0.0 && cy == 0.0)
-
 
1581
	{
-
 
1582
	   while (akt)
-
 
1583
	   {
-
 
1584
	      cx = akt->LatLon.minx + (akt->LatLon.maxx - akt->LatLon.minx) / 2.0;
-
 
1585
	      cy = akt->LatLon.miny + (akt->LatLon.maxy - akt->LatLon.miny) / 2.0;
-
 
1586
 
-
 
1587
	      if ((cx != 0.0 || cy != 0.0) && !item)
-
 
1588
	         break;
-
 
1589
 
-
 
1590
	      if (item && item->text() == akt->Name && cx != 0.0 && cy != 0.0)
-
 
1591
	         break;
-
 
1592
 
-
 
1593
	      akt = akt->next;
-
 
1594
	   }
-
 
1595
 
1482
	maxx = cx + (0.014108 / 2.0);
1596
	   if (cx == 0.0 && cy == 0.0)
-
 
1597
	   {	// Schloss Schoenbrunn in Vienna
1483
	miny = cy + (0.003554 / 2.0);
1598
	      cx = 16.298223 + (0.014108 / 2.0);
1484
	maxy = cy - (0.003554 / 2.0);
1599
	      cy = 48.177103 + (0.003554 / 2.0);
-
 
1600
	   }
-
 
1601
 
-
 
1602
	   edLat->setValue(cx);
-
 
1603
	   edLon->setValue(cy);
-
 
1604
	}
1485
 
1605
 
1486
//	edLat->setValue(cx);
1606
	minx = cx - (levX / 2.0);
-
 
1607
	maxx = cx + (levX / 2.0);
-
 
1608
	miny = cy + (levY / 2.0);
1487
//	edLon->setValue(cy);
1609
	maxy = cy - (levY / 2.0);
1488
}
1610
}
1489
 
1611
 
1490
#include "wmsselectorwidget.moc"
1612
#include "wmsselectorwidget.moc"
1491
 
1613