Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
QmitkProgressBar.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "QmitkProgressBar.h"
18 
19 #include "mitkProgressBar.h"
20 #include "mitkRenderingManager.h"
21 
22 #include <qapplication.h>
23 #include <qprogressbar.h>
24 
28 void QmitkProgressBar::Reset()
29 {
30  this->reset();
31  this->hide();
32  m_TotalSteps = 0;
33  m_Progress = 0;
34 }
35 
40 {
41  emit SignalSetPercentageVisible(visible);
42 }
43 
48 void QmitkProgressBar::AddStepsToDo(unsigned int steps)
49 {
50  emit SignalAddStepsToDo(steps);
51 }
52 
58 void QmitkProgressBar::Progress(unsigned int steps)
59 {
60  emit SignalProgress(steps);
61 }
62 
63 QmitkProgressBar::QmitkProgressBar(QWidget *parent, const char * /*name*/)
64  : QProgressBar(parent), ProgressBarImplementation()
65 {
66  m_TotalSteps = 0;
67  m_Progress = 0;
68  this->hide();
69  this->SetPercentageVisible(true);
70 
71  connect(this, SIGNAL(SignalAddStepsToDo(unsigned int)), this, SLOT(SlotAddStepsToDo(unsigned int)));
72  connect(this, SIGNAL(SignalProgress(unsigned int)), this, SLOT(SlotProgress(unsigned int)));
73  connect(this, SIGNAL(SignalSetPercentageVisible(bool)), this, SLOT(SlotSetPercentageVisible(bool)));
74 
76 }
77 
79 {
81 }
82 
83 void QmitkProgressBar::SlotProgress(unsigned int steps)
84 {
85  m_Progress += steps;
86  this->setValue(m_Progress);
87 
88  if (m_Progress >= m_TotalSteps)
89  Reset();
90  else
91  {
92  this->show();
93  }
94 
95  // Update views if repaint has been requested in the meanwhile
96  // (because Qt event loop is not reached while progress bar is updating,
97  // unless the application is threaded)
98  // qApp->processEvents();
100 }
101 
102 void QmitkProgressBar::SlotAddStepsToDo(unsigned int steps)
103 {
104  m_TotalSteps += steps;
105  this->setMaximum(m_TotalSteps);
106  this->setValue(m_Progress);
107  if (m_TotalSteps > 0)
108  {
109  this->show();
110  }
111 
112  // Update views if repaint has been requested in the meanwhile
113  // (because Qt event loop is not reached while progress bar is updating,
114  // unless the application is threaded)
116 }
117 
119 {
120  this->setTextVisible(visible);
121 }
virtual void SetPercentageVisible(bool visible) override
Sets whether the current progress value is displayed.
void SignalSetPercentageVisible(bool visible)
void RegisterImplementationInstance(ProgressBarImplementation *implementation)
Supply a GUI- dependent ProgressBar. Has to be set by the application to connect the application depe...
virtual void Progress(unsigned int steps) override
Sets the current amount of progress to current progress + steps.
virtual void SlotAddStepsToDo(unsigned int steps)
static ProgressBar * GetInstance()
static method to get the GUI dependent ProgressBar-instance so the methods for steps to do and progre...
QmitkProgressBar(QWidget *parent=nullptr, const char *name=nullptr)
Constructor; holds param instance internally and connects this to the mitkProgressBar.
void SignalAddStepsToDo(unsigned int steps)
static RenderingManager * GetInstance()
void UnregisterImplementationInstance(ProgressBarImplementation *implementation)
virtual void AddStepsToDo(unsigned int steps) override
Adds steps to totalSteps.
virtual void SlotProgress(unsigned int steps)
virtual void SlotSetPercentageVisible(bool visible)
virtual ~QmitkProgressBar()
Destructor.
void SignalProgress(unsigned int steps)