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

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