source: ntrip/trunk/BNC/src/rinex/graphwin.cpp@ 8556

Last change on this file since 8556 was 8556, checked in by mervart, 5 years ago

Analyze more than two signals

File size: 6.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: t_graphWin
30 *
31 * Purpose: Window for plots
32 *
33 * Author: L. Mervart
34 *
35 * Created: 23-Jun-2012
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <qwt_scale_widget.h>
42#include <qwt_scale_engine.h>
43
44#include <QDir>
45#include <QFileInfo>
46#include <QHBoxLayout>
47#include <QVBoxLayout>
48#include <QPushButton>
49
50#include "graphwin.h"
51#include "bncsettings.h"
52
53using namespace std;
54
55// Constructor
56////////////////////////////////////////////////////////////////////////////
57t_graphWin::t_graphWin(QWidget* parent, const QString& fileName,
58 const QVector<QWidget*>& plots, const QByteArray* scaleTitle,
59 const QwtInterval* scaleInterval, bool specialLayout) : QDialog(parent) {
60
61 _fileName = fileName;
62
63 this->setAttribute(Qt::WA_DeleteOnClose);
64
65 setWindowTitle(_fileName);
66
67 int ww = QFontMetrics(font()).width('w');
68 setMinimumSize(plots.size()*40*ww, 40*ww);
69
70 // Buttons
71 // -------
72 _buttonClose = new QPushButton(tr("Close"), this);
73 _buttonClose->setMaximumWidth(10*ww);
74 connect(_buttonClose, SIGNAL(clicked()), this, SLOT(slotClose()));
75
76 _buttonPrint = new QPushButton(tr("Print"), this);
77 _buttonPrint->setMaximumWidth(10*ww);
78 connect(_buttonPrint, SIGNAL(clicked()), this, SLOT(slotPrint()));
79
80 // Color Scale
81 // -----------
82 if (scaleTitle && scaleInterval) {
83 _colorScale = new QwtScaleWidget( this );
84 _colorScale->setAlignment( QwtScaleDraw::RightScale );
85 _colorScale->setColorBarEnabled( true );
86
87 QwtText title(*scaleTitle);
88 QFont font = _colorScale->font();
89 font.setBold( true );
90 title.setFont( font );
91 _colorScale->setTitle( title );
92
93 _colorScale->setColorMap(*scaleInterval, new t_colorMap());
94
95 QwtLinearScaleEngine scaleEngine;
96 _colorScale->setTransformation(scaleEngine.transformation());
97 _colorScale->setScaleDiv(scaleEngine.divideScale(scaleInterval->minValue(),
98 scaleInterval->maxValue(),
99 8, 5));
100 }
101 else {
102 _colorScale = 0;
103 }
104
105 // Layout
106 // ------
107 _canvas = new QWidget(this);
108 if (specialLayout) {
109 QHBoxLayout* plotLayout = new QHBoxLayout(_canvas);
110 plotLayout->addWidget(plots[0]);
111 QVBoxLayout* hlpLayout = new QVBoxLayout;
112 hlpLayout->addWidget(plots[1]);
113 hlpLayout->addWidget(plots[2]);
114 plotLayout->addLayout(hlpLayout);
115 }
116 else {
117 QHBoxLayout* plotLayout = new QHBoxLayout(_canvas);
118 for (int ip = 0; ip < plots.size(); ip++) {
119 plotLayout->addWidget(plots[ip]);
120 }
121 if (_colorScale) {
122 plotLayout->addWidget(_colorScale);
123 }
124 }
125
126 QHBoxLayout* buttonLayout = new QHBoxLayout;
127 buttonLayout->addWidget(_buttonClose);
128 buttonLayout->addWidget(_buttonPrint);
129
130 QVBoxLayout* mainLayout = new QVBoxLayout(this);
131 mainLayout->addWidget(_canvas);
132 mainLayout->addLayout(buttonLayout);
133}
134
135// Destructor
136////////////////////////////////////////////////////////////////////////////
137t_graphWin::~t_graphWin() {
138}
139
140// Accept the Options
141////////////////////////////////////////////////////////////////////////////
142void t_graphWin::slotClose() {
143 done(0);
144}
145
146// Close Dialog gracefully
147////////////////////////////////////////////////////////////////////////////
148void t_graphWin::closeEvent(QCloseEvent* event) {
149 QDialog::closeEvent(event);
150}
151
152// Print the widget
153////////////////////////////////////////////////////////////////////////////
154void t_graphWin::slotPrint() {
155
156 QPrinter printer;
157 QPrintDialog* dialog = new QPrintDialog(&printer, this);
158 dialog->setWindowTitle(tr("Print Plot"));
159 if (dialog->exec() != QDialog::Accepted) {
160 return;
161 }
162 else {
163 QPainter painter;
164 painter.begin(&printer);
165 double xscale = printer.pageRect().width()/double(_canvas->width());
166 double yscale = printer.pageRect().height()/double(_canvas->height());
167 double scale = qMin(xscale, yscale);
168 painter.translate(printer.paperRect().x() + printer.pageRect().width()/2,
169 printer.paperRect().y() + printer.pageRect().height()/2);
170 painter.scale(scale, scale);
171 painter.translate(-width()/2, -height()/2);
172 _canvas->render(&painter);
173 }
174}
175
176// Save the Widget as PNG Files
177////////////////////////////////////////////////////////////////////////////
178void t_graphWin::savePNG(const QString& dirName, QByteArray ext) {
179
180 if (dirName.isEmpty()) {
181 return;
182 }
183
184 QDir dir(dirName);
185 QFileInfo fileInfo(_fileName);
186 if (ext.isEmpty()) {
187 ext = ".png";
188 }
189 QString fileName = dir.path() + QDir::separator()
190 + fileInfo.completeBaseName() + ext;
191
192 QPalette palette = _canvas->palette();
193 QColor oldColor = palette.color(QPalette::Window);
194 palette.setColor(QPalette::Window, Qt::white);
195 _canvas->setPalette(palette);
196
197 QImage image(_canvas->size(), QImage::Format_RGB32);
198 QPainter painter(&image);
199 _canvas->render(&painter);
200 image.save(fileName,"PNG");
201
202 palette.setColor(QPalette::Window, oldColor);
203 _canvas->setPalette(palette);
204}
Note: See TracBrowser for help on using the repository browser.