Hey.
I've a plot with a curve and a bunch of markers on it.
When zooming in sometimes I get some random markers apearing.
ufos.jpg
Points with text are added by me, all other points appear from somewhere.
I have no idea why it's happening. Maybe I'm missing some zoomer setting?
Anyway, I've created simple example app to demonstrate the issue:
//mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
{
Q_OBJECT
public:
~MainWindow();
private:
void addCurve( void );
void addMarkers( void );
QVector<double> x;
QVector<double> y;
};
#endif // MAINWINDOW_H
//mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
class QwtPlot;
class QwtPlotZoomer;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
private:
void addCurve( void );
void addMarkers( void );
QwtPlot* plot;
QwtPlotZoomer* zoomer;
QVector<double> x;
QVector<double> y;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
// mainwindow.cpp
#include "mainwindow.h"
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_marker.h>
#include <qwt_symbol.h>
#include <qwt_plot_zoomer.h>
MainWindow
::MainWindow(QWidget *parent
){
this->addCurve();
this->addMarkers();
this->zoomer->setZoomBase();;
this->setCentralWidget(this->plot);
}
MainWindow::~MainWindow()
{
}
void MainWindow::addCurve( void )
{
int count = 20000;
for(int i = 0; i < count; ++i)
{
this->x.append(i);
this->y.append(i);
}
curve->setRawData(this->x.constBegin(), this->y.constBegin(), this->x.size());
curve->attach(this->plot);
}
void MainWindow::addMarkers( void )
{
int count = 5000;
int step = this->x.size()/count;
for(int i = 0; i < count; ++i)
{
int x = i*step;
int y = this->y[x];
m->setValue(x, y);
m
->setLabel
(QString("%1x%2").
arg(x
).
arg(y
));
m->attach(this->plot);
}
}
// mainwindow.cpp
#include "mainwindow.h"
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_marker.h>
#include <qwt_symbol.h>
#include <qwt_plot_zoomer.h>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
this->plot = new QwtPlot(this);
this->zoomer = new QwtPlotZoomer(this->plot->canvas());
this->addCurve();
this->addMarkers();
this->zoomer->setZoomBase();;
this->setCentralWidget(this->plot);
}
MainWindow::~MainWindow()
{
}
void MainWindow::addCurve( void )
{
int count = 20000;
for(int i = 0; i < count; ++i)
{
this->x.append(i);
this->y.append(i);
}
QwtPlotCurve* curve = new QwtPlotCurve();
curve->setRawData(this->x.constBegin(), this->y.constBegin(), this->x.size());
curve->attach(this->plot);
}
void MainWindow::addMarkers( void )
{
int count = 5000;
int step = this->x.size()/count;
for(int i = 0; i < count; ++i)
{
int x = i*step;
int y = this->y[x];
QwtPlotMarker* m = new QwtPlotMarker();
m->setSymbol(QwtSymbol(QwtSymbol::Ellipse, QBrush(Qt::red), QPen(Qt::red), QSize(5,5)));
m->setValue(x, y);
m->setLabel(QString("%1x%2").arg(x).arg(y));
m->attach(this->plot);
}
}
To copy to clipboard, switch view to plain text mode
Any suggestions how to get rid of that UFOs are welcome.
PS: I'm running w7 64 bit with qt 4.6.3 and qwt 5.2.0.
Bookmarks