Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
void PlottingGraph::draw()
{
m_time++;
memmove(m_y, &m_y[1], 99 * sizeof(double));
m_y[99] = 10000 * sin((double)m_time / 360 * 3.1415 * 10) + rand() % 4000 - 2000;//m_y[99] = 100 * sin((double)m_time / 360 * 3.1415 * 10) + rand() % 400 - 200;
for (int i = 0; i < 100; i++)
m_x[i]++;
if (!m_curve)
{
qreal left = int(rect.left()) - (int(rect.left()) % gridSize);
qreal top = int(rect.top()) - (int(rect.top()) % gridSize);
QVarLengthArray<QLineF, 100> lines;
for (qreal x = left; x < rect.right(); x += gridSize)
lines.append(QLineF(x, rect.top(), x, rect.bottom()));
for (qreal y = top; y < rect.bottom(); y += gridSize)
lines.append(QLineF(rect.left(), y, rect.right(), y));
qDebug() << lines.size();
painter->drawLines(lines.data(), lines.size());
m_curve = new QwtPlotCurve();
m_curve->setPen(QPen(Qt::blue));//setPen(QPen(QColor::fromRgb(255, 255, 0), 3));
m_curve->setData(m_x, m_y, 100);
m_curve->attach(myPlot);
}
m_curve->setData(m_x, m_y, 100);
myPlot->setAxisScale(QwtPlot::xBottom, m_time, m_time + 100); // auto replots
}
|
This post has been edited 1 times, last edit by "crazycoder" (May 15th 2008, 11:59am)