Hello. I have a plot, which is updated on a timer. New points are taken from the database.
New points are added to the chart every 3 seconds and the plot is redrawn.
curv1
->setPen
(QPen(Qt
::red));
curv1->setAxes(xb,yl);
myPlot->enableAxis(yl);
curv1->attach(myPlot);
connect (timerUpdPlot, SIGNAL(timeout()), SLOT(realTimePoints()));
timerUpdPlot->start(3000);
realTimePoints();
curv1 = new QwtPlotCurve();
curv1->setPen(QPen(Qt::red));
curv1->setAxes(xb,yl);
myPlot->enableAxis(yl);
curv1->attach(myPlot);
timerUpdPlot = new QTimer;
connect (timerUpdPlot, SIGNAL(timeout()), SLOT(realTimePoints()));
timerUpdPlot->start(3000);
realTimePoints();
To copy to clipboard, switch view to plain text mode
Curve is connected to zoomer
d_zoomer[0] = new Zoomer( xb, yl, myPlot->canvas());
d_zoomer
[0]->setRubberBand
(QwtPicker::RectRubberBand);
d_zoomer
[0]->setRubberBandPen
(QColor(Qt
::white));
d_zoomer
[0]->setTrackerPen
(QColor(Qt
::white));
d_zoomer[0] = new Zoomer( xb, yl, myPlot->canvas());
d_zoomer[0]->setRubberBand(QwtPicker::RectRubberBand);
d_zoomer[0]->setRubberBandPen(QColor(Qt::white));
d_zoomer[0]->setTrackerPen(QColor(Qt::white));
To copy to clipboard, switch view to plain text mode
void TrendTop::realTimePoints()
{
if (!db.open()) {
CreateConnection();
}
if (db.isOpen())
{
query.exec("SELECT tm, val FROM currstamp where id = 1136");
if (query.next())
{
osX = query.value(0).toUInt();
osY = query.value(1).toDouble();
}
X++;
vectX.append(X);
vectY.append(osY);
curv1->setSamples(vectX,vectY);
myPlot->replot();
}
}
void TrendTop::realTimePoints()
{
if (!db.open()) {
CreateConnection();
}
if (db.isOpen())
{
QSqlQuery query(db);
query.exec("SELECT tm, val FROM currstamp where id = 1136");
if (query.next())
{
osX = query.value(0).toUInt();
osY = query.value(1).toDouble();
}
X++;
vectX.append(X);
vectY.append(osY);
curv1->setSamples(vectX,vectY);
myPlot->replot();
}
}
To copy to clipboard, switch view to plain text mode
1.JPG
But when I click zoom, plot itself is scaled to the very first point on the graph.
2.jpg
Although, I must first select the area that I want to scale.
Slot is invoked by pressing the zoom:
void TrendTop::enableZoomMode(bool on)
{
d_panner->setEnabled(on);
d_zoomer[0]->setEnabled(on);
d_zoomer[0]->zoom(0);
d_zoomer1[0]->setEnabled(on);
d_zoomer1[0]->zoom(0);
}
void TrendTop::enableZoomMode(bool on)
{
d_panner->setEnabled(on);
d_zoomer[0]->setEnabled(on);
d_zoomer[0]->zoom(0);
d_zoomer1[0]->setEnabled(on);
d_zoomer1[0]->zoom(0);
}
To copy to clipboard, switch view to plain text mode
What am I doing wrong?
Bookmarks