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

Last change on this file since 11205 was 11158, checked in by stuerze, 3 weeks ago

deprecated functions exchanged libs updated

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