21 #include "datastreamswidget.h"
24 #include <QPushButton>
27 #include <QMutexLocker>
28 #include <QProgressDialog>
34 mutex( QMutex::Recursive ) {
36 QVBoxLayout* lay =
new QVBoxLayout(
this );
39 QHBoxLayout* toolLay =
new QHBoxLayout();
40 lay->addLayout( toolLay );
42 QCheckBox* ck =
new QCheckBox(
"Automatic Update",
this );
43 toolLay->addWidget( ck );
44 ck->setChecked(
true );
45 connect( ck, SIGNAL(toggled(
bool)),
this, SLOT(enableAutomaticUpdates(
bool)) );
46 QPushButton* bt =
new QPushButton(
"Update Plots",
this );
47 toolLay->addWidget( bt );
48 bt->setEnabled(
false );
49 bt->setAutoRepeat(
true );
50 bt->setAutoRepeatDelay( 100 );
51 connect( bt, SIGNAL(clicked()),
this, SLOT(updatePlots()) );
52 connect( ck, SIGNAL(toggled(
bool)), bt, SLOT(setDisabled(
bool)) );
53 bt =
new QPushButton(
"Dequeue All Data",
this );
54 toolLay->addWidget( bt );
55 connect( bt, SIGNAL(clicked()),
this, SLOT(dequeueAllData()) );
58 replotTimer.setInterval( 20 );
59 replotTimer.setSingleShot(
false );
61 connect( &replotTimer, SIGNAL(timeout()),
this, SLOT(updatePlots()) );
69 QMutexLocker locker( &mutex );
71 QFrame* frame =
new QFrame(
this);
72 frame->setFrameStyle( QFrame::StyledPanel | QFrame::Plain );
73 QHBoxLayout* frameLay =
new QHBoxLayout( frame );
74 QLabel* lb =
new QLabel( name+
"\nNo Data", frame );
75 frameLay->addWidget( lb );
77 plot->setMinimumSize( QSize(100,80) );
78 plot->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Ignored ) );
79 frameLay->addWidget( plot );
80 layout()->addWidget( frame );
82 plotNames.append( name );
83 plotInfos.append( lb );
84 queuedValues.append( QQueue< QVector<float> >() );
85 return (plots.size()-1);
89 QMutexLocker locker( &mutex );
94 QMutexLocker locker( &mutex );
99 QMutexLocker locker( &mutex );
100 queuedValues[plotID].enqueue( values );
103 void DataStreamsWidget::updatePlots() {
104 QMutexLocker locker( &mutex );
105 for(
int p=0; p<plots.size(); p++ ) {
107 if ( !queuedValues[p].isEmpty() ) {
109 QVector<float> values = queuedValues[p].dequeue();
110 for(
int i=0; i<values.size(); i++ ) {
115 plotInfos[p]->setText( QString(
"%1\n%2 Queued Data")
117 .arg(queuedValues[p].size()) );
121 void DataStreamsWidget::enableAutomaticUpdates(
bool enable ) {
129 void DataStreamsWidget::dequeueAllData() {
130 QMutexLocker locker( &mutex );
132 QProgressDialog progress(
"Dequeuing All Pending Data...",
"Stop", 0, plots.size(), this );
134 for(
int p=0; p<plots.size(); p++ ) {
135 QQueue< QVector<float> > queue = queuedValues[p];
136 while( !queue.isEmpty() ) {
137 QVector<float> values = queue.dequeue();
138 for(
int i=0; i<values.size(); i++ ) {
139 plots[p]->appendData( i, values[i] );
142 progress.setValue(p);
144 progress.setValue(plots.size());
void updatePlot()
recalculate the x and y scale axis and replot the data
A macro to deprecate functions.
void appendData(int streamID, float value)
append a point to the stream specified
The DataStreamPlot display a series of data streams into the plot storing all the history of the data...