Skip to content

Commit 3e2cc87

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 c6fff64 commit 3e2cc87

File tree

5 files changed

+77
-28
lines changed

5 files changed

+77
-28
lines changed

src/gui/MainWindow.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ MainWindow::MainWindow(IDeviceManager& device_manager, QWidget* parent)
2424
connect(signal_estimator_, &SignalEstimator::error, this, &MainWindow::show_error);
2525
connect(signal_estimator_, &SignalEstimator::can_read, this,
2626
&MainWindow::read_graph_data);
27+
connect(signal_estimator_, &SignalEstimator::finished, this, [this]() {
28+
ui->StartButton->setVisible(true);
29+
ui->StopButton->setVisible(false);
30+
ui->StatusLabel->setText("");
31+
timer_->stop();
32+
});
2733

2834
ui->OutputSig->setCanvasBackground(Qt::white);
2935

@@ -100,6 +106,8 @@ MainWindow::~MainWindow() {
100106
}
101107

102108
void MainWindow::on_StartButton_released() {
109+
ui->StartButton->setVisible(false);
110+
ui->StopButton->setVisible(true);
103111
QStringList args = set_up_program_();
104112

105113
set_update_plots_(true); // must be true to update graphs
@@ -119,21 +127,29 @@ void MainWindow::on_StartButton_released() {
119127
}
120128

121129
if (signal_estimator_->start(args)) {
122-
ui->ErrorLabel->setText("");
130+
ui->StatusLabel->setText("Running");
123131
} else {
124-
ui->ErrorLabel->setText(QString("Failed to open signal-estimator"));
132+
ui->StatusLabel->setText(QString("Failed to open signal-estimator"));
125133
}
126134

127135
set_update_plots_(true);
128136
timer_->start();
129137
}
130138

131139
void MainWindow::on_StopButton_clicked() {
140+
ui->StartButton->setVisible(true);
141+
ui->StopButton->setVisible(false);
142+
ui->StatusLabel->setText("");
132143
signal_estimator_->stop();
133144

134145
set_update_plots_(false);
135146
}
136147

