source: ntrip/trunk/BNC/bnctabledlg.cpp@ 3336

Last change on this file since 3336 was 3336, checked in by mervart, 13 years ago
File size: 24.2 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
8// http://www.fsv.cvut.cz
9//
10// Email: euref-ip@bkg.bund.de
11//
12// This program is free software; you can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation, version 2.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: bncTableDlg
30 *
31 * Purpose: Displays the source table, allows mountpoints selection
32 *
33 * Author: L. Mervart
34 *
35 * Created: 24-Dec-2005
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iostream>
42
43#include "bnctabledlg.h"
44#include "bncgetthread.h"
45#include "bncnetqueryv1.h"
46#include "bncnetqueryv2.h"
47#include "bncsettings.h"
48#include "bncmap.h"
49
50using namespace std;
51
52// Constructor
53////////////////////////////////////////////////////////////////////////////
54bncTableDlg::bncTableDlg(QWidget* parent) : QDialog(parent) {
55
56 setMinimumSize(600,400);
57 setWindowTitle(tr("Add Streams from Caster"));
58
59 QVBoxLayout* mainLayout = new QVBoxLayout(this);
60
61 int ww = QFontMetrics(font()).width('w');
62
63 _casterPortLineEdit = new QLineEdit();
64 _casterPortLineEdit->setMaximumWidth(9*ww);
65
66 _casterUserLineEdit = new QLineEdit();
67 _casterUserLineEdit->setMaximumWidth(9*ww);
68
69 _casterPasswordLineEdit = new QLineEdit();
70 _casterPasswordLineEdit->setMaximumWidth(9*ww);
71 _casterPasswordLineEdit->setEchoMode(QLineEdit::PasswordEchoOnEdit);
72
73 _casterHostComboBox = new QComboBox();
74 _casterHostComboBox->setMaxCount(10);
75 _casterHostComboBox->setDuplicatesEnabled(false);
76 _casterHostComboBox->setEditable(true);
77 _casterHostComboBox->setMinimumWidth(20*ww);
78 _casterHostComboBox->setMaximumWidth(20*ww);
79 connect(_casterHostComboBox, SIGNAL(currentIndexChanged(const QString&)),
80 this, SLOT(slotCasterHostChanged(const QString&)));
81 bncSettings settings;
82 settings.remove("casterHostList");
83 settings.remove("casterHost");
84 settings.remove("casterPort");
85 settings.remove("casterUser");
86 settings.remove("casterPassword");
87 QStringList casterUrlList = settings.value("casterUrlList").toStringList();
88 for (int ii = 0; ii < casterUrlList.count(); ii++) {
89 QUrl url(casterUrlList[ii]);
90 _casterHostComboBox->addItem(url.host());
91 }
92
93 _ntripVersionComboBox = new QComboBox();
94 _ntripVersionComboBox->addItems(QString("1,2,2s,R,U").split(","));
95 int kk = _ntripVersionComboBox->findText(settings.value("ntripVersion").toString());
96 if (kk != -1) {
97 _ntripVersionComboBox->setCurrentIndex(kk);
98 }
99 _ntripVersionComboBox->setMaximumWidth(5*ww);
100
101 _buttonCasterTable = new QPushButton(tr("Show"), this);
102 connect(_buttonCasterTable, SIGNAL(clicked()), this, SLOT(slotCasterTable()));
103 _buttonCasterTable->setMaximumWidth(5*ww);
104
105 // WhatsThis
106 // ---------
107 _casterUserLineEdit->setWhatsThis(tr("<p>Access to some streams on NTRIP broadcasters may be restricted. You'll need to enter a valid 'User ID' and 'Password' for access to these protected streams.</p><p>Accounts are usually provided per NTRIP broadcaster through a registration process. Register through <u>http://igs.bkg.bund.de/index_ntrip_reg.htm</u> for access to protected streams on <u>www.euref-ip.net</u> and <u>www.igs-ip.net</u>.</p>"));
108 _casterHostComboBox->setWhatsThis(tr("<p>Enter the NTRIP broadcaster hostname or IP number.</p><p>Note that EUREF and IGS operate NTRIP broadcasters at <u>http://www.euref-ip.net/home</u> and <u>http://www.igs-ip.net/home</u>.</p>"));
109 _casterPortLineEdit->setWhatsThis(tr("Enter the NTRIP broadcaster port number."));
110 _casterPasswordLineEdit->setWhatsThis(tr("Access to some streams on NTRIP broadcasters may be restricted. You'll need to enter a valid 'Password' for access to these protected streams."));
111
112 QGridLayout* editLayout = new QGridLayout;
113 editLayout->addWidget(new QLabel(tr("Caster host")), 0, 0);
114 editLayout->addWidget(_casterHostComboBox, 0, 1);
115 editLayout->addWidget(new QLabel(tr(" Caster port")), 0, 2, Qt::AlignRight);
116 editLayout->addWidget(_casterPortLineEdit, 0, 3);
117 editLayout->addWidget(new QLabel(tr("Casters table")), 0, 4, Qt::AlignRight);
118 editLayout->addWidget(_buttonCasterTable, 0, 5);
119 editLayout->addWidget(new QLabel(tr("User")), 1, 0, Qt::AlignRight);
120 editLayout->addWidget(_casterUserLineEdit, 1, 1);
121 editLayout->addWidget(new QLabel(tr("Password")), 1, 2, Qt::AlignRight);
122 editLayout->addWidget(_casterPasswordLineEdit, 1, 3);
123 editLayout->addWidget(new QLabel(tr(" NTRIP Version")),1, 4, Qt::AlignRight);
124 editLayout->addWidget(_ntripVersionComboBox, 1, 5);
125
126 mainLayout->addLayout(editLayout);
127
128 _buttonCasterTable->setWhatsThis(tr("<p>Hit 'Show' for a table of known NTRIP broadcaster installations as maintained at <u>www.rtcm-ntrip.org/home.</u></p><p>A window opens which allows to select a broadcaster for stream retrieval.</p>"));
129 _ntripVersionComboBox->setWhatsThis(tr("<p>Select the NTRIP transport protocol version you want to use. Implemented options are:<br>&nbsp; 1:&nbsp; NTRIP version 1, TCP/IP<br>&nbsp; 2:&nbsp; NTRIP version 2, TCP/IP mode<br>&nbsp; R:&nbsp; NTRIP Version 2, RTSP/RTP mode<br>&nbsp; U:&nbsp; NTRIP Version 2, UDP mode<br>Select option '1' if you are not sure whether the NTRIP broadcaster supports NTRIP version 2.</p><p>Note that RTSP/RTP (option 'R') and UDP (option 'U') are not accepted by proxies and sometimes not supported by mobile Internet Service Providers.</p>"));
130
131 _table = new QTableWidget(this);
132 _table->setWhatsThis(tr("<p>Use the 'Get Table' button to download the sourcetable from the selected NTRIP broadcaster. Select the desired streams line by line, using +Shift and +Ctrl when necessary. Hit 'OK' to return to the main window.</p><p>Pay attention to data field 'format'. Keep in mind that BNC can only decode and convert streams that come in RTCM Version 2.x, RTCM Version 3.x, or RTIGS format. See data field 'format-details' for available message types and their repetition rates in brackets.</p><p>The content of data field 'nmea' tells you whether a stream comes from a virtual reference station (VRS).</p>"));
133 connect(_table, SIGNAL(itemSelectionChanged()),
134 this, SLOT(slotSelectionChanged()));
135 mainLayout->addWidget(_table);
136
137 _buttonWhatsThis = new QPushButton(tr("Help=Shift+F1"), this);
138 connect(_buttonWhatsThis, SIGNAL(clicked()), this, SLOT(slotWhatsThis()));
139
140 _buttonGet = new QPushButton(tr("Get table"), this);
141 _buttonGet->setDefault(true);
142 connect(_buttonGet, SIGNAL(clicked()), this, SLOT(slotGetTable()));
143
144 _buttonMap = new QPushButton(tr("Map"), this);
145 _buttonMap->setEnabled(false);
146 connect(_buttonMap, SIGNAL(clicked()), this, SLOT(slotShowMap()));
147
148 _buttonClose = new QPushButton(tr("Close"), this);
149 connect(_buttonClose, SIGNAL(clicked()), this, SLOT(close()));
150
151 _buttonSelect = new QPushButton(tr("Select"), this);
152 connect(_buttonSelect, SIGNAL(clicked()), this, SLOT(select()));
153
154 QHBoxLayout* buttonLayout = new QHBoxLayout;
155 buttonLayout->addWidget(_buttonWhatsThis);
156 buttonLayout->addStretch(1);
157 buttonLayout->addWidget(_buttonMap);
158 buttonLayout->addWidget(_buttonGet);
159 buttonLayout->addWidget(_buttonSelect);
160 buttonLayout->addWidget(_buttonClose);
161
162 mainLayout->addLayout(buttonLayout);
163}
164
165// Destructor
166////////////////////////////////////////////////////////////////////////////
167bncTableDlg::~bncTableDlg() {
168 delete _casterHostComboBox;
169 delete _casterPortLineEdit;
170 delete _casterUserLineEdit;
171 delete _casterPasswordLineEdit;
172 delete _ntripVersionComboBox;
173 delete _buttonGet;
174 delete _buttonClose;
175 delete _buttonSelect;
176 delete _buttonWhatsThis;
177 delete _buttonCasterTable;
178 delete _table;
179}
180
181// Read full caster table (static)
182////////////////////////////////////////////////////////////////////////////
183t_irc bncTableDlg::getFullTable(const QString& ntripVersion,
184 const QString& casterHost,
185 int casterPort, QStringList& allLines,
186 bool alwaysRead) {
187
188 static QMutex mutex;
189 static QMap<QString, QStringList> allTables;
190
191 QMutexLocker locker(&mutex);
192
193 if (!alwaysRead && allTables.find(casterHost) != allTables.end()) {
194 allLines = allTables.find(casterHost).value();
195 return success;
196 }
197
198 allLines.clear();
199
200 bncNetQuery* query = 0;
201 if (ntripVersion == "2" || ntripVersion == "2s") {
202 query = new bncNetQueryV2();
203 }
204 else {
205 query = new bncNetQueryV1();
206 }
207
208 QUrl url;
209 url.setHost(casterHost);
210 url.setPort(casterPort);
211 url.setPath("/");
212 if (ntripVersion == "2s") {
213 url.setScheme("https");
214 }
215 else {
216 url.setScheme("http");
217 }
218
219 QByteArray outData;
220 query->waitForRequestResult(url, outData);
221 if (query->status() == bncNetQuery::finished) {
222 QTextStream in(outData);
223 QString line = in.readLine();
224 while ( !line.isNull() ) {
225 allLines.append(line);
226 line = in.readLine();
227 }
228 allTables.insert(casterHost, allLines);
229 delete query;
230 return success;
231 }
232 else {
233 delete query;
234 return failure;
235 }
236}
237
238// Read Table from Caster
239////////////////////////////////////////////////////////////////////////////
240void bncTableDlg::slotGetTable() {
241
242 _buttonGet->setEnabled(false);
243 _buttonMap->setEnabled(true);
244 _buttonCasterTable->setEnabled(false);
245
246 if ( getFullTable(_ntripVersionComboBox->currentText(),
247 _casterHostComboBox->currentText(),
248 _casterPortLineEdit->text().toInt(),
249 _allLines, true) != success ) {
250 QMessageBox::warning(0, "BNC", "Cannot retrieve table of data");
251 _buttonGet->setEnabled(true);
252 return;
253 }
254
255 static const QStringList labels = QString("mountpoint,identifier,format,"
256 "format-details,carrier,system,network,country,lat,long,"
257 "nmea,solution,generator,compress.,auth.,fee,bitrate,"
258 "misc").split(",");
259
260 QStringList lines;
261 QStringListIterator it(_allLines);
262 while (it.hasNext()) {
263 QString line = it.next();
264 if (line.indexOf("STR") == 0) {
265 QStringList hlp = line.split(";");
266 if (hlp.size() > labels.size()) {
267 lines.push_back(line);
268 }
269 }
270 }
271
272 if (lines.size() > 0) {
273 _table->setSelectionMode(QAbstractItemView::ExtendedSelection);
274 _table->setSelectionBehavior(QAbstractItemView::SelectRows);
275 _table->setColumnCount(labels.size());
276 _table->setRowCount(lines.size());
277 for (int nRow = 0; nRow < lines.size(); nRow++) {
278 QStringList columns = lines[nRow].split(";");
279 for (int ic = 1; ic < columns.size(); ic++) {
280 if (ic == 11) {
281 if (columns[ic] == "0") {
282 columns[ic] = "no";
283 } else {
284 columns[ic] = "yes";
285 }
286 }
287 QTableWidgetItem* item = new QTableWidgetItem(columns[ic]);
288 item->setFlags(item->flags() & ~Qt::ItemIsEditable);
289 _table->setItem(nRow, ic-1, item);
290 }
291 }
292 _table->setHorizontalHeaderLabels(labels);
293 _table->setSortingEnabled(true);
294 int ww = QFontMetrics(this->font()).width('w');
295 _table->horizontalHeader()->resizeSection( 0,10*ww);
296 _table->horizontalHeader()->resizeSection( 1,10*ww);
297 _table->horizontalHeader()->resizeSection( 2, 8*ww);
298 _table->horizontalHeader()->resizeSection( 3,22*ww);
299 _table->horizontalHeader()->resizeSection( 4, 5*ww);
300 _table->horizontalHeader()->resizeSection( 5, 8*ww);
301 _table->horizontalHeader()->resizeSection( 6, 8*ww);
302 _table->horizontalHeader()->resizeSection( 7, 7*ww);
303 _table->horizontalHeader()->resizeSection( 8, 6*ww);
304 _table->horizontalHeader()->resizeSection( 9, 6*ww);
305 _table->horizontalHeader()->resizeSection(10, 6*ww);
306 _table->horizontalHeader()->resizeSection(11, 6*ww);
307 _table->horizontalHeader()->resizeSection(12,15*ww);
308 _table->horizontalHeader()->resizeSection(13, 8*ww);
309 _table->horizontalHeader()->resizeSection(14, 5*ww);
310 _table->horizontalHeader()->resizeSection(15, 5*ww);
311 _table->horizontalHeader()->resizeSection(16, 7*ww);
312 _table->horizontalHeader()->resizeSection(17,15*ww);
313 _table->sortItems(0);
314 }
315}
316
317// Show world map
318////////////////////////////////////////////////////////////////////////////
319void bncTableDlg::slotShowMap() {
320
321 bncMap* winMap = new bncMap(this);
322 winMap->setGeometry( x(), int(y()+height()*1.3), 880, 440 );
323
324 connect(this, SIGNAL(newPoint(QPointF, QString, QPen, double)),
325 winMap, SLOT(slotNewPoint(QPointF, QString, QPen, double)));
326
327 connect(this, SIGNAL(fitMap()),
328 winMap, SLOT(slotFitMap() ));
329
330 connect(this, SIGNAL(fitFont()),
331 winMap, SLOT(slotFitFont() ));
332
333 _buttonMap->setEnabled(false);
334 showSourceTable();
335 winMap->exec();
336 _buttonMap->setEnabled(true);
337
338 disconnect(this, SIGNAL(newPoint(QPointF, QString, QPen, double)),
339 winMap, SLOT(slotNewPoint(QPointF, QString, QPen, double)));
340
341 disconnect(this, SIGNAL(fitMap()),
342 winMap, SLOT(slotFitMap() ));
343
344 disconnect(this, SIGNAL(fitFont()),
345 winMap, SLOT(slotFitFont() ));
346
347 delete winMap;
348}
349
350// Show world map
351////////////////////////////////////////////////////////////////////////////
352void bncTableDlg::showSourceTable() {
353
354 for( int i = 0; i < _allLines.size(); i++ ){
355
356 if( _allLines.at(i).startsWith("STR") == true ){
357
358 QStringList tmp = _allLines.at(i).split(';');
359 if( tmp.size() > 0 ){
360
361 QPointF point;
362 point.setY( tmp.at(9).toDouble() );
363 point.setX( tmp.at(10).toDouble() );
364
365 QString site = tmp.at(1);
366 site.resize(4);
367
368 emit newPoint(point, site, QPen(QBrush(QColor(0,0,255,200)), 1.5), 1.5 );
369 }
370 }
371 }
372 emit fitMap();
373}
374
375
376// Select slot
377////////////////////////////////////////////////////////////////////////////
378void bncTableDlg::select() {
379
380 QString ntripVersion = _ntripVersionComboBox->currentText();
381
382 QUrl url;
383 if (ntripVersion == "2s") {
384 url.setScheme("https");
385 }
386 else {
387 url.setScheme("http");
388 }
389 url.setHost(_casterHostComboBox->currentText());
390 url.setPort(_casterPortLineEdit->text().toInt());
391 url.setUserName(QUrl::toPercentEncoding(_casterUserLineEdit->text()));
392 url.setPassword(QUrl::toPercentEncoding(_casterPasswordLineEdit->text()));
393 addUrl(url);
394
395 QStringList* mountPoints = new QStringList;
396 if (_table) {
397 for (int ir = 0; ir < _table->rowCount(); ir++) {
398 QTableWidgetItem* item = _table->item(ir,0);
399 QString site = _table->item(ir,0)->text();
400 QString format = _table->item(ir,2)->text();
401 QString latitude = _table->item(ir,8)->text();
402 QString longitude = _table->item(ir,9)->text();
403 QString nmea = _table->item(ir,10)->text();
404 format.replace(" ", "_");
405 if (_table->isItemSelected(item)) {
406 url.setPath(item->text());
407 mountPoints->push_back(url.toString() + " " + format + " " + latitude
408 + " " + longitude + " " + nmea + " " + ntripVersion);
409
410 site.resize(4);
411 emit newPoint(QPointF(longitude.toDouble(),latitude.toDouble()), site,
412 QPen(QBrush(QColor(255,0,0,200)), 3.0), 3.0 );
413 }
414 }
415 }
416 emit newMountPoints(mountPoints);
417 emit fitFont();
418}
419
420// User changed the selection of mountPoints
421////////////////////////////////////////////////////////////////////////////
422void bncTableDlg::slotSelectionChanged() {
423 if (_table->selectedItems().isEmpty()) {
424 }
425}
426
427// Whats This Help
428void bncTableDlg::slotWhatsThis() {
429QWhatsThis::enterWhatsThisMode();
430}
431
432// Slot caster table
433////////////////////////////////////////////////////////////////////////////
434void bncTableDlg::slotCasterTable() {
435
436 _buttonCasterTable->setEnabled(false);
437 _casterHostComboBox->setEnabled(false);
438 _casterPortLineEdit->setEnabled(false);
439 _casterUserLineEdit->setEnabled(false);
440 _casterPasswordLineEdit->setEnabled(false);
441 _ntripVersionComboBox->setEnabled(false);
442 _buttonWhatsThis->setEnabled(false);
443 _buttonGet->setEnabled(false);
444 _buttonClose->setEnabled(false);
445 _buttonSelect->setEnabled(false);
446
447 bncCasterTableDlg* dlg =
448 new bncCasterTableDlg(_ntripVersionComboBox->currentText(), this);
449 dlg->move(this->pos().x()+50, this->pos().y()+50);
450 connect(dlg, SIGNAL(newCaster(QString, QString)),
451 this, SLOT(slotNewCaster(QString, QString)));
452 dlg->exec();
453 delete dlg;
454
455 _buttonCasterTable->setEnabled(true);
456 _casterHostComboBox->setEnabled(true);
457 _casterPortLineEdit->setEnabled(true);
458 _casterUserLineEdit->setEnabled(true);
459 _casterPasswordLineEdit->setEnabled(true);
460 _ntripVersionComboBox->setEnabled(true);
461 _buttonWhatsThis->setEnabled(true);
462 _buttonGet->setEnabled(true);
463 _buttonClose->setEnabled(true);
464 _buttonSelect->setEnabled(true);
465
466}
467
468// New caster selected
469////////////////////////////////////////////////////////////////////////////
470void bncTableDlg::slotNewCaster(QString newCasterHost, QString newCasterPort) {
471
472 _casterHostComboBox->insertItem(0, newCasterHost);
473 _casterHostComboBox->setCurrentIndex(0);
474 _casterUserLineEdit->setText("");
475 _casterPasswordLineEdit->setText("");
476 _casterPortLineEdit->setText(newCasterPort);
477
478 QString ntripVersion = _ntripVersionComboBox->currentText();
479
480 QUrl url;
481 if (ntripVersion == "2s") {
482 url.setScheme("https");
483 }
484 else {
485 url.setScheme("http");
486 }
487 url.setHost(newCasterHost);
488 url.setPort(newCasterPort.toInt());
489 addUrl(url);
490
491 _casterHostComboBox->setCurrentIndex(0);
492}
493
494// New caster selected
495////////////////////////////////////////////////////////////////////////////
496void bncTableDlg::addUrl(const QUrl& url) {
497 bncSettings settings;
498 QStringList oldUrlList = settings.value("casterUrlList").toStringList();
499 QStringList newUrlList;
500 newUrlList << url.toString();
501 for (int ii = 0; ii < oldUrlList.count(); ii++) {
502 QUrl oldUrl(oldUrlList[ii]);
503 if (url.host() != oldUrl.host()) {
504 newUrlList << oldUrl.toString();
505 }
506 }
507 settings.setValue("casterUrlList", newUrlList);
508 settings.sync();
509}
510
511// New caster selected in combobox
512////////////////////////////////////////////////////////////////////////////
513void bncTableDlg::slotCasterHostChanged(const QString& newHost) {
514 bncSettings settings;
515 QStringList casterUrlList = settings.value("casterUrlList").toStringList();
516 for (int ii = 0; ii < casterUrlList.count(); ii++) {
517 QUrl url(casterUrlList[ii]);
518 if (url.host() == newHost) {
519 _casterUserLineEdit->setText(
520 QUrl::fromPercentEncoding(url.userName().toAscii()));
521 _casterPasswordLineEdit->setText(
522 QUrl::fromPercentEncoding(url.password().toAscii()));
523 if (url.port() > 0) {
524 _casterPortLineEdit->setText(QString("%1").arg(url.port()));
525 }
526 else {
527 _casterPortLineEdit->setText("");
528 }
529 }
530 }
531}
532
533// Caster table
534////////////////////////////////////////////////////////////////////////////
535bncCasterTableDlg::bncCasterTableDlg(const QString& ntripVersion,
536 QWidget* parent) :
537 QDialog(parent) {
538
539 static const QStringList labels = QString("host,port,identifier,operator,nmea,country,lat,long,link").split(",");
540
541 _casterTable = new QTableWidget(this);
542
543 QUrl url;
544 url.setHost("www.rtcm-ntrip.org");
545 url.setPath("/");
546 if (ntripVersion == "2s") {
547 url.setPort(443);
548 url.setScheme("https");
549 }
550 else {
551 url.setPort(2101);
552 url.setScheme("http");
553 }
554
555 bncNetQuery* query = 0;
556 if (ntripVersion == "2" || ntripVersion == "2s") {
557 query = new bncNetQueryV2();
558 }
559 else {
560 query = new bncNetQueryV1();
561 }
562
563 QByteArray outData;
564 query->waitForRequestResult(url, outData);
565
566 QStringList lines;
567 if (query->status() == bncNetQuery::finished) {
568 QTextStream in(outData);
569 QString line = in.readLine();
570 while ( !line.isNull() ) {
571 line = in.readLine();
572 if (line.indexOf("CAS") == 0) {
573 QStringList hlp = line.split(";");
574 if (hlp.size() > labels.size()) {
575 lines.push_back(line);
576 }
577 }
578 }
579 }
580
581 delete query;
582
583 if (lines.size() > 0) {
584 _casterTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
585 _casterTable->setSelectionBehavior(QAbstractItemView::SelectRows);
586
587 QStringList hlp = lines[0].split(";");
588 _casterTable->setColumnCount(labels.size());
589 _casterTable->setRowCount(lines.size());
590
591 for (int nRow = 0; nRow < lines.size(); nRow++) {
592 QStringList columns = lines[nRow].split(";");
593 for (int ic = 1; ic < columns.size(); ic++) {
594 if (ic == 5) {
595 if (columns[ic] == "0") {
596 columns[ic] = "no";
597 } else {
598 columns[ic] = "yes";
599 }
600 }
601 QTableWidgetItem* item = new QTableWidgetItem(columns[ic]);
602 item->setFlags(item->flags() & ~Qt::ItemIsEditable);
603 _casterTable->setItem(nRow, ic-1, item);
604 }
605 }
606 }
607 _casterTable->setHorizontalHeaderLabels(labels);
608 _casterTable->setSortingEnabled(true);
609 _casterTable->sortItems(0);
610 int ww = QFontMetrics(this->font()).width('w');
611 _casterTable->horizontalHeader()->resizeSection(0,15*ww);
612 _casterTable->horizontalHeader()->resizeSection(1, 5*ww);
613 _casterTable->horizontalHeader()->resizeSection(2,15*ww);
614 _casterTable->horizontalHeader()->resizeSection(3,15*ww);
615 _casterTable->horizontalHeader()->resizeSection(4, 5*ww);
616 _casterTable->horizontalHeader()->resizeSection(5, 7*ww);
617 _casterTable->horizontalHeader()->resizeSection(6, 7*ww);
618 _casterTable->horizontalHeader()->resizeSection(7, 7*ww);
619 _casterTable->horizontalHeader()->resizeSection(8,15*ww);
620
621 _closeButton = new QPushButton("Cancel");
622 connect(_closeButton, SIGNAL(clicked()), this, SLOT(close()));
623 _closeButton->setMinimumWidth(8*ww);
624 _closeButton->setMaximumWidth(8*ww);
625
626 _okButton = new QPushButton(tr("OK"), this);
627 connect(_okButton, SIGNAL(clicked()), this, SLOT(slotAcceptCasterTable()));
628 _okButton->setMinimumWidth(8*ww);
629 _okButton->setMaximumWidth(8*ww);
630
631 _whatsThisButton = new QPushButton(tr("Help=Shift+F1"), this);
632 connect(_whatsThisButton, SIGNAL(clicked()), this, SLOT(slotWhatsThis()));
633 _whatsThisButton->setMinimumWidth(12*ww);
634 _whatsThisButton->setMaximumWidth(12*ww);
635
636 _casterTable->setWhatsThis(tr("<p>Select an NTRIP broadcaster and hit 'OK'.</p><p>See <u>http://www.rtcm-ntrip.org/home</u> for further details on known NTRIP broadcaster installations.</u>."));
637
638 QGridLayout* dlgLayout = new QGridLayout();
639 dlgLayout->addWidget(new QLabel(" List of NTRIP Broadcasters from www.rtcm-ntrip.org"), 0,0,1,3,Qt::AlignLeft);
640 dlgLayout->addWidget(_casterTable, 1, 0, 1, 3);
641 dlgLayout->addWidget(_whatsThisButton, 2, 0);
642 dlgLayout->addWidget(_closeButton, 2, 1, Qt::AlignRight);
643 dlgLayout->addWidget(_okButton, 2, 2);
644
645 setMinimumSize(600,400);
646 setWindowTitle(tr("Select Broadcaster"));
647 setLayout(dlgLayout);
648 resize(68*ww, 50*ww);
649 show();
650}
651
652// Caster table destructor
653////////////////////////////////////////////////////////////////////////////
654bncCasterTableDlg::~bncCasterTableDlg() {
655 delete _casterTable;
656 delete _okButton;
657 delete _closeButton;
658 delete _whatsThisButton;
659}
660
661// Caster table what's this
662////////////////////////////////////////////////////////////////////////////
663void bncCasterTableDlg:: slotWhatsThis() {
664 QWhatsThis::enterWhatsThisMode();
665}
666
667// Accept caster table
668////////////////////////////////////////////////////////////////////////////
669void bncCasterTableDlg::slotAcceptCasterTable() {
670 if (_casterTable) {
671 for (int ir = _casterTable->rowCount() - 1; ir >= 0 ; ir--) {
672 if (_casterTable->isItemSelected(_casterTable->item(ir,0))) {
673 emit newCaster(_casterTable->item(ir,0)->text(),
674 _casterTable->item(ir,1)->text());
675 }
676 }
677 }
678 QDialog::accept();
679}
Note: See TracBrowser for help on using the repository browser.