Changeset - 347335d8956f
[Not reviewed]
Hasan Yavuz Ă–ZDERYA - 9 years ago 2017-03-13 11:18:26
hy@ozderya.net
fixed wrong x axis scale at startup
2 files changed with 10 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/plot.cpp
Show inline comments
 
@@ -25,14 +25,12 @@
 
#include <math.h>
 
#include <algorithm>
 

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

	
 
#include <QtDebug>
 

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

	
 
Plot::Plot(QWidget* parent) :
 
    QwtPlot(parent),
 
    zoomer(this->canvas(), false),
 
@@ -93,31 +91,28 @@ void Plot::setYAxis(bool autoScaled, dou
 
    zoomer.zoom(0);
 
    resetAxes();
 
}
 

	
 
void Plot::setXAxis(double xMin, double xMax)
 
{
 
    qDebug() << "setXAxis:" << xMin << xMax;
 
    _xMin = xMin;
 
    _xMax = xMax;
 

	
 
    zoomer.zoom(0); // unzoom
 

	
 
    // set axis
 
    setAxisScale(QwtPlot::xBottom, xMin, xMax);
 
    replot(); // Note: if we don't replot here scale at startup isn't set correctly
 

	
 
    // reset zoom base
 
    auto base = zoomer.zoomBase();
 
    base.setLeft(xMin);
 
    base.setRight(xMax);
 
    zoomer.setZoomBase(base);
 

	
 
    qDebug() << "base:" << base;
 

	
 
    onXScaleChanged();
 
    replot();
 
}
 

	
 
void Plot::resetAxes()
 
{
 
    // reset y axis
 
    if (isAutoScaled)
src/plotmanager.cpp
Show inline comments
 
@@ -14,13 +14,12 @@
 
  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 <QtDebug>
 
#include "qwt_symbol.h"
 

	
 
#include "plot.h"
 
#include "plotmanager.h"
 
#include "utils.h"
 
#include "setting_defines.h"
 
@@ -251,12 +250,21 @@ Plot* PlotManager::addPlotWidget()
 
    plot->showGrid(showGridAction.isChecked());
 
    plot->showMinorGrid(showMinorGridAction.isChecked());
 
    plot->showLegend(showLegendAction.isChecked());
 
    plot->showDemoIndicator(isDemoShown);
 
    plot->setYAxis(_autoScaled, _yMin, _yMax);
 

	
 
    if (_xAxisAsIndex)
 
    {
 
        plot->setXAxis(0, _numOfSamples);
 
    }
 
    else
 
    {
 
        plot->setXAxis(_xMin, _xMax);
 
    }
 

	
 
    return plot;
 
}
 

	
 
void PlotManager::addCurve(QString title, FrameBuffer* buffer)
 
{
 
    auto curve = new QwtPlotCurve(title);
 
@@ -455,16 +463,14 @@ void PlotManager::onNumOfSamplesChanged(
 
{
 
    _numOfSamples = value;
 
    if (_xAxisAsIndex)
 
    {
 
        for (auto plot : plotWidgets)
 
        {
 
            // plot->onNumOfSamplesChanged(value);
 
            plot->setXAxis(0, value);
 
        }
 
        qDebug() << "_xAxisAsIndex" << value;
 
    }
 
}
 

	
 
void PlotManager::saveSettings(QSettings* settings)
 
{
 
    settings->beginGroup(SettingGroup_Plot);
0 comments (0 inline, 0 general)