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

📄 bode.cpp

📁 This a framework to test new ideas in transmission technology. Actual development is a LDPC-coder in
💻 CPP
字号:
#include <qregexp.h>#include <qapplication.h>#include <qhbox.h>#include <qtoolbar.h>#include <qtoolbutton.h>#include <qlabel.h>#include <qstatusbar.h>#include <qprinter.h>#include <qwt_counter.h>#include <qwt_plot_zoomer.h>#include <qwt_math.h>#include "pixmaps.h"#include "bode_plot.h"#include "bode.h"class PrintFilter: public QwtPlotPrintFilter{public:    PrintFilter() {};    virtual QFont font(const QFont &f, Item, int) const    {        QFont f2 = f;        f2.setPointSize(int(f.pointSize() * 0.75));        return f2;    }};//-----------------------------------------------------------------////      bode.cpp -- A demo program featuring QwtPlot and QwtCounter////      This example demonstrates the mapping of different curves//      to different axes in a QwtPlot widget. It also shows how to//      display the cursor position and how to implement zooming.////-----------------------------------------------------------------MainWin::MainWin(QWidget *p , const char *name):     QMainWindow(p, name){    d_plot = new BodePlot(this);    d_plot->setMargin(5);    d_zoomer[0] = new QwtPlotZoomer(QwtPlot::xBottom, QwtPlot::yLeft,        QwtPicker::DragSelection, QwtPicker::AlwaysOff, d_plot->canvas());    d_zoomer[0]->setRubberBandPen(Qt::green);    d_zoomer[1] = new QwtPlotZoomer(QwtPlot::xTop, QwtPlot::yRight,        QwtPicker::DragSelection, QwtPicker::AlwaysOff, d_plot->canvas());    d_zoomer[1]->setRubberBand(QwtPicker::NoRubberBand);        d_picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft,        QwtPicker::PointSelection | QwtPicker::DragSelection,         QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOff,         d_plot->canvas());    d_picker->setRubberBandPen(Qt::green);    setCentralWidget(d_plot);    QToolBar *toolBar = new QToolBar(this);    QToolButton *btnZoom = new QToolButton(toolBar);    btnZoom->setTextLabel("Zoom");    btnZoom->setPixmap(zoom_xpm);    btnZoom->setToggleButton(TRUE);    btnZoom->setUsesTextLabel(TRUE);    QToolButton *btnPrint = new QToolButton(toolBar);    btnPrint->setTextLabel("Print");    btnPrint->setPixmap(print_xpm);    btnPrint->setUsesTextLabel(TRUE);    toolBar->setStretchableWidget(new QWidget(toolBar));    QHBox *dampBox = new QHBox(toolBar);    dampBox->setSpacing(10);    (void)new QLabel("Damping Factor", dampBox);    QwtCounter *cntDamp = new QwtCounter(dampBox);    cntDamp->setRange(0.0, 5.0, 0.01);    cntDamp->setValue(0.0);        addToolBar(toolBar);    (void)statusBar();    zoom(FALSE);    showInfo();    connect(cntDamp, SIGNAL(valueChanged(double)),         d_plot, SLOT(setDamp(double)));     connect(btnPrint, SIGNAL(clicked()), SLOT(print()));    connect(btnZoom, SIGNAL(toggled(bool)), SLOT(zoom(bool)));    connect(d_picker, SIGNAL(moved(const QPoint &)),            SLOT(moved(const QPoint &)));    connect(d_picker, SIGNAL(selected(const QPointArray &)),            SLOT(selected(const QPointArray &)));}void MainWin::print(){#if 1    QPrinter printer;#else    QPrinter printer(QPrinter::HighResolution);    printer.setOutputToFile(TRUE);    printer.setOutputFileName("/tmp/bode.ps");#endif    QString docName = d_plot->title();    if ( docName.isEmpty() )    {        docName.replace (QRegExp (QString::fromLatin1 ("\n")), tr (" -- "));        printer.setDocName (docName);    }    printer.setCreator("Bode example");    printer.setOrientation(QPrinter::Landscape);    if (printer.setup())    {        PrintFilter filter;        if ( printer.colorMode() == QPrinter::GrayScale )        {            filter.setOptions(QwtPlotPrintFilter::PrintAll                 & ~QwtPlotPrintFilter::PrintBackground);        }        d_plot->print(printer, filter);    }}void MainWin::zoom(bool on){    d_zoomer[0]->setEnabled(on);    d_zoomer[0]->zoom(0);    d_zoomer[1]->setEnabled(on);    d_zoomer[1]->zoom(0);    d_picker->setRubberBand(        on ? QwtPicker::NoRubberBand: QwtPicker::CrossRubberBand);    showInfo();}void MainWin::showInfo(QString text){    if ( text == QString::null )    {        if ( d_picker->rubberBand() )            text = "Cursor Pos: Press left mouse button in plot region";        else            text = "Zoom: Press mouse button and drag";    }    statusBar()->message(text);}void MainWin::moved(const QPoint &pos){    QString info;    info.sprintf("Freq=%g, Ampl=%g, Phase=%g",        d_plot->invTransform(QwtPlot::xBottom, pos.x()),        d_plot->invTransform(QwtPlot::yLeft, pos.y()),        d_plot->invTransform(QwtPlot::yRight, pos.y())    );    showInfo(info);}void MainWin::selected(const QPointArray &){    showInfo();}int main (int argc, char **argv){    QApplication a(argc, argv);    MainWin w;    a.setMainWidget(&w);    w.resize(540,400);    w.show();    int rv = a.exec();    return rv;}

⌨️ 快捷键说明

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