Skip to content

Instantly share code, notes, and snippets.

@joshz
Created August 14, 2011 22:31
Show Gist options
  • Save joshz/1145394 to your computer and use it in GitHub Desktop.
Save joshz/1145394 to your computer and use it in GitHub Desktop.
/******* TEST ***********/
void Plotter::addPlotPoints()
{
m_plot = new KPlotWidget( );
QGraphicsProxyWidget *proxy;
QGraphicsScene scene;
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout;
QGraphicsWidget *form = new QGraphicsWidget;
proxy = scene.addWidget(m_plot);
layout->addItem(proxy);
form->setLayout(layout);
m_layout->addItem(form);
m_plot->setMinimumSize( 400, 400 );
m_plot->setAntialiasing( true );
double x[] = {8.12, 8.13, 8.14, 8.15, 8.18, 8.20, 11.34};
// Set the boundaries of the plot to display the full extent of the sine curve:
m_plot->setLimits(lowerLimit(x[0]), upperLimit(x[5]), 1.22-.05, 9.1+.05 );
qDebug() << "[PLOTTER LIMITS]" << lowerLimit(x[0]) << upperLimit(x[5]);
// Create a KPlotObject which will display data
// points by connecting them with red line segments
// with a width of 2 pixels:
KPlotObject *sineobj = new KPlotObject( Qt::red, KPlotObject::Lines, 2 );
// Add data points to the KPlotObject for a
// sine curve (these are stored internally
// as KPlotPoints):
QList<KPlotPoint*> points;
points << new KPlotPoint(toAxisTime(x[0]), 1.22, timeToString(x[0]))
<< new KPlotPoint(toAxisTime(x[1]), 1.32, timeToString(x[1]))
<< new KPlotPoint(toAxisTime(x[2]), 1.54, timeToString(x[2]))
<< new KPlotPoint(toAxisTime(x[3]), 2.2, timeToString(x[3]))
<< new KPlotPoint(toAxisTime(x[4]), 2.1, timeToString(x[4]))
<< new KPlotPoint(toAxisTime(x[5]), 4.1, timeToString(x[5]))
<< new KPlotPoint(toAxisTime(x[6]), 9.1, timeToString(x[6]));
KPlotPoint *point;
foreach (point, points) {
sineobj->addPoint(point);
}
// Add the KPlotObject to the plot:
m_plot->addPlotObject( sineobj );
// Add a text label to the bottom axis:
m_plot->axis( KPlotWidget::BottomAxis )->setLabel( "Angle in radians" );
m_plot->axis( KPlotWidget::BottomAxis )->setTickLabelFormat('t');
m_plot->axis( KPlotWidget::RightAxis )->setTickLabelsShown(true);
m_plot->axis( KPlotWidget::BottomAxis )->setTickLabelsShown(true);
m_plot->axis( KPlotWidget::LeftAxis )->setTickLabelsShown(false);
m_plot->setShowGrid(true);
}
/*******************/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment