From: Alexey Chernobaev Date: Fri, 16 Mar 2018 15:40:23 +0000 (+0300) Subject: implementing tooltips for histograms (QWT), in progress X-Git-Tag: submit/tizen/20180620.112952^2^2~53 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e879b76a5d0ac78c3dc13ffe944a7dc85d900878;p=sdk%2Ftools%2Fheaptrack.git implementing tooltips for histograms (QWT), in progress --- diff --git a/src/analyze/gui/histogramwidgetqwtplot.cpp b/src/analyze/gui/histogramwidgetqwtplot.cpp index 917b814..7cd3a8b 100644 --- a/src/analyze/gui/histogramwidgetqwtplot.cpp +++ b/src/analyze/gui/histogramwidgetqwtplot.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include class HistogramScaleDraw: public QwtScaleDraw @@ -26,8 +27,44 @@ private: QVector m_rowNames; }; +class Picker: public QwtPlotPicker +{ +public: + Picker(HistogramWidgetQwtPlot *plot) + : QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yRight, plot->canvas()) + { + setTrackerMode(QwtPlotPicker::AlwaysOn); + } + +protected: + virtual QwtText trackerText(const QPoint &pos) const + { +// qDebug() << "Picker: (" << pos.x() << "; " << pos.y() << ")"; + return QwtText(QString(" (%1, %2) ").arg(pos.x()).arg(pos.y())); + } +/* virtual QwtText trackerTextF(const QPointF &pos) const + { +// qDebug() << "Picker: (" << pos.x() << "; " << pos.y() << ")"; + return QwtText(QString(" (%1, %2) ").arg(pos.x()).arg(pos.y())); + }*/ +}; + +class MultiBarChart: public QwtPlotMultiBarChart +{ +public: + +protected: + virtual void drawBar( QPainter *painter, int sampleIndex, + int barIndex, const QwtColumnRect &rect) const + { + qDebug() << "drawBar: (sampleIndex=" << sampleIndex << "; barIndex=" << barIndex + << "; " << rect.toRect() << ")"; + QwtPlotMultiBarChart::drawBar(painter, sampleIndex, barIndex, rect); + } +}; + HistogramWidgetQwtPlot::HistogramWidgetQwtPlot(QWidget *parent) - : QwtPlot(parent), m_model(nullptr) + : QwtPlot(parent), m_model(nullptr), m_picker(new Picker(this)) { setCanvasBackground(Qt::white); enableAxis(QwtPlot::yRight); @@ -51,12 +88,12 @@ void HistogramWidgetQwtPlot::rebuild(bool resetZoomAndPan) setAxisAutoScale(QwtPlot::yRight); - auto totalBarChart = new QwtPlotMultiBarChart(); + auto totalBarChart = new MultiBarChart(); totalBarChart->setStyle(QwtPlotMultiBarChart::Stacked); totalBarChart->setLayoutHint(0.33); totalBarChart->setLayoutPolicy(QwtPlotMultiBarChart::ScaleSamplesToAxes); - auto barChart = new QwtPlotMultiBarChart(); + auto barChart = new MultiBarChart(); barChart->setStyle(QwtPlotMultiBarChart::Stacked); barChart->setLayoutHint(totalBarChart->layoutHint()); barChart->setLayoutPolicy(QwtPlotMultiBarChart::ScaleSamplesToAxes); diff --git a/src/analyze/gui/histogramwidgetqwtplot.h b/src/analyze/gui/histogramwidgetqwtplot.h index 8d24250..a22eafc 100644 --- a/src/analyze/gui/histogramwidgetqwtplot.h +++ b/src/analyze/gui/histogramwidgetqwtplot.h @@ -4,6 +4,7 @@ #include class HistogramModel; +class Picker; class HistogramWidgetQwtPlot : public QwtPlot { @@ -16,6 +17,8 @@ public: private: HistogramModel *m_model; + + Picker *m_picker; }; #endif // HISTOGRAMWIDGETQWTPLOT_H