DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Loading...
Searching...
No Matches
BusyDialog.cpp
Go to the documentation of this file.
1// This file is part of DynExp.
2
3#include "stdafx.h"
4#include "moc_BusyDialog.cpp"
5#include "ui_BusyDialog.h"
6#include "BusyDialog.h"
7
8BusyDialog::BusyDialog(QWidget* parent)
9 : QDialog(parent, Qt::Dialog | Qt::WindowTitleHint),
10 ui(std::make_unique<Ui::BusyDialog>()),
11 CheckFinishedTimer(new QTimer(this)), CheckFinishedFunction(nullptr)
12{
13 ui->setupUi(this);
14
15 setWindowTitle(QString("Please wait for ") + DynExp::DynExpName + "...");
16 setFixedSize(size());
17
18 // Start timer which regularly checks whether the specified action has finished.
19 // If this is the case, the dialog is closed.
20 connect(CheckFinishedTimer, &QTimer::timeout, this, &BusyDialog::OnCheckFinished);
21 CheckFinishedTimer->setInterval(std::chrono::milliseconds(1));
22}
23
27
29{
30 if (Text.isEmpty())
31 ui->DescriptionLabel->setText("Please wait...");
32 else
33 ui->DescriptionLabel->setText(Text);
34}
35
37{
38 this->CheckFinishedFunction = CheckFinishedFunction;
39}
40
41void BusyDialog::showEvent(QShowEvent* event)
42{
43 Exception = nullptr;
44
46 CheckFinishedTimer->start();
47
48 ui->cancelButton->setEnabled(CheckFinishedFunction != nullptr);
49
50 event->accept();
51}
52
53void BusyDialog::closeEvent(QCloseEvent* event)
54{
55 CheckFinishedTimer->stop();
56
57 event->accept();
58}
59
60// If CheckFinishedFunction is nullptr, only the parent decides when this dialog is closed
62{
64 QDialog::reject();
65}
66
68{
69 try
70 {
73 accept();
74 }
75 catch ([[maybe_unused]] const Util::TimeoutException& e)
76 {
77 // Swallow TimeoutException, because this is most likely a temporary error.
78 }
79 catch (...)
80 {
81 Exception = std::current_exception();
82
83 // Treat any case of an exception as aborting the action.
84 reject();
85 }
86}
Implements a dialog with a progress bar, which shows the user that DynExp is busy.
CheckFinishedFunctionType CheckFinishedFunction
Definition BusyDialog.h:40
virtual void closeEvent(QCloseEvent *event) override
void SetDescriptionText(QString Text)
std::exception_ptr Exception
Definition BusyDialog.h:41
std::function< bool(void)> CheckFinishedFunctionType
Definition BusyDialog.h:22
void SetCheckFinishedFunction(const CheckFinishedFunctionType CheckFinishedFunction)
void OnCheckFinished()
virtual void showEvent(QShowEvent *event) override
QTimer * CheckFinishedTimer
Definition BusyDialog.h:38
std::unique_ptr< Ui::BusyDialog > ui
Definition BusyDialog.h:37
BusyDialog(QWidget *parent)
Definition BusyDialog.cpp:8
virtual void reject() override
Thrown when an operation timed out before it could be completed, especially used for locking shared d...
Definition Exception.h:262
constexpr auto DynExpName
DynExp's name string
Accumulates include statements to provide a precompiled header.