77#include < QFrame>
88#include < QHBoxLayout>
99#include < QString>
10+ #include < QValueAxis>
1011#include < QWidget>
1112#include < QtCharts>
1213#include < algorithm>
2526
2627namespace gui {
2728
29+ class GuiChart : public Chart
30+ {
31+ public:
32+ GuiChart (QChart* chart);
33+
34+ void setAxisLabel (const std::string& label,
35+ odb::Orientation2D orientation) override ;
36+ void setAxisFormat (const std::string& format,
37+ odb::Orientation2D orientation) override ;
38+ void addPoint (double x, double y) override ;
39+
40+ void addVerticalMarker (double x, const Painter::Color& color) override ;
41+
42+ private:
43+ QChart* chart_;
44+ QLineSeries* series_;
45+ QValueAxis* x_axis_;
46+ QValueAxis* y_axis_;
47+ double x_min_{std::numeric_limits<double >::max ()};
48+ double x_max_{std::numeric_limits<double >::lowest ()};
49+ double y_min_{std::numeric_limits<double >::max ()};
50+ double y_max_{std::numeric_limits<double >::lowest ()};
51+ };
52+
53+ GuiChart::GuiChart (QChart* chart) : chart_(chart)
54+ {
55+ series_ = new QLineSeries ();
56+ chart->addSeries (series_);
57+ chart->createDefaultAxes ();
58+
59+ x_axis_ = qobject_cast<QValueAxis*>(chart_->axes (Qt::Horizontal).first ());
60+ y_axis_ = qobject_cast<QValueAxis*>(chart_->axes (Qt::Vertical).first ());
61+ }
62+
63+ void GuiChart::setAxisLabel (const std::string& label,
64+ odb::Orientation2D orientation)
65+ {
66+ QValueAxis* axis = (orientation == odb::horizontal) ? x_axis_ : y_axis_;
67+ axis->setTitleText (QString::fromStdString (label));
68+ }
69+
70+ void GuiChart::setAxisFormat (const std::string& format,
71+ odb::Orientation2D orientation)
72+ {
73+ QValueAxis* axis = (orientation == odb::horizontal) ? x_axis_ : y_axis_;
74+ axis->setLabelFormat (QString::fromStdString (format));
75+ }
76+
77+ void GuiChart::addPoint (const double x, const double y)
78+ {
79+ series_->append (x, y);
80+ x_min_ = std::min (x_min_, x);
81+ x_max_ = std::max (x_max_, x);
82+ y_min_ = std::min (y_min_, x);
83+ y_max_ = std::max (y_max_, y);
84+
85+ // Adjust the axes to match the data range
86+ x_axis_->setMin (x_min_);
87+ x_axis_->setMax (x_max_);
88+ y_axis_->setMin (y_min_);
89+ y_axis_->setMax (y_max_);
90+ }
91+
92+ void GuiChart::addVerticalMarker (const double x, const Painter::Color& color)
93+ {
94+ QLineSeries* vline = new QLineSeries ();
95+ vline->append (x, y_axis_->min ());
96+ vline->append (x, y_axis_->max ());
97+
98+ QColor qt_color (color.r , color.g , color.b , color.a );
99+ vline->setPen (QPen (qt_color, 2 , Qt::DashLine));
100+
101+ chart_->addSeries (vline);
102+
103+ // link to same axes
104+ vline->attachAxis (x_axis_);
105+ vline->attachAxis (y_axis_);
106+ }
107+
108+ // ////////////////////////////////////////////////
109+
28110ChartsWidget::ChartsWidget (QWidget* parent)
29111 : QDockWidget(" Charts" , parent),
30112 logger_ (nullptr ),
31113 sta_(nullptr ),
32114 stagui_(nullptr ),
115+ chart_tabs_(new QTabWidget(this )),
33116 mode_menu_(new QComboBox(this )),
34117 filters_menu_(new QComboBox(this )),
35118 display_(new HistogramView(this )),
@@ -39,29 +122,37 @@ ChartsWidget::ChartsWidget(QWidget* parent)
39122 label_(new QLabel(this ))
40123{
41124 setObjectName (" charts_widget" ); // for settings
125+ chart_tabs_->setTabBarAutoHide (true );
42126
43- QWidget* container = new QWidget (this );
44127 QHBoxLayout* controls_layout = new QHBoxLayout;
45128 controls_layout->addWidget (label_);
46129
47- QVBoxLayout* layout = new QVBoxLayout;
48- QFrame* controls_frame = new QFrame;
49-
50- controls_layout->insertWidget (0 , mode_menu_);
130+ controls_layout->addWidget (mode_menu_);
51131 setModeMenu ();
52- controls_layout->insertWidget ( 1 , filters_menu_);
132+ controls_layout->addWidget ( filters_menu_);
53133 filters_menu_->hide ();
54134 controls_layout->addWidget (refresh_filters_button_);
55135 refresh_filters_button_->hide ();
56136 controls_layout->insertStretch (2 );
57137
138+ QFrame* controls_frame = new QFrame;
58139 controls_frame->setLayout (controls_layout);
59140 controls_frame->setFrameShape (QFrame::StyledPanel);
60141 controls_frame->setFrameShadow (QFrame::Raised);
61142
62- layout->addWidget (controls_frame);
63- layout->addWidget (display_);
143+ QVBoxLayout* slack_layout = new QVBoxLayout;
144+ slack_layout->addWidget (controls_frame);
145+ slack_layout->addWidget (display_);
146+
147+ QWidget* slack_container = new QWidget (this );
148+ slack_container->setLayout (slack_layout);
149+
150+ chart_tabs_->addTab (slack_container, " Slack" );
151+
152+ QVBoxLayout* layout = new QVBoxLayout;
153+ layout->addWidget (chart_tabs_);
64154
155+ QWidget* container = new QWidget (this );
65156 container->setLayout (layout);
66157
67158 connect (refresh_filters_button_,
@@ -81,6 +172,15 @@ ChartsWidget::ChartsWidget(QWidget* parent)
81172 setWidget (container);
82173}
83174
175+ Chart* ChartsWidget::addChart (const std::string& name)
176+ {
177+ QChart* chart = new QChart;
178+ QChartView* view = new QChartView (chart);
179+ const int tab_index = chart_tabs_->addTab (view, QString::fromStdString (name));
180+ chart_tabs_->setCurrentIndex (tab_index);
181+ return new GuiChart (chart);
182+ }
183+
84184void ChartsWidget::changeMode ()
85185{
86186 filters_menu_->clear ();
0 commit comments