148+
void MainWindow::on_DurationCheckBox_stateChanged(int state) {
149+
const bool checked = (state == Qt::Checked);
150+
ui->Duration->setEnabled(!checked);
151+
}
152+
137153
void MainWindow::update_graphs() {
138154
if (!update_plots_) {
139155
return;
@@ -170,7 +186,7 @@ void MainWindow::read_graph_data() {
170186
}
171187

172188
void MainWindow::show_error(QString error) {
173-
ui->ErrorLabel->setText(error);
189+
ui->StatusLabel->setText(error);
174190
}
175191

176192
QStringList MainWindow::set_up_program_() {
@@ -210,7 +226,12 @@ QStringList MainWindow::set_up_program_() {
210226
list.append("-l");
211227
list.append(t);
212228

213-
t = ui->Duration->cleanText();
229+
if (ui->Duration->isEnabled()) {
230+
t = ui->Duration->cleanText();
231+
} else {
232+
// one year. TODO find a better solution to have infinite measurement
233+
t = "31536000";
234+
}
214235
list.append("-d");
215236
list.append(t);
216237

src/gui/MainWindow.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class MainWindow : public QMainWindow {
4242
private slots:
4343
void on_StartButton_released();
4444
void on_StopButton_clicked();
45+
void on_DurationCheckBox_stateChanged(int state);
4546

4647
void update_graphs();
4748
void read_graph_data();

src/gui/MainWindow.ui

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@
188188
</item>
189189
<item>
190190
<widget class="QPushButton" name="StopButton">
191+
<property name="visible">
192+
<bool>false</bool>
193+
</property>
191194
<property name="toolTip">
192195
<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>
193196
</property>
@@ -448,20 +451,40 @@
448451
</widget>
449452
</item>
450453
<item row="5" column="1">
451-
<widget class="QSpinBox" name="Duration">
452-
<property name="minimum">
454+
<layout class="QHBoxLayout" name="DurationLayout">
455+
<property name="margin">
453456
<number>0</number>
454457
</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>
458+
<item>
459+
<widget class="QSpinBox" name="Duration">
460+
<property name="minimum">
461+
<number>1</number>
462+
</property>
463+
<property name="maximum">
464+
<number>2147483647</number>
465+
</property>
466+
<property name="singleStep">
467+
<number>1</number>
468+
</property>
469+
<property name="value">
470+
<number>10</number>
471+
</property>
472+
<property name="enabled">
473+
<bool>false</bool>
474+
</property>
475+
</widget>
476+
</item>
477+
<item>
478+
<widget class="QCheckBox" name="DurationCheckBox">
479+
<property name="checked">
480+
<bool>true</bool>
481+
</property>
482+
<property name="toolTip">
483+
<string>run measurement unlimited</string>
484+
</property>
485+
</widget>
486+
</item>
487+
</layout>
465488
</item>
466489
<item row="6" column="0">
467490
<widget class="QLabel" name="Label1_6">
@@ -683,7 +706,7 @@
683706
</widget>
684707
</item>
685708
<item>
686-
<widget class="QLabel" name="ErrorLabel">
709+
<widget class="QLabel" name="StatusLabel">
687710
<property name="text">
688711
<string/>
689712
</property>

src/gui/SignalEstimator.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ QString SignalEstimator::find() {
4040
return {};
4141
}
4242

43-
bool SignalEstimator::start(QStringList args) {
43+
bool SignalEstimator::start(const QStringList& args) {
4444
stop();
4545

4646
proc_ = QSharedPointer<QProcess>(new QProcess);
@@ -53,15 +53,19 @@ bool SignalEstimator::start(QStringList args) {
5353
connect(proc_.data(), &QProcess::readyReadStandardOutput, this,
5454
&SignalEstimator::can_read);
5555

56-
connect(proc_.data(), qOverload<QProcess::ProcessError>(&QProcess::errorOccurred),
57-
this, [this]() {
56+
connect(
57+
proc_.data(), qOverload<QProcess::ProcessError>(&QProcess::errorOccurred), this,
58+
[this]() {
5859
if (proc_) {
59-
error(proc_->errorString());
60+
emit error(proc_->errorString());
6061
}
61-
});
62+
},
63+
Qt::QueuedConnection);
64+
connect(proc_.data(), qOverload<int, QProcess::ExitStatus>(&QProcess::finished), this,
65+
[this](int, QProcess::ExitStatus) { emit finished(); });
6266

6367
if (!proc_->open(QProcess::ReadOnly)) {
64-
proc_ = {};
68+
proc_.reset();
6569
return false;
6670
}
6771

@@ -72,8 +76,7 @@ void SignalEstimator::stop() {
7276
if (proc_ && proc_->isOpen()) {
7377
proc_->close();
7478
}
75-
76-
proc_ = {};
79+
proc_.reset();
7780
}
7881

7982
std::optional<std::tuple<QPointF, PointType>> SignalEstimator::read() {
@@ -112,7 +115,7 @@ std::optional<std::tuple<QPointF, PointType>> SignalEstimator::parse_(QString bu
112115
QPointF pt;
113116

114117
try {
115-
pt.setX(tokens[1].toDouble() / 1000000);
118+
pt.setX(tokens[1].toDouble() / 1'000'000);
116119
} catch (const std::invalid_argument&) {
117120
return {};
118121
}

src/gui/SignalEstimator.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@ class SignalEstimator : public QObject {
2222
public:
2323
static QString find();
2424

25-
SignalEstimator(QObject* parent = nullptr);
25+
explicit SignalEstimator(QObject* parent = nullptr);
2626
~SignalEstimator() override;
2727

28-
bool start(QStringList args);
28+
bool start(const QStringList& args);
2929
void stop();
3030

3131
std::optional<std::tuple<QPointF, PointType>> read();
3232

3333
signals:
3434
void can_read();
3535
void error(QString);
36+
void finished();
3637

3738
private:
3839
std::optional<std::tuple<QPointF, PointType>> parse_(QString buffer);

0 commit comments

Comments
 (0)