source: ntrip/trunk/BNC/src/rinex/availplot.cpp@ 4618

Last change on this file since 4618 was 4618, checked in by mervart, 12 years ago
File size: 5.3 KB
Line 
1
2#include <qwt_scale_draw.h>
3#include <qwt_text.h>
4#include <qwt_legend.h>
5
6#include "availplot.h"
7#include "reqcanalyze.h"
8
9//
10//////////////////////////////////////////////////////////////////////////////
11class t_scaleDrawTime : public QwtScaleDraw {
12 public:
13 t_scaleDrawTime() {}
14 virtual QwtText label(double mjdX24) const {
15 bncTime epoTime; epoTime.setmjd(mjdX24/24.0);
16 return QwtText(epoTime.timestr(0,':').c_str());
17 }
18};
19
20//
21//////////////////////////////////////////////////////////////////////////////
22class t_scaleDrawPrn : public QwtScaleDraw {
23 public:
24 t_scaleDrawPrn() {}
25 virtual QwtText label(double iPrn) const {
26 return _yLabels[iPrn];
27 }
28 QMap<int, QString> _yLabels;
29};
30
31// Constructor
32//////////////////////////////////////////////////////////////////////////////
33t_availPlot::t_availPlot(QWidget* parent,
34 QMap<QString, t_availData>* availDataMap)
35: QwtPlot(parent) {
36
37 setCanvasBackground(QColor(Qt::white));
38
39 // Axes
40 // ----
41 setAxisScaleDraw(QwtPlot::xBottom, new t_scaleDrawTime());
42 setAxisLabelRotation(QwtPlot::xBottom, -10.0);
43 setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom);
44
45 t_scaleDrawPrn* scaleDrawPrn = new t_scaleDrawPrn();
46 setAxisScaleDraw(QwtPlot::yLeft, scaleDrawPrn);
47
48 // Smaller Font for y-Axis
49 // -----------------------
50 QFont yFont = axisFont(QwtPlot::yLeft);
51 yFont.setPointSize(yFont.pointSize()/2);
52 setAxisFont(QwtPlot::yLeft, yFont);
53
54 // Symbols
55 // -------
56 QColor red(220,20,60);
57 QColor green(150,200,50);
58 QColor blue(60,100,200);
59 QwtSymbol symbRed(QwtSymbol::Rect, QBrush(red), QPen(red), QSize(2,1));
60 QwtSymbol symbGreen(QwtSymbol::Rect, QBrush(green), QPen(green), QSize(2,1));
61 QwtSymbol symbBlue (QwtSymbol::Rect, QBrush(blue), QPen(blue), QSize(2,1));
62
63 // Legend
64 // ------
65 QwtLegend* legend = new QwtLegend;
66 insertLegend(legend, QwtPlot::RightLegend);
67
68 QVector<double> xData0(0);
69 QVector<double> yData0(0);
70 addCurve("OK ", symbGreen, xData0, yData0);
71 addCurve("Gap ", symbBlue, xData0, yData0);
72 addCurve("Slip", symbRed, xData0, yData0);
73
74 // Curves
75 // ------
76 int iC = 0;
77 QMapIterator<QString, t_availData > it(*availDataMap);
78 while (it.hasNext()) {
79 it.next();
80 ++iC;
81 const QString& prn = it.key();
82 const t_availData& availData = it.value();
83
84 scaleDrawPrn->_yLabels[iC] = prn;
85
86 double eps = 0.1;
87
88 // L1 ok Curve
89 // -----------
90 if (availData._L1ok.size()) {
91 const QVector<double>& xData = availData._L1ok;
92 QVector<double> yData(xData.size(), double(iC)+eps);
93 QwtPlotCurve* curve = addCurve(prn, symbGreen, xData, yData);
94 curve->setItemAttribute(QwtPlotItem::Legend, false);
95 }
96
97 // L2 ok Curve
98 // -----------
99 if (availData._L2ok.size()) {
100 const QVector<double>& xData = availData._L2ok;
101 QVector<double> yData(xData.size(), double(iC)-eps);
102 QwtPlotCurve* curve = addCurve(prn, symbGreen, xData, yData);
103 curve->setItemAttribute(QwtPlotItem::Legend, false);
104 }
105
106 // L1 gaps Curve
107 // -------------
108 if (availData._L1gap.size()) {
109 const QVector<double>& xData = availData._L1gap;
110 QVector<double> yData(xData.size(), double(iC)+eps);
111 QwtPlotCurve* curve = addCurve(prn, symbBlue, xData, yData);
112 curve->setItemAttribute(QwtPlotItem::Legend, false);
113 }
114
115 // L2 gaps Curve
116 // -------------
117 if (availData._L2gap.size()) {
118 const QVector<double>& xData = availData._L2gap;
119 QVector<double> yData(xData.size(), double(iC)-eps);
120 QwtPlotCurve* curve = addCurve(prn, symbBlue, xData, yData);
121 curve->setItemAttribute(QwtPlotItem::Legend, false);
122 }
123
124 // L1 slips Curve
125 // --------------
126 if (availData._L1slip.size()) {
127 const QVector<double>& xData = availData._L1slip;
128 QVector<double> yData(xData.size(), double(iC)+eps);
129 QwtPlotCurve* curve = addCurve(prn, symbRed, xData, yData);
130 curve->setItemAttribute(QwtPlotItem::Legend, false);
131 }
132
133 // L2 slips Curve
134 // --------------
135 if (availData._L2slip.size()) {
136 const QVector<double>& xData = availData._L2slip;
137 QVector<double> yData(xData.size(), double(iC)-eps);
138 QwtPlotCurve* curve = addCurve(prn, symbRed, xData, yData);
139 curve->setItemAttribute(QwtPlotItem::Legend, false);
140 }
141 }
142
143 QList<double> ticks[QwtScaleDiv::NTickTypes];
144 QList<double> &majorTicks = ticks[QwtScaleDiv::MajorTick];
145 QMapIterator<int, QString> itT(scaleDrawPrn->_yLabels);
146 while (itT.hasNext()) {
147 itT.next();
148 majorTicks << double(itT.key());
149 }
150 QwtScaleDiv yScaleDiv(majorTicks.first()-0.5, majorTicks.last()+0.5, ticks );
151 setAxisScaleDiv(QwtPlot::yLeft, yScaleDiv);
152
153 // Important !!!
154 // -------------
155 replot();
156}
157
158// Add Curve
159//////////////////////////////////////////////////////////////////////////////
160QwtPlotCurve* t_availPlot::addCurve(const QString& name,
161 const QwtSymbol& symbol,
162 const QVector<double>& xData,
163 const QVector<double>& yData) {
164 QwtPlotCurve* curve = new QwtPlotCurve(name);
165 curve->setSymbol(new QwtSymbol(symbol));
166 curve->setStyle(QwtPlotCurve::NoCurve);
167 curve->setXAxis(QwtPlot::xBottom);
168 curve->setYAxis(QwtPlot::yLeft);
169 curve->setSamples(xData, yData);
170 curve->attach(this);
171 return curve;
172}
Note: See TracBrowser for help on using the repository browser.