source: ntrip/trunk/BNC/src/bnctabledlg.cpp@ 4626

Last change on this file since 4626 was 4626, checked in by mervart, 12 years ago
File size: 24.1 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; 2s:&nbsp; NTRIP version 2 TCP/IP mode via SSL<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, or RTCM Version 3.x 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 bncSettings settings;
173 settings.setValue("ntripVersion", _ntripVersionComboBox->currentText());
174 delete _ntripVersionComboBox;
175 delete _buttonGet;
176 delete _buttonClose;
177 delete _buttonSelect;
178 delete _buttonWhatsThis;
179 delete _buttonCasterTable;
180 delete _table;
181}
182
183// Read full caster table (static)
184////////////////////////////////////////////////////////////////////////////
185t_irc bncTableDlg::getFullTable(const QString& ntripVersion,
186 const QString& casterHost,
187 int casterPort, QStringList& allLines,
188 bool alwaysRead) {
189
190 static QMutex mutex;
191 static QMap<QString, QStringList> allTables;
192
193 QMutexLocker locker(&mutex);
194
195 if (!alwaysRead && allTables.find(casterHost) != allTables.end()) {
196 allLines = allTables.find(casterHost).value();
197 return success;
198 }
199
200 allLines.clear();
201
202 bncNetQuery* query = 0;
203 if (ntripVersion == "2") {
204 query = new bncNetQueryV2(false);
205 }
206 else if (ntripVersion == "2s") {
207 query = new bncNetQueryV2(true);
208 }
209 else {
210 query = new bncNetQueryV1();
211 }
212
213 QUrl url;
214 url.setHost(casterHost);
215 url.setPort(casterPort);
216 url.setPath("/");
217 if (ntripVersion == "2s") {
218 url.setScheme("https");
219 }
220 else {
221 url.setScheme("http");
222 }
223
224 QByteArray outData;
225 query->waitForRequestResult(url, outData);
226 if (query->status() == bncNetQuery::finished) {
227 QTextStream in(outData);
228 QString line = in.readLine();
229 while ( !line.isNull() ) {
230 allLines.append(line);
231 line = in.readLine();
232 }
233 allTables.insert(casterHost, allLines);
234 delete query;
235 return success;
236 }
237 else {
238 delete query;
239 return failure;
240 }
241}
242
243// Read Table from Caster
244////////////////////////////////////////////////////////////////////////////
245void bncTableDlg::slotGetTable() {
246
247 _buttonGet->setEnabled(false);
248 _buttonMap->setEnabled(true);
249 _buttonCasterTable->setEnabled(false);
250
251 if ( getFullTable(_ntripVersionComboBox->currentText(),
252 _casterHostComboBox->currentText(),
253 _casterPortLineEdit->text().toInt(),
254 _allLines, true) != success ) {
255 QMessageBox::warning(0, "BNC", "Cannot retrieve table of data");
256 _buttonGet->setEnabled(true);
257 return;
258 }
259
260 static const QStringList labels = QString("mountpoint,identifier,format,"
261 "format-details,carrier,system,network,country,lat,long,"
262 "nmea,solution,generator,compress.,auth.,fee,bitrate,"
263 "misc").split(",");
264
265 QStringList lines;
266 QStringListIterator it(_allLines);
267 while (it.hasNext()) {
268 QString line = it.next();
269 if (line.indexOf("STR") == 0) {
270 QStringList hlp = line.split(";");
271 if (hlp.size() > labels.size()) {
272 lines.push_back(line);
273 }
274 }
275 }
276
277 if (lines.size() > 0) {
278 _table->setSelectionMode(QAbstractItemView::ExtendedSelection);
279 _table->setSelectionBehavior(QAbstractItemView::SelectRows);
280 _table->setColumnCount(labels.size());
281 _table->setRowCount(lines.size());
282 for (int nRow = 0; nRow < lines.size(); nRow++) {
283 QStringList columns = lines[nRow].split(";");
284 for (int ic = 1; ic < columns.size(); ic++) {
285 if (ic == 11) {
286 if (columns[ic] == "0") {
287 columns[ic] = "no";
288 } else {
289 columns[ic] = "yes";
290 }
291 }
292 QTableWidgetItem* item = new QTableWidgetItem(columns[ic]);
293 item->setFlags(item->flags() & ~Qt::ItemIsEditable);
294 _table->setItem(nRow, ic-1, item);
295 }
296 }
297 _table->setHorizontalHeaderLabels(labels);
298 _table->setSortingEnabled(true);
299 int ww = QFontMetrics(this->font()).width('w');
300 _table->horizontalHeader()->resizeSection( 0,10*ww);
301 _table->horizontalHeader()->resizeSection( 1,10*ww);
302 _table->horizontalHeader()->resizeSection( 2, 8*ww);
303 _table->horizontalHeader()->resizeSection( 3,22*ww);
304 _table->horizontalHeader()->resizeSection( 4, 5*ww);
305 _table->horizontalHeader()->resizeSection( 5, 8*ww);
306 _table->horizontalHeader()->resizeSection( 6, 8*ww);
307 _table->horizontalHeader()->resizeSection( 7, 7*ww);
308 _table->horizontalHeader()->resizeSection( 8, 6*ww);
309 _table->horizontalHeader()->resizeSection( 9, 6*ww);
310 _table->horizontalHeader()->resizeSection(10, 6*ww);
311 _table->horizontalHeader()->resizeSection(11, 6*ww);
312 _table->horizontalHeader()->resizeSection(12,15*ww);
313 _table->horizontalHeader()->resizeSection(13, 8*ww);
314 _table->horizontalHeader()->resizeSection(14, 5*ww);
315 _table->horizontalHeader()->resizeSection(15, 5*ww);
316 _table->horizontalHeader()->resizeSection(16, 7*ww);
317 _table->horizontalHeader()->resizeSection(17,15*ww);
318 _table->sortItems(0);
319 }
320}
321
322// Show world map
323////////////////////////////////////////////////////////////////////////////
324void bncTableDlg::slotShowMap() {
325
326 t_bncMap* bncMap = new t_bncMap(this);
327 bncMap->setGeometry( x(), int(y()+height()*1.3), 880, 440 );
328
329 connect(this, SIGNAL(newPoint(QPointF, QString, QPen, double)),
330 bncMap, SLOT(slotNewPoint(QPointF, QString, QPen, double)));
331
332 _buttonMap->setEnabled(false);
333 showSourceTable();
334 bncMap->exec();
335 _buttonMap->setEnabled(true);
336
337 disconnect(this, SIGNAL(newPoint(QPointF, QString, QPen, double)),
338 bncMap, SLOT(slotNewPoint(QPointF, QString, QPen, double)));
339
340 delete bncMap;
341}
342
343// Show world map
344////////////////////////////////////////////////////////////////////////////
345void bncTableDlg::showSourceTable() {
346
347 for( int i = 0; i < _allLines.size(); i++ ){
348
349 if( _allLines.at(i).startsWith("STR") == true ){
350
351 QStringList tmp = _allLines.at(i).split(';');
352 if( tmp.size() > 0 ){
353
354 QPointF point;
355 point.setY( tmp.at(9).toDouble() );
356 point.setX( tmp.at(10).toDouble() );
357
358 QString site = tmp.at(1);
359 site.resize(4);
360
361 emit newPoint(point, site, QPen(QBrush(QColor(0,0,255,200)), 1.5), 1.5 );
362 }
363 }
364 }
365 emit fitMap();
366}
367
368
369// Select slot
370////////////////////////////////////////////////////////////////////////////
371void bncTableDlg::select() {
372
373 QString ntripVersion = _ntripVersionComboBox->currentText();
374
375 QUrl url;
376 if (ntripVersion == "2s") {
377 url.setScheme("https");
378 }
379 else {
380 url.setScheme("http");
381 }
382 url.setHost(_casterHostComboBox->currentText());
383 url.setPort(_casterPortLineEdit->text().toInt());
384 url.setUserName(QUrl::toPercentEncoding(_casterUserLineEdit->text()));
385 url.setPassword(QUrl::toPercentEncoding(_casterPasswordLineEdit->text()));
386 addUrl(url);
387
388 QStringList* mountPoints = new QStringList;
389 if (_table) {
390 for (int ir = 0; ir < _table->rowCount(); ir++) {
391 QTableWidgetItem* item = _table->item(ir,0);
392 QString site = _table->item(ir,0)->text();
393 QString format = _table->item(ir,2)->text();
394 QString latitude = _table->item(ir,8)->text();
395 QString longitude = _table->item(ir,9)->text();
396 QString nmea = _table->item(ir,10)->text();
397 format.replace(" ", "_");
398 if (_table->isItemSelected(item)) {
399 url.setPath(item->text());
400 mountPoints->push_back(url.toString() + " " + format + " " + latitude
401 + " " + longitude + " " + nmea + " " + ntripVersion);
402
403 site.resize(4);
404 emit newPoint(QPointF(longitude.toDouble(),latitude.toDouble()), site,
405 QPen(QBrush(QColor(255,0,0,200)), 3.0), 3.0 );
406 }
407 }
408 }
409 emit newMountPoints(mountPoints);
410 emit fitFont();
411}
412
413// User changed the selection of mountPoints
414////////////////////////////////////////////////////////////////////////////
415void bncTableDlg::slotSelectionChanged() {
416 if (_table->selectedItems().isEmpty()) {
417 }
418}
419
420// Whats This Help
421void bncTableDlg::slotWhatsThis() {
422QWhatsThis::enterWhatsThisMode();
423}
424
425// Slot caster table
426////////////////////////////////////////////////////////////////////////////
427void bncTableDlg::slotCasterTable() {
428
429 _buttonCasterTable->setEnabled(false);
430 _casterHostComboBox->setEnabled(false);
431 _casterPortLineEdit->setEnabled(false);
432 _casterUserLineEdit->setEnabled(false);
433 _casterPasswordLineEdit->setEnabled(false);
434 _ntripVersionComboBox->setEnabled(false);
435 _buttonWhatsThis->setEnabled(false);
436 _buttonGet->setEnabled(false);
437 _buttonClose->setEnabled(false);
438 _buttonSelect->setEnabled(false);
439
440 bncCasterTableDlg* dlg =
441 new bncCasterTableDlg(_ntripVersionComboBox->currentText(), this);
442 dlg->move(this->pos().x()+50, this->pos().y()+50);
443 connect(dlg, SIGNAL(newCaster(QString, QString)),
444 this, SLOT(slotNewCaster(QString, QString)));
445 dlg->exec();
446 delete dlg;
447
448 _buttonCasterTable->setEnabled(true);
449 _casterHostComboBox->setEnabled(true);
450 _casterPortLineEdit->setEnabled(true);
451 _casterUserLineEdit->setEnabled(true);
452 _casterPasswordLineEdit->setEnabled(true);
453 _ntripVersionComboBox->setEnabled(true);
454 _buttonWhatsThis->setEnabled(true);
455 _buttonGet->setEnabled(true);
456 _buttonClose->setEnabled(true);
457 _buttonSelect->setEnabled(true);
458
459}
460
461// New caster selected
462////////////////////////////////////////////////////////////////////////////
463void bncTableDlg::slotNewCaster(QString newCasterHost, QString newCasterPort) {
464
465 _casterHostComboBox->insertItem(0, newCasterHost);
466 _casterHostComboBox->setCurrentIndex(0);
467 _casterUserLineEdit->setText("");
468 _casterPasswordLineEdit->setText("");
469 _casterPortLineEdit->setText(newCasterPort);
470
471 QString ntripVersion = _ntripVersionComboBox->currentText();
472
473 QUrl url;
474 if (ntripVersion == "2s") {
475 url.setScheme("https");
476 }
477 else {
478 url.setScheme("http");
479 }
480 url.setHost(newCasterHost);
481 url.setPort(newCasterPort.toInt());
482 addUrl(url);
483
484 _casterHostComboBox->setCurrentIndex(0);
485}
486
487// New caster selected
488////////////////////////////////////////////////////////////////////////////
489void bncTableDlg::addUrl(const QUrl& url) {
490 bncSettings settings;
491 QStringList oldUrlList = settings.value("casterUrlList").toStringList();
492 QStringList newUrlList;
493 newUrlList << url.toString();
494 for (int ii = 0; ii < oldUrlList.count(); ii++) {
495 QUrl oldUrl(oldUrlList[ii]);
496 if (url.host() != oldUrl.host()) {
497 newUrlList << oldUrl.toString();
498 }
499 }
500 settings.setValue("casterUrlList", newUrlList);
501}
502
503// New caster selected in combobox
504////////////////////////////////////////////////////////////////////////////
505void bncTableDlg::slotCasterHostChanged(const QString& newHost) {
506 bncSettings settings;
507 QStringList casterUrlList = settings.value("casterUrlList").toStringList();
508 for (int ii = 0; ii < casterUrlList.count(); ii++) {
509 QUrl url(casterUrlList[ii]);
510 if (url.host() == newHost) {
511 _casterUserLineEdit->setText(
512 QUrl::fromPercentEncoding(url.userName().toAscii()));
513 _casterPasswordLineEdit->setText(
514 QUrl::fromPercentEncoding(url.password().toAscii()));
515 if (url.port() > 0) {
516 _casterPortLineEdit->setText(QString("%1").arg(url.port()));
517 }
518 else {
519 _casterPortLineEdit->setText("");
520 }
521 }
522 }
523}
524
525// Caster table
526////////////////////////////////////////////////////////////////////////////
527bncCasterTableDlg::bncCasterTableDlg(const QString& ntripVersion,
528 QWidget* parent) :
529 QDialog(parent) {
530
531 static const QStringList labels = QString("host,port,identifier,operator,nmea,country,lat,long,link").split(",");
532
533 _casterTable = new QTableWidget(this);
534
535 QUrl url;
536 url.setHost("www.rtcm-ntrip.org");
537 url.setPath("/");
538 if (ntripVersion == "2s") {
539 url.setPort(443);
540 url.setScheme("https");
541 }
542 else {
543 url.setPort(2101);
544 url.setScheme("http");
545 }
546
547 bncNetQuery* query = 0;
548 if (ntripVersion == "2") {
549 query = new bncNetQueryV2(false);
550 }
551 else if (ntripVersion == "2s") {
552 query = new bncNetQueryV2(true);
553 }
554 else {
555 query = new bncNetQueryV1();
556 }
557
558 QByteArray outData;
559 query->waitForRequestResult(url, outData);
560
561 QStringList lines;
562 if (query->status() == bncNetQuery::finished) {
563 QTextStream in(outData);
564 QString line = in.readLine();
565 while ( !line.isNull() ) {
566 line = in.readLine();
567 if (line.indexOf("CAS") == 0) {
568 QStringList hlp = line.split(";");
569 if (hlp.size() > labels.size()) {
570 lines.push_back(line);
571 }
572 }
573 }
574 }
575
576 delete query;
577
578 if (lines.size() > 0) {
579 _casterTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
580 _casterTable->setSelectionBehavior(QAbstractItemView::SelectRows);
581
582 QStringList hlp = lines[0].split(";");
583 _casterTable->setColumnCount(labels.size());
584 _casterTable->setRowCount(lines.size());
585
586 for (int nRow = 0; nRow < lines.size(); nRow++) {
587 QStringList columns = lines[nRow].split(";");
588 for (int ic = 1; ic < columns.size(); ic++) {
589 if (ic == 5) {
590 if (columns[ic] == "0") {
591 columns[ic] = "no";
592 } else {
593 columns[ic] = "yes";
594 }
595 }
596 QTableWidgetItem* item = new QTableWidgetItem(columns[ic]);
597 item->setFlags(item->flags() & ~Qt::ItemIsEditable);
598 _casterTable->setItem(nRow, ic-1, item);
599 }
600 }
601 }
602 _casterTable->setHorizontalHeaderLabels(labels);
603 _casterTable->setSortingEnabled(true);
604 _casterTable->sortItems(0);
605 int ww = QFontMetrics(this->font()).width('w');
606 _casterTable->horizontalHeader()->resizeSection(0,15*ww);
607 _casterTable->horizontalHeader()->resizeSection(1, 5*ww);
608 _casterTable->horizontalHeader()->resizeSection(2,15*ww);
609 _casterTable->horizontalHeader()->resizeSection(3,15*ww);
610 _casterTable->horizontalHeader()->resizeSection(4, 5*ww);
611 _casterTable->horizontalHeader()->resizeSection(5, 7*ww);
612 _casterTable->horizontalHeader()->resizeSection(6, 7*ww);
613 _casterTable->horizontalHeader()->resizeSection(7, 7*ww);
614 _casterTable->horizontalHeader()->resizeSection(8,15*ww);
615
616 _closeButton = new QPushButton("Cancel");
617 connect(_closeButton, SIGNAL(clicked()), this, SLOT(close()));
618 _closeButton->setMinimumWidth(8*ww);
619 _closeButton->setMaximumWidth(8*ww);
620
621 _okButton = new QPushButton(tr("OK"), this);
622 connect(_okButton, SIGNAL(clicked()), this, SLOT(slotAcceptCasterTable()));
623 _okButton->setMinimumWidth(8*ww);
624 _okButton->setMaximumWidth(8*ww);
625
626 _whatsThisButton = new QPushButton(tr("Help=Shift+F1"), this);
627 connect(_whatsThisButton, SIGNAL(clicked()), this, SLOT(slotWhatsThis()));
628 _whatsThisButton->setMinimumWidth(12*ww);
629 _whatsThisButton->setMaximumWidth(12*ww);
630
631 _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>."));
632
633 QGridLayout* dlgLayout = new QGridLayout();
634 dlgLayout->addWidget(new QLabel(" List of NTRIP Broadcasters from www.rtcm-ntrip.org"), 0,0,1,3,Qt::AlignLeft);
635 dlgLayout->addWidget(_casterTable, 1, 0, 1, 3);
636 dlgLayout->addWidget(_whatsThisButton, 2, 0);
637 dlgLayout->addWidget(_closeButton, 2, 1, Qt::AlignRight);
638 dlgLayout->addWidget(_okButton, 2, 2);
639
640 setMinimumSize(600,400);
641 setWindowTitle(tr("Select Broadcaster"));
642 setLayout(dlgLayout);
643 resize(68*ww, 50*ww);
644 show();
645}
646
647// Caster table destructor
648////////////////////////////////////////////////////////////////////////////
649bncCasterTableDlg::~bncCasterTableDlg() {
650 delete _casterTable;
651 delete _okButton;
652 delete _closeButton;
653 delete _whatsThisButton;
654}
655
656// Caster table what's this
657////////////////////////////////////////////////////////////////////////////
658void bncCasterTableDlg:: slotWhatsThis() {
659 QWhatsThis::enterWhatsThisMode();
660}
661
662// Accept caster table
663////////////////////////////////////////////////////////////////////////////
664void bncCasterTableDlg::slotAcceptCasterTable() {
665 if (_casterTable) {
666 for (int ir = _casterTable->rowCount() - 1; ir >= 0 ; ir--) {
667 if (_casterTable->isItemSelected(_casterTable->item(ir,0))) {
668 emit newCaster(_casterTable->item(ir,0)->text(),
669 _casterTable->item(ir,1)->text());
670 }
671 }
672 }
673 QDialog::accept();
674}
Note: See TracBrowser for help on using the repository browser.