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
RevLine 
[4299]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 *
[8231]37 * Changes:
[4299]38 *
39 * -----------------------------------------------------------------------*/
40
[4580]41#include <qwt_scale_widget.h>
[4330]42#include <qwt_scale_engine.h>
[4299]43
[8252]44#include <QDir>
45#include <QFileInfo>
46#include <QHBoxLayout>
47#include <QVBoxLayout>
48#include <QPushButton>
49
[4580]50#include "graphwin.h"
51#include "bncsettings.h"
52
[4299]53using namespace std;
54
55// Constructor
56////////////////////////////////////////////////////////////////////////////
[8231]57t_graphWin::t_graphWin(QWidget* parent, const QString& fileName,
[8556]58 const QVector<QWidget*>& plots, const QByteArray* scaleTitle,
59 const QwtInterval* scaleInterval, bool specialLayout) : QDialog(parent) {
[4299]60
[4450]61 _fileName = fileName;
62
[4309]63 this->setAttribute(Qt::WA_DeleteOnClose);
64
[4454]65 setWindowTitle(_fileName);
[4299]66
67 int ww = QFontMetrics(font()).width('w');
[4307]68 setMinimumSize(plots.size()*40*ww, 40*ww);
[4299]69
[4304]70 // Buttons
71 // -------
[4337]72 _buttonClose = new QPushButton(tr("Close"), this);
73 _buttonClose->setMaximumWidth(10*ww);
74 connect(_buttonClose, SIGNAL(clicked()), this, SLOT(slotClose()));
[4299]75
[4348]76 _buttonPrint = new QPushButton(tr("Print"), this);
77 _buttonPrint->setMaximumWidth(10*ww);
78 connect(_buttonPrint, SIGNAL(clicked()), this, SLOT(slotPrint()));
79
[4329]80 // Color Scale
81 // -----------
[4573]82 if (scaleTitle && scaleInterval) {
83 _colorScale = new QwtScaleWidget( this );
84 _colorScale->setAlignment( QwtScaleDraw::RightScale );
85 _colorScale->setColorBarEnabled( true );
[8231]86
[4573]87 QwtText title(*scaleTitle);
88 QFont font = _colorScale->font();
89 font.setBold( true );
90 title.setFont( font );
91 _colorScale->setTitle( title );
[8231]92
[4573]93 _colorScale->setColorMap(*scaleInterval, new t_colorMap());
[8231]94
[4573]95 QwtLinearScaleEngine scaleEngine;
[8127]96 _colorScale->setTransformation(scaleEngine.transformation());
97 _colorScale->setScaleDiv(scaleEngine.divideScale(scaleInterval->minValue(),
[4573]98 scaleInterval->maxValue(),
99 8, 5));
100 }
101 else {
102 _colorScale = 0;
103 }
[4329]104
[4304]105 // Layout
106 // ------
[4349]107 _canvas = new QWidget(this);
[8556]108 if (specialLayout) {
[4671]109 QHBoxLayout* plotLayout = new QHBoxLayout(_canvas);
[8556]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);
[4671]118 for (int ip = 0; ip < plots.size(); ip++) {
119 plotLayout->addWidget(plots[ip]);
120 }
121 if (_colorScale) {
122 plotLayout->addWidget(_colorScale);
123 }
[4307]124 }
[4304]125
[4299]126 QHBoxLayout* buttonLayout = new QHBoxLayout;
[4337]127 buttonLayout->addWidget(_buttonClose);
[4348]128 buttonLayout->addWidget(_buttonPrint);
[4299]129
130 QVBoxLayout* mainLayout = new QVBoxLayout(this);
[4349]131 mainLayout->addWidget(_canvas);
[4299]132 mainLayout->addLayout(buttonLayout);
133}
134
135// Destructor
136////////////////////////////////////////////////////////////////////////////
137t_graphWin::~t_graphWin() {
138}
139
140// Accept the Options
141////////////////////////////////////////////////////////////////////////////
[4337]142void t_graphWin::slotClose() {
[4299]143 done(0);
144}
145
146// Close Dialog gracefully
147////////////////////////////////////////////////////////////////////////////
148void t_graphWin::closeEvent(QCloseEvent* event) {
149 QDialog::closeEvent(event);
150}
[4348]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);
[4349]165 double xscale = printer.pageRect().width()/double(_canvas->width());
166 double yscale = printer.pageRect().height()/double(_canvas->height());
[4348]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);
[4349]172 _canvas->render(&painter);
[4348]173 }
174}
[4444]175
176// Save the Widget as PNG Files
177////////////////////////////////////////////////////////////////////////////
[4579]178void t_graphWin::savePNG(const QString& dirName, QByteArray ext) {
179
[4451]180 if (dirName.isEmpty()) {
181 return;
182 }
[4577]183
[4452]184 QDir dir(dirName);
[4454]185 QFileInfo fileInfo(_fileName);
[4565]186 if (ext.isEmpty()) {
187 ext = ".png";
188 }
[4454]189 QString fileName = dir.path() + QDir::separator()
[4565]190 + fileInfo.completeBaseName() + ext;
[4577]191
[6262]192 QPalette palette = _canvas->palette();
193 QColor oldColor = palette.color(QPalette::Window);
194 palette.setColor(QPalette::Window, Qt::white);
195 _canvas->setPalette(palette);
196
[4579]197 QImage image(_canvas->size(), QImage::Format_RGB32);
198 QPainter painter(&image);
199 _canvas->render(&painter);
200 image.save(fileName,"PNG");
[6262]201
202 palette.setColor(QPalette::Window, oldColor);
203 _canvas->setPalette(palette);
[4444]204}
Note: See TracBrowser for help on using the repository browser.