AsyncProgressDialog
AsyncProgressDialog.h
1 #pragma once
2 
3 #include "ProgressWidgetFactory.h"
4 #include "ProgressBar.h"
5 #include "FunctionThread.h"
6 
7 #include <QDialog>
8 
9 #include <functional>
10 
11 
12 namespace APD
13 {
14 
15 class TaskThread;
16 class ProgressWidget;
17 
18 class AsyncProgressDialog : public QDialog
19 {
20  Q_OBJECT
21 
22 public:
23  explicit AsyncProgressDialog(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
24  ~AsyncProgressDialog() override;
25 
26  void addTask(TaskThread* thread, ProgressWidget* widget);
27 
39  template <typename F>
42  {
43  using ResultType = decltype(func(static_cast<TaskThread*>(nullptr)));
44  auto thread = new FunctionThread<ResultType>(std::move(func), this);
45  addTask(thread, widget);
46  return thread;
47  }
48 
49  void setAutoClose(bool close);
50  bool autoClose() const;
51 
52  void setOverallProgress(bool enabled);
53  bool hasOverallProgress() const;
54 
55  void setLabelText(const QString& labelText);
56  QString labelText() const;
57 
58  int threadCount() const;
59  TaskThread* threadAt(int index) const;
60 
61  int widgetCount() const;
62  ProgressWidget* widgetAt(int index) const;
63 
64  void setAutoHideWidget(int index, bool autoHide);
65  bool autoHideWidget(int index) const;
66 
67 public slots:
68  void reject() override;
69 
70 private:
71  Q_DISABLE_COPY(AsyncProgressDialog)
72 
73  class Impl;
74  std::unique_ptr<Impl> m_impl;
75 };
76 
77 
78 }
79 
TaskThread * threadAt(int index) const
Definition: AsyncProgressDialog.cpp:375
auto addTask(F func, ProgressWidget *widget=ProgressWidgetFactory::createProgressBar()) -> FunctionThread< decltype(func(static_cast< TaskThread * >(nullptr)))> *
Definition: AsyncProgressDialog.h:40
bool autoHideWidget(int index) const
Definition: AsyncProgressDialog.cpp:424
void addTask(TaskThread *thread, ProgressWidget *widget)
Definition: AsyncProgressDialog.cpp:267
void setAutoHideWidget(int index, bool autoHide)
Definition: AsyncProgressDialog.cpp:411
bool autoClose() const
Definition: AsyncProgressDialog.cpp:302
The AsyncProgressDialog dialog is capable of running task threads and displaying a progress widget fo...
Definition: AsyncProgressDialog.h:18
Base class for all widgets capable of displaying progress for a TaskThread.
Definition: ProgressWidget.h:10
AsyncProgressDialog(QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::WindowFlags())
Definition: AsyncProgressDialog.cpp:238
bool hasOverallProgress() const
Definition: AsyncProgressDialog.cpp:329
static ProgressWidget * createProgressBar(const QString &label, AdditionalWidgets additionalWidgets=AdditionalWidget::NoWidget)
Definition: ProgressWidgetFactory.cpp:63
void setLabelText(const QString &labelText)
Definition: AsyncProgressDialog.cpp:339
QString labelText() const
Definition: AsyncProgressDialog.cpp:353
int threadCount() const
Definition: AsyncProgressDialog.cpp:364
void setAutoClose(bool close)
Definition: AsyncProgressDialog.cpp:289
Base class for all threads capable of reporting progress and cancelling the progress when requested.
Definition: TaskThread.h:11
void setOverallProgress(bool enabled)
Definition: AsyncProgressDialog.cpp:313
ProgressWidget * widgetAt(int index) const
Definition: AsyncProgressDialog.cpp:397
int widgetCount() const
Definition: AsyncProgressDialog.cpp:386
void reject() override
Definition: AsyncProgressDialog.cpp:275
A thread class, which executes the function provided in the constructor of this class as soon as the ...
Definition: FunctionThread.h:22