32 #include <QHBoxLayout>
33 #include <QPushButton>
34 #include <QScrollArea>
41 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
43 _main_layout =
new QVBoxLayout(
this);
45 _main_layout->setAlignment(Qt::AlignTop);
51 ScopeCollectionWidget::~ScopeCollectionWidget() {}
53 QSize ScopeCollectionWidget::sizeHint()
const {
return QSize(1500, 800); }
55 void ScopeCollectionWidget::createMenu()
57 QHBoxLayout* menu_layout =
new QHBoxLayout;
60 QPushButton* new_scope_btn =
new QPushButton(tr(
"Add Scope"));
61 new_scope_btn->setMaximumWidth(100);
63 QFont font = new_scope_btn->font();
64 font.setPointSize(10);
65 new_scope_btn->setFont(font);
66 connect(new_scope_btn, &QPushButton::clicked, [
this](
bool) { addScope(); });
68 menu_layout->addWidget(new_scope_btn);
70 menu_layout->addStretch();
73 LabelEditWidget* tfs_edit =
new LabelEditWidget(tr(
"Preview time"),
"0");
74 tfs_edit->setMaximumWidth(130);
75 auto tfs_edit_changed = [tfs_edit,
this]() {
78 double value = tfs_edit->widgetLineEdit()->text().toDouble(&
ok);
82 tfs_edit->setText(
"0");
84 _current_preview_time = value;
85 emit previewTimeUpdate(_current_preview_time);
87 connect(tfs_edit->widgetLineEdit(), &QLineEdit::editingFinished, tfs_edit_changed);
88 menu_layout->addWidget(tfs_edit);
93 slider->setMaximumWidth(80);
94 slider->setToCenter();
95 slider->setStuckToCenter(10);
96 connect(slider, &SliderCenterStuck::valueChanged,
this, [slider, tfs_edit,
this](
int value) {
97 int speed = value - slider->getCenter();
99 if (_dial_preview_time_timer)
101 _dial_preview_time_timer->stop();
102 delete _dial_preview_time_timer;
103 _dial_preview_time_timer =
nullptr;
107 _dial_preview_time_timer =
new QTimer(
this);
109 double dt = (double)speed * (
double)
std::abs(speed) * 0.0001;
110 dt = std::trunc(dt * 100) / 100;
111 connect(_dial_preview_time_timer, &QTimer::timeout, tfs_edit, [tfs_edit, dt,
this]() {
113 double time = tfs_edit->widgetLineEdit()->
text().toDouble(&
ok);
119 _dial_preview_time_timer->stop();
121 tfs_edit->setText(QString::number(time));
122 _current_preview_time = time;
123 emit previewTimeUpdate(_current_preview_time);
125 _dial_preview_time_timer->start(250);
128 menu_layout->addWidget(slider);
130 menu_layout->addSpacing(20);
133 QCheckBox* inherit_signals =
new QCheckBox(tr(
"Inherit Signals"));
134 inherit_signals->setChecked(
true);
135 inherit_signals->setToolTip(tr(
"If selected, the signal-to-scope association is remembered for future tasks."));
136 connect(inherit_signals, &QCheckBox::toggled, [
this](
bool checked) { _inherit_signals = checked; });
138 menu_layout->addWidget(inherit_signals);
140 _main_layout->addLayout(menu_layout);
142 QFrame* hline =
new QFrame;
143 hline->setFrameShape(QFrame::HLine);
144 hline->setFrameShadow(QFrame::Sunken);
145 hline->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
146 _main_layout->addWidget(hline);
149 void ScopeCollectionWidget::createScopeArea()
151 _scope_layout =
new QVBoxLayout;
152 _scope_layout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
153 _scope_layout->setContentsMargins(0, 0, 0, 0);
156 QScrollArea* scroll_area =
new QScrollArea;
158 QWidget* group =
new QWidget;
159 group->setLayout(_scope_layout);
161 scroll_area->setWidgetResizable(
true);
162 scroll_area->setWidget(group);
163 _main_layout->addWidget(scroll_area);
166 void ScopeCollectionWidget::addScope()
168 if (!_signal_helper)
return;
170 ScopeWidget* scope_widget =
new ScopeWidget(_signal_helper);
171 scope_widget->setPreviewTime(_current_preview_time);
174 connect(
this, &ScopeCollectionWidget::scopeMeasurementUpdate, scope_widget,
175 [scope_widget](
const QString& key, Measurement::ConstPtr measurement, SignalHelper::SignalData& data,
bool ) {
176 scope_widget->addMeasurement(key, measurement, data);
183 connect(
this, &ScopeCollectionWidget::scopeSignalRemoval, scope_widget, &ScopeWidget::removeSignal);
185 connect(
this, &ScopeCollectionWidget::scopeTaskInitialization, scope_widget, &ScopeWidget::initializeTask);
187 connect(
this, &ScopeCollectionWidget::requestScopeAxesResize, scope_widget, &ScopeWidget::rescaleAxes);
189 connect(
this, &ScopeCollectionWidget::previewTimeUpdate, scope_widget, &ScopeWidget::setPreviewTime);
191 _scope_layout->addWidget(scope_widget);
194 void ScopeCollectionWidget::closeAllScopes()
202 while ((item = _scope_layout->takeAt(0)) !=
nullptr)
204 delete item->widget();
211 emit scopeMeasurementUpdate(key, measurement, signal_data, first);
214 void ScopeCollectionWidget::removeSignal(
const QString& key,
int value_idx) { emit scopeSignalRemoval(key, value_idx); }
216 void ScopeCollectionWidget::initializeTask(
int task_id) { emit scopeTaskInitialization(task_id, _inherit_signals); }
218 void ScopeCollectionWidget::resizeScopeAxes() { emit requestScopeAxesResize(); }