source: ntrip/trunk/BNC/bncwindow.cpp@ 105

Last change on this file since 105 was 105, checked in by mervart, 20 years ago

* empty log message *

File size: 11.7 KB
Line 
1
2/* -------------------------------------------------------------------------
3 * BKG NTRIP Client
4 * -------------------------------------------------------------------------
5 *
6 * Class: bncWindow
7 *
8 * Purpose: This class implements the main application window.
9 *
10 * Author: L. Mervart
11 *
12 * Created: 24-Dec-2005
13 *
14 * Changes:
15 *
16 * -----------------------------------------------------------------------*/
17
18#include "bncwindow.h"
19#include "bncgetthread.h"
20#include "bnctabledlg.h"
21
22using namespace std;
23
24// Constructor
25////////////////////////////////////////////////////////////////////////////
26bncWindow::bncWindow() {
27
28 int ww = QFontMetrics(this->font()).width('w');
29
30 setMinimumSize(80*ww, 80*ww);
31
32 // Create Actions
33 // --------------
34 _actAbout = new QAction(tr("&About"),this);
35 _actAbout->setEnabled(false);
36
37 _actSaveOpt = new QAction(tr("&Save Options"),this);
38 connect(_actSaveOpt, SIGNAL(triggered()), SLOT(slotSaveOptions()));
39
40 _actQuit = new QAction(tr("&Quit"),this);
41 connect(_actQuit, SIGNAL(triggered()), SLOT(close()));
42
43 _actAddMountPoints = new QAction(tr("&Add Mountpoints"),this);
44 connect(_actAddMountPoints, SIGNAL(triggered()), SLOT(slotAddMountPoints()));
45
46 _actDeleteMountPoints = new QAction(tr("&Delete Mountpoints"),this);
47 connect(_actDeleteMountPoints, SIGNAL(triggered()), SLOT(slotDeleteMountPoints()));
48 _actDeleteMountPoints->setEnabled(false);
49
50 _actGetData = new QAction(tr("&Get Data"),this);
51 connect(_actGetData, SIGNAL(triggered()), SLOT(slotGetData()));
52
53 // Create Menus
54 // ------------
55 _menuFile = menuBar()->addMenu(tr("&File"));
56 _menuFile->addAction(_actSaveOpt);
57 _menuFile->addSeparator();
58 _menuFile->addAction(_actQuit);
59
60 _menuHlp = menuBar()->addMenu(tr("&Help"));
61 _menuHlp->addAction(_actAbout);
62
63 // Tool (Command) Bar
64 // ------------------
65 QToolBar* toolBar = new QToolBar;
66 addToolBar(Qt::BottomToolBarArea, toolBar);
67 toolBar->setMovable(false);
68 toolBar->addAction(_actAddMountPoints);
69 toolBar->addAction(_actDeleteMountPoints);
70 toolBar->addAction(_actGetData);
71
72 // Canvas with Editable Fields
73 // ---------------------------
74 _canvas = new QWidget;
75 setCentralWidget(_canvas);
76
77 QGridLayout* layout = new QGridLayout;
78 _canvas->setLayout(layout);
79
80 QSettings settings;
81
82 _proxyHostLineEdit = new QLineEdit(settings.value("proxyHost").toString());
83 _proxyHostLineEdit->setMaximumWidth(12*ww);
84 _proxyPortLineEdit = new QLineEdit(settings.value("proxyPort").toString());
85 _proxyPortLineEdit->setMaximumWidth(9*ww);
86 _timeOutLineEdit = new QLineEdit(settings.value("timeOut").toString());
87 _timeOutLineEdit->setMaximumWidth(9*ww);
88 _outFileLineEdit = new QLineEdit(settings.value("outFile").toString());
89 _outPortLineEdit = new QLineEdit(settings.value("outPort").toString());
90 _outPortLineEdit->setMaximumWidth(9*ww);
91 _rnxPathLineEdit = new QLineEdit(settings.value("rnxPath").toString());
92 _rnxSkelLineEdit = new QLineEdit(settings.value("rnxSkel").toString());
93 _rnxSkelLineEdit->setMaximumWidth(5*ww);
94 _rnxIntrSpinBox = new QSpinBox();
95 _rnxIntrSpinBox->setMaximumWidth(12*ww);
96 _rnxIntrSpinBox->setValue(settings.value("rnxIntr").toInt());
97 _rnxIntrSpinBox->setSuffix(" hour");
98 _rnxIntrSpinBox->setRange(1,24);
99 _rnxIntrSpinBox->setSingleStep(23);
100 _mountPointsTable = new QTableWidget(0,2);
101 _mountPointsTable->setMinimumWidth(70*ww);
102 _mountPointsTable->setMaximumHeight(20*ww);
103 _mountPointsTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
104 _mountPointsTable->horizontalHeader()->hide();
105 _mountPointsTable->verticalHeader()->hide();
106 _mountPointsTable->setGridStyle(Qt::NoPen);
107 _mountPointsTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
108 _mountPointsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
109 QListIterator<QString> it(settings.value("mountPoints").toStringList());
110 if (!it.hasNext()) {
111 _actGetData->setEnabled(false);
112 }
113 int iRow = 0;
114 while (it.hasNext()) {
115 QStringList hlp = it.next().split(" ");
116 if (hlp.size() <= 1) continue;
117 QString mPoint = hlp[0];
118 QString format = hlp[1];
119 _mountPointsTable->insertRow(iRow);
120 _mountPointsTable->setItem(iRow, 0, new QTableWidgetItem(mPoint));
121 _mountPointsTable->setItem(iRow, 1, new QTableWidgetItem(format));
122 iRow++;
123 }
124 _mountPointsTable->sortItems(0);
125
126 connect(_mountPointsTable, SIGNAL(itemSelectionChanged()),
127 SLOT(slotSelectionChanged()));
128
129 _log = new QTextEdit();
130 _log->setMaximumHeight(120);
131 _log->setReadOnly(true);
132
133 layout->addWidget(new QLabel("Proxy host"), 0, 0);
134 layout->addWidget(_proxyHostLineEdit, 0, 2);
135 layout->addWidget(new QLabel("Proxy port"), 0, 3);
136 layout->addWidget(_proxyPortLineEdit, 0, 4);
137 layout->addWidget(new QLabel("timeout (sec)"), 1, 2);
138 layout->addWidget(_timeOutLineEdit, 1, 3);
139 layout->addWidget(new QLabel("ASCII output file (full path)"), 2, 2);
140 layout->addWidget(_outFileLineEdit, 2, 3, 1, 2);
141 layout->addWidget(new QLabel("port for binary output"), 3, 2);
142 layout->addWidget(_outPortLineEdit, 3, 3);
143 layout->addWidget(new QLabel("RINEX path"), 4, 2);
144 layout->addWidget(_rnxPathLineEdit, 4, 3, 1, 2);
145 layout->addWidget(new QLabel("RINEX skeleton extension"), 5, 2);
146 layout->addWidget(_rnxSkelLineEdit, 5, 3);
147 layout->addWidget(new QLabel("RINEX file interval"), 6, 2);
148 layout->addWidget(_rnxIntrSpinBox, 6, 3);
149 layout->addWidget(new QLabel("Mountpoints"), 7, 1);
150 layout->addWidget(_mountPointsTable, 7, 2, 1, 3);
151 layout->addWidget(new QLabel("Log"), 8, 1);
152 layout->addWidget(_log, 8, 2, 1, 3);
153
154 _bncCaster = 0;
155}
156
157// Destructor
158////////////////////////////////////////////////////////////////////////////
159bncWindow::~bncWindow() {
160}
161
162// Retrieve Table
163////////////////////////////////////////////////////////////////////////////
164void bncWindow::slotAddMountPoints() {
165
166 QSettings settings;
167 QString proxyHost = settings.value("proxyHost").toString();
168 int proxyPort = settings.value("proxyPort").toInt();
169 if (proxyHost != _proxyHostLineEdit->text() ||
170 proxyPort != _proxyPortLineEdit->text().toInt()) {
171 int iRet = QMessageBox::question(this, "Question", "Proxy options "
172 "changed. Use the new ones?",
173 QMessageBox::Yes, QMessageBox::No,
174 QMessageBox::NoButton);
175 if (iRet == QMessageBox::Yes) {
176 settings.setValue("proxyHost", _proxyHostLineEdit->text());
177 settings.setValue("proxyPort", _proxyPortLineEdit->text());
178 }
179 }
180
181 bncTableDlg* dlg = new bncTableDlg(this);
182 dlg->move(this->pos().x()+50, this->pos().y()+50);
183 connect(dlg, SIGNAL(newMountPoints(QStringList*)),
184 this, SLOT(slotNewMountPoints(QStringList*)));
185 dlg->exec();
186 delete dlg;
187
188}
189
190// Delete Selected Mount Points
191////////////////////////////////////////////////////////////////////////////
192void bncWindow::slotDeleteMountPoints() {
193 while(1) {
194 bool itemRemoved = false;
195 for (int iRow = 0; iRow < _mountPointsTable->rowCount(); iRow++) {
196 if (_mountPointsTable->isItemSelected(_mountPointsTable->item(iRow,0))) {
197 _mountPointsTable->removeRow(iRow);
198 itemRemoved = true;
199 break;
200 }
201 }
202 if (!itemRemoved) {
203 break;
204 }
205 }
206 _actDeleteMountPoints->setEnabled(false);
207}
208
209// New Mount Points Selected
210////////////////////////////////////////////////////////////////////////////
211void bncWindow::slotNewMountPoints(QStringList* mountPoints) {
212 int iRow = 0;
213 QListIterator<QString> it(*mountPoints);
214 while (it.hasNext()) {
215 QStringList hlp = it.next().split(" ");
216 QString mPoint = hlp[0];
217 QString format = hlp[1];
218 _mountPointsTable->insertRow(iRow);
219 _mountPointsTable->setItem(iRow, 0, new QTableWidgetItem(mPoint));
220 _mountPointsTable->setItem(iRow, 1, new QTableWidgetItem(format));
221 iRow++;
222 }
223 _mountPointsTable->sortItems(0);
224 if (mountPoints->count() > 0) {
225 _actGetData->setEnabled(true);
226 }
227 delete mountPoints;
228}
229
230// Save Options
231////////////////////////////////////////////////////////////////////////////
232void bncWindow::slotSaveOptions() {
233 QSettings settings;
234 settings.setValue("proxyHost", _proxyHostLineEdit->text());
235 settings.setValue("proxyPort", _proxyPortLineEdit->text());
236 settings.setValue("timeOut", _timeOutLineEdit->text());
237 settings.setValue("outFile", _outFileLineEdit->text());
238 settings.setValue("outPort", _outPortLineEdit->text());
239 settings.setValue("rnxPath", _rnxPathLineEdit->text());
240 settings.setValue("rnxIntr", _rnxIntrSpinBox->value());
241 settings.setValue("rnxSkel", _rnxSkelLineEdit->text());
242 QStringList mountPoints;
243 for (int iRow = 0; iRow < _mountPointsTable->rowCount(); iRow++) {
244 mountPoints.append(_mountPointsTable->item(iRow, 0)->text() +
245 " " + _mountPointsTable->item(iRow, 1)->text());
246 }
247 settings.setValue("mountPoints", mountPoints);
248}
249
250// All get slots terminated
251////////////////////////////////////////////////////////////////////////////
252void bncWindow::slotGetThreadErrors() {
253 slotMessage("All Get Threads Terminated");
254 _actAddMountPoints->setEnabled(true);
255 _actGetData->setEnabled(true);
256}
257
258// Retrieve Data
259////////////////////////////////////////////////////////////////////////////
260void bncWindow::slotGetData() {
261 _actAddMountPoints->setEnabled(false);
262 _actDeleteMountPoints->setEnabled(false);
263 _actGetData->setEnabled(false);
264
265 _bncCaster = new bncCaster(_outFileLineEdit->text(),
266 _outPortLineEdit->text().toInt());
267
268 connect(_bncCaster, SIGNAL(getThreadErrors()),
269 this, SLOT(slotGetThreadErrors()));
270
271 connect(_bncCaster, SIGNAL(newMessage(const QByteArray&)),
272 this, SLOT(slotMessage(const QByteArray&)));
273
274 _bncCaster->start();
275
276 for (int iRow = 0; iRow < _mountPointsTable->rowCount(); iRow++) {
277 QUrl url(_mountPointsTable->item(iRow, 0)->text());
278 QByteArray format = _mountPointsTable->item(iRow, 1)->text().toAscii();
279
280 bncGetThread* getThread = new bncGetThread(url, format);
281
282 connect(getThread, SIGNAL(newMessage(const QByteArray&)),
283 this, SLOT(slotMessage(const QByteArray&)));
284
285 _bncCaster->addGetThread(getThread);
286
287 getThread->start();
288 }
289}
290
291// Close Application gracefully
292////////////////////////////////////////////////////////////////////////////
293void bncWindow::closeEvent(QCloseEvent* event) {
294
295 int iRet = QMessageBox::question(this, "Close", "Save Options?",
296 QMessageBox::Yes, QMessageBox::No,
297 QMessageBox::Cancel);
298
299 if (iRet == QMessageBox::Cancel) {
300 event->ignore();
301 return;
302 }
303 else if (iRet == QMessageBox::Yes) {
304 slotSaveOptions();
305 }
306
307 return QMainWindow::closeEvent(event);
308}
309
310// User changed the selection of mountPoints
311////////////////////////////////////////////////////////////////////////////
312void bncWindow::slotSelectionChanged() {
313 if (_mountPointsTable->selectedItems().isEmpty()) {
314 _actDeleteMountPoints->setEnabled(false);
315 }
316 else {
317 _actDeleteMountPoints->setEnabled(true);
318 }
319}
320
321// Display Program Messages
322////////////////////////////////////////////////////////////////////////////
323void bncWindow::slotMessage(const QByteArray& msg) {
324
325 const int maxBufferSize = 10000;
326
327 QString txt = _log->toPlainText() + "\n" + msg;
328 _log->clear();
329 _log->append(txt.right(maxBufferSize));
330}
331
Note: See TracBrowser for help on using the repository browser.