Changeset - f641cc1fcdd8
[Not reviewed]
show-symbols
0 3 0
Hasan Yavuz Ă–ZDERYA - 9 years ago 2016-08-20 11:06:43
hy@ozderya.net
symbol size varies according to zoom level
3 files changed with 26 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/mainwindow.cpp
Show inline comments
 
@@ -113,6 +113,9 @@ MainWindow::MainWindow(QWidget *parent) 
 
    connect(&plotControlPanel, &PlotControlPanel::numOfSamplesChanged,
 
            this, &MainWindow::onNumOfSamplesChanged);
 

	
 
    connect(&plotControlPanel, &PlotControlPanel::numOfSamplesChanged,
 
            ui->plot, &Plot::onNumOfSamplesChanged);
 

	
 
    connect(&plotControlPanel, &PlotControlPanel::scaleChanged,
 
            ui->plot, &Plot::setAxis);
 

	
src/plot.cpp
Show inline comments
 
@@ -23,12 +23,13 @@
 
#include <qwt_symbol.h>
 
#include <qwt_plot_curve.h>
 
#include <math.h>
 
#include <algorithm>
 

	
 
#include "plot.h"
 
#include "utils.h"
 

	
 
static const int SYMBOL_SIZE = 5;
 
static const int SYMBOL_SHOW_AT_WIDTH = 15;
 
static const int SYMBOL_SHOW_AT_WIDTH = 5;
 
static const int SYMBOL_SIZE_MAX = 7;
 

	
 
Plot::Plot(QWidget* parent) :
 
    QwtPlot(parent),
 
@@ -41,7 +42,7 @@ Plot::Plot(QWidget* parent) :
 
    showLegendAction("Legend", this)
 
{
 
    isAutoScaled = true;
 
    isSymbolsOn = true;
 
    symbolSize = 0;
 

	
 
    QObject::connect(&zoomer, &Zoomer::unzoomed, this, &Plot::unzoomed);
 

	
 
@@ -94,7 +95,7 @@ Plot::Plot(QWidget* parent) :
 
    connect(this, &QwtPlot::itemAttached,
 
            [this](QwtPlotItem *plotItem, bool on)
 
            {
 
                if (isSymbolsOn) updateSymbols();
 
                if (symbolSize) updateSymbols();
 
            });
 

	
 
    snapshotOverlay = NULL;
 
@@ -253,15 +254,15 @@ void Plot::onXScaleChanged()
 
    auto sw = axisWidget(QwtPlot::xBottom);
 
    auto paintDist = sw->scaleDraw()->scaleMap().pDist();
 
    auto scaleDist = sw->scaleDraw()->scaleMap().sDist();
 
    double symDisPx = paintDist / scaleDist;
 
    int symDisPx = round(paintDist / scaleDist);
 

	
 
    if (symDisPx > SYMBOL_SHOW_AT_WIDTH)
 
    if (symDisPx < SYMBOL_SHOW_AT_WIDTH)
 
    {
 
        isSymbolsOn = true;
 
        symbolSize = 0;
 
    }
 
    else
 
    {
 
        isSymbolsOn = false;
 
        symbolSize = std::min(SYMBOL_SIZE_MAX, symDisPx-SYMBOL_SHOW_AT_WIDTH+1);
 
    }
 

	
 
    updateSymbols();
 
@@ -277,12 +278,12 @@ void Plot::updateSymbols()
 
        {
 
            QwtSymbol* symbol = NULL;
 
            QwtPlotCurve* curve = static_cast<QwtPlotCurve*>(curves[i]);
 
            if (isSymbolsOn)
 
            if (symbolSize)
 
            {
 
                symbol = new QwtSymbol(QwtSymbol::Ellipse,
 
                                       QBrush(Qt::white),
 
                                       curve->pen(),
 
                                       QSize(SYMBOL_SIZE, SYMBOL_SIZE));
 
                                       QSize(symbolSize, symbolSize));
 
            }
 
            curve->setSymbol(symbol);
 
        }
 
@@ -294,3 +295,11 @@ void Plot::resizeEvent(QResizeEvent * ev
 
    QwtPlot::resizeEvent(event);
 
    onXScaleChanged();
 
}
 

	
 
void Plot::onNumOfSamplesChanged(unsigned value)
 
{
 
    auto currentBase = zoomer.zoomBase();
 
    currentBase.setWidth(value);
 
    zoomer.setZoomBase(currentBase);
 
    onXScaleChanged();
 
}
src/plot.h
Show inline comments
 
@@ -47,7 +47,7 @@ public:
 
private:
 
    bool isAutoScaled;
 
    double yMin, yMax;
 
    bool isSymbolsOn;
 
    int symbolSize;
 
    Zoomer zoomer;
 
    ScaleZoomer sZoomer;
 
    QwtPlotGrid grid;
 
@@ -60,7 +60,7 @@ private:
 
    QAction darkBackgroundAction;
 
    QAction showLegendAction;
 

	
 
    /// update the display of symbols depending on `isSymbolsOn`
 
    /// update the display of symbols depending on `symbolSize`
 
    void updateSymbols();
 
    void resetAxes();
 
    void resizeEvent(QResizeEvent * event);
 
@@ -74,6 +74,8 @@ public slots:
 

	
 
    void flashSnapshotOverlay();
 

	
 
    void onNumOfSamplesChanged(unsigned value);
 

	
 
private slots:
 
    void unzoomed();
 
    void onXScaleChanged();
0 comments (0 inline, 0 general)