4 #include <qwt/qwt_plot_curve.h> 5 #include <qwt/qwt_plot.h> 6 #include <qwt/qwt_plot_magnifier.h> 7 #include <qwt/qwt_plot_panner.h> 8 #include <qwt/qwt_plot_picker.h> 9 #include <qwt/qwt_picker_machine.h> 10 #include <qwt/qwt_legend.h> 11 #include <qapplication.h> 20 Figure() : holdOn_(false), magnifier_(plot_.canvas()), panner_(plot_.canvas()), picker_(plot_.canvas())
22 plot_.setFixedWidth(800);
23 plot_.setFixedHeight(600);
24 plot_.setCanvasBackground(QBrush(Qt::white));
26 picker_.setStateMachine(
new QwtPickerDragPointMachine);
27 picker_.setTrackerMode(QwtPicker::AlwaysOn);
28 picker_.setEnabled(
true);
29 picker_.setRubberBandPen(QColor(Qt::black));
30 picker_.setRubberBand(QwtPicker::CrossRubberBand);
34 void plot(
const std::vector<double>& y)
36 std::cout <<
"plotting" << std::endl;
38 if (!holdOn_ || curves_.size() == 0)
42 x.setLinSpaced(y.size(), 0, y.size());
44 curves_.back()->setSamples(x.data(), y.data(), x.size());
46 std::cout <<
"set data" << std::endl;
51 std::cout <<
"showing result" << std::endl;
54 std::cout <<
"done" << std::endl;
58 void title(
const std::string&
title) { plot_.setWindowTitle(title.c_str()); }
61 plot_.setFixedWidth(dimX_pixels);
62 plot_.setFixedHeight(dimY_pixels);
66 typedef std::shared_ptr<QwtPlotCurve> QwtPlotCurvePtr;
68 void setDefaultCurveParams(QwtPlotCurvePtr& curve) { curve->setRenderHint(QwtPlotItem::RenderAntialiased); }
71 std::cout <<
"creating curve" << std::endl;
74 curves_.resize(curves_.size() + 1);
75 curves_.back() = QwtPlotCurvePtr(
new QwtPlotCurve);
76 setDefaultCurveParams(curves_.back());
78 curves_.back()->attach(&plot_);
84 QwtPlotMagnifier magnifier_;
85 QwtPlotPanner panner_;
86 QwtPlotPicker picker_;
87 std::vector<QwtPlotCurvePtr> curves_;
100 std::cout <<
"creating figure" << std::endl;
102 figures_.resize(figures_.size() + 1);
104 figures_.back()->title(
"Figure " + std::to_string(figures_.size() - 1));
106 return figures_.back();
111 std::cout <<
"initializing application " << std::endl;
113 fake_argv_[0] =
"foo";
114 fake_argv_[1] = NULL;
116 application_ =
new QApplication(fake_argc_, fake_argv_);
121 void exec() { application_->exec(); }
123 std::string appName_ =
"Plot";
124 static const int fake_argc_size_ = 2;
125 int fake_argc_ = fake_argc_size_;
126 char* fake_argv_[fake_argc_size_];
128 QApplication* application_;
130 std::vector<FigurePtr> figures_;
135 std::cout <<
"starting application" << std::endl;
137 std::cout <<
"created application, will now exec" << std::endl;
146 if (ctx.app_ ==
nullptr)
148 std::cout <<
"ctx.app_ is null ptr" << std::endl;
174 std::cout <<
"waiting for app to finish" << std::endl;
Definition: plotQwt.h:141
std::shared_ptr< Figure > FigurePtr
Definition: plotQwt.h:90
_application()
Definition: plotQwt.h:109
FigurePtr createFigure()
Definition: plotQwt.h:98
FigurePtr createFigure()
Definition: plotQwt.h:187
static _application * get()
Definition: plotQwt.h:143
void exec()
Definition: plotQwt.h:121
~_application()
Definition: plotQwt.h:120
ct::core::StateVector< state_dim > x
void render()
Definition: plotQwt.h:192