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

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