fw4spl
t/src/fwGuiQt/dialog/PulseProgressDialog.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include <QtCore>
8 #include <QString>
9 #include <QFutureWatcher>
10 #include <QApplication>
11 #include <QtConcurrent>
12 
13 #include <fwCore/base.hpp>
14 #include <fwGui/registry/macros.hpp>
15 
16 
17 #include "fwGuiQt/dialog/PulseProgressDialog.hpp"
18 
19 
21 
22 
23 namespace fwGuiQt
24 {
25 namespace dialog
26 {
27 //------------------------------------------------------------------------------
28 
29 PulseProgressDialog::PulseProgressDialog(::fwGui::GuiBaseObject::Key key)
30 {
31  m_pdialog = new QProgressDialog(qApp->activeWindow());
32 }
33 
34 //------------------------------------------------------------------------------
35 
36 PulseProgressDialog::~PulseProgressDialog()
37 {
38  if (m_pdialog)
39  {
40  m_pdialog->hide();
41  delete m_pdialog;
42  }
43 }
44 
45 //------------------------------------------------------------------------------
46 
47 void PulseProgressDialog::setTitle(const std::string &title)
48 {
49  m_pdialog->setWindowTitle(QString::fromStdString(title));
50 }
51 
52 //------------------------------------------------------------------------------
53 
54 void PulseProgressDialog::setMessage(const std::string &msg)
55 {
56  m_pdialog->setLabelText(QString::fromStdString(msg));
57 }
58 
59 //------------------------------------------------------------------------------
60 
62 {
63  // Create a QFutureWatcher and connect signals and slots.
64  QFutureWatcher<void> futureWatcher;
65  QObject::connect(&futureWatcher, SIGNAL(finished()), m_pdialog, SLOT(reset()));
66  QObject::connect(m_pdialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel()));
67  QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int,int)), m_pdialog, SLOT(setRange(int,int)));
68  QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), m_pdialog, SLOT(setValue(int)));
69 
70  // Start the computation.
71  futureWatcher.setFuture(QtConcurrent::run(m_stuff));
72 
73  m_pdialog->exec();
74 }
75 
76 //------------------------------------------------------------------------------
77 
78 } // namespace dialog
79 } // namespace fwGuiQt
This class allows us to show a pulse progress bar.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
static FWGUI_API const FactoryRegistryKeyType REGISTRY_KEY
this unique key should be used for all factory for specific LocationDialog(qt,wx,...)
The namespace fwGuiQt contains classes which provide the implementation of the Gui using Qt library...
Definition: WindowLevel.hpp:32
FWGUIQT_API void setTitle(const std::string &title) override
override
FWGUIQT_API void setMessage(const std::string &message) override
override
FWGUIQT_API void show() override
show the pulse progress dialog