Skip to content

Commit 26ba5b6

Browse files
committed
Minor improvements to GUI:
- Made start/stop buttons mutually exclusive - Added option to run the measurement infinite - Removed "Process crashed" status update after finished measurement
1 parent 6764ca9 commit 26ba5b6

File tree

5 files changed

+206
-64
lines changed

5 files changed

+206
-64
lines changed

src/gui/MainWindow.cpp

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "ui_MainWindow.h"
77

88
#include <QCheckBox>
9+
#include <QCloseEvent>
910
#include <QList>
1011
#include <QPen>
1112

@@ -24,6 +25,12 @@ MainWindow::MainWindow(IDeviceManager& device_manager, QWidget* parent)
2425
connect(signal_estimator_, &SignalEstimator::error, this, &MainWindow::show_error);
2526
connect(signal_estimator_, &SignalEstimator::can_read, this,
2627
&MainWindow::read_graph_data);
28+
connect(signal_estimator_, &SignalEstimator::finished, this, [this]() {
29+
ui->actionStart->setEnabled(true);
30+
ui->actionStop->setEnabled(false);
31+
ui->StatusLabel->setText("");
32+
timer_->stop();
33+
});
2734

2835
ui->OutputSig->setCanvasBackground(Qt::white);
2936

@@ -99,7 +106,14 @@ MainWindow::~MainWindow() {
99106
delete ui;
100107
}
101108

