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

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