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

Last change on this file since 8938 was 8566, checked in by mervart, 6 years ago
File size: 6.5 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////////////////////////////////////////////////////////////////////////////
[8566]57t_graphWin::t_graphWin(QWidget* parent, const QString& fileName, const QVector<QWidget*>& plots,
58 bool specialLayout, const QByteArray* scaleTitle,
59 const QwtInterval* scaleInterval,
60 const QVector<int>* rows) : QDialog(parent) {
[4299]61
[4450]62 _fileName = fileName;
63
[4309]64 this->setAttribute(Qt::WA_DeleteOnClose);
65
[4454]66 setWindowTitle(_fileName);
[4299]67
68 int ww = QFontMetrics(font()).width('w');
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 {
[8566]117 int iRow = -1;
118 QVBoxLayout* plotLayout = new QVBoxLayout(_canvas);
119 QHBoxLayout* rowLayout = new QHBoxLayout();
[4671]120 for (int ip = 0; ip < plots.size(); ip++) {
[8566]121 if (rows) {
122 if (iRow != -1 && iRow != rows->at(ip)) {
123 plotLayout->addLayout(rowLayout);
124 rowLayout = new QHBoxLayout();
125 }
126 iRow = rows->at(ip);
127 }
128 plots[ip]->setMinimumSize(30*ww, 30*ww);
129 rowLayout->addWidget(plots[ip]);
[4671]130 }
131 if (_colorScale) {
[8566]132 rowLayout->addWidget(_colorScale);
[4671]133 }
[8566]134 plotLayout->addLayout(rowLayout);
[4307]135 }
[4304]136
[4299]137 QHBoxLayout* buttonLayout = new QHBoxLayout;
[4337]138 buttonLayout->addWidget(_buttonClose);
[4348]139 buttonLayout->addWidget(_buttonPrint);
[4299]140
141 QVBoxLayout* mainLayout = new QVBoxLayout(this);
[4349]142 mainLayout->addWidget(_canvas);
[4299]143 mainLayout->addLayout(buttonLayout);
144}
145
146// Destructor
147////////////////////////////////////////////////////////////////////////////
148t_graphWin::~t_graphWin() {
149}
150
151// Accept the Options
152////////////////////////////////////////////////////////////////////////////
[4337]153void t_graphWin::slotClose() {
[4299]154 done(0);
155}
156
157// Close Dialog gracefully
158////////////////////////////////////////////////////////////////////////////
159void t_graphWin::closeEvent(QCloseEvent* event) {
160 QDialog::closeEvent(event);
161}
[4348]162
163// Print the widget
164////////////////////////////////////////////////////////////////////////////
165void t_graphWin::slotPrint() {
166
167 QPrinter printer;
168 QPrintDialog* dialog = new QPrintDialog(&printer, this);
169 dialog->setWindowTitle(tr("Print Plot"));
170 if (dialog->exec() != QDialog::Accepted) {
171 return;
172 }
173 else {
174 QPainter painter;
175 painter.begin(&printer);
[4349]176 double xscale = printer.pageRect().width()/double(_canvas->width());
177 double yscale = printer.pageRect().height()/double(_canvas->height());
[4348]178 double scale = qMin(xscale, yscale);
179 painter.translate(printer.paperRect().x() + printer.pageRect().width()/2,
180 printer.paperRect().y() + printer.pageRect().height()/2);
181 painter.scale(scale, scale);
182 painter.translate(-width()/2, -height()/2);
[4349]183 _canvas->render(&painter);
[4348]184 }
185}
[4444]186
187// Save the Widget as PNG Files
188////////////////////////////////////////////////////////////////////////////
[4579]189void t_graphWin::savePNG(const QString& dirName, QByteArray ext) {
190
[4451]191 if (dirName.isEmpty()) {
192 return;
193 }
[4577]194
[4452]195 QDir dir(dirName);
[4454]196 QFileInfo fileInfo(_fileName);
[4565]197 if (ext.isEmpty()) {
198 ext = ".png";
199 }
[4454]200 QString fileName = dir.path() + QDir::separator()
[4565]201 + fileInfo.completeBaseName() + ext;
[4577]202
[6262]203 QPalette palette = _canvas->palette();
204 QColor oldColor = palette.color(QPalette::Window);
205 palette.setColor(QPalette::Window, Qt::white);
206 _canvas->setPalette(palette);
207
[4579]208 QImage image(_canvas->size(), QImage::Format_RGB32);
209 QPainter painter(&image);
210 _canvas->render(&painter);
211 image.save(fileName,"PNG");
[6262]212
213 palette.setColor(QPalette::Window, oldColor);
214 _canvas->setPalette(palette);
[4444]215}
Note: See TracBrowser for help on using the repository browser.