Changeset - c9922f40a20e
[Not reviewed]
Hasan Yavuz Ă–ZDERYA - 7 years ago 2018-09-27 16:58:01
hy@ozderya.net
draw dots on tracked points
1 file changed with 15 insertions and 7 deletions:
0 comments (0 inline, 0 general)
src/zoomer.cpp
Show inline comments
 
@@ -10,26 +10,25 @@
 

	
 
  serialplot is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  GNU General Public License for more details.
 

	
 
  You should have received a copy of the GNU General Public License
 
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include "zoomer.h"
 
#include <qwt_plot.h>
 
#include <QtDebug>
 

	
 
#include <QPen>
 
#include <QMouseEvent>
 

	
 
Zoomer::Zoomer(QWidget* widget, const Stream* stream, bool doReplot) :
 
    ScrollZoomer(widget)
 
{
 
    is_panning = false;
 
    _stream = stream;
 

	
 
    setTrackerMode(AlwaysOn);
 

	
 
    // set corner widget between the scrollbars with default background color
 
    auto cornerWidget = new QWidget();
 
@@ -110,38 +109,47 @@ void Zoomer::drawTracker(QPainter* paint
 
    {
 
        drawValues(painter);
 
    }
 
    return;
 
}
 

	
 
void Zoomer::drawValues(QPainter* painter) const
 
{
 
    painter->save();
 

	
 
    double x = invTransform(trackerPosition()).x();
 
    auto values = findValues(x);
 
    qDebug() <<  x << ":" << values; // TODO: cleanup
 

	
 
    // draw vertical line
 
    painter->setPen(Qt::white);
 
    auto linePen = QPen(Qt::DotLine);
 
    linePen.setColor(Qt::white);
 
    painter->setPen(linePen);
 
    const QRect pRect = pickArea().boundingRect().toRect();
 
    int px = trackerPosition().x();
 
    painter->drawLine(px, pRect.top(), px, pRect.bottom());
 

	
 
    for (auto val : values)
 
    // draw sample values
 
    for (int ci = 0; ci < values.size(); ci++)
 
    {
 
        double val = values[ci];
 
        if (!std::isnan(val))
 
        {
 
            painter->drawText(transform(QPointF(x, val)),
 
                              QString("%1").arg(val));
 
            auto p = transform(QPointF(x, val));
 

	
 
            painter->setBrush(_stream->channel(ci)->color());
 
            painter->setPen(Qt::NoPen);
 
            painter->drawEllipse(p, 4, 4);
 

	
 
            painter->setPen(Qt::white);
 
            painter->drawText(p, QString("%1").arg(val));
 
        }
 
    }
 

	
 
    painter->restore();
 
}
 

	
 
QVector<double> Zoomer::findValues(double x) const
 
{
 
    // TODO: process only channel(s) of this plot
 
    unsigned nc = _stream->numChannels();
 
    QVector<double> r(nc);
 
    for (unsigned ci = 0; ci < nc; ci++)
0 comments (0 inline, 0 general)