⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plotwin.cpp

📁 This a framework to test new ideas in transmission technology. Actual development is a LDPC-coder in
💻 CPP
字号:
/*******************************************************************************//*  Project:        SOFTWARE RADIO - LCM Laboratoire de Communications Mobiles *//*  -------------------------------------------------------------------------- *//*  Filename:       plotwin.cpp                                               *//*  Description:    Subclass of QMainWindow. It implements the multi-plot      *//*                  window for XY and Y(t) plot.                               *//*  -------------------------------------------------------------------------- *//*  Date:           April 7 2003                                               *//*  Version:        v1.0                                                       *//*  Authors:        Porchet Vincent                                            *//*                  Computer Science (6th semester) - EPFL                     *//*******************************************************************************//*******************************************************************************//*  This program is free software; you can redistribute it and/or modify it    *//*  under the terms of the GNU General Public License as published by the Free *//*  Software Foundation; either version 2 of the License, or (at your option)  *//*  any later version.                                                         *//*******************************************************************************//****** *  Changes * * 04/04/02 - ineiti - plot with X(t) now uses a list, too, so there is *                     no need anymore to have a time-button. */#include <qapplication.h>#include <qmainwindow.h>#include <qlayout.h>#include <qfile.h>#include <qstring.h>#include <qpushbutton.h>#include <qcombobox.h>#include <qtimer.h>#include <qspinbox.h>#include <qlabel.h>#include <qinputdialog.h>#include <qmessagebox.h>#include <unistd.h>#include <qwt_plot.h>#include "defines.h"#include "plotwin.h"#include "parameter_types.h"PlotWin::PlotWin( FifoCmd *c, bool do_xy ) :   radio( c ), xy( do_xy ) {  isAddCurve = false;  id_module1 = -1;  id_module2 = -1;  time = -1;  // timer for plot.  plotTimer = new QTimer();  connect( plotTimer, SIGNAL( timeout() ),           this, SLOT( updateGraph() ) );  plotTimerVal = 100;  isAddCurve = true;  QDesktopWidget *d = QApplication::desktop();  int desktopWidth = d->width();     // returns desktop width  frame = new MainSub( 0, 0, Qt::WType_Dialog + Qt::WDestructiveClose );  frame->move( desktopWidth - 500, 0 );  QWidget *mainW = new QWidget( frame );  frame->setCentralWidget( mainW );  QVBoxLayout *vBox = new QVBoxLayout( mainW, 5, 5, "plotWindowVerticalLayout" );  //graphic with show  plot = new Plot();  graph = new Show( "Trace", plot, mainW );  graph->styling(0);  graph->showType = show_plot;  connect( frame, SIGNAL( destroyed() ),           graph, SLOT( close() ) );  vBox->addWidget( graph );  graph->AddTypes( vBox, false );  // For xy-plots there is only a clear button, as we get every 'sample'  // anyway  // Add a clear-button  QPushButton *clearButton = new QPushButton( "Clear", mainW );  vBox->addWidget( clearButton );  connect( clearButton, SIGNAL( clicked() ),	   plot, SLOT( slotClear() ) );  connect( clearButton, SIGNAL( clicked() ),	   SLOT( slotClearTimer() ) );  graph->AddExport( vBox );  connect( frame, SIGNAL( closing() ), graph, SLOT( close() ) );  frame->resize( 300, 390 );  frame->show();  list_id = -1;}void PlotWin::slotAddCurve() {  if ( id_module1 < 0 ){    emit isAddingCurve( true );    isAddCurve = true;    //     QMessageBox::information(0,"info box","please, select module(s).");  } else {    QMessageBox::information( 0, "info box", "a curve is plotting." );  }}int PlotWin::getStats( int id, QString &name, int &type ){  //cree la lise et fait le choix de la stats1  bool ok;  QStringList stats = radio->getStats( id );    if ( !stats.count() ){    QMessageBox::information( 0, "info box", "no stat in this module,"			      " please select an other." );    return -1;  }    // Search for all ints and doubles  QStringList listOfStats;  QValueList<int> states_ids;  QValueList<int> types;  for ( uint i=0; i < stats.count(); i++ ){    QStringList args = QStringList::split( ",", stats[i] );    type = args[1].toInt();    if ( type == INT || type == DOUBLE ){      listOfStats += args[0];      states_ids += (int)i;      types += type;    }  }    name = QInputDialog::getItem( "stats input dialog", 				"choose a stat :",				listOfStats, 0, false, &ok );  if ( !ok ) {    QMessageBox::information( 0, "info box", "no stat selected, "			      "please select a module and a stat." );    type = -1;    return -1;  }   int index = listOfStats.findIndex( name );  type = types[ index ];  return states_ids[ index ];}void PlotWin::slotSelectedModule( Module* module ) {  int id = module->getId();  if ( isAddCurve ) {    //     cout<<"plotWin receved module : "<<module->name<<"\n";    if ( id_module1 < 0 ) {      id_stats1 = getStats( id, stats_name1, type1 );            if ( id_stats1 >= 0 ){	graph->setAxisTitle( QwtPlot::yLeft, stats_name1 );	id_module1 = id;      } else {	return;      }            if ( !xy ){	graph->setAxisTitle( QwtPlot::xBottom, "time [ms]" );	list_id = radio->newList( id_module1, id_stats1, -1, -1 );	type2 = INT;	stats_name2 = "time";	addCurveContinuous();      }    } else {      if ( xy ) {	if ( id_module2 < 0 ){	  id_stats2 = getStats( id, stats_name2, type2 );	  if ( id_stats2 >= 0 ){	    id_module2 = id;	    	    // If we add a second stats, the first gets on the x-axis	    // and the second on the y-axis. This is more intuitive	    graph->setAxisTitle( QwtPlot::xBottom, stats_name1 );	    graph->setAxisTitle( QwtPlot::yLeft, stats_name2 );	    list_id = radio->newList( id_module1, id_stats1,				      id_module2, id_stats2 );	    if ( list_id < 0 ){	      cout << QString( "Couldn't create list for %1/%2 and %3/%4\n" ).		arg( id_module1 ).arg( id_stats1 ).arg( id_module2 ).arg( id_stats2 );	    }	    addCurveContinuous();	  }	}      }    }  }}void PlotWin::slotClearTimer(){  time = -1;}void PlotWin::addCurveContinuous() {  //   cout<<"addCurveContinuous is call.\n";  isAddCurve = false;  emit isAddingCurve( false );  frame->hide();  frame->show();  plotTimer->start( plotTimerVal * 10 );  updateGraph();}void PlotWin::updateGraph() {  double val[2];  int type;  QStringList values = radio->readList( list_id );      for ( uint i = 0; i < values.count(); i++ ){    QStringList vals( QStringList::split( ",", values[ i ] ) );    for ( int j = 0; j < 2; j++ ) {      type = j ? type2:type1;      switch ( type ) {      case INT:	val[j] = vals[j].toInt();	break;      case DOUBLE:	val[j] = vals[j].toDouble();	break;      default:	cout << "wrong type " << ( j?type1:type2 ) << " " << i << endl;	break;      }    }    if ( xy ){      plot->addPoint( val[0], val[1] );    } else {      if ( time == -1 ){	time = (long int)val[1];      }      plot->addPoint( ( val[1] - time ) / 1000, val[0] );    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -