22 #include "MPDiagram.hpp" 24 #include <qwt_legend.h> 25 #include <qwt_plot_marker.h> 26 #include <qwt_scale_widget.h> 27 #include <qwt_text_label.h> 31 #include <boost/scoped_ptr.hpp> 33 QwtText MPTimeScaleDraw::label(
double value)
const 37 NumberStr.sprintf(
"%1.2f", value);
38 if (NumberStr.endsWith(QLatin1String(
".00")))
40 NumberStr.remove(NumberStr.size()-3, 3);
42 QwtText Text(NumberStr);
44 Text.setColor(Qt::black);
49 MPPlotCurve::MPPlotCurve() : QwtPlotCurve()
51 setRenderHint(QwtPlotItem::RenderAntialiased);
52 setLegendAttribute(QwtPlotCurve::LegendShowLine,
true);
54 setLegendIconSize(QSize(20, 5));
55 setStyle(QwtPlotCurve::Lines);
59 void MPLegendLabel::drawText(QPainter* painter,
const QRectF& rect)
64 #if defined(__unix__) && !defined(__ANDROID__) 66 if (text().text().contains(
"<sub>"))
68 newRect.setY(newRect.y()-14);
70 newRect.setY(newRect.y()-6);
73 QwtTextLabel::drawText(painter, newRect);
77 void MPLegendLabel::paintEvent(QPaintEvent* event)
84 QwtLegendLabel::paintEvent(event);
88 QWidget* MPLegend::createWidget(
const QwtLegendData& legend_data)
const 95 Label->setItemMode(defaultItemMode());
96 Label->setData(legend_data);
97 connect(Label, SIGNAL(clicked()), SLOT(itemClicked()));
98 connect(Label, SIGNAL(checked(
bool)), SLOT(itemChecked(
bool)));
104 MajorTicksGrid(new QwtPlotGrid)
108 insertLegend(
new MPLegend(), QwtPlot::TopLegend);
109 QWidget* ContentsWidget =
static_cast<QwtLegend*
>(legend())->contentsWidget();
110 #if defined(__ANDROID__) 111 boost::scoped_ptr<QFont> Font(
new QFont(
"Courier New", 7));
113 setAxisFont(QwtPlot::xBottom, *Font);
114 setAxisFont(QwtPlot::yLeft, *Font);
115 boost::scoped_ptr<QFont> TitleFont(
new QFont(
"Courier New", 8, QFont::Bold));
118 Title.setFont(*TitleFont);
119 setAxisTitle(QwtPlot::xBottom, Title);
120 ContentsWidget->setStyleSheet(ContentsWidget->styleSheet()+
" QWidget { font: 8pt \"Courier New\"; }");
122 ContentsWidget->setStyleSheet(ContentsWidget->styleSheet()+
" QWidget { font: 10.5pt \"Courier New\"; }");
125 ContentsWidget->layout()->setMargin(0);
126 ContentsWidget->layout()->setSpacing(0);
128 setContentsMargins(10, 10, 10, 10);
133 SetMinorGridEnabled(
true);
136 SetMajorGridEnabled(
true);
138 QwtText AxisTitle = axisTitle(QwtPlot::xBottom);
140 AxisTitle.setColor(Qt::black);
141 setAxisTitle(QwtPlot::xBottom, AxisTitle);
144 axisWidget(QwtPlot::xBottom)->setPalette(Qt::white);
145 axisWidget(QwtPlot::yLeft)->setPalette(Qt::white);
153 iter.value()->detach();
159 iter.value()->detach();
166 void MPDiagram::SetHorizontalTicks(
double first,
double last)
170 for (
int i = 0; i <= 10; ++i)
172 Ticks.push_back(first+i*(last-first) / 10);
174 QwtScaleDiv ScaleDiv = axisScaleDiv(QwtPlot::xBottom);
176 ScaleDiv.setTicks(QwtScaleDiv::MajorTick, Ticks);
178 for (
int i = 0; i <= 40; ++i)
180 Ticks.push_back(first+i*(last-first) / 40);
182 ScaleDiv.setTicks(QwtScaleDiv::MinorTick, Ticks);
183 setAxisScaleDiv(QwtPlot::xBottom, ScaleDiv);
189 void MPDiagram::SetVerticalTicks(
double first,
double last)
193 for (
int i = 0; i <= 10; ++i)
195 Ticks.push_back(first+i*(last-first) / 10);
197 QwtScaleDiv ScaleDiv = axisScaleDiv(QwtPlot::yLeft);
199 ScaleDiv.setTicks(QwtScaleDiv::MajorTick, Ticks);
201 ScaleDiv.setTicks(QwtScaleDiv::MediumTick, Ticks);
203 ScaleDiv.setTicks(QwtScaleDiv::MinorTick, Ticks);
204 setAxisScaleDiv(QwtPlot::yLeft, ScaleDiv);
210 void MPDiagram::SetMinorGridEnabled(
bool new_state)
227 void MPDiagram::SetMajorGridEnabled(
bool new_state)
244 QwtPlotMarker* MPDiagram::AddMissingDataMarker(
float value)
249 QwtPlotMarker* NewMarker =
new QwtPlotMarker();
251 NewMarker->setLineStyle(QwtPlotMarker::VLine);
252 NewMarker->setLabelAlignment(Qt::AlignRight | Qt::AlignBottom);
253 NewMarker->setLinePen(QPen(QColor(0x90, 0x90, 0x90), 0, Qt::DashLine));
254 NewMarker->setValue(value, 0.0);
255 NewMarker->attach(
this);
261 QwtPlotMarker* MPDiagram::AddStickMarker(
float value,
const QColor& color,
bool big_stick)
266 QwtPlotMarker* NewMarker =
new QwtPlotMarker();
269 NewMarker->setLineStyle(QwtPlotMarker::VDoubleStick);
271 NewMarker->setLineStyle(QwtPlotMarker::VStick);
272 NewMarker->setLabelAlignment(Qt::AlignRight | Qt::AlignBottom);
273 NewMarker->setLinePen(QPen(color, 0, Qt::SolidLine));
274 NewMarker->setValue(value, 0.0);
275 NewMarker->attach(
this);
281 void MPDiagram::RemoveMissingDataMarker(
float value)
288 Iter.value()->detach();
294 void MPDiagram::RemoveStickMarker(
float value)
301 Iter.value()->detach();
virtual ~MPDiagram()
Class destructor.
MP::TimestampMarkerMap StickMarkers
Stick marker list.
Legend label on QwtLegendLabel.
Legend based on QwtLegend.
QwtPlotGrid * MinorTicksGrid
Helper grid for the minor ticks.
MP::TimestampMarkerMap MissingDataMarkers
Missing data marker list.
Time scale draw based on QwtScaleDraw.
MPDiagram(bool enable_legend=true)
Class constructor.
QwtPlotGrid * MajorTicksGrid
Helper grid for the major ticks.