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

Last change on this file since 8127 was 8127, checked in by stoecker, 2 years ago

update qwt and qwtpolar, many QT5 fixes (unfinished)

File size: 24.5 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#include <QHeaderView>
43#include <QLabel>
44#include <QLineEdit>
45#include <QMessageBox>
46#include <QVBoxLayout>
47
48#include "bnctabledlg.h"
49#include "bncgetthread.h"
50#include "bncnetqueryv1.h"
51#include "bncnetqueryv2.h"
52#include "bncsettings.h"
53#include "bncmap.h"
54
55using namespace std;
56
57// Constructor
58////////////////////////////////////////////////////////////////////////////
59bncTableDlg::bncTableDlg(QWidget* parent) : QDialog(parent) {
60
61  setMinimumSize(600,400);
62  setWindowTitle(tr("Add Streams from Caster"));
63
64  QVBoxLayout* mainLayout = new QVBoxLayout(this);
65
66  int ww = QFontMetrics(font()).width('w');
67
68  _casterPortLineEdit = new QLineEdit();
69  _casterPortLineEdit->setMaximumWidth(9*ww);
70
71  _casterUserLineEdit = new QLineEdit();
72  _casterUserLineEdit->setMaximumWidth(9*ww);
73
74  _casterPasswordLineEdit = new QLineEdit();
75  _casterPasswordLineEdit->setMaximumWidth(9*ww);
76  _casterPasswordLineEdit->setEchoMode(QLineEdit::PasswordEchoOnEdit);
77
78  _casterHostComboBox = new QComboBox();
79  _casterHostComboBox->setMaxCount(10);
80  _casterHostComboBox->setDuplicatesEnabled(false);
81  _casterHostComboBox->setEditable(true);
82  _casterHostComboBox->setMinimumWidth(20*ww);
83  _casterHostComboBox->setMaximumWidth(20*ww);
84  connect(_casterHostComboBox, SIGNAL(currentIndexChanged(const QString&)),
85          this, SLOT(slotCasterHostChanged(const QString&)));
86  bncSettings settings;
87  settings.remove("casterHostList");
88  settings.remove("casterHost");
89  settings.remove("casterPort");
90  settings.remove("casterUser");
91  settings.remove("casterPassword");
92  QStringList casterUrlList = settings.value("casterUrlList").toStringList();
93  for (int ii = 0; ii < casterUrlList.count(); ii++) {
94    QUrl url(casterUrlList[ii]);
95    _casterHostComboBox->addItem(url.host());
96  }
97
98  _ntripVersionComboBox = new QComboBox();
99  _ntripVersionComboBox->addItems(QString("1,2,2s,R,U").split(","));
100  int kk = _ntripVersionComboBox->findText(settings.value("ntripVersion").toString());
101  if (kk != -1) {
102    _ntripVersionComboBox->setCurrentIndex(kk);
103  }
104  _ntripVersionComboBox->setMaximumWidth(5*ww);
105
106  _buttonCasterTable = new QPushButton(tr("Show"), this);
107  connect(_buttonCasterTable, SIGNAL(clicked()), this, SLOT(slotCasterTable()));
108  _buttonCasterTable->setMaximumWidth(6*ww);
109
110  // WhatsThis, Add Streams from Caster, Top
111  // ---------------------------------------
112  _casterHostComboBox->setWhatsThis(tr("<p>Enter the Ntrip Broadcaster URL or IP number.</p><p>Note that EUREF and IGS operate Ntrip Broadcasters at <u>www.euref-ip.net</u>, <u>www.igs-ip.net</u>, <u>products.igs-ip.net</u>, and <u>mgex.igs-ip.net</u>.</p>"));
113  _casterPortLineEdit->setWhatsThis(tr("<p>Enter the Ntrip Broadcaster port number.</p></p>Note that 80 and 2101 are often used port numbers. Note further that Ntrip Version 2 via SSL usually requires specifying port 443.</p>"));
114  _buttonCasterTable->setWhatsThis(tr("<p>Hit 'Show' for a table of known Ntrip Broadcaster installations as maintained at <u>http://www.rtcm-ntrip.org/home.</u></p><p>A window opens which allows to select a broadcaster for stream retrieval.</p>"));
115  _casterUserLineEdit->setWhatsThis(tr("<p>Access to streams on Ntrip Broadcasters can be restricted. You may need to enter a valid 'User' ID and 'Password' for access to protected streams.</p><p>Accounts are usually provided per Ntrip Broadcaster following a registration process. Register via <u>https://registration.rtcm-ntrip.org</u> for access to protected streams on <u>www.euref-ip.net</u>, <u>www.igs-ip.net</u>, <u>products.igs-ip.net</u>, or <u>mges.igs-ip.net</u>.</p>"));
116  _casterPasswordLineEdit->setWhatsThis(tr("<p>Enter a valid 'Password' for access to protected streams.</p>"));
117  _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 (usually port 443)<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>"));
118
119  QGridLayout* editLayout = new QGridLayout;
120  editLayout->addWidget(new QLabel(tr("Caster host")),    0, 0);
121  editLayout->addWidget(_casterHostComboBox,              0, 1);
122  editLayout->addWidget(new QLabel(tr("  Caster port")),  0, 2, Qt::AlignRight);
123  editLayout->addWidget(_casterPortLineEdit,              0, 3);
124  editLayout->addWidget(new QLabel(tr("Casters table")),  0, 4, Qt::AlignRight);
125  editLayout->addWidget(_buttonCasterTable,               0, 5);
126  editLayout->addWidget(new QLabel(tr("User")),           1, 0, Qt::AlignRight);
127  editLayout->addWidget(_casterUserLineEdit,              1, 1);
128  editLayout->addWidget(new QLabel(tr("Password")),       1, 2, Qt::AlignRight);
129  editLayout->addWidget(_casterPasswordLineEdit,          1, 3);
130  editLayout->addWidget(new QLabel(tr("  Ntrip Version")),1, 4, Qt::AlignRight);
131  editLayout->addWidget(_ntripVersionComboBox,            1, 5);
132
133  mainLayout->addLayout(editLayout);
134
135
136  _table = new QTableWidget(this);
137  connect(_table, SIGNAL(itemSelectionChanged()),
138          this, SLOT(slotSelectionChanged()));
139  mainLayout->addWidget(_table);
140
141  _buttonWhatsThis = new QPushButton(tr("Help=Shift+F1"), this);
142  connect(_buttonWhatsThis, SIGNAL(clicked()), this, SLOT(slotWhatsThis()));
143
144  _buttonGet = new QPushButton(tr("Get table"), this);
145  _buttonGet->setDefault(true);
146  connect(_buttonGet, SIGNAL(clicked()), this, SLOT(slotGetTable()));
147 
148  _buttonMap = new QPushButton(tr("Map"), this);
149  _buttonMap->setEnabled(false);
150  connect(_buttonMap, SIGNAL(clicked()), this, SLOT(slotShowMap()));
151 
152  _buttonClose = new QPushButton(tr("Close"), this);
153  connect(_buttonClose, SIGNAL(clicked()), this, SLOT(close()));
154
155  _buttonSelect = new QPushButton(tr("Select"), this);
156  connect(_buttonSelect, SIGNAL(clicked()), this, SLOT(select()));
157
158  // WhatsThis, Add Streams from Caster, Bottom
159  // ------------------------------------------
160  _table->setWhatsThis(tr("<p>Use the 'Get Table' button to download the source-table 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 or not a stream comes from a virtual reference station (VRS).</p>"));
161  _buttonMap->setWhatsThis(tr("<p>Draw distribution map of streams in downloaded caster source-table. Use mouse to zoom in or out.</p><p>Left button: Draw rectangle to zoom in.<br>Right button: Zoom out.<br>Middle button: Zoom back.</p>"));
162  _buttonGet->setWhatsThis(tr("<p>Download source-table from specified caster.</p>"));
163  _buttonClose->setWhatsThis(tr("<p>Close window.</p>"));
164  _buttonSelect->setWhatsThis(tr("<p>Select streams highlighted in downloaded source-table.</p>"));
165
166  QHBoxLayout* buttonLayout = new QHBoxLayout;
167  buttonLayout->addWidget(_buttonWhatsThis);
168  buttonLayout->addStretch(1);
169  buttonLayout->addWidget(_buttonMap);
170  buttonLayout->addWidget(_buttonGet);
171  buttonLayout->addWidget(_buttonSelect);
172  buttonLayout->addWidget(_buttonClose);
173
174  mainLayout->addLayout(buttonLayout);
175}
176
177// Destructor
178////////////////////////////////////////////////////////////////////////////
179bncTableDlg::~bncTableDlg() {
180  delete _casterHostComboBox;
181  delete _casterPortLineEdit;
182  delete _casterUserLineEdit;
183  delete _casterPasswordLineEdit;
184  bncSettings settings;
185  settings.setValue("ntripVersion", _ntripVersionComboBox->currentText());
186  delete _ntripVersionComboBox;
187  delete _buttonMap;
188  delete _buttonGet;
189  delete _buttonClose;
190  delete _buttonSelect;
191  delete _buttonWhatsThis;
192  delete _buttonCasterTable;
193  delete _table;
194}
195
196// Read full caster table (static)
197////////////////////////////////////////////////////////////////////////////
198t_irc bncTableDlg::getFullTable(const QString& ntripVersion, 
199                                const QString& casterHost, 
200                                int casterPort, QStringList& allLines, 
201                                bool alwaysRead) {
202
203  static QMutex mutex;
204  static QMap<QString, QStringList> allTables;
205
206  QMutexLocker locker(&mutex);
207
208  if (!alwaysRead && allTables.find(casterHost) != allTables.end()) {
209    allLines = allTables.find(casterHost).value();
210    return success;
211  }
212
213  allLines.clear();
214
215  bncNetQuery* query = 0;
216  if      (ntripVersion == "2") {
217    query = new bncNetQueryV2(false);
218  }
219  else if (ntripVersion == "2s") {
220    query = new bncNetQueryV2(true);
221  }
222  else {
223    query = new bncNetQueryV1();
224  }
225
226  QUrl url;
227  url.setHost(casterHost);
228  url.setPort(casterPort);
229  url.setPath("/");
230  if (ntripVersion == "2s") {
231    url.setScheme("https");
232  }
233  else {
234    url.setScheme("http");
235  }
236
237  QByteArray outData;
238  query->waitForRequestResult(url, outData);
239  if (query->status() == bncNetQuery::finished) {
240    QTextStream in(outData);
241    QString line = in.readLine();
242    while ( !line.isNull() ) {
243      allLines.append(line);
244      line = in.readLine();
245    } 
246    allTables.insert(casterHost, allLines);
247    delete query;
248    return success;
249  }
250  else {
251    delete query;
252    return failure;
253  }
254}
255
256// Read Table from Caster
257////////////////////////////////////////////////////////////////////////////
258void bncTableDlg::slotGetTable() {
259
260  _buttonGet->setEnabled(false);
261  _buttonMap->setEnabled(true);
262  _buttonCasterTable->setEnabled(false); 
263
264  if ( getFullTable(_ntripVersionComboBox->currentText(),
265                    _casterHostComboBox->currentText(),
266                    _casterPortLineEdit->text().toInt(),
267                    _allLines, true) != success ) {
268    QMessageBox::warning(0, "BNC", "Cannot retrieve table of data");
269    _buttonGet->setEnabled(true);
270    return;
271  }
272 
273  static const QStringList labels = QString("mountpoint,identifier,format,"
274    "format-details,carrier,system,network,country,lat,long,"
275    "nmea,solution,generator,compress.,auth.,fee,bitrate,"
276    "misc").split(",");
277
278  QStringList lines;
279  QStringListIterator it(_allLines);
280  while (it.hasNext()) {
281    QString line = it.next();
282    if (line.indexOf("STR") == 0) {
283      QStringList hlp = line.split(";");
284      if (hlp.size() > labels.size()) {
285        lines.push_back(line);
286      }
287    }
288  }
289
290  if (lines.size() > 0) {
291    _table->setSelectionMode(QAbstractItemView::ExtendedSelection);
292    _table->setSelectionBehavior(QAbstractItemView::SelectRows);
293    _table->setColumnCount(labels.size());
294    _table->setRowCount(lines.size());
295    for (int nRow = 0; nRow < lines.size(); nRow++) {
296      QStringList columns = lines[nRow].split(";");
297      for (int ic = 1; ic < columns.size(); ic++) {
298            if (ic == 11) {
299          if (columns[ic] == "0") { 
300            columns[ic] = "no"; 
301          } else { 
302            columns[ic] = "yes"; 
303          }
304        }
305        QTableWidgetItem* item = new QTableWidgetItem(columns[ic]);
306        item->setFlags(item->flags() & ~Qt::ItemIsEditable);
307        _table->setItem(nRow, ic-1, item);
308      }
309    }
310    _table->setHorizontalHeaderLabels(labels);
311    _table->setSortingEnabled(true);
312    int ww = QFontMetrics(this->font()).width('w');
313    _table->horizontalHeader()->resizeSection( 0,10*ww);
314    _table->horizontalHeader()->resizeSection( 1,10*ww);
315    _table->horizontalHeader()->resizeSection( 2, 8*ww);
316    _table->horizontalHeader()->resizeSection( 3,22*ww);
317    _table->horizontalHeader()->resizeSection( 4, 5*ww);
318    _table->horizontalHeader()->resizeSection( 5, 8*ww);
319    _table->horizontalHeader()->resizeSection( 6, 8*ww);
320    _table->horizontalHeader()->resizeSection( 7, 7*ww);
321    _table->horizontalHeader()->resizeSection( 8, 6*ww);
322    _table->horizontalHeader()->resizeSection( 9, 6*ww);
323    _table->horizontalHeader()->resizeSection(10, 6*ww);
324    _table->horizontalHeader()->resizeSection(11, 6*ww);
325    _table->horizontalHeader()->resizeSection(12,15*ww);
326    _table->horizontalHeader()->resizeSection(13, 8*ww);
327    _table->horizontalHeader()->resizeSection(14, 5*ww);
328    _table->horizontalHeader()->resizeSection(15, 5*ww);
329    _table->horizontalHeader()->resizeSection(16, 7*ww);
330    _table->horizontalHeader()->resizeSection(17,15*ww);
331    _table->sortItems(0);
332  }
333}
334
335// Show world map
336////////////////////////////////////////////////////////////////////////////
337void bncTableDlg::slotShowMap() {
338
339  t_bncMap* bncMap = new t_bncMap(this);
340
341  bncMap->setMinimumSize(800, 600);
342
343  for (int ii = 0; ii < _allLines.size(); ii++) {
344    if (_allLines.at(ii).startsWith("STR") == true) {
345      QStringList tmp = _allLines.at(ii).split(';');
346      if (tmp.size() > 10) {
347        double  latDeg = tmp.at(9).toDouble();
348        double  lonDeg = tmp.at(10).toDouble();
349        QString name   = tmp.at(1);
350        bncMap->slotNewPoint(name, latDeg, lonDeg);
351      }
352    }
353  }
354
355  bncMap->show();
356}
357
358// Select slot
359////////////////////////////////////////////////////////////////////////////
360void bncTableDlg::select() {
361
362  QString ntripVersion = _ntripVersionComboBox->currentText();
363
364  QUrl url;
365  if (ntripVersion == "2s") {
366    url.setScheme("https");
367  }
368  else {
369    url.setScheme("http");
370  }
371  url.setHost(_casterHostComboBox->currentText());
372  url.setPort(_casterPortLineEdit->text().toInt());
373  url.setUserName(QUrl::toPercentEncoding(_casterUserLineEdit->text()));
374  url.setPassword(QUrl::toPercentEncoding(_casterPasswordLineEdit->text()));
375  addUrl(url);
376
377  QStringList* mountPoints = new QStringList;
378  if (_table) {
379    for (int ir = 0; ir < _table->rowCount(); ir++) {
380      QTableWidgetItem*   item = _table->item(ir,0);
381      QString             site = _table->item(ir,0)->text();
382      QString           format = _table->item(ir,2)->text();
383      QString          country = _table->item(ir,7)->text();
384      QString         latitude = _table->item(ir,8)->text();
385      QString        longitude = _table->item(ir,9)->text();
386      QString             nmea = _table->item(ir,10)->text();
387      format.replace(" ", "_");
388      if (_table->isItemSelected(item)) {
389        url.setPath(item->text());
390        mountPoints->push_back(url.toString() + " " + format + " " + country + " " + latitude
391                        + " " + longitude + " " + nmea + " " + ntripVersion);
392
393        site.resize(4);
394      }
395    }
396  }
397  emit newMountPoints(mountPoints);
398}
399
400// User changed the selection of mountPoints
401////////////////////////////////////////////////////////////////////////////
402void bncTableDlg::slotSelectionChanged() {
403  if (_table->selectedItems().isEmpty()) {
404  }
405}
406
407// Whats This Help
408void bncTableDlg::slotWhatsThis() {
409QWhatsThis::enterWhatsThisMode();
410}
411
412// Slot caster table
413////////////////////////////////////////////////////////////////////////////
414void bncTableDlg::slotCasterTable() {
415       
416  _buttonCasterTable->setEnabled(false);
417  _casterHostComboBox->setEnabled(false);
418  _casterPortLineEdit->setEnabled(false);
419  _casterUserLineEdit->setEnabled(false);
420  _casterPasswordLineEdit->setEnabled(false);
421  _ntripVersionComboBox->setEnabled(false);
422  _buttonWhatsThis->setEnabled(false);
423  _buttonGet->setEnabled(false);
424  _buttonClose->setEnabled(false);
425  _buttonSelect->setEnabled(false);
426
427  bncCasterTableDlg* dlg = 
428          new bncCasterTableDlg(_ntripVersionComboBox->currentText(), this);
429  dlg->move(this->pos().x()+50, this->pos().y()+50);
430  connect(dlg, SIGNAL(newCaster(QString, QString)),
431          this, SLOT(slotNewCaster(QString, QString)));
432  dlg->exec();
433  delete dlg;
434
435  _buttonCasterTable->setEnabled(true);
436  _casterHostComboBox->setEnabled(true);
437  _casterPortLineEdit->setEnabled(true);
438  _casterUserLineEdit->setEnabled(true);
439  _casterPasswordLineEdit->setEnabled(true);
440  _ntripVersionComboBox->setEnabled(true);
441  _buttonWhatsThis->setEnabled(true);
442  _buttonGet->setEnabled(true);
443  _buttonClose->setEnabled(true);
444  _buttonSelect->setEnabled(true);
445
446}
447
448// New caster selected
449////////////////////////////////////////////////////////////////////////////
450void bncTableDlg::slotNewCaster(QString newCasterHost, QString newCasterPort) {
451
452  _casterHostComboBox->insertItem(0, newCasterHost);
453  _casterHostComboBox->setCurrentIndex(0);
454  _casterUserLineEdit->setText("");
455  _casterPasswordLineEdit->setText("");
456  _casterPortLineEdit->setText(newCasterPort);
457
458  QString ntripVersion = _ntripVersionComboBox->currentText();
459
460  QUrl url;
461  if (ntripVersion == "2s") {
462    url.setScheme("https");
463  }
464  else {
465    url.setScheme("http");
466  }
467  url.setHost(newCasterHost);
468  url.setPort(newCasterPort.toInt());
469  addUrl(url);
470 
471  _casterHostComboBox->setCurrentIndex(0);
472}
473
474// New caster selected
475////////////////////////////////////////////////////////////////////////////
476void bncTableDlg::addUrl(const QUrl& url) {
477  bncSettings settings;
478  QStringList oldUrlList = settings.value("casterUrlList").toStringList();
479  QStringList newUrlList;
480  newUrlList << url.toString();
481  for (int ii = 0; ii < oldUrlList.count(); ii++) {
482    QUrl oldUrl(oldUrlList[ii]);
483    if (url.host() != oldUrl.host()) {
484      newUrlList << oldUrl.toString();
485    }
486  }
487  settings.setValue("casterUrlList", newUrlList);
488}
489
490// New caster selected in combobox
491////////////////////////////////////////////////////////////////////////////
492void bncTableDlg::slotCasterHostChanged(const QString& newHost) {
493  bncSettings settings;
494  QStringList casterUrlList = settings.value("casterUrlList").toStringList();
495  for (int ii = 0; ii < casterUrlList.count(); ii++) {
496    QUrl url(casterUrlList[ii]);
497    if (url.host() == newHost) {
498      _casterUserLineEdit->setText(
499                QUrl::fromPercentEncoding(url.userName().toLatin1()));
500      _casterPasswordLineEdit->setText(
501                QUrl::fromPercentEncoding(url.password().toLatin1()));
502      if (url.port() > 0) {
503        _casterPortLineEdit->setText(QString("%1").arg(url.port()));
504      }
505      else {
506        _casterPortLineEdit->setText("");
507      }
508    }
509  }
510}
511
512// Caster table
513////////////////////////////////////////////////////////////////////////////
514bncCasterTableDlg::bncCasterTableDlg(const QString& ntripVersion,
515                                     QWidget* parent) : 
516   QDialog(parent) {
517
518  static const QStringList labels = QString("host,port,identifier,operator,nmea,country,lat,long,link").split(",");
519
520  _casterTable = new QTableWidget(this);
521
522  QUrl url;
523  url.setHost("www.rtcm-ntrip.org");
524  url.setPath("/");
525  if (ntripVersion == "2s") {
526    url.setPort(443);
527    url.setScheme("https");
528  }
529  else {
530    url.setPort(2101);
531    url.setScheme("http");
532  }
533
534  bncNetQuery* query = 0;
535  if (ntripVersion == "2") {
536    query = new bncNetQueryV2(false);
537  }
538  else if (ntripVersion == "2s") {
539    query = new bncNetQueryV2(true);
540  }
541  else {
542    query = new bncNetQueryV1();
543  }
544
545  QByteArray outData;
546  query->waitForRequestResult(url, outData);
547
548  QStringList lines;
549  if (query->status() == bncNetQuery::finished) {
550    QTextStream in(outData);
551    QString line = in.readLine();
552    while ( !line.isNull() ) {
553      line = in.readLine();
554      if (line.indexOf("CAS") == 0) {
555        QStringList hlp = line.split(";");
556        if (hlp.size() > labels.size()) {
557          lines.push_back(line);
558        }
559      }
560    }
561  }
562
563  delete query;
564
565  if (lines.size() > 0) {
566    _casterTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
567    _casterTable->setSelectionBehavior(QAbstractItemView::SelectRows);
568
569    QStringList hlp = lines[0].split(";");
570    _casterTable->setColumnCount(labels.size());
571    _casterTable->setRowCount(lines.size());
572
573    for (int nRow = 0; nRow < lines.size(); nRow++) {
574      QStringList columns = lines[nRow].split(";");
575      for (int ic = 1; ic < columns.size(); ic++) {
576         if (ic == 5) { 
577           if (columns[ic] == "0") { 
578             columns[ic] = "no"; 
579           } else { 
580             columns[ic] = "yes"; 
581           }
582         }
583         QTableWidgetItem* item = new QTableWidgetItem(columns[ic]);
584        item->setFlags(item->flags() & ~Qt::ItemIsEditable);
585        _casterTable->setItem(nRow, ic-1, item);
586      }
587    }
588  } 
589  _casterTable->setHorizontalHeaderLabels(labels);
590  _casterTable->setSortingEnabled(true);
591  _casterTable->sortItems(0);
592   int ww = QFontMetrics(this->font()).width('w');
593  _casterTable->horizontalHeader()->resizeSection(0,15*ww);
594  _casterTable->horizontalHeader()->resizeSection(1, 5*ww);
595  _casterTable->horizontalHeader()->resizeSection(2,15*ww);
596  _casterTable->horizontalHeader()->resizeSection(3,15*ww);
597  _casterTable->horizontalHeader()->resizeSection(4, 5*ww);
598  _casterTable->horizontalHeader()->resizeSection(5, 7*ww);
599  _casterTable->horizontalHeader()->resizeSection(6, 7*ww);
600  _casterTable->horizontalHeader()->resizeSection(7, 7*ww);
601  _casterTable->horizontalHeader()->resizeSection(8,15*ww);
602
603  _closeButton = new QPushButton("Cancel");
604  connect(_closeButton, SIGNAL(clicked()), this, SLOT(close()));
605  _closeButton->setMinimumWidth(8*ww);
606  _closeButton->setMaximumWidth(8*ww);
607
608  _okButton = new QPushButton(tr("OK"), this);
609  connect(_okButton, SIGNAL(clicked()), this, SLOT(slotAcceptCasterTable()));
610  _okButton->setMinimumWidth(8*ww);
611  _okButton->setMaximumWidth(8*ww);
612
613  _whatsThisButton = new QPushButton(tr("Help=Shift+F1"), this);
614  connect(_whatsThisButton, SIGNAL(clicked()), this, SLOT(slotWhatsThis()));
615  _whatsThisButton->setMinimumWidth(12*ww);
616  _whatsThisButton->setMaximumWidth(12*ww);
617
618  // WhatsThis, List of Ntrip Broadcasters from www.rtcm-ntrip.org
619  // -------------------------------------------------------------
620  _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>"));
621
622  QGridLayout* dlgLayout = new QGridLayout();
623  dlgLayout->addWidget(new QLabel("  List of Ntrip Broadcasters from www.rtcm-ntrip.org"), 0,0,1,3,Qt::AlignLeft);
624  dlgLayout->addWidget(_casterTable,     1, 0, 1, 3);
625  dlgLayout->addWidget(_whatsThisButton, 2, 0);
626  dlgLayout->addWidget(_closeButton,     2, 1, Qt::AlignRight); 
627  dlgLayout->addWidget(_okButton,        2, 2);
628
629  setMinimumSize(600,400);
630  setWindowTitle(tr("Select Broadcaster"));
631  setLayout(dlgLayout);
632  resize(68*ww, 50*ww);
633  show();
634}
635
636// Caster table destructor
637////////////////////////////////////////////////////////////////////////////
638bncCasterTableDlg::~bncCasterTableDlg() {
639  delete _casterTable;
640  delete _okButton;
641  delete _closeButton;
642  delete _whatsThisButton;
643}
644
645// Caster table what's this
646////////////////////////////////////////////////////////////////////////////
647void bncCasterTableDlg:: slotWhatsThis() {
648  QWhatsThis::enterWhatsThisMode();
649}
650
651// Accept caster table
652////////////////////////////////////////////////////////////////////////////
653void bncCasterTableDlg::slotAcceptCasterTable() {
654  if (_casterTable) {
655    for (int ir = _casterTable->rowCount() - 1; ir >= 0 ; ir--) {
656      if (_casterTable->isItemSelected(_casterTable->item(ir,0))) {
657        emit newCaster(_casterTable->item(ir,0)->text(), 
658                       _casterTable->item(ir,1)->text());
659      }
660    }
661  }
662  QDialog::accept();
663}
Note: See TracBrowser for help on using the repository browser.