102-
void MainWindow::on_StartButton_released() {
109+
void MainWindow::closeEvent(QCloseEvent* event) {
110+
signal_estimator_->stop();
111+
event->accept();
112+
}
113+
114+
void MainWindow::on_start() {
115+
ui->actionStart->setEnabled(false);
116+
ui->actionStop->setEnabled(true);
103117
QStringList args = set_up_program_();
104118

105119
set_update_plots_(true); // must be true to update graphs
@@ -119,21 +133,29 @@ void MainWindow::on_StartButton_released() {
119133
}
120134

121135
if (signal_estimator_->start(args)) {
122-
ui->ErrorLabel->setText("");
136+
ui->StatusLabel->setText("Running");
123137
} else {
124-
ui->ErrorLabel->setText(QString("Failed to open signal-estimator"));
138+
ui->StatusLabel->setText(QString("Failed to open signal-estimator"));
125139
}
126140

127141
set_update_plots_(true);
128142
timer_->start();
129143
}
130144

131-
void MainWindow::on_StopButton_clicked() {
145+
void MainWindow::on_stop() {
146+
ui->actionStart->setEnabled(true);
147+
ui->actionStop->setEnabled(false);
148+
ui->StatusLabel->setText("");
132149
signal_estimator_->stop();
133150

134151
set_update_plots_(false);
135152
}
136153

154+
void MainWindow::on_DurationCheckBox_stateChanged(int state) {
155+
const bool checked = (state == Qt::Checked);
156+
ui->Duration->setEnabled(!checked);
157+
}
158+
137159
void MainWindow::update_graphs() {
138160
if (!update_plots_) {
139161
return;
@@ -170,7 +192,7 @@ void MainWindow::read_graph_data() {
170192
}
171193

172194
void MainWindow::show_error(QString error) {
173-
ui->ErrorLabel->setText(error);
195+
ui->StatusLabel->setText(error);
174196
}
175197

176198
QStringList MainWindow::set_up_program_() {
@@ -210,7 +232,12 @@ QStringList MainWindow::set_up_program_() {
210232
list.append("-l");
211233
list.append(t);
212234

213-
t = ui->Duration->cleanText();
235+
if (ui->Duration->isEnabled()) {
236+
t = ui->Duration->cleanText();
237+
} else {
238+
// one year. TODO find a better solution to have infinite measurement
239+
t = "31536000";
240+
}
214241
list.append("-d");
215242
list.append(t);
216243

src/gui/MainWindow.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@ class MainWindow : public QMainWindow {
3939
explicit MainWindow(IDeviceManager& device_manager, QWidget* parent = nullptr);
4040
~MainWindow() override;
4141

42+
protected slots:
43+
void closeEvent(QCloseEvent*) override;
44+
4245
private slots:
43-
void on_StartButton_released();
44-
void on_StopButton_clicked();
46+
void on_start();
47+
void on_stop();
48+
void on_DurationCheckBox_stateChanged(int state);
4549

4650
void update_graphs();
4751
void read_graph_data();

src/gui/MainWindow.ui

Lines changed: 152 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -174,43 +174,15 @@
174174
</property>
175175
</widget>
176176
</item>
177-
<item>
178-
<layout class="QHBoxLayout" name="horizontalLayout">
179-
<item>
180-
<widget class="QPushButton" name="StartButton">
181-
<property name="toolTip">
182-
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Run signal-estimator and graph the results&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
183-
</property>
184-
<property name="text">
185-
<string>Start</string>
186-
</property>
187-
</widget>
188-
</item>
189-
<item>
190-
<widget class="QPushButton" name="StopButton">
191-
<property name="toolTip">
192-
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Stop graphing. Please wait for the sounds of signal-estimator to stop&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
193-
</property>
194-
<property name="text">
195-
<string>Stop</string>
196-
</property>
197-
</widget>
198-
</item>
199-
</layout>
200-
</item>
201177
<item>
202178
<layout class="QHBoxLayout" name="horizontalLayout_3">
203179
<item>
204180
<widget class ="QCheckBox" name="GridCheckBox">
181+
<property name="text">
182+
<string>show grid</string>
183+
</property>
205184
</widget>
206185
</item>
207-
<item>
208-
<widget class="QLabel" name="GridCheckBoxLabel">
209-
<property name="text">
210-
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;show grid&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
211-
</property>
212-
</widget>
213-
</item>
214186
<item>
215187
<spacer name="horizontalSpacer_3">
216188
<property name="orientation">
@@ -448,20 +420,53 @@
448420
</widget>
449421
</item>
450422
<item row="5" column="1">
451-
<widget class="QSpinBox" name="Duration">
452-
<property name="minimum">
423+
<layout class="QHBoxLayout" name="DurationLayout">
424+
<property name="margin">
453425
<number>0</number>
454426
</property>
455-
<property name="maximum">
456-
<number>2147483647</number>
457-
</property>
458-
<property name="singleStep">
459-
<number>1</number>
460-
</property>
461-
<property name="value">
462-
<number>10</number>
463-
</property>
464-
</widget>
427+
<item>
428+
<widget class="QSpinBox" name="Duration">
429+
<property name="minimum">
430+
<number>1</number>
431+
</property>
432+
<property name="maximum">
433+
<number>2147483647</number>
434+
</property>
435+
<property name="singleStep">
436+
<number>1</number>
437+
</property>
438+
<property name="value">
439+
<number>10</number>
440+
</property>
441+
<property name="enabled">
442+
<bool>false</bool>
443+
</property>
444+
</widget>
445+
</item>
446+
<item>
447+
<widget class="QCheckBox" name="DurationCheckBox">
448+
<property name="checked">
449+
<bool>true</bool>
450+
</property>
451+
<property name="text">
452+
<string>run measurement unlimited</string>
453+
</property>
454+
</widget>
455+
</item>
456+
<item>
457+
<spacer name="horizontalSpacer">
458+
<property name="orientation">
459+
<enum>Qt::Horizontal</enum>
460+
</property>
461+
<property name="sizeHint" stdset="0">
462+
<size>
463+
<width>40</width>
464+
<height>20</height>
465+
</size>
466+
</property>
467+
</spacer>
468+
</item>
469+
</layout>
465470
</item>
466471
<item row="6" column="0">
467472
<widget class="QLabel" name="Label1_6">
@@ -683,7 +688,7 @@
683688
</widget>
684689
</item>
685690
<item>
686-
<widget class="QLabel" name="ErrorLabel">
691+
<widget class="QLabel" name="StatusLabel">
687692
<property name="text">
688693
<string/>
689694
</property>
@@ -700,6 +705,21 @@
700705
<height>28</height>
701706
</rect>
702707
</property>
708+
<widget class="QMenu" name="menuFile">
709+
<property name="title">
710+
<string>File</string>
711+
</property>
712+
<addaction name="actionQuit"/>
713+
</widget>
714+
<widget class="QMenu" name="menuMeasurement">
715+
<property name="title">
716+
<string>Measurement</string>
717+
</property>
718+
<addaction name="actionStart"/>
719+
<addaction name="actionStop"/>
720+
</widget>
721+
<addaction name="menuFile"/>
722+
<addaction name="menuMeasurement"/>
703723
</widget>
704724
<widget class="QToolBar" name="mainToolBar">
705725
<attribute name="toolBarArea">
@@ -708,7 +728,45 @@
708728
<attribute name="toolBarBreak">
709729
<bool>false</bool>
710730
</attribute>
731+
<addaction name="actionStart"/>
732+
<addaction name="actionStop"/>
711733
</widget>
734+
<action name="actionQuit">
735+
<property name="text">
736+
<string>Quit</string>
737+
</property>
738+
<property name="toolTip">
739+
<string>Quit application</string>
740+
</property>
741+
<property name="shortcut">
742+
<string>Ctrl+Q</string>
743+
</property>
744+
</action>
745+
<action name="actionStart">
746+
<property name="text">
747+
<string>Start</string>
748+
</property>
749+
<property name="toolTip">
750+
<string>Start measurement (Ctrl+R)</string>
751+
</property>
752+
<property name="shortcut">
753+
<string>Ctrl+R</string>
754+
</property>
755+
</action>
756+
<action name="actionStop">
757+
<property name="text">
758+
<string>Stop</string>
759+
</property>
760+
<property name="toolTip">
761+
<string>Stop measurement (Ctrl+A)</string>
762+
</property>
763+
<property name="shortcut">
764+
<string>Ctrl+A</string>
765+
</property>
766+
<property name="enabled">
767+
<bool>false</bool>
768+
</property>
769+
</action>
712770
<widget class="QStatusBar" name="statusBar"/>
713771
</widget>
714772
<layoutdefault spacing="6" margin="11"/>
@@ -720,5 +778,54 @@
720778
</customwidget>
721779
</customwidgets>
722780
<resources/>
723-
<connections/>
781+
<connections>
782+
<connection>
783+
<sender>actionQuit</sender>
784+
<signal>triggered()</signal>
785+
<receiver>MainWindow</receiver>
786+
<slot>close()</slot>
787+
<hints>
788+
<hint type="sourcelabel">
789+
<x>-1</x>
790+
<y>-1</y>
791+
</hint>
792+
<hint type="destinationlabel">
793+
<x>399</x>
794+
<y>299</y>
795+
</hint>
796+
</hints>
797+
</connection>
798+
<connection>
799+
<sender>actionStart</sender>
800+
<signal>triggered()</signal>
801+
<receiver>MainWindow</receiver>
802+
<slot>on_start()</slot>
803+
<hints>
804+
<hint type="sourcelabel">
805+
<x>-1</x>
806+
<y>-1</y>
807+
</hint>
808+
<hint type="destinationlabel">
809+
<x>399</x>
810+
<y>299</y>
811+
</hint>
812+
</hints>
813+
</connection>
814+
<connection>
815+
<sender>actionStop</sender>
816+
<signal>triggered()</signal>
817+
<receiver>MainWindow</receiver>
818+
<slot>on_stop()</slot>
819+
<hints>
820+
<hint type="sourcelabel">
821+
<x>-1</x>
822+
<y>-1</y>
823+
</hint>
824+
<hint type="destinationlabel">
825+
<x>399</x>
826+
<y>299</y>
827+
</hint>
828+
</hints>
829+
</connection>
830+
</connections>
724831
</ui>

0 commit comments

Comments
 (0)